Skip to content

Commit 2d37cd5

Browse files
committed
WIP: Refactor HoughCircle to extend AbstractSphere
This commit refactors the HoughCircle ROI to implement the new ROI system. This commit is a WIP because it depends on a SNAPSHOT of imglib2-roi
1 parent 8b021bd commit 2d37cd5

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ Wisconsin-Madison, University of Konstanz and Brian Northan.</license.copyrightO
233233
<dependency>
234234
<groupId>net.imglib2</groupId>
235235
<artifactId>imglib2-roi</artifactId>
236+
<version>0.4.8-SNAPSHOT</version>
236237
</dependency>
237238

238239
<!-- SciJava dependencies -->

src/main/java/net/imagej/ops/segment/hough/HoughCircle.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package net.imagej.ops.segment.hough;
22

33
import net.imglib2.RealLocalizable;
4-
import net.imglib2.RealPoint;
5-
import net.imglib2.roi.util.Contains;
4+
import net.imglib2.roi.geom.real.AbstractSphere;
65

76
/**
87
* Representation of a circle segmented via Hough circle transformation.
@@ -13,21 +12,26 @@
1312
* can be used to sort a list of circles.
1413
*
1514
* @author Jean-Yves Tinevez.
15+
* @author Gabe Selzer.
1616
*
1717
*/
18-
public class HoughCircle extends RealPoint implements Comparable< HoughCircle >, Contains< RealLocalizable >
18+
public class HoughCircle extends AbstractSphere implements Comparable< HoughCircle >
1919
{
2020

21-
private final double radius;
22-
2321
private final double sensitivity;
2422

2523
public HoughCircle( final RealLocalizable pos, final double radius, final double sensitivity )
2624
{
27-
super( pos );
25+
super( getCenter(pos) , radius);
2826
this.radius = radius;
2927
this.sensitivity = sensitivity;
3028
}
29+
30+
private static double[] getCenter(RealLocalizable l) {
31+
double[] center = new double[l.numDimensions()];
32+
l.localize(center);
33+
return center;
34+
}
3135

3236
@Override
3337
public String toString()
@@ -37,7 +41,7 @@ public String toString()
3741
for ( int i = 0; i < numDimensions(); i++ )
3842
{
3943
sb.append( c );
40-
sb.append( String.format( "%.1f", position[ i ] ) );
44+
sb.append( String.format( "%.1f", center[ i ] ) );
4145
c = ',';
4246
}
4347
sb.append( ")" );
@@ -61,10 +65,10 @@ public int compareTo( final HoughCircle o )
6165
}
6266

6367
@Override
64-
public boolean contains( final RealLocalizable point )
68+
public boolean test( final RealLocalizable point )
6569
{
66-
final double dx = getDoublePosition( 0 ) - point.getDoublePosition( 0 );
67-
final double dy = getDoublePosition( 1 ) - point.getDoublePosition( 1 );
70+
final double dx = center[0] - point.getDoublePosition( 0 );
71+
final double dy = center[1] - point.getDoublePosition( 1 );
6872
final double dr2 = dx * dx + dy * dy;
6973

7074
if ( dr2 < radius * radius )
@@ -73,9 +77,4 @@ public boolean contains( final RealLocalizable point )
7377
return true;
7478
}
7579

76-
@Override
77-
public HoughCircle copyContains()
78-
{
79-
return new HoughCircle( this, radius, sensitivity );
80-
}
8180
}

0 commit comments

Comments
 (0)