/**
* A test of a ROI that has no pixel iterator.
*/
@Test
public final void testNonIterableROI() {
final RegionOfInterest roi = new AbstractRegionOfInterest(2) {
private double center_x = 25.0;
private double center_y = 10.0;
public boolean contains(double[] position) {
// Mandelbrot set goes from x = -2.5 to 1, y = -1 to 1
// so we add 2.5, 1 and multiply each by 10.
final double x0 = position[0] * 10 + center_x;
final double y0 = position[1] * 10 + center_y;
double x = x0;
double y = y0;
for (int i=0;i < 100; i++) {
if (x*x + y*y >= 4) return false;
final double xnext = x*x - y*y + x0;
y = 2 * x * y + y0;
x = xnext;
}
return true;
}
public void move(double displacement, int d) {
if (d == 0)
center_x += displacement;
else
center_y += displacement;
}
@Override
protected void getRealExtrema(double[] minima, double[] maxima) {
minima[0] = center_x - 25.0;
minima[1] = center_y - 10.0;
maxima[0] = center_x + 10.0;
maxima[1] = center_y + 10.0;
}};
Overlay o = new AbstractROIOverlay<RegionOfInterest>(context.getContext(), roi) {
/* (non-Javadoc)
* @see imagej.data.overlay.Overlay#move(double[])
*/
public void move(double[] deltas) {
roi.move(deltas);
}
};
Dataset dataset = getDatasetService().create(new long [] { 30, 30 }, "Foo", new AxisType [] { Axes.X, Axes.Y }, 8, true, false);
Display<?> display = getDisplayService().createDisplay(getImageDisplayService().createDataView(dataset));
assertTrue(display instanceof ImageDisplay);
ImageDisplay iDisplay = (ImageDisplay)display;
getOverlayService().addOverlays(iDisplay, Collections.singletonList((Overlay)o));
for (DataView v:iDisplay) {
v.setSelected(true);
}
Img<BitType> mask = OverlayUtils.extractMask(iDisplay);
assertNotNull(mask);
Cursor<BitType> c = mask.cursor();
double [] position = new double [2];
while(c.hasNext()) {
BitType t = c.next();
position[1] = c.getDoublePosition(0);
position[0] = c.getDoublePosition(1);
assertEquals(t.get(), roi.contains(position));
}
}