Skip to content

Commit

Permalink
Improving headless mode - 3D Analyzer - #3 - avoid ProgressDialog
Browse files Browse the repository at this point in the history
Avoid ProgressDialog entirely in noGUIs (headless) macro mode.
  • Loading branch information
hansenjn committed Jul 30, 2024
1 parent de84b05 commit 678e28d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 59 deletions.
2 changes: 1 addition & 1 deletion 3D Analyzer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<artifactId>MotiQ_3D</artifactId>
<groupId>JNH</groupId>
<version>0.3.2-SNAPSHOT</version>
<version>0.3.3-SNAPSHOT</version>

<!-- Plugin Information -->
<name>MotiQ 3D Analyzer</name>
Expand Down
75 changes: 43 additions & 32 deletions 3D Analyzer/src/main/java/motiQ3D/MotiQ_3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C) 2014-2024 Jan N. Hansen
* First version: July 28, 2014
* This Version: July 29, 2024
* This Version: July 30, 2024
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -43,7 +43,7 @@
public class MotiQ_3D implements PlugIn, Measurements{
//Name variables
static final String PLUGINNAME = "MotiQ 3D Analyzer";
static final String PLUGINVERSION = "v0.3.2";
static final String PLUGINVERSION = "v0.3.3";

DecimalFormat dformat6 = new DecimalFormat("#0.000000");
DecimalFormat dformat3 = new DecimalFormat("#0.000");
Expand Down Expand Up @@ -313,6 +313,7 @@ record = true;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

GenericDialog gd = new GenericDialog(PLUGINNAME + " - settings");
gd.addHelp("https://github.com/hansenjn/MotiQ/wiki");
//show Dialog-----------------------------------------------------------------
// gd.setInsets(0,0,0); (top, left, bottom)
gd.setInsets(0,0,0); gd.addMessage(PLUGINNAME + ", version " + PLUGINVERSION
Expand Down Expand Up @@ -534,8 +535,8 @@ public void windowClosing(WindowEvent winEvt) {
}

//add progressDialog
progress = new ProgressDialog(name, tasks, noGUIs);
if(!noGUIs) {
progress = new ProgressDialog(name, tasks, noGUIs);
progress.setLocation(0,0);
progress.setVisible(true);
progress.addWindowListener(new java.awt.event.WindowAdapter() {
Expand Down Expand Up @@ -565,17 +566,21 @@ public void windowClosing(WindowEvent winEvt) {
break continueAll;
}
Date startDate = new Date();
progress.updateBarText(" in progress...");
if(!noGUIs) progress.updateBarText(" in progress...");
running: while(true){
//Check for problems with image file
if(name[task].substring(name[task].lastIndexOf("."),name[task].length()).equals(".txt")){
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": File is no image! Could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
if(!noGUIs) {
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": File is no image! Could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
}
break running;
}
if(name[task].substring(name[task].lastIndexOf("."),name[task].length()).equals(".zip")){
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": File is no image! Could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
if(!noGUIs) {
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": File is no image! Could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
}
break running;
}
//Check for problems with image file
Expand All @@ -594,8 +599,10 @@ public void windowClosing(WindowEvent winEvt) {
imp.deleteRoi();
}
}catch (Exception e) {
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": file is no image - could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
if(!noGUIs) {
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": file is no image - could not be processed!",ProgressDialog.ERROR);
progress.moveTask(task);
}
break running;
}

Expand Down Expand Up @@ -678,7 +685,7 @@ public void windowClosing(WindowEvent winEvt) {
cal.fps = fps;
timeUnit = calTimeUnit;
}else{
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": recalibration failed! Metadata calibration is used instead!!",ProgressDialog.ERROR);
if(!noGUIs) progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": recalibration failed! Metadata calibration is used instead!!",ProgressDialog.ERROR);
}
}
//Calibrate
Expand Down Expand Up @@ -845,8 +852,10 @@ public void windowClosing(WindowEvent winEvt) {
floodNodes[index][3] = floodNodeT;
}
if(processedPxCount%(pxCount100)<pxCount1000){
progress.setBar(ProgressFactor0*((double)(processedPxCount)/(double)(pxCount)));
progress.updateBarText("filtering particles ... " + dformat3.format(100.0*(double)(processedPxCount)/(double)(pxCount)) + "%");
if(!noGUIs) {
progress.setBar(ProgressFactor0*((double)(processedPxCount)/(double)(pxCount)));
progress.updateBarText("filtering particles ... " + dformat3.format(100.0*(double)(processedPxCount)/(double)(pxCount)) + "%");
}
}
}
//Floodfiller
Expand Down Expand Up @@ -929,11 +938,12 @@ public void windowClosing(WindowEvent winEvt) {
}
}
wholePointCollection.trimToSize();
progress.setBar(ProgressFactor0+ProgressFactor1);
progress.updateBarText("detecting particles ... " + dformat3.format(100.0) + "%");

if(!noGUIs) {
progress.setBar(ProgressFactor0+ProgressFactor1);
progress.updateBarText("detecting particles ... " + dformat3.format(100.0) + "%");
}
allParticles = new TimelapseParticle(wholePointCollection, cal, totalGroupSize, skeletonize, gSigmaXY, gSigmaZ,
width, height, slices, frames, false, binarizeBeforeSkl, progress);
width, height, slices, frames, false, binarizeBeforeSkl, progress, noGUIs);
wholePointCollection.clear();
}else{
//separate objects over time
Expand Down Expand Up @@ -1080,19 +1090,18 @@ public void windowClosing(WindowEvent winEvt) {
floodNodes[index][3] = floodNodeT+1;
}
if(processedPxCount%(pxCount100)<pxCount1000){
progress.setBar(ProgressFactor0+ProgressFactor1*((double)(processedPxCount)/(double)(pxCount)));
progress.updateBarText("detecting particles ... " + dformat3.format(100.0*(double)(processedPxCount)/(double)(pxCount)) + "%");
if(!noGUIs) {
progress.setBar(ProgressFactor0+ProgressFactor1*((double)(processedPxCount)/(double)(pxCount)));
progress.updateBarText("detecting particles ... " + dformat3.format(100.0*(double)(processedPxCount)/(double)(pxCount)) + "%");
}
}
}
//Floodfiller

pointCollection.trimToSize();
//TimelapseParticle(ArrayList<imPoint> points, Calibration cal, double projectedFrames, boolean skeletonize,
//double gaussSigmaXY, double gaussSigmaZ, int orWidth, int orHeight, int orSlices, int orTimes, boolean minimizeImages,
//boolean binarizeBeforeSkeletonization, ProgressDialog progress)
particleCollection.add(new TimelapseParticle(pointCollection, cal, totalGroupSize, skeletonize,
gSigmaXY, gSigmaZ, width, height, slices, frames, true,
binarizeBeforeSkl, progress));
binarizeBeforeSkl, progress, noGUIs));
}
}
}
Expand All @@ -1112,7 +1121,7 @@ public void windowClosing(WindowEvent winEvt) {
}
//Filter particles

progress.setBar(0.8);
if(!noGUIs) progress.setBar(0.8);

/***************************************************************************
*#########################################################################*
Expand All @@ -1135,7 +1144,7 @@ public void windowClosing(WindowEvent winEvt) {
try{
new File(dir [task] + filePrefix).mkdirs();
}catch(Exception e){
progress.notifyMessage("failed to create subfolder to save additional plots! Will save plots into origianl folder!",ProgressDialog.NOTIFICATION);
if(!noGUIs) progress.notifyMessage("failed to create subfolder to save additional plots! Will save plots into origianl folder!",ProgressDialog.NOTIFICATION);
}

String RPSuffix = "_RP" + dformat0.format(minParticleVolume);
Expand Down Expand Up @@ -1602,7 +1611,7 @@ public void windowClosing(WindowEvent winEvt) {
}
}
}catch(Exception e){
progress.notifyMessage("Task " + task + "/" + tasks + ": error - could not correctly write results...",ProgressDialog.ERROR);
if(!noGUIs) progress.notifyMessage("Task " + task + "/" + tasks + ": error - could not correctly write results...",ProgressDialog.ERROR);
}
tw1.append("");
}
Expand Down Expand Up @@ -1640,7 +1649,7 @@ public void windowClosing(WindowEvent winEvt) {
v3D = new Visualizer3D(imp, 3.0f);
v3D.setAngle(10.0f, -10.0f, 0.0f);

progress.updateBarText("generating visualizations...");
if(!noGUIs) progress.updateBarText("generating visualizations...");
if(mergeSelection.equals(mergeOrNotMerge[0])){
IJ.saveAs(allParticles.particleImp, "tif", subfolderPrefix + RPSuffix + ".tif");
IJ.saveAs(allParticles.convexHullImp, "tif", subfolderPrefix + "_H.tif");
Expand All @@ -1654,7 +1663,7 @@ public void windowClosing(WindowEvent winEvt) {
for(int err = 0; err < e.getStackTrace().length; err++){
out += " \n " + e.getStackTrace()[err].toString();
}
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": No 3D visualization generated - an error occured: " + out,ProgressDialog.NOTIFICATION);
if(!noGUIs) progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": No 3D visualization generated - an error occured: " + out,ProgressDialog.NOTIFICATION);
}
allParticles.closeImps();
}else if(mergeSelection.equals(mergeOrNotMerge[1])){
Expand All @@ -1671,21 +1680,23 @@ public void windowClosing(WindowEvent winEvt) {
for(int err = 0; err < e.getStackTrace().length; err++){
out += " \n " + e.getStackTrace()[err].toString();
}
progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": An error occured when generating a 3D visualization - the analysis and all other output files than the missing 3D file are however unaffected and valid!"
if(!noGUIs) progress.notifyMessage("Task " + (task+1) + "/" + tasks + ": An error occured when generating a 3D visualization - the analysis and all other output files than the missing 3D file are however unaffected and valid!"
+ " Debuggin information: " + out + "",ProgressDialog.NOTIFICATION);
}
particleCollection.get(i).closeImps();
}
}
progress.setBar(0.9);
if(!noGUIs) progress.setBar(0.9);

//Save Images

//Save results text files

//Update Multi-Task-Manager
progress.setBar(1.0);
progress.moveTask(task);
if(!noGUIs) {
progress.setBar(1.0);
progress.moveTask(task);
}
break running;
}
}
Expand Down
Loading

0 comments on commit 678e28d

Please sign in to comment.