Permalink
Browse files

Add generics to RasterizedRegion, change return type of Regions.raster

The generics were added to RasterizedRegion so that getRealRegion can
return the actual type of the region which was rasterized. This could be
done by calling getSource numerous times, but occassionally the
getSource method is not part of the interface which makes the casts more
confusing. Also the generics provide a nice syntax, for example a
rasterized HyperRectangle can now be written as
RasterizedRegion<HyperRectangle>.

The return type of Regions.raster was changed to RasterizedRegion to
take advantage of these nice features.
  • Loading branch information...
awalter17 committed Dec 12, 2016
1 parent 08a4008 commit 1c5b880344c8553d1a5d7d8252aad7cead7e2aba
@@ -82,11 +82,9 @@
*
* @return {@link RasterizedRegion} which wraps the source region
*/
public static RandomAccessibleInterval< BoolType > rasterize( final RealRandomAccessibleRealInterval< BoolType > region )
public static < T extends RealRandomAccessibleRealInterval< BoolType > > RasterizedRegion< T > rasterize( final T region )
{
if ( region instanceof Contains )
return new RasterizedRegion( region );
return null;
return new RasterizedRegion< T >( region );
}
public static RealRandomAccessibleRealInterval< BoolType > intersect( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand )
@@ -37,9 +37,7 @@
import net.imglib2.AbstractWrappedInterval;
import net.imglib2.Interval;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType;
import net.imglib2.util.Intervals;
@@ -51,11 +49,11 @@
*
* @author Alison Walter
*/
public class RasterizedRegion extends AbstractWrappedInterval< RandomAccessibleInterval< BoolType > > implements RandomAccessibleInterval< BoolType >
public class RasterizedRegion< T extends RealRandomAccessibleRealInterval< BoolType > > extends AbstractWrappedInterval< RandomAccessibleInterval< BoolType > > implements RandomAccessibleInterval< BoolType >
{
private final RealRandomAccessibleRealInterval< BoolType > region;
private final T region;
public RasterizedRegion( final RealRandomAccessibleRealInterval< BoolType > region )
public RasterizedRegion( final T region )
{
super( Views.interval( Views.raster( region ), Intervals.smallestContainingInterval( region ) ) );
this.region = region;
@@ -73,7 +71,7 @@ public RasterizedRegion( final RealRandomAccessibleRealInterval< BoolType > regi
return sourceInterval.randomAccess();
}
public RealRandomAccessibleRealInterval< BoolType > getRealRegion()
public T getRealRegion()
{
return region;
}

0 comments on commit 1c5b880

Please sign in to comment.