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 #include<vcg/complex/complex.h>
00024
00025 #include<wrap/io_trimesh/import.h>
00026 #include<wrap/io_trimesh/export.h>
00027
00028 #include<vcg/complex/algorithms/point_sampling.h>
00029 #include<vcg/complex/algorithms/create/platonic.h>
00030 #include<vcg/complex/algorithms/clustering.h>
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::BitFlags >{};
00043 class MyFace : public Face< MyUsedTypes, face::FFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
00044 class MyEdge : public Edge<MyUsedTypes>{};
00045 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
00046
00047 int main( int argc, char **argv )
00048 {
00049 if(argc<3)
00050 {
00051 printf("Usage trimesh_base <meshfilename> radius (as perc) (\n");
00052 return -1;
00053 }
00054
00055 MyMesh m;
00056 MyMesh subM;
00057 MyMesh cluM;
00058 MyMesh rndM;
00059
00060 tri::MeshSampler<MyMesh> mps(subM);
00061 tri::MeshSampler<MyMesh> mrs(rndM);
00062
00063 if(tri::io::Importer<MyMesh>::Open(m,argv[1])!=0)
00064 {
00065 printf("Error reading file %s\n",argv[1]);
00066 exit(0);
00067 }
00068 tri::SurfaceSampling<MyMesh,tri::TrivialSampler<MyMesh> >::SamplingRandomGenerator().initialize(time(0));
00069 float perc = atof(argv[2]);
00070
00071 float radius = m.bbox.Diag() * perc;
00072 printf("Subsampling a PointCloud of %i vert with %f radius\n",m.VN(),radius);
00073 tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam pp;
00074 tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam::Stat pds; pp.pds=&pds;
00075 pp.bestSampleChoiceFlag=false;
00076 tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskPruning(mps, m, radius, pp);
00077 tri::io::ExporterPLY<MyMesh>::Save(subM,"PoissonMesh.ply");
00078 printf("Sampled %i vertices in %5.2f\n",subM.VN(), float(pds.pruneTime+pds.gridTime)/float(CLOCKS_PER_SEC));
00079
00080 int t0=clock();
00081 tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > ClusteringGrid;
00082 ClusteringGrid.Init(m.bbox,100000,radius*sqrt(2.0f));
00083 ClusteringGrid.AddPointSet(m);
00084 ClusteringGrid.ExtractMesh(cluM);
00085 int t1=clock();
00086 tri::io::ExporterPLY<MyMesh>::Save(cluM,"ClusterMesh.ply");
00087 printf("Sampled %i vertices in %5.2f\n",cluM.VN(), float(t1-t0)/float(CLOCKS_PER_SEC));
00088
00089 int t2=clock();
00090 int sampleNum = (cluM.VN()+subM.VN())/2;
00091 tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::VertexUniform(m, mrs,sampleNum);
00092 int t3=clock();
00093 tri::io::ExporterPLY<MyMesh>::Save(rndM,"RandomMesh.ply");
00094 printf("Sampled %i vertices in %5.2f\n",rndM.VN(), float(t3-t2)/float(CLOCKS_PER_SEC));
00095
00096
00097 return 0;
00098 }