vcglib/apps/sample/trimesh_refine/trimesh_refine.cpp

126 lines
3.8 KiB
C++
Raw Normal View History

#include<vcg/complex/complex.h>
2005-09-21 12:29:33 +02:00
#include <vcg/complex/algorithms/update/topology.h>
#include <vcg/complex/algorithms/update/normal.h>
#include <vcg/complex/algorithms/update/flag.h>
#include <vcg/complex/algorithms/refine.h>
#include <vcg/complex/algorithms/refine_loop.h>
#include <vcg/complex/algorithms/bitquad_creation.h>
2005-09-21 12:29:33 +02:00
// input output
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/export.h>
2005-09-21 12:29:33 +02:00
using namespace vcg;
using namespace std;
2005-12-02 01:46:12 +01:00
class MyEdge; // dummy prototype never used
class MyFace;
class MyVertex;
[ Changes in definition of TriMesh: PART I ] Note for the developers: the change to make to existing projects is very little but strictly necessary to compile. This change IS NOT backward compliant. ==== OLD ==== way to define a TriMesh: // forward declarations class MyVertex; class MyEdge; class MyFace; class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{}; class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{}; class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{}; ==== NEW ==== way to define a TriMesh: // forward declarations class MyVertex; class MyEdge; class MyFace; // declaration of which types is used as VertexType, which type is used as FaceType and so on... class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType, vcg::Use<MyFace>::AsFaceType>{}; class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{}; class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{}; class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{}; ===== classes introduced [vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So <MyVertex, MyEdge, MyFace becomes <MyUsedTypes< and VertexSimp2 becomes Vertex [vcg::Use] : an auxiliary class to give a simple way to specify the role of a type Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g: class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType, vcg::Use<MyEdge>::AsEdgeType, vcg::Use<MyFace>::AsFaceType>{}; is the same as: class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType, vcg::Use<MyEdge>::AsEdgeType, vcg::Use<MyVertex>::AsVertexType>{}; Note 3: you only need to specify the type you use. If you do not have edges you do not need to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes. ==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType,
Use<MyFace>::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<MyVertex>, face::vector_ocf<MyFace> > {};
2005-12-02 01:46:12 +01:00
2005-09-21 12:29:33 +02:00
#define FLAT 0
#define LOOP 1
#define CATMULL 2
#define BUTTERFLY 3
#define ONE_QUAD_X_EDGE 4
2005-09-21 12:29:33 +02:00
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"
2005-09-21 12:29:33 +02:00
"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);
2005-09-21 12:29:33 +02:00
}
int RefMode = FLAT ;
int i=4; int n_steps; float length=0;
while(i<argc)
{
if(argv[i][0]!='-')
{printf("Error unable to parse option '%s'\n",argv[i]); exit(5);}
2005-09-21 12:29:33 +02:00
switch(argv[i][1])
{
case 'm' : RefMode=FLAT; break;
case 'b' : RefMode=BUTTERFLY; break;
case 'l' : RefMode=LOOP; break;
case 'c' : RefMode=CATMULL; break;
case 'o' : RefMode=ONE_QUAD_X_EDGE; break;
case 'e' : length=(float)atof(argv[i]+2); break;
2005-09-21 12:29:33 +02:00
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
}
++i;
}
MyMesh m;
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0) {
2005-09-21 12:29:33 +02:00
printf("Error reading file %s\n",argv[1]);
exit(1);
}
m.face.EnableFFAdjacency();
tri::UpdateTopology<MyMesh>::FaceFace(m);
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
tri::UpdateNormal<MyMesh>::PerVertexNormalized(m);
printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
2005-09-21 12:29:33 +02:00
n_steps=atoi(argv[3]);
for(i=0;i < n_steps;++i)
{
switch(RefMode)
{
case FLAT:
tri::Refine<MyMesh, tri::MidPoint<MyMesh> >(m,tri::MidPoint<MyMesh>(&m),length);
break;
case LOOP:
tri::RefineOddEven<MyMesh, tri::OddPointLoop<MyMesh>, tri::EvenPointLoop<MyMesh> >(m, tri::OddPointLoop<MyMesh>(m), tri::EvenPointLoop<MyMesh>(), length);
break;
case CATMULL:
tri::BitQuadCreation<MyMesh>::MakePureByCatmullClark(m);
tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
break;
case ONE_QUAD_X_EDGE:
tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
tri::UpdateNormal<MyMesh>::PerBitQuadFaceNormalized(m);
break;
case BUTTERFLY:
tri::Refine<MyMesh, tri::MidPointButterfly<MyMesh> >(m,tri::MidPointButterfly<MyMesh>(m),length);
break;
2005-09-21 12:29:33 +02:00
}
}
printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
2005-09-21 12:29:33 +02:00
vcg::tri::io::PlyInfo pi;
pi.mask|=vcg::tri::io::Mask::IOM_BITPOLYGONAL;
vcg::tri::io::Exporter<MyMesh>::Save(m,argv[2],pi.mask);
return 0;
}