VCG Library
trimesh_implicit_smooth.cpp
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 ****************************************************************************/
33 #include<vcg/complex/complex.h>
34 
35 #include<wrap/io_trimesh/import_ply.h>
36 #include<wrap/io_trimesh/export_ply.h>
37 
38 #include<vcg/complex/algorithms/implicit_smooth.h>
39 
40 using namespace vcg;
41 using namespace std;
42 
43 class MyEdge;
44 class MyFace;
45 class MyVertex;
46 struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
47  vcg::Use<MyEdge> ::AsEdgeType,
48  vcg::Use<MyFace> ::AsFaceType>{};
49 
50 class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
51 class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::BitFlags > {};
52 class MyEdge : public vcg::Edge<MyUsedTypes>{};
53 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
54 
55 
56 int main( int argc, char **argv )
57 {
58  MyMesh m;
59  if(argc < 2 )
60  {
61  printf("Usage: trimesh_implicit_smooth mesh.ply\n");
62  return -1;
63  }
64 
65  int ret= tri::io::ImporterPLY<MyMesh>::Open(m,argv[1]);
66  if(ret!=0)
67  {
68  printf("Unable to open %s for '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
69  return -1;
70  }
71 
73 
74  ImplicitSmoother<MyMesh>::Parameter par;
75  par.lambda = 0.5f;
76  ImplicitSmoother<MyMesh>::Compute(m,par);
77 
78  tri::io::ExporterPLY<MyMesh>::Save(m,"smooth.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
79 
80  return 0;
81 }