DGtal  1.0.0
exampleMeshVoxelizer.cpp
Go to the documentation of this file.
1 
37 #include <iostream>
39 #include "ConfigExamples.h"
40 #include "DGtal/helpers/StdDefs.h"
41 #include "DGtal/base/Common.h"
42 #include "DGtal/shapes/Mesh.h"
44 #include "DGtal/shapes/MeshVoxelizer.h"
46 #include "DGtal/io/boards/Board3D.h"
47 #include "DGtal/io/writers/MeshWriter.h"
49 
50 using namespace std;
51 using namespace DGtal;
52 
54 
55 int main( )
56 {
57  trace.beginBlock ( "Example MeshVoxelizer" );
58 
59 
61  using namespace Z3i;
62  Mesh<Point> aMesh;
63 
64  trace.info()<<"Creating a cube"<<std::endl;
65  //Creating a cube
66  aMesh.addVertex(Point(0,0,0));
67  aMesh.addVertex(Point(1,0,0));
68  aMesh.addVertex(Point(1,1,0));
69  aMesh.addVertex(Point(0,1,0));
70  aMesh.addVertex(Point(0,1,1));
71  aMesh.addVertex(Point(1,1,1));
72  aMesh.addVertex(Point(1,0,1));
73  aMesh.addVertex(Point(0,0,1));
74 
75  aMesh.addQuadFace(0,1,2,3);
76  aMesh.addQuadFace(1,2,5,6);
77  aMesh.addQuadFace(7,6,5,4);
78  aMesh.addQuadFace(3,2,5,4);
79  aMesh.addQuadFace(0,3,4,7);
80  aMesh.addQuadFace(0,1,6,7);
82 
83 
85  Domain domain(Point(0,0,0), Point(128,128,128));
86  DigitalSet outputSet(domain);
87 
89 
90  trace.info()<<"Digitization..."<<std::endl;
91  voxelizer.voxelize(outputSet, aMesh, 15.0);
92 
93  trace.info()<<"Got "<< outputSet.size() << " voxels."<<std::endl;
95 
97  Board3D<> board;
98  for(auto voxel : outputSet)
99  board << voxel;
100  board.saveOBJ("voxelizedCube.obj");
102 
103 
104 
105  trace.endBlock();
106  return 0;
107 }
108 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, unsigned int indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
void saveOBJ(const std::string &filename, const bool isNormalized=false)
void voxelize(DigitalSet &outputSet, const Mesh< MeshPoint > &aMesh, const double scaleFactor=1.0)
int main()
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition: Mesh.h:91
double endBlock()
Domain domain
void addVertex(const TPoint &vertex)
The class Board3D is a type of Display3D which export the figures in the format OBJ/MTL when calling ...
Definition: Board3D.h:81
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Aim: A class for computing the digitization of a triangle or a Mesh.
Definition: MeshVoxelizer.h:79