Class ModelSurfaceTopology
- java.lang.Object
-
- gov.nih.mipav.view.renderer.J3D.model.structures.ModelSurfaceTopology
-
- Direct Known Subclasses:
ModelSurfaceDecimator
public class ModelSurfaceTopology extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ModelSurfaceTopology.Edge
A representation of an edge for the vertex-edge-triangle table.protected class
ModelSurfaceTopology.EdgeAttribute
The attributes associated with an edge.static class
ModelSurfaceTopology.Statistics
For debugging and testing.class
ModelSurfaceTopology.Triangle
A representation of a triangle for the vertex-edge-triangle table.protected class
ModelSurfaceTopology.TriangleAttribute
The attributes associated with a triangle.class
ModelSurfaceTopology.Vertex
A representation of a vertex for the vertex-edge-triangle table.protected class
ModelSurfaceTopology.VertexAttribute
The attributes associated with a vertex.
-
Constructor Summary
Constructors Constructor Description ModelSurfaceTopology()
The default constructor whose job is solely to allocate the hashmaps for the vertex-edge-triangle table.ModelSurfaceTopology(int iVCapacity, float fVLoad, int iECapacity, float fELoad, int iTCapacity, float fTLoad)
Creates a new ModelSurfaceTopology object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ModelSurfaceTopology
Create()
A factory that is used for operations that create new meshes from the current one.java.util.Vector
getComponents()
Construct the connected components of the mesh.int[]
getComponents(java.util.Vector kIndex)
Construct the connected components of the mesh by factoring the connectivity array into disjoint subarrays.java.util.Vector
getConsistentComponents()
Construct the connected components of the mesh.java.lang.Object
getData(ModelSurfaceTopology.Edge kE)
Get the attribute data associated with the specified edge.java.lang.Object
getData(ModelSurfaceTopology.Triangle kT)
Get the attribute data associated with the specified triangle.java.lang.Object
getData(ModelSurfaceTopology.Vertex kV)
Get the attribute data associated with the specified vertex.java.util.HashMap
getEdgeMap()
Access the hash map of edges.int
getEdgeQuantity()
The number of edges currently in the table.ModelSurfaceTopology
getReversedOrderMesh()
Reverse the order of each triangle in the mesh.java.util.HashMap
getTriangleMap()
Access the hash map of triangles.int
getTriangleQuantity()
The number of triangles currently in the table.java.util.HashMap
getVertexMap()
Access the hash map of vertices.int
getVertexQuantity()
The number of vertices currently in the table.void
insertTriangle(int iV0, int iV1, int iV2)
Insert triangleinto the mesh. void
insertTriangle(ModelSurfaceTopology.Triangle kT)
Convenience function for inserting triangles into the mesh.boolean
isClosed()
Determine if the triangle mesh is closed.boolean
isConnected()
Determine if the triangle mesh is connected.boolean
isManifold()
Determine if the triangle mesh is manifold.void
OnEdgeInsert(ModelSurfaceTopology.Edge kE, boolean bCreate, ModelSurfaceTopology.EdgeAttribute kEAttr)
Stub provided for overriding in derived classes.void
OnEdgeRemove(ModelSurfaceTopology.Edge kE, boolean bDestroy, ModelSurfaceTopology.EdgeAttribute kEAttr)
Stub provided for overriding in derived classes.void
OnTriangleInsert(ModelSurfaceTopology.Triangle kT, boolean bCreate, ModelSurfaceTopology.TriangleAttribute kTAttr)
Stub provided for overriding in derived classes.void
OnTriangleRemove(ModelSurfaceTopology.Triangle kT, boolean bDestroy, ModelSurfaceTopology.TriangleAttribute kTAttr)
Stub provided for overriding in derived classes.void
OnVertexInsert(ModelSurfaceTopology.Vertex kV, boolean bCreate, ModelSurfaceTopology.VertexAttribute kVAttr)
Stub provided for overriding in derived classes.void
OnVertexRemove(ModelSurfaceTopology.Vertex kV, boolean bDestroy, ModelSurfaceTopology.VertexAttribute kVAttr)
Stub provided for overriding in derived classes.void
print(java.lang.String kFilename)
Print the vertex-edge-triangle table to a text file.int
removeComponent(int iOffset, int[] aiConnect)
Extract a connected component from the mesh and remove all the triangles of the component from the mesh.void
removeTriangle(int iV0, int iV1, int iV2)
Remove trianglefrom the mesh. void
removeTriangle(ModelSurfaceTopology.Triangle kT)
Convenience function for removing triangles from the mesh.void
setData(ModelSurfaceTopology.Edge kE, java.lang.Object kData)
Set the attribute data associated with the specified edge.void
setData(ModelSurfaceTopology.Triangle kT, java.lang.Object kData)
Set the attribute data associated with the specified triangle.void
setData(ModelSurfaceTopology.Vertex kV, java.lang.Object kData)
Set the attribute data associated with the specified vertex.
-
-
-
Constructor Detail
-
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 hashmapfVLoad
- the load factor for the vertex hash map, in (0,1)iECapacity
- the initial number of buckets in the edge hash mapfELoad
- the load factor for the edge hash map, in (0,1)iTCapacity
- the initial number of buckets in the triangle hashmapfTLoad
- the load factor for the triangle hash map, in (0,1)
-
-
Method Detail
-
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 java.util.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(java.util.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 java.util.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 java.lang.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 java.lang.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
public java.lang.Object getData(ModelSurfaceTopology.Triangle kT)
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 java.util.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, the returned vertex-edge-table contains a corresponding triangle . - Returns:
- the vertex-edge-table containing the reversed order triangles
-
getTriangleMap
public java.util.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 java.util.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 triangleinto the mesh. The ordering of the indices is relevant. Triangle is considered to be a different triangle (reversed ordering from ). - Parameters:
iV0
- index of triangleiV1
- index of triangleiV2
- 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 mapbCreate
- 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 mapbDestroy
- 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 mapbCreate
- 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 mapbDestroy
- 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 mapbCreate
- 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 mapbDestroy
- 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(java.lang.String kFilename) throws java.io.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:
java.io.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 isModelSurfaceTopology 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 < 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 <= C <= 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 storedaiConnect
- 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 trianglefrom the mesh. The ordering of the indices is relevant. Triangle is considered to be a different triangle (reversed ordering from ). - Parameters:
iV0
- index of triangleiV1
- index of triangleiV2
- index of triangle
-
setData
public void setData(ModelSurfaceTopology.Vertex kV, java.lang.Object kData)
Set the attribute data associated with the specified vertex.- Parameters:
kV
- the vertex whose attribute data will be setkData
- the attribute data
-
setData
public void setData(ModelSurfaceTopology.Edge kE, java.lang.Object kData)
Set the attribute data associated with the specified edge.- Parameters:
kE
- the edge whose attribute data will be setkData
- the attribute data
-
setData
public void setData(ModelSurfaceTopology.Triangle kT, java.lang.Object kData)
Set the attribute data associated with the specified triangle.- Parameters:
kT
- the triangle whose attribute data will be setkData
- the attribute data
-
-