From 4907cf21774352c3aec4f77fac1ef51ece2336c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Ulman?= Date: Thu, 3 Sep 2020 16:44:06 +0200 Subject: [PATCH 1/2] 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 --- .../commands/edit/AddOrientationCompass.java | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java b/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java index c9da9995..1ffe87e8 100644 --- a/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java +++ b/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java @@ -29,19 +29,14 @@ package sc.iview.commands.edit; import graphics.scenery.*; -import org.joml.Matrix4f; import org.joml.Quaternionf; import org.joml.Vector2f; import org.joml.Vector3f; import org.scijava.command.Command; -import org.scijava.command.CommandService; import org.scijava.plugin.Menu; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; import sc.iview.SciView; -import sc.iview.node.Line3D; - -import java.util.HashMap; import static sc.iview.commands.MenuWeights.EDIT; import static sc.iview.commands.MenuWeights.EDIT_ADD_COMPASS; @@ -50,6 +45,7 @@ * Command to orientation compass (R,G,B cylinders oriented along X,Y,Z axes, respectively) to the scene * * @author Vladimir Ulman + * @author Kyle Harrington * */ @Plugin(type = Command.class, menuRoot = "SciView", // @@ -60,30 +56,39 @@ public class AddOrientationCompass implements Command { @Parameter private SciView sciView; - @Parameter + @Parameter(label = "Length of each bar:", stepSize = "0.1", min = "0") private float axisLength = 0.1f; - @Parameter - private float AXESBARRADIUS = 0.001f; + @Parameter(label = "Thickness of each bar:", stepSize = "0.001", min = "0") + private float axisBarRadius = 0.001f; - @Parameter + //@Parameter -- waits until scijava can offer color-picker dialog private Vector3f xColor = new Vector3f(1f,0f,0f); + //NB: RGB colors ~ XYZ axes - @Parameter + //@Parameter private Vector3f yColor = new Vector3f(0f,1f,0f); - @Parameter + //@Parameter private Vector3f zColor = new Vector3f(0f,0f,1f); + @Parameter(label = "Show in overlay in top-left corner:") + boolean attachToCam = true; + + @Parameter(label = "Show as controllable node in the scene:") + boolean showInTheScene = false; + + private Node makeAxis( float axisLength, float angleX, float angleY, float angleZ, Vector3f color ) { - Cylinder axisNode = new Cylinder(AXESBARRADIUS, axisLength,4); - axisNode.setName("compass axis: X"); + Cylinder axisNode = new Cylinder(axisBarRadius, axisLength,4); + axisNode.setName("compass bar"); axisNode.setRotation( new Quaternionf().rotateXYZ( angleX, angleY, angleZ ) ); axisNode.getMaterial().getDiffuse().set(color); axisNode.getMaterial().setDepthTest(Material.DepthTest.Always); axisNode.getMaterial().getBlending().setTransparent(true); - Icosphere axisCap = new Icosphere(AXESBARRADIUS, 2); + Icosphere axisCap = new Icosphere(axisBarRadius, 2); + axisCap.setName("cap of the bar"); axisCap.setPosition(new Vector3f(0, axisLength, 0)); axisCap.getMaterial().getDiffuse().set(color); axisCap.getMaterial().setDepthTest(Material.DepthTest.Always); @@ -93,11 +98,9 @@ private Node makeAxis( float axisLength, float angleX, float angleY, float angle return axisNode; } - @Override - public void run() { + private Node createCompass() { final Node root = new Node("Scene orientation compass"); - //NB: RGB colors ~ XYZ axes //x axis: Node axisNode = makeAxis( axisLength, 0,0,(float)(-0.5*Math.PI), xColor ); axisNode.setName("compass axis: X"); @@ -105,7 +108,6 @@ public void run() { //y axis: axisNode = makeAxis( axisLength, 0,0, 0, yColor ); - axisNode.setName("compass axis: Y"); root.addChild( axisNode ); @@ -113,27 +115,22 @@ public void run() { axisNode = makeAxis( axisLength, (float)(0.5*Math.PI),0,0, zColor ); axisNode.setName("compass axis: Z"); root.addChild( axisNode ); - - sciView.addNode( root ); - - sciView.getCamera().addChild(root); - - root.getUpdate().add(() -> { - final Camera cam = sciView.getCamera(); - root.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f))); - root.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate()); - return null; - }); - + return root; } - public static void main(String... args) throws Exception { - SciView sv = SciView.create(); - - CommandService command = sv.getScijavaContext().getService(CommandService.class); - - HashMap argmap = new HashMap<>(); - - command.run(AddOrientationCompass.class, true, argmap); + @Override + public void run() { + if (showInTheScene) sciView.addNode( createCompass() ); + if (attachToCam) { + final Node compass = createCompass(); + sciView.getCamera().addChild( compass ); + + compass.getUpdate().add(() -> { + final Camera cam = sciView.getCamera(); + compass.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f))); + compass.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate()); + return null; + }); + } } } From 8fae1648ab883401daff30805c468a97ab875ca1 Mon Sep 17 00:00:00 2001 From: Vladimir Ulman Date: Fri, 11 Sep 2020 22:37:11 +0200 Subject: [PATCH 2/2] CHG: overlay compass is a box --- .../commands/edit/AddOrientationCompass.java | 73 +++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java b/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java index 1ffe87e8..4ee889a0 100644 --- a/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java +++ b/src/main/java/sc/iview/commands/edit/AddOrientationCompass.java @@ -29,15 +29,17 @@ package sc.iview.commands.edit; import graphics.scenery.*; -import org.joml.Quaternionf; -import org.joml.Vector2f; import org.joml.Vector3f; +import org.joml.Matrix4f; +import org.joml.Quaternionf; import org.scijava.command.Command; import org.scijava.plugin.Menu; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; import sc.iview.SciView; +import java.lang.Math; + import static sc.iview.commands.MenuWeights.EDIT; import static sc.iview.commands.MenuWeights.EDIT_ADD_COMPASS; @@ -118,17 +120,76 @@ private Node createCompass() { return root; } + private Node createBox() { + final Node root = new Node("Scene representing box"); + + // X - red edges + final float halfPI = (float)(0.5*Math.PI); + final float edgeLen = 0.05f; + final float edgeRadius = 0.0008f; + for (int i = 0; i < 4; ++i) + { + final Node n = new Cylinder(edgeRadius,edgeLen,4); + n.getPosition().set( -0.5f * edgeLen ); + n.getPosition().add( new Vector3f(0, i%2 *edgeLen, i < 2 ? 0 : edgeLen) ); + n.setRotation( new Quaternionf().rotateXYZ(0,0,-halfPI).normalize() ); + n.setName("box edge: X"); + n.getMaterial().getDiffuse().set( new Vector3f(1,0,0) ); + n.getMaterial().setDepthTest(Material.DepthTest.Always); + //n.getMaterial().getBlending().setTransparent(true); + root.addChild( n ); + } + + // Y - green edges + for (int i = 0; i < 4; ++i) + { + final Node n = new Cylinder(edgeRadius,edgeLen,4); + n.getPosition().set( -0.5f * edgeLen ); + n.getPosition().add( new Vector3f(i%2 *edgeLen, 0, i < 2 ? 0 : edgeLen) ); + n.setName("box edge: Y"); + n.getMaterial().getDiffuse().set( new Vector3f(0,1,0) ); + n.getMaterial().setDepthTest(Material.DepthTest.Always); + //n.getMaterial().getBlending().setTransparent(true); + root.addChild( n ); + } + + // Z - blue edges + for (int i = 0; i < 4; ++i) + { + final Node n = new Cylinder(edgeRadius,edgeLen,4); + n.getPosition().set( -0.5f * edgeLen ); + n.getPosition().add( new Vector3f(i%2 *edgeLen, i < 2 ? 0 : edgeLen, 0) ); + n.setRotation( new Quaternionf().rotateXYZ(halfPI,0,0).normalize() ); + n.setName("box edge: Z"); + n.getMaterial().getDiffuse().set( new Vector3f(0,0,1) ); + n.getMaterial().setDepthTest(Material.DepthTest.Always); + //n.getMaterial().getBlending().setTransparent(true); + root.addChild( n ); + } + + return root; + } + @Override public void run() { if (showInTheScene) sciView.addNode( createCompass() ); if (attachToCam) { - final Node compass = createCompass(); + final Node compass = createBox(); sciView.getCamera().addChild( compass ); + compass.setWantsComposeModel(false); + + final float xStretch = sciView.getCamera().getProjection().m00(); + final float yStretch = sciView.getCamera().getProjection().m11(); + // + final Matrix4f positionDaBox = new Matrix4f(); + positionDaBox.set(1,0,0,0, //1st col + 0,1,0,0, //2nd col + 0,0,1,0, + -0.9f/xStretch,+0.85f/yStretch,-1.0f,1); compass.getUpdate().add(() -> { - final Camera cam = sciView.getCamera(); - compass.setPosition(cam.viewportToView(new Vector2f(-0.9f, 0.7f))); - compass.setRotation(new Quaternionf(sciView.getCamera().getRotation()).conjugate()); + sciView.getCamera().getRotation().get( compass.getModel() ); + compass.getModel().mulLocal( positionDaBox ); return null; }); }