// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2015 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "polyhedron_to_mesh.h" #include template < typename Polyhedron, typename DerivedV, typename DerivedF> IGL_INLINE void igl::copyleft::cgal::polyhedron_to_mesh( const Polyhedron & poly, Eigen::PlainObjectBase & V, Eigen::PlainObjectBase & F) { using namespace std; V.resize(poly.size_of_vertices(),3); F.resize(poly.size_of_facets(),3); typedef typename Polyhedron::Vertex_const_iterator Vertex_iterator; std::map vertex_to_index; { size_t v = 0; for( typename Polyhedron::Vertex_const_iterator p = poly.vertices_begin(); p != poly.vertices_end(); p++) { V(v,0) = p->point().x(); V(v,1) = p->point().y(); V(v,2) = p->point().z(); vertex_to_index[p] = v; v++; } } { size_t f = 0; for( typename Polyhedron::Facet_const_iterator facet = poly.facets_begin(); facet != poly.facets_end(); ++facet) { typename Polyhedron::Halfedge_around_facet_const_circulator he = facet->facet_begin(); // Facets in polyhedral surfaces are at least triangles. assert(CGAL::circulator_size(he) == 3 && "Facets should be triangles"); size_t c = 0; do { //// This is stooopidly slow // F(f,c) = std::distance(poly.vertices_begin(), he->vertex()); F(f,c) = vertex_to_index[he->vertex()]; c++; } while ( ++he != facet->facet_begin()); f++; } } } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation #include #include #include template void igl::copyleft::cgal::polyhedron_to_mesh >, Eigen::Matrix, Eigen::Matrix >(CGAL::Polyhedron_3 > const&, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::copyleft::cgal::polyhedron_to_mesh,CGAL::Polyhedron_items_with_id_3, CGAL::HalfedgeDS_default, std::allocator >, Eigen::Matrix, Eigen::Matrix >(CGAL::Polyhedron_3,CGAL::Polyhedron_items_with_id_3, CGAL::HalfedgeDS_default, std::allocator > const&,Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); #endif