Skip to content

Commit d250765

Browse files
Add UX improvements into QuPath extension (#1514)
Signed-off-by: Ivan Vykopal <[email protected]> Co-authored-by: SACHIDANAND ALLE <[email protected]>
1 parent 8ad073b commit d250765

File tree

1 file changed

+46
-3
lines changed
  • plugins/qupath/src/main/java/qupath/lib/extension/monailabel/commands

1 file changed

+46
-3
lines changed

plugins/qupath/src/main/java/qupath/lib/extension/monailabel/commands/RunInference.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626

2727
import javax.xml.parsers.ParserConfigurationException;
2828

29+
import org.controlsfx.dialog.ProgressDialog;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
3132
import org.w3c.dom.Document;
3233
import org.w3c.dom.Node;
3334
import org.w3c.dom.NodeList;
3435
import org.xml.sax.SAXException;
3536

37+
import javafx.concurrent.Task;
3638
import qupath.lib.extension.monailabel.MonaiLabelClient;
3739
import qupath.lib.extension.monailabel.MonaiLabelClient.RequestInfer;
3840
import qupath.lib.extension.monailabel.MonaiLabelClient.ResponseInfo;
@@ -76,9 +78,15 @@ public void run() {
7678
var selected = imageData.getHierarchy().getSelectionModel().getSelectedObject();
7779
var roi = selected != null ? selected.getROI() : null;
7880

81+
if (roi == null || !(roi instanceof RectangleROI)) {
82+
Dialogs.showPlainMessage("Please create and select ROI", "Please create and select a Rectangle ROI before " +
83+
"running this method.\nThe \"Annotations\" function creates annotations within the selected rectangle.");
84+
return;
85+
}
86+
7987
String imageFile = Utils.getFileName(viewer.getImageData().getServerPath());
8088
String im = imageFile.toLowerCase();
81-
boolean isWSI = (im.endsWith(".png") || im.endsWith(".jpg") || im.endsWith(".jpeg")) ? false : true;
89+
boolean isWSI = !im.endsWith(".png") && !im.endsWith(".jpg") && !im.endsWith(".jpeg");
8290
logger.info("MONAILabel:: isWSI: " + isWSI + "; File: " + imageFile);
8391

8492
// Select first RectangleROI if not selected explicitly
@@ -112,6 +120,7 @@ public void run() {
112120

113121
ParameterList list = new ParameterList();
114122
list.addChoiceParameter("Model", "Model Name", selectedModel, names);
123+
list.addTitleParameter("Parameters of selected ROI:");
115124
if (isWSI) {
116125
list.addStringParameter("Location", "Location (x,y,w,h)", Arrays.toString(bbox));
117126
list.addIntParameter("TileSize", "TileSize", tileSize);
@@ -131,8 +140,42 @@ public void run() {
131140
selectedBBox = bbox;
132141
selectedTileSize = tileSize;
133142

134-
runInference(model, info, bbox, tileSize, imageData, imageFile, isWSI);
143+
// runInference(model, info, bbox, tileSize, imageData, imageFile, isWSI);
144+
final int[] finalBbox = bbox;
145+
final int finalTileSize = tileSize;
146+
147+
Task<Void> task = new Task<Void>() {
148+
@Override
149+
protected Void call() throws Exception {
150+
runInference(model, info, finalBbox, finalTileSize, imageData, imageFile, isWSI);
151+
return null;
152+
}
153+
};
154+
155+
ProgressDialog progressDialog = new ProgressDialog(task);
156+
progressDialog.setTitle("MONAILabel");
157+
progressDialog.setHeaderText("Server-side processing is in progress, please wait...");
158+
progressDialog.setContentText("Annotations will be drawn immediately after the method ends.");
159+
progressDialog.initOwner(qupath.getStage());
160+
161+
// Start the inference
162+
new Thread(task).start();
163+
164+
task.setOnSucceeded(event -> {
165+
progressDialog.close();
166+
});
167+
task.setOnFailed(event -> {
168+
progressDialog.close();
169+
Throwable ex = task.getException();
170+
if (ex != null) {
171+
ex.printStackTrace();
172+
Dialogs.showErrorMessage("MONAILabel", ex);
173+
}
174+
});
135175
}
176+
177+
imageData.getHierarchy().removeObject(imageData.getHierarchy().getSelectionModel().getSelectedObject(), true);
178+
imageData.getHierarchy().getSelectionModel().clearSelection();
136179
} catch (Exception ex) {
137180
ex.printStackTrace();
138181
Dialogs.showErrorMessage("MONAILabel", ex);
@@ -296,7 +339,7 @@ public static int updateAnnotations(Set<String> labels, NodeList annotation_list
296339
int color = Color.RED.getRGB();
297340
Node colorNode = annotation.getAttributes().getNamedItem("Color");
298341
if (colorNode != null) {
299-
color = Integer.parseInt(colorNode.getTextContent().replaceFirst("#", ""), 16) ;
342+
color = Integer.parseInt(colorNode.getTextContent().replaceFirst("#", ""), 16);
300343
// logger.info("Annotation Class: " + annotationClass + " Annotation Color: " + colorNode.getTextContent());
301344
}
302345

0 commit comments

Comments
 (0)