Procházet zdrojové kódy

missing files

Former-commit-id: 95a56ac8a8c193de06fe0b46e0a162cbbc0c35b3
Alec Jacobson před 10 roky
rodič
revize
42dd3e59e6

+ 57 - 0
include/igl/cgal/polyhedron_to_mesh.cpp

@@ -0,0 +1,57 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// 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 <CGAL/Polyhedron_3.h>
+
+template <typename Polyhedron>
+IGL_INLINE void igl::polyhedron_to_mesh(
+  const Polyhedron & poly,
+  Eigen::MatrixXd & V,
+  Eigen::MatrixXi & 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_iterator,size_t> 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++;
+    }
+  }
+}

+ 34 - 0
include/igl/cgal/polyhedron_to_mesh.h

@@ -0,0 +1,34 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// 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/.
+#ifndef IGL_POLYHEDRON_TO_MESH_H
+#define IGL_POLYHEDRON_TO_MESH_H
+#include <igl/igl_inline.h>
+#include <Eigen/Core>
+
+namespace igl
+{
+  // Convert a CGAL Polyhedron to a mesh (V,F)
+  //
+  // Templates:
+  //   Polyhedron  CGAL Polyhedron type (e.g. Polyhedron_3)
+  // Inputs:
+  //   poly  cgal polyhedron
+  // Outputs:
+  //   V  #V by 3 list of vertex positions
+  //   F  #F by 3 list of triangle indices
+  template <typename Polyhedron>
+  IGL_INLINE void polyhedron_to_mesh(
+    const Polyhedron & poly,
+    Eigen::MatrixXd & V,
+    Eigen::MatrixXi & F);
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "polyhedron_to_mesh.cpp"
+#endif
+
+#endif