Advertisement
zOlive

Check edge cases of CGAL::Polygon_mesh_processing::corefine_and_compute_union

Feb 17th, 2021 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. /*
  2. https://github.com/openscad/openscad/pull/3641
  3.  
  4. g++ \
  5. -stdlib=libc++ -std=c++1y \
  6. -I../CGAL-5.2/include \
  7. -lgmp -lmpfr \
  8. test_pmp.cc \
  9. -o test_pmp && ./test_pmp
  10. */
  11.  
  12. #include <CGAL/Polygon_mesh_processing/corefinement.h>
  13. #include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
  14.  
  15. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
  16. #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
  17. #include <CGAL/Polyhedron_3.h>
  18. #include <CGAL/IO/Polyhedron_iostream.h>
  19. #include <CGAL/draw_polyhedron.h>
  20. #include <fstream>
  21. // typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
  22. typedef CGAL::Epeck Kernel;
  23. typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
  24. typedef Polyhedron::Halfedge_handle Halfedge_handle;
  25.  
  26. // Adapted from https://doc.cgal.org/latest/Polyhedron/Polyhedron_2polyhedron_prog_cube_8cpp-example.html
  27. // (added ugly dx, dy, dz)
  28. template <class Poly>
  29. typename Poly::Halfedge_handle make_cube_3( Poly& P, double sx, double sy, double sz, double dx, double dy, double dz) {
  30. // appends a cube of size [0,1]^3 to the polyhedron P.
  31. CGAL_precondition( P.is_valid());
  32. typedef typename Poly::Point_3 Point;
  33. typedef typename Poly::Halfedge_handle Halfedge_handle;
  34. Halfedge_handle h = P.make_tetrahedron( Point( sx + dx, 0 + dy, 0 + dz),
  35. Point( 0 + dx, 0 + dy, sz + dz),
  36. Point( 0 + dx, 0 + dy, 0 + dz),
  37. Point( 0 + dx, sy + dy, 0 + dz));
  38. Halfedge_handle g = h->next()->opposite()->next(); // Fig. (a)
  39. P.split_edge( h->next());
  40. P.split_edge( g->next());
  41. P.split_edge( g); // Fig. (b)
  42. h->next()->vertex()->point() = Point( sx + dx, 0 + dy, sz + dz);
  43. g->next()->vertex()->point() = Point( 0 + dx, sy + dy, sz + dz);
  44. g->opposite()->vertex()->point() = Point( sx + dx, sy + dy, 0 + dz); // Fig. (c)
  45. Halfedge_handle f = P.split_facet( g->next(),
  46. g->next()->next()->next()); // Fig. (d)
  47. Halfedge_handle e = P.split_edge( f);
  48. e->vertex()->point() = Point( sx + dx, sy + dy, sz + dz); // Fig. (e)
  49. P.split_facet( e, f->next()->next()); // Fig. (f)
  50. CGAL_postcondition( P.is_valid());
  51. return h;
  52. }
  53.  
  54.  
  55. int main(int argc, char* argv[])
  56. {
  57. Polyhedron P1; make_cube_3(P1, 1, 1, 1, 0, 0, 0); // cube(1);
  58.  
  59. Polyhedron P2; make_cube_3(P2, 1, 1, 1, 1, 1, 0); // translate([1, 1, 0]) cube(1); // BREAKS
  60. // Polyhedron P2; make_cube_3(P2, 0.5, 0.5, 0.5, 1, 1, 1); // translate([1, 1, 1]) cube(0.5); // OK
  61. // Polyhedron P2; make_cube_3(P2, 0.5, 0.5, 0.5, 1, 1, 0.25); // translate([1, 1, 0.25]) cube(0.5); // BREAKS
  62. // Polyhedron P2; make_cube_3(P2, 0.5, 0.5, 0.5, 1, 0, 0.25); // translate([1, 0, 0.25]) cube(0.5); // BREAKS
  63.  
  64. CGAL::Polygon_mesh_processing::triangulate_faces(P1);
  65. CGAL::Polygon_mesh_processing::triangulate_faces(P2);
  66.  
  67. CGAL::Polygon_mesh_processing::corefine_and_compute_union(P1, P2, P1);
  68.  
  69. std::ofstream out("out.off");
  70. out << P1;
  71. return EXIT_SUCCESS;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement