preparing release pom-trakem2-2.0.0, VectorString-2.0.0, TrakEM2_-1.0h
[trakem2.git] / TrakEM2_ / src / main / java / ini / trakem2 / display / d3d / ControlClickBehavior.java
blob92231e384f375c7b3fca96d83df1157902c53b69
1 package ini.trakem2.display.d3d;
3 import java.awt.event.MouseEvent;
5 import org.scijava.vecmath.Point3d;
7 import ij.measure.Calibration;
8 import ij3d.Content;
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) {
27 super(univ);
28 this.universe = univ;
29 this.ls = ls;
32 @Override
33 public void doProcess(final MouseEvent e) {
34 if(!e.isControlDown() ||
35 e.getID() != MouseEvent.MOUSE_PRESSED) {
36 super.doProcess(e);
37 return;
39 final Picker picker = universe.getPicker();
40 final Content content = picker.getPickedContent(e.getX(),e.getY());
41 if(content==null)
42 return;
43 final Point3d p = picker.getPickPointGeometry(content,e);
44 if(p==null) {
45 Utils.log("No point was found on content "+content);
46 return;
48 final Display display = Display.getFront(ls.getProject());
49 if(display==null) {
50 // If there's no Display, just return...
51 return;
53 if (display.getLayerSet() != ls) {
54 Utils.log("The LayerSet instances do not match");
55 return;
57 if(ls==null) {
58 Utils.log("No LayerSet was found for the Display");
59 return;
61 final Calibration cal = ls.getCalibration();
62 if(cal==null) {
63 Utils.log("No calibration information was found for the LayerSet");
64 return;
66 final double scaledZ = p.z/cal.pixelWidth;
67 final Layer l = ls.getNearestLayer(scaledZ);
68 if(l==null) {
69 Utils.log("No layer was found nearest to "+scaledZ);
70 return;
72 final Coordinate<?> coordinate = new Coordinate<Object>(p.x/cal.pixelWidth,p.y/cal.pixelHeight,l,null);
73 display.center(coordinate);