Permalink
Browse files

Add tests for rasterizing hyper- rectangle/ellipsoid

  • Loading branch information...
awalter17 committed Dec 19, 2016
1 parent 1c5b880 commit 3340fa5b680e91902daf1660bf8f973ba1cb8378
Showing with 98 additions and 1 deletion.
  1. +98 −1 src/test/java/net/imglib2/roi/geometric/GeometricShapeTest.java
@@ -6,18 +6,21 @@
import java.io.IOException;
import net.imglib2.RandomAccess;
import net.imglib2.RealPoint;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.realtransform.AffineGet;
import net.imglib2.realtransform.AffineRealRandomAccessible;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.realtransform.RealViews;
import net.imglib2.roi.Regions;
import net.imglib2.roi.operators.RealBinaryExclusiveOr;
import net.imglib2.roi.operators.RealBinaryIntersection;
import net.imglib2.roi.operators.RealUnaryNot;
import net.imglib2.roi.operators.RealBinarySubtraction;
import net.imglib2.roi.operators.RealBinaryUnion;
import net.imglib2.roi.util.ROIUtils;
import net.imglib2.type.logic.BoolType;
import org.junit.Test;
@@ -453,7 +456,101 @@ public void testIfNotWorksProperly()
assertTrue(reference.compareTo(result) == 0);
}
@Test
public void testRasterizedHyperRectangle()
{
final HyperRectangle hr = new HyperRectangle( new RealPoint( 0, 0 ), new double[]{ 4, 7 });
assertTrue( hr.contains( new RealPoint( 0, 0 ) ) );
assertTrue( hr.contains( new RealPoint( 4, 0 ) ) );
assertTrue( hr.contains( new RealPoint( -4, 0 ) ) );
assertTrue( hr.contains( new RealPoint( 0, 7 ) ) );
assertTrue( hr.contains( new RealPoint( 0, -7 ) ) );
assertTrue( hr.contains( new RealPoint( 3, 6 ) ) );
assertFalse( hr.contains( new RealPoint( 4, 8 ) ) );
assertFalse( hr.contains( new RealPoint( -5, 6 ) ) );
final RasterizedRegion< HyperRectangle > rhr = Regions.rasterize( hr );
final RandomAccess< BoolType > ra = rhr.randomAccess();
ra.setPosition( new int[]{ 0, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 4, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ -4, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 0, 7 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 0, -7 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 3, 6 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 4, 8 } );
assertFalse( ra.get().get() );
ra.setPosition( new int[]{ -5, 6 } );
assertFalse( ra.get().get() );
// Contains all four corners and sides
// 8*14 + 14 + 8 + 1 = 135
assertEquals( 135, ROIUtils.countTrue( rhr ) );
}
@Test
public void testRasterizedHyperEllipsoid()
{
final HyperEllipsoid he = new HyperEllipsoid( new RealPoint( 0, 0 ), new double[]{ 3, 4 } );
assertTrue( he.contains( new RealPoint( 0, 0 ) ) );
assertTrue( he.contains( new RealPoint( 3, 0 ) ) );
assertTrue( he.contains( new RealPoint( -3, 0 ) ) );
assertTrue( he.contains( new RealPoint( 0, 4 ) ) );
assertTrue( he.contains( new RealPoint( 0, -4 ) ) );
assertTrue( he.contains( new RealPoint( 2, 1 ) ) );
assertFalse( he.contains( new RealPoint( 0, 5 ) ) );
assertFalse( he.contains( new RealPoint( 1, 4 ) ) );
final RasterizedRegion< HyperEllipsoid > rhe = Regions.rasterize( he );
final RandomAccess< BoolType > ra = rhe.randomAccess();
ra.setPosition( new int[]{ 0, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 3, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ -3, 0 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 0, 4 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 0, -4 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 2, 1 } );
assertTrue( ra.get().get() );
ra.setPosition( new int[]{ 0, 5 } );
assertFalse( ra.get().get() );
ra.setPosition( new int[]{ 1, 4 } );
assertFalse( ra.get().get() );
assertEquals( rhe.min( 0 ), -3 );
assertEquals( rhe.max( 0 ), 3 );
assertEquals( rhe.min( 1 ), -4 );
assertEquals( rhe.max( 1 ), 4 );
}
public static void main(final String... args) throws IOException {
//new GeometricShapeTest().testHyperEllipsoid();
//new GeometricShapeTest().testHyperCubeWithoutVolume();

0 comments on commit 3340fa5

Please sign in to comment.