main.cpp
Go to the documentation of this file.
00001         
00002 // mesh definition 
00003 #include <vcg/simplex/vertex/with/afvn.h>
00004 #include <vcg/simplex/face/with/af.h>
00005 #include <vcg/complex/complex.h>
00006 
00007 #include <vcg/complex/algorithms/update/topology.h>
00008 #include <vcg/complex/algorithms/update/flag.h>
00009 #include <vcg/complex/algorithms/update/normal.h>
00010 #include <vcg/complex/algorithms/refine.h>
00011 
00012 // input output
00013 #include <wrap/io_trimesh/import_ply.h>
00014 #include <wrap/io_trimesh/export_ply.h>
00015 
00016 // std
00017 #include <vector>
00018 
00019 using namespace vcg;
00020 using namespace std;
00021 
00022 struct MyFace;
00023 struct MyTetra;
00024 struct MyEdge;
00025 struct MyVertex: public VertexAFVNf<MyEdge,MyFace,MyTetra>{};
00026 struct MyFace: public FaceAF<MyVertex,MyEdge,MyFace>{};
00027 struct MyMesh: public tri::TriMesh< vector<MyVertex>, vector<MyFace> >{};
00028 
00029 
00030 
00031 
00032 #define FLAT    0
00033 #define ARC             1
00034 #define BUTTERFLY 2
00035 //#define BUTTERFLY2 3
00036 
00037 //#define PLANE 4
00038 //#define SPHERE 5
00039 
00040 #define LENGTH 6
00041 #define ONLY_SEL 7
00042 
00043 
00044 int  main(int argc, char **argv){
00045                 if(argc<4)
00046         {
00047                 printf(
00048                 "\n                  PlyRefine ("__DATE__")\n"
00049                         "                                               Visual Computing Group I.S.T.I. C.N.R.\n"
00050                         "Usage: PlyRefine filein.ply fileout.ply [command list]\n"
00051                         "Commands: \n"
00052                         " Refinement rules:\n"
00053                         "     -m# midpoint flat \n"
00054                         "     -a# midpoint arc\n"
00055                         "     -b# butterfly\n"
00056                         //"     -p# clip with plane   \n"
00057                         //"     -s# clip with sphere   \n"
00058                         " Selective Refinement\n"
00059                         "     -L# refine only if the the edge is longer than #(default 0.0)\n"
00060                         "     -S(0|1)  refine only selected faces\n"
00061                         );
00062                 exit(0);
00063         }
00064 
00065         typedef pair<int,float> OP_TYPE;
00066         vector<OP_TYPE > operations;
00067         bool only_selected=false;
00068         int i=3; int n_steps;float length=0;
00069         while(i<argc)
00070                 {
00071                         if(argv[i][0]!='-')
00072                                 {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00073                         operations.push_back(OP_TYPE()); OP_TYPE & op = operations.back();
00074                         switch(argv[i][1])
00075                         {
00076                                 
00077                                 case 'm' :      
00078                                                                                 n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00079                                                                                 op.first = FLAT;op.second = n_steps; break;
00080                                 case 'a' :      
00081                                                                                 n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00082                                                                                 op.first = ARC;op.second = n_steps; break;
00083                                 case 'b' :      
00084                                                                                 n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00085                                                                                 op.first = BUTTERFLY;op.second = n_steps; break;
00086                                 //case 'v' :    
00087                                 //                                              n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00088                                 //                                              op.first = BUTTERFLY2;op.second = n_steps; break;
00089                                 //case 'p' :    
00090                                 //                                              n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00091                                 //                                              op.first = PLANE;op.second = n_steps; break;
00092                                 //case 's' :    
00093                                 //                                              n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00094                                 //                                              op.first = SPHERE;op.second = n_steps; break;
00095                                 case 'L' :      
00096                                                                                 n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00097                                                                                 op.first = LENGTH;op.second = n_steps; break;
00098                                 case 'S' :      
00099                                                                                 n_steps = atof(argv[i]+2); n_steps=max(1,n_steps);
00100                                                                                 op.first = ONLY_SEL;op.second = n_steps; break;
00101                                 default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00102                         }
00103                         ++i;
00104                 }
00105 
00106 
00107         MyMesh m;
00108                 if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
00109                         {
00110                         printf("Error reading file  %s\n",argv[1]);
00111                         exit(0);
00112                 }
00113 
00114                 
00115 
00116         vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
00117         vcg::tri::UpdateTopology<MyMesh>::FaceBorderFlags(m);
00118         vcg::tri::UpdateNormals<MyMesh>::PerVertexNormalized(m);
00119 
00120         int h;
00121         for(i=0;i < operations.size();++i){
00122                                         
00123                                 switch(operations[i].first){
00124                                         case FLAT:
00125                                                                                 for(h=0;h<operations[i].second;++h){
00126                                                                                         Refine(m,MidPoint<MyMesh>(),length,only_selected);
00127                                                                                         }
00128                                                                          break;
00129                                         case ARC:
00130                                                                 for(h=0;h<operations[i].second;++h){
00131                                                                                         Refine(m,MidPointArc<MyMesh>(),length,only_selected);}
00132                                                                  break;
00133                                         case BUTTERFLY:
00134                                                                 for(h=0;h<operations[i].second;++h){
00135                                                                                         Refine(m,MidPointButterfly<MyMesh>(),length,only_selected); }
00136                                                                                 break;
00137                                         //case BUTTERFLY2:
00138                                         //                      for(h=0;h<operations[i].second;++h){
00139                                         //                                              m.ComputeNormalizedVertexNormal();
00140                                         //                                              Refine(m,MidPointButterfly2<MyMesh>(),length,only_selected);
00141                                         //                              }
00142                                         //                                              break;
00143         /*                              case PLANE:
00144                                                                 for(h=0;h<operations[i].second;++h){
00145                                                                                 m.ComputeNormalizedVertexNormal();
00146                                                                                 Refine(m,MidPointPlane<MyMesh>(),length,only_selected);
00147                                                                         }
00148                                                                          break;
00149                                         case SPHERE:
00150                                                                 for(h=0;h<operations[i].second;++h){
00151                                                                                         m.ComputeNormalizedVertexNormal();
00152                                                                                         Refine(m,MidPointSphere<MyMesh>(),length,only_selected);
00153                                                                         }
00154                                                         break;
00155         */                              case LENGTH:
00156                                                                                 length = operations[i].second; break;
00157                                         case ONLY_SEL:
00158                                                                                 only_selected = (bool)operations[i].second; break;
00159                         }
00160                 }
00161         
00162         
00163         //m.ComputeNormalizedVertexNormal();
00164         //Refine(m,MidPointArc<MyMesh>(),0);
00165         vcg::tri::io::PlyInfo pi;
00166         vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
00167         return 0;
00168         }


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