DGtal  1.5.beta
DGtal::Mesh< TPoint > Class Template Reference

Aim: This class is defined to represent a surface mesh through a set of vertices and faces. By using the default constructor, the mesh does not store any color information (it can be changed by setting the default constructor parameter saveFaceColor to 'true'). More...

#include <DGtal/shapes/Mesh.h>

Data Structures

struct  CompPoints
 

Public Types

typedef TPoint Point
 
typedef DGtal::PointVector< TPoint::dimension, double > RealPoint
 
typedef std::vector< TPoint > VertexStorage
 
typedef VertexStorage::size_type Index
 
typedef std::vector< IndexMeshFace
 
typedef std::vector< MeshFaceFaceStorage
 
typedef std::vector< DGtal::ColorColorStorage
 
typedef VertexStorage::const_iterator ConstIterator
 
typedef VertexStorage::iterator Iterator
 
typedef std::size_t Size
 

Public Member Functions

 Mesh (bool saveFaceColor=false)
 
 Mesh (const DGtal::Color &aColor)
 
 Mesh (const std::vector< TPoint > &vertexSet)
 
 ~Mesh ()
 
 Mesh (const Mesh &other)
 
Meshoperator= (const Mesh &other)
 
std::string className () const
 
void addVertex (const TPoint &vertex)
 
void addTriangularFace (Index indexVertex1, Index indexVertex2, Index indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
 
void addQuadFace (Index indexVertex1, Index indexVertex2, Index indexVertex3, Index indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
 
void addFace (const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White)
 
void removeFaces (const std::vector< Index > &facesIndex)
 
const TPoint & getVertex (Index i) const
 
TPoint & getVertex (Index i)
 
const MeshFacegetFace (Index i) const
 
RealPoint getFaceBarycenter (Index i) const
 
MeshFacegetFace (Index i)
 
const ColorgetFaceColor (Index i) const
 
std::pair< TPoint, TPoint > getBoundingBox () const
 
void setFaceColor (Index i, const DGtal::Color &aColor)
 
bool isStoringFaceColors () const
 
ConstIterator vertexBegin () const
 
ConstIterator vertexEnd () const
 
Iterator vertexBegin ()
 
Iterator vertexEnd ()
 
FaceStorage::const_iterator faceBegin () const
 
FaceStorage::const_iterator faceEnd () const
 
FaceStorage::iterator faceBegin ()
 
FaceStorage::iterator faceEnd ()
 
Size nbFaces () const
 
Size nbVertex () const
 
void invertVertexFaceOrder ()
 
void clearFaces ()
 
void clearVertices ()
 
void removeIsolatedVertices ()
 
void rescale (const typename TPoint::Component aScale)
 
double subDivideTriangularFaces (const double minArea)
 
unsigned int quadToTriangularFaces ()
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Static Public Member Functions

static void createTubularMesh (Mesh< TPoint > &aMesh, const std::vector< TPoint > &aSkeleton, const double aRadius, const double angleStep=0.2, const DGtal::Color &aMeshColor=DGtal::Color::White)
 
static void createTubularMesh (Mesh< TPoint > &aMesh, const std::vector< TPoint > &aSkeleton, const std::vector< double > &aVectOfRadius, const double angleStep=0.2, const DGtal::Color &aMeshColor=DGtal::Color::White)
 
template<typename TValue >
static void createMeshFromHeightSequence (Mesh< TPoint > &aMesh, const std::vector< TValue > &anValueSequence, const unsigned int lengthSequence, double stepX, double stepY, double stepZ, const DGtal::Color &aMeshColor=DGtal::Color::White)
 

Private Attributes

FaceStorage myFaceList
 
VertexStorage myVertexList
 
ColorStorage myFaceColorList
 
bool mySaveFaceColor
 
DGtal::Color myDefaultColor
 

Detailed Description

template<typename TPoint>
class DGtal::Mesh< TPoint >

Aim: This class is defined to represent a surface mesh through a set of vertices and faces. By using the default constructor, the mesh does not store any color information (it can be changed by setting the default constructor parameter saveFaceColor to 'true').

Description of template class 'Mesh'

The mesh object stores explicitly each vertex and each face are represented with the list of point index.

Note
This class is a preliminary version of a mesh strucuture (the method to access neigborhing facets or to a given facet are not yet given)

This class was defined to import and display a mesh from different formats like OFF file format. Since it realized the concept of CDrawableWithDisplay3D we can display an Mesh with a Display3D object:

First we have to include the following header files:

#include "DGtal/shapes/Mesh.h"

Prepare display using QGLviewer: Viewer3D

QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.show();

Construct a Mesh with various faces:

// A mesh is constructed and faces are added from the vertex set.
Mesh<Point> aMesh(true);
aMesh.addVertex(Point(0,0,0));
aMesh.addVertex(Point(1,0,0));
aMesh.addVertex(Point(1,1,0));
aMesh.addVertex(Point(0,0,1));
aMesh.addVertex(Point(1,0,1));
aMesh.addVertex(Point(1,1,1));
aMesh.addVertex(Point(0,1,1));
aMesh.addVertex(Point(0,1,0));
aMesh.addVertex(Point(0,2,0));
aMesh.addVertex(Point(0,3,1));
aMesh.addVertex(Point(0,2,2));
aMesh.addVertex(Point(0,1,2));
aMesh.addVertex(Point(0,0,1));
aMesh.addTriangularFace(0, 1, 2, Color(150,0,150,104));
aMesh.addQuadFace(6,5,4,3, Color::Blue);
listIndex.push_back(7);
listIndex.push_back(8);
listIndex.push_back(9);
listIndex.push_back(10);
listIndex.push_back(11);
listIndex.push_back(12);
aMesh.addFace(listIndex, Color(150,150,0,54));
static const Color Blue
Definition: Color.h:419
std::vector< Index > MeshFace
Definition: Mesh.h:126
TPoint Point
Definition: Mesh.h:102

Displaying the result:

viewer.setLineColor(Color(150,0,0,254));
viewer << aMesh;
viewer << Viewer3D<>::updateDisplay;
See also
MeshReader MeshWriter .

Definition at line 91 of file Mesh.h.

Member Typedef Documentation

◆ ColorStorage

template<typename TPoint >
typedef std::vector<DGtal::Color> DGtal::Mesh< TPoint >::ColorStorage

Define the type to store the color associated to each face

Definition at line 137 of file Mesh.h.

◆ ConstIterator

template<typename TPoint >
typedef VertexStorage::const_iterator DGtal::Mesh< TPoint >::ConstIterator

Define the type of the const iterator on vertex.

Definition at line 143 of file Mesh.h.

◆ FaceStorage

template<typename TPoint >
typedef std::vector<MeshFace> DGtal::Mesh< TPoint >::FaceStorage

Define the type to store the faces of the mesh.

Definition at line 132 of file Mesh.h.

◆ Index

template<typename TPoint >
typedef VertexStorage::size_type DGtal::Mesh< TPoint >::Index

Define the size type of the containers.

Definition at line 120 of file Mesh.h.

◆ Iterator

template<typename TPoint >
typedef VertexStorage::iterator DGtal::Mesh< TPoint >::Iterator

Define the type of the iterator on vertex.

Definition at line 148 of file Mesh.h.

◆ MeshFace

template<typename TPoint >
typedef std::vector<Index> DGtal::Mesh< TPoint >::MeshFace

Structure for representing the faces from the vertex index.

Definition at line 126 of file Mesh.h.

◆ Point

template<typename TPoint >
typedef TPoint DGtal::Mesh< TPoint >::Point

Main type associated to the mesh vertices.

Definition at line 102 of file Mesh.h.

◆ RealPoint

template<typename TPoint >
typedef DGtal::PointVector<TPoint::dimension, double> DGtal::Mesh< TPoint >::RealPoint

Type to represent real points which can be obtained from various methods (like getFaceBarycenter).

Definition at line 109 of file Mesh.h.

◆ Size

template<typename TPoint >
typedef std::size_t DGtal::Mesh< TPoint >::Size

Define the size type of the containers.

Definition at line 153 of file Mesh.h.

◆ VertexStorage

template<typename TPoint >
typedef std::vector<TPoint> DGtal::Mesh< TPoint >::VertexStorage

Define the type to store each mesh vertex.

Definition at line 115 of file Mesh.h.

Constructor & Destructor Documentation

◆ Mesh() [1/4]

template<typename TPoint >
DGtal::Mesh< TPoint >::Mesh ( bool  saveFaceColor = false)

Constructor. By default the constructed mesh does not store color information about the mesh. If you want to include color in the Mesh object you have to set the constructor parameter saveFaceColor to true.

Parameters
saveFaceColorused to memorize the color of a face (default= false)

◆ Mesh() [2/4]

template<typename TPoint >
DGtal::Mesh< TPoint >::Mesh ( const DGtal::Color aColor)

Constructor. The constructed mesh will store an unique default color information about the mesh.

Parameters
aColorused to memorize the color of a face (default= false)

◆ Mesh() [3/4]

template<typename TPoint >
DGtal::Mesh< TPoint >::Mesh ( const std::vector< TPoint > &  vertexSet)

Constructor by usung a vertex set as init. The color are not stored in this case.

Parameters
vertexSetthe set of vertex.

◆ ~Mesh()

template<typename TPoint >
DGtal::Mesh< TPoint >::~Mesh ( )

Destructor.

◆ Mesh() [4/4]

template<typename TPoint >
DGtal::Mesh< TPoint >::Mesh ( const Mesh< TPoint > &  other)

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

◆ addFace()

template<typename TPoint >
void DGtal::Mesh< TPoint >::addFace ( const MeshFace aFace,
const DGtal::Color aColor = DGtal::Color::White 
)

Add a quad face given from index position.

Note
If you want to follow the OBJ format convention, you have to order the vertices of the face in CCW (to have the correct normal orientation).

Referenced by main().

◆ addQuadFace()

template<typename TPoint >
void DGtal::Mesh< TPoint >::addQuadFace ( Index  indexVertex1,
Index  indexVertex2,
Index  indexVertex3,
Index  indexVertex4,
const DGtal::Color aColor = DGtal::Color::White 
)

Add a quad face given from index position.

Parameters
indexVertex1the index of the first vertex face.
indexVertex2the index of the second vertex face.
indexVertex3the index of the third vertex face.
indexVertex4the index of the fourth vertex face.
aColorthe quad face color.
Note
If you want to follow the OBJ format convention, you have to order the vertices in CCW (to have the correct normal orientation).

Referenced by main(), testMesh(), and testMeshWriter().

◆ addTriangularFace()

template<typename TPoint >
void DGtal::Mesh< TPoint >::addTriangularFace ( Index  indexVertex1,
Index  indexVertex2,
Index  indexVertex3,
const DGtal::Color aColor = DGtal::Color::White 
)

Add a triangle face given from index position.

Parameters
indexVertex1the index of the first vertex face.
indexVertex2the index of the second vertex face.
indexVertex3the index of the third vertex face.
aColorthe triangle face color.
Note
If you want to follow the OBJ format convention, you have to order the vertices in CCW (to have the correct normal orientation).

Referenced by main(), and testMesh().

◆ addVertex()

template<typename TPoint >
void DGtal::Mesh< TPoint >::addVertex ( const TPoint &  vertex)

Adding new vertex.

Referenced by main(), testMesh(), and testMeshWriter().

◆ className()

template<typename TPoint >
std::string DGtal::Mesh< TPoint >::className ( ) const
Returns
the style name used for drawing this object.

◆ clearFaces()

template<typename TPoint >
void DGtal::Mesh< TPoint >::clearFaces ( )

Clear all faces of the mesh.

◆ clearVertices()

template<typename TPoint >
void DGtal::Mesh< TPoint >::clearVertices ( )

Clear all vertices of the mesh.

◆ createMeshFromHeightSequence()

template<typename TPoint >
template<typename TValue >
static void DGtal::Mesh< TPoint >::createMeshFromHeightSequence ( Mesh< TPoint > &  aMesh,
const std::vector< TValue > &  anValueSequence,
const unsigned int  lengthSequence,
double  stepX,
double  stepY,
double  stepZ,
const DGtal::Color aMeshColor = DGtal::Color::White 
)
static

Generates a surface mesh defined from a sequence of 2D height values (can be seen as a height map).

Parameters
[out]aMeshthe mesh in which the new surface mesh will be created.
[in]anValueSequencethe sequence of values defining the height points.
[in]lengthSequencethe number of points constituing a line in the height map.
[in]stepXthe x grid step to define the scale of the resulting mesh.
[in]stepYthe y grid step to define the scale of the resulting mesh.
[in]stepZthe z grid step to define the scale of the resulting mesh.
[in]aMeshColorthe color given to the generated tube mesh.

◆ createTubularMesh() [1/2]

template<typename TPoint >
static void DGtal::Mesh< TPoint >::createTubularMesh ( Mesh< TPoint > &  aMesh,
const std::vector< TPoint > &  aSkeleton,
const double  aRadius,
const double  angleStep = 0.2,
const DGtal::Color aMeshColor = DGtal::Color::White 
)
static

Generates a tube mesh (of constant radius) from a set of points representing the tube skeleton. Each circular section is connected with quads.

Note
The vertices of circular sections are associated from nearest point according to the tube direction.
Parameters
[out]aMeshthe mesh in which the new tube mesh will be created.
[in]aSkeletonthe set of points which defines the tube skeleton.
[in]aRadiusthe tube radius.
[in]angleStepthe circular precision of the tube approximation.
[in]aMeshColorthe color given to the generated tube mesh.

Referenced by testVisualTubularMesh().

◆ createTubularMesh() [2/2]

template<typename TPoint >
static void DGtal::Mesh< TPoint >::createTubularMesh ( Mesh< TPoint > &  aMesh,
const std::vector< TPoint > &  aSkeleton,
const std::vector< double > &  aVectOfRadius,
const double  angleStep = 0.2,
const DGtal::Color aMeshColor = DGtal::Color::White 
)
static

Generates a tube mesh from a tube skeleton and from its associated circular section radii. Each circular section is connected with quads.

Note
The vertices of circular sections are associated from nearest point according to the tube direction.
Parameters
[out]aMeshthe mesh in which the new tube mesh will be created.
[in]aSkeletonthe set of points which defines the tube skeleton.
[in]aVectOfRadiusthe vector containing all circular sections (if it contains not enougth it value, the next values will be taken from the begining of the vector).
[in]angleStepthe circular precision of the tube approximation.
[in]aMeshColorthe color given to the generated tube mesh.

◆ faceBegin() [1/2]

template<typename TPoint >
FaceStorage::iterator DGtal::Mesh< TPoint >::faceBegin ( )
inline
Returns
a const iterator pointing to the first face of the mesh.

Definition at line 425 of file Mesh.h.

425  {
426  return myFaceList.begin();
427  }
FaceStorage myFaceList
Definition: Mesh.h:513

References DGtal::Mesh< TPoint >::myFaceList.

◆ faceBegin() [2/2]

template<typename TPoint >
FaceStorage::const_iterator DGtal::Mesh< TPoint >::faceBegin ( ) const
inline
Returns
a const iterator pointing to the first face of the mesh.

Definition at line 402 of file Mesh.h.

402  {
403  return myFaceList.begin();
404  }

References DGtal::Mesh< TPoint >::myFaceList.

Referenced by testMesh().

◆ faceEnd() [1/2]

template<typename TPoint >
FaceStorage::iterator DGtal::Mesh< TPoint >::faceEnd ( )
inline
Returns
a const iterator pointing after the end of the last face of the mesh.

Definition at line 437 of file Mesh.h.

437  {
438  return myFaceList.end();
439  }

References DGtal::Mesh< TPoint >::myFaceList.

◆ faceEnd() [2/2]

template<typename TPoint >
FaceStorage::const_iterator DGtal::Mesh< TPoint >::faceEnd ( ) const
inline
Returns
a const iterator pointing after the end of the last face of the mesh.

Definition at line 414 of file Mesh.h.

414  {
415  return myFaceList.end();
416  }

References DGtal::Mesh< TPoint >::myFaceList.

Referenced by testMesh().

◆ getBoundingBox()

template<typename TPoint >
std::pair<TPoint, TPoint> DGtal::Mesh< TPoint >::getBoundingBox ( ) const
Returns
the bounding box of the mesh represented as a pair of points.

Referenced by testMesh().

◆ getFace() [1/2]

template<typename TPoint >
MeshFace& DGtal::Mesh< TPoint >::getFace ( Index  i)
Parameters
ithe index of the face.
Returns
a const reference to the face of index i.

◆ getFace() [2/2]

template<typename TPoint >
const MeshFace& DGtal::Mesh< TPoint >::getFace ( Index  i) const
Parameters
ithe index of the face.
Returns
a const reference to the face of index i.

Referenced by testMesh(), and testMeshReader().

◆ getFaceBarycenter()

template<typename TPoint >
RealPoint DGtal::Mesh< TPoint >::getFaceBarycenter ( Index  i) const
Parameters
ithe index of the face.
Returns
barycenter (RealPoint) of the face of index i.

Referenced by testMesh().

◆ getFaceColor()

template<typename TPoint >
const Color& DGtal::Mesh< TPoint >::getFaceColor ( Index  i) const

Return a reference to a face Color of index i.

Parameters
ithe index of the face.
Returns
the color of the face of index i.

Referenced by testMesh(), and testMeshReader().

◆ getVertex() [1/2]

template<typename TPoint >
TPoint& DGtal::Mesh< TPoint >::getVertex ( Index  i)
Parameters
ithe index of the vertex.
Returns
a reference to the vertex of index i.

◆ getVertex() [2/2]

template<typename TPoint >
const TPoint& DGtal::Mesh< TPoint >::getVertex ( Index  i) const
Parameters
ithe index of the vertex.
Returns
a const reference to the vertex of index i.

Referenced by testMesh().

◆ invertVertexFaceOrder()

template<typename TPoint >
void DGtal::Mesh< TPoint >::invertVertexFaceOrder ( )

Invert the face order (useful when normal is deducted from vertex order).

Referenced by testMesh().

◆ isStoringFaceColors()

template<typename TPoint >
bool DGtal::Mesh< TPoint >::isStoringFaceColors ( ) const
Returns
true if the Mesh is storing a color for each faces.

◆ isValid()

template<typename TPoint >
bool DGtal::Mesh< TPoint >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ nbFaces()

template<typename TPoint >
Size DGtal::Mesh< TPoint >::nbFaces ( ) const

Return the number of faces contained on the mesh object.

Returns
the number of faces.

Referenced by SCENARIO(), TEST_CASE(), testMesh(), testMeshGeneration(), testMeshReader(), and testVisualTubularMesh().

◆ nbVertex()

template<typename TPoint >
Size DGtal::Mesh< TPoint >::nbVertex ( ) const

Return the number of faces contained on the mesh object.

Returns
the number of faces.

Referenced by SCENARIO(), testMesh(), testMeshGeneration(), and testMeshReader().

◆ operator=()

template<typename TPoint >
Mesh& DGtal::Mesh< TPoint >::operator= ( const Mesh< TPoint > &  other)

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.

◆ quadToTriangularFaces()

template<typename TPoint >
unsigned int DGtal::Mesh< TPoint >::quadToTriangularFaces ( )

Transform quad faces of the mesh to triangular one.

Returns
the number of quads which were transformed.

Referenced by testMesh().

◆ removeFaces()

template<typename TPoint >
void DGtal::Mesh< TPoint >::removeFaces ( const std::vector< Index > &  facesIndex)

Remove faces from the mesh.

Note
the vertexes which are no more associated to any face are also removed.
Parameters
[in]facesIndexthe index of the face to be removed.

Referenced by testMesh().

◆ removeIsolatedVertices()

template<typename TPoint >
void DGtal::Mesh< TPoint >::removeIsolatedVertices ( )

Removed isolated vertices of input mesh that are not associated to a face.

Referenced by testMesh().

◆ rescale()

template<typename TPoint >
void DGtal::Mesh< TPoint >::rescale ( const typename TPoint::Component  aScale)

Change the scale of the mesh (i.e all vertex coordinates are multiplied by a given factor aScale).

Parameters
[in]aScalethe scale factor.

Referenced by testMesh().

◆ selfDisplay()

template<typename TPoint >
void DGtal::Mesh< TPoint >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

◆ setFaceColor()

template<typename TPoint >
void DGtal::Mesh< TPoint >::setFaceColor ( Index  i,
const DGtal::Color aColor 
)

Set the color of a particular face of the mesh. If the mesh does not yet store the color of all individual faces (isStoringFaceColors to false) it fills each face color with the default color and the value of isStoringFaceColors is set to true.

Parameters
[in]ithe index of the face
[in]aColorthe color for the considered face.

Referenced by testMesh().

◆ subDivideTriangularFaces()

template<typename TPoint >
double DGtal::Mesh< TPoint >::subDivideTriangularFaces ( const double  minArea)

SubDivide triangular mesh if triangle area is larger than the given parameter.

Parameters
[in]minAreathe minimum area factor.
Returns
the new max triangle area.

Referenced by testMesh().

◆ vertexBegin() [1/2]

template<typename TPoint >
Iterator DGtal::Mesh< TPoint >::vertexBegin ( )
inline
Returns
an iterator pointing to the first vertex of the mesh.

Definition at line 379 of file Mesh.h.

379  {
380  return myVertexList.begin();
381  }
VertexStorage myVertexList
Definition: Mesh.h:514

References DGtal::Mesh< TPoint >::myVertexList.

◆ vertexBegin() [2/2]

template<typename TPoint >
ConstIterator DGtal::Mesh< TPoint >::vertexBegin ( ) const
inline
Returns
an const_iterator pointing to the first vertex of the mesh.

Definition at line 359 of file Mesh.h.

359  {
360  return myVertexList.begin();
361  }

References DGtal::Mesh< TPoint >::myVertexList.

Referenced by testMesh().

◆ vertexEnd() [1/2]

template<typename TPoint >
Iterator DGtal::Mesh< TPoint >::vertexEnd ( )
inline
Returns
an iterator pointing after the end of the last vertex of the mesh.

Definition at line 390 of file Mesh.h.

390  {
391  return myVertexList.end();
392  }

References DGtal::Mesh< TPoint >::myVertexList.

◆ vertexEnd() [2/2]

template<typename TPoint >
ConstIterator DGtal::Mesh< TPoint >::vertexEnd ( ) const
inline
Returns
an const_iterator pointing after the end of the last vertex of the mesh.

Definition at line 369 of file Mesh.h.

369  {
370  return myVertexList.end();
371  }

References DGtal::Mesh< TPoint >::myVertexList.

Referenced by testMesh().

Field Documentation

◆ myDefaultColor

template<typename TPoint >
DGtal::Color DGtal::Mesh< TPoint >::myDefaultColor
private

Definition at line 517 of file Mesh.h.

◆ myFaceColorList

template<typename TPoint >
ColorStorage DGtal::Mesh< TPoint >::myFaceColorList
private

Definition at line 515 of file Mesh.h.

◆ myFaceList

template<typename TPoint >
FaceStorage DGtal::Mesh< TPoint >::myFaceList
private

Definition at line 513 of file Mesh.h.

Referenced by DGtal::Mesh< TPoint >::faceBegin(), and DGtal::Mesh< TPoint >::faceEnd().

◆ mySaveFaceColor

template<typename TPoint >
bool DGtal::Mesh< TPoint >::mySaveFaceColor
private

Definition at line 516 of file Mesh.h.

◆ myVertexList

template<typename TPoint >
VertexStorage DGtal::Mesh< TPoint >::myVertexList
private

Definition at line 514 of file Mesh.h.

Referenced by DGtal::Mesh< TPoint >::vertexBegin(), and DGtal::Mesh< TPoint >::vertexEnd().


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