![]() |
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality. More...
#include <SurgSim/DataStructures/TriangleMeshBase.h>
Public Types | |
typedef MeshElement< 2, EdgeData > | EdgeType |
Edge type for convenience (Ids of the 2 vertices) More... | |
typedef MeshElement< 3, TriangleData > | TriangleType |
Triangle type for convenience (Ids of the 3 vertices) More... | |
![]() | |
typedef Vertex< VertexData > | VertexType |
Vertex type for convenience. More... | |
Public Member Functions | |
TriangleMeshBase () | |
Constructor. The mesh is initially empty (no vertices, no edges, no triangles). More... | |
template<class VertexDataSource , class EdgeDataSource , class TriangleDataSource > | |
TriangleMeshBase (const TriangleMeshBase< VertexDataSource, EdgeDataSource, TriangleDataSource > &mesh) | |
Copy constructor. More... | |
virtual | ~TriangleMeshBase () |
Destructor. More... | |
size_t | addEdge (const EdgeType &edge) |
Adds an edge to the mesh. More... | |
size_t | addTriangle (const TriangleType &triangle) |
Adds a triangle to the mesh. More... | |
size_t | getNumEdges () const |
Get the number of edges. More... | |
size_t | getNumTriangles () const |
Get the number of triangles. More... | |
const std::vector< EdgeType > & | getEdges () const |
Retrieve all edges. More... | |
std::vector< EdgeType > & | getEdges () |
Retrieve all edges (non const version) More... | |
const std::vector< TriangleType > & | getTriangles () const |
Retrieve all triangles. More... | |
std::vector< TriangleType > & | getTriangles () |
Retrieve all triangles (non const version) More... | |
const EdgeType & | getEdge (size_t id) const |
Retrieve a specific edge. More... | |
EdgeType & | getEdge (size_t id) |
Retrieve a specific edge (non const version) More... | |
const TriangleType & | getTriangle (size_t id) const |
Retrieve a specific triangle. More... | |
TriangleType & | getTriangle (size_t id) |
Retrieve a specific triangle (non const version) More... | |
void | removeTriangle (size_t id) |
Marks a triangle as invalid, the triangle cannot be accessed via getTriangle anymore. More... | |
std::array< SurgSim::Math::Vector3d, 3 > | getTrianglePositions (size_t id) const |
Returns an array of the triangle's vertices' positions. More... | |
bool | isValid () const |
Test if the TriangleMeshBase is valid (valid vertex Ids used in all MeshElements) More... | |
![]() | |
Vertices () | |
Constructor. The mesh is initially empty (no vertices). More... | |
virtual | ~Vertices () |
Destructor. More... | |
void | clear () |
Clear mesh to return to an empty state (no vertices). More... | |
void | update () |
Performs any updates that are required when the vertices are modified. More... | |
size_t | addVertex (const VertexType &vertex) |
Adds a vertex to the mesh. More... | |
size_t | getNumVertices () const |
Returns the number of vertices in this mesh. More... | |
const VertexType & | getVertex (size_t id) const |
Returns the specified vertex. More... | |
VertexType & | getVertex (size_t id) |
Returns the specified vertex (non const version). More... | |
const std::vector< VertexType > & | getVertices () const |
Returns a vector containing the position of each vertex. More... | |
std::vector< VertexType > & | getVertices () |
Returns a vector containing the position of each vertex (non const version). More... | |
void | setVertexPosition (size_t id, const SurgSim::Math::Vector3d &position) |
Sets the position of a vertex. More... | |
const SurgSim::Math::Vector3d & | getVertexPosition (size_t id) const |
Returns the position of a vertex. More... | |
void | setVertexPositions (const std::vector< SurgSim::Math::Vector3d > &positions, bool doUpdate=true) |
Sets the position of each vertex. More... | |
bool | operator== (const Vertices &mesh) const |
Compares the mesh with another one (equality) More... | |
bool | operator!= (const Vertices &mesh) const |
Compares the mesh with another one (inequality) More... | |
Protected Member Functions | |
virtual void | doClearEdges () |
Remove all edges from the mesh. More... | |
virtual void | doClearTriangles () |
Remove all triangles from the mesh. More... | |
virtual bool | isEqual (const Vertices< VertexData > &mesh) const |
Internal comparison of meshes of the same type: returns true if equal, false if not equal. More... | |
![]() | |
virtual void | doClearVertices () |
Remove all vertices from the mesh. More... | |
Private Member Functions | |
virtual void | doClear () |
Clear mesh to return to an empty state (no vertices, no edges, no triangles). More... | |
Private Attributes | |
std::vector< EdgeType > | m_edges |
Edges. More... | |
std::vector< TriangleType > | m_triangles |
Triangles. More... | |
std::vector< size_t > | m_freeTriangles |
List of indices of deleted triangles, to be reused when another triangle is added. More... | |
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality.
TriangleMeshBase is to be used purely as a data structure and not provide implementation of algorithms. For example, a physics 2D FEM is not a subclass of TriangleMeshBase, but may use a TriangleMeshBase for storing the structure of the FEM.
It is recommended that subclasses with a specific purpose (such as for use in collision detection) provide convenience methods for creation of vertices, edges, and triangles and the data each contains. Methods such as createVertex(position, other data...), createEdge(vertices, other data...), and createTriangle(vertices, other data...) simplify the creation of vertices and elements and the data required. These methods would use the addVertex(), addEdge(), and addTriangle() methods to add the created vertices and elements to the TriangleMeshBase.
Overriding isEqual(const Mesh&) is necessary to do more than just basic list comparison of the vertices, edges, and triangles, which is dependent on order in the list.
Override doUpdate() to provide update functionality when vertices are changes, such as recalculating surface normals.
A subclass that is designed for a specific use (such as collision detection) may also specify the VertexData, EdgeData, and TriangleData to what is required.
VertexData | Type of extra data stored in each vertex |
EdgeData | Type of extra data stored in each edge |
TriangleData | Type of extra data stored in each triangle |
typedef MeshElement<2, EdgeData> SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::EdgeType |
Edge type for convenience (Ids of the 2 vertices)
typedef MeshElement<3, TriangleData> SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleType |
Triangle type for convenience (Ids of the 3 vertices)
SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleMeshBase | ( | ) |
Constructor. The mesh is initially empty (no vertices, no edges, no triangles).
|
explicit |
Copy constructor.
VertexDataSource | Type of extra data stored in each vertex |
EdgeDataSource | Type of extra data stored in each edge |
TriangleDataSource | Type of extra data stored in each triangle |
mesh | The mesh to be copied from. Vertex, edge and triangle data will be emptied. |
|
virtual |
Destructor.
size_t SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::addEdge | ( | const EdgeType & | edge | ) |
Adds an edge to the mesh.
No checking on the edge's vertices is performed. Recommend that subclasses with a specific purpose (such as for use in collision detection) have a createEdge(vertices, other data...) method which performs any checking desired and sets up the edge data based on the vertices and other parameters.
edge | Edge to add to the mesh |
size_t SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::addTriangle | ( | const TriangleType & | triangle | ) |
Adds a triangle to the mesh.
triangle | Triangle to add to the mesh Recommend that subclasses with a specific purpose (such as for use in collision detection) have a createTriangle(vertices, other data...) method which performs any checking desired and sets up the triangle data based on the vertices and other parameters. |
|
privatevirtual |
Clear mesh to return to an empty state (no vertices, no edges, no triangles).
Reimplemented from SurgSim::DataStructures::Vertices< VertexData >.
|
protectedvirtual |
Remove all edges from the mesh.
|
protectedvirtual |
Remove all triangles from the mesh.
const TriangleMeshBase< VertexData, EdgeData, TriangleData >::EdgeType & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getEdge | ( | size_t | id | ) | const |
Retrieve a specific edge.
id | the edge to be retrieved. |
TriangleMeshBase< VertexData, EdgeData, TriangleData >::EdgeType & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getEdge | ( | size_t | id | ) |
Retrieve a specific edge (non const version)
id | the edge to be retrieved. |
const std::vector< typename TriangleMeshBase< VertexData, EdgeData, TriangleData >::EdgeType > & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getEdges | ( | ) | const |
Retrieve all edges.
std::vector< typename TriangleMeshBase< VertexData, EdgeData, TriangleData >::EdgeType > & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getEdges | ( | ) |
Retrieve all edges (non const version)
size_t SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getNumEdges | ( | ) | const |
Get the number of edges.
size_t SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getNumTriangles | ( | ) | const |
Get the number of triangles.
const TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleType & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getTriangle | ( | size_t | id | ) | const |
Retrieve a specific triangle.
SurgSim::Framework::AssertionFailure | if the given triangle was deleted |
id | The id of the triangle to retrieve |
TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleType & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getTriangle | ( | size_t | id | ) |
Retrieve a specific triangle (non const version)
SurgSim::Framework::AssertionFailure | if the give triangle was deleted |
id | The id of the triangle to retrieve |
std::array< SurgSim::Math::Vector3d, 3 > SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getTrianglePositions | ( | size_t | id | ) | const |
Returns an array of the triangle's vertices' positions.
id | the id of the triangle |
const std::vector< typename TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleType > & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getTriangles | ( | ) | const |
Retrieve all triangles.
std::vector< typename TriangleMeshBase< VertexData, EdgeData, TriangleData >::TriangleType > & SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::getTriangles | ( | ) |
Retrieve all triangles (non const version)
|
protectedvirtual |
Internal comparison of meshes of the same type: returns true if equal, false if not equal.
Override this method to provide custom comparison. Basic TriangleMeshBase implementation compares vertices, edges and triangles: the order of vertices, edges, and triangles must also match to be considered equal.
mesh | Mesh must be of the same type as that which it is compared against |
Reimplemented from SurgSim::DataStructures::Vertices< VertexData >.
bool SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::isValid | ( | ) | const |
Test if the TriangleMeshBase is valid (valid vertex Ids used in all MeshElements)
void SurgSim::DataStructures::TriangleMeshBase< VertexData, EdgeData, TriangleData >::removeTriangle | ( | size_t | id | ) |
Marks a triangle as invalid, the triangle cannot be accessed via getTriangle anymore.
id | triangle to delete |
|
private |
Edges.
|
private |
List of indices of deleted triangles, to be reused when another triangle is added.
|
private |
Triangles.