Class ModelQuadMesh

  • All Implemented Interfaces:
    javax.media.j3d.GeometryUpdater

    public class ModelQuadMesh
    extends javax.media.j3d.IndexedQuadArray
    implements javax.media.j3d.GeometryUpdater
    A simple quadrilateral mesh that represents a level surface. The mesh only stores vertex positions and vertex normals. The surface viewer creates a Shape3D object whose geometry is an object from ModelQuadMesh. The surface color is provided through the LUT. To save memory, everything is done by reference - the connection array, the vertex array, the normal array, and the color array are all stored here and modified directly.
    Author:
    Matthew J. McAuliffe, Ph.D., David Eberley, Neva Cherniavsky
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.vecmath.Color3f[] colors3f
      Holds colors for vertices.
      private int[] connect
      Holds how vertices are connected.
      private float heightRange
      Scale the height of the vertice - typically relative the image size.
      private float[][] LUT
      Holds current LUT which dictates colors for vertices.
      private int[] lutBufferRemapped
      DOCUMENT ME!
      private javax.vecmath.Vector3f m_kE0
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Vector3f m_kE1
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Vector3f m_kN1
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Point3f m_kV0
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Point3f m_kV1
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Point3f m_kV2
      Temporary variables to avoid 'new' calls.
      private javax.vecmath.Vector3f[] normal
      Holds normals in the mesh.
      private javax.vecmath.Point3f[] vertex
      Holds vertices in the mesh.
      • Fields inherited from class javax.media.j3d.IndexedGeometryArray

        ALLOW_COLOR_INDEX_READ, ALLOW_COLOR_INDEX_WRITE, ALLOW_COORDINATE_INDEX_READ, ALLOW_COORDINATE_INDEX_WRITE, ALLOW_NORMAL_INDEX_READ, ALLOW_NORMAL_INDEX_WRITE, ALLOW_TEXCOORD_INDEX_READ, ALLOW_TEXCOORD_INDEX_WRITE, ALLOW_VERTEX_ATTR_INDEX_READ, ALLOW_VERTEX_ATTR_INDEX_WRITE
      • Fields inherited from class javax.media.j3d.GeometryArray

        ALLOW_COLOR_READ, ALLOW_COLOR_WRITE, ALLOW_COORDINATE_READ, ALLOW_COORDINATE_WRITE, ALLOW_COUNT_READ, ALLOW_COUNT_WRITE, ALLOW_FORMAT_READ, ALLOW_NORMAL_READ, ALLOW_NORMAL_WRITE, ALLOW_REF_DATA_READ, ALLOW_REF_DATA_WRITE, ALLOW_TEXCOORD_READ, ALLOW_TEXCOORD_WRITE, ALLOW_VERTEX_ATTR_READ, ALLOW_VERTEX_ATTR_WRITE, BY_REFERENCE, BY_REFERENCE_INDICES, COLOR_3, COLOR_4, COORDINATES, INTERLEAVED, NORMALS, TEXTURE_COORDINATE_2, TEXTURE_COORDINATE_3, TEXTURE_COORDINATE_4, USE_COORD_INDEX_ONLY, USE_NIO_BUFFER, VERTEX_ATTRIBUTES
      • Fields inherited from class javax.media.j3d.Geometry

        ALLOW_INTERSECT
    • Constructor Summary

      Constructors 
      Constructor Description
      ModelQuadMesh​(javax.vecmath.Point3f[] akVertex, int[] aiConnect, int length1, int length2, float[][] LUT, float hgtRange)
      A quad mesh whose vertex normal vectors are computed from the geometry of the mesh itself.
      ModelQuadMesh​(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, int[] aiConnect)
      A quad mesh whose vertex normal vectors have been precomputed.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void computeNormals()
      A normal vector at a vertex is computed by averaging the triangle normals for all triangles sharing the vertex.
      void dispose()
      Sets all variables to null.
      static ModelQuadMesh loadQMesh​(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total)
      Load the quad mesh from a binary file.
      protected void print​(java.io.PrintWriter kOut)
      Internal support for 'void print (String)' and 'void print (String, ModelTriangleMesh[])'.
      void print​(java.lang.String kName)
      Save the quad mesh to a text file.
      static void print​(java.lang.String kName, ModelTriangleMesh[] akComponent)
      Save an array of quad meshes to a text file.
      protected void save​(java.io.RandomAccessFile kOut, ViewJProgressBar progress, int added, int total)
      Internal support for 'void save (String)' and 'void save (String, ModelQuadMesh[])'.
      static void save​(java.lang.String kName, ModelQuadMesh[] akComponent, ViewJProgressBar progress)
      Save an array of quad meshes to a binary file.
      void save​(java.lang.String kName, ViewJProgressBar progress, int added, int total)
      Save the quad mesh to a binary file.
      void setLUT​(float[][] LUT)
      I don't think both are needed in the new Model LUT design. /** Accessor that sets the LUT for the colors of the indices.
      void setLUTBufferRemapped​(int[] lutBufferRemapped)
      Set.
      void updateData​(javax.media.j3d.Geometry geometry)
      This method is required for an implementor of the GeometryUpdater interface.
      • Methods inherited from class javax.media.j3d.IndexedQuadArray

        cloneNodeComponent
      • Methods inherited from class javax.media.j3d.IndexedGeometryArray

        getColorIndex, getColorIndices, getCoordinateIndex, getCoordinateIndices, getCoordIndicesRef, getIndexCount, getInitialIndexIndex, getNormalIndex, getNormalIndices, getTextureCoordinateIndex, getTextureCoordinateIndex, getTextureCoordinateIndices, getTextureCoordinateIndices, getValidIndexCount, getVertexAttrIndex, getVertexAttrIndices, setColorIndex, setColorIndices, setCoordinateIndex, setCoordinateIndices, setCoordIndicesRef, setInitialColorIndex, setInitialCoordIndex, setInitialIndexIndex, setInitialNormalIndex, setInitialTexCoordIndex, setInitialVertexAttrIndex, setInitialVertexIndex, setNormalIndex, setNormalIndices, setTextureCoordinateIndex, setTextureCoordinateIndex, setTextureCoordinateIndices, setTextureCoordinateIndices, setValidIndexCount, setValidVertexCount, setVertexAttrIndex, setVertexAttrIndices
      • Methods inherited from class javax.media.j3d.GeometryArray

        getColor, getColor, getColor, getColor, getColor, getColor, getColorRef3b, getColorRef3f, getColorRef4b, getColorRef4f, getColorRefBuffer, getColorRefByte, getColorRefFloat, getColors, getColors, getColors, getColors, getColors, getColors, getCoordinate, getCoordinate, getCoordinate, getCoordinate, getCoordinates, getCoordinates, getCoordinates, getCoordinates, getCoordRef3d, getCoordRef3f, getCoordRefBuffer, getCoordRefDouble, getCoordRefFloat, getInitialColorIndex, getInitialCoordIndex, getInitialNormalIndex, getInitialTexCoordIndex, getInitialVertexAttrIndex, getInitialVertexIndex, getInterleavedVertexBuffer, getInterleavedVertices, getNormal, getNormal, getNormalRef3f, getNormalRefBuffer, getNormalRefFloat, getNormals, getNormals, getTexCoordRef2f, getTexCoordRef3f, getTexCoordRefBuffer, getTexCoordRefFloat, getTexCoordSetCount, getTexCoordSetMap, getTexCoordSetMapLength, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getValidVertexCount, getVertexAttr, getVertexAttr, getVertexAttr, getVertexAttr, getVertexAttrCount, getVertexAttrRefBuffer, getVertexAttrRefFloat, getVertexAttrs, getVertexAttrs, getVertexAttrs, getVertexAttrs, getVertexAttrSizes, getVertexCount, getVertexFormat, setColor, setColor, setColor, setColor, setColor, setColor, setColorRef3b, setColorRef3f, setColorRef4b, setColorRef4f, setColorRefBuffer, setColorRefByte, setColorRefFloat, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setCoordinate, setCoordinate, setCoordinate, setCoordinate, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordRef3d, setCoordRef3f, setCoordRefBuffer, setCoordRefDouble, setCoordRefFloat, setInterleavedVertexBuffer, setInterleavedVertices, setNormal, setNormal, setNormalRef3f, setNormalRefBuffer, setNormalRefFloat, setNormals, setNormals, setNormals, setNormals, setTexCoordRef2f, setTexCoordRef3f, setTexCoordRefBuffer, setTexCoordRefFloat, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setVertexAttr, setVertexAttr, setVertexAttr, setVertexAttr, setVertexAttrRefBuffer, setVertexAttrRefFloat, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, updateData
      • Methods inherited from class javax.media.j3d.NodeComponent

        cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree
      • Methods inherited from class javax.media.j3d.SceneGraphObject

        clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString, updateNodeReferences
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • colors3f

        private javax.vecmath.Color3f[] colors3f
        Holds colors for vertices.
      • connect

        private int[] connect
        Holds how vertices are connected.
      • heightRange

        private float heightRange
        Scale the height of the vertice - typically relative the image size.
      • LUT

        private float[][] LUT
        Holds current LUT which dictates colors for vertices.
      • lutBufferRemapped

        private int[] lutBufferRemapped
        DOCUMENT ME!
      • m_kE0

        private javax.vecmath.Vector3f m_kE0
        Temporary variables to avoid 'new' calls.
      • m_kE1

        private javax.vecmath.Vector3f m_kE1
        Temporary variables to avoid 'new' calls.
      • m_kN1

        private javax.vecmath.Vector3f m_kN1
        Temporary variables to avoid 'new' calls.
      • m_kV0

        private javax.vecmath.Point3f m_kV0
        Temporary variables to avoid 'new' calls.
      • m_kV1

        private javax.vecmath.Point3f m_kV1
        Temporary variables to avoid 'new' calls.
      • m_kV2

        private javax.vecmath.Point3f m_kV2
        Temporary variables to avoid 'new' calls.
      • normal

        private javax.vecmath.Vector3f[] normal
        Holds normals in the mesh.
      • vertex

        private javax.vecmath.Point3f[] vertex
        Holds vertices in the mesh.
    • Constructor Detail

      • ModelQuadMesh

        public ModelQuadMesh​(javax.vecmath.Point3f[] akVertex,
                             javax.vecmath.Vector3f[] akNormal,
                             int[] aiConnect)
        A quad mesh whose vertex normal vectors have been precomputed.
        Parameters:
        akVertex - Array of vertices in the mesh.
        akNormal - Array of vertex normals for the mesh.
        aiConnect - Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
      • ModelQuadMesh

        public ModelQuadMesh​(javax.vecmath.Point3f[] akVertex,
                             int[] aiConnect,
                             int length1,
                             int length2,
                             float[][] LUT,
                             float hgtRange)
        A quad mesh whose vertex normal vectors are computed from the geometry of the mesh itself. The normal at a vertex is the normalized average of normals of the triangles that share the vertex. This constructor makes a quad mesh whose vertices and colors are set by reference.
        Parameters:
        akVertex - Array of vertices in the mesh.
        aiConnect - Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
        length1 - True length of vertex array.
        length2 - True length of connection array.
        LUT - LUT for colors.
        hgtRange - Used to scale the height of the vertices
    • Method Detail

      • loadQMesh

        public static ModelQuadMesh loadQMesh​(java.io.RandomAccessFile kIn,
                                              ViewJProgressBar progress,
                                              int added,
                                              int total)
                                       throws java.io.IOException
        Load the quad mesh from a binary file. The caller then calls this function for each mesh. The format for a mesh is
                int vCount;  // number of vertices
                Point3f vertices[vCount];
                Point3f normals[vCount];
                int iCount;  // number of indices in the connectivity array
                int indices[iCount];
          
        with 4-byte quantities stored in Big Endian format.
        Parameters:
        kIn - The file from which the triangle mesh is loaded.
        progress - DOCUMENT ME!
        added - DOCUMENT ME!
        total - DOCUMENT ME!
        Returns:
        The loaded quad mesh.
        Throws:
        java.io.IOException - if there is an error reading from the file
      • print

        public static void print​(java.lang.String kName,
                                 ModelTriangleMesh[] akComponent)
                          throws java.io.IOException
        Save an array of quad meshes to a text file. The format for the file is
               int type;  // 2 = ModelQuadMesh
               int aCount;  // number of array elements
               array of 'aCount' meshes, each of the form:
               int vCount;  // number of vertices
               vertex[0].x vertex[0].y vertex[0].z;
               :
               normal[0].x normal[0].y normal[0].z;
               :
               int tCount;  // number of quadrilaterals
               index[0] index[1] index[2] index[3]
               :
         index[4*(tCount-1)] index[4*(tCount-1)+1] index[4*(tCount-1)+2] index[4*(tCount-1)+3]
         
        Parameters:
        kName - The name of the file to which the components are saved.
        akComponent - The array of mesh components to save
        Throws:
        java.io.IOException - if the specified file could not be opened for writing.
      • save

        public static void save​(java.lang.String kName,
                                ModelQuadMesh[] akComponent,
                                ViewJProgressBar progress)
                         throws java.io.IOException
        Save an array of quad meshes to a binary file. The format for the file is
                int type;        // 2 = ModelQuadMesh
                int aCount;      // number of array elements
                array of 'aCount' meshes, each of the form:
                int vCount;      // number of vertices
                Point3f vertices[vCount];
                Point3f normals[vCount];
                int iCount;      // number of indices in the connectivity array
                int indices[iCount];
          
        with 4-byte quantities stored in Big Endian format.
        Parameters:
        kName - The name of the file to which the components are saved.
        akComponent - The array of mesh components to be saved.
        progress - DOCUMENT ME!
        Throws:
        java.io.IOException - if there is an error writing to the file.
      • computeNormals

        public void computeNormals()
        A normal vector at a vertex is computed by averaging the triangle normals for all triangles sharing the vertex. This routine computes all vertex normals.
      • dispose

        public void dispose()
        Sets all variables to null.
      • print

        public void print​(java.lang.String kName)
                   throws java.io.IOException
        Save the quad mesh to a text file. The format for the file is
               int type;    // 2 = ModelQuadMesh
               int aCount;  // 1, write the entire mesh as a single component
               int vCount;  // number of vertices
               vertex[0].x vertex[0].y vertex[0].z;
               :
               normal[0].x normal[0].y normal[0].z;
               :
               int tCount;  // number of quadrilaterals
               index[0] index[1] index[2] index[3]
               :
               index[4*(tCount-1)] index[4*(tCount-1)+1] index[4*(tCount-1)+2] index[4*(tCount-1)+3]
         
        Parameters:
        kName - The name of file to which the triangle mesh is saved.
        Throws:
        java.io.IOException - If the specified file could not be opened for writing.
      • save

        public void save​(java.lang.String kName,
                         ViewJProgressBar progress,
                         int added,
                         int total)
                  throws java.io.IOException
        Save the quad mesh to a binary file. The format for the file is
                int type;     // 2 = ModelQuadMesh
                int aCount;   // 1, write the entire mesh as a single component
                int vCount;   // number of vertices
                Point3f vertices[vCount];
                Point3f normals[vCount];
                int iCount;  // number of indices in the connectivity array
                int indices[iCount];
          
        with 4-byte quantities stored in Big Endian format.
        Parameters:
        kName - The name of the file to which the triangle mesh is saved.
        progress - DOCUMENT ME!
        added - DOCUMENT ME!
        total - DOCUMENT ME!
        Throws:
        java.io.IOException - if the specified file could not be opened for writing.
      • setLUT

        public void setLUT​(float[][] LUT)
        I don't think both are needed in the new Model LUT design. /** Accessor that sets the LUT for the colors of the indices.
        Parameters:
        LUT - New LUT to use when setting vertex colors.
      • setLUTBufferRemapped

        public void setLUTBufferRemapped​(int[] lutBufferRemapped)
        Set.
        Parameters:
        lutBufferRemapped - int[]
      • updateData

        public void updateData​(javax.media.j3d.Geometry geometry)
        This method is required for an implementor of the GeometryUpdater interface. It is not called directly by the application. It sets the colors of the vertices based on the LUT. The System.gc() call is necessary because otherwise the application eats up memory.
        Specified by:
        updateData in interface javax.media.j3d.GeometryUpdater
        Parameters:
        geometry - Geometry object to update (ignored).
      • print

        protected void print​(java.io.PrintWriter kOut)
                      throws java.io.IOException
        Internal support for 'void print (String)' and 'void print (String, ModelTriangleMesh[])'. ModelTriangleMesh uses this function to print vertices, normals, and connectivity indices to the file. ModelClodMesh overrides this to additionally print collapse records to the file
        Parameters:
        kOut - The file to which the triangle mesh is saved.
        Throws:
        java.io.IOException - if there is an error writing to the file.
      • save

        protected void save​(java.io.RandomAccessFile kOut,
                            ViewJProgressBar progress,
                            int added,
                            int total)
                     throws java.io.IOException
        Internal support for 'void save (String)' and 'void save (String, ModelQuadMesh[])'. ModelQuadMesh uses this function to write vertices, normals, and connectivity indices to the file.
        Parameters:
        kOut - The file to which the quad mesh is saved.
        progress - DOCUMENT ME!
        added - DOCUMENT ME!
        total - DOCUMENT ME!
        Throws:
        java.io.IOException - if there is an error writing to the file