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
00029 #include<vcg/complex/complex.h>
00030
00031 #include <vcg/complex/algorithms/update/bounding.h>
00032 #include <vcg/complex/algorithms/update/topology.h>
00033 #include <vcg/complex/algorithms/update/normal.h>
00034 #include <vcg/complex/algorithms/update/flag.h>
00035 #include <vcg/complex/algorithms/clustering.h>
00036
00037
00038 #include <wrap/io_trimesh/import.h>
00039 #include <wrap/io_trimesh/export.h>
00040
00041 class MyFace;
00042 class MyVertex;
00043
00044 struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex>::AsVertexType, vcg::Use<MyFace>::AsFaceType>{};
00045
00046 class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
00047 class MyFace : public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
00048 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
00049
00050 int main(int argc, char **argv)
00051 {
00052 if(argc<3)
00053 {
00054 printf(
00055 "Usage: trimesh_clustering filein.ply fileout.ply [opt] \n"
00056 "options: \n"
00057 "-k cellnum approx number of cluster that should be defined; (default 10e5)\n"
00058 "-s size in absolute units the size of the clustering cell (override the previous param)\n"
00059 "-d enable the duplication of faces for double surfaces\n"
00060 );
00061 exit(0);
00062 }
00063
00064 int CellNum=100000;
00065 float CellSize=0;
00066 bool DupFace=false;
00067
00068 int i=3;
00069 while(i<argc)
00070 {
00071 if(argv[i][0]!='-')
00072 { printf("Error unable to parse option '%s'\n",argv[i]); exit(0); }
00073 switch(argv[i][1])
00074 {
00075 case 'k' : CellNum=atoi(argv[i+1]); ++i; printf("Using %i clustering cells\n",CellNum); break;
00076 case 's' : CellSize=atof(argv[i+1]); ++i; printf("Using %5f as clustering cell size\n",CellSize); break;
00077 case 'd' : DupFace=true; printf("Enabling the duplication of faces for double surfaces\n"); break;
00078
00079 default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00080 }
00081 ++i;
00082 }
00083
00084 MyMesh m;
00085 if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
00086 {
00087 printf("Error reading file %s\n",argv[1]);
00088 exit(0);
00089 }
00090
00091 vcg::tri::UpdateBounding<MyMesh>::Box(m);
00092 vcg::tri::UpdateNormal<MyMesh>::PerFace(m);
00093 printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
00094 vcg::tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > Grid;
00095 Grid.DuplicateFaceParam=DupFace;
00096 Grid.Init(m.bbox,CellNum,CellSize);
00097
00098 printf("Clustering to %i cells\n",Grid.Grid.siz[0]*Grid.Grid.siz[1]*Grid.Grid.siz[2] );
00099 printf("Grid of %i x %i x %i cells\n",Grid.Grid.siz[0],Grid.Grid.siz[1],Grid.Grid.siz[2]);
00100 printf("with cells size of %.2f x %.2f x %.2f units\n",Grid.Grid.voxel[0],Grid.Grid.voxel[1],Grid.Grid.voxel[2]);
00101
00102 Grid.AddMesh(m);
00103 Grid.ExtractMesh(m);
00104 printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
00105
00106 vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2]);
00107 return 0;
00108 }