From a2641a3ec21cb7aec24628773aae066cb078fc41 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Wed, 13 Nov 2024 11:42:04 +0000 Subject: [PATCH] Model versioning and display --- .../ext/instanseg/core/InstanSegModel.java | 5 +-- .../ext/instanseg/ui/InstanSegController.java | 35 +++++++++++-------- .../ext/instanseg/ui/ModelListCell.java | 4 +-- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java b/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java index 8df1d4d..e2b41a6 100644 --- a/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java +++ b/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java @@ -48,8 +48,8 @@ private InstanSegModel(BioimageIoSpec.BioimageIoModel bioimageIoModel) { } private InstanSegModel(String name, URL modelURL) { - this.modelURL = modelURL; this.name = name; + this.modelURL = modelURL; } /** @@ -215,8 +215,9 @@ public String toString() { String name = getName(); String parent = getPath().map(Path::getFileName).map(Path::toString).orElse(null); String version = getModel().map(BioimageIoSpec.BioimageIoModel::getVersion).orElse(null); - if (parent != null && !Objects.equals(parent, name)) + if (parent != null && !parent.equals(name)) { name = parent + "/" + name; + } if (version != null) name += "-" + version; return name; diff --git a/src/main/java/qupath/ext/instanseg/ui/InstanSegController.java b/src/main/java/qupath/ext/instanseg/ui/InstanSegController.java index 5792243..f50715f 100644 --- a/src/main/java/qupath/ext/instanseg/ui/InstanSegController.java +++ b/src/main/java/qupath/ext/instanseg/ui/InstanSegController.java @@ -282,7 +282,6 @@ private void configureDefaultValues() { /** * Open the model directory in the system file browser when double-clicked. - * @param event */ @FXML void handleModelDirectoryLabelClick(MouseEvent event) { @@ -357,22 +356,28 @@ private void updateInputChannels(ImageData imageData) { // Return if we could store previously-saved checks - this will fail if the items have changed, // of if there were no previous checks (e.g. because its'a new model) return; - } else if (imageData.isBrightfield()) { - comboInputChannels.getCheckModel().checkIndices(IntStream.range(0, 3).toArray()); - var modelDir = InstanSegUtils.getModelDirectory().orElse(null); - if (model != null && modelDir != null && model.isDownloaded(modelDir)) { - var modelChannels = model.getNumChannels(); - if (modelChannels.isPresent()) { - int nModelChannels = modelChannels.get(); - if (nModelChannels != InstanSegModel.ANY_CHANNELS) { - comboInputChannels.getCheckModel().clearChecks(); - comboInputChannels.getCheckModel().checkIndices(0, 1, 2); - } - } + } - } - } else { + if (!imageData.isBrightfield()) { + // if fluorescence or similar, then bung in all channels comboInputChannels.getCheckModel().checkIndices(IntStream.range(0, imageData.getServer().nChannels()).toArray()); + return; + } + + // if brightfield, then check R, G, and B + comboInputChannels.getCheckModel().checkIndices(IntStream.range(0, 3).toArray()); + var modelDir = InstanSegUtils.getModelDirectory().orElse(null); + // todo: not clear why this is needed. is this handling the checkcombobox weirdness on clearing checks, or? + if (model != null && modelDir != null && model.isDownloaded(modelDir)) { + var modelChannels = model.getNumChannels(); + if (modelChannels.isPresent()) { + int nModelChannels = modelChannels.get(); + if (nModelChannels != InstanSegModel.ANY_CHANNELS) { + comboInputChannels.getCheckModel().clearChecks(); + comboInputChannels.getCheckModel().checkIndices(0, 1, 2); + } + } + } } diff --git a/src/main/java/qupath/ext/instanseg/ui/ModelListCell.java b/src/main/java/qupath/ext/instanseg/ui/ModelListCell.java index 0d896d8..d7e27e1 100644 --- a/src/main/java/qupath/ext/instanseg/ui/ModelListCell.java +++ b/src/main/java/qupath/ext/instanseg/ui/ModelListCell.java @@ -30,7 +30,7 @@ public void updateItem(InstanSegModel model, boolean empty) { setGraphic(null); setTooltip(null); } else { - setText(model.getName()); + setText(model.toString()); var dir = InstanSegUtils.getLocalModelDirectory().orElse(null); if (dir != null && !model.isDownloaded(dir)) { setGraphic(web); @@ -38,7 +38,7 @@ public void updateItem(InstanSegModel model, boolean empty) { setTooltip(tooltip); } else { setGraphic(null); - tooltip.setText(model.getName()); + tooltip.setText(model.toString()); setTooltip(tooltip); } }