ROIGeometry extends ROI { @Override public ROI add(ROI roi) { try { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry union = geom.union(theGeom.getGeometry()); return buildROIGeometry(union); } } catch(TopologyException e) { if(LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Failed to perform operation using geometries, falling back on raster path", e); } } return super.add(roi); } ROIGeometry(Geometry geom);  ROIGeometry(Rectangle rect);  ROIGeometry(Geometry geom, final boolean useFixedPrecision);  ROIGeometry(Geometry geom, final boolean antiAliasing, final boolean useFixedPrecision);  ROIGeometry(Geometry geom, final RenderingHints hints);  ROIGeometry(Geometry geom, final boolean antiAliasing, 
            final boolean useFixedPrecision, final RenderingHints hints); @Override ROI add(ROI roi); @Override boolean contains(Point p); @Override boolean contains(Point2D p); @Override boolean contains(int x, int y); @Override boolean contains(double x, double y); @Override boolean contains(Rectangle rect); @Override boolean contains(Rectangle2D rect); @Override boolean contains(int x, int y, int w, int h); @Override boolean contains(double x, double y, double w, double h); @Override ROI exclusiveOr(ROI roi); @Override int[][] getAsBitmask(int x, int y, int width, int height, int[][] mask); @Override PlanarImage getAsImage(); @Override LinkedList getAsRectangleList(int x, int y, int width, int height); @Override Shape getAsShape(); Geometry getAsGeometry(); @Override Rectangle getBounds(); @Override Rectangle2D getBounds2D(); @Override int getThreshold(); @Override ROI intersect(ROI roi); @Override boolean intersects(Rectangle rect); @Override boolean intersects(Rectangle2D rect); @Override boolean intersects(int x, int y, int w, int h); @Override boolean intersects(double x, double y, double w, double h); @Override ROI performImageOp(RenderedImageFactory RIF, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints); @Override ROI performImageOp(String name, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints); @Override void setThreshold(int threshold); @Override ROI subtract(ROI roi); @Override ROI transform(AffineTransform at, Interpolation interp); @Override ROI transform(AffineTransform at); @Override String toString(); static final boolean DEFAULT_ROIGEOMETRY_ANTIALISING; static final boolean DEFAULT_ROIGEOMETRY_USEFIXEDPRECISION; }
@Test public void testRotatedRectangleUnion() throws Exception { if (isOSX) { System.out.println("skipping testRotatedRectangleUnion on OSX"); } else { Polygon polygon1 = (Polygon) new WKTReader().read("POLYGON((20 0, 50 -30, 30 -50, 0 -20, 20 0))"); Polygon polygon2 = (Polygon) new WKTReader().read("POLYGON((60 -40, 80 -20, 40 20, 20 0, 60 -40))"); ROIGeometry geom1 = new ROIGeometry(polygon1); ROIShape shape1 = getEquivalentROIShape(geom1); ROIGeometry geom2 = new ROIGeometry(polygon2); ROIShape shape2 = getEquivalentROIShape(geom2); final ROI geomUnion = geom1.add(geom2); final ROI shapeUnion = shape1.add(shape2); assertROIEquivalent(geomUnion, shapeUnion, "RotatedUnion"); } }
@Test public void testUnionFractional() throws Exception{ final String geom1 = "POLYGON ((256.0156254550953 384.00000013906043, 384.00000082678343 384.00000013906043, 384.00000082678343 256.00000005685433, 256.0000004550675 256.00000005685433, 256.0000004550675 384.00000013906043, 256.0156254550953 384.00000013906043))"; final String geom2 = "POLYGON ((384.0156256825708 128.00000008217478, 512.0000010543083 128.00000008217478, 512.0000010543083 -0.0000000000291038, 384.00000068254303 -0.0000000000291038, 384.00000068254303 128.00000008217478, 384.0156256825708 128.00000008217478))"; final WKTReader wktReader = new WKTReader(); final Geometry geometry1 = wktReader.read(geom1); final Geometry geometry2 = wktReader.read(geom2); final ROIGeometry roiGeom1 = new ROIGeometry(geometry1); final ROIGeometry roiGeom2 = new ROIGeometry(geometry2); final ROI roiGeometryUnion = roiGeom1.add(roiGeom2); final ROIShape roiShape1 = getEquivalentROIShape(roiGeom1); final ROIShape roiShape2 = getEquivalentROIShape(roiGeom2); final ROI roiShapeUnion = roiShape1.add(roiShape2); assertROIEquivalent(roiGeometryUnion, roiShapeUnion, "Union"); }
@Test public void testUnionTransformedFractional() throws Exception { if (isOSX) { System.out.println("skipping testUnionTransformedFractional on OSX"); } else { final String geom1 = "POLYGON ((256.0156254550953 384.00000013906043, 384.00000082678343 384.00000013906043, 384.00000082678343 256.00000005685433, 256.0000004550675 256.00000005685433, 256.0000004550675 384.00000013906043, 256.0156254550953 384.00000013906043))"; final String geom2 = "POLYGON ((384.0156256825708 128.00000008217478, 512.0000010543083 128.00000008217478, 512.0000010543083 -0.0000000000291038, 384.00000068254303 -0.0000000000291038, 384.00000068254303 128.00000008217478, 384.0156256825708 128.00000008217478))"; final WKTReader wktReader = new WKTReader(); final Geometry geometry1 = wktReader.read(geom1); final Geometry geometry2 = wktReader.read(geom2); geometry1.apply(new AffineTransformation(1.1, 1.1, 0, 0, 1.1, 0)); geometry2.apply(new AffineTransformation(0, 1.1, 0, 1.1, 0, 0)); final ROIGeometry roiGeom1 = new ROIGeometry(geometry1); final ROIGeometry roiGeom2 = new ROIGeometry(geometry2); final ROI roiGeometryUnion = roiGeom1.add(roiGeom2); final ROIShape roiShape1 = getEquivalentROIShape(roiGeom1); final ROIShape roiShape2 = getEquivalentROIShape(roiGeom2); final ROI roiShapeUnion = roiShape1.add(roiShape2); assertROIEquivalent(roiGeometryUnion, roiShapeUnion, "Union"); } }