DGtal  0.9.4beta
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
DGtal::Mesh< TPoint > Class Template Reference

#include <DGtal/shapes/Mesh.h>

Collaboration diagram for DGtal::Mesh< TPoint >:
[legend]

Data Structures

struct  CompPoints
 

Public Types

typedef TPoint Point
 
typedef DGtal::PointVector< TPoint::dimension, double > RealPoint
 
typedef std::vector< unsigned int > MeshFace
 
typedef std::vector< TPoint > VertexStorage
 
typedef std::vector< MeshFaceFaceStorage
 
typedef std::vector< DGtal::ColorColorStorage
 
typedef VertexStorage::const_iterator ConstIterator
 
typedef VertexStorage::iterator Iterator
 

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 (unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
 
void addQuadFace (unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, unsigned int 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< unsigned int > &facesIndex)
 
const TPoint & getVertex (unsigned int i) const
 
TPoint & getVertex (unsigned int i)
 
const MeshFacegetFace (unsigned int i) const
 
RealPoint getFaceBarycenter (unsigned int i) const
 
MeshFacegetFace (unsigned int i)
 
const ColorgetFaceColor (unsigned int i) const
 
std::pair< TPoint, TPoint > getBoundingBox () const
 
void setFaceColor (unsigned int 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 ()
 
unsigned int nbFaces () const
 
unsigned int nbVertex () const
 
void invertVertexFaceOrder ()
 
void clearFaces ()
 
void changeScale (const double 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);
vector<unsigned int> listIndex;
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));

Displaying the result:

viewer.setLineColor(Color(150,0,0,254));
viewer << aMesh;
viewer << Viewer3D<>::updateDisplay;
See also
MeshReader MeshWriter .
Examples:
examples/tutorial-examples/polyhedralizer.cpp, io/meshFromOFF.cpp, shapes/mesh3DConstructionAndVisualisation.cpp, and tutorial-examples/polyhedralizer.cpp.

Definition at line 91 of file Mesh.h.

Member Typedef Documentation

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 132 of file Mesh.h.

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

Define the type of the const iterator on vertex.

Definition at line 138 of file Mesh.h.

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

Define the type to store the faces of the mesh.

Definition at line 127 of file Mesh.h.

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

Define the type of the iterator on vertex.

Definition at line 143 of file Mesh.h.

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

Structure for representing the faces from the vertex index.

Definition at line 116 of file Mesh.h.

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

Main type associated to the mesh vertices.

Definition at line 102 of file Mesh.h.

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.

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

Define the type to store each mesh vertex.

Definition at line 122 of file Mesh.h.

Constructor & Destructor Documentation

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)
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)
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.
template<typename TPoint>
DGtal::Mesh< TPoint >::~Mesh ( )

Destructor.

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

Copy constructor.

Parameters
otherthe object to clone.

Member Function Documentation

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).
template<typename TPoint>
void DGtal::Mesh< TPoint >::addQuadFace ( unsigned int  indexVertex1,
unsigned int  indexVertex2,
unsigned int  indexVertex3,
unsigned int  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).
template<typename TPoint>
void DGtal::Mesh< TPoint >::addTriangularFace ( unsigned int  indexVertex1,
unsigned int  indexVertex2,
unsigned int  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).
template<typename TPoint>
void DGtal::Mesh< TPoint >::addVertex ( const TPoint &  vertex)

Adding new vertex.

template<typename TPoint>
void DGtal::Mesh< TPoint >::changeScale ( const double  aScale)

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

Parameters
[in]aScalethe scale factor.
template<typename TPoint>
std::string DGtal::Mesh< TPoint >::className ( ) const
Returns
the style name used for drawing this object.
template<typename TPoint>
void DGtal::Mesh< TPoint >::clearFaces ( )

Clear all faces of the mesh.

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.
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.
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.
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 393 of file Mesh.h.

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

393  {
394  return myFaceList.begin();
395  }
FaceStorage myFaceList
Definition: Mesh.h:500
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 416 of file Mesh.h.

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

416  {
417  return myFaceList.begin();
418  }
FaceStorage myFaceList
Definition: Mesh.h:500
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 405 of file Mesh.h.

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

405  {
406  return myFaceList.end();
407  }
FaceStorage myFaceList
Definition: Mesh.h:500
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 428 of file Mesh.h.

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

428  {
429  return myFaceList.end();
430  }
FaceStorage myFaceList
Definition: Mesh.h:500
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.
template<typename TPoint>
const MeshFace& DGtal::Mesh< TPoint >::getFace ( unsigned int  i) const
Parameters
ithe index of the face.
Returns
a const reference to the face of index i.
template<typename TPoint>
MeshFace& DGtal::Mesh< TPoint >::getFace ( unsigned int  i)
Parameters
ithe index of the face.
Returns
a const reference to the face of index i.
template<typename TPoint>
RealPoint DGtal::Mesh< TPoint >::getFaceBarycenter ( unsigned int  i) const
Parameters
ithe index of the face.
Returns
barycenter (RealPoint) of the face of index i.
template<typename TPoint>
const Color& DGtal::Mesh< TPoint >::getFaceColor ( unsigned int  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.
template<typename TPoint>
const TPoint& DGtal::Mesh< TPoint >::getVertex ( unsigned int  i) const
Parameters
ithe index of the vertex.
Returns
a const reference to the vertex of index i.
template<typename TPoint>
TPoint& DGtal::Mesh< TPoint >::getVertex ( unsigned int  i)
Parameters
ithe index of the vertex.
Returns
a reference to the vertex of index i.
template<typename TPoint>
void DGtal::Mesh< TPoint >::invertVertexFaceOrder ( )

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

template<typename TPoint>
bool DGtal::Mesh< TPoint >::isStoringFaceColors ( ) const
Returns
true if the Mesh is storing a color for each faces.
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.
template<typename TPoint>
unsigned int DGtal::Mesh< TPoint >::nbFaces ( ) const

Return the number of faces contained on the mesh object.

Returns
the number of faces.
template<typename TPoint>
unsigned int DGtal::Mesh< TPoint >::nbVertex ( ) const

Return the number of faces contained on the mesh object.

Returns
the number of faces.
template<typename TPoint>
Mesh& DGtal::Mesh< TPoint >::operator= ( const Mesh< TPoint > &  other)

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.
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.
template<typename TPoint>
void DGtal::Mesh< TPoint >::removeFaces ( const std::vector< unsigned int > &  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.
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.
template<typename TPoint>
void DGtal::Mesh< TPoint >::setFaceColor ( unsigned int  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.
template<typename TPoint>
double DGtal::Mesh< TPoint >::subDivideTriangularFaces ( const double  minArea)

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

Parameters
[in]minAreathe minimum area factor.
Returns
the new max triangle area.
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 350 of file Mesh.h.

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

350  {
351  return myVertexList.begin();
352  }
VertexStorage myVertexList
Definition: Mesh.h:501
template<typename TPoint>
Iterator DGtal::Mesh< TPoint >::vertexBegin ( )
inline
Returns
an iterator pointing to the first vertex of the mesh.

Definition at line 370 of file Mesh.h.

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

370  {
371  return myVertexList.begin();
372  }
VertexStorage myVertexList
Definition: Mesh.h:501
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 360 of file Mesh.h.

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

360  {
361  return myVertexList.end();
362  }
VertexStorage myVertexList
Definition: Mesh.h:501
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 381 of file Mesh.h.

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

381  {
382  return myVertexList.end();
383  }
VertexStorage myVertexList
Definition: Mesh.h:501

Field Documentation

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

Definition at line 504 of file Mesh.h.

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

Definition at line 502 of file Mesh.h.

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

Definition at line 500 of file Mesh.h.

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

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

Definition at line 503 of file Mesh.h.

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

Definition at line 501 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: