#include #include #include #include #include #include #include // input output #include #include using namespace vcg; using namespace std; class MyEdge; // dummy prototype never used class MyFace; class MyVertex; struct MyUsedTypes : public UsedTypes< Use::AsVertexType, Use::AsFaceType>{}; class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{}; class MyFace : public Face < MyUsedTypes, face::InfoOcf, face::FFAdjOcf, face::VertexRef, face::BitFlags > {}; class MyMesh : public vcg::tri::TriMesh< vector, face::vector_ocf > {}; #define FLAT 0 #define LOOP 1 #define CATMULL 2 #define BUTTERFLY 3 #define ONE_QUAD_X_EDGE 4 int main(int argc, char **argv) { if(argc<4) { printf( "\n PlyRefine ("__DATE__")\n" " Visual Computing Group I.S.T.I. C.N.R.\n" "Usage: PlyRefine filein.ply fileout.[ply|off|obj|...] ref_step [opt] \n" "Commands: \n" " Refinement rules:\n" " -m use simple midpoint subdivision (default) \n" " -b use butterfly subdivision scheme \n" " -l use loop subdivision scheme \n" " -o use one-quad-per-edge schema (*) \n" " -c use Catmull-Clark (*) \n" " -e# refine only if the the edge is longer than #(default 0.0)\n" "Info:\n" " (*) produces quad-only meshes, but updates topology only, \n" " and leaves geometry unaffected \n" ); exit(2); } int RefMode = FLAT ; int i=4; int n_steps; float length=0; while(i::Open(m,argv[1])!=0) { printf("Error reading file %s\n",argv[1]); exit(1); } m.face.EnableFFAdjacency(); tri::UpdateTopology::FaceFace(m); tri::UpdateFlags::FaceBorderFromFF(m); tri::UpdateNormal::PerVertexNormalized(m); printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN()); n_steps=atoi(argv[3]); for(i=0;i < n_steps;++i) { switch(RefMode) { case FLAT: tri::Refine >(m,tri::MidPoint(&m),length); break; case LOOP: tri::RefineOddEven, tri::EvenPointLoop >(m, tri::OddPointLoop(m), tri::EvenPointLoop(), length); break; case CATMULL: tri::BitQuadCreation::MakePureByCatmullClark(m); tri::UpdateNormal::PerBitQuadFaceNormalized(m); break; case ONE_QUAD_X_EDGE: tri::BitQuadCreation::MakePureByRefine(m); tri::UpdateNormal::PerBitQuadFaceNormalized(m); break; case BUTTERFLY: tri::Refine >(m,tri::MidPointButterfly(m),length); break; } } printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN()); vcg::tri::io::PlyInfo pi; pi.mask|=vcg::tri::io::Mask::IOM_BITPOLYGONAL; vcg::tri::io::Exporter::Save(m,argv[2],pi.mask); return 0; }