/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * @param interp ignored * * @return the new ROI */ @Override public ROI transform(AffineTransform at, Interpolation interp) { return transform(at); }
/** * Returns a new instance which is the exclusive OR of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI exclusiveOr(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { return buildROIGeometry(theGeom.getGeometry().symDifference(geom)); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Tests if this ROI contains the given image location. * * @param x location X ordinate * @param y location Y ordinate * * @return {@code true} if the location is within this ROI; * {@code false} otherwise */ @Override public boolean contains(int x, int y) { return contains((double)x, (double)y); }
/** * Setup a ROIGeometry on top of a geometry. * It takes care of removing invalid polygon, opened line strings and so on * @param geometry the input geometry to be used as reference to create a new {@link ROIGeometry} * @return a ROI from the input geometry. */ private ROI buildROIGeometry(Geometry geometry) { // cleanup the geometry, extract only the polygons, set oriented operations might // have returned a mix of points and lines in the resulting geometries final List<Polygon> polygons = new ArrayList<Polygon>(); geometry.apply(new GeometryComponentFilter() { public void filter(Geometry geom) { if (geom instanceof Polygon) { polygons.add((Polygon) geom); } } }); // build a polygon or a multipolygon Geometry geom = null; if (polygons.size() == 0) { geom = geomFactory.createMultiPolygon(new Polygon[0]); } else if (polygons.size() == 1) { geom = polygons.get(0); } else { Polygon[] polygonArray = (Polygon[]) polygons.toArray(new Polygon[polygons.size()]); geom = geomFactory.createMultiPolygon(polygonArray); } return new ROIGeometry(geom, this.useAntialiasing, this.useFixedPrecision, this.hints); }
for (int i=0; i<rois.length; i++){ if (globalRoi == null){ globalRoi = new ROIGeometry(((ROIGeometry)rois[i]).getAsGeometry()); } else { globalRoi = globalRoi.add(rois[i]);
/** * Gets a {@link Geometry} from an input {@link ROI}. * * @param roi the ROI * @return a {@link Geometry} instance from the provided input; * null in case the input roi is neither a geometry, nor a shape. */ private Geometry getGeometry(ROI roi){ if (roi instanceof ROIGeometry){ return ((ROIGeometry) roi).getAsGeometry(); } else if (roi instanceof ROIShape){ final Shape shape = ((ROIShape) roi).getAsShape(); final Geometry geom = ShapeReader.read(shape, 0, geomFactory); geom.apply(Y_INVERSION); return geom; } return null; }
/** * Tests if the given rectangle intersects with this ROI. * * @param rect the rectangle * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(Rectangle2D rect) { setTestRect(rect.getMinX(), rect.getMinY(), rect.getWidth(), rect.getHeight()); return theGeom.intersects(testRect); }
/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * * @return the new ROI */ @Override public ROI transform(AffineTransform at) { Geometry cloned = theGeom.getGeometry().copy(); cloned.apply(new AffineTransformation(at.getScaleX(), at.getShearX(), at.getTranslateX(), at.getShearY(), at.getScaleY(), at.getTranslateY())); if (useFixedPrecision){ Geometry fixed = PRECISE_FACTORY.createGeometry(cloned); Coordinate[] coords = fixed.getCoordinates(); for (Coordinate coord : coords) { Coordinate precise = coord; PRECISION.makePrecise(precise); } cloned = fixed; } return buildROIGeometry(cloned); }
ROI imageBounds = new ROIGeometry(mask); if (footprintManagement){ final ROI footprint = result.getFootprint();
/** * Tests if the given rectangle intersects with this ROI. * * @param rect the rectangle * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(Rectangle rect) { setTestRect(rect.x, rect.y, rect.width, rect.height); return theGeom.intersects(testRect); }
/** * Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation. * * @param roi a {@link Geometry} in model space. * @param mt2d an {@link AffineTransform} that maps from raster to model space. This is already referred to the pixel corner. * @return a {@link ROI} suitable for using with JAI. * @throws ProcessException in case there are problems with ivnerting the provided {@link AffineTransform}. Very unlikely to happen. */ public static ROI prepareROI(Geometry roi, AffineTransform mt2d) throws ProcessException { // transform the geometry to raster space so that we can use it as a ROI source Geometry rasterSpaceGeometry; try { rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse())); } catch (MismatchedDimensionException e) { throw new ProcessException(e); } catch (TransformException e) { throw new ProcessException(e); } catch (NoninvertibleTransformException e) { throw new ProcessException(e); } // simplify the geometry so that it's as precise as the coverage, excess coordinates // just make it slower to determine the point in polygon relationship Geometry simplifiedGeometry = DouglasPeuckerSimplifier.simplify( rasterSpaceGeometry, 1); // build a shape using a fast point in polygon wrapper return new ROIGeometry(simplifiedGeometry); }
/** * Returns a new instance which is the intersection of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to intersect with * @return the intersection as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry intersect = geom.intersection(theGeom.getGeometry()); return buildROIGeometry(intersect); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
-((AffineTransform)baseGridToWorld).getScaleY())); tx2.preConcatenate(AffineTransform.getTranslateInstance(translate.getX(),translate.getY())); granuleLoadingShape = (ROI) granuleROIShape.transform(tx2);
/** * Tests if this ROI contains the given rectangle. * * @param x rectangle origin X ordinate * @param y rectangle origin Y ordinate * @param w rectangle width * @param h rectangle height * * @return {@code true} if the rectangle is within this ROI; * {@code false} otherwise */ @Override public boolean contains(int x, int y, int w, int h) { return contains((double)x, (double)y, (double)w, (double)h); }
/** * Tests if the given rectangle intersects with this ROI. * * @param x rectangle origin X ordinate * @param y rectangle origin Y ordinate * @param w rectangle width * @param h rectangle height * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(int x, int y, int w, int h) { setTestRect(x, y, w, h); return theGeom.intersects(testRect); }
geMapper.setPixelAnchor(PixelInCell.CELL_CORNER); Geometry mapped = JTS.transform(inclusionGeometry, geMapper.createTransform().inverse()); this.granuleROIShape = new ROIGeometry(mapped);
/** * Returns a new instance which is the difference of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI subtract(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry difference = theGeom.getGeometry().difference(geom); return buildROIGeometry(difference); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Tests if this ROI contains the given point. * * @param p the point * * @return {@code true} if the point is within this ROI; * {@code false} otherwise */ @Override public boolean contains(Point p) { return contains(p.getX(), p.getY()); }
/** * Tests if the given rectangle intersects with this ROI. * * @param x rectangle origin X ordinate * @param y rectangle origin Y ordinate * @param w rectangle width * @param h rectangle height * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(double x, double y, double w, double h) { setTestRect(x, y, w, h); return theGeom.intersects(testRect); }
ROI roi = new ROIGeometry(simplifiedGeometry, false);