Trees | Indices | Help |
|
---|
|
1 # 2 # 3 #------------------------------------------------------------------------------ 4 # Copyright (C) 2006-2009 University of Dundee. All rights reserved. 5 # 6 # 7 # This program is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # This program is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 # GNU General Public License for more details. 15 # 16 # You should have received a copy of the GNU General Public License along 17 # with this program; if not, write to the Free Software Foundation, Inc., 18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 # 20 #------------------------------------------------------------------------------ 21 22 ### 23 # 24 # ROIUtils allows the mapping of omero.model.ROIDataTypesI to python types 25 # and to create ROIDataTypesI from ROIUtil types. 26 # These methods also implement the acceptVisitor method linking to the ROIDrawingCanvas. 27 # 28 # 29 # @author Jean-Marie Burel 30 # <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a> 31 # @author Donald MacDonald 32 # <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a> 33 # @version 3.0 34 # <small> 35 # (<b>Internal version:</b> $Revision: $Date: $) 36 # </small> 37 # @since 3.0-Beta4 38 #/ 39 import omero.clients 40 from omero.model import RoiI 41 from omero.model import EllipseI 42 from omero.model import LineI 43 from omero.model import RectI 44 from omero.model import PointI 45 from omero.model import TextI 46 from omero.model import PolylineI 47 from omero.model import PolygonI 48 from omero.model import PathI 49 from omero.model import MaskI 50 from omero.rtypes import rdouble 51 from omero.rtypes import rstring 52 from omero.rtypes import rint 53 from omero.rtypes import rfloat 54 55 56 ## 57 # abstract, defines the method that call it as abstract. 58 # 59 #61 import inspect 62 caller = inspect.getouterframes(inspect.currentframe())[1][3] 63 raise NotImplementedError(caller + ' must be implemented in subclass')64 65 ## 66 # ShapeSettingsData contains all the display information about the ROI that aggregates it. 67 #69 70 ## 71 # Initialises the default values of the ShapeSettings. 72 # Stroke has default colour of darkGrey 73 # StrokeWidth defaults to 1 74 #154 155 ## 156 # This class stores the ROI Coordinate (Z,T). 157 #76 self.WHITE = 16777215 77 self.BLACK = 0 78 self.GREY = 11184810 79 self.strokeColour = rint(self.GREY) 80 self.strokeWidth = rint(1) 81 self.strokeDashArray = rstring('') 82 self.strokeDashOffset = rint(0) 83 self.strokeLineCap = rstring('') 84 self.strokeLineJoin = rstring('') 85 self.strokeMiterLimit = rint(0) 86 self.fillColour = rint(self.GREY) 87 self.fillRule = rstring('')88 89 ## 90 # Applies the settings in the ShapeSettingsData to the ROITypeI 91 # @param shape the omero.model.ROITypeI that these settings will be applied to 92 #94 shape.setStrokeColor(self.strokeColour); 95 shape.setStrokeWidth(self.strokeWidth); 96 shape.setStrokeDashArray(self.strokeDashArray); 97 shape.setStrokeDashOffset(self.strokeDashOffset); 98 shape.setStrokeLineCap(self.strokeLineCap); 99 shape.setStrokeLineJoin(self.strokeLineJoin); 100 shape.setStrokeMiterLimit(self.strokeMiterLimit); 101 shape.setFillColor(self.fillColour); 102 shape.setFillRule(self.fillRule);103 104 ## 105 # Set the Stroke settings of the ShapeSettings. 106 # @param colour The colour of the stroke. 107 # @param width The stroke width. 108 # 112 113 ### 114 # Set the Fill Settings for the ShapeSettings. 115 # @param colour The fill colour of the shape.117 self.fillColour = rstring(colour);118 119 ## 120 # Get the stroke settings as the tuple (strokeColour, strokeWidth). 121 # @return See above. 122 # 125 126 ## 127 # Get the fill setting as a tuple of (fillColour) 128 # @return See above. 129 #131 return (self.fillColour.getValue());132 133 ## 134 # Get the tuple ((stokeColor, strokeWidth), (fillColour)). 135 # @return see above. 136 # 139 140 ## 141 # Set the current shapeSettings from the ROI roi. 142 # @param roi see above. 143 #145 self.strokeColour = roi.getStrokeColor(); 146 self.strokeWidth = roi.getStrokeWidth(); 147 self.strokeDashArray = roi.getStrokeDashArray(); 148 self.strokeDashOffset = roi.getStrokeDashOffset(); 149 self.strokeLineCap = roi.getStrokeLineCap(); 150 self.strokeLineJoin = roi.getStrokeLineJoin(); 151 self.strokeMiterLimit = roi.getStrokeMiterLimit(); 152 self.fillColour = roi.getFillColor(); 153 self.fillRule = roi.getFillRule();159 160 ## 161 # Initialise the ROICoordinate. 162 # @param z The z-section. 163 # @param t The timepoint. 167 168 ## 169 # Set the (z, t) for the roi using the (z, t) of the ROICoordinate. 170 # @param roi The ROI to set the (z, t) on. 171 # 175 176 ## 177 # Get the (z, t) from the ROI. 178 # @param See above. 179 #183 184 ## 185 # Interface to inherit for accepting ROIDrawing as a visitor. 186 # @param visitor The ROIDrawingCompoent. 187 # 191 192 ## 193 # The base class for all ROIShapeData objects. 194 #196 197 ## 198 # Constructor sets up the coord, shapeSettings and ROI objects. 199 #297 298 ## 299 # The EllispeData class contains all the manipulation and create of EllipseI 300 # types. 301 # It also accepts the ROIDrawingUtils visitor for drawing ellipses. 302 #201 self.coord = ROICoordinate(); 202 self.shapeSettings = ShapeSettingsData(); 203 self.ROI = None;204 205 ## 206 # Set the coord of the class to coord. 207 # @param See above. 208 # 211 212 ## 213 # Set the ROICoordinate of the roi. 214 # @param roi See above. 215 #217 self.coord.setROICoord(roi);218 219 ## 220 # Set the Geometry of the roi from the geometry in ShapeData. 221 # @param roi See above. 222 #224 abstract();225 226 ## 227 # Set the Settings of the ShapeDate form the settings object. 228 # @param settings See above. 229 #231 self.shapeSettings = settings;232 233 ## 234 # Set the Settings of the roi from the setting in ShapeData. 235 # @param roi See above. 236 #238 self.shapeSettings.setROIShapeSettings(roi);239 240 ## 241 # Accept visitor. 242 # @param visitor See above. 243 #245 abstract();246 247 ## 248 # Create the base type of ROI for this shape. 249 #251 abstract();252 253 ## 254 # Get the roi from the ShapeData. If the roi already exists return it. 255 # Otherwise create it from the ShapeData and return it. 256 # @return See above. 257 #259 if(self.roi != None): 260 return self.roi; 261 self.roi = self.createBaseType(); 262 self.setROICoord(self.roi); 263 self.setROIGeometry(self.roi); 264 self.setROIShapeSettings(self.roi); 265 return self.roi;266 267 ## 268 # Set the shape settings object from the roi. 269 # @param roi see above. 270 #272 self.shapeSettings.getShapeSettingsFromROI(roi);273 274 ## 275 # Set the ROICoordinate from the roi. 276 # @param roi See above. 277 #279 self.coord.setCoordFromROI(roi);280 281 ## 282 # Set the Geometr from the roi. 283 # @param roi See above. 284 #286 abstract();287 288 ## 289 # Get all settings from the roi, Geomerty, Shapesettins, ROICoordinate. 290 # @param roi See above. 291 #293 self.roi = roi; 294 self.getShapeSettingsFromROI(roi); 295 self.getCoordFromROI(roi); 296 self.getGeometryFromROI(roi);304 305 ## 306 # Constructor for EllipseData object. 307 # @param roicoord The ROICoordinate of the object (default: 0,0) 308 # @param cx The centre x coordinate of the ellipse. 309 # @param cy The centre y coordinate of the ellipse. 310 # @param rx The major axis of the ellipse. 311 # @param ry The minor axis of the ellipse.351 352 ## 353 # The RectangleData class contains all the manipulation and create of RectI 354 # types. 355 # It also accepts the ROIDrawingUtils visitor for drawing rectangles. 356 #313 ShapeData.__init__(self); 314 self.cx = rdouble(cx); 315 self.cy = rdouble(cy); 316 self.rx = rdouble(rx); 317 self.ry = rdouble(ry); 318 self.setCoord(roicoord);319 320 ## 321 # overridden, @See ShapeData#setROIGeometry 322 #324 ellipse.setTheZ(self.coord.theZ); 325 ellipse.setTheT(self.coord.theZ); 326 ellipse.setCx(self.cx); 327 ellipse.setCy(self.cy); 328 ellipse.setRx(self.rx); 329 ellipse.setRy(self.ry);330 331 ## 332 # overridden, @See ShapeData#getGeometryFromROI 333 #335 self.cx = roi.getCx(); 336 self.cy = roi.getCy(); 337 self.rx = roi.getRx(); 338 self.ry = roi.getRy();339 340 ## 341 # overridden, @See ShapeData#createBaseType 342 # 345 346 ## 347 # overridden, @See ShapeData#acceptVisitor 348 #350 visitor.drawEllipse(self.cx.getValue(), self.cy.getValue(), self.rx.getValue(), self.ry.getValue(), self.shapeSettings.getSettings());358 359 ## 360 # Constructor for RectangleData object. 361 # @param roicoord The ROICoordinate of the object (default: 0,0) 362 # @param x The top left x - coordinate of the shape. 363 # @param y The top left y - coordinate of the shape. 364 # @param width The width of the shape. 365 # @param height The height of the shape.405 ## 406 # The LineData class contains all the manipulation and create of LineI 407 # types. 408 # It also accepts the ROIDrawingUtils visitor for drawing lines. 409 #367 ShapeData.__init__(self); 368 self.x = rdouble(x); 369 self.y = rdouble(y); 370 self.width = rdouble(width); 371 self.height = rdouble(height); 372 self.setCoord(roicoord);373 374 ## 375 # overridden, @See ShapeData#setGeometry 376 #378 rectangle.setTheZ(self.coord.theZ); 379 rectangle.setTheT(self.coord.theZ); 380 rectangle.setX(self.x); 381 rectangle.setY(self.y); 382 rectangle.setWidth(self.width); 383 rectangle.setHeight(self.height);384 385 ## 386 # overridden, @See ShapeData#getGeometryFromROI 387 #389 self.x = roi.getX(); 390 self.y = roi.getY(); 391 self.width = roi.getWidth(); 392 self.height = roi.getHeight();393 394 ## 395 # overridden, @See ShapeData#createBaseType 396 # 399 400 ## 401 # overridden, @See ShapeData#acceptVisitor 402 #404 visitor.drawRectangle(self.x, self.y, self.width, self.height, self.shapeSettings.getSettings());411 412 ## 413 # Constructor for LineData object. 414 # @param roicoord The ROICoordinate of the object (default: 0,0) 415 # @param x1 The first x coordinate of the shape. 416 # @param y1 The first y coordinate of the shape. 417 # @param x2 The second x coordinate of the shape. 418 # @param y2 The second y coordinate of the shape.458 459 ## 460 # The MaskData class contains all the manipulation and create of MaskI 461 # types. 462 # It also accepts the ROIDrawingUtils visitor for drawing masks. 463 #420 ShapeData.__init__(self); 421 self.x1 = rdouble(x1); 422 self.y1 = rdouble(y1); 423 self.x2 = rdouble(x2); 424 self.y2 = rdouble(y2); 425 self.setCoord(roicoord);426 427 ## 428 # overridden, @See ShapeData#setGeometry 429 #431 line.setTheZ(self.coord.theZ); 432 line.setTheT(self.coord.theZ); 433 line.setX1(self.x1); 434 line.setY1(self.y1); 435 line.setX2(self.x2); 436 line.setY2(self.y2);437 438 ## 439 # overridden, @See ShapeData#getGeometryFromROI 440 #442 self.x1 = roi.getX1(); 443 self.y1 = roi.getY1(); 444 self.x2 = roi.getX2(); 445 self.y2 = roi.getY2();446 447 ## 448 # overridden, @See ShapeData#createBaseType 449 # 452 453 ## 454 # overridden, @See ShapeData#acceptVisitor 455 #465 466 ## 467 # Constructor for MaskData object. 468 # @param roicoord The ROICoordinate of the object (default: 0,0) 469 # @param bytes The mask data. 470 # @param x The top left x - coordinate of the shape. 471 # @param y The top left y - coordinate of the shape. 472 # @param width The width of the shape. 473 # @param height The height of the shape.516 517 ## 518 # The PointData class contains all the manipulation and create of PointI 519 # types. 520 # It also accepts the ROIDrawingUtils visitor for drawing points. 521 #474 - def __init__(self, roicoord = ROICoordinate(), bytes = None, x = 0, y = 0, width = 0, height = 0):475 ShapeData.__init__(self); 476 self.x = rdouble(x); 477 self.y = rdouble(y); 478 self.width = rdouble(width); 479 self.height = rdouble(height); 480 self.bytesdata = bytes; 481 self.setCoord(roicoord);482 483 ## 484 # overridden, @See ShapeData#setGeometry 485 #487 mask.setTheZ(self.coord.theZ); 488 mask.setTheT(self.coord.theZ); 489 mask.setX(self.x); 490 mask.setY(self.y); 491 mask.setWidth(self.width); 492 mask.setHeight(self.height); 493 mask.setBytes(self.bytedata);494 495 ## 496 # overridden, @See ShapeData#getGeometryFromROI 497 #499 self.x = roi.getX(); 500 self.y = roi.getY(); 501 self.width = roi.getWidth(); 502 self.height = roi.getHeight(); 503 self.bytesdata = roi.getBytes();504 505 ## 506 # overridden, @See ShapeData#createBaseType 507 # 510 511 ## 512 # overridden, @See ShapeData#acceptVisitor 513 #523 524 ## 525 # Constructor for PointData object. 526 # @param roicoord The ROICoordinate of the object (default: 0,0) 527 # @param x The x coordinate of the shape. 528 # @param y The y coordinate of the shape.562 563 ## 564 # The PolygonData class contains all the manipulation and create of PolygonI 565 # types. 566 # It also accepts the ROIDrawingUtils visitor for drawing polygons. 567 #530 ShapeData.__init__(self); 531 self.x = rdouble(x); 532 self.y = rdouble(y); 533 self.setCoord(roicoord);534 535 ## 536 # overridden, @See ShapeData#setGeometry 537 #539 point.setTheZ(self.coord.theZ); 540 point.setTheT(self.coord.theZ); 541 point.setX(self.x); 542 point.setY(self.y);543 544 ## 545 # overridden, @See ShapeData#getGeometryFromROI 546 # 550 551 ## 552 # overridden, @See ShapeData#createBaseType 553 # 556 557 ## 558 # overridden, @See ShapeData#acceptVisitor 559 #561 visitor.drawEllipse(self.x.getValue(), self.y.getValue(), 3, 3, self.shapeSettings.getSettings());569 570 ## 571 # Constructor for PolygonData object. 572 # @param roicoord The ROICoordinate of the object (default: 0,0) 573 # @param pointList The list of points that make up the polygon, as pairs [x1, y1, x2, y2 ..].630 631 ## 632 # The PolylineData class contains all the manipulation and create of PolylineI 633 # types. 634 # It also accepts the ROIDrawingUtils visitor for drawing polylines. 635 #575 ShapeData.__init__(self); 576 self.points = rstring(self.listToString(pointsList)); 577 self.setCoord(roicoord);578 579 ## 580 # overridden, @See ShapeData#setGeometry 581 #583 polygon.setTheZ(self.coord.theZ); 584 polygon.setTheT(self.coord.theZ); 585 polygon.setPoints(self.points);586 587 ## 588 # overridden, @See ShapeData#getGeometryFromROI 589 #591 self.points = roi.getPoints();592 593 ## 594 # Convert a pointsList[x1,y1,x2,y2..] to a string. 595 # @param pointsList The list of points to convert. 596 # @return The pointsList converted to a string.598 string = ''; 599 cnt = 0; 600 for element in pointsList: 601 if(cnt!=0): 602 string = string + ','; 603 cnt += 1; 604 string = string + str(element); 605 return string;606 607 ## 608 # Convert a string of points to a tuple list [(x1,y1),(x2,y2)..]. 609 # @param pointString The string to convert. 610 # @return The tuple list converted from a string.612 elements = []; 613 list = pointString.split(','); 614 numTokens = len(list); 615 for tokenPair in range(0,numTokens/2): 616 elements.append((int(list[tokenPair*2]), int(list[tokenPair*2+1]))); 617 return elements;618 619 ## 620 # overridden, @See ShapeData#createBaseType 621 # 624 625 ## 626 # overridden, @See ShapeData#acceptVisitor 627 #629 visitor.drawPolygon(self.stringToTupleList(self.points.getValue()), self.shapeSettings.getSettings());637 638 ## 639 # Constructor for PolylineData object. 640 # @param roicoord The ROICoordinate of the object (default: 0,0) 641 # @param pointList The list of points that make up the polygon, as pairs [x1, y1, x2, y2 ..].698643 ShapeData.__init__(self); 644 self.points = rstring(self.listToString(pointsList)); 645 self.setCoord(roicoord);646 647 ## 648 # overridden, @See ShapeData#setGeometry 649 #651 point.setTheZ(self.coord.theZ); 652 point.setTheT(self.coord.theZ); 653 point.setPoints(self.points);654 655 ## 656 # overridden, @See ShapeData#getGeometryFromROI 657 #659 self.points = roi.getPoints();660 661 ## 662 # Convert a pointsList[x1,y1,x2,y2..] to a string. 663 # @param pointsList The list of points to convert. 664 # @return The pointsList converted to a string.666 string = ''; 667 cnt = 0; 668 for element in pointsList: 669 if(cnt > 0): 670 string = string + ','; 671 string = string + str(element); 672 cnt+=1; 673 return string;674 675 ## 676 # Convert a string of points to a tuple list [(x1,y1),(x2,y2)..]. 677 # @param pointString The string to convert. 678 # @return The tuple list converted from a string.680 elements = []; 681 list = pointString.split(','); 682 numTokens = len(list); 683 for tokenPair in range(0,numTokens/2): 684 elements.append((int(list[tokenPair*2]), int(list[tokenPair*2+1]))); 685 return elements;686 687 ## 688 # overridden, @See ShapeData#createBaseType 689 # 692 693 ## 694 # overridden, @See ShapeData#acceptVisitor 695 #697 visitor.drawPolyline(self.stringToTupleList(self.points.getValue()), self.shapeSettings.getSettings());
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Oct 18 13:29:20 2011 | http://epydoc.sourceforge.net |