} else { rectList = roi.getAsRectangleList( bounds.x, bounds.y, bounds.width, bounds.height);
@Test public void testRectangleListSimple() throws ParseException { ROI leftRight = createLeftRightROIGeometry(); // try with an area larger than the ROI LinkedList rectangles = leftRight.getAsRectangleList(-50, -50, 500, 500); assertSingleLeftRectangle(rectangles, 0, 0, 128, 256); // just as bit as the ROI rectangles = leftRight.getAsRectangleList(0, 0, 256, 256); assertSingleLeftRectangle(rectangles, 0, 0, 128, 256); // a subset, checks if intersection actually works rectangles = leftRight.getAsRectangleList(64, 64, 64, 64); assertSingleLeftRectangle(rectangles, 64, 64, 64, 64); // fully outside rectangles = leftRight.getAsRectangleList(130, 0, 64, 64); assertNull(rectangles); }
} else { rectList = roi.getAsRectangleList( bounds.x, bounds.y, bounds.width, bounds.height);
@Override public LinkedList getAsRectangleList(int x, int y, int width, int height) { Rectangle rect = new Rectangle(x, y, width, height); if (!intersects(rect)) { // no overlap return null; } else if (theGeom.getGeometry().isRectangle()) { // simple case, the geometry is a rectangle to start with Envelope env = theGeom.getGeometry().getEnvelopeInternal(); Envelope intersection = env.intersection(new Envelope(x, x + width, y, y + width)); int rx = (int) Math.round(intersection.getMinX()); int ry = (int) Math.round(intersection.getMinY()); int rw = (int) Math.round(intersection.getMaxX() - rx); int rh = (int) Math.round(intersection.getMaxY() - ry); LinkedList result = new LinkedList(); result.add(new Rectangle(rx, ry, rw, rh)); return result; } else { // we cannot force the base class to use our image, but // we can create a ROI around it ROI roiImage = new ROI(getAsImage()); return roiImage.getAsRectangleList(x, y, width, height); } }
@Override public LinkedList getAsRectangleList(int x, int y, int width, int height) { Rectangle rect = new Rectangle(x, y, width, height); if (!intersects(rect)) { // no overlap return null; } else if (theGeom.getGeometry().isRectangle()) { // simple case, the geometry is a rectangle to start with Envelope env = theGeom.getGeometry().getEnvelopeInternal(); Envelope intersection = env.intersection(new Envelope(x, x + width, y, y + width)); int rx = (int) Math.round(intersection.getMinX()); int ry = (int) Math.round(intersection.getMinY()); int rw = (int) Math.round(intersection.getMaxX() - rx); int rh = (int) Math.round(intersection.getMaxY() - ry); LinkedList result = new LinkedList(); result.add(new Rectangle(rx, ry, rw, rh)); return result; } else { // we cannot force the base class to use our image, but // we can create a ROI around it ROI roiImage = new ROI(getAsImage()); return roiImage.getAsRectangleList(x, y, width, height); } }
@Test public void testRectangleListSimpleReduction() throws IOException, ParseException { // create a simple, but not rectangular, shape, that should result in only // two rectangles ROIGeometry leftRight = createLeftRightROIGeometry(); ROIGeometry topRight = createTopBottomROIGeometry(); ROI threeQuarters = leftRight.add(topRight); LinkedList rectangles = threeQuarters.getAsRectangleList(0, 0, 256, 256); assertEquals(2, rectangles.size()); Rectangle r1 = (Rectangle) rectangles.get(0); assertRectangle(0, 0, 256, 128, r1); Rectangle r2 = (Rectangle) rectangles.get(1); assertRectangle(0, 128, 128, 128, r2); }
LinkedList rectangles = bowTie.getAsRectangleList(-50, -50, 500, 500); assertEquals(254, rectangles.size()); int expectedWidth = 1;