Skip to content

Commit

Permalink
Sim Listeners Pass Image Result
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Oct 18, 2024
1 parent 802ca0e commit f941014
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.vcell.N5.UI.MainPanel;
import org.vcell.N5.UI.N5ExportTable;
import org.vcell.N5.retrieving.LoadingFactory;
import org.vcell.N5.retrieving.LoadingManager;
import org.vcell.N5.retrieving.SimResultsLoader;

import java.io.*;
Expand All @@ -34,12 +33,12 @@ public class N5ImageHandler implements Command {
public static MainPanel exportTable;
public static String exportedMetaDataPath = System.getProperty("user.home") + "/.vcell/exportMetaData.json";
private static ExportDataRepresentation.FormatExportDataRepresentation exampleJSONData;
public static LoadingFactory loadingFactory;
public static LoadingManager loadingManager;

@Override
public void run() {
initializeLogService();
loadingFactory = new LoadingFactory();
loadingManager = new LoadingManager();
exportTable = new MainPanel();
setExampleJSONData();
// N5ImageHandler.logService.setLevel(LogService.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vcell.N5.UI;

import ij.ImagePlus;
import org.scijava.log.Logger;
import org.vcell.N5.ExportDataRepresentation;
import org.vcell.N5.N5ImageHandler;
Expand Down Expand Up @@ -41,7 +42,7 @@ public N5ExportTable(){}
public void initialize(ControlButtonsPanel controlButtonsPanel, ExportDetailsPanel exportDetailsPanel){
this.controlPanel = controlButtonsPanel;
this.exportDetailsPanel = exportDetailsPanel;
N5ImageHandler.loadingFactory.addSimLoadingListener(this);
N5ImageHandler.loadingManager.addSimLoadingListener(this);
n5ExportTableModel = new N5ExportTableModel();
exportListTable = new JTable(n5ExportTableModel);
this.setViewportView(exportListTable);
Expand Down Expand Up @@ -181,7 +182,7 @@ public void openSelectedRows(boolean inMemory){
SimResultsLoader simResultsLoader = new SimResultsLoader(uri, rowData.savedFileName, row, rowData.jobID);
filesToOpen.add(simResultsLoader);
}
N5ImageHandler.loadingFactory.openN5FileDataset(filesToOpen, inMemory);
N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, inMemory);
}

public void copySelectedRowLink(){
Expand Down Expand Up @@ -227,7 +228,7 @@ public void valueChanged(ListSelectionEvent e) {

public void removeFromLoadingRows(){
int row = exportListTable.getSelectedRow();
N5ImageHandler.loadingFactory.stopOpeningSimulation(n5ExportTableModel.tableData.get(row).jobID);
N5ImageHandler.loadingManager.stopOpeningSimulation(n5ExportTableModel.tableData.get(row).jobID);
loadingRowsJobID.remove(row);
exportListTable.repaint();
}
Expand All @@ -239,10 +240,11 @@ public void simIsLoading(int itemRow, String exportID) {
}

@Override
public void simFinishedLoading(int itemRow, String exportID) {
public void simFinishedLoading(int itemRow, String exportID, ImagePlus imagePlus) {
loadingRowsJobID.remove(itemRow);
exportListTable.repaint();
controlPanel.allowCancel(false);
imagePlus.show();
}

static class N5ExportTableModel extends AbstractTableModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public String getS3URL(){
@Override
public void actionPerformed(ActionEvent e) {
SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, "");
N5ImageHandler.loadingFactory.openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}}, false);
N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}}, false);
this.setVisible(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void displayGUI(){
0, 0, 0,
5, saveToFile.getSelectedFile()
);
N5ImageHandler.loadingFactory.addSimLoadingListener(dataReduction);
N5ImageHandler.loadingManager.addSimLoadingListener(dataReduction);
});
thread.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.ArrayList;
import java.util.HashMap;

public class LoadingFactory implements SimLoadingEventCreator {
public class LoadingManager implements SimLoadingEventCreator {
private static final EventListenerList eventListenerList = new EventListenerList();

private final ControlButtonsPanel controlButtonsPanel = MainPanel.controlButtonsPanel;
Expand All @@ -35,6 +35,7 @@ public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean o
for (int i = 0; i < filesToOpen.size(); i++){
SimResultsLoader simResultsLoader = filesToOpen.get(i);
Thread openThread = new Thread(() -> {
ImagePlus imagePlus = null;
try{
simResultsLoader.createS3ClientAndReader();
notifySimIsLoading(simResultsLoader);
Expand All @@ -44,12 +45,11 @@ public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean o
rangeSelector = new RangeSelector(dimensions.get(2), dimensions.get(3), dimensions.get(4), simResultsLoader.userSetFileName);
rangeSelector.displayRangeMenu();
if (!rangeSelector.cancel){
openInMemory(simResultsLoader, rangeSelector);
imagePlus = openInMemory(simResultsLoader, rangeSelector);
}
rangeSelector.dispose();
} else{
ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File();
imagePlus.show();
imagePlus = simResultsLoader.getImgPlusFromN5File();
}
}
catch (RuntimeException e) {
Expand All @@ -65,7 +65,7 @@ public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean o
} finally {
MainPanel.changeCursor(new Cursor(Cursor.DEFAULT_CURSOR));
controlButtonsPanel.enableCriticalButtons(true);
notifySimIsDoneLoading(simResultsLoader);
notifySimIsDoneLoading(simResultsLoader, imagePlus);
synchronized (openSimulationsLock){
openingSimulations.remove(simResultsLoader.exportID);
}
Expand All @@ -79,15 +79,15 @@ public void openN5FileDataset(ArrayList<SimResultsLoader> filesToOpen, boolean o
}
}

private void openInMemory(SimResultsLoader simResultsLoader, RangeSelector rangeSelector) throws IOException {
private ImagePlus openInMemory(SimResultsLoader simResultsLoader, RangeSelector rangeSelector) throws IOException {
ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File();
long start = System.currentTimeMillis();
logger.debug("Loading Virtual N5 File " + simResultsLoader.userSetFileName + " Into Memory");
imagePlus = new Duplicator().run(imagePlus, rangeSelector.startC, rangeSelector.endC, rangeSelector.startZ,
rangeSelector.endZ, rangeSelector.startT, rangeSelector.endT);
long end = System.currentTimeMillis();
logger.debug("Loaded Virtual N5 File " + simResultsLoader.userSetFileName + " Into Memory taking: " + ((end - start)/ 1000) + "s");
imagePlus.show();
return imagePlus;
}

public void stopOpeningSimulation(String exportID){
Expand Down Expand Up @@ -145,9 +145,9 @@ public void notifySimIsLoading(SimResultsLoader simResultsLoader) {
}

@Override
public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader) {
public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader, ImagePlus imagePlus) {
for (SimLoadingListener simLoadingListener: eventListenerList.getListeners(SimLoadingListener.class)){
simLoadingListener.simFinishedLoading(simResultsLoader.rowNumber, simResultsLoader.exportID);
simLoadingListener.simFinishedLoading(simResultsLoader.rowNumber, simResultsLoader.exportID, imagePlus);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.vcell.N5.retrieving;

import ij.ImagePlus;

public interface SimLoadingEventCreator {
public void addSimLoadingListener(SimLoadingListener simLoadingListener);

public void notifySimIsLoading(SimResultsLoader simResultsLoader);

public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader);
public void notifySimIsDoneLoading(SimResultsLoader simResultsLoader, ImagePlus imagePlus);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.vcell.N5.retrieving;

import ij.ImagePlus;

import java.util.EventListener;

public interface SimLoadingListener extends EventListener {

public void simIsLoading(int itemRow, String exportID);

public void simFinishedLoading(int itemRow, String exportID);
public void simFinishedLoading(int itemRow, String exportID, ImagePlus imagePlus);

}

0 comments on commit f941014

Please sign in to comment.