diff --git a/vcg/complex/algorithms/create/extrude.h b/vcg/complex/algorithms/create/extrude.h new file mode 100644 index 00000000..3a60580e --- /dev/null +++ b/vcg/complex/algorithms/create/extrude.h @@ -0,0 +1,75 @@ +#ifndef EXTRUDE_H +#define EXTRUDE_H + +namespace vcg { +namespace tri { + + +template class Extrude +{ + public: + typedef typename MeshType::FacePointer FacePointer; + typedef typename MeshType::EdgePointer EdgePointer; + typedef typename MeshType::VertexPointer VertexPointer; + typedef typename MeshType::FaceType FaceType; + typedef typename MeshType::EdgeType EdgeType; + typedef typename MeshType::VertexIterator VertexIterator; + typedef typename MeshType::EdgeIterator EdgeIterator; + typedef typename MeshType::FaceIterator FaceIterator; + +static void ProfileWithCap(MeshType &profile, MeshType &surface, const vcg::Similarityf &sim ) +{ + surface.Clear(); + + for(VertexIterator vi=profile.vert.begin();vi!=profile.vert.end();++vi) + { + VertexIterator vp=tri::Allocator::AddVertices(surface,2); + vp->P()=vi->P(); + ++vp; + vp->P()= sim*vi->P() ; + } + + for(EdgeIterator ei=profile.edge.begin();ei!=profile.edge.end();++ei) + { + int i0=tri::Index(profile,ei->V(0)); + int i1=tri::Index(profile,ei->V(1)); + + FaceIterator fp= tri::Allocator::AddFaces(surface,2); + fp->V(0) = &surface.vert[i0*2]; + fp->V(1) = &surface.vert[i1*2]; + fp->V(2) = &surface.vert[i0*2+1]; + ++fp; + fp->V(0) = &surface.vert[i1*2+1]; + fp->V(1) = &surface.vert[i0*2+1]; + fp->V(2) = &surface.vert[i1*2]; + } + + MeshType cap1; + + tri::CapEdgeMesh(profile,cap1); + if(cap1.fn==0) CapEdgeMesh(profile,cap1,true); + tri::Append::Mesh(surface,cap1); + + for(VertexIterator vi=cap1.vert.begin();vi!=cap1.vert.end();++vi) + vi->P() = sim*vi->P(); + tri::Append::Mesh(surface,cap1); + + tri::Clean::RemoveDuplicateVertex(surface); + bool oriented,orientable; + tri::UpdateTopology::FaceFace(surface); + tri::Clean::OrientCoherentlyMesh(surface,oriented,orientable); +} + +static void ProfileWithCap(MeshType &profile, MeshType &surface, const Point3f offset) +{ + Similarityf tra; + tra.SetTranslate(offset); + ProfileWithCap(profile,surface,tra); +} + +}; // end class + +} // end namespace tri +} // end namespace vcg + +#endif // EXTRUDE_H