Skip to content

Commit

Permalink
added load view
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Dec 27, 2024
1 parent 8060be4 commit 5edeb79
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 91 deletions.
22 changes: 18 additions & 4 deletions src/main/java/bigtrace/BigTrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

Expand Down Expand Up @@ -68,6 +70,7 @@
import bigtrace.geometry.Line3D;
import bigtrace.gui.AnisotropicTransformAnimator3D;
import bigtrace.gui.GuiMisc;
import bigtrace.io.ViewsIO;
import bigtrace.math.OneClickTrace;
import bigtrace.math.TraceBoxMath;
import bigtrace.math.TracingBGVect;
Expand Down Expand Up @@ -198,7 +201,7 @@ public void run(String arg)

if(btData.sFileNameFullImg == null)
return;

btData.lastDir = Paths.get(btData.sFileNameFullImg ).getParent().toString();
//load data sources

// TIF files are fully loaded (to RAM) for now
Expand Down Expand Up @@ -339,8 +342,19 @@ public void windowClosing( WindowEvent ev )
};

btPanel.finFrame.addWindowListener( closeWA );
bvvFrame.addWindowListener( closeWA);
bvvFrame.addWindowListener( closeWA );
bInputLock = false;

//check if there is a saved view
File f = new File(btData.sFileNameFullImg+"_btview.csv");
if(f.exists() && !f.isDirectory())
{
if (JOptionPane.showConfirmDialog(null, "There is a saved view state for this file,\ndo you want to load it?", "Load saved view?",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
ViewsIO.loadView( this, btData.sFileNameFullImg+"_btview.csv" );
}
}
}

public void closeWindows()
Expand Down Expand Up @@ -1487,8 +1501,8 @@ public static void main(String... args) throws Exception
new ImageJ();
BigTrace testI = new BigTrace();

//testI.run("");
testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
testI.run("");
//testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/ExM_MT.tif");
///testI.run("/home/eugene/Desktop/projects/BigTrace/BT_tracks/Snejana_small_example.tif");
//testI.run("/home/eugene/Desktop/projects/BigTrace/BigTrace_data/Nefeli_test/20230815_DNAH5_volume_time_Experiment-1397.czi");

Expand Down
132 changes: 82 additions & 50 deletions src/main/java/bigtrace/BigTraceControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

import javax.swing.ImageIcon;
import javax.swing.JButton;
Expand Down Expand Up @@ -49,6 +51,7 @@
import bigtrace.volume.ExtractClip;
import bvvpg.vistools.BvvStackSource;
import ij.Prefs;
import ij.io.OpenDialog;
import ij.io.SaveDialog;

import net.imglib2.FinalInterval;
Expand Down Expand Up @@ -90,6 +93,7 @@ public class BigTraceControlPanel< T extends RealType< T > & NativeType< T > > e
JButton butSaveView;
JButton butLoadView;
JButton butSettings;


public ColorUserSettings selectColors = new ColorUserSettings();

Expand Down Expand Up @@ -165,21 +169,21 @@ public void activeRoiChanged(int nRoi) {


GridBagConstraints cv = new GridBagConstraints();
cv.gridx=0;
cv.gridy=0;
cv.weightx=0.5;
cv.weighty=1.0;
cv.gridx = 0;
cv.gridy = 0;
cv.weightx = 0.5;
cv.weighty = 1.0;
cv.anchor = GridBagConstraints.NORTHWEST;
cv.gridwidth = GridBagConstraints.REMAINDER;
cv.fill = GridBagConstraints.HORIZONTAL;
cv.fill = GridBagConstraints.BOTH;

this.add(tabPane,cv);
cv.gridx=0;
cv.gridy=1;
cv.gridx = 0;
cv.gridy = 1;
cv.gridwidth = GridBagConstraints.RELATIVE;
cv.gridheight = GridBagConstraints.RELATIVE;
cv.weighty=0.01;
cv.weighty = 0.01;
cv.anchor = GridBagConstraints.SOUTHEAST;
cv.fill = GridBagConstraints.HORIZONTAL;

Expand Down Expand Up @@ -256,11 +260,9 @@ public void itemStateChanged(ItemEvent e) {
}
});

clipPanel.butExtractClipped.addActionListener(this);

clipPanel.butExtractClipped.addActionListener(this);

GridBagConstraints c = new GridBagConstraints();


//VIEW PANEL
JPanel panView = new JPanel(new GridBagLayout());
Expand All @@ -283,8 +285,8 @@ public void itemStateChanged(ItemEvent e) {
}
}
});
c.gridx=0;
c.gridy=0;
c.gridx = 0;
c.gridy = 0;
panView.add(butOrigin,c);

//BOX AROUND VOLUME
Expand Down Expand Up @@ -338,7 +340,6 @@ public void itemStateChanged(ItemEvent e) {
c.gridx++;
panView.add(butSettings,c);



//Render method panel
JPanel panRender=new JPanel(new GridBagLayout());
Expand All @@ -361,33 +362,31 @@ public void itemStateChanged(ItemEvent e) {
panVoxel.setBorder(new PanelTitle(" Voxel size "));
}

c.gridx=0;
c.gridy=0;
c.weightx=1.0;
c.fill=GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.fill = GridBagConstraints.HORIZONTAL;
panVoxel.add(voxelSizePanel,c);


//Clipping Panel
JPanel panClip=new JPanel(new GridBagLayout());
panClip.setBorder(new PanelTitle(" Clipping "));

c.gridx=0;
c.gridy=0;
c.weightx=1.0;
c.fill=GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.fill = GridBagConstraints.HORIZONTAL;
panClip.add(clipPanel,c);




//add panels to Navigation
c.insets=new Insets(4,4,2,2);
c.insets = new Insets(4,4,2,2);
//View
c.gridx=0;
c.gridy=0;
c.weightx=1.0;
c.gridwidth=1;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
panNavigation.add(panView,c);

Expand Down Expand Up @@ -430,6 +429,22 @@ public void dialSaveView()
ViewsIO.saveView( bt, filename );
}

public void dialLoadView()
{
String filename;


OpenDialog openDial = new OpenDialog("Load BigTrace ROIs",bt.btData.lastDir, "*.csv");

String path = openDial.getDirectory();
if (path == null)
return;
bt.btData.lastDir = path;
Prefs.set( "BigTrace.lastDir", bt.btData.lastDir );
filename = path + openDial.getFileName();
ViewsIO.loadView( bt, filename );
}


public void dialSettings()
{
Expand All @@ -439,6 +454,9 @@ public void dialSettings()

pViewSettings.setLayout(new GridBagLayout());

DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat df3 = new DecimalFormat ("#.#####", symbols);

JButton butCanvasBGColor = new JButton( new ColorIcon( bt.btData.canvasBGColor ) );
butCanvasBGColor.addActionListener( e -> {
Expand Down Expand Up @@ -470,17 +488,17 @@ public void dialSettings()
nfZoomBoxSize.setMaximumSize(nfZoomBoxSize.getPreferredSize());

NumberField nfZoomBoxScreenFraction = new NumberField(4);
nfZoomBoxScreenFraction.setText(Double.toString(bt.btData.dZoomBoxScreenFraction));
nfZoomBoxScreenFraction.setText(df3.format(bt.btData.dZoomBoxScreenFraction));
nfZoomBoxScreenFraction.setMaximumSize(nfZoomBoxScreenFraction.getPreferredSize());

NumberField nfCamera = new NumberField(4);
nfCamera.setText(Double.toString(bt.btData.dCam));
nfCamera.setText(df3.format( bt.btData.dCam));

NumberField nfClipNear = new NumberField(4);
nfClipNear.setText(Double.toString(bt.btData.dClipNear));
nfClipNear.setText(df3.format(bt.btData.dClipNear));

NumberField nfClipFar = new NumberField(4);
nfClipFar.setText(Double.toString(bt.btData.dClipFar));
nfClipFar.setText(df3.format(bt.btData.dClipFar));

cd.gridx=0;
cd.gridy=0;
Expand Down Expand Up @@ -567,12 +585,7 @@ public void dialSettings()
tempC = selectColors.getColor(0);
if(tempC != null)
{
bt.btData.canvasBGColor = new Color(tempC.getRed(),tempC.getGreen(),tempC.getBlue(),tempC.getAlpha());
selectColors.setColor(null, 0);
Prefs.set("BigTrace.canvasBGColor", tempC.getRGB());
final Color frame = BigTraceData.getInvertedColor(tempC);
bt.volumeBox.setLineColor( frame );
bt.clipBox.setLineColor( frame.darker() );
setCanvasBGColor(tempC);
}

bt.btData.nHalfClickSizeWindow = (int)(0.5*Integer.parseInt(nfClickArea.getText()));
Expand All @@ -591,22 +604,36 @@ public void dialSettings()
bt.btData.dZoomBoxScreenFraction = Double.parseDouble(nfZoomBoxScreenFraction.getText());
Prefs.set("BigTrace.dZoomBoxScreenFraction", bt.btData.dZoomBoxScreenFraction);

bt.btData.dCam = Math.abs(Double.parseDouble(nfCamera.getText()));
bt.btData.dClipNear = Math.abs(Double.parseDouble(nfClipNear.getText()));
bt.btData.dClipFar = Math.abs(Double.parseDouble(nfClipFar.getText()));
if(bt.btData.dCam<=bt.btData.dClipNear)
bt.btData.dCam = bt.btData.dClipNear+1;

Prefs.set("BigTrace.dCam", bt.btData.dCam);
Prefs.set("BigTrace.dClipNear", bt.btData.dClipNear);
Prefs.set("BigTrace.dClipFar", bt.btData.dClipFar);

bt.viewer.setCamParams(bt.btData.dCam, bt.btData.dClipNear, bt.btData.dClipFar);
setCameraParameters(nfCamera.getText(), nfClipNear.getText(), nfClipFar.getText());

bt.repaintBVV();
}
}

public void setCameraParameters(String sCam, String sNear, String sFar)
{
bt.btData.dCam = Math.abs(Double.parseDouble(sCam));
bt.btData.dClipNear = Math.abs(Double.parseDouble(sNear));
bt.btData.dClipFar = Math.abs(Double.parseDouble(sFar));
if(bt.btData.dCam <= bt.btData.dClipNear)
bt.btData.dCam = bt.btData.dClipNear+1;

Prefs.set("BigTrace.dCam", bt.btData.dCam);
Prefs.set("BigTrace.dClipNear", bt.btData.dClipNear);
Prefs.set("BigTrace.dClipFar", bt.btData.dClipFar);
bt.viewer.setCamParams(bt.btData.dCam, bt.btData.dClipNear, bt.btData.dClipFar);
}

public void setCanvasBGColor(final Color bgColor)
{
bt.btData.canvasBGColor = new Color(bgColor.getRed(),bgColor.getGreen(),bgColor.getBlue(),bgColor.getAlpha());
selectColors.setColor(null, 0);
Prefs.set("BigTrace.canvasBGColor", bgColor.getRGB());
final Color frame = BigTraceData.getInvertedColor(bgColor);
bt.volumeBox.setLineColor( frame );
bt.clipBox.setLineColor( frame.darker() );
}

public void extractClippedView()
{

Expand Down Expand Up @@ -896,7 +923,12 @@ public void actionPerformed(ActionEvent e) {
{
dialSaveView();
}


//LOAD VIEW
if(e.getSource() == butLoadView)
{
dialLoadView();
}
//SETTINGS
if(e.getSource() == butSettings)
{
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/bigtrace/BigTraceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ public class BigTraceData < T extends RealType< T > & NativeType< T > > {
/** value of the intensity threshold to stop One click tracing **/
public double dOCIntensityThreshold;

//IO default/last folder

public String lastDir = Prefs.get( "BigTrace.lastDir", "" );


///////////////// DEFAULT SETTINGS FOR UNDEFINED GROUP

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/bigtrace/animation/AnimationPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,9 @@ void dialStorylineSave()
filename = bt.btData.sFileNameFullImg + "_btstory";
SaveDialog sd = new SaveDialog("Save storyline ", filename, ".csv");
String path = sd.getDirectory();
if (path==null)
if (path == null)
return;
filename = path+sd.getFileName();
filename = path + sd.getFileName();

bt.setLockMode(true);
bt.bInputLock = true;
Expand All @@ -883,13 +883,15 @@ void dialStorylineLoad()
{
String filename;

OpenDialog openDial = new OpenDialog("Load BigTrace storyline","", "*.csv");
OpenDialog openDial = new OpenDialog("Load BigTrace storyline",bt.btData.lastDir, "*.csv");

String path = openDial.getDirectory();
if (path==null)
return;

filename = path+openDial.getFileName();
bt.btData.lastDir = path;
Prefs.set( "BigTrace.lastDir", bt.btData.lastDir );

filename = path + openDial.getFileName();
bt.setLockMode(true);
bt.bInputLock = true;
StorylineLoad<T> stLoad = new StorylineLoad<>(bt, this);
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/bigtrace/io/ROIsLoadBG.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,14 @@ protected Void doInBackground() throws Exception {
double [] globCalNew = new double [3];
globCalNew[0]= Double.NaN;
globCalNew[1]= Double.NaN;
globCalNew[2]= Double.NaN;


globCalNew[2]= Double.NaN;

Roi3DGroupManager<T> roiGM;

bt.bInputLock = true;
bt.setLockMode(true);
try ( BufferedReader br = new BufferedReader(new FileReader(sFilename));)
{


{
String line = "";
//read Groups first
if(nLoadMode == 0)
Expand Down
Loading

0 comments on commit 5edeb79

Please sign in to comment.