فهرست منبع

python support for remesh_self_intersections

Former-commit-id: a25fd7b3ce395e70d039774af6047c35316e5ee8
root 8 سال پیش
والد
کامیت
3f1cb13d7b

+ 4 - 0
python/modules/copyleft/py_igl_cgal.cpp

@@ -6,6 +6,8 @@
 #include "../../python_shared.h"
 
 #include <igl/copyleft/cgal/mesh_boolean.h>
+#include <igl/copyleft/cgal/remesh_self_intersections.h>
+#include <igl/copyleft/cgal/RemeshSelfIntersectionsParam.h>
 
 
 void python_export_igl_cgal(py::module &me) {
@@ -14,5 +16,7 @@ void python_export_igl_cgal(py::module &me) {
     "cgal", "Wrappers for libigl functions that use cgal");
 
   #include "../../py_igl/copyleft/cgal/py_mesh_boolean.cpp"
+  #include "../../py_igl/copyleft/cgal/py_remesh_self_intersections.cpp"
+  #include "../../py_igl/copyleft/cgal/py_RemeshSelfIntersectionsParam.cpp"
 
 }

+ 34 - 0
python/py_doc.cpp

@@ -182,6 +182,40 @@ const char *__doc_igl_copyleft_cgal_mesh_boolean = R"igl_Qu8mg5v7(//  MESH_BOOLE
       //
       //  See also: mesh_boolean_cork, intersect_other,
       //  remesh_self_intersections)igl_Qu8mg5v7";
+const char *__doc_igl_copyleft_cgal_remesh_self_intersections = R"igl_Qu8mg5v7(// Given a triangle mesh (V,F) compute a new mesh (VV,FF) which is the same
+      // as (V,F) except that any self-intersecting triangles in (V,F) have been
+      // subdivided (new vertices and face created) so that the self-intersection
+      // contour lies exactly on edges in (VV,FF). New vertices will appear in
+      // original faces or on original edges. New vertices on edges are "merged"
+      // only across original faces sharing that edge. This means that if the input
+      // triangle mesh is a closed manifold the output will be too.
+      //
+      // Inputs:
+      //   V  #V by 3 list of vertex positions
+      //   F  #F by 3 list of triangle indices into V
+      //   params  struct of optional parameters
+      // Outputs:
+      //   VV  #VV by 3 list of vertex positions
+      //   FF  #FF by 3 list of triangle indices into VV
+      //   IF  #intersecting face pairs by 2  list of intersecting face pairs,
+      //     indexing F
+      //   J  #FF list of indices into F denoting birth triangle
+      //   IM  #VV list of indices into VV of unique vertices.
+      //
+      // Known bugs: If an existing edge in (V,F) lies exactly on another face then
+      // any resulting additional vertices along that edge may not get properly
+      // connected so that the output mesh has the same global topology. This is
+      // because 
+      //
+      // Example:
+      //     // resolve intersections
+      //     igl::copyleft::cgal::remesh_self_intersections(V,F,params,VV,FF,IF,J,IM);
+      //     // _apply_ duplicate vertex mapping IM to FF
+      //     for_each(FF.data(),FF.data()+FF.size(),[&IM](int & a){a=IM(a);});
+      //     // remove any vertices now unreferenced after duplicate mapping.
+      //     igl::remove_unreferenced(VV,FF,SV,SF,UIM);
+      //     // Now (SV,SF) is ready to extract outer hull
+      //     igl::copyleft::cgal::outer_hull(SV,SF,G,J,flip);igl_Qu8mg5v7";
 const char *__doc_igl_copyleft_comiso_miq = R"igl_Qu8mg5v7(// Inputs:
     //   V              #V by 3 list of mesh vertex 3D positions
     //   F              #F by 3 list of faces indices in V

+ 1 - 0
python/py_doc.h

@@ -13,6 +13,7 @@ extern const char *__doc_igl_comb_cross_field;
 extern const char *__doc_igl_comb_frame_field;
 extern const char *__doc_igl_compute_frame_field_bisectors;
 extern const char *__doc_igl_copyleft_cgal_mesh_boolean;
+extern const char *__doc_igl_copyleft_cgal_remesh_self_intersections;
 extern const char *__doc_igl_copyleft_comiso_miq;
 extern const char *__doc_igl_copyleft_comiso_nrosy;
 extern const char *__doc_igl_copyleft_marching_cubes;

+ 14 - 0
python/py_igl/copyleft/cgal/py_RemeshSelfIntersectionsParam.cpp

@@ -0,0 +1,14 @@
+py::class_<igl::copyleft::cgal::RemeshSelfIntersectionsParam > RemeshSelfIntersectionsParam(m, "RemeshSelfIntersectionsParam");
+
+RemeshSelfIntersectionsParam
+.def("__init__", [](igl::copyleft::cgal::RemeshSelfIntersectionsParam &m)
+{
+    new (&m) igl::copyleft::cgal::RemeshSelfIntersectionsParam();
+    m.detect_only = false;
+    m.first_only = false;
+    m.stitch_all = false;
+})
+.def_readwrite("detect_only", &igl::copyleft::cgal::RemeshSelfIntersectionsParam::detect_only)
+.def_readwrite("first_only", &igl::copyleft::cgal::RemeshSelfIntersectionsParam::first_only)
+.def_readwrite("stitch_all", &igl::copyleft::cgal::RemeshSelfIntersectionsParam::stitch_all)
+;

+ 22 - 0
python/py_igl/copyleft/cgal/py_remesh_self_intersections.cpp

@@ -0,0 +1,22 @@
+m.def("remesh_self_intersections", []
+(
+	const Eigen::MatrixXd& V,	
+	const Eigen::MatrixXi& F,
+	const igl::copyleft::cgal::RemeshSelfIntersectionsParam& params,
+	Eigen::MatrixXd& VV,
+	Eigen::MatrixXi& FF,
+	Eigen::MatrixXi& IF,
+	Eigen::MatrixXi& J,
+	Eigen::MatrixXi& IM
+)
+{
+	assert_is_VectorX("J", J);
+	assert_is_VectorX("IM", IM);
+	Eigen::VectorXi Jt;
+	Eigen::VectorXi IMt;
+	igl::copyleft::cgal::remesh_self_intersections(V, F, params, VV, FF, IF, Jt, IMt);
+	J = Jt;
+	IM = IMt;
+}, __doc_igl_copyleft_cgal_remesh_self_intersections,
+py::arg("V"), py::arg("F"), py::arg("params"), py::arg("VV")
+, py::arg("FF"), py::arg("IF"), py::arg("J"), py::arg("IM")); 

+ 2 - 0
python/python_shared.cpp

@@ -66,6 +66,8 @@ PYBIND11_PLUGIN(pyigl) {
            comb_frame_field
            compute_frame_field_bisectors
            copyleft_cgal_mesh_boolean
+           copyleft_cgal_remesh_self_intersections
+           copyleft_cgal_RemeshSelfIntersectionsParam
            copyleft_comiso_miq
            copyleft_comiso_nrosy
            copyleft_marching_cubes