Skip to content

Commit

Permalink
Test rasterize method with combined regions
Browse files Browse the repository at this point in the history
  • Loading branch information
awalter17 committed Jan 27, 2017
1 parent 3340fa5 commit a8712f0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/java/net/imglib2/roi/geometric/GeometricShapeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.IOException;

import net.imglib2.Cursor;
import net.imglib2.RandomAccess;
import net.imglib2.RealPoint;
import net.imglib2.RealRandomAccess;
Expand All @@ -14,6 +15,7 @@
import net.imglib2.realtransform.AffineRealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.realtransform.RealViews;
import net.imglib2.roi.IterableRegion;
import net.imglib2.roi.Regions;
import net.imglib2.roi.operators.RealBinaryExclusiveOr;
import net.imglib2.roi.operators.RealBinaryIntersection;
Expand Down Expand Up @@ -551,6 +553,41 @@ public void testRasterizedHyperEllipsoid()
assertEquals( rhe.max( 1 ), 4 );
}

@Test
public void testCombineRaster()
{
final HyperRectangle hc0 = GeomRegions.hyperRectangle( new RealPoint( new double[] { 10, 10 } ), new double[] { 5, 8 } );
final HyperRectangle hc1 = GeomRegions.hyperRectangle( new RealPoint( new double[] { 5, 5 } ), new double[] { 10, 2 } );
final HyperRectangle hc2 = GeomRegions.hyperRectangle( new RealPoint( new double[] { 20, 10 } ), new double[] { 9, 4 } );

final RealRandomAccessibleRealInterval< BoolType > combine = Regions.intersect( hc0, Regions.intersect( hc1, hc2 ) );

final RasterizedRegion< RealRandomAccessibleRealInterval< BoolType > > rcombine = Regions.rasterize( combine );
final RandomAccess< BoolType > rra = rcombine.randomAccess();

rra.setPosition( new int[] { 13, 6 } );
assertTrue( rra.get().get() );

rra.setPosition( new int[] { -1, 4 } );
assertFalse( rra.get().get() );
rra.setPosition( new int[] { 14, 10 } );
assertFalse( rra.get().get() );
rra.setPosition( new int[] { 20, 8 } );
assertFalse( rra.get().get() );

final IterableRegion< BoolType > itrCombine = Regions.iterable( rcombine );
final Cursor< Void > c = itrCombine.cursor();

int s = 0;
while( c.hasNext() )
{
c.next();
s++;
}

assertTrue( s == 10 ); // This is true because a hyperRectangle contains all boundary points
}

public static void main(final String... args) throws IOException {
//new GeometricShapeTest().testHyperEllipsoid();
//new GeometricShapeTest().testHyperCubeWithoutVolume();
Expand Down

0 comments on commit a8712f0

Please sign in to comment.