TriangleMesh.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_TRIANGLEMESH_H
17 #define SURGSIM_DATASTRUCTURES_TRIANGLEMESH_H
18 
19 #include <array>
20 #include <memory>
21 
28 
29 namespace SurgSim
30 {
31 namespace DataStructures
32 {
33 
61 template <class VertexData, class EdgeData, class TriangleData>
62 class TriangleMesh : public Vertices<VertexData>, public SurgSim::Framework::Asset,
63  public std::enable_shared_from_this<TriangleMesh<VertexData, EdgeData, TriangleData>>
64 {
65 public:
70 
72  TriangleMesh();
73 
77 
84  template <class V, class E, class T>
85  explicit TriangleMesh(const TriangleMesh<V, E, T>& other);
86 
88  virtual ~TriangleMesh();
89 
92  TriangleMesh(TriangleMesh&& other);
93 
98 
103 
104 
105  std::string getClassName() const override;
106 
114  size_t addEdge(const EdgeType& edge);
115 
123  size_t addTriangle(const TriangleType& triangle);
124 
127  size_t getNumEdges() const;
128 
133  size_t getNumTriangles() const;
134 
137  const std::vector<EdgeType>& getEdges() const;
138 
141  std::vector<EdgeType>& getEdges();
142 
149  const std::vector<TriangleType>& getTriangles() const;
150 
157  std::vector<TriangleType>& getTriangles();
158 
162  const EdgeType& getEdge(size_t id) const;
163 
167  EdgeType& getEdge(size_t id);
168 
172  std::array<SurgSim::Math::Vector3d, 2> getEdgePositions(size_t id) const;
173 
178  const TriangleType& getTriangle(size_t id) const;
179 
184  TriangleType& getTriangle(size_t id);
185 
191  void removeTriangle(size_t id);
192 
196  std::array<SurgSim::Math::Vector3d, 3> getTrianglePositions(size_t id) const;
197 
200  bool isValid() const;
201 
204  void save(const std::string& fileName);
205 
206 protected:
208  virtual void doClearEdges();
209 
211  virtual void doClearTriangles();
212 
218  virtual bool isEqual(const Vertices<VertexData>& mesh) const;
219 
220  bool doLoad(const std::string& fileName) override;
221 
223 
225 
226 private:
227 
229  virtual void doClear();
230 
232  std::vector<EdgeType> m_edges;
233 
235  std::vector<TriangleType> m_triangles;
236 
238  std::vector<size_t> m_freeTriangles;
239 
240 public:
241  // Dependent name resolution for inherited functions and typenames from templates
242  using typename Vertices<VertexData>::VertexType;
246 
247 };
248 
250 
251 }; // namespace DataStructures
252 }; // namespace SurgSim
253 
255 
256 #endif // SURGSIM_DATASTRUCTURES_TRIANGLEMESH_H
SurgSim::DataStructures::TriangleMesh::operator=
TriangleMesh< VertexData, EdgeData, TriangleData > & operator=(const TriangleMesh< VertexData, EdgeData, TriangleData > &other)
Copy Assignment.
Definition: TriangleMesh-inl.h:322
MeshElement.h
NormalData.h
SurgSim::DataStructures::TriangleMesh
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality.
Definition: TriangleMesh.h:62
TriangleMesh-inl.h
SurgSim::DataStructures::TriangleMesh::m_className
static std::string m_className
Definition: TriangleMesh.h:224
SurgSim::DataStructures::TriangleMesh::doLoad
bool doLoad(const std::string &fileName) override
Derived classes will overwrite this method to do actual loading.
Definition: TriangleMesh-inl.h:280
SurgSim::DataStructures::TriangleMesh::getNumTriangles
size_t getNumTriangles() const
Get the number of triangles.
Definition: TriangleMesh-inl.h:116
SurgSim::DataStructures::TriangleMesh::isValid
bool isValid() const
Test if the TriangleMesh is valid (valid vertex Ids used in all MeshElements)
Definition: TriangleMesh-inl.h:223
SurgSim::DataStructures::TriangleMesh::getNumEdges
size_t getNumEdges() const
Get the number of edges.
Definition: TriangleMesh-inl.h:110
SurgSim::DataStructures::Vertices
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
Vertices.h
SurgSim::DataStructures::TriangleMesh::getEdges
const std::vector< EdgeType > & getEdges() const
Retrieve all edges.
Definition: TriangleMesh-inl.h:123
SurgSim::DataStructures::TriangleMesh::m_triangles
std::vector< TriangleType > m_triangles
Triangles.
Definition: TriangleMesh.h:235
SurgSim::DataStructures::TriangleMesh::removeTriangle
void removeTriangle(size_t id)
Marks a triangle as invalid, the triangle cannot be accessed via getTriangle anymore.
Definition: TriangleMesh-inl.h:197
Asset.h
SurgSim::DataStructures::MeshElement
Element structure for meshes.
Definition: MeshElement.h:44
SurgSim::DataStructures::TriangleMesh::getTrianglePositions
std::array< SurgSim::Math::Vector3d, 3 > getTrianglePositions(size_t id) const
Returns an array of the triangle's vertices' positions.
Definition: TriangleMesh-inl.h:209
EmptyData.h
SurgSim::DataStructures::TriangleMesh::addTriangle
size_t addTriangle(const TriangleType &triangle)
Adds a triangle to the mesh.
Definition: TriangleMesh-inl.h:88
SurgSim::DataStructures::TriangleMesh::doClearEdges
virtual void doClearEdges()
Remove all edges from the mesh.
Definition: TriangleMesh-inl.h:259
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::Vertex
Vertex structure for meshes.
Definition: Vertex.h:44
SurgSim::DataStructures::TriangleMesh::~TriangleMesh
virtual ~TriangleMesh()
Destructor.
Definition: TriangleMesh-inl.h:69
SurgSim::DataStructures::TriangleMesh::TriangleType
MeshElement< 3, TriangleData > TriangleType
Triangle type for convenience (Ids of the 3 vertices)
Definition: TriangleMesh.h:69
SurgSim::DataStructures::TriangleMesh::save
void save(const std::string &fileName)
Save the triangle mesh in the ply format.
Definition: TriangleMesh-inl.h:346
SurgSim::DataStructures::TriangleMesh::getEdge
const EdgeType & getEdge(size_t id) const
Retrieve a specific edge.
Definition: TriangleMesh-inl.h:151
SurgSim::DataStructures::TriangleMesh::doClearTriangles
virtual void doClearTriangles()
Remove all triangles from the mesh.
Definition: TriangleMesh-inl.h:265
SurgSim::DataStructures::TriangleMesh::m_edges
std::vector< EdgeType > m_edges
Edges.
Definition: TriangleMesh.h:232
SurgSim::DataStructures::TriangleMesh::m_freeTriangles
std::vector< size_t > m_freeTriangles
List of indices of deleted triangles, to be reused when another triangle is added.
Definition: TriangleMesh.h:238
SurgSim::DataStructures::TriangleMesh::isEqual
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: TriangleMesh-inl.h:272
SurgSim::DataStructures::TriangleMesh::getClassName
std::string getClassName() const override
Support serialization with a classname.
Definition: TriangleMesh-inl.h:74
TriangleMeshPlyReaderDelegate.h
SurgSim::DataStructures::TriangleMesh::doClear
virtual void doClear()
Clear mesh to return to an empty state (no vertices, no edges, no triangles).
Definition: TriangleMesh-inl.h:303
SurgSim::DataStructures::TriangleMesh::getTriangles
const std::vector< TriangleType > & getTriangles() const
Retrieve all triangles.
Definition: TriangleMesh-inl.h:137
SurgSim::DataStructures::TriangleMesh::TriangleMesh
TriangleMesh()
Constructor. The mesh is initially empty (no vertices, no edges, no triangles).
Definition: TriangleMesh-inl.h:28
SurgSim::DataStructures::TriangleMesh::EdgeType
MeshElement< 2, EdgeData > EdgeType
Edge type for convenience (Ids of the 2 vertices)
Definition: TriangleMesh.h:67
SurgSim::Framework::Asset
This class is used to facilitate file loading.
Definition: Asset.h:39
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::DataStructures::TriangleMesh::getTriangle
const TriangleType & getTriangle(size_t id) const
Retrieve a specific triangle.
Definition: TriangleMesh-inl.h:179
SurgSim::DataStructures::TriangleMesh::getEdgePositions
std::array< SurgSim::Math::Vector3d, 2 > getEdgePositions(size_t id) const
Returns an array of the edge's vertices' positions.
Definition: TriangleMesh-inl.h:165
SurgSim::DataStructures::TriangleMeshPlain
TriangleMesh< EmptyData, EmptyData, EmptyData > TriangleMeshPlain
Definition: TriangleMesh.h:249
SurgSim::DataStructures::TriangleMesh::addEdge
size_t addEdge(const EdgeType &edge)
Adds an edge to the mesh.
Definition: TriangleMesh-inl.h:81