Permalink
Browse files

Modify RealBinaryOperators to use RealRandomAccessibleIntervals

This removes the dependency on the Contains interface.
  • Loading branch information...
awalter17 committed Oct 18, 2016
1 parent e560f2b commit 2adc7e38d71fc743481f318f3587bf39484a918d
@@ -5,6 +5,7 @@
import net.imglib2.RealLocalizable;
import net.imglib2.RealPositionable;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.roi.geometric.RealRandomAccessibleRealIntervalContains;
import net.imglib2.roi.util.Contains;
import net.imglib2.roi.util.ContainsRealRandomAccess;
@@ -17,75 +18,63 @@
* @version 1.0.0 Jan 14, 2016
*
*/
public abstract class AbstractRealBinaryOperator extends AbstractRealInterval implements RealRandomAccessibleRealIntervalContains {
public abstract class AbstractRealBinaryOperator extends AbstractRealInterval implements RealRandomAccessibleRealInterval< BoolType > {
protected RealRandomAccessibleRealIntervalContains leftOperand;
protected RealRandomAccessibleRealIntervalContains rightOperand;
protected final RealRandomAccessibleRealInterval< BoolType > leftOperand;
protected final RealRandomAccessibleRealInterval< BoolType > rightOperand;
public AbstractRealBinaryOperator(RealRandomAccessibleRealIntervalContains leftOperand, RealRandomAccessibleRealIntervalContains rightOperand)
public AbstractRealBinaryOperator(RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand)
{
super(leftOperand.numDimensions());
super( leftOperand.numDimensions() );
this.leftOperand = leftOperand;
this.rightOperand = rightOperand;
}
@Override
public RealRandomAccess<BoolType> realRandomAccess() {
return new ContainsRealRandomAccess(this);
}
public abstract RealRandomAccess< BoolType > realRandomAccess();
@Override
public RealRandomAccess<BoolType> realRandomAccess(RealInterval interval) {
public RealRandomAccess< BoolType > realRandomAccess( RealInterval interval ) {
return realRandomAccess();
}
@Override
public abstract boolean contains(RealLocalizable l);
@Override
public Contains<RealLocalizable> copyContains() {
return this;
}
@Override
public double realMin( final int d )
{
return Math.min(leftOperand.realMin(d), rightOperand.realMin(d));
return Math.min( leftOperand.realMin( d ), rightOperand.realMin( d ) );
}
@Override
public void realMin( final double[] realMin )
{
for ( int d = 0; d < n; ++d )
realMin[ d ] = realMin(d);
realMin[ d ] = realMin( d );
}
@Override
public void realMin( final RealPositionable realMin )
{
for ( int d = 0; d < n; ++d )
realMin.setPosition( realMin(d), d );
realMin.setPosition( realMin( d ), d );
}
@Override
public double realMax( final int d )
{
return Math.max(leftOperand.realMax(d), rightOperand.realMax(d));
return Math.max( leftOperand.realMax( d ), rightOperand.realMax( d ) );
}
@Override
public void realMax( final double[] realMax )
{
for ( int d = 0; d < n; ++d )
realMax[ d ] = realMax(d) ;
realMax[ d ] = realMax( d ) ;
}
@Override
public void realMax( final RealPositionable realMax )
{
for ( int d = 0; d < n; ++d )
realMax.setPosition( realMax(d), d );
realMax.setPosition( realMax( d ), d );
}
}
@@ -0,0 +1,82 @@
/*
* #%L
* ImgLib2: a general-purpose, multidimensional image processing library.
* %%
* Copyright (C) 2009 - 2015 Tobias Pietzsch, Stephan Preibisch, Barry DeZonia,
* Stephan Saalfeld, Curtis Rueden, Albert Cardona, Christian Dietz, Jean-Yves
* Tinevez, Johannes Schindelin, Jonathan Hale, Lee Kamentsky, Larry Lindsey, Mark
* Hiner, Michael Zinsmaier, Martin Horn, Grant Harris, Aivar Grislis, John
* Bogovic, Steffen Jaensch, Stefan Helfrich, Jan Funke, Nick Perry, Mark Longair,
* Melissa Linkert and Dimiter Prodanov.
* %%
* 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.operators;
import net.imglib2.RealPoint;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType;
/**
* Abstract base class for {@link RealRandomAccess}ors for combined regions of interest.
*
* @author Alison Walter
*/
public abstract class AbstractRealBinaryOperatorRealRandomAccess extends RealPoint implements RealRandomAccess< BoolType >
{
protected final RealRandomAccess< BoolType > leftOperandRA;
protected final RealRandomAccess< BoolType > rightOperandRA;
protected final BoolType type;
public AbstractRealBinaryOperatorRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand )
{
super( leftOperand.numDimensions() );
this.leftOperandRA = leftOperand.realRandomAccess();
this.rightOperandRA = rightOperand.realRandomAccess();
type = new BoolType();
}
protected AbstractRealBinaryOperatorRealRandomAccess( final AbstractRealBinaryOperatorRealRandomAccess rborra )
{
super( rborra.numDimensions() );
leftOperandRA = rborra.leftOperandRA;
rightOperandRA = rborra.rightOperandRA;
type = rborra.type.copy();
}
@Override
public RealRandomAccess< BoolType > copyRealRandomAccess()
{
return copy();
}
@Override
public abstract BoolType get();
@Override
public abstract RealRandomAccess< BoolType > copy();
}
@@ -1,7 +1,8 @@
package net.imglib2.roi.operators;
import net.imglib2.RealLocalizable;
import net.imglib2.roi.geometric.RealRandomAccessibleRealIntervalContains;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType;
/**
* This class represents a combination of two continuous regions of interest using an XOR-operator.
@@ -12,16 +13,41 @@
*/
public class RealBinaryExclusiveOr extends AbstractRealBinaryOperator {
public RealBinaryExclusiveOr(RealRandomAccessibleRealIntervalContains leftOperand,
RealRandomAccessibleRealIntervalContains rightOperand) {
super(leftOperand, rightOperand);
public RealBinaryExclusiveOr( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand)
{
super( leftOperand, rightOperand );
}
@Override
public boolean contains(RealLocalizable l) {
return
(leftOperand.contains(l) && !rightOperand.contains(l)) ||
(!leftOperand.contains(l) && rightOperand.contains(l));
public RealRandomAccess<BoolType> realRandomAccess() {
return new RealBinaryExclusiveOrRealRandomAccess( leftOperand, rightOperand );
}
private class RealBinaryExclusiveOrRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess {
public RealBinaryExclusiveOrRealRandomAccess( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand )
{
super( leftOperand, rightOperand );
}
private RealBinaryExclusiveOrRealRandomAccess( RealBinaryExclusiveOrRealRandomAccess rbeorra )
{
super( rbeorra );
}
@Override
public BoolType get() {
leftOperandRA.setPosition( this );
rightOperandRA.setPosition( this );
boolean value = ( leftOperandRA.get().get() && !rightOperandRA.get().get() ) || ( !leftOperandRA.get().get() && rightOperandRA.get().get() );
type.set( value );
return type;
}
@Override
public RealBinaryExclusiveOrRealRandomAccess copy() {
return new RealBinaryExclusiveOrRealRandomAccess( this );
}
}
}
@@ -1,7 +1,8 @@
package net.imglib2.roi.operators;
import net.imglib2.RealLocalizable;
import net.imglib2.roi.geometric.RealRandomAccessibleRealIntervalContains;
import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType;
/**
*
* This class represents a combination of two continuous regions of interest using an AND-operator.
@@ -12,16 +13,40 @@
*/
public class RealBinaryIntersection extends AbstractRealBinaryOperator {
public RealBinaryIntersection(RealRandomAccessibleRealIntervalContains leftOperand,
RealRandomAccessibleRealIntervalContains rightOperand) {
super(leftOperand, rightOperand);
public RealBinaryIntersection( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand)
{
super( leftOperand, rightOperand );
}
@Override
public boolean contains(RealLocalizable l) {
return leftOperand.contains(l) && rightOperand.contains(l);
public RealRandomAccess<BoolType> realRandomAccess() {
return new RealBinaryIntersectionRealRandomAccess( leftOperand, rightOperand );
}
private class RealBinaryIntersectionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess {
public RealBinaryIntersectionRealRandomAccess( RealRandomAccessibleRealInterval< BoolType > leftOperand, RealRandomAccessibleRealInterval< BoolType > rightOperand )
{
super( leftOperand, rightOperand );
}
private RealBinaryIntersectionRealRandomAccess( RealBinaryIntersectionRealRandomAccess rbirra )
{
super( rbirra );
}
@Override
public BoolType get() {
leftOperandRA.setPosition( this );
rightOperandRA.setPosition( this );
type.set( leftOperandRA.get().get() && rightOperandRA.get().get() );
return type;
}
@Override
public RealBinaryIntersectionRealRandomAccess copy() {
return new RealBinaryIntersectionRealRandomAccess( this );
}
}
}
Oops, something went wrong.

0 comments on commit 2adc7e3

Please sign in to comment.