Added clipping to annotating volumes for worm untwisting.
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 8 Mar 2018 21:30:17 +0000 (21:30 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Thu, 8 Mar 2018 21:30:17 +0000 (21:30 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15406 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/view/renderer/WildMagic/Interface/JPanelClip_WM.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/Render/VolumeVOI.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/VolumeTriPlanarRender.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/VolumeTriPlanarRenderBase.java
mipav/src/plugins/PlugInDialogVolumeRender.java

index a7d99b6..b7dff86 100644 (file)
@@ -4,6 +4,7 @@ package gov.nih.mipav.view.renderer.WildMagic.Interface;
 import gov.nih.mipav.view.MipavUtil;\r
 import gov.nih.mipav.view.ViewJColorChooser;\r
 import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarInterface;\r
+import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarRender;\r
 \r
 import java.awt.BorderLayout;\r
 import java.awt.Color;\r
@@ -102,6 +103,26 @@ public class JPanelClip_WM extends JInterfaceBase
     }\r
 \r
     /**\r
+     * 3D clipping dialog control.\r
+     * @param kVolumeViewer parent frame.\r
+     */\r
+    public JPanelClip_WM( VolumeTriPlanarRender rayBasedRenderWM ) {\r
+       this.rayBasedRenderWM = rayBasedRenderWM; \r
+        clipValue[CLIP_X_INV] = rayBasedRenderWM.getImage().getExtents()[0];\r
+        clipValue[CLIP_X] = 0;\r
+        clipValue[CLIP_Y_INV] = rayBasedRenderWM.getImage().getExtents()[1];\r
+        clipValue[CLIP_Y] = 0;\r
+        clipValue[CLIP_Z_INV] = rayBasedRenderWM.getImage().getExtents()[2];\r
+        clipValue[CLIP_Z] = 0;\r
+        clipValue[CLIP_EYE_INV] = rayBasedRenderWM.getImage().getExtents()[2];\r
+        clipValue[CLIP_EYE] = 0;\r
+        clipValue[CLIP_A] = clipValue[CLIP_X_INV];//(int)(Math.max( clipValue[CLIP_X_INV], Math.max( clipValue[CLIP_Y_INV], clipValue[CLIP_Z_INV]) ) );\r
+\r
+        // Build dialog.\r
+        init();\r
+    }\r
+\r
+    /**\r
      * Changes color of slices box frame and button if color button was pressed; turns bounding box on and off if\r
      * checkbox was pressed.\r
      *\r
@@ -691,6 +712,21 @@ public class JPanelClip_WM extends JInterfaceBase
         }\r
     }\r
 \r
+    public void setRenderer( VolumeTriPlanarRender rayBasedRenderWM ) {\r
+       this.rayBasedRenderWM = rayBasedRenderWM; \r
+        clipValue[CLIP_X_INV] = rayBasedRenderWM.getImage().getExtents()[0];\r
+        clipValue[CLIP_X] = 0;\r
+        clipValue[CLIP_Y_INV] = rayBasedRenderWM.getImage().getExtents()[1];\r
+        clipValue[CLIP_Y] = 0;\r
+        clipValue[CLIP_Z_INV] = rayBasedRenderWM.getImage().getExtents()[2];\r
+        clipValue[CLIP_Z] = 0;\r
+        clipValue[CLIP_EYE_INV] = rayBasedRenderWM.getImage().getExtents()[2];\r
+        clipValue[CLIP_EYE] = 0;\r
+        clipValue[CLIP_A] = clipValue[CLIP_X_INV];//(int)(Math.max( clipValue[CLIP_X_INV], Math.max( clipValue[CLIP_Y_INV], clipValue[CLIP_Z_INV]) ) );\r
+\r
+        // Build dialog.\r
+        init();\r
+    }\r
 \r
     /**\r
      * Sets the x slider and the labels beside and beneath it to the state given by <code>flag</code>.\r
index f1233ef..a6dcbc5 100644 (file)
@@ -176,7 +176,7 @@ public class VolumeVOI extends VolumeObject
         */\r
        public void Render( Renderer kRenderer, Culler kCuller, boolean bPreRender, boolean bSolid )\r
        {\r
-               if ( !m_bDisplay || !bSolid )\r
+               if ( !m_bDisplay || !bSolid || m_bClipped)\r
                {\r
                        return;\r
                }\r
@@ -326,6 +326,51 @@ public class VolumeVOI extends VolumeObject
 //             }\r
 //     }\r
 \r
+       private Vector3f m_kClip = null;\r
+       private Vector3f m_kClipInv = null;\r
+       private boolean m_bClipped = false;\r
+    /** Sets axis-aligned clipping for the VolumeShaderEffect.\r
+     * @param afClip the clipping parameters for axis-aligned clipping.\r
+     */\r
+    public void SetClip( int iWhich, float data, boolean bEnable)\r
+    {          \r
+       if ( m_kVOI.getType() == VOI.ANNOTATION )\r
+       {\r
+               if ( m_kClip == null )\r
+               {\r
+                       m_kClip = new Vector3f();\r
+                       m_kClipInv = new Vector3f( m_kVolumeImageA.GetImage().getExtents()[0], m_kVolumeImageA.GetImage().getExtents()[1], m_kVolumeImageA.GetImage().getExtents()[2] );\r
+               }\r
+                       switch ( iWhich ) {\r
+                       case 0:\r
+                               m_kClip.X = data * (m_kVolumeImageA.GetImage().getExtents()[0] - 1);\r
+                               break;\r
+                       case 1:\r
+                               m_kClipInv.X = data * (m_kVolumeImageA.GetImage().getExtents()[0] - 1);\r
+                               break;\r
+                       case 2:\r
+                               m_kClip.Y = data * (m_kVolumeImageA.GetImage().getExtents()[1] - 1);\r
+                               break;\r
+                       case 3:\r
+                               m_kClipInv.Y = data * (m_kVolumeImageA.GetImage().getExtents()[1] - 1);\r
+                               break;\r
+                       case 4:\r
+                               m_kClip.Z = data * (m_kVolumeImageA.GetImage().getExtents()[2] - 1);\r
+                               break;\r
+                       case 5:\r
+                               m_kClipInv.Z = data * (m_kVolumeImageA.GetImage().getExtents()[2] - 1);\r
+                               break;\r
+                       }\r
+               Vector3f test = m_kVOI.elementAt(0);\r
+                       m_bClipped = ( (test.X < m_kClip.X) || (test.X > m_kClipInv.X) || (test.Y < m_kClip.Y) || (test.Y > m_kClipInv.Y) || (test.Z < m_kClip.Z) || (test.Z > m_kClipInv.Z) );\r
+//             test = m_kVOI.elementAt(1);\r
+//                     m_bClipped |= ( (test.X < m_kClip.X) || (test.X > m_kClipInv.X) || (test.Y < m_kClip.Y) || (test.Y > m_kClipInv.Y) || (test.Z < m_kClip.Z) || (test.Z > m_kClipInv.Z) );\r
+                       System.err.println( test );\r
+                       System.err.println( m_kClip );\r
+                       System.err.println( m_kClipInv );\r
+       }\r
+    }\r
+    \r
        /**\r
         * Sets the slice information for the shader.\r
         * @param bUseSlice\r
index 2dfbcc9..204bbc1 100644 (file)
@@ -1498,6 +1498,20 @@ implements GLEventListener, KeyListener, MouseMotionListener,  MouseListener, Na
                                                                // step along the ray and pick the voxel with the highest value:\r
                                                                p0.add(step);\r
                                                                // test for clipping:\r
+                                                               if ( m_kVolumeRayCast.GetShaderEffect().isClip() )\r
+                                                               {\r
+                                                                       test.copy( p0 );\r
+                                                                       Vector3f clip = m_kVolumeRayCast.GetShaderEffect().getClip();  \r
+                                                                       clip.scale((m_kVolumeImageA.GetImage().getExtents()[0] - 1), (m_kVolumeImageA.GetImage().getExtents()[1] - 1), (m_kVolumeImageA.GetImage().getExtents()[2] - 1) );\r
+                                                                       Vector3f clipInv = m_kVolumeRayCast.GetShaderEffect().getClipInv();\r
+                                                                       clipInv.scale((m_kVolumeImageA.GetImage().getExtents()[0] - 1), (m_kVolumeImageA.GetImage().getExtents()[1] - 1), (m_kVolumeImageA.GetImage().getExtents()[2] - 1) );\r
+                                                                       \r
+                                                                       if ( (test.X < clip.X) || (test.X > clipInv.X) || (test.Y < clip.Y) || (test.Y > clipInv.Y) || (test.Z < clip.Z) || (test.Z > clipInv.Z) )\r
+                                                                       {\r
+                                                                               continue;\r
+                                                                       }\r
+                                                                       \r
+                                                               }\r
                                                                if ( ellipsoidClip != null ) {\r
                                                                        test.copy( p0 );\r
                                                                        m_kVolumeRayCast.volumeToLocalCoords( test );\r
index 779d5ec..8aea691 100644 (file)
@@ -2100,6 +2100,10 @@ public class VolumeTriPlanarRenderBase extends GPURenderBase implements
                                ((VolumeSurface) m_kDisplayList.get(i)).SetClip(iWhich, fValue,\r
                                                bEnable);\r
                        }\r
+                       if (m_kDisplayList.get(i) instanceof VolumeVOI) {\r
+                               ((VolumeVOI) m_kDisplayList.get(i)).SetClip(iWhich, fValue,\r
+                                               bEnable);\r
+                       }\r
                }\r
        }\r
 \r
index 477ba63..84e5739 100644 (file)
@@ -49,6 +49,7 @@ import gov.nih.mipav.view.dialogs.GuiBuilder;
 import gov.nih.mipav.view.dialogs.JDialogBase;\r
 import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarInterface;\r
 import gov.nih.mipav.view.renderer.WildMagic.VolumeTriPlanarRender;\r
+import gov.nih.mipav.view.renderer.WildMagic.Interface.JPanelClip_WM;\r
 import gov.nih.mipav.view.renderer.WildMagic.Render.VolumeImage;\r
 import gov.nih.mipav.view.renderer.WildMagic.WormUntwisting.WormData;\r
 import gov.nih.mipav.view.renderer.WildMagic.WormUntwisting.WormSegmentation;\r
@@ -169,6 +170,8 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
        private JButton nextButton;\r
        \r
        private JPanel opacityPanel;\r
+       private JPanel clipPanel;\r
+       private JPanelClip_WM clipGUI;\r
        \r
        private PlugInDialogVolumeRender parent;\r
        private VOI finalLattice;\r
@@ -606,6 +609,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                kTransfer.addPoint((min + ((max - min) * 2.0f / 3.0f)), 255 * 0.333f);\r
                kTransfer.addPoint(max, 0);\r
                volumeRenderer.getVolumeImage().UpdateImages(kTransfer, 0, null);\r
+               updateClipPanel();\r
 \r
 //             System.err.println( "algorithmPerformed" );\r
                voiManager = new VOILatticeManagerInterface( null, volumeImage.GetImage(), null, 0, true, null );\r
@@ -1091,6 +1095,7 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                {\r
                                        volumeRenderer.setVisible(true);\r
                                }\r
+                               updateClipPanel();\r
                                if ( !tabbedPane.isVisible() || !volumePanel.isVisible() )\r
                                {\r
                                        tabbedPane.setVisible(true);\r
@@ -1687,9 +1692,11 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
 \r
                lutPanel = new JPanel();\r
                opacityPanel = new JPanel();\r
+               clipPanel = new JPanel();\r
                tabbedPane = new JTabbedPane();\r
                tabbedPane.addTab("LUT", null, lutPanel);\r
                tabbedPane.addTab("Opacity", null, opacityPanel);\r
+               tabbedPane.addTab("Clip", null, clipPanel);\r
                tabbedPane.setVisible(false);\r
                \r
                JPanel leftPanel = new JPanel(new BorderLayout());\r
@@ -2233,5 +2240,20 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                volumeImage.GetImage().addImageDisplayListener(this);\r
        }\r
 \r
+       private void updateClipPanel()\r
+       {\r
+               if ( clipGUI == null ) \r
+               {\r
+                       clipGUI = new JPanelClip_WM(volumeRenderer);\r
+               }\r
+               else\r
+               {\r
+                       clipGUI.setRenderer(volumeRenderer);\r
+                       clipPanel.removeAll();\r
+               }\r
+               clipPanel.add(clipGUI.getMainPanel() );\r
+        clipGUI.resizePanel(clipPanel.getWidth(), 400);\r
+               clipPanel.revalidate();\r
+       }\r
 \r
 }\r