mesh_to_polyhedron.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "mesh_to_polyhedron.h"
  9. #include <CGAL/Polyhedron_3.h>
  10. #include <CGAL/Polyhedron_incremental_builder_3.h>
  11. template <typename Polyhedron>
  12. IGL_INLINE bool igl::cgal::mesh_to_polyhedron(
  13. const Eigen::MatrixXd & V,
  14. const Eigen::MatrixXi & F,
  15. Polyhedron & poly)
  16. {
  17. typedef typename Polyhedron::HalfedgeDS HalfedgeDS;
  18. // Postcondition: hds is a valid polyhedral surface.
  19. CGAL::Polyhedron_incremental_builder_3<HalfedgeDS> B(poly.hds());
  20. B.begin_surface(V.rows(),F.rows());
  21. typedef typename HalfedgeDS::Vertex Vertex;
  22. typedef typename Vertex::Point Point;
  23. assert(V.cols() == 3 && "V must be #V by 3");
  24. for(int v = 0;v<V.rows();v++)
  25. {
  26. B.add_vertex(Point(V(v,0),V(v,1),V(v,2)));
  27. }
  28. assert(F.cols() == 3 && "F must be #F by 3");
  29. for(int f=0;f<F.rows();f++)
  30. {
  31. B.begin_facet();
  32. for(int c = 0;c<3;c++)
  33. {
  34. B.add_vertex_to_facet(F(f,c));
  35. }
  36. B.end_facet();
  37. }
  38. if(B.error())
  39. {
  40. B.rollback();
  41. return false;
  42. }
  43. B.end_surface();
  44. return poly.is_valid();
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. // Explicit template specialization
  48. #include <CGAL/Simple_cartesian.h>
  49. #include <CGAL/Polyhedron_items_with_id_3.h>
  50. template bool igl::cgal::mesh_to_polyhedron<CGAL::Polyhedron_3<CGAL::Simple_cartesian<double>, CGAL::Polyhedron_items_with_id_3, CGAL::HalfedgeDS_default, std::allocator<int> > >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, CGAL::Polyhedron_3<CGAL::Simple_cartesian<double>, CGAL::Polyhedron_items_with_id_3, CGAL::HalfedgeDS_default, std::allocator<int> >&);
  51. #endif