Skip to content

Commit 8060be4

Browse files
committed
save view
1 parent 20e2ab9 commit 8060be4

10 files changed

+301
-392
lines changed

src/main/java/bigtrace/BigTrace.java

+29-224
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package bigtrace;
22

33
import java.awt.Color;
4+
import java.awt.event.WindowAdapter;
45
import java.awt.event.WindowEvent;
5-
import java.awt.event.WindowListener;
66
import java.nio.file.Path;
77
import java.nio.file.Paths;
88
import java.util.ArrayList;
@@ -29,7 +29,6 @@
2929
import ij.plugin.PlugIn;
3030
import mpicbg.spim.data.SpimData;
3131
import mpicbg.spim.data.SpimDataException;
32-
import net.imglib2.AbstractInterval;
3332
import net.imglib2.FinalInterval;
3433
import net.imglib2.FinalRealInterval;
3534
import net.imglib2.Interval;
@@ -43,18 +42,14 @@
4342
import net.imglib2.type.numeric.ARGBType;
4443
import net.imglib2.type.numeric.RealType;
4544
import net.imglib2.type.numeric.integer.UnsignedByteType;
46-
import net.imglib2.util.Intervals;
4745
import net.imglib2.util.LinAlgHelpers;
4846
import net.imglib2.view.IntervalView;
4947
import net.imglib2.view.Views;
5048

51-
import bdv.tools.InitializeViewerState;
5249
import bdv.tools.transformation.TransformedSource;
53-
import bdv.util.Bounds;
54-
import bdv.viewer.Source;
50+
5551
import bdv.viewer.SourceAndConverter;
5652
import bdv.viewer.TimePointListener;
57-
import bdv.viewer.ViewerState;
5853

5954
import bvvpg.vistools.BvvFunctions;
6055
import bvvpg.vistools.BvvHandleFrame;
@@ -83,7 +78,7 @@
8378
import bigtrace.volume.VolumeMisc;
8479

8580

86-
public class BigTrace < T extends RealType< T > & NativeType< T > > implements PlugIn, MacroExtension, WindowListener, TimePointListener
81+
public class BigTrace < T extends RealType< T > & NativeType< T > > implements PlugIn, MacroExtension, TimePointListener
8782
{
8883
/** main instance of BVV **/
8984
public BvvStackSource< ? > bvv_main = null;
@@ -319,13 +314,11 @@ private void createAndShowGUI()
319314
btPanel = new BigTraceControlPanel<>(this, btData,roiManager);
320315
btPanel.finFrame = new JFrame("BigTrace");
321316
btPanel.finFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
322-
323317

324318
bvvFrame = ((BvvHandleFrame)bvv_main.getBvvHandle()).getBigVolumeViewer().getViewerFrame();
325319

326320
bvvFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
327321

328-
329322
btPanel.finFrame.add(btPanel);
330323

331324
//Display the window.
@@ -334,16 +327,29 @@ private void createAndShowGUI()
334327
java.awt.Point bvv_p = bvvFrame.getLocationOnScreen();
335328
java.awt.Dimension bvv_d = bvvFrame.getSize();
336329

337-
btPanel.finFrame.setLocation(bvv_p.x+bvv_d.width, bvv_p.y);
338-
btPanel.finFrame.addWindowListener(this);
339-
bvvFrame.addWindowListener(this);
340-
341-
330+
btPanel.finFrame.setLocation(bvv_p.x + bvv_d.width, bvv_p.y);
331+
332+
final WindowAdapter closeWA = new WindowAdapter()
333+
{
334+
@Override
335+
public void windowClosing( WindowEvent ev )
336+
{
337+
closeWindows();
338+
}
339+
};
340+
341+
btPanel.finFrame.addWindowListener( closeWA );
342+
bvvFrame.addWindowListener( closeWA);
342343
bInputLock = false;
343344
}
345+
346+
public void closeWindows()
347+
{
348+
viewer.stop();
349+
bvvFrame.dispose();
350+
btPanel.finFrame.dispose();
351+
}
344352

345-
346-
347353
public void focusOnInterval(Interval interval_in)
348354
{
349355
if(!bInputLock && !bTraceMode)
@@ -364,9 +370,9 @@ public void calcShowTraceBox(final LineTrace3D trace, final boolean bRefine)
364370

365371
traceIV = getTraceInterval(btData.bTraceOnlyClipped);
366372

367-
if(trace.numVertices()==1)
373+
if(trace.numVertices() == 1)
368374
{
369-
rangeTraceBox = getTraceBoxCentered(traceIV,btData.lTraceBoxSize, trace.vertices.get(0));
375+
rangeTraceBox = VolumeMisc.getTraceBoxCentered(traceIV,btData.lTraceBoxSize, trace.vertices.get(0));
370376
}
371377
else
372378
{
@@ -455,7 +461,8 @@ public synchronized void setLockMode(boolean bLockMode)
455461
//keep it on
456462
roiManager.butShowAll.setEnabled(true);
457463
}
458-
/** calculate optimal path **/
464+
465+
/** turn on Trace Box mode **/
459466
public void getSemiAutoTrace(RealPoint target)
460467
{
461468

@@ -480,39 +487,6 @@ public void showCorners(ArrayList<long []> corners)
480487
}
481488
}
482489

483-
/** gets a box around "target" with half size of range in all axes.
484-
crops the box so it is inside viewclick interval **/
485-
public FinalInterval getTraceBoxCentered(final AbstractInterval viewclick, final long range, final RealPoint target)
486-
{
487-
long[][] rangeM = new long[2][3];
488-
int i;
489-
float [] pos = new float[3];
490-
target.localize(pos);
491-
for(i=0;i<3;i++)
492-
{
493-
rangeM[0][i]=(long)(pos[i])-range ;
494-
rangeM[1][i]=(long)(pos[i])+range;
495-
}
496-
VolumeMisc.checkBoxInside(viewclick, rangeM);
497-
FinalInterval finInt = new FinalInterval(rangeM[0],rangeM[1]);
498-
return finInt;
499-
}
500-
501-
//gets a box around "target" with half size of range
502-
public FinalInterval getZoomBoxCentered(final long range, final RealPoint target)
503-
{
504-
long[][] rangeM = new long[2][3];
505-
int i;
506-
float [] pos = new float[3];
507-
target.localize(pos);
508-
for(i=0;i<3;i++)
509-
{
510-
rangeM[0][i]=(long)(pos[i])-range ;
511-
rangeM[1][i]=(long)(pos[i])+range;
512-
}
513-
FinalInterval finInt = new FinalInterval(rangeM[0],rangeM[1]);
514-
return finInt;
515-
}
516490

517491
//gets a box around "target" with half size of range
518492
public FinalInterval getTraceBoxNext(final IntervalView< ? > viewclick, final long range, final float fFollowDegree, LineTrace3D trace)
@@ -895,7 +869,6 @@ public void initBVVSourcesSpimData()
895869
transformTranslation.identity();
896870
transformTranslation.translate(shiftTR);
897871

898-
899872
// Remove voxel scale for all sources.
900873
// We needed it, because later voxel size transform is applied to the general ViewerPanel.
901874
for ( SourceAndConverter< ? > source : viewer.state().getSources() )
@@ -1402,109 +1375,7 @@ public <X extends RealType< X >> boolean findPointLocationMaxIntensity(final Int
14021375
//System.out.println("al2:"+Integer.toString(foundMaxPosition.getIntPosition(0))+" "+Integer.toString(foundMaxPosition.getIntPosition(1))+" "+Integer.toString(foundMaxPosition.getIntPosition(2)));
14031376

14041377
return true;
1405-
}
1406-
/** find click location in 3D when using maximum intensity render **/
1407-
@Deprecated
1408-
public <X extends RealType< X >>boolean findPointLocationMaxIntensityOLD(final IntervalView< X > viewclick, java.awt.Point point_mouse, final RealPoint target)
1409-
{
1410-
int i,j;
1411-
//check if mouse position it is inside bvv window
1412-
//java.awt.Rectangle windowBVVbounds = btpanel.bvv_frame.getContentPane().getBounds();
1413-
//System.out.println( "click x = [" + point_mouse.x + "], y = [" + point_mouse.y + "]" );
1414-
1415-
final int nHalfWindowSize = btData.nHalfClickSizeWindow;
1416-
//get perspective matrix:
1417-
AffineTransform3D transform = new AffineTransform3D();
1418-
viewer.state().getViewerTransform(transform);
1419-
int sW = viewer.getWidth();
1420-
int sH = viewer.getHeight();
1421-
Matrix4f matPerspWorld = new Matrix4f();
1422-
MatrixMath.screenPerspective( btData.dCam, btData.dClipNear, btData.dClipFar, sW, sH, 0, matPerspWorld ).mul( MatrixMath.affine( transform, new Matrix4f() ) );
1423-
1424-
1425-
ArrayList<RealPoint> clickFrustum = new ArrayList<> ();
1426-
Vector3f temp = new Vector3f();
1427-
1428-
//float [] zVals = new float []{0.0f,1.0f,1.0f,0.0f,0.0f,1.0f,1.0f,0.0f};
1429-
for (i = -nHalfWindowSize;i<3*nHalfWindowSize;i+=2*nHalfWindowSize)
1430-
for (j = -nHalfWindowSize;j<3*nHalfWindowSize;j+=2*nHalfWindowSize)
1431-
for (int z =0 ; z<2; z++)
1432-
{
1433-
//take coordinates in original data volume space
1434-
matPerspWorld.unproject((float)point_mouse.x+i,sH-(float)point_mouse.y+j,z, //z=1 ->far from camera z=0 -> close to camera
1435-
new int[] { 0, 0, sW, sH },temp);
1436-
//persp.unproject((float)point_mouse.x+i,sH-(float)point_mouse.y+j,zVals[nCount+1], //z=1 ->far from camera z=0 -> close to camera
1437-
//new int[] { 0, 0, sW, sH },temp);
1438-
1439-
clickFrustum.add(new RealPoint(temp.x,temp.y,temp.z));
1440-
1441-
}
1442-
//build lines (rays)
1443-
ArrayList<Line3D> frustumLines = new ArrayList<>();
1444-
for(i =0;i<clickFrustum.size();i+=2)
1445-
{
1446-
frustumLines.add(new Line3D(clickFrustum.get(i),clickFrustum.get(i+1)));
1447-
}
1448-
1449-
/*
1450-
// original lines (rays)
1451-
for(i =0;i<clickFrustum.size();i+=2)
1452-
{
1453-
traces.addNewLine();
1454-
traces.addPointToActive(clickFrustum.get(i));
1455-
traces.addPointToActive(clickFrustum.get(i+1));
1456-
}
1457-
*/
1458-
1459-
//current dataset
1460-
Cuboid3D dataCube = new Cuboid3D(viewclick);
1461-
dataCube.iniFaces();
1462-
ArrayList<RealPoint> intersectionPoints = Intersections3D.cuboidLinesIntersect(dataCube, frustumLines);
1463-
// Lines(rays) truncated to the volume.
1464-
// For now, all of them must contained inside datacube.
1465-
1466-
if(intersectionPoints.size()==8)
1467-
{
1468-
btPanel.progressBar.setString("click point found");
1469-
/*
1470-
for(i =0;i<intersectionPoints.size();i++)
1471-
{
1472-
Point3D point = new Point3D(roiManager.groups.get(0));
1473-
point.setVertex(intersectionPoints.get(i));
1474-
point.setGroupInd(0);
1475-
roiManager.addRoi(point);
1476-
}
1477-
*/
1478-
}
1479-
else
1480-
{
1481-
btPanel.progressBar.setString("cannot find clicked point");
1482-
//System.out.println( "#intersection points " + intersectionPoints.size());
1483-
return false;
1484-
}
1485-
long [][] nClickMinMax = new long[2][3];
1486-
1487-
if(VolumeMisc.newBoundBox(viewclick, intersectionPoints, nClickMinMax))
1488-
{
1489-
1490-
IntervalView< X > intRay = Views.interval(viewclick, Intervals.createMinMax(nClickMinMax[0][0],nClickMinMax[0][1],nClickMinMax[0][2],
1491-
nClickMinMax[1][0],nClickMinMax[1][1],nClickMinMax[1][2]));
1492-
Cuboid3D clickVolume = new Cuboid3D(clickFrustum);
1493-
clickVolume.iniFaces();
1494-
RealPoint target_found = new RealPoint( 3 );
1495-
1496-
if(VolumeMisc.findMaxLocationCuboid(intRay,target_found,clickVolume))
1497-
{
1498-
btPanel.progressBar.setString("click point found");
1499-
target.setPosition(target_found);
1500-
return true;
1501-
}
1502-
btPanel.progressBar.setString("cannot find clicked point");
1503-
return false;
1504-
}
1505-
return false;
1506-
}
1507-
1378+
}
15081379

15091380
@Override
15101381
public void timePointChanged(int timePointIndex)
@@ -1557,73 +1428,7 @@ public void setScene(final Scene scene)
15571428
}
15581429
btPanel.clipPanel.setBoundingBox( scene.getClipBox());
15591430
}
1560-
1561-
1562-
@Override
1563-
public void windowActivated(WindowEvent arg0) {
1564-
// TODO Auto-generated method stub
1565-
//System.out.println("yay1");
1566-
}
1567-
1568-
@Override
1569-
public void windowClosed(WindowEvent arg0) {
1570-
// TODO Auto-generated method stub
1571-
//System.out.println("yay");
1572-
}
1573-
1574-
@Override
1575-
public void windowClosing(WindowEvent arg0) {
1576-
// TODO Auto-generated method stub
1577-
closeWindows();
1578-
}
1579-
1580-
@Override
1581-
public void windowDeactivated(WindowEvent arg0) {
1582-
// TODO Auto-generated method stub
1583-
//System.out.println("yay3");
1584-
}
1585-
1586-
@Override
1587-
public void windowDeiconified(WindowEvent arg0) {
1588-
// TODO Auto-generated method stub
1589-
//System.out.println("yay4");
1590-
}
1591-
1592-
@Override
1593-
public void windowIconified(WindowEvent arg0) {
1594-
// TODO Auto-generated method stub
1595-
//System.out.println("yay5");
1596-
}
1597-
1598-
@Override
1599-
public void windowOpened(WindowEvent arg0) {
1600-
// TODO Auto-generated method stub
1601-
//System.out.println("yay6");
1602-
}
1603-
1604-
1605-
public void closeWindows()
1606-
{
1607-
viewer.stop();
1608-
bvvFrame.dispose();
1609-
btPanel.finFrame.dispose();
1610-
}
1611-
1612-
public static double [] initBrightnessBVV( final double cumulativeMinCutoff, final double cumulativeMaxCutoff, final ViewerState state )
1613-
{
1614-
final SourceAndConverter< ? > current = state.getCurrentSource();
1615-
if ( current == null )
1616-
return null;
1617-
final Source< ? > source = current.getSpimSource();
1618-
final int timepoint = state.getCurrentTimepoint();
1619-
final Bounds bounds = InitializeViewerState.estimateSourceRange( source, timepoint, cumulativeMinCutoff, cumulativeMaxCutoff );
1620-
double [] out = new double [2];
1621-
out[0]=bounds.getMinBound();
1622-
out[1]=bounds.getMaxBound();
1623-
return out;
1624-
1625-
}
1626-
1431+
16271432

16281433
@Override
16291434
public ExtensionDescriptor[] getExtensionFunctions() {

src/main/java/bigtrace/BigTraceActions.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public void actionZoomIn()
382382
if(bt.findPointLocationFromClick(bt.btData.getDataCurrentSourceClipped(),target))
383383
{
384384

385-
final FinalInterval zoomInterval = bt.getTraceBoxCentered(bt.getTraceInterval(!bt.btData.bZoomClip),bt.btData.nZoomBoxSize, target);
385+
final FinalInterval zoomInterval = VolumeMisc.getTraceBoxCentered(bt.getTraceInterval(!bt.btData.bZoomClip),bt.btData.nZoomBoxSize, target);
386386

387387
if(bt.btData.bZoomClip)
388388
{
@@ -397,8 +397,7 @@ public void actionZoomIn()
397397
{
398398
if(bt.findPointLocationFromClick(bt.btData.trace_weights,target))
399399
{
400-
//FinalInterval zoomInterval = getTraceBoxCentered(btdata.trace_weights,(long)(btdata.lTraceBoxSize*0.8), target);
401-
FinalInterval zoomInterval = bt.getZoomBoxCentered((long)(bt.btData.lTraceBoxSize*0.5), target);
400+
FinalInterval zoomInterval = VolumeMisc.getZoomBoxCentered((long)(bt.btData.lTraceBoxSize*0.5), target);
402401

403402
bt.viewer.setTransformAnimator(bt.getCenteredViewAnim(zoomInterval,bt.btData.dZoomBoxScreenFraction));
404403
}

src/main/java/bigtrace/BigTraceControlPanel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public void dialSettings()
443443
JButton butCanvasBGColor = new JButton( new ColorIcon( bt.btData.canvasBGColor ) );
444444
butCanvasBGColor.addActionListener( e -> {
445445
Color newColor = JColorChooser.showDialog(bt.btPanel.finFrame, "Choose background color", bt.btData.canvasBGColor );
446-
if (newColor!=null)
446+
if (newColor != null)
447447
{
448448
selectColors.setColor(newColor, 0);
449449

@@ -565,7 +565,7 @@ public void dialSettings()
565565
Color tempC;
566566

567567
tempC = selectColors.getColor(0);
568-
if(tempC!=null)
568+
if(tempC != null)
569569
{
570570
bt.btData.canvasBGColor = new Color(tempC.getRed(),tempC.getGreen(),tempC.getBlue(),tempC.getAlpha());
571571
selectColors.setColor(null, 0);

0 commit comments

Comments
 (0)