TriangleMesh.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DATASTRUCTURES_TRIANGLEMESH_H
#define SURGSIM_DATASTRUCTURES_TRIANGLEMESH_H
#include <array>
#include <memory>
#include "SurgSim/DataStructures/EmptyData.h"
#include "SurgSim/DataStructures/MeshElement.h"
#include "SurgSim/DataStructures/NormalData.h"
#include "SurgSim/DataStructures/TriangleMeshPlyReaderDelegate.h"
#include "SurgSim/DataStructures/Vertices.h"
#include "SurgSim/Framework/Asset.h"
namespace SurgSim
{
namespace DataStructures
{
template <class VertexData, class EdgeData, class TriangleData>
class TriangleMesh : public Vertices<VertexData>, public SurgSim::Framework::Asset,
public std::enable_shared_from_this<TriangleMesh<VertexData, EdgeData, TriangleData>>
{
public:
typedef MeshElement<2, EdgeData> EdgeType;
typedef MeshElement<3, TriangleData> TriangleType;
TriangleMesh();
TriangleMesh(const TriangleMesh<VertexData, EdgeData, TriangleData>& other);
template <class V, class E, class T>
explicit TriangleMesh(const TriangleMesh<V, E, T>& other);
virtual ~TriangleMesh();
TriangleMesh(TriangleMesh&& other);
TriangleMesh<VertexData, EdgeData, TriangleData>& operator=(
const TriangleMesh<VertexData, EdgeData, TriangleData>& other);
TriangleMesh<VertexData, EdgeData, TriangleData>& operator=(
TriangleMesh<VertexData, EdgeData, TriangleData>&& other);
std::string getClassName() const override;
size_t addEdge(const EdgeType& edge);
size_t addTriangle(const TriangleType& triangle);
size_t getNumEdges() const;
size_t getNumTriangles() const;
const std::vector<EdgeType>& getEdges() const;
std::vector<EdgeType>& getEdges();
const std::vector<TriangleType>& getTriangles() const;
std::vector<TriangleType>& getTriangles();
const EdgeType& getEdge(size_t id) const;
EdgeType& getEdge(size_t id);
std::array<SurgSim::Math::Vector3d, 2> getEdgePositions(size_t id) const;
const TriangleType& getTriangle(size_t id) const;
TriangleType& getTriangle(size_t id);
void removeTriangle(size_t id);
std::array<SurgSim::Math::Vector3d, 3> getTrianglePositions(size_t id) const;
bool isValid() const;
void save(const std::string& fileName);
protected:
virtual void doClearEdges();
virtual void doClearTriangles();
virtual bool isEqual(const Vertices<VertexData>& mesh) const;
bool doLoad(const std::string& fileName) override;
using Vertices<VertexData>::doClearVertices;
static std::string m_className;
private:
virtual void doClear();
std::vector<EdgeType> m_edges;
std::vector<TriangleType> m_triangles;
std::vector<size_t> m_freeTriangles;
public:
// Dependent name resolution for inherited functions and typenames from templates
using typename Vertices<VertexData>::VertexType;
using Vertices<VertexData>::addVertex;
using Vertices<VertexData>::getNumVertices;
using Vertices<VertexData>::getVertices;
};
typedef TriangleMesh<EmptyData, EmptyData, EmptyData> TriangleMeshPlain;
}; // namespace DataStructures
}; // namespace SurgSim
#include "SurgSim/DataStructures/TriangleMesh-inl.h"
#endif // SURGSIM_DATASTRUCTURES_TRIANGLEMESH_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
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Asset
This class is used to facilitate file loading.
Definition: Asset.h:39
Vertices.h
SurgSim::DataStructures::TriangleMesh::getTriangle
const TriangleType & getTriangle(size_t id) const
Retrieve a specific triangle.
Definition: TriangleMesh-inl.h:179
SurgSim::DataStructures::TriangleMesh::addTriangle
size_t addTriangle(const TriangleType &triangle)
Adds a triangle to the mesh.
Definition: TriangleMesh-inl.h:88
SurgSim::DataStructures::TriangleMesh::getEdgePositions
std::array< SurgSim::Math::Vector3d, 2 > getEdgePositions(size_t id) const
Returns an array of the edge&#39;s vertices&#39; positions.
Definition: TriangleMesh-inl.h:165
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
MeshElement.h
SurgSim::DataStructures::TriangleMesh::doClearTriangles
virtual void doClearTriangles()
Remove all triangles from the mesh.
Definition: TriangleMesh-inl.h:265
SurgSim::DataStructures::Vertex
Vertex structure for meshes.
Definition: Vertex.h:44
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::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::getTriangles
const std::vector< TriangleType > & getTriangles() const
Retrieve all triangles.
Definition: TriangleMesh-inl.h:137
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::doClearEdges
virtual void doClearEdges()
Remove all edges from the mesh.
Definition: TriangleMesh-inl.h:259
SurgSim::DataStructures::TriangleMesh::getTrianglePositions
std::array< SurgSim::Math::Vector3d, 3 > getTrianglePositions(size_t id) const
Returns an array of the triangle&#39;s vertices&#39; positions.
Definition: TriangleMesh-inl.h:209
TriangleMesh-inl.h
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::TriangleMesh
TriangleMesh()
Constructor. The mesh is initially empty (no vertices, no edges, no triangles).
Definition: TriangleMesh-inl.h:28
SurgSim::DataStructures::TriangleMesh::TriangleType
MeshElement< 3, TriangleData > TriangleType
Triangle type for convenience (Ids of the 3 vertices)
Definition: TriangleMesh.h:69
SurgSim::DataStructures::TriangleMesh::~TriangleMesh
virtual ~TriangleMesh()
Destructor.
Definition: TriangleMesh-inl.h:69
SurgSim::DataStructures::TriangleMesh::getEdge
const EdgeType & getEdge(size_t id) const
Retrieve a specific edge.
Definition: TriangleMesh-inl.h:151
NormalData.h
SurgSim::DataStructures::TriangleMesh::operator=
TriangleMesh< VertexData, EdgeData, TriangleData > & operator=(const TriangleMesh< VertexData, EdgeData, TriangleData > &other)
Copy Assignment.
Definition: TriangleMesh-inl.h:322
SurgSim::DataStructures::TriangleMesh::EdgeType
MeshElement< 2, EdgeData > EdgeType
Edge type for convenience (Ids of the 2 vertices)
Definition: TriangleMesh.h:67
SurgSim::DataStructures::TriangleMesh::m_edges
std::vector< EdgeType > m_edges
Edges.
Definition: TriangleMesh.h:232
SurgSim::DataStructures::TriangleMesh::addEdge
size_t addEdge(const EdgeType &edge)
Adds an edge to the mesh.
Definition: TriangleMesh-inl.h:81
SurgSim::DataStructures::TriangleMesh
Basic class for storing Triangle Meshes, handling basic vertex, edge, and triangle functionality...
Definition: TriangleMesh.h:62
TriangleMeshPlyReaderDelegate.h
SurgSim::DataStructures::MeshElement
Element structure for meshes.
Definition: MeshElement.h:44
SurgSim::DataStructures::TriangleMesh::m_className
static std::string m_className
Definition: TriangleMesh.h:224
SurgSim::DataStructures::TriangleMesh::getEdges
const std::vector< EdgeType > & getEdges() const
Retrieve all edges.
Definition: TriangleMesh-inl.h:123
SurgSim::DataStructures::TriangleMesh::getNumTriangles
size_t getNumTriangles() const
Get the number of triangles.
Definition: TriangleMesh-inl.h:116
SurgSim::DataStructures::Vertices
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
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::TriangleMeshPlain
TriangleMesh< EmptyData, EmptyData, EmptyData > TriangleMeshPlain
Definition: TriangleMesh.h:249
SurgSim::DataStructures::TriangleMesh::getClassName
std::string getClassName() const override
Support serialization with a classname.
Definition: TriangleMesh-inl.h:74
EmptyData.h
SurgSim::DataStructures::TriangleMesh::getNumEdges
size_t getNumEdges() const
Get the number of edges.
Definition: TriangleMesh-inl.h:110