Permalink
Browse files

Add general rasterize class and add method to Regions

  • Loading branch information...
awalter17 committed Nov 30, 2016
1 parent 6567ada commit 08a40087796caaef66a8729e279f1276abaf65fb
@@ -34,14 +34,17 @@
package net.imglib2.roi;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.roi.geometric.RasterizedRegion;
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.Contains;
import net.imglib2.roi.util.IterableRandomAccessibleRegion;
import net.imglib2.roi.util.SamplingIterableInterval;
import net.imglib2.type.BooleanType;
@@ -66,6 +69,26 @@
return IterableRandomAccessibleRegion.create( region );
}
/**
* Rasterizes a region of interest by transforming a
* {@link RealRandomAccessibleRealInterval} into a
* {@link RandomAccessibleInterval}. Since the provided region of interest
* is rasterized by wrapping it as a {@link RandomAccessibleInterval}, it is
* possible for this method to return a {@link RandomAccessibleInterval}
* that never returns {@code true} at any point.
*
* @param region
* {@link RealRandomAccessibleRealInterval} to be rasterized
*
* @return {@link RasterizedRegion} which wraps the source region
*/
public static RandomAccessibleInterval< BoolType > rasterize( final RealRandomAccessibleRealInterval< BoolType > region )
{
if ( region instanceof Contains )
return new RasterizedRegion( region );
return null;
}
public static RealRandomAccessibleRealInterval< BoolType > intersect( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand )
{
return new RealBinaryIntersection( leftOperand, rightOperand );
@@ -0,0 +1,80 @@
/*
* #%L
* ImgLib2: a general-purpose, multidimensional image processing library.
* %%
* Copyright (C) 2009 - 2016 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
* Jean-Yves Tinevez and Michael Zinsmaier.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package net.imglib2.roi.geometric;
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;
import net.imglib2.view.Views;
/**
* Represents a {@link RealRandomAccessibleRealInterval} in integer space, by
* transforming it into a {@link RandomAccessibleInterval}.
*
* @author Alison Walter
*/
public class RasterizedRegion extends AbstractWrappedInterval< RandomAccessibleInterval< BoolType > > implements RandomAccessibleInterval< BoolType >
{
private final RealRandomAccessibleRealInterval< BoolType > region;
public RasterizedRegion( final RealRandomAccessibleRealInterval< BoolType > region )
{
super( Views.interval( Views.raster( region ), Intervals.smallestContainingInterval( region ) ) );
this.region = region;
}
@Override
public RandomAccess< BoolType > randomAccess()
{
return sourceInterval.randomAccess();
}
@Override
public RandomAccess< BoolType > randomAccess( final Interval interval )
{
return sourceInterval.randomAccess();
}
public RealRandomAccessibleRealInterval< BoolType > getRealRegion()
{
return region;
}
}

0 comments on commit 08a4008

Please sign in to comment.