00001 #include <vector>
00002
00003 #include<vcg/simplex/vertex/base.h>
00004 #include<vcg/simplex/face/base.h>
00005 #include<vcg/simplex/face/topology.h>
00006
00007 #include<vcg/complex/trimesh/base.h>
00008
00009 #include <vcg/complex/trimesh/update/topology.h>
00010 #include <vcg/complex/trimesh/update/normal.h>
00011
00012 #include<vcg/complex/trimesh/clean.h>
00013 #include<vcg/complex/trimesh/smooth.h>
00014
00015
00016 #include <wrap/io_trimesh/import.h>
00017 #include <wrap/io_trimesh/export_ply.h>
00018
00019
00020 using namespace vcg;
00021 using namespace std;
00022
00023
00024 class MyFace;
00025 class MyVertex;
00026 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType,
00027 Use<MyFace>::AsFaceType>{};
00028
00029 class MyVertex : public Vertex< MyUsedTypes, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
00030 class MyFace : public Face < MyUsedTypes, face::VFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
00031 class MyMesh : public vcg::tri::TriMesh<vector<MyVertex>, vector<MyFace> > {};
00032
00033 int main(int argc,char ** argv)
00034 {
00035 if(argc<4)
00036 {
00037 printf("Usage: trimesh_smooth <filename> <steps> <sigma> <fitstep>\n");
00038 return 0;
00039 }
00040
00041 MyMesh m;
00042
00043
00044 int err = tri::io::Importer<MyMesh>::Open(m,argv[1]);
00045 if(err) {
00046 printf("Error in reading %s: '%s'\n",argv[1], tri::io::Importer<MyMesh>::ErrorMsg(err));
00047 exit(-1);
00048 }
00049
00050
00051 int dup = tri::Clean<MyMesh>::RemoveDuplicateVertex(m);
00052 int unref = tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
00053 printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]);
00054 int Step= atoi(argv[2]);
00055
00056 tri::UpdateTopology<MyMesh>::VertexFace(m);
00057
00058 for(int i=0;i<Step;++i)
00059 {
00060 tri::UpdateNormals<MyMesh>::PerFaceNormalized(m);
00061 tri::Smooth<MyMesh>::VertexCoordPasoDobleFast(m,atoi(argv[3]),atof(argv[4]),atoi(argv[5]));
00062 }
00063
00064
00065 tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply");
00066
00067 return 0;
00068 }
00069