Skip to content

Commit

Permalink
Modify SuperEllipsoid etc. to use RealLocalizableRealPositionable
Browse files Browse the repository at this point in the history
  • Loading branch information
awalter17 committed Jan 18, 2018
1 parent 7040497 commit e2db559
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/main/java/net/imglib2/roi/geom/GeomMasks.java
Expand Up @@ -39,7 +39,6 @@

import net.imglib2.KDTree;
import net.imglib2.RealLocalizable;
import net.imglib2.RealPoint;
import net.imglib2.RealPointSampleList;
import net.imglib2.roi.MaskPredicate;
import net.imglib2.roi.geom.real.Box;
Expand Down Expand Up @@ -101,13 +100,13 @@ public static Box< RealLocalizableRealPositionable > openBox( final double[] min
// -- Ellipsoid --

/** Creates a {@link ClosedEllipsoid}. */
public static Ellipsoid< RealPoint > closedEllipsoid( final double[] center, final double[] semiAxisLengths )
public static Ellipsoid< RealLocalizableRealPositionable > closedEllipsoid( final double[] center, final double[] semiAxisLengths )
{
return new ClosedEllipsoid( center, semiAxisLengths );
}

/** Creates an {@link OpenEllipsoid}. */
public static Ellipsoid< RealPoint > openEllipsoid( final double[] center, final double[] semiAxisLengths )
public static Ellipsoid< RealLocalizableRealPositionable > openEllipsoid( final double[] center, final double[] semiAxisLengths )
{
return new OpenEllipsoid( center, semiAxisLengths );
}
Expand Down Expand Up @@ -221,29 +220,29 @@ public static < L extends RealLocalizable > NNSRealPointCollection< L > realPoin
// -- Sphere --

/** Creates a {@link ClosedSphere}. */
public static Sphere< RealPoint > closedSphere( final double[] center, final double radius )
public static Sphere< RealLocalizableRealPositionable > closedSphere( final double[] center, final double radius )
{
return new ClosedSphere( center, radius );
}

/** Creates an {@link OpenSphere}. */
public static Sphere< RealPoint > openSphere( final double[] center, final double radius )
public static Sphere< RealLocalizableRealPositionable > openSphere( final double[] center, final double radius )
{
return new OpenSphere( center, radius );
}

// -- SuperEllipsoid --

/** Creates a {@link ClosedSuperEllipsoid}. */
public static SuperEllipsoid< RealPoint > closedSuperEllipsoid( final double[] center, final double[] semiAxisLengths, final double exponent )
public static SuperEllipsoid< RealLocalizableRealPositionable > closedSuperEllipsoid( final double[] center, final double[] semiAxisLengths, final double exponent )
{
if ( exponent == 2 )
return new ClosedEllipsoid( center, semiAxisLengths );
return new ClosedSuperEllipsoid( center, semiAxisLengths, exponent );
}

/** Creates an {@link OpenSuperEllipsoid}. */
public static SuperEllipsoid< RealPoint > openSuperEllipsoid( final double[] center, final double[] semiAxisLengths, final double exponent )
public static SuperEllipsoid< RealLocalizableRealPositionable > openSuperEllipsoid( final double[] center, final double[] semiAxisLengths, final double exponent )
{
if ( exponent == 2 )
return new OpenEllipsoid( center, semiAxisLengths );
Expand Down
Expand Up @@ -34,14 +34,14 @@
package net.imglib2.roi.geom.real;

import net.imglib2.RealLocalizable;
import net.imglib2.RealPoint;
import net.imglib2.roi.util.RealLocalizableRealPositionable;

/**
* Abstract base class for {@link Ellipsoid} implementations.
*
* @author Alison Walter
*/
public abstract class AbstractEllipsoid extends AbstractSuperEllipsoid implements Ellipsoid< RealPoint >
public abstract class AbstractEllipsoid extends AbstractSuperEllipsoid implements Ellipsoid< RealLocalizableRealPositionable >
{

/**
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/net/imglib2/roi/geom/real/AbstractSphere.java
Expand Up @@ -11,13 +11,13 @@
* %%
* 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
Expand All @@ -35,15 +35,16 @@

import net.imglib2.AbstractEuclideanSpace;
import net.imglib2.RealLocalizable;
import net.imglib2.RealPoint;
import net.imglib2.roi.BoundaryType;
import net.imglib2.roi.util.AbstractRealMaskPoint;
import net.imglib2.roi.util.RealLocalizableRealPositionable;

/**
* Abstract base class for {@link Sphere} implementations.
*
* @author Alison Walter
*/
public abstract class AbstractSphere extends AbstractEuclideanSpace implements Sphere< RealPoint >
public abstract class AbstractSphere extends AbstractEuclideanSpace implements Sphere< RealLocalizableRealPositionable >
{
protected final double[] center;

Expand Down Expand Up @@ -97,9 +98,9 @@ public double semiAxisLength( final int d )
* sphere.
*/
@Override
public RealPoint center()
public RealLocalizableRealPositionable center()
{
return RealPoint.wrap( center );
return new SphereCenter( center );
}

@Override
Expand Down Expand Up @@ -175,4 +176,22 @@ protected double distancePowered( final RealLocalizable l )

return distancePowered;
}

// -- Helper classes --

private class SphereCenter extends AbstractRealMaskPoint
{

public SphereCenter( final double[] pos )
{
super( pos );
}

@Override
public void updateBounds()
{
// No implementation needed, min/max easy to compute
}

}
}
Expand Up @@ -11,13 +11,13 @@
* %%
* 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
Expand All @@ -35,15 +35,16 @@

import net.imglib2.AbstractEuclideanSpace;
import net.imglib2.RealLocalizable;
import net.imglib2.RealPoint;
import net.imglib2.roi.BoundaryType;
import net.imglib2.roi.util.AbstractRealMaskPoint;
import net.imglib2.roi.util.RealLocalizableRealPositionable;

/**
* Abstract base class for {@link SuperEllipsoid} implementations.
*
* @author Alison Walter
*/
public abstract class AbstractSuperEllipsoid extends AbstractEuclideanSpace implements SuperEllipsoid< RealPoint >
public abstract class AbstractSuperEllipsoid extends AbstractEuclideanSpace implements SuperEllipsoid< RealLocalizableRealPositionable >
{
protected double exponent;

Expand Down Expand Up @@ -114,9 +115,9 @@ public double semiAxisLength( final int d )
* superellipsoid.
*/
@Override
public RealPoint center()
public RealLocalizableRealPositionable center()
{
return RealPoint.wrap( center );
return new SuperEllipsoidCenter( center );
}

@Override
Expand Down Expand Up @@ -192,4 +193,22 @@ protected double distancePowered( final RealLocalizable l )

return distancePowered;
}

// -- Helper classes --

private class SuperEllipsoidCenter extends AbstractRealMaskPoint
{

public SuperEllipsoidCenter( final double[] pos )
{
super( pos );
}

@Override
public void updateBounds()
{
// Not needed, bounds are simple enough to compute
}

}
}

0 comments on commit e2db559

Please sign in to comment.