Skip to content

Commit 8135db5

Browse files
authored
Merge pull request #12 from Rylern/main
Updated QuPath version to 0.5.0
2 parents a42b4f4 + 10f606c commit 8135db5

9 files changed

Lines changed: 54 additions & 30 deletions

File tree

build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ plugins {
55
id 'com.github.johnrengelman.shadow' version '7.1.2'
66
// Include this plugin to avoid downloading JavaCPP dependencies for all platforms
77
id 'org.bytedeco.gradle-javacpp-platform'
8+
// Include JavaFX dependencies
9+
alias(libs.plugins.javafx)
810
}
911

1012
// TODO: Change the module name
1113
ext.moduleName = 'org.elephant.sam.qupath'
1214

1315
// TODO: Define the extension version & provide a short description
14-
version = "0.4.1"
16+
version = "0.5.0"
1517
description = 'QuPath extension for Segment Anything Model (SAM)'
1618

1719
// TODO: Specify the QuPath version, compatible with the extension.
@@ -20,7 +22,7 @@ ext.qupathVersion = gradle.ext.qupathVersion
2022

2123
// TODO: Specify the Java version compatible with the extension
2224
// Generally 11 for QuPath v0.4.3, but will be 17 for QuPath v0.5.0
23-
ext.qupathJavaVersion = 11
25+
ext.qupathJavaVersion = 17
2426

2527
/**
2628
* Define dependencies.
@@ -39,6 +41,9 @@ dependencies {
3941
// Automatically includes other QuPath jars as subdependencies.
4042
shadow "io.github.qupath:qupath-gui-fx:${qupathVersion}"
4143

44+
// QuPath FX utils
45+
shadow libs.qupath.fxtras
46+
4247
// For logging - the version comes from QuPath's version catalog at
4348
// https://github.com/qupath/qupath/blob/main/gradle/libs.versions.toml
4449
// See https://docs.gradle.org/current/userguide/platforms.html

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rootProject.name = 'qupath-extension-sam'
1414
// TODO: Define the QuPath version compatible with the extension
1515
// Note that the QuPath API isn't stable; something designed for
1616
// 0.X.a should work with 0.X.b, but not necessarily with 0.Y.a.
17-
gradle.ext.qupathVersion = "0.4.3"
17+
gradle.ext.qupathVersion = "0.5.0"
1818

1919
dependencyResolutionManagement {
2020

src/main/java/org/elephant/sam/SAMExtension.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import org.controlsfx.control.action.Action;
44
import org.elephant.sam.commands.SAMMainCommand;
5-
import qupath.lib.gui.ActionTools;
6-
import qupath.lib.gui.ActionTools.ActionDescription;
7-
import qupath.lib.gui.ActionTools.ActionMenu;
5+
import qupath.lib.gui.actions.ActionTools;
6+
import qupath.lib.common.Version;
87
import qupath.lib.gui.QuPathGUI;
8+
import qupath.lib.gui.actions.annotations.ActionMenu;
9+
import qupath.lib.gui.extensions.GitHubProject;
910
import qupath.lib.gui.extensions.QuPathExtension;
1011

1112
/**
1213
* QuPath extension for SegmentAnything Model (SAM).
1314
*/
14-
public class SAMExtension implements QuPathExtension {
15+
public class SAMExtension implements QuPathExtension, GitHubProject {
1516

1617
/**
1718
* Get the description of the extension.
@@ -38,8 +39,6 @@ public void installExtension(QuPathGUI qupath) {
3839
@ActionMenu("Extensions")
3940
public class SAMCommands {
4041

41-
@ActionMenu("SAM")
42-
@ActionDescription("Launch SAM dialog.")
4342
public final Action actionSAMCommand;
4443

4544
/**
@@ -50,9 +49,19 @@ public class SAMCommands {
5049
*/
5150
private SAMCommands(QuPathGUI qupath) {
5251
SAMMainCommand samCommand = new SAMMainCommand(qupath);
53-
actionSAMCommand = new Action(event -> samCommand.run());
52+
actionSAMCommand = new Action("SAM", event -> samCommand.run());
5453
}
5554

5655
}
5756

57+
@Override
58+
public GitHubRepo getRepository() {
59+
return GitHubRepo.create(getName(), "ksugar", "qupath-extension-sam");
60+
}
61+
62+
@Override
63+
public Version getQuPathVersion() {
64+
return Version.parse("0.5.0");
65+
}
66+
5867
}

src/main/java/org/elephant/sam/Utils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ public static void setNameForSAM(PathObject pathObject) {
183183
* @return the quality score, or null if no score could be found
184184
*/
185185
static Double getSAMQuality(PathObject pathObject) {
186-
return pathObject.getMeasurements().getOrDefault(SAM_QUALITY_MEASUREMENT, null);
186+
return (Double) pathObject.getMeasurements()
187+
.getOrDefault(SAM_QUALITY_MEASUREMENT, null);
187188
}
188189

189190
/**
@@ -204,8 +205,9 @@ public static void setRandomColor(PathObject pathObject) {
204205
*
205206
* @param viewer
206207
* @return the image server
208+
* @throws IOException
207209
*/
208-
public static ImageServer<BufferedImage> createRenderedServer(QuPathViewer viewer) {
210+
public static ImageServer<BufferedImage> createRenderedServer(QuPathViewer viewer) throws IOException {
209211
return new RenderedImageServer.Builder(viewer.getImageData())
210212
.store(viewer.getImageRegionStore())
211213
.renderer(viewer.getImageDisplay())

src/main/java/org/elephant/sam/commands/SAMMainCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
import javafx.scene.Scene;
4747
import javafx.scene.layout.Pane;
4848
import javafx.stage.Stage;
49+
import qupath.fx.dialogs.Dialogs;
4950
import qupath.lib.common.ThreadTools;
5051
import qupath.lib.gui.QuPathGUI;
51-
import qupath.lib.gui.dialogs.Dialogs;
5252
import qupath.lib.gui.prefs.PathPrefs;
5353
import qupath.lib.gui.viewer.QuPathViewer;
5454
import qupath.lib.images.ImageData;

src/main/java/org/elephant/sam/tasks/SAMAutoMaskTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ private SAMAutoMaskTask(Builder builder) {
109109
logger.warn("Cannot use non-RGB image server for SAM auto mask!");
110110
}
111111
if (this.renderedServer == null) {
112-
this.renderedServer = Utils.createRenderedServer(viewer);
112+
try {
113+
this.renderedServer = Utils.createRenderedServer(viewer);
114+
} catch (IOException e) {
115+
logger.error("Failed to create rendered server", e);
116+
}
113117
}
114118

115119
// Find the region and downsample currently used within the viewer

src/main/java/org/elephant/sam/tasks/SAMDetectionTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ private SAMDetectionTask(Builder builder) {
9292
logger.warn("Cannot use non-RGB image server for detection!");
9393
}
9494
if (this.renderedServer == null) {
95-
this.renderedServer = Utils.createRenderedServer(viewer);
95+
try {
96+
this.renderedServer = Utils.createRenderedServer(viewer);
97+
} catch (IOException e) {
98+
logger.error("Failed to create rendered server", e);
99+
}
96100
}
97101

98102
// Find the region and downsample currently used within the viewer

src/main/java/org/elephant/sam/ui/SAMPromptPane.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import javafx.scene.layout.Pane;
2323
import javafx.scene.layout.Priority;
2424
import javafx.scene.layout.VBox;
25-
import qupath.lib.gui.ActionTools;
25+
import qupath.lib.gui.actions.ActionTools;
2626
import qupath.lib.gui.prefs.PathPrefs;
2727
import qupath.lib.gui.viewer.tools.PathTools;
2828
import qupath.lib.objects.classes.PathClass;
@@ -73,14 +73,14 @@ public SAMPromptPane(SAMMainCommand command) {
7373
}
7474

7575
private void addCommandPane(int row) {
76-
Action actionRectangle = command.getQuPath().getToolAction(PathTools.RECTANGLE);
77-
ToggleButton btnRectangle = ActionTools.createToggleButton(actionRectangle, true);
76+
Action actionRectangle = command.getQuPath().getToolManager().getToolAction(PathTools.RECTANGLE);
77+
ToggleButton btnRectangle = ActionTools.createToggleButtonWithGraphicOnly(actionRectangle);
7878

79-
Action actionPoints = command.getQuPath().getToolAction(PathTools.POINTS);
80-
ToggleButton btnPoints = ActionTools.createToggleButton(actionPoints, true);
79+
Action actionPoints = command.getQuPath().getToolManager().getToolAction(PathTools.POINTS);
80+
ToggleButton btnPoints = ActionTools.createToggleButtonWithGraphicOnly(actionPoints);
8181

82-
Action actionMove = command.getQuPath().getToolAction(PathTools.MOVE);
83-
ToggleButton btnMove = ActionTools.createToggleButton(actionMove, true);
82+
Action actionMove = command.getQuPath().getToolManager().getToolAction(PathTools.MOVE);
83+
ToggleButton btnMove = ActionTools.createToggleButtonWithGraphicOnly(actionMove);
8484

8585
Label label = new Label("Draw prompts");
8686
label.setTooltip(new Tooltip("Draw foreground or background prompts.\n" +
@@ -90,14 +90,14 @@ private void addCommandPane(int row) {
9090
"Draw foreground prompt.\n" +
9191
"Requires rectangle or point tool to be selected."));
9292
radioForeground.disableProperty().bind(
93-
command.getQuPath().selectedToolProperty().isNotEqualTo(PathTools.POINTS).and(
94-
command.getQuPath().selectedToolProperty().isNotEqualTo(PathTools.RECTANGLE)));
93+
command.getQuPath().getToolManager().selectedToolProperty().isNotEqualTo(PathTools.POINTS).and(
94+
command.getQuPath().getToolManager().selectedToolProperty().isNotEqualTo(PathTools.RECTANGLE)));
9595
RadioButton radioBackground = new RadioButton("Background");
9696
radioBackground.setTooltip(new Tooltip(
9797
"Draw background prompt.\n" +
9898
"Requires point tool to be selected."));
9999
radioBackground.disableProperty()
100-
.bind(command.getQuPath().selectedToolProperty().isNotEqualTo(PathTools.POINTS));
100+
.bind(command.getQuPath().getToolManager().selectedToolProperty().isNotEqualTo(PathTools.POINTS));
101101
ObjectProperty<PathClass> autoAnnotation = PathPrefs.autoSetAnnotationClassProperty();
102102
if (autoAnnotation.get() != null && PathClassTools.isIgnoredClass(autoAnnotation.get()))
103103
radioBackground.setSelected(true);

src/main/java/org/elephant/sam/ui/SAMUIUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javafx.scene.layout.ColumnConstraints;
99
import javafx.scene.layout.GridPane;
1010
import javafx.scene.layout.Priority;
11-
import qupath.lib.gui.tools.GuiTools;
11+
import qupath.fx.utils.FXUtils;
1212

1313
/**
1414
* Utilities for the SAM UI.
@@ -80,8 +80,8 @@ public static Spinner<Integer> createIntegerSpinner(int min, int max, IntegerPro
8080
spinner.setTooltip(new Tooltip(tooltipText));
8181
property.asObject().bindBidirectional(spinner.getValueFactory().valueProperty());
8282
spinner.setEditable(true);
83-
GuiTools.restrictTextFieldInputToNumber(spinner.getEditor(), false);
84-
GuiTools.resetSpinnerNullToPrevious(spinner);
83+
FXUtils.restrictTextFieldInputToNumber(spinner.getEditor(), false);
84+
FXUtils.resetSpinnerNullToPrevious(spinner);
8585
spinner.focusedProperty().addListener((v, o, n) -> {
8686
if (spinner.getEditor().getText().equals(""))
8787
spinner.getValueFactory().valueProperty().set(min);
@@ -118,8 +118,8 @@ public static Spinner<Double> createDoubleSpinner(double min, double max, Double
118118
spinner.setTooltip(new Tooltip(tooltipText));
119119
property.asObject().bindBidirectional(spinner.getValueFactory().valueProperty());
120120
spinner.setEditable(true);
121-
GuiTools.restrictTextFieldInputToNumber(spinner.getEditor(), true);
122-
GuiTools.resetSpinnerNullToPrevious(spinner);
121+
FXUtils.restrictTextFieldInputToNumber(spinner.getEditor(), true);
122+
FXUtils.resetSpinnerNullToPrevious(spinner);
123123
spinner.focusedProperty().addListener((v, o, n) -> {
124124
if (spinner.getEditor().getText().equals(""))
125125
spinner.getValueFactory().valueProperty().set(min);

0 commit comments

Comments
 (0)