Class ModelSurfaceTopology

java.lang.Object
gov.nih.mipav.view.renderer.J3D.model.structures.ModelSurfaceTopology
Direct Known Subclasses:
ModelSurfaceDecimator

public class ModelSurfaceTopology extends Object
This is an implementation of a vertex-edge-triangle table. It uses hash maps for storing the mesh components. Basic operations are supported including insertion and removal of triangles and accessing the mesh components and their adjacent components. More complex operations are also supported including determination if the mesh is connected, closed, or manifold, and allows for computing the connected components of a mesh. With additional computation time, the connected components can be created so that the triangles within each component are consistely ordered. See the document Level Set Extraction for more details on vertex-edge-triangle tables.
  • Field Details

    • m_kEMap

      protected HashMap m_kEMap
      map of invalid input: '<'Edge,EdgeAttribute>.
    • m_kTMap

      protected HashMap m_kTMap
      map of invalid input: '<'Triangle,TriangleAttribute>.
    • m_kVMap

      protected HashMap m_kVMap
      map of invalid input: '<'Vertex,VertexAttribute>.
  • Constructor Details

    • ModelSurfaceTopology

      public ModelSurfaceTopology()
      The default constructor whose job is solely to allocate the hashmaps for the vertex-edge-triangle table.
    • ModelSurfaceTopology

      public ModelSurfaceTopology(int iVCapacity, float fVLoad, int iECapacity, float fELoad, int iTCapacity, float fTLoad)
      Creates a new ModelSurfaceTopology object.
      Parameters:
      iVCapacity - the initial number of buckets in the vertex hashmap
      fVLoad - the load factor for the vertex hash map, in (0,1)
      iECapacity - the initial number of buckets in the edge hash map
      fELoad - the load factor for the edge hash map, in (0,1)
      iTCapacity - the initial number of buckets in the triangle hashmap
      fTLoad - the load factor for the triangle hash map, in (0,1)
  • Method Details

    • Create

      public ModelSurfaceTopology Create()
      A factory that is used for operations that create new meshes from the current one. This allows derived class construction within the base class operations.
      Returns:
      a new vertex-edge-triangle table of the correct derived-class type
    • getComponents

      public Vector getComponents()
      Construct the connected components of the mesh. The triangle ordering within a single component is not guaranteed to be consistent. That is, it is possible for a triangle to be counterclockwise ordered, but an adjacent triangle to be clockwise ordered.
      Returns:
      an array of components, each entry of type ModelSurfaceTopology
    • getComponents

      public int[] getComponents(Vector kIndex)
      Construct the connected components of the mesh by factoring the connectivity array into disjoint subarrays. The triangle ordering within a single component is not guaranteed to be consistent. That is, it is possible for a triangle to be counterclockwise ordered, but an adjacent triangle to be clockwise ordered.
      Parameters:
      kIndex - - An array whose entries indicate the starting point of each subarray in the returned integer array. Each entry is of type Integer. kIndex[0] always has value 0 since the first subarray always starts at the beginning. The next subarray is at kIndex[1]. The number of elements in the first subarray is kIndex[1]-kIndex[0]. The last entry kIndex[kIndex.size()-1] stores the total length of the returned array, so there are only kIndex.size()-1 subarrays.
      Returns:
      An array of indices that contain the disjoint subarrays in contiguous order.
    • getConsistentComponents

      public Vector getConsistentComponents()
      Construct the connected components of the mesh. The triangle ordering within a single component is guaranteed to be consistent. That is, all triangles in the component are counterclockwise ordered, or all are clockwise ordered. It is not possible to make ordering between two components consistent since this requires geometric information about how the components are placed in space relative to each other (requires specification of an eye point).
      Returns:
      an array of components (triangles), each entry of type ModelSurfaceTopology
    • getData

      public Object getData(ModelSurfaceTopology.Vertex kV)
      Get the attribute data associated with the specified vertex.
      Parameters:
      kV - the vertex whose attribute data will be retrieved
      Returns:
      the attribute data
    • getData

      public Object getData(ModelSurfaceTopology.Edge kE)
      Get the attribute data associated with the specified edge.
      Parameters:
      kE - the edge whose attribute data will be retrieved
      Returns:
      the attribute data
    • getData

      Get the attribute data associated with the specified triangle.
      Parameters:
      kT - the triangle whose attribute data will be retrieved
      Returns:
      the attribute data
    • getEdgeMap

      public HashMap getEdgeMap()
      Access the hash map of edges. This is useful for allowing an application to iterate over the edge/attribute pairs.
      Returns:
      the hash map of edges
    • getEdgeQuantity

      public int getEdgeQuantity()
      The number of edges currently in the table.
      Returns:
      the number of edges
    • getReversedOrderMesh

      public ModelSurfaceTopology getReversedOrderMesh()
      Reverse the order of each triangle in the mesh. If a triangle in the mesh is invalid input: '<'V0,V1,V2>, the returned vertex-edge-table contains a corresponding triangle invalid input: '<'V0,V2,V1>.
      Returns:
      the vertex-edge-table containing the reversed order triangles
    • getTriangleMap

      public HashMap getTriangleMap()
      Access the hash map of triangles. This is useful for allowing an application to iterate over the triangle/attribute pairs.
      Returns:
      the hash map of triangles
    • getTriangleQuantity

      public int getTriangleQuantity()
      The number of triangles currently in the table.
      Returns:
      the number of triangles
    • getVertexMap

      public HashMap getVertexMap()
      Access the hash map of vertices. This is useful for allowing an application to iterate over the vertex/attribute pairs.
      Returns:
      the hash map of vertices
    • getVertexQuantity

      public int getVertexQuantity()
      The number of vertices currently in the table.
      Returns:
      the number of vertices
    • insertTriangle

      public void insertTriangle(ModelSurfaceTopology.Triangle kT)
      Convenience function for inserting triangles into the mesh.
      Parameters:
      kT - the triangle to be inserted
    • insertTriangle

      public void insertTriangle(int iV0, int iV1, int iV2)
      Insert triangle invalid input: '<'V0,V1,V2> into the mesh. The ordering of the indices is relevant. Triangle invalid input: '<'V0,V2,V1> is considered to be a different triangle (reversed ordering from invalid input: '<'V0,V1,V2>).
      Parameters:
      iV0 - index of triangle
      iV1 - index of triangle
      iV2 - index of triangle
    • isClosed

      public boolean isClosed()
      Determine if the triangle mesh is closed. Each edge must have exactly two triangles sharing it
      Returns:
      true iff the mesh is closed
    • isConnected

      public boolean isConnected()
      Determine if the triangle mesh is connected.
      Returns:
      true iff the mesh is connected
    • isManifold

      public boolean isManifold()
      Determine if the triangle mesh is manifold. An edge is a manifold edge if it has at most two triangles sharing it.
      Returns:
      true iff the mesh is manifold
    • OnEdgeInsert

      public void OnEdgeInsert(ModelSurfaceTopology.Edge kE, boolean bCreate, ModelSurfaceTopology.EdgeAttribute kEAttr)
      Stub provided for overriding in derived classes. Each time an edge is attempted to be inserted into a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kE - the edge that was attempted to be inserted into the map
      bCreate - true if the edge did not exist in the map before insertion (it is a brand new edge), false if the edge already existed.
      kEAttr - the attribute for the edge
    • OnEdgeRemove

      public void OnEdgeRemove(ModelSurfaceTopology.Edge kE, boolean bDestroy, ModelSurfaceTopology.EdgeAttribute kEAttr)
      Stub provided for overriding in derived classes. Each time an edge is attempted to be removed from a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kE - the edge that was attempted to be removed from the map
      bDestroy - true if the edge did exist in the map before the attempted removal and no other mesh components are referencing the edge, false if the edge does exist in the map, but other mesh components are referencing it.
      kEAttr - the attribute for the edge
    • OnTriangleInsert

      public void OnTriangleInsert(ModelSurfaceTopology.Triangle kT, boolean bCreate, ModelSurfaceTopology.TriangleAttribute kTAttr)
      Stub provided for overriding in derived classes. Each time a triangle is attempted to be inserted into a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kT - the triangle that was attempted to be inserted into the map
      bCreate - true if the triangle did not exist in the map before insertion (it is a brand new triangle), false if the triangle already existed.
      kTAttr - the attribute for the triangle
    • OnTriangleRemove

      public void OnTriangleRemove(ModelSurfaceTopology.Triangle kT, boolean bDestroy, ModelSurfaceTopology.TriangleAttribute kTAttr)
      Stub provided for overriding in derived classes. Each time a triangle is attempted to be removed from a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kT - the triangle that was attempted to be removed from the map
      bDestroy - true if the triangle did exist in the map before the attempted removal and no other mesh components are referencing the triangle, false if the triangle does exist in the map, but other mesh components are referencing it.
      kTAttr - the attribute for the triangle
    • OnVertexInsert

      public void OnVertexInsert(ModelSurfaceTopology.Vertex kV, boolean bCreate, ModelSurfaceTopology.VertexAttribute kVAttr)
      Stub provided for overriding in derived classes. Each time a vertex is attempted to be inserted into a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kV - the vertex that was attempted to be inserted into the map
      bCreate - true if the vertex did not exist in the map before insertion (it is a brand new vertex), false if the vertex already existed.
      kVAttr - the attribute for the vertex
    • OnVertexRemove

      public void OnVertexRemove(ModelSurfaceTopology.Vertex kV, boolean bDestroy, ModelSurfaceTopology.VertexAttribute kVAttr)
      Stub provided for overriding in derived classes. Each time a vertex is attempted to be removed from a map, this function is called so that the derived class can perform actions specific to the application.
      Parameters:
      kV - the vertex that was attempted to be removed from the map
      bDestroy - true if the vertex did exist in the map before the attempted removal and no other mesh components are referencing the vertex, false if the vertex does exist in the map, but other mesh components are referencing it.
      kVAttr - the attribute for the vertex
    • print

      public void print(String kFilename) throws IOException
      Print the vertex-edge-triangle table to a text file. This function is provided for debugging support and is not needed by the triangle decimation scheme or surface visualizer.
      Parameters:
      kFilename - the name of the file to which the table should be printed
      Throws:
      IOException - if the specified file could not be opened for writing
    • removeComponent

      public int removeComponent(int iOffset, int[] aiConnect)
      Extract a connected component from the mesh and remove all the triangles of the component from the mesh. This is useful for computing the components in a very large mesh that uses a lot of memory. The intention is that the function is called until all components are found. The typical code is

      ModelSurfaceTopology kTopo = ; Vector kIndex = new Vector(); // vector of kIndex.add(new Integer(0)); int iITotalQuantity = 3*kTopo.getTriangleQuantity(); int[] aiConnect = new int[iITotalQuantity]; int iNumComponents = 0; for (int iIQuantity = 0; iIQuantity invalid input: '<' iITotalQuantity; ) { int iComponentIQuantity = kTopo.removeComponent(iIQuantity,aiConnect); iIQuantity += iComponentIQuantity; kIndex.add(new Integer(iQuantity)); iNumComponents++; }

      The components are stored contiguously in aiConnect. The starting index for component C is stored in the kIndex[C] for 0 invalid input: '<'= C invalid input: '<'= iNumComponents. kIndex[iNumComponents+1] stores the length of the connectivity array.

      Parameters:
      iOffset - the starting index in aiConnect where the next component is to be stored
      aiConnect - the array of connectivity indices that will store all the components
      Returns:
      the number of indices in the just-extracted component
    • removeTriangle

      public void removeTriangle(ModelSurfaceTopology.Triangle kT)
      Convenience function for removing triangles from the mesh.
      Parameters:
      kT - the triangle to be removed
    • removeTriangle

      public void removeTriangle(int iV0, int iV1, int iV2)
      Remove triangle invalid input: '<'V0,V1,V2> from the mesh. The ordering of the indices is relevant. Triangle invalid input: '<'V0,V2,V1> is considered to be a different triangle (reversed ordering from invalid input: '<'V0,V1,V2>).
      Parameters:
      iV0 - index of triangle
      iV1 - index of triangle
      iV2 - index of triangle
    • setData

      public void setData(ModelSurfaceTopology.Vertex kV, Object kData)
      Set the attribute data associated with the specified vertex.
      Parameters:
      kV - the vertex whose attribute data will be set
      kData - the attribute data
    • setData

      public void setData(ModelSurfaceTopology.Edge kE, Object kData)
      Set the attribute data associated with the specified edge.
      Parameters:
      kE - the edge whose attribute data will be set
      kData - the attribute data
    • setData

      public void setData(ModelSurfaceTopology.Triangle kT, Object kData)
      Set the attribute data associated with the specified triangle.
      Parameters:
      kT - the triangle whose attribute data will be set
      kData - the attribute data