trimesh_smooth.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00032 #include<vcg/complex/complex.h>
00033 #include <vcg/complex/algorithms/update/topology.h>
00034 #include <vcg/complex/algorithms/update/normal.h>
00035 
00036 #include<vcg/complex/algorithms/clean.h>
00037 #include<vcg/complex/algorithms/smooth.h>
00038 
00039 // input output
00040 #include <wrap/io_trimesh/import.h>
00041 #include <wrap/io_trimesh/export_ply.h>
00042 
00043 
00044 using namespace vcg;
00045 using namespace std;
00046 
00047 
00048 class MyFace;
00049 class MyVertex;
00050 
00051 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
00052 class MyVertex  : public Vertex< MyUsedTypes, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags  >{};
00053 class MyFace    : public Face  < MyUsedTypes, face::VFAdj, face::Normal3f, face::VertexRef, face::BitFlags > {};
00054 class MyMesh    : public vcg::tri::TriMesh<vector<MyVertex>, vector<MyFace> > {};
00055 
00056 int main(int argc,char ** argv)
00057 {
00058   if(argc<4)
00059   {
00060     printf("Usage: trimesh_smooth <filename> <steps> <sigma> <fitstep>\n");
00061     return 0;
00062   }
00063 
00064   int Step= atoi(argv[2]);
00065 
00066   MyMesh m;
00067 
00068   //open a mesh
00069   int err = tri::io::Importer<MyMesh>::Open(m,argv[1]);
00070   if(err) { // all the importers return 0 in case of success
00071     printf("Error in reading %s: '%s'\n",argv[1], tri::io::Importer<MyMesh>::ErrorMsg(err));
00072     exit(-1);
00073   }
00074 
00075   // some cleaning to get rid of bad file formats like stl that duplicate vertexes..
00076   int dup = tri::Clean<MyMesh>::RemoveDuplicateVertex(m);
00077   int unref = tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
00078   printf("Removed %i duplicate and %i unreferenced vertices from mesh %s\n",dup,unref,argv[1]);
00079 
00080   tri::UpdateTopology<MyMesh>::VertexFace(m);
00081 
00082   for(int i=0;i<Step;++i)
00083   {
00084     tri::UpdateNormal<MyMesh>::PerFaceNormalized(m);
00085     tri::Smooth<MyMesh>::VertexCoordPasoDoble(m,atoi(argv[3]),atof(argv[4]),atoi(argv[5]));
00086   }
00087 
00088   //LaplacianSmooth(m,atoi(argv[2]));
00089   tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply");
00090 
00091   return 0;
00092 }
00093 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:25