trimesh_topology.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 
00024 #include<vcg/complex/complex.h>
00025 #include<vcg/complex/algorithms/create/platonic.h>
00026 
00027 #include<vcg/complex/algorithms/update/topology.h>
00028 
00029 #include<vcg/simplex/face/pos.h>
00030 
00031 using namespace vcg;
00032 
00033 class MyEdge;
00034 class MyFace;
00035 class MyVertex;
00036 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType>{};
00037 
00038 class MyVertex  : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags  >{};
00039 class MyFace    : public Face  < MyUsedTypes, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags > {};
00040 class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
00041 
00042 
00043 int main(int ,char ** )
00044 {
00045   MyMesh m;
00046 
00047   //generate a mesh
00048   vcg::tri::Icosahedron(m);
00049 
00050   //update the face-face topology
00051   vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
00052 
00053   // Now for each face the FFp() FFi() members are correctly initialized 
00054 
00055   if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n");
00056   else printf("Edge 0 of face 0 is NOT a border\n"); // always this path!
00057 
00058   vcg::face::FFDetach<MyFace>(m.face[0],0);  // Detach the face [0] from the mesh
00059   vcg::face::FFDetach<MyFace>(m.face[0],1);
00060   vcg::face::FFDetach<MyFace>(m.face[0],2);
00061 
00062   if(face::IsBorder(m.face[0],0)) printf("Edge 0 of face 0 is a border\n"); // always this path!
00063   else printf("Edge 0 of face 0 is NOT a border\n");
00064 
00065   tri::Allocator<MyMesh>::DeleteFace(m,m.face[0]);
00066 
00067   // declare an iterator on the mesh
00068   vcg::face::Pos<MyMesh::FaceType> he, hei;
00069 
00070   UnMarkAll(m);
00071 
00072   // Now a simple search and trace of all the borders of the mesh
00073   int BorderEdgeNum=0;
00074   int HoleNum=0;
00075   for(MyMesh::FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
00076   {
00077     for(int j=0;j<3;j++)
00078     {
00079       if ( face::IsBorder(*fi,j) && !tri::IsMarked(m,&*fi))
00080       {
00081         tri::Mark(m,&*fi);
00082         hei.Set(&*fi,j,fi->V(j));
00083         he=hei;
00084         do
00085         {
00086           BorderEdgeNum++;
00087           he.NextB(); // next pos along a border
00088           tri::Mark(m,he.f);
00089         }
00090         while (he.f!=hei.f);
00091         HoleNum++;
00092       }
00093     }
00094   }
00095 
00096   printf("Mesh has %i holes and %i border edges\n",HoleNum,BorderEdgeNum);
00097   return 0;
00098 }
00099 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:26