VCG Library
trimesh_geodesic.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 ****************************************************************************/
23 #include<vcg/complex/complex.h>
24 
25 #include<wrap/io_trimesh/import_ply.h>
26 #include<wrap/io_trimesh/export_ply.h>
27 
28 #include<vcg/complex/algorithms/point_sampling.h>
29 #include<vcg/complex/algorithms/geodesic.h>
30 #include<vcg/complex/algorithms/update/color.h>
31 
32 using namespace vcg;
33 using namespace std;
34 
35 class MyEdge;
36 class MyFace;
37 class MyVertex;
38 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
39  Use<MyEdge> ::AsEdgeType,
40  Use<MyFace> ::AsFaceType>{};
41 
42 class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Mark, vertex::VFAdj, vertex::Color4b, vertex::Qualityf, vertex::BitFlags >{};
43 class MyFace : public Face< MyUsedTypes, face::VFAdj, face::VertexRef, face::Normal3f, face::BitFlags > {};
44 class MyEdge : public Edge<MyUsedTypes>{};
45 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
46 
47 int main( int argc, char **argv )
48 {
49  if(argc<2)
50  {
51  printf("Usage trimesh_geodesic <meshfilename.obj>\n");
52 // return -1;
53  }
54 
55  MyMesh m;
56 
57 // if(tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/disk_irregular_1k.ply")!=0)
58  if(tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/disk_irregular_650k.ply")!=0)
59  {
60  printf("Error reading file %s\n",argv[1]);
61  exit(0);
62  }
63 
64  Point3f c=m.bbox.Center();
65  MyVertex*closest=&*m.vert.begin();
66  float minDist = Distance(closest->P(),c);
67  for(MyMesh::VertexIterator vi=m.vert.begin();vi!=m.vert.end(); ++vi)
68  {
69  if(Distance(vi->P(),c)<minDist)
70  {
71  minDist = Distance(vi->P(),c);
72  closest = &*vi;
73  }
74  }
75  vector<MyVertex*> seedVec;
76  seedVec.push_back(closest);
77  tri::EuclideanDistance<MyMesh> ed;
81  tri::Geodesic<MyMesh>::Compute(m,seedVec,ed);
82  pair<float,float> minmax = tri::Stat<MyMesh>::ComputePerVertexQualityMinMax(m);
84  printf("min %f max %f\n",minmax.first,minmax.second);
85  tri::io::ExporterPLY<MyMesh>::Save(m,"base.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
86  int t0=clock();
88  int t1=clock();
89  printf("Geodesic dijkstra %6.3f\n",float(t1-t0)/CLOCKS_PER_SEC);
91  tri::io::ExporterPLY<MyMesh>::Save(m,"base_d.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
92 
93  return 0;
94 }