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

using index_t = uint32_t
 
using vertex_t = Vector3< real_t >
 
using normal_t = Vector3< real_t >
 
using color_t = Vector3< float >
 

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)
 

Static Public Member Functions

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

Mesh Operations

std::vector< index_tvertexIndices_
 
std::vector< index_tnormalIndices_
 
std::vector< vertex_tvertices_
 
std::vector< normal_tvertexNormals_
 
std::vector< color_tvertexColors_
 
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)
 

Member Typedef Documentation

◆ color_t

◆ index_t

◆ normal_t

◆ vertex_t

Member Function Documentation

◆ addTriangle() [1/2]

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()

◆ addTriangle() [2/2]

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

◆ addVertex() [1/2]

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.

◆ addVertex() [2/2]

TriangleMesh::index_t walberla::geometry::TriangleMesh::addVertex ( const vertex_t v,
const color_t c 
)

◆ addVertexNormal()

TriangleMesh::index_t walberla::geometry::TriangleMesh::addVertexNormal ( const normal_t n)

◆ clear()

void walberla::geometry::TriangleMesh::clear ( )
inline

◆ exchangeAxes()

void walberla::geometry::TriangleMesh::exchangeAxes ( uint_t  xAxisId,
uint_t  yAxisId,
uint_t  zAxisId 
)

◆ getAABB()

math::AABB walberla::geometry::TriangleMesh::getAABB ( ) const

◆ getNormalIndex() [1/2]

TriangleMesh::index_t walberla::geometry::TriangleMesh::getNormalIndex ( index_t  i) const
inline

◆ getNormalIndex() [2/2]

TriangleMesh::index_t walberla::geometry::TriangleMesh::getNormalIndex ( size_t  triangle,
uint8_t  index 
) const
inline

◆ getNormalIndices() [1/2]

std::vector<index_t>& walberla::geometry::TriangleMesh::getNormalIndices ( )
inline

◆ getNormalIndices() [2/2]

const std::vector<index_t>& walberla::geometry::TriangleMesh::getNormalIndices ( ) const
inline

◆ getNumNormalIndices()

size_t walberla::geometry::TriangleMesh::getNumNormalIndices ( ) const
inline

◆ getNumNormals()

index_t walberla::geometry::TriangleMesh::getNumNormals ( ) const
inline

◆ getNumTriangles()

size_t walberla::geometry::TriangleMesh::getNumTriangles ( ) const
inline

◆ getNumVertexIndices()

size_t walberla::geometry::TriangleMesh::getNumVertexIndices ( ) const
inline

◆ getNumVertices()

index_t walberla::geometry::TriangleMesh::getNumVertices ( ) const
inline

◆ getTriangle() [1/2]

void walberla::geometry::TriangleMesh::getTriangle ( size_t  triangleIdx,
vertex_t v0,
vertex_t v1,
vertex_t v2 
) const
inline

◆ getTriangle() [2/2]

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

◆ getTriangleVertexNormals()

void walberla::geometry::TriangleMesh::getTriangleVertexNormals ( size_t  triangleIdx,
normal_t n0,
normal_t n1,
normal_t n2 
) const
inline

◆ getVertex()

const vertex_t& walberla::geometry::TriangleMesh::getVertex ( index_t  i) const
inline

◆ getVertexColor()

const color_t& walberla::geometry::TriangleMesh::getVertexColor ( index_t  i) const
inline

◆ getVertexColors() [1/2]

std::vector<color_t>& walberla::geometry::TriangleMesh::getVertexColors ( )
inline

◆ getVertexColors() [2/2]

const std::vector<color_t>& walberla::geometry::TriangleMesh::getVertexColors ( ) const
inline

◆ getVertexIndex() [1/2]

TriangleMesh::index_t walberla::geometry::TriangleMesh::getVertexIndex ( index_t  i) const
inline

◆ getVertexIndex() [2/2]

TriangleMesh::index_t walberla::geometry::TriangleMesh::getVertexIndex ( size_t  triangle,
uint8_t  index 
) const
inline

◆ getVertexIndices() [1/2]

std::vector<index_t>& walberla::geometry::TriangleMesh::getVertexIndices ( )
inline

◆ getVertexIndices() [2/2]

const std::vector<index_t>& walberla::geometry::TriangleMesh::getVertexIndices ( ) const
inline

◆ getVertexNormal()

const normal_t& walberla::geometry::TriangleMesh::getVertexNormal ( index_t  i) const
inline

◆ getVertexNormals() [1/2]

std::vector<normal_t>& walberla::geometry::TriangleMesh::getVertexNormals ( )
inline

◆ getVertexNormals() [2/2]

const std::vector<normal_t>& walberla::geometry::TriangleMesh::getVertexNormals ( ) const
inline

◆ getVertices() [1/2]

std::vector<vertex_t>& walberla::geometry::TriangleMesh::getVertices ( )
inline

◆ getVertices() [2/2]

const std::vector<vertex_t>& walberla::geometry::TriangleMesh::getVertices ( ) const
inline

◆ getVerticesOfColor()

template<typename OutputIterator >
void walberla::geometry::TriangleMesh::getVerticesOfColor ( const color_t color,
OutputIterator  outIt 
) const

◆ hasNormalIndices()

bool walberla::geometry::TriangleMesh::hasNormalIndices ( ) const
inline

◆ hasVertexColors()

bool walberla::geometry::TriangleMesh::hasVertexColors ( ) const
inline

◆ hasVertexNormals()

bool walberla::geometry::TriangleMesh::hasVertexNormals ( ) const
inline

◆ index_c()

template<typename T >
static index_t walberla::geometry::TriangleMesh::index_c ( x)
inlinestatic

◆ merge()

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

◆ removeDuplicateVertices()

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

◆ scale() [1/2]

void walberla::geometry::TriangleMesh::scale ( const Vector3< real_t > &  scaleFactors)

◆ scale() [2/2]

void walberla::geometry::TriangleMesh::scale ( real_t  scaleFactor)
inline

◆ split()

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

◆ surfaceArea()

real_t walberla::geometry::TriangleMesh::surfaceArea ( ) const

◆ translate()

void walberla::geometry::TriangleMesh::translate ( const Vector3< real_t > &  offset)

◆ volume()

real_t walberla::geometry::TriangleMesh::volume ( ) const

Member Data Documentation

◆ normalIndices_

std::vector<index_t> walberla::geometry::TriangleMesh::normalIndices_
protected

◆ vertexColors_

std::vector<color_t> walberla::geometry::TriangleMesh::vertexColors_
protected

◆ vertexIndices_

std::vector<index_t> walberla::geometry::TriangleMesh::vertexIndices_
protected

◆ vertexNormals_

std::vector<normal_t> walberla::geometry::TriangleMesh::vertexNormals_
protected

◆ vertices_

std::vector<vertex_t> walberla::geometry::TriangleMesh::vertices_
protected

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