All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriangleMeshBase.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DATASTRUCTURES_TRIANGLEMESHBASE_H
17 #define SURGSIM_DATASTRUCTURES_TRIANGLEMESHBASE_H
18 
19 #include <array>
20 
23 
24 namespace SurgSim
25 {
26 namespace DataStructures
27 {
28 class EmptyData;
29 
57 template <class VertexData, class EdgeData, class TriangleData>
58 class TriangleMeshBase : public Vertices<VertexData>
59 {
60 public:
65 
68 
75  template <class VertexDataSource, class EdgeDataSource, class TriangleDataSource>
77 
79  virtual ~TriangleMeshBase();
80 
88  size_t addEdge(const EdgeType& edge);
89 
97  size_t addTriangle(const TriangleType& triangle);
98 
101  size_t getNumEdges() const;
102 
107  size_t getNumTriangles() const;
108 
111  const std::vector<EdgeType>& getEdges() const;
112 
115  std::vector<EdgeType>& getEdges();
116 
123  const std::vector<TriangleType>& getTriangles() const;
124 
131  std::vector<TriangleType>& getTriangles();
132 
136  const EdgeType& getEdge(size_t id) const;
137 
141  EdgeType& getEdge(size_t id);
142 
147  const TriangleType& getTriangle(size_t id) const;
148 
153  TriangleType& getTriangle(size_t id);
154 
160  void removeTriangle(size_t id);
161 
165  std::array<SurgSim::Math::Vector3d, 3> getTrianglePositions(size_t id) const;
166 
169  bool isValid() const;
170 
171 protected:
173  virtual void doClearEdges();
174 
176  virtual void doClearTriangles();
177 
183  virtual bool isEqual(const Vertices<VertexData>& mesh) const;
184 private:
185 
187  virtual void doClear();
188 
190  std::vector<EdgeType> m_edges;
191 
193  std::vector<TriangleType> m_triangles;
194 
196  std::vector<size_t> m_freeTriangles;
197 
198 public:
199  // Dependent name resolution for inherited functions and typenames from templates
200  using typename Vertices<VertexData>::VertexType;
202 };
203 
204 
205 }; // namespace DataStructures
206 
207 }; // namespace SurgSim
208 
210 
211 #endif // SURGSIM_DATASTRUCTURES_TRIANGLEMESHBASE_H
bool isValid() const
Test if the TriangleMeshBase is valid (valid vertex Ids used in all MeshElements) ...
Definition: TriangleMeshBase-inl.h:194
size_t addEdge(const EdgeType &edge)
Adds an edge to the mesh.
Definition: TriangleMeshBase-inl.h:68
void removeTriangle(size_t id)
Marks a triangle as invalid, the triangle cannot be accessed via getTriangle anymore.
Definition: TriangleMeshBase-inl.h:169
std::vector< EdgeType > m_edges
Edges.
Definition: TriangleMeshBase.h:190
virtual void doClearEdges()
Remove all edges from the mesh.
Definition: TriangleMeshBase-inl.h:230
MeshElement< 3, TriangleData > TriangleType
Triangle type for convenience (Ids of the 3 vertices)
Definition: TriangleMeshBase.h:64
const std::vector< TriangleType > & getTriangles() const
Retrieve all triangles.
Definition: TriangleMeshBase-inl.h:124
Vertex structure for meshes.
Definition: Vertex.h:44
virtual ~TriangleMeshBase()
Destructor.
Definition: TriangleMeshBase-inl.h:63
size_t getNumEdges() const
Get the number of edges.
Definition: TriangleMeshBase-inl.h:97
std::vector< size_t > m_freeTriangles
List of indices of deleted triangles, to be reused when another triangle is added.
Definition: TriangleMeshBase.h:196
TriangleMeshBase()
Constructor. The mesh is initially empty (no vertices, no edges, no triangles).
Definition: TriangleMeshBase-inl.h:27
virtual bool isEqual(const Vertices< VertexData > &mesh) const
Internal comparison of meshes of the same type: returns true if equal, false if not equal...
Definition: TriangleMeshBase-inl.h:243
std::array< SurgSim::Math::Vector3d, 3 > getTrianglePositions(size_t id) const
Returns an array of the triangle's vertices' positions.
Definition: TriangleMeshBase-inl.h:179
const EdgeType & getEdge(size_t id) const
Retrieve a specific edge.
Definition: TriangleMeshBase-inl.h:138
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality...
Definition: TriangleMeshBase.h:58
size_t getNumTriangles() const
Get the number of triangles.
Definition: TriangleMeshBase-inl.h:103
virtual void doClearTriangles()
Remove all triangles from the mesh.
Definition: TriangleMeshBase-inl.h:236
virtual void doClear()
Clear mesh to return to an empty state (no vertices, no edges, no triangles).
Definition: TriangleMeshBase-inl.h:251
size_t addTriangle(const TriangleType &triangle)
Adds a triangle to the mesh.
Definition: TriangleMeshBase-inl.h:75
std::vector< TriangleType > m_triangles
Triangles.
Definition: TriangleMeshBase.h:193
Element structure for meshes.
Definition: MeshElement.h:44
const TriangleType & getTriangle(size_t id) const
Retrieve a specific triangle.
Definition: TriangleMeshBase-inl.h:152
MeshElement< 2, EdgeData > EdgeType
Edge type for convenience (Ids of the 2 vertices)
Definition: TriangleMeshBase.h:62
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:50
const std::vector< EdgeType > & getEdges() const
Retrieve all edges.
Definition: TriangleMeshBase-inl.h:110