Go to the documentation of this file.00001 #include<vcg/complex/complex.h>
00002
00003 #include <vcg/complex/algorithms/update/topology.h>
00004 #include <vcg/complex/algorithms/update/normal.h>
00005 #include <vcg/complex/algorithms/update/flag.h>
00006 #include <vcg/complex/algorithms/refine.h>
00007 #include <vcg/complex/algorithms/refine_loop.h>
00008
00009 #include <vcg/complex/algorithms/bitquad_creation.h>
00010
00011
00012 #include <wrap/io_trimesh/import_ply.h>
00013 #include <wrap/io_trimesh/export.h>
00014
00015 using namespace vcg;
00016 using namespace std;
00017
00018
00019 class MyEdge;
00020 class MyFace;
00021 class MyVertex;
00022
00023 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType,
00024 Use<MyFace>::AsFaceType>{};
00025
00026 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
00027 class MyFace : public Face < MyUsedTypes, face::InfoOcf, face::FFAdjOcf, face::VertexRef, face::BitFlags > {};
00028 class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, face::vector_ocf<MyFace> > {};
00029
00030
00031
00032 #define FLAT 0
00033 #define LOOP 1
00034 #define CATMULL 2
00035 #define BUTTERFLY 3
00036 #define ONE_QUAD_X_EDGE 4
00037
00038 int main(int argc, char **argv)
00039 {
00040 if(argc<4)
00041 {
00042 printf(
00043 "\n PlyRefine (" __DATE__ ")\n"
00044 " Visual Computing Group I.S.T.I. C.N.R.\n"
00045 "Usage: PlyRefine filein.ply fileout.[ply|off|obj|...] ref_step [opt] \n"
00046 "Commands: \n"
00047 " Refinement rules:\n"
00048 " -m use simple midpoint subdivision (default) \n"
00049 " -b use butterfly subdivision scheme \n"
00050 " -l use loop subdivision scheme \n"
00051 " -o use one-quad-per-edge schema (*) \n"
00052 " -c use Catmull-Clark (*) \n"
00053 " -e# refine only if the the edge is longer than #(default 0.0)\n"
00054 "Info:\n"
00055 " (*) produces quad-only meshes, but updates topology only, \n"
00056 " and leaves geometry unaffected \n"
00057 );
00058 exit(2);
00059 }
00060
00061 int RefMode = FLAT ;
00062 int i=4; int n_steps; float length=0;
00063 while(i<argc)
00064 {
00065 if(argv[i][0]!='-')
00066 {printf("Error unable to parse option '%s'\n",argv[i]); exit(5);}
00067 switch(argv[i][1])
00068 {
00069 case 'm' : RefMode=FLAT; break;
00070 case 'b' : RefMode=BUTTERFLY; break;
00071 case 'l' : RefMode=LOOP; break;
00072 case 'c' : RefMode=CATMULL; break;
00073 case 'o' : RefMode=ONE_QUAD_X_EDGE; break;
00074 case 'e' : length=(float)atof(argv[i]+2); break;
00075 default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
00076 }
00077 ++i;
00078 }
00079
00080 MyMesh m;
00081
00082 if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0) {
00083 printf("Error reading file %s\n",argv[1]);
00084 exit(1);
00085 }
00086
00087 m.face.EnableFFAdjacency();
00088 tri::UpdateTopology<MyMesh>::FaceFace(m);
00089 tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
00090 tri::UpdateNormal<MyMesh>::PerVertexNormalized(m);
00091 printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
00092
00093 n_steps=atoi(argv[3]);
00094
00095 for(i=0;i < n_steps;++i)
00096 {
00097 switch(RefMode)
00098 {
00099 case FLAT:
00100 tri::Refine<MyMesh, tri::MidPoint<MyMesh> >(m,tri::MidPoint<MyMesh>(&m),length);
00101 break;
00102 case LOOP:
00103 tri::RefineOddEven<MyMesh, tri::OddPointLoop<MyMesh>, tri::EvenPointLoop<MyMesh> >(m, tri::OddPointLoop<MyMesh>(m), tri::EvenPointLoop<MyMesh>(), length);
00104 break;
00105 case CATMULL:
00106 tri::BitQuadCreation<MyMesh>::MakePureByCatmullClark(m);
00107 tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
00108 break;
00109 case ONE_QUAD_X_EDGE:
00110 tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
00111 tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
00112 break;
00113 case BUTTERFLY:
00114 tri::Refine<MyMesh, tri::MidPointButterfly<MyMesh> >(m,tri::MidPointButterfly<MyMesh>(m),length);
00115 break;
00116 }
00117 }
00118
00119 printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
00120
00121 vcg::tri::io::PlyInfo pi;
00122 pi.mask|=vcg::tri::io::Mask::IOM_BITPOLYGONAL;
00123 vcg::tri::io::Exporter<MyMesh>::Save(m,argv[2],pi.mask);
00124 return 0;
00125 }