00001
00002
00003
00004
00005
00006
00007 #include<vcg/simplex/vertex/base.h>
00008 #include<vcg/simplex/face/base.h>
00009 #include<vcg/simplex/face/topology.h>
00010
00011 #include<vcg/complex/trimesh/base.h>
00012
00013 #include <vcg/complex/trimesh/update/bounding.h>
00014 #include <vcg/complex/trimesh/update/topology.h>
00015 #include <vcg/complex/trimesh/update/normal.h>
00016 #include <vcg/complex/trimesh/update/flag.h>
00017 #include <vcg/complex/trimesh/create/ball_pivoting.h>
00018
00019
00020 #include <wrap/io_trimesh/import_ply.h>
00021 #include <wrap/io_trimesh/export_ply.h>
00022
00023
00024 #include <iostream>
00025 #include <vector>
00026 #include <time.h>
00027
00028 using namespace vcg;
00029 using namespace std;
00030
00031 class MyFace;
00032 class MyVertex;
00033
00034 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00035 Use<MyFace> ::AsFaceType>{};
00036
00037 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags, vertex::Mark>{};
00038 class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {};
00039 class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
00040
00041 bool callback(int percent, const char *str) {
00042 cout << "str: " << str << " " << percent << "%\n";
00043 return true;
00044 }
00045
00046 int main(int argc, char **argv)
00047 {
00048 if(argc<3)
00049 {
00050 printf(
00051 "\n trimesh_ball_pivoting ("__DATE__")\n"
00052 " Visual Computing Group I.S.T.I. C.N.R.\n"
00053 "Usage: trimesh_ball_pivoting filein.ply fileout.ply [opt]\n"
00054 "options: \n"
00055 "-r <val> radius of the rolling ball\n"
00056 "-c <val> clustering radius (as fraction of radius) default: 0.05\n"
00057 );
00058 exit(0);
00059 }
00060
00061 float radius = 0.0f;
00062 float clustering = 0.05;
00063 int i = 3;
00064 while(i<argc)
00065 {
00066 if(argv[i][0]!='-')
00067 {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00068 switch(argv[i][1])
00069 {
00070 case 'r' : radius = atof(argv[++i]); printf("Using %f sphere radius\n",radius); break;
00071 case 'c' : clustering = atof(argv[++i]); printf("Using %f clustering radius\n",clustering); break;
00072
00073 default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00074 }
00075 ++i;
00076 }
00077 if(radius == 0)
00078 printf("Autodetecting ball radius...\n");
00079
00080 MyMesh m;
00081
00082 if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
00083 {
00084 printf("Error reading file %s\n",argv[1]);
00085 exit(0);
00086 }
00087 vcg::tri::UpdateBounding<MyMesh>::Box(m);
00088 vcg::tri::UpdateNormals<MyMesh>::PerFace(m);
00089 printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn);
00090
00091 int t0=clock();
00092
00093 tri::BallPivoting<MyMesh> pivot(m, radius, clustering);
00094 printf("Ball radius: %f\nClustering points withing %f radii\n", pivot.radius, clustering);
00095
00096 int t1=clock();
00097
00098 pivot.BuildMesh(callback);
00099
00100 int t2=clock();
00101
00102 printf("Output mesh vn:%i fn:%i\n",m.vn,m.fn);
00103 printf("Created in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1);
00104
00105 vcg::tri::io::PlyInfo pi;
00106 vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
00107 return 0;
00108
00109 }