trimesh_ball_pivoting.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 #include<vcg/complex/complex.h>
00024 
00025 #include <vcg/complex/algorithms/update/bounding.h>
00026 #include <vcg/complex/algorithms/update/topology.h>
00027 #include <vcg/complex/algorithms/update/normal.h>
00028 #include <vcg/complex/algorithms/update/flag.h>
00029 #include <vcg/complex/algorithms/create/ball_pivoting.h>
00030 
00031 // input output
00032 #include <wrap/io_trimesh/import_ply.h>
00033 #include <wrap/io_trimesh/export_ply.h>
00034 
00035 using namespace vcg;
00036 using namespace std;
00037 
00038 class MyFace;
00039 class MyVertex;
00040 
00041 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>           ::AsVertexType,
00042                                                                                 Use<MyFace>                     ::AsFaceType>{};
00043 
00044 class MyVertex  : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags, vertex::Mark>{};
00045 class MyFace    : public Face  < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {};
00046 class MyMesh    : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
00047 
00048 bool callback(int percent, const char *str) {
00049   cout << "str: " << str << " " << percent << "%\n";
00050   return true;
00051 }
00052 
00053 int  main(int argc, char **argv)
00054 {
00055  if(argc<3)
00056     {
00057         printf(
00058       "Usage: trimesh_ball_pivoting filein.ply fileout.ply [opt]\n"
00059       "options: \n"
00060       "-r <val> radius of the rolling ball\n"
00061       "-c <val> clustering radius (as fraction of radius) default: 0.05\n"
00062             );
00063         exit(0);
00064     }
00065 
00066    float radius = 0.0f;
00067    float clustering = 0.05;
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 'r' :      radius = atof(argv[++i]); printf("Using %f sphere radius\n",radius);  break;
00076                 case 'c' :      clustering = atof(argv[++i]); printf("Using %f clustering radius\n",clustering); break;
00077 
00078                 default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00079             }
00080             ++i;
00081         }
00082     if(radius == 0)
00083       printf("Autodetecting ball radius...\n");
00084 
00085     MyMesh m;
00086 
00087     if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
00088         {
00089       printf("Error reading file  %s\n",argv[1]);
00090             exit(0);
00091         }
00092   vcg::tri::UpdateBounding<MyMesh>::Box(m);
00093   vcg::tri::UpdateNormal<MyMesh>::PerFace(m);
00094   printf("Input mesh  vn:%i fn:%i\n",m.VN(),m.FN());
00095 
00096   int t0=clock();
00097   // Initialization
00098   tri::BallPivoting<MyMesh> pivot(m, radius, clustering);
00099   printf("Ball radius: %f\nClustering points withing %f radii\n", pivot.radius, clustering);
00100 
00101   int t1=clock();
00102   // the main processing
00103   pivot.BuildMesh(callback);
00104 
00105   int t2=clock();
00106 
00107   printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
00108   printf("Created in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1);
00109 
00110   vcg::tri::io::PlyInfo pi;
00111   vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
00112   return 0;
00113 
00114 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:13