TetrahedronMesh-inl.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_TETRAHEDRONMESH_INL_H
#define SURGSIM_DATASTRUCTURES_TETRAHEDRONMESH_INL_H
namespace SurgSim
{
namespace DataStructures
{
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
TetrahedronMesh()
{
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
~TetrahedronMesh()
{
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
addEdge(const EdgeType& edge)
{
m_edges.push_back(edge);
return m_edges.size() - 1;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
addTriangle(const TriangleType& triangle)
{
m_triangles.push_back(triangle);
return m_triangles.size() - 1;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
addTetrahedron(const TetrahedronType& tetrahedron)
{
m_tetrahedrons.push_back(tetrahedron);
return m_tetrahedrons.size() - 1;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getNumEdges() const
{
return m_edges.size();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getNumTriangles() const
{
return m_triangles.size();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
size_t
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getNumTetrahedrons() const
{
return m_tetrahedrons.size();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::EdgeType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getEdges() const
{
return m_edges;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::EdgeType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getEdges()
{
return m_edges;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TriangleType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTriangles() const
{
return m_triangles;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TriangleType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTriangles()
{
return m_triangles;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TetrahedronType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTetrahedrons() const
{
return m_tetrahedrons;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
std::vector<typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TetrahedronType>&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTetrahedrons()
{
return m_tetrahedrons;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::EdgeType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getEdge(size_t id) const
{
return m_edges[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::EdgeType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getEdge(size_t id)
{
return m_edges[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TriangleType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTriangle(size_t id) const
{
return m_triangles[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TriangleType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTriangle(size_t id)
{
return m_triangles[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
const typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TetrahedronType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTetrahedron(size_t id) const
{
return m_tetrahedrons[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TetrahedronType&
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
getTetrahedron(size_t id)
{
return m_tetrahedrons[id];
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
bool
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
isValid() const
{
typedef typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::EdgeType
EdgeType;
typedef typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TriangleType
TriangleType;
typedef typename TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::TetrahedronType
TetrahedronType;
size_t numVertices = Vertices<VertexData>::getNumVertices();
// Test edges validity
for (typename std::vector<EdgeType>::const_iterator it = m_edges.begin();
it != m_edges.end();
it++)
{
for (size_t vertexId = 0; vertexId < 2; vertexId++)
{
if (it->verticesId[vertexId] >= numVertices)
{
return false;
}
}
}
// Test triangles validity
for (typename std::vector<TriangleType>::const_iterator it = m_triangles.begin();
it != m_triangles.end();
it++)
{
for (size_t vertexId = 0; vertexId < 3; vertexId++)
{
if (it->verticesId[vertexId] >= numVertices)
{
return false;
}
}
}
// Test tetrahedrons validity
for (typename std::vector<TetrahedronType>::const_iterator it = m_tetrahedrons.begin();
it != m_tetrahedrons.end();
it++)
{
for (size_t vertexId = 0; vertexId < 4; vertexId++)
{
if (it->verticesId[vertexId] >= numVertices)
{
return false;
}
}
}
return true;
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
void
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
doClearEdges()
{
m_edges.clear();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
void
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
doClearTriangles()
{
m_triangles.clear();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
void
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
doClearTetrahedrons()
{
m_tetrahedrons.clear();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
bool
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
isEqual(const Vertices<VertexData>& mesh) const
{
const TetrahedronMesh& tetrahedronMesh = static_cast<const TetrahedronMesh&>(mesh);
return Vertices<VertexData>::isEqual(mesh) && m_edges == tetrahedronMesh.getEdges() &&
m_triangles == tetrahedronMesh.getTriangles() && m_tetrahedrons == tetrahedronMesh.getTetrahedrons();
}
template <class VertexData, class EdgeData, class TriangleData, class TetrahedronData>
void
TetrahedronMesh<VertexData, EdgeData, TriangleData, TetrahedronData>::
doClear()
{
doClearTetrahedrons();
doClearTriangles();
doClearEdges();
Vertices<VertexData>::doClearVertices();
}
}; // namespace DataStructures
}; // namespace SurgSim
#endif // SURGSIM_DATASTRUCTURES_TETRAHEDRONMESH_INL_H
SurgSim::DataStructures::TetrahedronMesh::getEdges
const std::vector< EdgeType > & getEdges() const
Returns a vector containing the position of each edge.
Definition: TetrahedronMesh-inl.h:91
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::Vertices::getNumVertices
size_t getNumVertices() const
Returns the number of vertices in this mesh.
Definition: Vertices-inl.h:99
SurgSim::DataStructures::TetrahedronMesh
Basic class for storing Tetrahedron Meshes, handling basic vertex, edge, triangle and tetrahedron fun...
Definition: TetrahedronMesh.h:60
SurgSim::DataStructures::TetrahedronMesh::isValid
bool isValid() const
Test if the TetrahedronMesh is valid (valid vertex Ids used in all MeshElements)
Definition: TetrahedronMesh-inl.h:187
SurgSim::DataStructures::TetrahedronMesh::doClearEdges
virtual void doClearEdges()
Remove all edges from the mesh.
Definition: TetrahedronMesh-inl.h:246
SurgSim::DataStructures::TetrahedronMesh::getNumEdges
size_t getNumEdges() const
Returns the number of edges in this mesh.
Definition: TetrahedronMesh-inl.h:67
SurgSim::DataStructures::TetrahedronMesh::addTriangle
size_t addTriangle(const TriangleType &triangle)
Adds a triangle to the mesh.
Definition: TetrahedronMesh-inl.h:49
SurgSim::DataStructures::TetrahedronMesh::doClearTriangles
virtual void doClearTriangles()
Remove all triangles from the mesh.
Definition: TetrahedronMesh-inl.h:254
SurgSim::DataStructures::TetrahedronMesh::getNumTetrahedrons
size_t getNumTetrahedrons() const
Returns the number of tetrahedrons in this mesh.
Definition: TetrahedronMesh-inl.h:83
SurgSim::DataStructures::TetrahedronMesh::getTetrahedrons
const std::vector< TetrahedronType > & getTetrahedrons() const
Returns a vector containing the position of each tetrahedron.
Definition: TetrahedronMesh-inl.h:123
SurgSim::Testing::Cube::numVertices
int numVertices
Definition: TestCube.cpp:25
SurgSim::DataStructures::TetrahedronMesh::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: TetrahedronMesh-inl.h:270
SurgSim::DataStructures::TetrahedronMesh::doClear
virtual void doClear()
Clear mesh to return to an empty state (no vertices, no edges, no triangles, no m_tetrahedrons).
Definition: TetrahedronMesh-inl.h:280
SurgSim::DataStructures::TetrahedronMesh::addEdge
size_t addEdge(const EdgeType &edge)
Adds an edge to the mesh.
Definition: TetrahedronMesh-inl.h:40
SurgSim::DataStructures::TetrahedronMesh::doClearTetrahedrons
virtual void doClearTetrahedrons()
Remove all tetrahedrons from the mesh.
Definition: TetrahedronMesh-inl.h:262
SurgSim::DataStructures::TetrahedronMesh::addTetrahedron
size_t addTetrahedron(const TetrahedronType &tetrahedron)
Adds a tetrahedron to the mesh.
Definition: TetrahedronMesh-inl.h:58
SurgSim::DataStructures::TetrahedronMesh::~TetrahedronMesh
virtual ~TetrahedronMesh()
Destructor.
Definition: TetrahedronMesh-inl.h:33
SurgSim::DataStructures::TetrahedronMesh::TetrahedronMesh
TetrahedronMesh()
Constructor. The mesh is initially empty (no vertices, no edges, no triangles, no tetrahedrons)...
Definition: TetrahedronMesh-inl.h:27
SurgSim::DataStructures::MeshElement
Element structure for meshes.
Definition: MeshElement.h:44
SurgSim::DataStructures::TetrahedronMesh::getTetrahedron
const TetrahedronType & getTetrahedron(size_t id) const
Returns the specified tetrahedron.
Definition: TetrahedronMesh-inl.h:171
SurgSim::DataStructures::Vertices::isEqual
virtual bool isEqual(const Vertices &mesh) const
Internal comparison of meshes of the same type: returns true if equal, false if not equal...
Definition: Vertices-inl.h:184
SurgSim::DataStructures::TetrahedronMesh::getTriangle
const TriangleType & getTriangle(size_t id) const
Returns the specified triangle.
Definition: TetrahedronMesh-inl.h:155
SurgSim::DataStructures::Vertices::doClearVertices
virtual void doClearVertices()
Remove all vertices from the mesh.
Definition: Vertices-inl.h:178
SurgSim::DataStructures::TetrahedronMesh::getTriangles
const std::vector< TriangleType > & getTriangles() const
Returns a vector containing the position of each triangle.
Definition: TetrahedronMesh-inl.h:107
SurgSim::DataStructures::TetrahedronMesh::getEdge
const EdgeType & getEdge(size_t id) const
Returns the specified edge.
Definition: TetrahedronMesh-inl.h:139
SurgSim::DataStructures::Vertices
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51
SurgSim::DataStructures::TetrahedronMesh::getNumTriangles
size_t getNumTriangles() const
Returns the number of triangles in this mesh.
Definition: TetrahedronMesh-inl.h:75