DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
DGtal::MeshFromPoints< TPoint > Class Template Reference

#include <MeshFromPoints.h>

Collaboration diagram for DGtal::MeshFromPoints< TPoint >:
Collaboration graph
[legend]

Public Types

typedef std::vector< unsigned int > MeshFace

Public Member Functions

 MeshFromPoints (bool saveFaceColor=false)
 MeshFromPoints (const DGtal::Color &aColor)
 MeshFromPoints (const std::vector< TPoint > &vertexSet)
 ~MeshFromPoints ()
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)
const TPoint & getVertex (unsigned int i) const
const MeshFacegetFace (unsigned int i) const
const ColorgetFaceColor (unsigned int i) const
unsigned int nbFaces () const
unsigned int nbVertex () const
void invertVertexFaceOrder ()
void selfDisplay (std::ostream &out) const
bool isValid () const

Private Member Functions

 MeshFromPoints (const MeshFromPoints &other)
MeshFromPointsoperator= (const MeshFromPoints &other)

Private Attributes

std::vector< MeshFacemyFaceList
std::vector< TPoint > myVertexList
std::vector< DGtal::ColormyFaceColorList
bool mySaveFaceColor
DGtal::Color myDefaultColor

Detailed Description

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

Aim: This class is defined to represent a surface mesh through a set a vertex and a set of faces represented by its vertex index. By default it does not memorize the color Face and all faces will have the white color.

Description of template class 'MeshFromPoints'

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 MeshFromPoints with a Display3D object:

First we have to include the following header files:

#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/fromPoints/MeshFromPoints.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include <QtGui/qapplication.h>

Prepare display using QGLviewer: Viewer3D

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

Construct a MeshFromPoints with various faces:

MeshFromPoints<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;
bool res = application.exec();
See also:
MeshReader MeshWriter meshFromOFF.
Examples:
io/meshFromOFF.cpp.

Definition at line 86 of file MeshFromPoints.h.


Member Typedef Documentation

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

Structure for representing the faces from the vertex index.

Definition at line 98 of file MeshFromPoints.h.


Constructor & Destructor Documentation

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

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

Parameters:
saveFaceColor,:used to memorize the color of a face (default= false)

Constructor.

Definition at line 47 of file MeshFromPoints.ih.

References DGtal::Color::White.

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

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

Parameters:
saveFaceColor,:used to memorize the color of a face (default= false)

Constructor.

Definition at line 58 of file MeshFromPoints.ih.

{
myDefaultColor = aColor;
}
template<typename TPoint>
DGtal::MeshFromPoints< TPoint >::MeshFromPoints ( const std::vector< TPoint > &  vertexSet)

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

Parameters:
vertexSet,:the set of vertex.
template<typename TPoint >
DGtal::MeshFromPoints< TPoint >::~MeshFromPoints ( )
inline

Destructor.

Definition at line 69 of file MeshFromPoints.ih.

{
}
template<typename TPoint>
DGtal::MeshFromPoints< TPoint >::MeshFromPoints ( const MeshFromPoints< TPoint > &  other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

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

Add a quad face given from index position.

Parameters:
listIndex,:the index of all the face vertex.

Definition at line 177 of file MeshFromPoints.ih.

{
myFaceList.push_back(aFace);
myFaceColorList.push_back(aColor);
}
}
template<typename TPoint >
void DGtal::MeshFromPoints< TPoint >::addQuadFace ( unsigned int  indexVertex1,
unsigned int  indexVertex2,
unsigned int  indexVertex3,
unsigned int  indexVertex4,
const DGtal::Color aColor = DGtal::Color::White 
)
inline

Add a quad face given from index position.

Parameters:
indexVertex1,:the index of the first vertex face.
indexVertex2,:the index of the second vertex face.
indexVertex2,:the index of the second vertex face.

Definition at line 157 of file MeshFromPoints.ih.

Referenced by DGtal::Display3D::exportToMesh().

{
MeshFace aFace;
aFace.push_back(indexVertex1);
aFace.push_back(indexVertex2);
aFace.push_back(indexVertex3);
aFace.push_back(indexVertex4);
myFaceList.push_back(aFace);
myFaceColorList.push_back(aColor);
}
}
template<typename TPoint >
void DGtal::MeshFromPoints< TPoint >::addTriangularFace ( unsigned int  indexVertex1,
unsigned int  indexVertex2,
unsigned int  indexVertex3,
const DGtal::Color aColor = DGtal::Color::White 
)
inline

Add a triangle face given from index position.

Parameters:
indexVertex1,:the index of the first vertex face.
indexVertex2,:the index of the second vertex face.
indexVertex2,:the index of the second vertex face.

Definition at line 138 of file MeshFromPoints.ih.

Referenced by DGtal::Display3D::exportToMesh().

{
MeshFace aFace;
aFace.push_back(indexVertex1);
aFace.push_back(indexVertex2);
aFace.push_back(indexVertex3);
myFaceList.push_back(aFace);
myFaceColorList.push_back(aColor);
}
}
template<typename TPoint >
void DGtal::MeshFromPoints< TPoint >::addVertex ( const TPoint &  vertex)
inline

Adding new vertex.

Definition at line 128 of file MeshFromPoints.ih.

Referenced by DGtal::Display3D::exportToMesh().

{
myVertexList.push_back(point);
}
template<typename TPoint >
std::string DGtal::MeshFromPoints< TPoint >::className ( ) const
inline
Returns:
the style name used for drawing this object.

Definition at line 256 of file MeshFromPoints.ih.

Referenced by DGtal::Display3DFactory::draw().

{
return "MeshFromPoints";
}
template<typename TPoint >
const DGtal::MeshFromPoints< TPoint >::MeshFace & DGtal::MeshFromPoints< TPoint >::getFace ( unsigned int  i) const
inline

Return a reference to a face of index i.

Parameters:
i,:the index of the face.
Returns:
the face of index i.

Definition at line 200 of file MeshFromPoints.ih.

Referenced by DGtal::Display3DFactory::drawAsFaces().

{
return myFaceList.at(i);
}
template<typename TPoint >
const DGtal::Color & DGtal::MeshFromPoints< TPoint >::getFaceColor ( unsigned int  i) const
inline

Return a reference to a face Color of index i.

Parameters:
i,:the index of the face.
Returns:
the color of the face of index i.

Definition at line 225 of file MeshFromPoints.ih.

Referenced by DGtal::Display3DFactory::drawAsFaces().

{
return myFaceColorList.at(i);
}else{
}
}
template<typename TPoint >
const TPoint & DGtal::MeshFromPoints< TPoint >::getVertex ( unsigned int  i) const
inline

Return a reference to the vertex of index i.

Parameters:
i,:the index of the vertex.
Returns:
the vertex of index i.

Definition at line 190 of file MeshFromPoints.ih.

Referenced by DGtal::Display3DFactory::drawAsFaces().

{
return myVertexList.at(i);
}
template<typename TPoint >
void DGtal::MeshFromPoints< TPoint >::invertVertexFaceOrder ( )
inline

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

Definition at line 239 of file MeshFromPoints.ih.

{
for(unsigned int i=0; i<myFaceList.size(); i++){
vector<unsigned int> & aFace = myFaceList.at(i);
for(unsigned int j=0; j < aFace.size()/2; j++){
unsigned int tmp=aFace.at(j);
aFace.at(j)=aFace.at(aFace.size()-1-j);
aFace.at(aFace.size()-1-j)=tmp;
}
}
}
template<typename TPoint >
bool DGtal::MeshFromPoints< TPoint >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 95 of file MeshFromPoints.ih.

{
return true;
}
template<typename TPoint >
unsigned int DGtal::MeshFromPoints< TPoint >::nbFaces ( ) const
inline

Return the number of faces contained on the mesh object.

Returns:
the number of faces.

Definition at line 209 of file MeshFromPoints.ih.

Referenced by DGtal::Display3DFactory::drawAsFaces().

{
return myFaceList.size();
}
template<typename TPoint >
unsigned int DGtal::MeshFromPoints< TPoint >::nbVertex ( ) const
inline

Return the number of faces contained on the mesh object.

Returns:
the number of faces.

Definition at line 217 of file MeshFromPoints.ih.

{
return myVertexList.size();
}
template<typename TPoint>
MeshFromPoints& DGtal::MeshFromPoints< TPoint >::operator= ( const MeshFromPoints< TPoint > &  other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
template<typename TPoint >
void DGtal::MeshFromPoints< TPoint >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 83 of file MeshFromPoints.ih.

{
out << "[MeshFromPoints]";
}

Field Documentation

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

Definition at line 271 of file MeshFromPoints.h.

template<typename TPoint>
std::vector<DGtal::Color> DGtal::MeshFromPoints< TPoint >::myFaceColorList
private

Definition at line 269 of file MeshFromPoints.h.

template<typename TPoint>
std::vector<MeshFace> DGtal::MeshFromPoints< TPoint >::myFaceList
private

Definition at line 267 of file MeshFromPoints.h.

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

Definition at line 270 of file MeshFromPoints.h.

template<typename TPoint>
std::vector<TPoint> DGtal::MeshFromPoints< TPoint >::myVertexList
private

Definition at line 268 of file MeshFromPoints.h.


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