VCG Library
trimesh_texture_clean.cpp
Go to the documentation of this file.
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/export_obj.h>
26 #include <vcg/complex/algorithms/update/texture.h>
27 #include <vcg/complex/algorithms/create/platonic.h>
28 
36 using namespace vcg;
37 
38 class MyEdge;
39 class MyFace;
40 class MyVertex;
41 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
42 
43 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::VFAdj, vertex::Normal3f, vertex::BitFlags >{};
44 class MyFace : public Face < MyUsedTypes, face::VertexRef, face::VFAdj, face::WedgeTexCoord2f, face::Mark, face::BitFlags > {};
45 class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
46 
47 
48 int main(int ,char ** )
49 {
50  MyMesh m;
51  int mask = tri::io::Mask::IOM_WEDGTEXCOORD;
52 
53  // generate a simple 2D grid
54  Grid(m,20,20,1,1);
55  // assign it a simple planar parametrization
56  tri:UpdateTexture<MyMesh>::WedgeTexFromPlane(m,Point3f(1.0f,0,0),Point3f(0,1.0f,0),true);
57  tri::io::ExporterOBJ<MyMesh>::Save(m,"grid_0.obj",mask);
58 
59  // randomly perturb a few coord textures introducing fake seams
60  for(MyFace &f : m.face)
61  {
62  for(int i=0;i<3;++i)
63  if(rand()%20==0)
64  {
65  f.WT(i).U()+=0.0000001;
66  f.WT(i).V()-=0.0000001;
67  }
68  }
69  tri::io::ExporterOBJ<MyMesh>::Save(m,"grid_1.obj",mask);
70 
71  // Merge texture coords that very close
74 
75  tri::io::ExporterOBJ<MyMesh>::Save(m,"grid_2.obj",mask);
76 
77  return 0;
78 }
79