Skip to content

Commit

Permalink
Update RealOperators to use generics
Browse files Browse the repository at this point in the history
This allows the operator classes to be used for BitType or BoolType.
  • Loading branch information
awalter17 committed Feb 1, 2017
1 parent 9323653 commit 8ee318b
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 76 deletions.
Expand Up @@ -38,7 +38,7 @@
import net.imglib2.RealPositionable; import net.imglib2.RealPositionable;
import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.BooleanType;


/** /**
* This is an abstract class as base for all binary operators which allow * This is an abstract class as base for all binary operators which allow
Expand All @@ -50,24 +50,24 @@
* @version 1.0.0 Jan 14, 2016 * @version 1.0.0 Jan 14, 2016
* *
*/ */
public abstract class AbstractRealBinaryOperator extends AbstractRealInterval implements RealBinaryOperator public abstract class AbstractRealBinaryOperator< B extends BooleanType< B > > extends AbstractRealInterval implements RealBinaryOperator< B >
{ {
protected final RealRandomAccessibleRealInterval< BoolType > leftOperand; protected final RealRandomAccessibleRealInterval< B > leftOperand;


protected final RealRandomAccessibleRealInterval< BoolType > rightOperand; protected final RealRandomAccessibleRealInterval< B > rightOperand;


public AbstractRealBinaryOperator( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public AbstractRealBinaryOperator( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand.numDimensions() ); super( leftOperand.numDimensions() );
this.leftOperand = leftOperand; this.leftOperand = leftOperand;
this.rightOperand = rightOperand; this.rightOperand = rightOperand;
} }


@Override @Override
public abstract RealRandomAccess< BoolType > realRandomAccess(); public abstract RealRandomAccess< B > realRandomAccess();


@Override @Override
public RealRandomAccess< BoolType > realRandomAccess( final RealInterval interval ) public RealRandomAccess< B > realRandomAccess( final RealInterval interval )
{ {
return realRandomAccess(); return realRandomAccess();
} }
Expand Down Expand Up @@ -113,13 +113,13 @@ public void realMax( final RealPositionable realMax )
} }


@Override @Override
public RealRandomAccessibleRealInterval< BoolType > getA() public RealRandomAccessibleRealInterval< B > getA()
{ {
return leftOperand; return leftOperand;
} }


@Override @Override
public RealRandomAccessibleRealInterval< BoolType > getB() public RealRandomAccessibleRealInterval< B > getB()
{ {
return rightOperand; return rightOperand;
} }
Expand Down
Expand Up @@ -36,6 +36,7 @@
import net.imglib2.RealPoint; import net.imglib2.RealPoint;
import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.BooleanType;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.logic.BoolType;
import net.imglib2.util.Util; import net.imglib2.util.Util;


Expand All @@ -45,23 +46,23 @@
* *
* @author Alison Walter * @author Alison Walter
*/ */
public abstract class AbstractRealBinaryOperatorRealRandomAccess extends RealPoint implements RealBinaryOperatorRealRandomAccess public abstract class AbstractRealBinaryOperatorRealRandomAccess< B extends BooleanType< B > > extends RealPoint implements RealBinaryOperatorRealRandomAccess< B >
{ {
private final RealRandomAccess< BoolType > leftOperandRA; private final RealRandomAccess< B > leftOperandRA;


private final RealRandomAccess< BoolType > rightOperandRA; private final RealRandomAccess< B > rightOperandRA;


protected final BoolType type; protected final B type;


public AbstractRealBinaryOperatorRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public AbstractRealBinaryOperatorRealRandomAccess( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand.numDimensions() ); super( leftOperand.numDimensions() );
this.leftOperandRA = leftOperand.realRandomAccess(); this.leftOperandRA = leftOperand.realRandomAccess();
this.rightOperandRA = rightOperand.realRandomAccess(); this.rightOperandRA = rightOperand.realRandomAccess();
type = new BoolType(); type = Util.getTypeFromRealInterval( leftOperand ).copy();
} }


protected AbstractRealBinaryOperatorRealRandomAccess( final RealBinaryOperatorRealRandomAccess rborra ) protected AbstractRealBinaryOperatorRealRandomAccess( final RealBinaryOperatorRealRandomAccess< B > rborra )
{ {
super( rborra.numDimensions() ); super( rborra.numDimensions() );
leftOperandRA = rborra.getLeftOperandRealRandomAccess(); leftOperandRA = rborra.getLeftOperandRealRandomAccess();
Expand All @@ -70,27 +71,27 @@ protected AbstractRealBinaryOperatorRealRandomAccess( final RealBinaryOperatorRe
} }


@Override @Override
public RealRandomAccess< BoolType > getLeftOperandRealRandomAccess() public RealRandomAccess< B > getLeftOperandRealRandomAccess()
{ {
return leftOperandRA; return leftOperandRA;
} }


@Override @Override
public RealRandomAccess< BoolType > getRightOperandRealRandomAccess() public RealRandomAccess< B > getRightOperandRealRandomAccess()
{ {
return rightOperandRA; return rightOperandRA;
} }


@Override @Override
public RealRandomAccess< BoolType > copyRealRandomAccess() public RealRandomAccess< B > copyRealRandomAccess()
{ {
return copy(); return copy();
} }


@Override @Override
public abstract BoolType get(); public abstract B get();




@Override @Override
public abstract RealRandomAccess< BoolType > copy(); public abstract RealRandomAccess< B > copy();
} }
Expand Up @@ -35,6 +35,7 @@


import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.BooleanType;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.logic.BoolType;


/** /**
Expand All @@ -46,26 +47,26 @@
* @version 1.0.0 Jan 14, 2016 * @version 1.0.0 Jan 14, 2016
* *
*/ */
public class RealBinaryExclusiveOr extends AbstractRealBinaryOperator public class RealBinaryExclusiveOr< B extends BooleanType< B > > extends AbstractRealBinaryOperator< B >
{ {
public RealBinaryExclusiveOr( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryExclusiveOr( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
} }


@Override @Override
public RealRandomAccess< BoolType > realRandomAccess() public RealRandomAccess< B > realRandomAccess()
{ {
return new RealBinaryExclusiveOrRealRandomAccess( leftOperand, rightOperand ); return new RealBinaryExclusiveOrRealRandomAccess( leftOperand, rightOperand );
} }


private class RealBinaryExclusiveOrRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess private class RealBinaryExclusiveOrRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess< B >
{ {
private final RealRandomAccess< BoolType > leftRRA; private final RealRandomAccess< B > leftRRA;


private final RealRandomAccess< BoolType > rightRRA; private final RealRandomAccess< B > rightRRA;


public RealBinaryExclusiveOrRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryExclusiveOrRealRandomAccess( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
leftRRA = getLeftOperandRealRandomAccess(); leftRRA = getLeftOperandRealRandomAccess();
Expand All @@ -80,7 +81,7 @@ private RealBinaryExclusiveOrRealRandomAccess( final RealBinaryExclusiveOrRealRa
} }


@Override @Override
public BoolType get() public B get()
{ {
leftRRA.setPosition( this ); leftRRA.setPosition( this );
rightRRA.setPosition( this ); rightRRA.setPosition( this );
Expand Down
Expand Up @@ -35,6 +35,7 @@


import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.BooleanType;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.logic.BoolType;


/** /**
Expand All @@ -47,26 +48,26 @@
* @version 1.0.0 Jan 14, 2016 * @version 1.0.0 Jan 14, 2016
* *
*/ */
public class RealBinaryIntersection extends AbstractRealBinaryOperator public class RealBinaryIntersection< B extends BooleanType< B > > extends AbstractRealBinaryOperator< B >
{ {
public RealBinaryIntersection( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryIntersection( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
} }


@Override @Override
public RealRandomAccess< BoolType > realRandomAccess() public RealRandomAccess< B > realRandomAccess()
{ {
return new RealBinaryIntersectionRealRandomAccess( leftOperand, rightOperand ); return new RealBinaryIntersectionRealRandomAccess( leftOperand, rightOperand );
} }


private class RealBinaryIntersectionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess private class RealBinaryIntersectionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess< B >
{ {
private final RealRandomAccess< BoolType > leftRRA; private final RealRandomAccess< B > leftRRA;


private final RealRandomAccess< BoolType > rightRRA; private final RealRandomAccess< B > rightRRA;


public RealBinaryIntersectionRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryIntersectionRealRandomAccess( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
leftRRA = getLeftOperandRealRandomAccess(); leftRRA = getLeftOperandRealRandomAccess();
Expand All @@ -81,7 +82,7 @@ private RealBinaryIntersectionRealRandomAccess( final RealBinaryIntersectionReal
} }


@Override @Override
public BoolType get() public B get()
{ {
leftRRA.setPosition( this ); leftRRA.setPosition( this );
rightRRA.setPosition( this ); rightRRA.setPosition( this );
Expand Down
Expand Up @@ -35,7 +35,7 @@
package net.imglib2.roi.operators; package net.imglib2.roi.operators;


import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.BooleanType;
import net.imglib2.util.Pair; import net.imglib2.util.Pair;


/** /**
Expand All @@ -45,5 +45,5 @@
* *
* @author Alison Walter * @author Alison Walter
*/ */
public interface RealBinaryOperator extends RealRandomAccessibleRealInterval< BoolType >, Pair< RealRandomAccessibleRealInterval< BoolType >, RealRandomAccessibleRealInterval< BoolType > > public interface RealBinaryOperator< B extends BooleanType< B > > extends RealRandomAccessibleRealInterval< B >, Pair< RealRandomAccessibleRealInterval< B >, RealRandomAccessibleRealInterval< B > >
{} {}
Expand Up @@ -34,17 +34,17 @@
package net.imglib2.roi.operators; package net.imglib2.roi.operators;


import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.BooleanType;


/** /**
* Represents a {@link RealRandomAccess} for combined regions of interest. * Represents a {@link RealRandomAccess} for combined regions of interest.
* *
* @author Alison Walter * @author Alison Walter
*/ */
public interface RealBinaryOperatorRealRandomAccess extends RealRandomAccess< BoolType > public interface RealBinaryOperatorRealRandomAccess< B extends BooleanType< B > > extends RealRandomAccess< B >
{ {
RealRandomAccess< BoolType > getLeftOperandRealRandomAccess(); RealRandomAccess< B > getLeftOperandRealRandomAccess();


RealRandomAccess< BoolType > getRightOperandRealRandomAccess(); RealRandomAccess< B > getRightOperandRealRandomAccess();


} }
Expand Up @@ -35,7 +35,7 @@


import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.BooleanType;


/** /**
* This class represents the difference of two regions of interest. * This class represents the difference of two regions of interest.
Expand All @@ -45,26 +45,26 @@
* @version 1.0.0 Jan 14, 2016 * @version 1.0.0 Jan 14, 2016
* *
*/ */
public class RealBinarySubtraction extends AbstractRealBinaryOperator public class RealBinarySubtraction< B extends BooleanType< B > > extends AbstractRealBinaryOperator< B >
{ {
public RealBinarySubtraction( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinarySubtraction( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
} }


@Override @Override
public RealRandomAccess< BoolType > realRandomAccess() public RealRandomAccess< B > realRandomAccess()
{ {
return new RealBinarySubtractionRealRandomAccess( leftOperand, rightOperand ); return new RealBinarySubtractionRealRandomAccess( leftOperand, rightOperand );
} }


private class RealBinarySubtractionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess private class RealBinarySubtractionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess< B >
{ {
private final RealRandomAccess< BoolType > leftRRA; private final RealRandomAccess< B > leftRRA;


private final RealRandomAccess< BoolType > rightRRA; private final RealRandomAccess< B > rightRRA;


public RealBinarySubtractionRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinarySubtractionRealRandomAccess( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
leftRRA = getLeftOperandRealRandomAccess(); leftRRA = getLeftOperandRealRandomAccess();
Expand All @@ -79,7 +79,7 @@ private RealBinarySubtractionRealRandomAccess( final RealBinarySubtractionRealRa
} }


@Override @Override
public BoolType get() public B get()
{ {
leftRRA.setPosition( this ); leftRRA.setPosition( this );
rightRRA.setPosition( this ); rightRRA.setPosition( this );
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/imglib2/roi/operators/RealBinaryUnion.java
Expand Up @@ -35,6 +35,7 @@


import net.imglib2.RealRandomAccess; import net.imglib2.RealRandomAccess;
import net.imglib2.RealRandomAccessibleRealInterval; import net.imglib2.RealRandomAccessibleRealInterval;
import net.imglib2.type.BooleanType;
import net.imglib2.type.logic.BoolType; import net.imglib2.type.logic.BoolType;


/** /**
Expand All @@ -47,26 +48,26 @@
* @version 1.0.0 Jan 14, 2016 * @version 1.0.0 Jan 14, 2016
* *
*/ */
public class RealBinaryUnion extends AbstractRealBinaryOperator public class RealBinaryUnion< B extends BooleanType< B > > extends AbstractRealBinaryOperator< B >
{ {
public RealBinaryUnion( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryUnion( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
} }


@Override @Override
public RealRandomAccess< BoolType > realRandomAccess() public RealRandomAccess< B > realRandomAccess()
{ {
return new RealBinaryUnionRealRandomAccess( leftOperand, rightOperand ); return new RealBinaryUnionRealRandomAccess( leftOperand, rightOperand );
} }


private class RealBinaryUnionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess private class RealBinaryUnionRealRandomAccess extends AbstractRealBinaryOperatorRealRandomAccess< B >
{ {
private final RealRandomAccess< BoolType > leftRRA; private final RealRandomAccess< B > leftRRA;


private final RealRandomAccess< BoolType > rightRRA; private final RealRandomAccess< B > rightRRA;


public RealBinaryUnionRealRandomAccess( final RealRandomAccessibleRealInterval< BoolType > leftOperand, final RealRandomAccessibleRealInterval< BoolType > rightOperand ) public RealBinaryUnionRealRandomAccess( final RealRandomAccessibleRealInterval< B > leftOperand, final RealRandomAccessibleRealInterval< B > rightOperand )
{ {
super( leftOperand, rightOperand ); super( leftOperand, rightOperand );
leftRRA = getLeftOperandRealRandomAccess(); leftRRA = getLeftOperandRealRandomAccess();
Expand All @@ -81,7 +82,7 @@ private RealBinaryUnionRealRandomAccess( final RealBinaryUnionRealRandomAccess r
} }


@Override @Override
public BoolType get() public B get()
{ {
leftRRA.setPosition( this ); leftRRA.setPosition( this );
rightRRA.setPosition( this ); rightRRA.setPosition( this );
Expand Down

0 comments on commit 8ee318b

Please sign in to comment.