cleaned up and added all the refinement strategies including catmull clark (that now crash...)

This commit is contained in:
Paolo Cignoni 2010-04-27 14:59:12 +00:00
parent aa04a96264
commit 493553c5f1
2 changed files with 42 additions and 22 deletions

View File

@ -1,8 +1,6 @@
// mesh definition
#include<vcg/simplex/vertex/base.h>
#include<vcg/simplex/face/base.h>
#include<vcg/simplex/face/component_ocf.h>
#include<vcg/simplex/face/topology.h>
#include<vcg/complex/trimesh/base.h>
@ -11,6 +9,9 @@
#include <vcg/complex/trimesh/update/normal.h>
#include <vcg/complex/trimesh/update/flag.h>
#include <vcg/complex/trimesh/refine.h>
#include <vcg/complex/trimesh/refine_loop.h>
#include <vcg/complex/trimesh/bitquad_creation.h>
// input output
#include <wrap/io_trimesh/import_ply.h>
@ -22,11 +23,6 @@
using namespace vcg;
using namespace std;
//struct MyFace;
//struct MyEdge;
//struct MyVertex: public VertexVN<float,MyEdge,MyFace>{};
//struct MyFace: public FaceAF<MyVertex,MyEdge,MyFace>{};
//struct MyMesh: public tri::TriMesh< vector<MyVertex>, vector<MyFace> >{};
class MyEdge; // dummy prototype never used
class MyFace;
@ -36,13 +32,15 @@ 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::FFAdj, face::VertexRef, face::BitFlags > {};
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
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> > {};
#define FLAT 0
#define BUTTERFLY 2
#define LOOP 1
#define CATMULL 2
#define BUTTERFLY 3
int main(int argc, char **argv)
{
@ -55,8 +53,10 @@ int main(int argc, char **argv)
"Commands: \n"
" Refinement rules:\n"
" -m use simple midpoint subdivision (default) \n"
" -b use butterfly subdivision scheme \n"
" -l# refine only if the the edge is longer than #(default 0.0)\n"
" -b use butterfly subdivision scheme \n"
" -l use butterfly subdivision scheme \n"
" -c use butterfly subdivision scheme \n"
" -e# refine only if the the edge is longer than #(default 0.0)\n"
);
exit(0);
}
@ -71,30 +71,48 @@ int main(int argc, char **argv)
{
case 'm' : RefMode=FLAT; break;
case 'b' : RefMode=BUTTERFLY; break;
case 'l' : length=(float)atof(argv[i]+2); break;
case 'l' : RefMode=LOOP; break;
case 'c' : RefMode=CATMULL; break;
case 'e' : length=(float)atof(argv[i]+2); break;
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
}
++i;
}
MyMesh m;
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
{
printf("Error reading file %s\n",argv[1]);
exit(0);
}
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
vcg::tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
vcg::tri::UpdateNormals<MyMesh>::PerVertexNormalized(m);
m.face.EnableFFAdjacency();
tri::UpdateTopology<MyMesh>::FaceFace(m);
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
tri::UpdateNormals<MyMesh>::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: Refine<MyMesh, MidPoint<MyMesh> >(m,MidPoint<MyMesh>(&m),length); break;
case BUTTERFLY: Refine<MyMesh, MidPointButterfly<MyMesh> >(m,MidPointButterfly<MyMesh>(),length); break;
switch(RefMode)
{
case FLAT:
Refine<MyMesh, MidPoint<MyMesh> >(m,MidPoint<MyMesh>(&m),length);
break;
case LOOP:
tri::RefineOddEven<MyMesh, tri::OddPointLoop<MyMesh>, tri::EvenPointLoop<MyMesh> >(m, tri::OddPointLoop<MyMesh>(), tri::EvenPointLoop<MyMesh>(), length);
break;
case CATMULL:
tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
assert(tri::BitQuadCreation<MyMesh>::IsBitTriQuadConventional(m));
tri::UpdateTopology<MyMesh>::FaceFace(m);
tri::BitQuadCreation<MyMesh>::MakePureByRefine(m);
tri::UpdateNormals<MyMesh>::PerBitQuadFaceNormalized(m);
break;
case BUTTERFLY:
Refine<MyMesh, MidPointButterfly<MyMesh> >(m,MidPointButterfly<MyMesh>(),length);
break;
}
}

View File

@ -10,4 +10,6 @@ DEPENDPATH += .
INCLUDEPATH += . ../../..
CONFIG += console stl
TEMPLATE = app
SOURCES += trimesh_refine.cpp ../../../wrap/ply/plylib.cpp
SOURCES += trimesh_refine.cpp ../../../wrap/ply/plylib.cpp
# Mac specific Config required to avoid to make application bundles
CONFIG -= app_bundle