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