Skip to content

Commit d95525f

Browse files
committed
FIX: edit->Add compass can:
- is not asking/complaining for Vector3f, and shows dialog instead... - has nicer dialog - optionally be in the TL corner as overlay - optionally be as a part of the scene - tiny bit of refactoring
1 parent 16b6901 commit d95525f

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

src/main/java/sc/iview/commands/edit/AddOrientationCompass.java

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@
2929
package sc.iview.commands.edit;
3030

3131
import graphics.scenery.*;
32-
import org.joml.Matrix4f;
3332
import org.joml.Quaternionf;
3433
import org.joml.Vector2f;
3534
import org.joml.Vector3f;
3635
import org.scijava.command.Command;
37-
import org.scijava.command.CommandService;
3836
import org.scijava.plugin.Menu;
3937
import org.scijava.plugin.Parameter;
4038
import org.scijava.plugin.Plugin;
4139
import sc.iview.SciView;
42-
import sc.iview.node.Line3D;
43-
44-
import java.util.HashMap;
4540

4641
import static sc.iview.commands.MenuWeights.EDIT;
4742
import static sc.iview.commands.MenuWeights.EDIT_ADD_COMPASS;
@@ -50,6 +45,7 @@
5045
* Command to orientation compass (R,G,B cylinders oriented along X,Y,Z axes, respectively) to the scene
5146
*
5247
* @author Vladimir Ulman
48+
* @author Kyle Harrington
5349
*
5450
*/
5551
@Plugin(type = Command.class, menuRoot = "SciView", //
@@ -60,30 +56,39 @@ public class AddOrientationCompass implements Command {
6056
@Parameter
6157
private SciView sciView;
6258

63-
@Parameter
59+
@Parameter(label = "Length of each bar:", stepSize = "0.1", min = "0")
6460
private float axisLength = 0.1f;
6561

66-
@Parameter
67-
private float AXESBARRADIUS = 0.001f;
62+
@Parameter(label = "Thickness of each bar:", stepSize = "0.001", min = "0")
63+
private float axisBarRadius = 0.001f;
6864

69-
@Parameter
65+
//@Parameter -- waits until scijava can offer color-picker dialog
7066
private Vector3f xColor = new Vector3f(1f,0f,0f);
67+
//NB: RGB colors ~ XYZ axes
7168

72-
@Parameter
69+
//@Parameter
7370
private Vector3f yColor = new Vector3f(0f,1f,0f);
7471

75-
@Parameter
72+
//@Parameter
7673
private Vector3f zColor = new Vector3f(0f,0f,1f);
7774

75+
@Parameter(label = "Show in overlay in top-left corner:")
76+
boolean attachToCam = true;
77+
78+
@Parameter(label = "Show as controllable node in the scene:")
79+
boolean showInTheScene = false;
80+
81+
7882
private Node makeAxis( float axisLength, float angleX, float angleY, float angleZ, Vector3f color ) {
79-
Cylinder axisNode = new Cylinder(AXESBARRADIUS, axisLength,4);
80-
axisNode.setName("compass axis: X");
83+
Cylinder axisNode = new Cylinder(axisBarRadius, axisLength,4);
84+
axisNode.setName("compass bar");
8185
axisNode.setRotation( new Quaternionf().rotateXYZ( angleX, angleY, angleZ ) );
8286
axisNode.getMaterial().getDiffuse().set(color);
8387
axisNode.getMaterial().setDepthTest(Material.DepthTest.Always);
8488
axisNode.getMaterial().getBlending().setTransparent(true);
8589

86-
Icosphere axisCap = new Icosphere(AXESBARRADIUS, 2);
90+
Icosphere axisCap = new Icosphere(axisBarRadius, 2);
91+
axisCap.setName("cap of the bar");
8792
axisCap.setPosition(new Vector3f(0, axisLength, 0));
8893
axisCap.getMaterial().getDiffuse().set(color);
8994
axisCap.getMaterial().setDepthTest(Material.DepthTest.Always);
@@ -93,47 +98,39 @@ private Node makeAxis( float axisLength, float angleX, float angleY, float angle
9398
return axisNode;
9499
}
95100

96-
@Override
97-
public void run() {
101+
private Node createCompass() {
98102
final Node root = new Node("Scene orientation compass");
99103

100-
//NB: RGB colors ~ XYZ axes
101104
//x axis:
102105
Node axisNode = makeAxis( axisLength, 0,0,(float)(-0.5*Math.PI), xColor );
103106
axisNode.setName("compass axis: X");
104107
root.addChild( axisNode );
105108

106109
//y axis:
107110
axisNode = makeAxis( axisLength, 0,0, 0, yColor );
108-
109111
axisNode.setName("compass axis: Y");
110112
root.addChild( axisNode );
111113

112114
//z axis:
113115
axisNode = makeAxis( axisLength, (float)(0.5*Math.PI),0,0, zColor );
114116
axisNode.setName("compass axis: Z");
115117
root.addChild( axisNode );
116-
117-
sciView.addNode( root );
118-
119-
sciView.getCamera().addChild(root);
120-
121-
root.getUpdate().add(() -> {
122-
final Camera cam = sciView.getCamera();
123-
root.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f)));
124-
root.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate());
125-
return null;
126-
});
127-
118+
return root;
128119
}
129120

130-
public static void main(String... args) throws Exception {
131-
SciView sv = SciView.create();
132-
133-
CommandService command = sv.getScijavaContext().getService(CommandService.class);
134-
135-
HashMap<String, Object> argmap = new HashMap<>();
136-
137-
command.run(AddOrientationCompass.class, true, argmap);
121+
@Override
122+
public void run() {
123+
if (showInTheScene) sciView.addNode( createCompass() );
124+
if (attachToCam) {
125+
final Node compass = createCompass();
126+
sciView.getCamera().addChild( compass );
127+
128+
compass.getUpdate().add(() -> {
129+
final Camera cam = sciView.getCamera();
130+
compass.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f)));
131+
compass.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate());
132+
return null;
133+
});
134+
}
138135
}
139136
}

0 commit comments

Comments
 (0)