Commit cc41c9b9 authored by Stéphane  DALLONGEVILLE's avatar Stéphane DALLONGEVILLE
Browse files

Updated for Icy kernel 2.4.0 (interruptible process)

parent 9c1bab1f
......@@ -11,7 +11,7 @@
</parent>
<artifactId>active-contours</artifactId>
<version>4.4.11</version>
<version>4.4.12</version>
<packaging>jar</packaging>
......
......@@ -190,54 +190,54 @@ public abstract class ActiveContour extends Detection implements Iterable<Point3
public abstract double computeBackgroundIntensity(Sequence imageData, BooleanMask3D mask);
/**
* Tests whether the given point is inside the contour, and if so returns
* the penetration depth of this point. <br>
*
* @param p
* a point to test
* @return
* <ul>
* <li>if <code>p</code> is outside: <code>0</code>
* <li>if <code>p</code> is inside: the distance from <code>p</code>
* to the contour edge
* </ul>
*/
* Tests whether the given point is inside the contour, and if so returns
* the penetration depth of this point. <br>
*
* @param p
* a point to test
* @return
* <ul>
* <li>if <code>p</code> is outside: <code>0</code>
* <li>if <code>p</code> is inside: the distance from <code>p</code>
* to the contour edge
* </ul>
*/
public abstract double getDistanceToEdge(Point3d p);
/**
* @param order
* the dimension (a.k.a. norm) to compute:
* <ul>
* <li>0: number of points,</li>
* <li>1: perimeter (2D) or surface area (3D),</li>
* <li>2: surface (2D) or volume (3D)</li>
* </ul>
* @return the dimension for the specified order
*/
* @param order
* the dimension (a.k.a. norm) to compute:
* <ul>
* <li>0: number of points,</li>
* <li>1: perimeter (2D) or surface area (3D),</li>
* <li>2: surface (2D) or volume (3D)</li>
* </ul>
* @return the dimension for the specified order
*/
public abstract double getDimension(int order);
abstract void move(ROI boundField, double timeStep);
/**
* Re-samples the Contour according to an 'average distance between points'
* criterion. This method ensures that the distance between two consecutive
* points is strictly comprised between a minimum value and a maximum value.
* In order to avoid oscillatory behavior, 'max' and 'min' should verify the
* following relations: min &lt; 1, max &gt; 1, 2*min &lt;= max.
*
* @param minFactor
* the minimum distance between two points.
* @param maxFactor
* the maximum distance between two points.
*/
* Re-samples the Contour according to an 'average distance between points'
* criterion. This method ensures that the distance between two consecutive
* points is strictly comprised between a minimum value and a maximum value.
* In order to avoid oscillatory behavior, 'max' and 'min' should verify the
* following relations: min &lt; 1, max &gt; 1, 2*min &lt;= max.
*
* @param minFactor
* the minimum distance between two points.
* @param maxFactor
* the maximum distance between two points.
*/
public abstract void reSample(double minFactor, double maxFactor) throws TopologyException;
/**
* @return a ROI representing the contour
* @deprecated use {@link #toROI(ROIType, Sequence)} instead
*/
* @return a ROI representing the contour
* @deprecated use {@link #toROI(ROIType, Sequence)} instead
*/
@Deprecated
public abstract ROI toROI();
public abstract ROI toROI() throws UnsupportedOperationException, InterruptedException;
/**
* @param type
......@@ -249,7 +249,8 @@ public abstract class ActiveContour extends Detection implements Iterable<Point3
* @throws UnsupportedOperationException
* if the contour cannot be exported in the requested type
*/
public abstract ROI toROI(ROIType type, Sequence sequence) throws UnsupportedOperationException;
public abstract ROI toROI(ROIType type, Sequence sequence)
throws UnsupportedOperationException, InterruptedException;
/**
* Paints the contour onto the specified sequence with the specified value
......@@ -260,16 +261,16 @@ public abstract class ActiveContour extends Detection implements Iterable<Point3
public abstract void toSequence(Sequence output, double value);
/**
* Updates the contour's meta-data (i.e. data that can be computed directly
* from the actual contour data, but stored locally for fast repetitive
* access). This includes:
* <ul>
* <li>bounding box</li>
* <li>bounding sphere</li>
* <li>contour normals</li>
* <li>center of mass</li>
* </ul>
*/
* Updates the contour's meta-data (i.e. data that can be computed directly
* from the actual contour data, but stored locally for fast repetitive
* access). This includes:
* <ul>
* <li>bounding box</li>
* <li>bounding sphere</li>
* <li>contour normals</li>
* <li>center of mass</li>
* </ul>
*/
protected void updateMetaData()
{
// center of mass
......
......@@ -101,7 +101,8 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
{
try
{
final double cin = contour.computeAverageIntensity(contour instanceof Mesh3D ? regionData : regionDataSummed,
final double cin = contour.computeAverageIntensity(
contour instanceof Mesh3D ? regionData : regionDataSummed,
maskBased ? contourMask_buffer : null);
region_cin.put(trackGroup.getValue().getTrackSegmentWithDetection(contour), cin);
}
......@@ -147,8 +148,8 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
final List<TrackSegment> activeTracks;
final List<TrackSegment> endedTracks;
public ContourInitializer(final ROI roi, final int z, final int t, final Tuple3d pixelSize, final int convWinSize,
final List<TrackSegment> activeTracks, final List<TrackSegment> justEndedTracks)
public ContourInitializer(final ROI roi, final int z, final int t, final Tuple3d pixelSize,
final int convWinSize, final List<TrackSegment> activeTracks, final List<TrackSegment> justEndedTracks)
{
super();
......@@ -163,7 +164,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
// test if the object is colliding an existing contour or if we need to discard
// it for other reason
private boolean colliding()
private boolean colliding() throws UnsupportedOperationException, InterruptedException
{
// // image bounds
// final Rectangle imageBounds = inputData.getBounds2D();
......@@ -190,7 +191,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
}
@Override
public Object call()
public Object call() throws InterruptedException
{
// object colliding active contours ? --> discard it
if (colliding())
......@@ -595,11 +596,16 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
+ e.getMessage()
+ "\nIf you are not sure how to fix this, change this parameter to \"No Sequence\"");
}
catch (InterruptedException e)
{
throw new VarException(evolution_bounds.getVariable(), "Interrupted Active Contours process...");
}
}
}
// no specific field ? limit to sequence bounds
if (field == null)
{
if (inputData.getSizeZ() == 1)
field = new ROI2DRectangle(0, 0, inputData.getWidth(), inputData.getHeight());
......@@ -632,7 +638,15 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
if (isHeadLess())
System.out.println("=> preparing image data...");
initData(t);
try
{
initData(t);
}
catch (InterruptedException e)
{
// so it will end nicely
Thread.currentThread().interrupt();
}
if (Thread.currentThread().isInterrupted())
break;
......@@ -654,38 +668,54 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
if (isHeadLess())
System.out.println("=> adding new contours...");
addNewContours(t);
try
{
addNewContours(t);
}
catch (InterruptedException e)
{
// so it will end nicely
Thread.currentThread().interrupt();
}
if (Thread.currentThread().isInterrupted())
break;
if (isHeadLess())
System.out.println("=> evolving new contours...");
// evolve new contours
iteration = evolveContours(t, field);
// evolve new contours
iteration = evolveContours(t, field);
// no more contours for this time point ?
if (iteration == -1)
{
// detection of new objects disable ?
if (!tracking_newObjects.getValue().booleanValue() || (inputData.getSizeZ() != 1))
try
{
// no more contours for this time point ?
if (iteration == -1)
{
// no ROIs to work with in future ? --> we can stop process here
if (!hasFutureRois(t))
// detection of new objects disable ?
if (!tracking_newObjects.getValue().booleanValue() || (inputData.getSizeZ() != 1))
{
storeResult(t);
break;
// no ROIs to work with in future ? --> we can stop process here
if (!hasFutureRois(t))
{
storeResult(t);
break;
}
}
}
}
// log info
if (iteration > 0)
System.out.println(
"[Active Contours] converged new contours on frame " + t + " in " + iteration + " iterations");
// log info
if (iteration > 0)
System.out.println("[Active Contours] converged new contours on frame " + t + " in " + iteration
+ " iterations");
// store detections and results
storeResult(t);
// store detections and results
storeResult(t);
}
catch (InterruptedException e)
{
// interrupt nicely
Thread.currentThread().interrupt();
}
if (Thread.currentThread().isInterrupted())
break;
......@@ -740,8 +770,15 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
switch (output_rois.getValue())
{
case ON_NEW_IMAGE:
out = SequenceUtil.getCopy(inputData);
out.setName(inputData.getName() + " + Active contours");
try
{
out = SequenceUtil.getCopy(inputData);
out.setName(inputData.getName() + " + Active contours");
}
catch (InterruptedException e)
{
throw new VarException(output_rois.getVariable(), "Interrupted output sequence creation...");
}
//$FALL-THROUGH$
case ON_INPUT:
for (final ROI roi : roiOutput.getValue())
......@@ -807,7 +844,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
return false;
}
private void initData(final int t)
private void initData(final int t) throws InterruptedException
{
final int edgeChannel = edge_c.getValue().intValue();
final int regionChannel = region_c.getValue().intValue();
......@@ -909,7 +946,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
}
}
private void addNewContours(final int t)
private void addNewContours(final int t) throws InterruptedException
{
// prepare parameters
final TrackGroup tg = trackGroup.getValue();
......@@ -1097,8 +1134,10 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
/**
* Create a copy of input ROI and split multiples components ROI if needed
*
* @throws InterruptedException
*/
private List<ROI> getWorkRois(final ROI roi)
private List<ROI> getWorkRois(final ROI roi) throws InterruptedException
{
// get minimum allowed size
final int minPoints = (int) (contour_resolution.getValue().doubleValue() * 3);
......@@ -1149,7 +1188,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
return result;
}
private List<ROI> getNewObjectsFor(final int t)
private List<ROI> getNewObjectsFor(final int t) throws InterruptedException
{
final List<ROI> result = new ArrayList<ROI>();
......@@ -1199,7 +1238,8 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
// we use HK-Means plugin to detect entering objects in region data only
// (HK-Mean won't work on edge signal anyway)
// Note that it will work only for fluo images here
for (final ROI roi : HKMeans.hKMeans(regionData, (byte) 7, (int) minVol, (int) maxVol, Double.valueOf(0d)))
for (final ROI roi : HKMeans.hKMeans(regionData, (byte) 7, (int) minVol, (int) maxVol,
Double.valueOf(0d)))
{
// set correct position for ROI
((ROI2D) roi).setC(-1);
......@@ -1216,8 +1256,11 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
/**
* Return new contour from a given ROI.
*
* @throws InterruptedException
*/
ActiveContour getContourOf(final ROI roi, final int z, final int t, final Tuple3d pixelSize, final int convWinSize)
throws InterruptedException
{
final int depth = inputData.getSizeZ();
ActiveContour result = null;
......@@ -1520,7 +1563,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
tasks.add(new Callable<Object>()
{
@Override
public Object call()
public Object call()
{
if (regul_weight.getValue() > EPSILON)
......@@ -1743,7 +1786,8 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
else
{
// use multiple threads
final Collection<Callable<Object>> updaters = new ArrayList<Callable<Object>>(allContoursAtTimeT.size());
final Collection<Callable<Object>> updaters = new ArrayList<Callable<Object>>(
allContoursAtTimeT.size());
for (final ActiveContour contour : allContoursAtTimeT)
updaters.add(new LocalBackgroundStatisticsComputer(contour));
......@@ -1799,7 +1843,7 @@ public class ActiveContours extends EzPlug implements EzStoppable, Block
}
}
private void storeResult(final int t)
private void storeResult(final int t) throws UnsupportedOperationException, InterruptedException
{
if (isHeadLess())
System.out.println("=> Storing result...");
......
......@@ -169,8 +169,9 @@ public class Polygon2D extends ActiveContour
* @throws TopologyException
* if the contour cannot created for topological reason (e.g. the roi is too small
* w.r.t. the sampling size)
* @throws InterruptedException
*/
public Polygon2D(final Var<Double> sampling, final SlidingWindow convergenceWindow, ROI2D roi) throws TopologyException
public Polygon2D(final Var<Double> sampling, final SlidingWindow convergenceWindow, ROI2D roi) throws TopologyException, InterruptedException
{
this(sampling, convergenceWindow);
......@@ -839,8 +840,9 @@ public class Polygon2D extends ActiveContour
* @param zRadius
* the radius in pixels along Z (not used if <code>roi</code> is 2D)
* @return a new, dilated ROI of type "area"
* @throws InterruptedException
*/
private static ROI2D dilateROI(final ROI2D roi, final int xRadius, final int yRadius)
private static ROI2D dilateROI(final ROI2D roi, final int xRadius, final int yRadius) throws InterruptedException
{
final int rx = xRadius, rrx = rx * rx;
final int ry = yRadius, rry = ry * ry;
......@@ -1358,7 +1360,7 @@ public class Polygon2D extends ActiveContour
updateMetaData();
}
private void triangulate(final ROI2DArea roi, final double resolution) throws TopologyException
private void triangulate(final ROI2DArea roi, final double resolution) throws TopologyException, InterruptedException
{
final ArrayList<Segment> segments = new ArrayList<Segment>();
......@@ -1378,6 +1380,11 @@ public class Polygon2D extends ActiveContour
mask[o] = false;
for (int j = 0; j < bounds.height; j += grid)
{
// check for interruption from time to time as this can be a long process
if (((j & 0xF) == 0xF) && Thread.interrupted())
throw new InterruptedException("Polygon2D.triangulate() process interrupted.");
for (int i = 0, index = j * bounds.width; i < bounds.width; i += grid, index += grid)
{
// The image is divided into square cells containing two
......@@ -1500,6 +1507,7 @@ public class Polygon2D extends ActiveContour
}
}
}
}
if (segments.size() == 0)
return;
......@@ -1583,13 +1591,13 @@ public class Polygon2D extends ActiveContour
@Deprecated
@Override
public ROI2D toROI()
public ROI2D toROI() throws InterruptedException
{
return toROI(ROIType.AREA, null);
}
@Override
public ROI2D toROI(final ROIType type, final Sequence sequence)
public ROI2D toROI(final ROIType type, final Sequence sequence) throws InterruptedException
{
ROI2D roi;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment