Skip to content

Commit

Permalink
Add choice to load ROIs to ROI Manager or Overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Nov 5, 2023
1 parent 9df7e80 commit 951ff7b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fr/igred/ij/io/LocalBatchImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public ImageWrapper getImageWrapper() {
@Override
public ImagePlus getImagePlus(ROIMode mode) {
ImagePlus imp = null;
boolean loadROIs = !mode.toString().isEmpty();
boolean loadROIs = mode != ROIMode.DO_NOT_LOAD;
try {
ImporterOptions options = initImporterOptions();
options.setShowROIs(loadROIs);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/igred/ij/io/ROIMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
public enum ROIMode {
/**
* Do not load ROIs (empty String for ImporterOptions).
* Do not load ROIs.
*/
DO_NOT_LOAD(""),
DO_NOT_LOAD("No"),
/**
* Load ROIs in the ROI Manager.
*/
Expand All @@ -38,7 +38,7 @@ public enum ROIMode {
OVERLAY(ImporterOptions.ROIS_MODE_OVERLAY);

/**
* ROI mode String value for ImporterOptions.
* ROI mode String value for ImporterOptions and user selection.
*/
private final String value;

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/fr/igred/ij/macro/BatchParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
package fr.igred.ij.macro;


import fr.igred.ij.io.ROIMode;


/**
* Holds the parameters to batch run scripts.
*/
public class BatchParameters {

private boolean loadROIs;
private ROIMode roiMode;
private boolean saveImages;
private boolean saveROIs;
private boolean saveResults;
Expand All @@ -40,7 +43,7 @@ public class BatchParameters {
* Default constructor.
*/
public BatchParameters() {
this.loadROIs = false;
this.roiMode = ROIMode.DO_NOT_LOAD;
this.saveImages = false;
this.saveROIs = false;
this.saveResults = false;
Expand All @@ -61,7 +64,7 @@ public BatchParameters() {
* @param parameters The parameters to copy.
*/
public BatchParameters(BatchParameters parameters) {
this.loadROIs = parameters.loadROIs;
this.roiMode = parameters.roiMode;
this.saveImages = parameters.saveImages;
this.saveROIs = parameters.saveROIs;
this.saveResults = parameters.saveResults;
Expand Down Expand Up @@ -185,18 +188,18 @@ public void setSaveImages(boolean saveImages) {
*
* @return See above.
*/
public boolean shouldLoadROIs() {
return loadROIs;
public ROIMode getROIMode() {
return roiMode;
}


/**
* Sets whether the ROIs should be loaded or not.
*
* @param loadROIs See above.
* @param roiMode See above.
*/
public void setLoadROIS(boolean loadROIs) {
this.loadROIs = loadROIs;
public void setROIMode(ROIMode roiMode) {
this.roiMode = roiMode;
}


Expand Down
8 changes: 2 additions & 6 deletions src/main/java/fr/igred/ij/macro/OMEROBatchRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,23 +494,19 @@ private List<ROIWrapper> getROIsFromManager(ImagePlus imp, String property) {
/**
* Runs a macro on images and saves the results.
*/
void runMacro() {
private void runMacro() {
String property = ROIWrapper.IJ_PROPERTY;
WindowManager.closeAllWindows();

// Initialize ROI Manager
initRoiManager();
ROIMode roiMode = ROIMode.DO_NOT_LOAD;
if (params.shouldLoadROIs()) {
roiMode = ROIMode.MANAGER;
}

int index = 0;
for (BatchImage image : images) {
//noinspection HardcodedFileSeparator
setProgress("Image " + (index + 1) + "/" + images.size());
setState("Opening image...");
ImagePlus imp = image.getImagePlus(roiMode);
ImagePlus imp = image.getImagePlus(params.getROIMode());
// If image could not be loaded, continue to next image.
if (imp != null) {
ImageWrapper imageWrapper = image.getImageWrapper();
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/fr/igred/ij/plugin/frame/OMEROBatchPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import fr.igred.ij.gui.OMEROConnectDialog;
import fr.igred.ij.gui.ProgressDialog;
import fr.igred.ij.io.BatchImage;
import fr.igred.ij.io.ROIMode;
import fr.igred.ij.macro.BatchListener;
import fr.igred.ij.macro.BatchParameters;
import fr.igred.ij.macro.OMEROBatchRunner;
Expand Down Expand Up @@ -97,7 +98,7 @@ public class OMEROBatchPlugin extends PlugInFrame implements BatchListener {
// choices of input images
private final JPanel input1a = new JPanel();
private final JPanel input1b = new JPanel();
private final JPanel input1c = new JPanel();
private final JPanel input3 = new JPanel();
private final JPanel input2 = new JPanel();

// group and user selection
Expand All @@ -113,8 +114,8 @@ public class OMEROBatchPlugin extends PlugInFrame implements BatchListener {
private final JComboBox<String> datasetListIn = new JComboBox<>();
/** The checkbox to delete ROIs. */
private final JCheckBox checkDelROIs = new JCheckBox("Clear ROIs each time");
/** The checkbox to load ROIs. */
private final JCheckBox checkLoadROIs = new JCheckBox("Load ROIs");
/** The list of possible output projects. */
private final JComboBox<ROIMode> roiMode = new JComboBox<>(ROIMode.values());

// choice of the record
/** The input folder. */
Expand Down Expand Up @@ -286,9 +287,6 @@ public OMEROBatchPlugin() {
projectListIn.setFont(listFont);
datasetListIn.setFont(listFont);

input1c.add(checkLoadROIs);
input1c.add(checkDelROIs);

JLabel inputFolderLabel = new JLabel("Images folder: ");
JButton inputFolderBtn = new JButton(browse);
inputFolderLabel.setLabelFor(inputFolder);
Expand All @@ -300,11 +298,16 @@ public OMEROBatchPlugin() {
input2.add(recursive);
inputFolderBtn.addActionListener(e -> chooseDirectory(inputFolder));

JLabel labelROIMode = new JLabel("Load ROIs: ");
input3.add(labelROIMode);
input3.add(roiMode);
input3.add(checkDelROIs);

JPanel panelInput = new JPanel();
panelInput.add(input1a);
panelInput.add(input1b);
panelInput.add(input1c);
panelInput.add(input2);
panelInput.add(input3);
panelInput.setLayout(new BoxLayout(panelInput, BoxLayout.PAGE_AXIS));
panelInput.setBorder(BorderFactory.createTitledBorder("Input"));
super.add(panelInput);
Expand Down Expand Up @@ -422,12 +425,12 @@ public OMEROBatchPlugin() {
input2.setVisible(false);
input1a.setVisible(true);
input1b.setVisible(true);
input1c.setVisible(true);
input3.setVisible(true);
super.pack();

input1a.setMaximumSize(new Dimension(input1a.getMaximumSize().width, input1a.getHeight()));
input1b.setMaximumSize(new Dimension(input1b.getMaximumSize().width, input1b.getHeight()));
input1c.setMaximumSize(new Dimension(input1c.getMaximumSize().width, input1c.getHeight()));
input3.setMaximumSize(new Dimension(input3.getMaximumSize().width, input3.getHeight()));

local.setSelected(true);

Expand Down Expand Up @@ -799,17 +802,15 @@ private void updateInput(ItemEvent e) {
if (connected) {
input1a.setVisible(true);
input1b.setVisible(true);
input1c.setVisible(true);
input1c.add(checkLoadROIs);
input2.setVisible(false);
checkDelROIs.setVisible(true);
} else {
local.setSelected(true);
}
} else { //local.isSelected()
input2.setVisible(true);
input2.add(checkLoadROIs);
checkDelROIs.setSelected(false);
input1c.setVisible(false);
checkDelROIs.setVisible(false);
input1b.setVisible(false);
input1a.setVisible(false);
}
Expand Down Expand Up @@ -999,7 +1000,7 @@ public void start(ActionEvent e) {

// input data
params.setSuffix(suffix.getText());
params.setLoadROIS(checkLoadROIs.isSelected());
params.setROIMode(roiMode.getItemAt(roiMode.getSelectedIndex()));
params.setClearROIS(checkDelROIs.isSelected());
params.setSaveImages(checkImage.isSelected());
params.setSaveResults(checkResults.isSelected());
Expand Down

0 comments on commit 951ff7b

Please sign in to comment.