VCG Library
trimesh_voronoiatlas.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<vcg/complex/algorithms/create/platonic.h>
25 
26 #include<wrap/io_trimesh/import_ply.h>
27 #include<wrap/io_trimesh/export_ply.h>
28 #include<vcg/complex/algorithms/parametrization/voronoi_atlas.h>
29 #include<vcg/space/outline2_packer.h>
30 
31 using namespace vcg;
32 using namespace std;
33 
34 class MyEdge;
35 class MyFace;
36 class MyVertex;
37 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
38  Use<MyEdge> ::AsEdgeType,
39  Use<MyFace> ::AsFaceType>{};
40 
41 class MyVertex : public Vertex<MyUsedTypes, vertex::InfoOcf, vertex::Coord3f, vertex::Normal3f, vertex::TexCoord2f, vertex::VFAdj , vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
42 class MyFace : public Face< MyUsedTypes, face::InfoOcf, face::VertexRef, face::CurvatureDirf, face::BitFlags, face::FFAdjOcf ,face::VFAdj , face::WedgeTexCoord2f> {};
43 class MyEdge : public Edge< MyUsedTypes>{};
44 class MyMesh : public tri::TriMesh< vertex::vector_ocf<MyVertex>, face::vector_ocf<MyFace> , vector<MyEdge> > {};
45 
46 
47 
48 int main( int argc, char **argv )
49 {
50  MyMesh startMesh;
51  if(argc < 3 )
52  {
53  printf("Usage trimesh_voro mesh region_num\n");
54  return -1;
55  }
56  int sampleNum =atoi(argv[2]);
57  printf("Reading %s and sampling %i \n",argv[1],sampleNum);
58  int ret= tri::io::ImporterPLY<MyMesh>::Open(startMesh,argv[1]);
59  if(ret!=0)
60  {
61  printf("Unable to open %s for '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
62  return -1;
63  }
64 
65  MyMesh paraMesh;
66  tri::VoronoiAtlas<MyMesh>::VoronoiAtlasParam pp;
67  pp.sampleNum =sampleNum;
68  pp.overlap=false;
69 
70  tri::VoronoiAtlas<MyMesh>::Build(startMesh,paraMesh,pp);
71 
72  tri::io::ExporterPLY<MyMesh>::Save(paraMesh,"Full.ply",tri::io::Mask::IOM_VERTCOLOR|tri::io::Mask::IOM_WEDGTEXCOORD );
73  return 0;
74 }