glu_tessellator_cap.h
Go to the documentation of this file.
00001 #ifndef GLU_TESSELLATOR_CAP_H
00002 #define GLU_TESSELLATOR_CAP_H
00003 #include "glu_tesselator.h"
00004 #include <vcg/simplex/edge/pos.h>
00005 #include <vcg/complex/algorithms/clean.h>
00006 #include <vcg/complex/algorithms/update/bounding.h>
00007 
00008 namespace vcg {
00009 namespace tri {
00010 
00011 
00012 // This function take a mesh with one or more boundary stored as edges, and fill another mesh with a triangulation of that boundaries.
00013 // it assumes that boundary are planar and exploits glutessellator for the triangulaiton
00014 template <class MeshType>
00015 void CapEdgeMesh(MeshType &em, MeshType &cm, bool revertFlag=false)
00016 {
00017   typedef typename MeshType::EdgeType EdgeType;
00018   typedef typename MeshType::CoordType CoordType;
00019   std::vector< std::vector<CoordType> > outlines;
00020   std::vector<CoordType> outline;
00021   UpdateFlags<MeshType>::EdgeClearV(em);
00022   UpdateTopology<MeshType>::EdgeEdge(em);
00023   int nv=0;
00024   for(size_t i=0;i<em.edge.size();i++) if(!em.edge[i].IsD())
00025   {
00026     if (!em.edge[i].IsV())
00027     {
00028       edge::Pos<EdgeType> startE(&em.edge[i],0);
00029        edge::Pos<EdgeType> curE=startE;
00030       do
00031       {
00032         curE.E()->SetV();
00033         outline.push_back(curE.V()->P());
00034         curE.NextE();
00035         nv++;
00036       }
00037       while(curE != startE);
00038       if(revertFlag) std::reverse(outline.begin(),outline.end());
00039       outlines.push_back(outline);
00040       outline.clear();
00041     }
00042   }
00043   if (nv<2) return;
00044 //  printf("Found %i outlines for a total of %i vertices",outlines.size(),nv);
00045 
00046   typename MeshType::VertexIterator vi=vcg::tri::Allocator<MeshType>::AddVertices(cm,nv);
00047   for (size_t i=0;i<outlines.size();i++)
00048   {
00049     for(size_t j=0;j<outlines[i].size();++j,++vi)
00050       (&*vi)->P()=outlines[i][j];
00051   }
00052 
00053   std::vector<int> indices;
00054   glu_tesselator::tesselate(outlines, indices);
00055   std::vector<CoordType> points;
00056   glu_tesselator::unroll(outlines, points);
00057   //typename MeshType::FaceIterator fi=tri::Allocator<MeshType>::AddFaces(cm,nv-2);
00058   typename MeshType::FaceIterator fi=tri::Allocator<MeshType>::AddFaces(cm,indices.size()/3);
00059   for (size_t i=0; i<indices.size(); i+=3,++fi)
00060   {
00061     (*&fi)->V(0)=&cm.vert[ indices[i+0] ];
00062     (*&fi)->V(1)=&cm.vert[ indices[i+1] ];
00063     (*&fi)->V(2)=&cm.vert[ indices[i+2] ];
00064   }
00065   Clean<MeshType>::RemoveDuplicateVertex(cm);
00066   UpdateBounding<MeshType>::Box(cm);
00067 }
00068 
00069 } // end namespace tri
00070 } // end namespace vcg
00071 
00072 #endif // GLU_TESSELLATOR_CAP_H


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