vcglib/apps/sample/trimesh_smooth/trimesh_smooth.cpp

70 lines
2.0 KiB
C++
Raw Normal View History

2005-09-21 12:29:33 +02:00
#include <vector>
#include<vcg/simplex/vertex/base.h>
#include<vcg/simplex/face/base.h>
#include<vcg/simplex/face/topology.h>
2005-09-21 12:29:33 +02:00
#include<vcg/complex/trimesh/base.h>
#include <vcg/complex/trimesh/update/topology.h>
#include <vcg/complex/trimesh/update/normal.h>
2005-09-21 12:29:33 +02:00
// to clean up a mesh
#include<vcg/complex/trimesh/clean.h>
#include<vcg/complex/trimesh/smooth.h>
// input output
#include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export_ply.h>
using namespace vcg;
using namespace std;
2005-09-21 12:29:33 +02:00
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>{};
2005-09-21 12:29:33 +02:00
[ 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
class MyVertex : public Vertex< MyUsedTypes, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
class MyFace : public Face < MyUsedTypes, face::VFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
class MyMesh : public vcg::tri::TriMesh<vector<MyVertex>, vector<MyFace> > {};
2005-09-21 12:29:33 +02:00
int main(int argc,char ** argv)
{
if(argc<4)
2005-09-21 12:29:33 +02:00
{
printf("Usage: trimesh_smooth <filename> <steps> <sigma> <fitstep>\n");
2005-09-21 12:29:33 +02:00
return 0;
}
MyMesh m;
//open a mesh
int err = tri::io::Importer<MyMesh>::Open(m,argv[1]);
if(err) { // all the importers return 0 in case of success
printf("Error in reading %s: '%s'\n",argv[1], tri::io::Importer<MyMesh>::ErrorMsg(err));
2005-09-21 12:29:33 +02:00
exit(-1);
}
2005-09-21 12:29:33 +02:00
// some cleaning to get rid of bad file formats like stl that duplicate vertexes..
int dup = tri::Clean<MyMesh>::RemoveDuplicateVertex(m);
int unref = tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]);
int Step= atoi(argv[2]);
tri::UpdateTopology<MyMesh>::VertexFace(m);
for(int i=0;i<Step;++i)
{
tri::UpdateNormals<MyMesh>::PerFaceNormalized(m);
2008-09-29 12:11:21 +02:00
tri::Smooth<MyMesh>::VertexCoordPasoDobleFast(m,atoi(argv[3]),atof(argv[4]),atoi(argv[5]));
}
2005-09-21 12:29:33 +02:00
//LaplacianSmooth(m,atoi(argv[2]));
2005-09-21 12:29:33 +02:00
tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply");
return 0;
}