Added a quick prototype for visually clipping the volume so the user can annotate...
authorabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 2 Mar 2018 20:21:08 +0000 (20:21 +0000)
committerabokinsky <abokinsky@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 2 Mar 2018 20:21:08 +0000 (20:21 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15396 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/view/renderer/WildMagic/Render/VolumeClipEffect.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/Render/VolumeRayCast.java
mipav/src/gov/nih/mipav/view/renderer/WildMagic/Render/VolumeShaderEffectMultiPassDynamic.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 727cc9b..5191dfb 100644 (file)
@@ -1,6 +1,7 @@
 package gov.nih.mipav.view.renderer.WildMagic.Render;\r
 \r
 \r
+import WildMagic.LibFoundation.Mathematics.Ellipsoid3f;\r
 import WildMagic.LibFoundation.Mathematics.Matrix4f;\r
 import WildMagic.LibFoundation.Mathematics.Vector3f;\r
 import WildMagic.LibFoundation.Mathematics.Vector4f;\r
@@ -49,6 +50,13 @@ public abstract class VolumeClipEffect extends ShaderEffect
 \r
 \r
     protected float[] m_afVolumeMatrix = { 1f, 0f, 0f, 0f,  0f, 1f, 0f, 0f,  0f, 0f, 1f, 0f,  0f, 0f, 0f, 1f };\r
+    \r
+    protected boolean m_bClipEllipsoid = false;\r
+    protected float[] m_afClipEllipsoidCenter = {0,0,0,0};\r
+    protected float[] m_afClipEllipsoidAxis0 = {0,0,0,0};\r
+    protected float[] m_afClipEllipsoidAxis1 = {0,0,0,0};\r
+    protected float[] m_afClipEllipsoidAxis2 = {0,0,0,0};\r
+    protected float[] m_afClipEllipsoidExtent = {0,0,0,0};\r
 \r
     /* (non-Javadoc)\r
      * @see WildMagic.LibGraphics.Effects.ShaderEffect#dispose()\r
@@ -94,6 +102,26 @@ public abstract class VolumeClipEffect extends ShaderEffect
         {\r
             pkCProgram.GetUC("volumeMatrix").SetDataSource(m_afVolumeMatrix);\r
         }\r
+        if ( pkCProgram.GetUC("ellipsoidCenter") != null ) \r
+        {\r
+            pkCProgram.GetUC("ellipsoidCenter").SetDataSource(m_afClipEllipsoidCenter);\r
+        }\r
+        if ( pkCProgram.GetUC("ellipsoidAxis0") != null ) \r
+        {\r
+            pkCProgram.GetUC("ellipsoidAxis0").SetDataSource(m_afClipEllipsoidAxis0);\r
+        }\r
+        if ( pkCProgram.GetUC("ellipsoidAxis1") != null ) \r
+        {\r
+            pkCProgram.GetUC("ellipsoidAxis1").SetDataSource(m_afClipEllipsoidAxis1);\r
+        }\r
+        if ( pkCProgram.GetUC("ellipsoidAxis2") != null ) \r
+        {\r
+            pkCProgram.GetUC("ellipsoidAxis2").SetDataSource(m_afClipEllipsoidAxis2);\r
+        }\r
+        if ( pkCProgram.GetUC("ellipsoidExtent") != null ) \r
+        {\r
+            pkCProgram.GetUC("ellipsoidExtent").SetDataSource(m_afClipEllipsoidExtent);\r
+        }\r
         super.OnLoadPrograms( iPass, pkVProgram, pkPProgram, pkCProgram );\r
     }\r
 \r
@@ -174,6 +202,17 @@ public abstract class VolumeClipEffect extends ShaderEffect
         EnableClip();\r
     }\r
     \r
+    public void SetClipEllipsoid(Ellipsoid3f ellipsoid, boolean bEnable ) {\r
+       m_bClipEllipsoid = true;\r
+       m_afClipEllipsoidCenter[0] = ellipsoid.Center.X;        m_afClipEllipsoidCenter[1] = ellipsoid.Center.Y;        m_afClipEllipsoidCenter[2] = ellipsoid.Center.Z;\r
+       m_afClipEllipsoidAxis0[0] = ellipsoid.Axis[0].X;        m_afClipEllipsoidAxis0[1] = ellipsoid.Axis[0].Y;        m_afClipEllipsoidAxis0[2] = ellipsoid.Axis[0].Z;\r
+       m_afClipEllipsoidAxis1[0] = ellipsoid.Axis[1].X;        m_afClipEllipsoidAxis1[1] = ellipsoid.Axis[1].Y;        m_afClipEllipsoidAxis1[2] = ellipsoid.Axis[1].Z;\r
+       m_afClipEllipsoidAxis2[0] = ellipsoid.Axis[2].X;        m_afClipEllipsoidAxis2[1] = ellipsoid.Axis[2].Y;        m_afClipEllipsoidAxis2[2] = ellipsoid.Axis[2].Z;\r
+       m_afClipEllipsoidExtent[0] = ellipsoid.Extent[0];       m_afClipEllipsoidExtent[1] = ellipsoid.Extent[1];       m_afClipEllipsoidExtent[2] = ellipsoid.Extent[2];\r
+\r
+        m_afDoClip[0] = (bEnable) ? 1 : m_afDoClip[0];\r
+    }\r
+    \r
     public void setVolumeMatrix( float[] volumeMatrix )\r
     {\r
        m_afVolumeMatrix = volumeMatrix;\r
@@ -198,6 +237,11 @@ public abstract class VolumeClipEffect extends ShaderEffect
        return (m_afClipAll[8] | m_afClipAll[7] | m_afClipAll[6]);\r
     }    \r
     \r
+    public boolean isClipEllipsoid()\r
+    {\r
+       return m_bClipEllipsoid;\r
+    }\r
+    \r
     public Vector3f getClip()\r
     {\r
        return new Vector3f( m_aafClipData[CLIP_X][0], m_aafClipData[CLIP_Y][0], m_aafClipData[CLIP_Z][0] );\r
index 3ac26f1..08c9eba 100644 (file)
@@ -8,6 +8,7 @@ import java.util.Vector;
 import WildMagic.LibFoundation.Intersection.IntrSegment3Plane3f;\r
 import WildMagic.LibFoundation.Mathematics.ColorRGB;\r
 import WildMagic.LibFoundation.Mathematics.ColorRGBA;\r
+import WildMagic.LibFoundation.Mathematics.Ellipsoid3f;\r
 import WildMagic.LibFoundation.Mathematics.Matrix4f;\r
 import WildMagic.LibFoundation.Mathematics.Plane3f;\r
 import WildMagic.LibFoundation.Mathematics.Segment3f;\r
@@ -578,6 +579,11 @@ public class VolumeRayCast extends VolumeObject
     {\r
         m_kVolumeShaderEffect.SetClipEyeInv(afEquation, bEnable);\r
     }\r
+    \r
+    public void SetClipEllipsoid( Ellipsoid3f ellipsoid, boolean bEnable )\r
+    {\r
+       m_kVolumeShaderEffect.SetClipEllipsoid(ellipsoid, bEnable);\r
+    }\r
 \r
     public void SetCustomBlend(int iBlendEquation, int iLogicOp, int iSrcBlend, int iDstBlend, ColorRGBA kColor  )\r
     {\r
index 71351b7..4da72e9 100644 (file)
@@ -8,6 +8,8 @@ import gov.nih.mipav.view.renderer.WildMagic.Render.MultiDimensionalTransfer.Cla
 import gov.nih.mipav.view.renderer.WildMagic.Render.MultiDimensionalTransfer.ClassificationWidgetState;
 import gov.nih.mipav.view.renderer.WildMagic.Render.MultiDimensionalTransfer.ClassificationWidget;
 import WildMagic.LibFoundation.Mathematics.ColorRGBA;
+import WildMagic.LibFoundation.Mathematics.Ellipsoid3f;
+import WildMagic.LibFoundation.Mathematics.Vector3f;
 import WildMagic.LibGraphics.ObjectSystem.StreamInterface;
 import WildMagic.LibGraphics.Rendering.Texture;
 import WildMagic.LibGraphics.Shaders.PixelShader;
@@ -64,6 +66,19 @@ public class VolumeShaderEffectMultiPassDynamic extends VolumeShaderEffectMultiP
        + "uniform vec4 clipEye;" + "\n"
        + "uniform vec4 clipEyeInv;" + "\n"
        + "" + "\n";
+    
+    private static String clipEllipsoidParameters = ""
+        + "uniform vec4 ellipsoidCenter;" + "\n"
+        + "uniform vec4 ellipsoidAxis0;" + "\n"
+        + "uniform vec4 ellipsoidAxis1;" + "\n"
+        + "uniform vec4 ellipsoidAxis2;" + "\n"
+        + "uniform vec4 ellipsoidExtent;" + "\n"
+        + "" + "\n";
+               
+    
+//    private static String filterParameters = ""
+//             + "uniform float filterRadius;" + "\n"
+//             + "" + "\n";
 
     private static String lightingParametersBasicColorA = ""
        + "uniform sampler3D eNormalMapA;" + "\n";
@@ -357,6 +372,21 @@ public class VolumeShaderEffectMultiPassDynamic extends VolumeShaderEffectMultiP
        + "   }" + "\n"
        + "}" + "\n";
 
+    private static String clipEllipsoidSetup = ""
+        + "if ( bClipped != 1.0 ) {" + "\n"
+       + "   vec3 clipDif = position.xyz - ellipsoidCenter.xyz;" + "\n"
+       + "   float aDot0 = dot(ellipsoidAxis0.xyz, clipDif);" + "\n"
+       + "   float ratio0 = aDot0 / ellipsoidExtent.x;" + "\n"
+       + "   float aDot1 = dot(ellipsoidAxis1.xyz, clipDif);" + "\n"
+       + "   float ratio1 = aDot1 / ellipsoidExtent.y;" + "\n"
+       + "   float aDot2 = dot(ellipsoidAxis2.xyz, clipDif);" + "\n"
+       + "   float ratio2 = aDot2 / ellipsoidExtent.z;" + "\n"
+       + "   float clipEllipsoid = ratio0*ratio0+ratio1*ratio1+ratio2*ratio2-1.0f;" + "\n"
+       + "   if ( clipEllipsoid > 0 ) {" + "\n"
+       + "     bClipped = 1.0;" + "\n"
+       + "   }" + "\n"
+       + "}" + "\n";
+
     public static String surfaceInit = ""
        + "vec4 LocalMaterialDiffuse = MaterialDiffuse;" + "\n"
        + "vec4 LocalMaterialSpecular = MaterialSpecular;" + "\n"
@@ -643,6 +673,11 @@ public class VolumeShaderEffectMultiPassDynamic extends VolumeShaderEffectMultiP
        super.SetClipEyeInv(afEquation, bEnable);
        checkPixelProgram();
     }
+    
+    public void SetClipEllipsoid(Ellipsoid3f ellipsoid, boolean bEnable ) {
+       super.SetClipEllipsoid(ellipsoid, bEnable);
+       checkPixelProgram();
+    }
 
     public void SetGradientMagnitude(boolean bShow)
     {
@@ -899,10 +934,18 @@ public class VolumeShaderEffectMultiPassDynamic extends VolumeShaderEffectMultiP
        {
                text += clipAEParameters;
        }
+       if ( isClipEllipsoid() )
+       {
+               text += clipEllipsoidParameters;
+       }
        //if ( (m_afBlendParam[0] != 1.0) )
        {
                text += blendParameters;
        }
+       
+//     if ( doFilter ) {
+//             text += filterParameters;
+//     }
        // End Parameters
        
        // add generated color code:
@@ -926,6 +969,10 @@ public class VolumeShaderEffectMultiPassDynamic extends VolumeShaderEffectMultiP
                {
                        text += clipAESetup;                            
                }
+               if ( isClipEllipsoid() )
+               {
+                       text += clipEllipsoidSetup;
+               }
        }
        if ( (m_afDoClip[0] != 0) )
        {
index 32c0d91..943b112 100644 (file)
@@ -1074,6 +1074,12 @@ implements GLEventListener, KeyListener, MouseMotionListener,  MouseListener, Na
                        case KeyEvent.VK_DELETE:\r
                                deleteSelectedPoint( );\r
                                break;\r
+                       case KeyEvent.VK_PAGE_DOWN:\r
+                               applyClipFilter(true);\r
+                               break;\r
+                       case KeyEvent.VK_PAGE_UP:\r
+                               applyClipFilter(false);\r
+                               break;\r
                        }\r
                // look for shortcuts now\r
                        if ( m_kVOIInterface != null )\r
index e946afb..3c07649 100644 (file)
@@ -64,8 +64,11 @@ import javax.swing.event.ChangeListener;
 \r
 import org.jocl.CL;\r
 \r
+import WildMagic.LibFoundation.Containment.ContBox3f;\r
+import WildMagic.LibFoundation.Mathematics.Box3f;\r
 import WildMagic.LibFoundation.Mathematics.ColorRGB;\r
 import WildMagic.LibFoundation.Mathematics.ColorRGBA;\r
+import WildMagic.LibFoundation.Mathematics.Ellipsoid3f;\r
 import WildMagic.LibFoundation.Mathematics.Matrix3f;\r
 import WildMagic.LibFoundation.Mathematics.Matrix4f;\r
 import WildMagic.LibFoundation.Mathematics.Vector2d;\r
@@ -1468,6 +1471,12 @@ public class VolumeTriPlanarRenderBase extends GPURenderBase implements
                char ucKey = e.getKeyChar();\r
                super.keyPressed(e);\r
                switch (ucKey) {\r
+               case 'l':\r
+                       applyClipFilter(true);\r
+                       break;\r
+               case 'L':\r
+                       applyClipFilter(false);\r
+                       break;\r
                case 'z':\r
                        m_bDoClip = !m_bDoClip;\r
                        System.err.println("Clipping is " + m_bDoClip);\r
@@ -3847,5 +3856,107 @@ public class VolumeTriPlanarRenderBase extends GPURenderBase implements
 //     System.err.println(max);\r
 //     System.err.println("");\r
     }\r
-       \r
+    \r
+    private int xFilter = 0;\r
+    private int yFilter = 0;\r
+    private int zFilter = 0;\r
+    private Ellipsoid3f ellipsoidClip = null;\r
+    private Box3f orientedBox = null;\r
+    protected void applyClipFilter(boolean increase) {\r
+               if (m_kVolumeRayCast == null) {\r
+                       return;\r
+               }\r
+               int[] aiExtents = m_kVolumeImageA.GetImage().getExtents();\r
+               if ( ellipsoidClip == null ) {\r
+                       System.err.println("creating oriented ellipse");\r
+//                     Vector<Vector3f> insidePts = new Vector<Vector3f>();\r
+//                     float max = (float) m_kVolumeImageA.GetImage().getMax();\r
+//                     for ( int z = 0; z < aiExtents[2]; z++ ) {\r
+//                             for ( int y = 0; y < aiExtents[1]; y++ ) {\r
+//                                     for ( int x = 0; x < aiExtents[0]; x++ ) {\r
+//                                             float value = m_kVolumeImageA.GetImage().getFloat(x,y,z);\r
+//                                             if ( value > (.5*max) ) {\r
+//                                                     Vector3f volumePt = new Vector3f(x,y,z);\r
+////                                                   volumePt.X /= aiExtents[0];\r
+////                                                   volumePt.Y /= aiExtents[1];\r
+////                                                   volumePt.Z /= aiExtents[2];\r
+////                                                   \r
+////                                                   volumePt.X *= m_fX;\r
+////                                                   volumePt.Y *= m_fY;\r
+////                                                   volumePt.Z *= m_fZ;\r
+////                                                   m_kVolumeRayCast.volumeToLocalCoords(volumePt);\r
+//                                                     insidePts.add(volumePt);\r
+//                                             }\r
+//                                     }\r
+//                             }\r
+//                     }\r
+//                     orientedBox = ContBox3f.ContOrientedBox(insidePts.size(), insidePts);\r
+//                     System.err.println(orientedBox.Center);\r
+//                     System.err.println(orientedBox.Extent[0] + "  " + orientedBox.Extent[1] + "  " + orientedBox.Extent[2] );\r
+//                     System.err.println(orientedBox.Axis[0] + "  " + orientedBox.Axis[1] + "  " + orientedBox.Axis[2] );\r
+//                     System.err.println("done " + insidePts.size() );\r
+\r
+//                     ellipsoidClip =  new Ellipsoid3f( new Vector3f( m_fX/2f, m_fY/2f, m_fZ/2f), new Vector3f[]{Vector3f.UNIT_X, Vector3f.UNIT_Y, Vector3f.UNIT_Z}, new float[]{m_fX, m_fY, m_fZ} );\r
+                       ellipsoidClip =  new Ellipsoid3f( new Vector3f( .5f, .5f, .5f ), new Vector3f[]{Vector3f.UNIT_X, Vector3f.UNIT_Y, Vector3f.UNIT_Z}, new float[]{m_fX, m_fY, m_fZ} );\r
+                       m_kVolumeRayCast.SetClipEllipsoid( ellipsoidClip, true );\r
+               }\r
+               \r
+               if ( increase )\r
+               {\r
+                       ellipsoidClip.Extent[0] *= .99;\r
+                       ellipsoidClip.Extent[1] *= .99;\r
+                       ellipsoidClip.Extent[2] *= .99;\r
+                       if ( ellipsoidClip.Extent[0] < (0.05 * m_fX) || ellipsoidClip.Extent[1] < (0.05 * m_fY) || ellipsoidClip.Extent[2] < (0.05 * m_fZ) ) {\r
+                               ellipsoidClip.Extent[0] = (float) (0.05 * m_fX);\r
+                               ellipsoidClip.Extent[1] = (float) (0.05 * m_fY);\r
+                               ellipsoidClip.Extent[2] = (float) (0.05 * m_fZ);\r
+                       }\r
+//                     System.err.println(ellipsoidClip.Extent[0] + "  " + ellipsoidClip.Extent[1] + "  " + ellipsoidClip.Extent[2] );\r
+                       m_kVolumeRayCast.SetClipEllipsoid( ellipsoidClip, true );\r
+               }\r
+               else\r
+               {\r
+                       ellipsoidClip.Extent[0] *= 1.01;\r
+                       ellipsoidClip.Extent[1] *= 1.01;\r
+                       ellipsoidClip.Extent[2] *= 1.01;\r
+//                     ellipsoidClip.Extent[0] = Math.min( ellipsoidClip.Extent[0], orientedBox.Extent[0] );\r
+//                     ellipsoidClip.Extent[1] = Math.min( ellipsoidClip.Extent[1], orientedBox.Extent[1] );\r
+//                     ellipsoidClip.Extent[2] = Math.min( ellipsoidClip.Extent[2], orientedBox.Extent[2] );\r
+//                     System.err.println(ellipsoidClip.Extent[0] + "  " + ellipsoidClip.Extent[1] + "  " + ellipsoidClip.Extent[2] );\r
+                       if ( ellipsoidClip.Extent[0] > m_fX || ellipsoidClip.Extent[1] > m_fY || ellipsoidClip.Extent[2] > m_fZ ) {\r
+                               ellipsoidClip.Extent[0] = m_fX;\r
+                               ellipsoidClip.Extent[1] = m_fY;\r
+                               ellipsoidClip.Extent[2] = m_fZ;\r
+                       }\r
+                       m_kVolumeRayCast.SetClipEllipsoid( ellipsoidClip, true );\r
+               }\r
+               \r
+//     if ( increase ) {\r
+//             xFilter++;\r
+//             yFilter++;\r
+//             zFilter++;\r
+//             xFilter = Math.min(xFilter, aiExtents[0]/2 );\r
+//             yFilter = Math.min(yFilter, aiExtents[1]/2 );\r
+//             zFilter = Math.min(zFilter, aiExtents[2]/2 );\r
+//     }\r
+//     else {\r
+//             xFilter--;\r
+//             yFilter--;\r
+//             zFilter--;\r
+//             xFilter = Math.max(xFilter, 0 );\r
+//             yFilter = Math.max(yFilter, 0 );\r
+//             zFilter = Math.max(zFilter, 0 );\r
+//             \r
+//     }\r
+//        setClipPlane( 0, xFilter, true );\r
+//        setClipPlane( 1, (aiExtents[0] -1) - xFilter, true );\r
+//        setClipPlane( 2, yFilter, true );\r
+//        setClipPlane( 3, (aiExtents[1] -1) - yFilter, true );\r
+//        setClipPlane( 4, zFilter, true );\r
+//        setClipPlane( 5, (aiExtents[2] -1) - zFilter, true );\r
+//        for ( int i = 0; i < 6; i++ )\r
+//        {\r
+//            displayClipPlane( i, false, ColorRGB.BLACK );\r
+//        }\r
+    }\r
 }\r
index 45330c1..477ba63 100644 (file)
@@ -619,9 +619,11 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                        voiManager.setAnnotations(annotations);\r
                                        if ( editMode == EditAnnotations1 || editMode == EditAnnotations2 )\r
                                        {\r
-                                               VOIVector latticeVector = new VOIVector();\r
-                                               latticeVector.add(finalLattice);\r
-                                               voiManager.setLattice(latticeVector);\r
+                                               if ( finalLattice != null ) {\r
+                                                       VOIVector latticeVector = new VOIVector();\r
+                                                       latticeVector.add(finalLattice);\r
+                                                       voiManager.setLattice(latticeVector);\r
+                                               }\r
                                        }\r
 \r
                                        for (int i = 0; i < annotations.elementAt(0).getCurves().size(); i++)\r
@@ -888,7 +890,10 @@ public class PlugInDialogVolumeRender extends JFrame implements ActionListener,
                                        if ( whichImage == 0 )\r
                                        {\r
                                                // continue with the default file:\r
-                                               wormImage.registerVOI( finalLattice );\r
+                                               if ( finalLattice != null ) \r
+                                               {\r
+                                                       wormImage.registerVOI( finalLattice );\r
+                                               }\r
                                                wormData.readMarkers();                         \r
 \r
                                                if ( annotations != null )\r