VCG Library
trimesh_remeshing.cpp
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2012 \/)\/ *
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 ****************************************************************************/
29 #include<vcg/complex/complex.h>
30 
31 #include<wrap/io_trimesh/import.h>
32 #include<wrap/io_trimesh/export.h>
33 
34 #include<vcg/complex/algorithms/clean.h>
35 #include<vcg/complex/algorithms/isotropic_remeshing.h>
36 
37 using namespace vcg;
38 using namespace std;
39 
40 class MyEdge;
41 class MyFace;
42 class MyVertex;
43 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
44  Use<MyEdge> ::AsEdgeType,
45  Use<MyFace> ::AsFaceType>{};
46 
47 class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::VFAdj, vertex::Qualityf, vertex::BitFlags >{};
48 class MyFace : public Face< MyUsedTypes, face::Mark, face::VertexRef, face::VFAdj, face::FFAdj, face::Normal3f, face::BitFlags > {};
49 class MyEdge : public Edge<MyUsedTypes>{};
50 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
51 
52 int main( int argc, char **argv )
53 {
54  MyMesh original,toremesh;
55  if(argc<2)
56  {
57  printf("Usage: trimesh_remesh <filename> [targetLen [iterNum] ]");
58  exit(0);
59  }
60 
61  if(tri::io::Importer<MyMesh>::Open(original,argv[1])!=0)
62  {
63  printf("Error reading file %s\n",argv[1]);
64  exit(0);
65  }
66  float targetLenPerc=.2f;
67  int iterNum=20;
68  if(argc>=3) targetLenPerc = atof(argv[2]);
69  if(argc>=4) iterNum = atoi(argv[3]);
70 
71  // Mesh cleaning
74  Allocator<MyMesh>::CompactEveryVector(original);
77 
81 
83  tri::MeshAssert<MyMesh>::FFTwoManifoldEdge(toremesh);
84  float lengthThr = targetLenPerc*(original.bbox.Diag()/100.f);
85  printf("Length Thr: %8.3f ~ %4.2f %% on %5.3f\n",lengthThr,targetLenPerc,original.bbox.Diag());
86 
87  IsotropicRemeshing<MyMesh>::Params params;
88  params.SetTargetLen(lengthThr);
89  params.SetFeatureAngleDeg(10);
90  params.iter=iterNum;
91  printf(" Input mesh %8i v %8i f\n",toremesh.VN(),toremesh.FN());
92  IsotropicRemeshing<MyMesh>::Do(toremesh, original, params);
93  vcg::tri::io::ExporterPLY<MyMesh>::Save(toremesh, "remesh.ply");
94  printf("Output mesh %8i v %8i f\n",toremesh.VN(),toremesh.FN());
95 
96  return 0;
97 }