Skip to content

Commit

Permalink
Model versioning and display
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Nov 13, 2024
1 parent 13fbb2f commit a2641a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/main/java/qupath/ext/instanseg/core/InstanSegModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ private InstanSegModel(BioimageIoSpec.BioimageIoModel bioimageIoModel) {
}

private InstanSegModel(String name, URL modelURL) {
this.modelURL = modelURL;
this.name = name;
this.modelURL = modelURL;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/qupath/ext/instanseg/ui/InstanSegController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -357,22 +356,28 @@ private void updateInputChannels(ImageData<BufferedImage> 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);
}
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/qupath/ext/instanseg/ui/ModelListCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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);
tooltip.setText(resources.getString("ui.model-not-downloaded.tooltip"));
setTooltip(tooltip);
} else {
setGraphic(null);
tooltip.setText(model.getName());
tooltip.setText(model.toString());
setTooltip(tooltip);
}
}
Expand Down

0 comments on commit a2641a3

Please sign in to comment.