VCG Library
trimesh_voronoi_remesh.cpp
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2009 \/)\/ *
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 ****************************************************************************/
23 #include<vcg/complex/complex.h>
24 #include<wrap/io_trimesh/import.h>
25 #include<wrap/io_trimesh/export_ply.h>
26 #include <vcg/complex/algorithms/voronoi_remesher.h>
27 
28 using namespace vcg;
29 using namespace std;
30 
31 class MyVertex;
32 class MyFace;
33 class MyEdge;
34 
35 struct MyUsedTypes : public vcg::UsedTypes<
36  vcg::Use<MyVertex>::AsVertexType,
37  vcg::Use<MyFace>::AsFaceType,
38  vcg::Use<MyEdge>::AsEdgeType> {};
39 
40 class MyVertex: public vcg::Vertex<MyUsedTypes,
41  vcg::vertex::Coord3f, vcg::vertex::Normal3f,
42  vcg::vertex::Color4b, vcg::vertex::Qualityd,
43  vcg::vertex::VFAdj, vcg::vertex::VEAdj,
44  vcg::vertex::BitFlags, vcg::vertex::Mark> {};
45 class MyFace : public vcg::Face<MyUsedTypes,
46  vcg::face::VertexRef, vcg::face::Normal3f,
47  vcg::face::Color4b, vcg::face::BitFlags,
48  vcg::face::VFAdj, vcg::face::FFAdj,
49  vcg::face::Mark> {};
50 class MyEdge: public vcg::Edge<MyUsedTypes,
51  vcg::edge::VertexRef, vcg::edge::BitFlags,
52  vcg::edge::EEAdj, vcg::edge::VEAdj> {};
53 
54 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};
55 
56 int main( int argc, char **argv )
57 {
58  MyMesh startMesh;
59  if(argc < 2 )
60  {
61  printf("Usage trimesh_voro mesh region_num\n");
62  return -1;
63  }
64  printf("Reading %s \n",argv[1]);
65  int ret = tri::io::Importer<MyMesh>::Open(startMesh,argv[1]);
66  if(ret!=0)
67  {
68  printf("Unable to open %s: '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
69  return -1;
70  }
72 
73  float samplingRadius = startMesh.bbox.Diag() * 0.005f;
74  if (argc == 3)
75  {
76  try {
77  samplingRadius = stof(string(argv[2]));
78  } catch (exception &) {}
79  }
80  std::cout << "Remeshing using sampling radius: " << samplingRadius << std::endl;
81  auto remeshed = Remesher<MyMesh>::Remesh(startMesh, samplingRadius, 70.0);
82 
83 
84  tri::io::ExporterPLY<MyMesh>::Save(*remeshed,"Full.ply",tri::io::Mask::IOM_VERTCOLOR|tri::io::Mask::IOM_WEDGTEXCOORD );
85  return 0;
86 }