1
1
package bigtrace ;
2
2
3
3
import java .awt .Color ;
4
+ import java .awt .event .WindowAdapter ;
4
5
import java .awt .event .WindowEvent ;
5
- import java .awt .event .WindowListener ;
6
6
import java .nio .file .Path ;
7
7
import java .nio .file .Paths ;
8
8
import java .util .ArrayList ;
29
29
import ij .plugin .PlugIn ;
30
30
import mpicbg .spim .data .SpimData ;
31
31
import mpicbg .spim .data .SpimDataException ;
32
- import net .imglib2 .AbstractInterval ;
33
32
import net .imglib2 .FinalInterval ;
34
33
import net .imglib2 .FinalRealInterval ;
35
34
import net .imglib2 .Interval ;
43
42
import net .imglib2 .type .numeric .ARGBType ;
44
43
import net .imglib2 .type .numeric .RealType ;
45
44
import net .imglib2 .type .numeric .integer .UnsignedByteType ;
46
- import net .imglib2 .util .Intervals ;
47
45
import net .imglib2 .util .LinAlgHelpers ;
48
46
import net .imglib2 .view .IntervalView ;
49
47
import net .imglib2 .view .Views ;
50
48
51
- import bdv .tools .InitializeViewerState ;
52
49
import bdv .tools .transformation .TransformedSource ;
53
- import bdv .util .Bounds ;
54
- import bdv .viewer .Source ;
50
+
55
51
import bdv .viewer .SourceAndConverter ;
56
52
import bdv .viewer .TimePointListener ;
57
- import bdv .viewer .ViewerState ;
58
53
59
54
import bvvpg .vistools .BvvFunctions ;
60
55
import bvvpg .vistools .BvvHandleFrame ;
83
78
import bigtrace .volume .VolumeMisc ;
84
79
85
80
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
87
82
{
88
83
/** main instance of BVV **/
89
84
public BvvStackSource < ? > bvv_main = null ;
@@ -319,13 +314,11 @@ private void createAndShowGUI()
319
314
btPanel = new BigTraceControlPanel <>(this , btData ,roiManager );
320
315
btPanel .finFrame = new JFrame ("BigTrace" );
321
316
btPanel .finFrame .setDefaultCloseOperation (WindowConstants .DO_NOTHING_ON_CLOSE );
322
-
323
317
324
318
bvvFrame = ((BvvHandleFrame )bvv_main .getBvvHandle ()).getBigVolumeViewer ().getViewerFrame ();
325
319
326
320
bvvFrame .setDefaultCloseOperation (WindowConstants .DO_NOTHING_ON_CLOSE );
327
321
328
-
329
322
btPanel .finFrame .add (btPanel );
330
323
331
324
//Display the window.
@@ -334,16 +327,29 @@ private void createAndShowGUI()
334
327
java .awt .Point bvv_p = bvvFrame .getLocationOnScreen ();
335
328
java .awt .Dimension bvv_d = bvvFrame .getSize ();
336
329
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 );
342
343
bInputLock = false ;
343
344
}
345
+
346
+ public void closeWindows ()
347
+ {
348
+ viewer .stop ();
349
+ bvvFrame .dispose ();
350
+ btPanel .finFrame .dispose ();
351
+ }
344
352
345
-
346
-
347
353
public void focusOnInterval (Interval interval_in )
348
354
{
349
355
if (!bInputLock && !bTraceMode )
@@ -364,9 +370,9 @@ public void calcShowTraceBox(final LineTrace3D trace, final boolean bRefine)
364
370
365
371
traceIV = getTraceInterval (btData .bTraceOnlyClipped );
366
372
367
- if (trace .numVertices ()== 1 )
373
+ if (trace .numVertices () == 1 )
368
374
{
369
- rangeTraceBox = getTraceBoxCentered (traceIV ,btData .lTraceBoxSize , trace .vertices .get (0 ));
375
+ rangeTraceBox = VolumeMisc . getTraceBoxCentered (traceIV ,btData .lTraceBoxSize , trace .vertices .get (0 ));
370
376
}
371
377
else
372
378
{
@@ -455,7 +461,8 @@ public synchronized void setLockMode(boolean bLockMode)
455
461
//keep it on
456
462
roiManager .butShowAll .setEnabled (true );
457
463
}
458
- /** calculate optimal path **/
464
+
465
+ /** turn on Trace Box mode **/
459
466
public void getSemiAutoTrace (RealPoint target )
460
467
{
461
468
@@ -480,39 +487,6 @@ public void showCorners(ArrayList<long []> corners)
480
487
}
481
488
}
482
489
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
- }
516
490
517
491
//gets a box around "target" with half size of range
518
492
public FinalInterval getTraceBoxNext (final IntervalView < ? > viewclick , final long range , final float fFollowDegree , LineTrace3D trace )
@@ -895,7 +869,6 @@ public void initBVVSourcesSpimData()
895
869
transformTranslation .identity ();
896
870
transformTranslation .translate (shiftTR );
897
871
898
-
899
872
// Remove voxel scale for all sources.
900
873
// We needed it, because later voxel size transform is applied to the general ViewerPanel.
901
874
for ( SourceAndConverter < ? > source : viewer .state ().getSources () )
@@ -1402,109 +1375,7 @@ public <X extends RealType< X >> boolean findPointLocationMaxIntensity(final Int
1402
1375
//System.out.println("al2:"+Integer.toString(foundMaxPosition.getIntPosition(0))+" "+Integer.toString(foundMaxPosition.getIntPosition(1))+" "+Integer.toString(foundMaxPosition.getIntPosition(2)));
1403
1376
1404
1377
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
+ }
1508
1379
1509
1380
@ Override
1510
1381
public void timePointChanged (int timePointIndex )
@@ -1557,73 +1428,7 @@ public void setScene(final Scene scene)
1557
1428
}
1558
1429
btPanel .clipPanel .setBoundingBox ( scene .getClipBox ());
1559
1430
}
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
+
1627
1432
1628
1433
@ Override
1629
1434
public ExtensionDescriptor [] getExtensionFunctions () {
0 commit comments