VCG Library
trimesh_topology.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 
24 #include<vcg/complex/complex.h>
25 #include<vcg/complex/algorithms/create/platonic.h>
26 
27 using namespace vcg;
28 
29 class MyEdge;
30 class MyFace;
31 class MyVertex;
32 struct MyUsedTypes : public UsedTypes< Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
33 
34 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags >{};
35 class MyFace : public Face < MyUsedTypes, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags > {};
36 class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
37 
38 
39 int main(int ,char ** )
40 {
41  MyMesh m;
42 
43  //generate a mesh
44  vcg::tri::Icosahedron(m);
45 
46  //update the face-face topology
48 
49  // Now for each face the FFp() FFi() members are correctly initialized
50 
51  if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n");
52  else printf("Edge 0 of face 0 is NOT a border\n"); // always this path!
53 
54  vcg::face::FFDetach<MyFace>(m.face[0],0); // Detach the face [0] from the mesh
55  vcg::face::FFDetach<MyFace>(m.face[0],1);
56  vcg::face::FFDetach<MyFace>(m.face[0],2);
57 
58  if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n"); // always this path!
59  else printf("Edge 0 of face 0 is NOT a border\n");
60 
62 
63  // declare an iterator on the mesh
64  vcg::face::Pos<MyMesh::FaceType> he, hei;
65 
66  UnMarkAll(m);
67 
68  // Now a simple search and trace of all the borders of the mesh
69  int BorderEdgeNum=0;
70  int HoleNum=0;
71  for(MyMesh::FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
72  {
73  for(int j=0;j<3;j++)
74  {
75  if ( face::IsBorder(*fi,j) && !tri::IsMarked(m,&*fi))
76  {
77  tri::Mark(m,&*fi);
78  hei.Set(&*fi,j,fi->V(j));
79  he=hei;
80  do
81  {
82  BorderEdgeNum++;
83  he.NextB(); // next pos along a border
84  tri::Mark(m,he.f);
85  }
86  while (he.f!=hei.f);
87  HoleNum++;
88  }
89  }
90  }
91 
92  printf("Mesh has %i holes and %i border edges\n",HoleNum,BorderEdgeNum);
93  return 0;
94 }
95