RoiManagerUtil { public static List<Vector3d> pointROICoordinates(final RoiManager manager) { final Roi[] rois = manager.getRoisAsArray(); return Arrays.stream(rois).filter(roi -> roi.getType() == Roi.POINT).map( roi -> { final int z = roi.getZPosition(); return Arrays.stream(roi.getContainedPoints()).distinct().map( p -> new Vector3d(p.x, p.y, z)); }).flatMap(s -> s).distinct().collect(Collectors.toList()); } private  RoiManagerUtil(); static boolean isActiveOnAllSlices(final int sliceNumber); static List<Vector3d> pointROICoordinates(final RoiManager manager);  }
@Test public void testPointRoiCoordinates() { final PointRoi pointRoi = new PointRoi(8, 9); pointRoi.setPosition(13); final RoiManager MOCK_ROI_MANAGER = mock(RoiManager.class); when(MOCK_ROI_MANAGER.getRoisAsArray()).thenReturn(new Roi[] { new Roi(1, 2, 1, 1), pointRoi, new TextRoi(3, 4, "foo") }); final List<Vector3d> points = RoiManagerUtil.pointROICoordinates( MOCK_ROI_MANAGER); assertEquals(1, points.size()); final Vector3d point = points.get(0); assertEquals(pointRoi.getXBase(), point.x, 1e-12); assertEquals(pointRoi.getYBase(), point.y, 1e-12); assertEquals(pointRoi.getPosition(), point.z, 1e-12); }
@Test public void testPointRoiCoordinatesMultiPointRois() { final PointRoi roi = new PointRoi(new int[] { 1, 1, 2 }, new int[] { 0, 0, 0 }, 3); roi.setPosition(1); final PointRoi roi2 = new PointRoi(new int[] { 1, 1 }, new int[] { 0, 0 }, 2); roi2.setPosition(2); final RoiManager MOCK_ROI_MANAGER = mock(RoiManager.class); when(MOCK_ROI_MANAGER.getRoisAsArray()).thenReturn(new Roi[] { roi, roi2 }); final List<Vector3d> result = RoiManagerUtil.pointROICoordinates( MOCK_ROI_MANAGER); assertEquals(3, result.size()); assertEquals(new Vector3d(1, 0, 1), result.get(0)); assertEquals(new Vector3d(2, 0, 1), result.get(1)); assertEquals(new Vector3d(1, 0, 2), result.get(2)); }
@Test(expected = NullPointerException.class) public void testPointRoiCoordinatesThrowsNPEIfRoiManagerNull() { RoiManagerUtil.pointROICoordinates(null); }