walberla::geometry::TriangleMesh Class Reference

Detailed Description

Class for storing a triangle mesh.

Format:

  • vertices are stored in an array
  • triangles are stored as an index triple into the vertex array, three consecutive entries in the indices_ array define a triangle

When adding new vertices no check is done if this vertex already exist. To remove duplicate vertices (and adapt the indices that store the triangles) use removeDuplicateVertices()

#include <TriangleMesh.h>

Public Types

typedef uint32_t index_t
 
typedef Vector3< real_tvertex_t
 
typedef Vector3< real_tnormal_t
 
typedef Vector3< float > color_t
 

Public Member Functions

Size Information
size_t getNumTriangles () const
 
size_t getNumVertexIndices () const
 
size_t getNumNormalIndices () const
 
index_t getNumVertices () const
 
index_t getNumNormals () const
 
math::AABB getAABB () const
 
Data Access
const vertex_tgetVertex (index_t i) const
 
const normal_tgetVertexNormal (index_t i) const
 
const color_tgetVertexColor (index_t i) const
 
void clear ()
 
index_t getVertexIndex (index_t i) const
 
index_t getVertexIndex (size_t triangle, uint8_t index) const
 
index_t getNormalIndex (index_t i) const
 
index_t getNormalIndex (size_t triangle, uint8_t index) const
 
bool hasVertexNormals () const
 
bool hasVertexColors () const
 
bool hasNormalIndices () const
 
void getTriangle (size_t triangleIdx, vertex_t &v0, vertex_t &v1, vertex_t &v2) const
 
void getTriangle (size_t triangleIdx, vertex_t &v0, vertex_t &v1, vertex_t &v2, color_t &c0, color_t &c1, color_t &c2) const
 
void getTriangleVertexNormals (size_t triangleIdx, normal_t &n0, normal_t &n1, normal_t &n2) const
 
const std::vector< index_t > & getVertexIndices () const
 
const std::vector< index_t > & getNormalIndices () const
 
const std::vector< vertex_t > & getVertices () const
 
const std::vector< normal_t > & getVertexNormals () const
 
const std::vector< color_t > & getVertexColors () const
 
std::vector< index_t > & getVertexIndices ()
 
std::vector< index_t > & getNormalIndices ()
 
std::vector< vertex_t > & getVertices ()
 
std::vector< normal_t > & getVertexNormals ()
 
std::vector< color_t > & getVertexColors ()
 
template<typename OutputIterator >
void getVerticesOfColor (const color_t &color, OutputIterator outIt) const
 
real_t volume () const
 
real_t surfaceArea () const
 
Inserting
index_t addVertex (const vertex_t &v)
 Adds a vertex to the mesh and returns its index No duplicate check is done when inserting, instead use removeDuplicateVertices. More...
 
index_t addVertex (const vertex_t &v, const color_t &c)
 
index_t addVertexNormal (const normal_t &n)
 
void addTriangle (index_t v0Idx, index_t v1Idx, index_t v2Idx)
 Adds a triangle to the mesh, as parameters use the return values of addVertex() More...
 
void addTriangle (index_t v0Idx, index_t v1Idx, index_t v2Idx, index_t n0Idx, index_t n1Idx, index_t n2Idx)
 
Mesh Operations
void merge (const TriangleMesh &other, const Vector3< real_t > &offset=Vector3< real_t >(0.0))
 Merges a second mesh into the given mesh. More...
 
size_t removeDuplicateVertices (real_t tolerance=real_t(1e-4))
 Removes duplicate vertices i.e. More...
 
void translate (const Vector3< real_t > &offset)
 
void scale (real_t scaleFactor)
 
void scale (const Vector3< real_t > &scaleFactors)
 
void split (std::vector< TriangleMesh > &meshes) const
 Split mesh into unconnected meshes. More...
 
void exchangeAxes (uint_t xAxisId, uint_t yAxisId, uint_t zAxisId)
 

Static Public Member Functions

template<typename T >
static index_t index_c (T x)
 

Protected Attributes

std::vector< index_tvertexIndices_
 
std::vector< index_tnormalIndices_
 
std::vector< vertex_tvertices_
 
std::vector< normal_tvertexNormals_
 
std::vector< color_tvertexColors_
 

Member Typedef Documentation

Member Function Documentation

void walberla::geometry::TriangleMesh::addTriangle ( index_t  v0Idx,
index_t  v1Idx,
index_t  v2Idx 
)

Adds a triangle to the mesh, as parameters use the return values of addVertex()

void walberla::geometry::TriangleMesh::addTriangle ( index_t  v0Idx,
index_t  v1Idx,
index_t  v2Idx,
index_t  n0Idx,
index_t  n1Idx,
index_t  n2Idx 
)
TriangleMesh::index_t walberla::geometry::TriangleMesh::addVertex ( const vertex_t v)

Adds a vertex to the mesh and returns its index No duplicate check is done when inserting, instead use removeDuplicateVertices.

TriangleMesh::index_t walberla::geometry::TriangleMesh::addVertex ( const vertex_t v,
const color_t c 
)
TriangleMesh::index_t walberla::geometry::TriangleMesh::addVertexNormal ( const normal_t n)
void walberla::geometry::TriangleMesh::clear ( )
inline
void walberla::geometry::TriangleMesh::exchangeAxes ( uint_t  xAxisId,
uint_t  yAxisId,
uint_t  zAxisId 
)
math::AABB walberla::geometry::TriangleMesh::getAABB ( ) const
TriangleMesh::index_t walberla::geometry::TriangleMesh::getNormalIndex ( index_t  i) const
inline
TriangleMesh::index_t walberla::geometry::TriangleMesh::getNormalIndex ( size_t  triangle,
uint8_t  index 
) const
inline
const std::vector<index_t>& walberla::geometry::TriangleMesh::getNormalIndices ( ) const
inline
std::vector<index_t>& walberla::geometry::TriangleMesh::getNormalIndices ( )
inline
size_t walberla::geometry::TriangleMesh::getNumNormalIndices ( ) const
inline
index_t walberla::geometry::TriangleMesh::getNumNormals ( ) const
inline
size_t walberla::geometry::TriangleMesh::getNumTriangles ( ) const
inline
size_t walberla::geometry::TriangleMesh::getNumVertexIndices ( ) const
inline
index_t walberla::geometry::TriangleMesh::getNumVertices ( ) const
inline
void walberla::geometry::TriangleMesh::getTriangle ( size_t  triangleIdx,
vertex_t v0,
vertex_t v1,
vertex_t v2 
) const
inline
void walberla::geometry::TriangleMesh::getTriangle ( size_t  triangleIdx,
vertex_t v0,
vertex_t v1,
vertex_t v2,
color_t c0,
color_t c1,
color_t c2 
) const
inline
void walberla::geometry::TriangleMesh::getTriangleVertexNormals ( size_t  triangleIdx,
normal_t n0,
normal_t n1,
normal_t n2 
) const
inline
const vertex_t& walberla::geometry::TriangleMesh::getVertex ( index_t  i) const
inline
const color_t& walberla::geometry::TriangleMesh::getVertexColor ( index_t  i) const
inline
const std::vector<color_t>& walberla::geometry::TriangleMesh::getVertexColors ( ) const
inline
std::vector<color_t>& walberla::geometry::TriangleMesh::getVertexColors ( )
inline
TriangleMesh::index_t walberla::geometry::TriangleMesh::getVertexIndex ( index_t  i) const
inline
TriangleMesh::index_t walberla::geometry::TriangleMesh::getVertexIndex ( size_t  triangle,
uint8_t  index 
) const
inline
const std::vector<index_t>& walberla::geometry::TriangleMesh::getVertexIndices ( ) const
inline
std::vector<index_t>& walberla::geometry::TriangleMesh::getVertexIndices ( )
inline
const normal_t& walberla::geometry::TriangleMesh::getVertexNormal ( index_t  i) const
inline
const std::vector<normal_t>& walberla::geometry::TriangleMesh::getVertexNormals ( ) const
inline
std::vector<normal_t>& walberla::geometry::TriangleMesh::getVertexNormals ( )
inline
const std::vector<vertex_t>& walberla::geometry::TriangleMesh::getVertices ( ) const
inline
std::vector<vertex_t>& walberla::geometry::TriangleMesh::getVertices ( )
inline
template<typename OutputIterator >
void walberla::geometry::TriangleMesh::getVerticesOfColor ( const color_t color,
OutputIterator  outIt 
) const
bool walberla::geometry::TriangleMesh::hasNormalIndices ( ) const
inline
bool walberla::geometry::TriangleMesh::hasVertexColors ( ) const
inline
bool walberla::geometry::TriangleMesh::hasVertexNormals ( ) const
inline
template<typename T >
static index_t walberla::geometry::TriangleMesh::index_c ( x)
inlinestatic
void walberla::geometry::TriangleMesh::merge ( const TriangleMesh other,
const Vector3< real_t > &  offset = Vector3<real_t>(0.0) 
)

Merges a second mesh into the given mesh.

All vertices and faces of the second mesh are added, no vertex duplicate checking is done.

Parameters
othermesh that has to merge into this
offsetbefore adding the vertices, they are moved by the given offset
size_t walberla::geometry::TriangleMesh::removeDuplicateVertices ( real_t  tolerance = real_t(1e-4))

Removes duplicate vertices i.e.

vertices with same positions

This is expensive, since the vertex array has to be sorted, scanned for duplicates, and the face indices array has to be rewritten.

Warning
This function changes vertex indices! Consider this when adding triangles.
Parameters
tolerancetwo vertices are considered equal if each of their coordinates does not differ more than the tolerance value (maximum-norm)
Returns
The number of removed vertices
void walberla::geometry::TriangleMesh::scale ( real_t  scaleFactor)
inline
void walberla::geometry::TriangleMesh::scale ( const Vector3< real_t > &  scaleFactors)
void walberla::geometry::TriangleMesh::split ( std::vector< TriangleMesh > &  meshes) const

Split mesh into unconnected meshes.

All triangle connections are checked. Unconnected meshes are split up.

Parameters
meshesempty vector where all unconnected meshes are returned
real_t walberla::geometry::TriangleMesh::surfaceArea ( ) const
void walberla::geometry::TriangleMesh::translate ( const Vector3< real_t > &  offset)
real_t walberla::geometry::TriangleMesh::volume ( ) const

Member Data Documentation

std::vector<index_t> walberla::geometry::TriangleMesh::normalIndices_
protected
std::vector<color_t> walberla::geometry::TriangleMesh::vertexColors_
protected
std::vector<index_t> walberla::geometry::TriangleMesh::vertexIndices_
protected
std::vector<normal_t> walberla::geometry::TriangleMesh::vertexNormals_
protected
std::vector<vertex_t> walberla::geometry::TriangleMesh::vertices_
protected

The documentation for this class was generated from the following files: