2005-09-21 12:29:33 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2008-12-19 11:43:36 +01:00
|
|
|
#include<vcg/simplex/vertex/base.h>
|
|
|
|
#include<vcg/simplex/face/base.h>
|
2006-09-25 11:41:41 +02:00
|
|
|
#include<vcg/simplex/face/topology.h>
|
|
|
|
|
2005-09-21 12:29:33 +02:00
|
|
|
#include<vcg/complex/trimesh/base.h>
|
2006-09-25 11:41:41 +02:00
|
|
|
|
|
|
|
#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;
|
2006-09-25 11:41:41 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2006-09-25 11:41:41 +02:00
|
|
|
class MyEdge; // dummy prototype never used
|
2005-09-21 12:29:33 +02:00
|
|
|
class MyFace;
|
2006-09-25 11:41:41 +02:00
|
|
|
class MyVertex;
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2008-09-30 13:37:41 +02:00
|
|
|
class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
|
2006-09-25 11:41:41 +02:00
|
|
|
class MyFace : public FaceSimp2 < MyVertex, MyEdge, MyFace, 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)
|
|
|
|
{
|
2006-10-13 15:17:23 +02:00
|
|
|
if(argc<4)
|
2005-09-21 12:29:33 +02:00
|
|
|
{
|
2006-09-25 11:41:41 +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]);
|
2006-10-13 15:17:23 +02:00
|
|
|
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);
|
|
|
|
}
|
2006-10-13 15:17:23 +02:00
|
|
|
|
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]);
|
2006-09-25 11:41:41 +02:00
|
|
|
int Step= atoi(argv[2]);
|
2006-10-13 15:17:23 +02:00
|
|
|
|
2006-09-25 11:41:41 +02:00
|
|
|
tri::UpdateTopology<MyMesh>::VertexFace(m);
|
2006-10-13 15:17:23 +02:00
|
|
|
|
2006-09-25 11:41:41 +02:00
|
|
|
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]));
|
2006-09-25 11:41:41 +02:00
|
|
|
}
|
2005-09-21 12:29:33 +02:00
|
|
|
|
2006-09-25 11:41:41 +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;
|
|
|
|
}
|
|
|
|
|