Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include<vcg/complex/complex.h>
00025 #include<vcg/complex/algorithms/create/platonic.h>
00026 #include<wrap/io_trimesh/import_ply.h>
00027 #include<wrap/io_trimesh/export_ply.h>
00028 #include<vcg/complex/algorithms/point_sampling.h>
00029 #include<vcg/complex/algorithms/voronoi_processing.h>
00030
00031
00032 using namespace vcg;
00033 using namespace std;
00034
00035 class MyEdge;
00036 class MyFace;
00037 class MyVertex;
00038 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00039 Use<MyEdge> ::AsEdgeType,
00040 Use<MyFace> ::AsFaceType>{};
00041
00042 class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::VFAdj , vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
00043 class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags, face::VFAdj > {};
00044 class MyEdge : public Edge< MyUsedTypes>{};
00045 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
00046
00047
00048
00049 int main( int argc, char **argv )
00050 {
00051 MyMesh baseMesh, clusteredMesh;
00052 if(argc < 4 )
00053 {
00054 printf("Usage trimesh_voronoiclustering mesh region_num iterNum\n");
00055 return -1;
00056 }
00057 int seedNum = atoi(argv[2]);
00058 int iterNum = atoi(argv[3]);
00059 printf("Reading %s and sampling %i \n",argv[1],seedNum);
00060 int ret= tri::io::ImporterPLY<MyMesh>::Open(baseMesh,argv[1]);
00061 if(ret!=0)
00062 {
00063 printf("Unable to open %s for '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
00064 return -1;
00065 }
00066
00067 int randSeed=time(0);
00068 tri::UpdateTopology<MyMesh>::VertexFace(baseMesh);
00069 tri::TrivialPointerSampler<MyMesh> cs;
00070 tri::SurfaceSampling<MyMesh, tri::TrivialPointerSampler<MyMesh> >::SamplingRandomGenerator().initialize(randSeed);
00071 tri::SurfaceSampling<MyMesh, tri::TrivialPointerSampler<MyMesh> >::VertexUniform(baseMesh,cs,seedNum);
00072 tri::VoronoiProcessingParameter vpp;
00073 tri::EuclideanDistance<MyMesh> df;
00074 tri::VoronoiProcessing<MyMesh>::VoronoiRelaxing(baseMesh, cs.sampleVec, iterNum, df, vpp);
00075 tri::VoronoiProcessing<MyMesh>::TopologicalVertexColoring(baseMesh, cs.sampleVec);
00076 tri::VoronoiProcessing<MyMesh>::ConvertDelaunayTriangulationToMesh(baseMesh,clusteredMesh,cs.sampleVec);
00077
00078 tri::io::ExporterPLY<MyMesh>::Save(baseMesh,"base.ply",tri::io::Mask::IOM_VERTCOLOR );
00079 tri::io::ExporterPLY<MyMesh>::Save(clusteredMesh,"clustered.ply");
00080 return 0;
00081 }