|
1 | 1 | #include "triangulations.h" |
2 | 2 |
|
3 | | -// #include <CGAL/Polygon_mesh_processing/remesh.h> |
4 | | -// #include <CGAL/Polygon_mesh_processing/detect_features.h> |
| 3 | +#include <CGAL/Delaunay_triangulation_2.h> |
| 4 | +#include <CGAL/Constrained_triangulation_2.h> |
| 5 | +#include <CGAL/Constrained_Delaunay_triangulation_2.h> |
| 6 | +#include <CGAL/Triangulation_vertex_base_with_info_2.h> |
| 7 | + |
| 8 | +using DT = CGAL::Delaunay_triangulation_2<Kernel>; |
| 9 | +using DT_Point = DT::Point; |
| 10 | +using DT_Vertex = DT::Vertex_handle; |
| 11 | + |
| 12 | +using CDT_VertexBase = CGAL::Triangulation_vertex_base_with_info_2<unsigned, Kernel>; |
| 13 | +using CDT_DS = CGAL::Triangulation_data_structure_2<CDT_VertexBase>; |
| 14 | +using CDT = CGAL::Constrained_Delaunay_triangulation_2<Kernel, CDT_DS>; |
| 15 | +using CDT_Point = CDT::Point; |
| 16 | +using CDT_Vertex = CDT::Vertex_handle; |
5 | 17 |
|
6 | | -// namespace PMP = CGAL::Polygon_mesh_processing; |
7 | | -// namespace params = PMP::parameters; |
8 | 18 | namespace py = pybind11; |
9 | 19 |
|
10 | | -std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> |
11 | | -pmp_tetrahedralisation( |
12 | | - Eigen::Ref<const compas::RowMatrixXd> & Points) |
| 20 | +compas::RowMatrixXi |
| 21 | +pmp_delaunay_triangulation( |
| 22 | + Eigen::Ref<const compas::RowMatrixXd> & V) |
13 | 23 | { |
14 | | - mesh.collect_garbage(); |
| 24 | + DT dt; |
15 | 25 |
|
16 | | - // Result |
17 | | - std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> R = compas::mesh_to_vertices_and_faces(mesh); |
| 26 | + int v = V.rows(); |
18 | 27 |
|
19 | | - return R; |
20 | | -}; |
| 28 | + std::vector< std::pair<Point, unsigned> > points(v); |
| 29 | + // std::vector< Vertex > vertex_handles(v); |
| 30 | + |
| 31 | + for (int i=0; i < v; i++) { |
| 32 | + points[i] = std::make_pair(Point(V(i, 0), V(i, 1)), i); |
| 33 | + } |
| 34 | + |
| 35 | + cdt.insert(points.begin(), points.end()); |
| 36 | + |
| 37 | + // for (int i=0; i < v; i++) { |
| 38 | + // std::pair<Point, unsigned> point; |
| 39 | + // point = std::make_pair(Point(V(i, 0), V(i, 1)), i); |
| 40 | + // vertex_handles[i] = cdt.insert(point); |
| 41 | + // } |
| 42 | + |
| 43 | + for (int i=0; i < e; i++) { |
| 44 | + cdt.insert_constraint(vertex_handles[E(i, 0)], vertex_handles[E(i, 1)]); |
| 45 | + } |
| 46 | + |
| 47 | + // int cdt_v = cdt.number_of_vertices(); |
| 48 | + int cdt_f = cdt.number_of_faces(); |
| 49 | + |
| 50 | + compas::RowMatrixXi RF(cdt_f, 3); |
| 51 | + |
| 52 | + // int i = 0; |
| 53 | + // for (auto point = cdt.points_begin(); point != cdt.points_end(); point++) { |
| 54 | + // RV(i, 0) = point->hx(); |
| 55 | + // RV(i, 1) = point->hy(); |
| 56 | + // i++; |
| 57 | + // } |
| 58 | + |
| 59 | + int j = 0; |
| 60 | + for (CDT::Finite_faces_iterator fit = cdt.finite_faces_begin(); fit != cdt.finite_faces_end(); fit++) { |
| 61 | + CDT::Face_handle face = fit; |
| 62 | + RF(j, 0) = face->vertex(0)->info(); |
| 63 | + RF(j, 1) = face->vertex(1)->info(); |
| 64 | + RF(j, 2) = face->vertex(2)->info(); |
| 65 | + j++; |
| 66 | + } |
| 67 | + |
| 68 | + // std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> result = std::make_tuple(RV, RF); |
| 69 | + return RF; |
| 70 | +} |
| 71 | + |
| 72 | +void |
| 73 | +pmp_constrained_delaunay_triangulation( |
| 74 | + Eigen::Ref<const compas::RowMatrixXd> & V, |
| 75 | + Eigen::Ref<const compas::RowMatrixXi> & E) |
| 76 | +{ |
| 77 | + // CDT cdt; |
21 | 78 |
|
22 | | -// void init_meshing(py::module & m) { |
23 | | -// py::module submodule = m.def_submodule("meshing"); |
24 | | - |
25 | | -// submodule.def( |
26 | | -// "remesh", |
27 | | -// &pmp_remesh, |
28 | | -// py::arg("V").noconvert(), |
29 | | -// py::arg("F").noconvert(), |
30 | | -// py::arg("target_edge_length"), |
31 | | -// py::arg("number_of_iterations") = 10, |
32 | | -// py::arg("do_project") = true |
33 | | -// ); |
34 | | -// }; |
| 79 | + // int v = V.rows(); |
| 80 | + // int e = E.rows(); |
| 81 | + |
| 82 | + // std::vector< std::pair<Point, unsigned> > points(v); |
| 83 | + // // std::vector< Vertex > vertex_handles(v); |
| 84 | + |
| 85 | + // for (int i=0; i < v; i++) { |
| 86 | + // points[i] = std::make_pair(Point(V(i, 0), V(i, 1)), i); |
| 87 | + // } |
| 88 | + |
| 89 | + // cdt.insert(points.begin(), points.end()); |
| 90 | + |
| 91 | + // // for (int i=0; i < v; i++) { |
| 92 | + // // std::pair<Point, unsigned> point; |
| 93 | + // // point = std::make_pair(Point(V(i, 0), V(i, 1)), i); |
| 94 | + // // vertex_handles[i] = cdt.insert(point); |
| 95 | + // // } |
| 96 | + |
| 97 | + // for (int i=0; i < e; i++) { |
| 98 | + // cdt.insert_constraint(vertex_handles[E(i, 0)], vertex_handles[E(i, 1)]); |
| 99 | + // } |
| 100 | + |
| 101 | + // // int cdt_v = cdt.number_of_vertices(); |
| 102 | + // int cdt_f = cdt.number_of_faces(); |
| 103 | + |
| 104 | + // compas::RowMatrixXi RF(cdt_f, 3); |
| 105 | + |
| 106 | + // // int i = 0; |
| 107 | + // // for (auto point = cdt.points_begin(); point != cdt.points_end(); point++) { |
| 108 | + // // RV(i, 0) = point->hx(); |
| 109 | + // // RV(i, 1) = point->hy(); |
| 110 | + // // i++; |
| 111 | + // // } |
| 112 | + |
| 113 | + // int j = 0; |
| 114 | + // for (CDT::Finite_faces_iterator fit = cdt.finite_faces_begin(); fit != cdt.finite_faces_end(); fit++) { |
| 115 | + // CDT::Face_handle face = fit; |
| 116 | + // RF(j, 0) = face->vertex(0)->info(); |
| 117 | + // RF(j, 1) = face->vertex(1)->info(); |
| 118 | + // RF(j, 2) = face->vertex(2)->info(); |
| 119 | + // j++; |
| 120 | + // } |
| 121 | + |
| 122 | + // // std::tuple<compas::RowMatrixXd, compas::RowMatrixXi> result = std::make_tuple(RV, RF); |
| 123 | + // return RF; |
| 124 | +} |
| 125 | + |
| 126 | +void init_triangulations(py::module & m) { |
| 127 | + py::module submodule = m.def_submodule("triangulations"); |
| 128 | + |
| 129 | + submodule.def( |
| 130 | + "constrained_delaunay_triangulation", |
| 131 | + &pmp_constrained_delaunay_triangulation, |
| 132 | + py::arg("V").noconvert(), |
| 133 | + py::arg("E").noconvert() |
| 134 | + ); |
| 135 | +}; |
0 commit comments