23 #include<vcg/complex/complex.h>
25 #include <vcg/complex/algorithms/refine.h>
26 #include <vcg/complex/algorithms/refine_loop.h>
28 #include <vcg/complex/algorithms/bitquad_creation.h>
31 #include <wrap/io_trimesh/import_ply.h>
32 #include <wrap/io_trimesh/export.h>
42 struct MyUsedTypes :
public UsedTypes< Use<MyVertex>::AsVertexType,
43 Use<MyFace>::AsFaceType>{};
45 class MyVertex :
public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
46 class MyFace :
public Face < MyUsedTypes, face::InfoOcf, face::FFAdjOcf, face::VertexRef, face::BitFlags > {};
47 class MyMesh :
public vcg::tri::TriMesh< vector<MyVertex>, face::vector_ocf<MyFace> > {};
55 #define ONE_QUAD_X_EDGE 4
57 int main(
int argc,
char **argv)
62 "\n PlyRefine (" __DATE__
")\n"
63 " Visual Computing Group I.S.T.I. C.N.R.\n"
64 "Usage: PlyRefine filein.ply fileout.[ply|off|obj|...] ref_step [opt] \n"
66 " Refinement rules:\n"
67 " -m use simple midpoint subdivision (default) \n"
68 " -b use butterfly subdivision scheme \n"
69 " -l use loop subdivision scheme \n"
70 " -o use one-quad-per-edge schema (*) \n"
71 " -c use Catmull-Clark (*) \n"
72 " -e# refine only if the the edge is longer than #(default 0.0)\n"
74 " (*) produces quad-only meshes, but updates topology only, \n"
75 " and leaves geometry unaffected \n"
81 int i=4;
int n_steps;
float length=0;
85 {printf(
"Error unable to parse option '%s'\n",argv[i]); exit(5);}
88 case 'm' : RefMode=FLAT;
break;
89 case 'b' : RefMode=BUTTERFLY;
break;
90 case 'l' : RefMode=LOOP;
break;
91 case 'c' : RefMode=CATMULL;
break;
92 case 'o' : RefMode=ONE_QUAD_X_EDGE;
break;
93 case 'e' : length=(float)atof(argv[i]+2);
break;
94 default : {printf(
"Error unable to parse option '%s'\n",argv[i]); exit(0);}
101 if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0) {
102 printf(
"Error reading file %s\n",argv[1]);
106 m.face.EnableFFAdjacency();
110 printf(
"Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
112 n_steps=atoi(argv[3]);
114 for(i=0;i < n_steps;++i)
119 tri::Refine<MyMesh, tri::MidPoint<MyMesh> >(m,tri::MidPoint<MyMesh>(&m),length);
122 tri::RefineOddEven<MyMesh, tri::OddPointLoop<MyMesh>, tri::EvenPointLoop<MyMesh> >(m, tri::OddPointLoop<MyMesh>(m), tri::EvenPointLoop<MyMesh>(), length);
125 tri::BitQuadCreation<MyMesh>::MakePureByCatmullClark(m);
128 case ONE_QUAD_X_EDGE:
129 tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
133 tri::Refine<MyMesh, tri::MidPointButterfly<MyMesh> >(m,tri::MidPointButterfly<MyMesh>(m),length);
138 printf(
"Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
140 vcg::tri::io::Exporter<MyMesh>::Save(m,argv[2],vcg::tri::io::Mask::IOM_BITPOLYGONAL);