24 #include<vcg/complex/complex.h>
25 #include<vcg/complex/algorithms/create/platonic.h>
26 #include<wrap/io_trimesh/import_ply.h>
27 #include<wrap/io_trimesh/export_off.h>
28 #include<wrap/io_trimesh/export_ply.h>
29 #include<wrap/io_trimesh/export_dxf.h>
30 #include<vcg/complex/algorithms/point_sampling.h>
31 #include<vcg/complex/algorithms/voronoi_processing.h>
40 struct MyUsedTypes :
public UsedTypes< Use<MyVertex> ::AsVertexType,
41 Use<MyEdge> ::AsEdgeType,
42 Use<MyFace> ::AsFaceType>{};
44 class MyVertex :
public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::VFAdj, vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
45 class MyFace :
public Face< MyUsedTypes, face::VertexRef, face::Normal3f, face::Mark, face::BitFlags, face::VFAdj, face::FFAdj > {};
46 class MyEdge :
public Edge< MyUsedTypes, edge::VertexRef, edge::BitFlags>{};
47 class MyMesh :
public tri::TriMesh< vector<MyVertex>, vector<MyEdge>, vector<MyFace> > {};
49 int main(
int argc,
char **argv )
51 MyMesh baseMesh,voronoiMesh, voronoiPoly, delaunayMesh;
54 printf(
"Usage: trimesh_voronoi mesh sampleNum voronoiRelaxIter delaunayRefinementStep delaunayRelaxStep \n");
57 int sampleNum = atoi(argv[2]);
58 int iterNum = atoi(argv[3]);
60 int refineStep = atoi(argv[4]);
61 int relaxStep = atoi(argv[5]);
64 int ret= tri::io::ImporterPLY<MyMesh>::Open(baseMesh,argv[1]);
67 printf(
"Unable to open %s for '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
70 tri::VoronoiProcessingParameter vpp;
72 tri::io::ImporterPLY<MyMesh>::Open(baseMesh,argv[1]);
74 printf(
"Read %30s (%7i vn %7i fn) in %6.3f \n",argv[1],baseMesh.vn,baseMesh.fn,
float(t1-t0)/CLOCKS_PER_SEC);
77 vector<Point3f> pointVec;
79 tri::PoissonSampling<MyMesh>(baseMesh,pointVec,sampleNum,radius);
80 vector<MyVertex *> seedVec;
81 tri::VoronoiProcessing<MyMesh>::PreprocessForVoronoi(baseMesh,radius,vpp);
82 tri::VoronoiProcessing<MyMesh>::SeedToVertexConversion(baseMesh,pointVec,seedVec);
85 printf(
"Preprocessed %30s (%7i vn %7i fn) Computed %lu seed (asked %i) (radius %f) in %6.3f\n",
86 argv[1],baseMesh.vn,baseMesh.fn, seedVec.size(), sampleNum, radius, float(t2-t1)/CLOCKS_PER_SEC);
88 tri::EuclideanDistance<MyMesh> df;
89 vpp.geodesicRelaxFlag=
false;
90 int actualIter = tri::VoronoiProcessing<MyMesh>::VoronoiRelaxing(baseMesh, seedVec, iterNum, df, vpp);
93 printf(
"relaxed %lu seeds for %i(up to %i) iterations in %f secs\n",
94 seedVec.size(), actualIter, iterNum,float(t3-t2)/CLOCKS_PER_SEC);
96 tri::io::ExporterPLY<MyMesh>::Save(baseMesh,
"baseMesh.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY );
97 if(tri::VoronoiProcessing<MyMesh>::CheckVoronoiTopology(baseMesh,seedVec))
99 tri::VoronoiProcessing<MyMesh>::ConvertVoronoiDiagramToMesh(baseMesh,voronoiMesh,voronoiPoly,seedVec, vpp);
103 printf(
"WARNING some voronoi region are not disk like; the resulting delaunay triangulation is not manifold.\n");
107 tri::VoronoiProcessing<MyMesh>::ConvertDelaunayTriangulationToMesh(baseMesh,delaunayMesh,seedVec,
true);
108 tri::io::ExporterPLY<MyMesh>::Save(delaunayMesh,
"delaunayBaseMesh.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTFLAGS,
false );
109 tri::VoronoiProcessing<MyMesh>::RelaxRefineTriangulationSpring(baseMesh,delaunayMesh,refineStep,relaxStep);
112 printf(
"Refined %i times and relaxed %i to a %i v %i f mesh in %f secs\n",
113 refineStep, relaxStep, delaunayMesh.vn,delaunayMesh.fn,
float(t4-t3)/CLOCKS_PER_SEC);
115 tri::io::ExporterPLY<MyMesh>::Save(baseMesh,
"baseMesh.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY );
116 tri::io::ExporterPLY<MyMesh>::Save(voronoiMesh,
"voronoiMesh.ply",tri::io::Mask::IOM_VERTCOLOR );
117 tri::io::ExporterPLY<MyMesh>::Save(delaunayMesh,
"delaunayMesh.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTFLAGS,
false );
118 tri::io::ExporterPLY<MyMesh>::Save(voronoiPoly,
"voronoiPoly.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_EDGEINDEX,
false);