1 package ini
.trakem2
.display
.d3d
;
3 import java
.awt
.event
.MouseEvent
;
5 import org
.scijava
.vecmath
.Point3d
;
7 import ij
.measure
.Calibration
;
9 import ij3d
.Image3DUniverse
;
10 import ij3d
.behaviors
.InteractiveBehavior
;
11 import ij3d
.behaviors
.Picker
;
12 import ini
.trakem2
.display
.Coordinate
;
13 import ini
.trakem2
.display
.Display
;
14 import ini
.trakem2
.display
.Layer
;
15 import ini
.trakem2
.display
.LayerSet
;
16 import ini
.trakem2
.utils
.Utils
;
18 /** A class to provide the behavior on control-clicking on
19 content in the 3D viewer. This will attempt to center
20 the front TrakEM2 Display on the clicked point */
21 public class ControlClickBehavior
extends InteractiveBehavior
{
23 protected Image3DUniverse universe
;
24 protected LayerSet ls
;
26 public ControlClickBehavior(final Image3DUniverse univ
, final LayerSet ls
) {
33 public void doProcess(final MouseEvent e
) {
34 if(!e
.isControlDown() ||
35 e
.getID() != MouseEvent
.MOUSE_PRESSED
) {
39 final Picker picker
= universe
.getPicker();
40 final Content content
= picker
.getPickedContent(e
.getX(),e
.getY());
43 final Point3d p
= picker
.getPickPointGeometry(content
,e
);
45 Utils
.log("No point was found on content "+content
);
48 final Display display
= Display
.getFront(ls
.getProject());
50 // If there's no Display, just return...
53 if (display
.getLayerSet() != ls
) {
54 Utils
.log("The LayerSet instances do not match");
58 Utils
.log("No LayerSet was found for the Display");
61 final Calibration cal
= ls
.getCalibration();
63 Utils
.log("No calibration information was found for the LayerSet");
66 final double scaledZ
= p
.z
/cal
.pixelWidth
;
67 final Layer l
= ls
.getNearestLayer(scaledZ
);
69 Utils
.log("No layer was found nearest to "+scaledZ
);
72 final Coordinate
<?
> coordinate
= new Coordinate
<Object
>(p
.x
/cal
.pixelWidth
,p
.y
/cal
.pixelHeight
,l
,null);
73 display
.center(coordinate
);