DGtal  0.9.3beta
Manipulating Simple Mesh

Table of Contents

Author
Bertrand Kerautret

Simple Mesh Class

The aim of this class is to handle basic simple mesh mainly for basic tasks such as to import/export/display of digital surface. This class is able to deal with triangulated, quad or polygonal faces and can include specific colors to display faces. It also provides several static tools to generate simple shapes like tubular objects or the 3d surface from height map.

The mesh object stores explicitly the vertices and each face is represented as a list of vertex indices.

Mesh Construction

To construct a Mesh object you need first to include the associated header file:

#include "DGtal/shapes/Mesh.h"

Then the mesh construction is very simple, for instance you start constructing an empty mesh input and specify if you want to store or not the vertex colors in the mesh:

Mesh<Point> aMesh(true);

Then you can add some vertices mesh:

aMesh.addVertex(Point(0,0,0));
aMesh.addVertex(Point(1,0,0));
aMesh.addVertex(Point(1,1,0));

and add some triangular/quad faces from the vertex indices:

aMesh.addTriangularFace(0, 1, 2, Color(150,0,150,104));
aMesh.addQuadFace(6,5,4,3, Color::Blue);

You can also insert some polygonal faces by defining a vector containing the vertices of the face:

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

An example of mesh construction is given here: mesh3DConstructionAndVisualisation.cpp and will produce the following faces:

example3dMeshConstruction.png
Simple example of 3D mesh construction.

Mesh IO

The Mesh object is integrated in the main IO framework of DGtal. You can for instance display a Mesh object directly through a Viewer3d object:

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

(See complete example in mesh3DConstructionAndVisualisation.cpp)

You can also export a mesh by using the MeshWriter class given in the header file:

#include "DGtal/shapes/Mesh.h"
#include "DGtal/io/writers/MeshWriter.h"

and export it:

bool isOK = aMesh >> "test.off";

The mesh import is also simple:

Generating Basic Mesh

The Mesh class also provides some methods to generate shape mesh associated to tubular object or 3d surface from height map.

For instance you can first define the vector of the 3D skeleton points:

std::vector<Z3i::RealPoint> aSkeleton;
aSkeleton.push_back(Z3i::RealPoint(0.0, 0.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(10.0, 0.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(20.0, 0.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(30.0, 0.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(35.0, 5.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 10.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 20.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 30.0, 0.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 35.0, 5.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 40.0, 10.0));
aSkeleton.push_back(Z3i::RealPoint(40.0, 40.0, 20.0));

Then you can reconstruct a tubular mesh with a given radius:

Mesh<Z3i::RealPoint> aMesh(true);

You will obtain such a tube display:

testMeshVisu3d.png
Resulting mesh of tubular object.

Another example is given in testMesh.cpp which generates an height field from a sequence of height values. In the same way than the previous example, you can construct your input height vector:

std::vector<double> heightSequence;
heightSequence.push_back(0.1);
heightSequence.push_back(0.2);
heightSequence.push_back(0.15);
heightSequence.push_back(1.1);
heightSequence.push_back(2.2);
heightSequence.push_back(1.15);
heightSequence.push_back(0.1);
heightSequence.push_back(0.2);
heightSequence.push_back(0.15);

and then construct the height field mesh:

You will obtain such a small height field display (with previous tube mesh):

testMeshVisu3dBis.png
Resulting mesh of tubular object and height field.
See also
tests/shapes/testMesh.cpp