Skip to content

Commit

Permalink
stop button for tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Dec 19, 2024
1 parent 807f2b2 commit 21045f1
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 38 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<dependency>
<groupId>nl.uu.science.cellbiology</groupId>
<artifactId>bvv-playground</artifactId>
<version>0.3.1</version>
<version>0.3.3</version>
</dependency>

<!-- BIOFORMATS -->
Expand Down Expand Up @@ -126,7 +126,7 @@
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf-jide-oss</artifactId>
<version>3.5</version>
<version>3.0</version>
</dependency>
<!-- SCIFIO dependencies -->
<dependency>
Expand All @@ -138,7 +138,7 @@
<dependency>
<groupId>ch.epfl.biop</groupId>
<artifactId>bigdataviewer-image-loaders</artifactId>
<version>0.8.6</version>
<version>0.6.4</version>
</dependency>

<!-- ImgLib2 dependencies -->
Expand Down
33 changes: 21 additions & 12 deletions src/main/java/bigtrace/BigTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public class BigTrace < T extends RealType< T > & NativeType< T > > implements P
/** BigTrace macro interface**/
public BigTraceMacro<T> btMacro;

/** One click tracing worker**/
OneClickTrace<T> oneClickTrace = null;

/**macro extensions **/
private ExtensionDescriptor[] extensions = {

Expand Down Expand Up @@ -404,21 +407,27 @@ public void runOneClickTrace(final RealPoint pclick, final boolean bNewTrace_)
{

final IntervalView<T> traceIV = getTraceInterval(btData.bTraceOnlyClipped);
// System.out.println(pclick.getDoublePosition(0));
// System.out.println(pclick.getDoublePosition(1));
// System.out.println(pclick.getDoublePosition(2));

bInputLock = true;
OneClickTrace<T> calcTask = new OneClickTrace<>();
calcTask.fullInput = traceIV;
calcTask.bt = this;
calcTask.startPoint = pclick;
calcTask.bNewTrace = bNewTrace_;
calcTask.addPropertyChangeListener(btPanel);
calcTask.execute();
oneClickTrace = new OneClickTrace<>();
oneClickTrace.fullInput = traceIV;
oneClickTrace.bt = this;
oneClickTrace.startPoint = pclick;
oneClickTrace.bNewTrace = bNewTrace_;
oneClickTrace.addPropertyChangeListener(btPanel);
roiManager.setOneClickTracing( true );
oneClickTrace.execute();

}

public void cancelOneClickTrace()
{
if(oneClickTrace != null )
{
oneClickTrace.cancel( false );
}
}

/** returns current Interval for the tracing. If bClippedInterval is true,
* returns clipped volume, otherwise returns full original volume. **/
public IntervalView<T> getTraceInterval(boolean bClippedInterval)
Expand Down Expand Up @@ -1673,8 +1682,8 @@ public static void main(String... args) throws Exception
new ImageJ();
BigTrace testI = new BigTrace();

testI.run("");
//testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
//testI.run("");
testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
///testI.run("/home/eugene/Desktop/projects/BigTrace/BT_tracks/Snejana_small_example.tif");
//testI.run("/home/eugene/Desktop/bend/test_bend_2ch/output/trace1514947168.xml");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bigtrace/BigTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class BigTraceData < T extends RealType< T > & NativeType< T > > {

/** current plugin version **/
public static String sVersion = "0.5.0";
public static String sVersion = "0.5.1";

/** plugin instance **/
BigTrace<T> bt;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bigtrace/BigTraceRenderSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ij.Prefs;


@Plugin(type = Command.class, menuPath = "Plugins>BigTrace 0.5.0>Volume Render Settings")
@Plugin(type = Command.class, menuPath = "Plugins>BigTrace 0.5.1>Volume Render Settings")
public class BigTraceRenderSettings implements Command {


Expand Down
43 changes: 34 additions & 9 deletions src/main/java/bigtrace/math/OneClickTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void setProgressState(String state_)
}

@Override
protected Void doInBackground() throws Exception {
protected Void doInBackground() throws Exception
{

runTracing ();
return null;
Expand Down Expand Up @@ -205,7 +206,11 @@ public void runTracing ()
allPointsIntersection = new ArrayList<>();
//trace in one direction
nTotPoints = traceOneDirection(true, 0);

if(nTotPoints<0)
{
setProgressState("Tracing interrupted by user.");
return;
}
if(bUpdateProgressBar)
{
setProgress(50);
Expand All @@ -223,7 +228,11 @@ public void runTracing ()
}
//trace in the other direction
nTotPoints = traceOneDirection(false, nTotPoints);

if(nTotPoints<0)
{
setProgressState("Tracing interrupted by user.");
return;
}
//end1 = System.currentTimeMillis();
//System.out.println("THREADED Elapsed Time in seconds: "+ 0.001*(end1-start1));

Expand All @@ -235,7 +244,8 @@ public void runTracing ()
}
return ;
}
/** traces line in one direction.
/** traces line in one direction. Returns number of current found points
* or -1 if it got interrupted.
* @param bFirstTrace
* if it is a first trace or continuation of existing
* @param nCountIn
Expand Down Expand Up @@ -325,7 +335,10 @@ public int traceOneDirection(boolean bFirstTrace, int nCountIn)
// System.out.println(nCountPoints+" "+LinAlgHelpers.dot(saveVector, nextPointD));
}


if(isCancelled())
{
return -1;
}
}
//adding last part of the trace

Expand Down Expand Up @@ -843,21 +856,33 @@ public void done()
{
//see if we have some errors
try {

get();
}
catch (ExecutionException e) {
}
catch (ExecutionException e)
{
e.getCause().printStackTrace();
String msg = String.format("Unexpected problem during one-click tracing: %s",
e.getCause().toString());
System.out.println(msg);
} catch (InterruptedException e) {
}
catch (InterruptedException e)
{
// Process e here
}
catch (Exception e)
{

//System.out.println("Tracing interrupted by user.");
setProgressState("Tracing interrupted by user.");
setProgress(100);
}
//es.shutdown();
releaseMultiThread();

bt.visBox = null;

bt.roiManager.setOneClickTracing( false );

//deselect the trace if we just made it
if(bNewTrace)
{
Expand Down
47 changes: 38 additions & 9 deletions src/main/java/bigtrace/rois/RoiManager3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public static interface Listener {
JButton roiImport;
JButton roiSettings;


ImageIcon tabIconOCTrace;
ImageIcon tabIconCancel;

private ArrayList<Listener> listeners = new ArrayList<>();


Expand Down Expand Up @@ -150,7 +152,7 @@ public RoiManager3D(BigTrace<T> bt)
{roiPointMode.setSelected(true);}


icon_path =bigtrace.BigTrace.class.getResource("/icons/polyline.png");
icon_path = bigtrace.BigTrace.class.getResource("/icons/polyline.png");
tabIcon = new ImageIcon(icon_path);
roiPolyLineMode = new JToggleButton(tabIcon);
roiPolyLineMode.setToolTipText("Trace polyline");
Expand Down Expand Up @@ -179,11 +181,13 @@ public void mouseClicked(MouseEvent evt) {


icon_path = bigtrace.BigTrace.class.getResource("/icons/oneclicktrace.png");
tabIcon = new ImageIcon(icon_path);
roiPolyOneClickMode = new JToggleButton(tabIcon);
tabIconOCTrace = new ImageIcon(icon_path);
icon_path = bigtrace.BigTrace.class.getResource("/icons/cancel.png");
tabIconCancel = new ImageIcon(icon_path);
roiPolyOneClickMode = new JToggleButton(tabIconOCTrace);
roiPolyOneClickMode.setToolTipText("One click trace");
roiPolyOneClickMode.setPreferredSize(new Dimension(nButtonSize, nButtonSize));
if(mode==RoiManager3D.ADD_POINT_ONECLICKLINE)
if(mode == RoiManager3D.ADD_POINT_ONECLICKLINE)
{roiPolyOneClickMode.setSelected(true);}

roiPolyOneClickMode.addMouseListener(new MouseAdapter()
Expand Down Expand Up @@ -1007,11 +1011,21 @@ public void actionPerformed(ActionEvent e)
}
if(e.getSource() == roiPolyOneClickMode)
{
if(RoiManager3D.mode != RoiManager3D.ADD_POINT_ONECLICKLINE)
if(!bt.bInputLock)
{
RoiManager3D.mode = RoiManager3D.ADD_POINT_ONECLICKLINE;
Prefs.set("BigTrace.RoiManagerMode", RoiManager3D.mode);
unselect();
if(RoiManager3D.mode != RoiManager3D.ADD_POINT_ONECLICKLINE)
{
RoiManager3D.mode = RoiManager3D.ADD_POINT_ONECLICKLINE;
Prefs.set("BigTrace.RoiManagerMode", RoiManager3D.mode);
unselect();
}
}
else
{
if(roiPolyOneClickMode.isEnabled())
{
bt.cancelOneClickTrace();
}
}
}
if(e.getSource() == roiPlaneMode)
Expand Down Expand Up @@ -1299,6 +1313,21 @@ public void dialProperties()
}
}

public void setOneClickTracing(boolean bBegin)
{
if(bBegin)
{
roiPolyOneClickMode.setIcon( tabIconCancel );
roiPolyOneClickMode.setToolTipText( "Stop tracing" );
roiPolyOneClickMode.setEnabled( true );
}
else
{
roiPolyOneClickMode.setIcon(tabIconOCTrace);
roiPolyOneClickMode.setToolTipText("One click trace");

}
}

public void loadROIs(String filename, int nLoadMode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bigtrace/tracks/CurveTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void done()
catch (Exception e)
{

System.out.println("Tracking interrupted by user.");
//System.out.println("Tracking interrupted by user.");
bt.visBox = null;
setProgressState("Tracking interrupted by user.");
setProgress(100);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bigtrace/tracks/TrackingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void simpleTracking()
bt.setLockMode(true);
butTrack.setEnabled( true );
Prefs.set("BigTrace.nTrackExpandBox", nBoxExpand);
btTracker.nNextFrame=nNextFrame;
btTracker.nNextFrame = nNextFrame;
btTracker.nBoxExpand = nBoxExpand;
butTrack.setIcon( tabIconCancel );
butTrack.setToolTipText( "Stop tracking" );
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugins.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Plugins>BigTrace 0.5.0, "Open 3D image", bigtrace.BigTrace
Plugins>BigTrace 0.5.1, "Open 3D image", bigtrace.BigTrace

0 comments on commit 21045f1

Please sign in to comment.