VCG Library
trimesh_smooth.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
32 #include<vcg/complex/complex.h>
33 
34 #include<vcg/complex/algorithms/clean.h>
35 #include<vcg/complex/algorithms/smooth.h>
36 
37 #include <wrap/io_trimesh/import.h>
38 #include <wrap/io_trimesh/export_ply.h>
39 
40 
41 using namespace vcg;
42 using namespace std;
43 
44 
45 class MyFace;
46 class MyVertex;
47 
48 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
49 class MyVertex : public Vertex< MyUsedTypes, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
50 class MyFace : public Face < MyUsedTypes, face::VFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
51 class MyMesh : public vcg::tri::TriMesh<vector<MyVertex>, vector<MyFace> > {};
52 
53 int main(int argc,char ** argv)
54 {
55  if(argc<4)
56  {
57  printf("Usage: trimesh_smooth <filename> <steps> <sigma> <fitstep>\n");
58  return 0;
59  }
60 
61  int Step= atoi(argv[2]);
62 
63  MyMesh m;
64 
65  //open a mesh
66  int err = tri::io::Importer<MyMesh>::Open(m,argv[1]);
67  if(err) { // all the importers return 0 in case of success
68  printf("Error in reading %s: '%s'\n",argv[1], tri::io::Importer<MyMesh>::ErrorMsg(err));
69  exit(-1);
70  }
71 
72  // some cleaning to get rid of bad file formats like stl that duplicate vertexes..
75  printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]);
76 
78 
79  for(int i=0;i<Step;++i)
80  {
82  tri::Smooth<MyMesh>::VertexCoordPasoDoble(m,atoi(argv[3]),atof(argv[4]),atoi(argv[5]));
83  }
84 
85  //LaplacianSmooth(m,atoi(argv[2]));
86  tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply");
87 
88  return 0;
89 }
90