From 2239cbd7470abfb3840008a97927a912438b9da6 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 11 May 2011 10:04:33 +0000 Subject: [PATCH] added simple boundary capper. Takes a edge mesh and caps its boundaries. --- wrap/gl/glu_tessellator_cap.h | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 wrap/gl/glu_tessellator_cap.h diff --git a/wrap/gl/glu_tessellator_cap.h b/wrap/gl/glu_tessellator_cap.h new file mode 100644 index 00000000..3675e377 --- /dev/null +++ b/wrap/gl/glu_tessellator_cap.h @@ -0,0 +1,72 @@ +#ifndef GLU_TESSELLATOR_CAP_H +#define GLU_TESSELLATOR_CAP_H +#include "glu_tesselator.h" + +namespace vcg { +namespace tri { + +// This function take a mesh with one or more boundary stored as edges, and fill another mesh with a triangulation of that boundaries. +// it assumes that boundary are planar and exploits glutessellator for the triangulaiton +template +void CapEdgeMesh(MeshType &em, MeshType &cm) +{ + typedef typename MeshType::EdgeType EdgeType; + std::vector< std::vector > outlines; + std::vector outline; + UpdateFlags::EdgeClearV(em); + UpdateTopology::EdgeEdge(em); + int nv=0; + for(size_t i=0;iSetV(); + outline.push_back(curE->V(curI)->P()); + nextE=curE->EEp((curI+1)%2); + nextI=curE->EEi((curI+1)%2); + curE=nextE; + curI=nextI; + nv++; + } + while(curE != startE); + + outlines.push_back(outline); + outline.clear(); + } + } + if (nv<2) return; +// printf("Found %i outlines for a total of %i vertices",outlines.size(),nv); + + typename MeshType::VertexIterator vi=vcg::tri::Allocator::AddVertices(cm,nv); + for (size_t i=0;iP()=outlines[i][j]; + } + + std::vector indices; + glu_tesselator::tesselate(outlines, indices); + std::vector points; + glu_tesselator::unroll(outlines, points); + typename MeshType::FaceIterator fi=tri::Allocator::AddFaces(cm,nv-2); + for (size_t i=0; iV(0)=&cm.vert[ indices[i+0] ]; + (*&fi)->V(1)=&cm.vert[ indices[i+1] ]; + (*&fi)->V(2)=&cm.vert[ indices[i+2] ]; + } + Clean::RemoveDuplicateVertex(cm); + UpdateBounding::Box(cm); +} + +} // end namespace tri +} // end namespace vcg + +#endif // GLU_TESSELLATOR_CAP_H