187 {
188 List<ROI> rois = new List<ROI>();
189
190 var queryService =
session.getQueryService();
191
192
193 var param = new ParametersI();
194 param.addId(imageId);
195
196
197 string query = "from Shape s where s.roi.image.id = :id";
198 var roiList = queryService.findAllByQuery(query, param);
199 int c = roiList.size();
200 for (int i = 0; i < c; i++)
201 {
202 var shape = (Shape)roiList.get(i);
203
204 var roiId = shape.getRoi().getId().getValue();
205 ROI ro = new ROI();
207 {
209 int zo = 0, co = 0, to = 0;
210 if (rec.getTheZ() != null)
211 zo = shape.getTheZ().getValue();
212 if (rec.getTheC() != null)
213 co = shape.getTheC().getValue();
214 if (rec.getTheT() != null)
215 to = shape.getTheT().getValue();
216 double x, y, w, h;
217 x = rec.getX().getValue();
218 y = rec.getY().getValue();
219 w = rec.getWidth().getValue();
220 h = rec.getHeight().getValue();
221
223 ro = ROI.CreateRectangle(
new ZCT(zo, co, to), x * physX, y * physY, w * physX, h * physY);
224 try
225 {
226 ro.Text = rec.getTextValue().getValue();
227 }
228 catch (Exception e)
229 {
230
231 }
232 rois.Add(ro);
233 }
234 else if (shape is Polygon)
235 {
236 Polygon pl = (Polygon)shape;
237 int zo = 0, co = 0, to = 0;
238 if (pl.getTheZ() != null)
239 zo = shape.getTheZ().getValue();
240 if (pl.getTheC() != null)
241 co = shape.getTheC().getValue();
242 if (pl.getTheT() != null)
243 to = shape.getTheT().getValue();
246 for (int p = 0; p < pds.Length; p++)
247 {
248 pds[p] =
new PointD(ps[p].X, ps[p].Y);
249 }
250 ro = ROI.CreatePolygon(
new ZCT(zo, co, to), pds);
251 try
252 {
253 ro.Text = pl.getTextValue().getValue();
254 }
255 catch (Exception e)
256 {
257
258 }
259 rois.Add(ro);
260 }
261 else if (shape is Polyline)
262 {
263 Polyline pl = (Polyline)shape;
264 int zo = 0, co = 0, to = 0;
265 if (pl.getTheZ() != null)
266 zo = shape.getTheZ().getValue();
267 if (pl.getTheC() != null)
268 co = shape.getTheC().getValue();
269 if (pl.getTheT() != null)
270 to = shape.getTheT().getValue();
273 for (int p = 0; p < pds.Length; p++)
274 {
275 pds[p] =
new PointD(ps[p].X, ps[p].Y);
276 }
277 ro = ROI.CreatePolygon(
new ZCT(zo, co, to), pds);
278 try
279 {
280 ro.Text = pl.getTextValue().getValue();
281 }
282 catch (Exception e)
283 {
284
285 }
286 ro.type = ROI.Type.Polyline;
287 ro.closed = false;
288 rois.Add(ro);
289 }
290 else if (shape is Line)
291 {
292 Line pl = (Line)shape;
293 int zo = 0, co = 0, to = 0;
294 if (pl.getTheZ() != null)
295 zo = shape.getTheZ().getValue();
296 if (pl.getTheC() != null)
297 co = shape.getTheC().getValue();
298 if (pl.getTheT() != null)
299 to = shape.getTheT().getValue();
302 for (int p = 0; p < pds.Length; p++)
303 {
304 pds[p] =
new PointD(ps[p].X, ps[p].Y);
305 }
306 ro = ROI.CreateLine(
new ZCT(zo, co, to),
new PointD(pds[0].X, pds[0].Y),
new PointD(pds[1].X, pds[1].Y));
307 try
308 {
309 ro.Text = pl.getTextValue().getValue();
310 }
311 catch (Exception e)
312 {
313
314 }
315 rois.Add(ro);
316 }
317 else if (shape is Ellipse)
318 {
319 Ellipse pl = (Ellipse)shape;
320 int zo = 0, co = 0, to = 0;
321 if (pl.getTheZ() != null)
322 zo = shape.getTheZ().getValue();
323 if (pl.getTheC() != null)
324 co = shape.getTheC().getValue();
325 if (pl.getTheT() != null)
326 to = shape.getTheT().getValue();
327 double rx = pl.getRadiusX().getValue() * physX;
328 double ry = pl.getRadiusY().getValue() * physY;
329 double x = pl.getX().getValue() * physX;
330 double y = pl.getY().getValue() * physY;
331 ro = ROI.CreateEllipse(
new ZCT(zo, co, to), x, y, rx * 2, ry * 2);
332 try
333 {
334 ro.Text = pl.getTextValue().getValue();
335 }
336 catch (Exception e)
337 {
338
339 }
340 rois.Add(ro);
341
342 }
343 else if (shape is Label)
344 {
345 Label pl = (Label)shape;
346 int zo = 0, co = 0, to = 0;
347 if (pl.getTheZ() != null)
348 zo = shape.getTheZ().getValue();
349 if (pl.getTheC() != null)
350 co = shape.getTheC().getValue();
351 if (pl.getTheT() != null)
352 to = shape.getTheT().getValue();
353 double x = pl.getX().getValue() * physX;
354 double y = pl.getY().getValue() * physY;
355 ro = ROI.CreateRectangle(
new ZCT(zo, co, to), x, y, physX * 5, physY * 5);
356 ro.type = ROI.Type.Label;
357 try
358 {
359 ro.Text = pl.getTextValue().getValue();
360 }
361 catch (Exception e)
362 {
363
364 }
365 rois.Add(ro);
366 }
367 else if (shape is omero.model.Point)
368 {
369 omero.model.Point po = (omero.model.Point)shape;
370 int zo = 0, co = 0, to = 0;
371 if (po.getTheZ() != null)
372 zo = shape.getTheZ().getValue();
373 if (po.getTheC() != null)
374 co = shape.getTheC().getValue();
375 if (po.getTheT() != null)
376 to = shape.getTheT().getValue();
377 double x, y, w, h;
378 x = po.getX().getValue();
379 y = po.getY().getValue();
380 ro = ROI.CreatePoint(
new ZCT(zo, co, to), x * physX, y * physY);
381 try
382 {
383 ro.Text = po.getTextValue().getValue();
384 }
385 catch (Exception e)
386 {
387
388 }
389 rois.Add(ro);
390 }
391 ro.UpdateBoundingBox();
392 }
393 return rois.ToArray();
394 }
AForge.ZCT ZCT
Definition Bio.cs:62
AForge.PointD PointD
Definition Bio.cs:60
AForge.Rectangle Rectangle
Definition Bio.cs:61
static List<(double X, double Y)> GetPoints(Image image, Shape shape, double physX, double physY)
Definition OMERO.cs:130
static double[] GetImageSize(long imageId)
Gets the physical pixel sizes (SizeX, SizeY, SizeZ) for a given image. Returns a double array {SizeX,...
Definition OMERO.cs:405
static Image GetOMEROImage(long imageId)
Definition OMERO.cs:395