00001
00002
00003 #include <vcg/simplex/vertex/with/afvn.h>
00004 #include <vcg/simplex/face/with/af.h>
00005 #include <vcg/complex/trimesh/base.h>
00006
00007 #include <vcg/complex/trimesh/update/topology.h>
00008 #include <vcg/complex/trimesh/update/flag.h>
00009 #include <vcg/complex/trimesh/update/normal.h>
00010 #include <vcg/complex/trimesh/refine.h>
00011
00012
00013 #include <wrap/io_trimesh/import_ply.h>
00014 #include <wrap/io_trimesh/export_ply.h>
00015
00016
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
00036
00037
00038
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
00057
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
00087
00088
00089
00090
00091
00092
00093
00094
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
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
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
00164
00165 vcg::tri::io::PlyInfo pi;
00166 vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
00167 return 0;
00168 }