diff --git a/CMakeLists.txt b/CMakeLists.txt index d040104f07..b5d7cb2ee6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -589,19 +589,10 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif(FREECAD_USE_PCL) # -------------------------------- PyBind11 ----------------------------- -EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c - "import pybind11; print(bool(pybind11))" - OUTPUT_VARIABLE PYBIND11_FOUND OUTPUT_STRIP_TRAILING_WHITESPACE ) - -EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c - "import pybind11; print(pybind11.get_include())" - OUTPUT_VARIABLE PYBIND11_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ) - -if (PYBIND11_FOUND) - message(STATUS "successfully found pybind11") - message(STATUS "pybind11 include dir is: " ${PYBIND11_INCLUDE_DIR}) +OPTION(FREECAD_USE_PYBIND11 "Use pybind11" OFF) +if (FREECAD_USE_PYBIND11) + find_package(pybind11 REQUIRED) endif() - # -------------------------------- Boost -------------------------------- SET(_boost_TEST_VERSIONS ${Boost_ADDITIONAL_VERSIONS}) diff --git a/src/Mod/MeshPart/App/CMakeLists.txt b/src/Mod/MeshPart/App/CMakeLists.txt index 496cfebcb0..f54859d11d 100644 --- a/src/Mod/MeshPart/App/CMakeLists.txt +++ b/src/Mod/MeshPart/App/CMakeLists.txt @@ -81,18 +81,21 @@ SET_PYTHON_PREFIX_SUFFIX(MeshPart) INSTALL(TARGETS MeshPart DESTINATION ${CMAKE_INSTALL_LIBDIR}) -if (PYBIND11_FOUND) - ################################ flat mesh ############################### +################################ flat mesh ############################### +if (FREECAD_USE_PYBIND11) SET(FLATMESH_SRCS - MeshFlatteningPy.cpp - MeshFlattening.cpp - MeshFlattening.h - MeshFlatteningNurbs.h - MeshFlatteningNurbs.cpp - MeshFlatteningLscmRelax.h - MeshFlatteningLscmRelax.cpp + MeshFlattening.cpp + MeshFlattening.h + MeshFlatteningNurbs.h + MeshFlatteningNurbs.cpp + MeshFlatteningLscmRelax.h + MeshFlatteningLscmRelax.cpp ) + SET(FLATMESH_SRCS + ${FLATMESH_SRCS} + MeshFlatteningPy.cpp + ) add_library(flatmesh SHARED ${FLATMESH_SRCS}) @@ -101,5 +104,5 @@ if (PYBIND11_FOUND) SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) - ############################################################################ endif() +############################################################################ diff --git a/src/Mod/MeshPart/App/MeshFlattening.cpp b/src/Mod/MeshPart/App/MeshFlattening.cpp index a4fcb6f51b..2b0cc22792 100644 --- a/src/Mod/MeshPart/App/MeshFlattening.cpp +++ b/src/Mod/MeshPart/App/MeshFlattening.cpp @@ -33,6 +33,7 @@ #include #include + std::vector> getBoundaries(ColMat vertices, ColMat tris) { // get a hashtable for all edges @@ -172,7 +173,7 @@ FaceUnwrapper::FaceUnwrapper(const TopoDS_Face& face) void FaceUnwrapper::findFlatNodes(int steps, double val) { std::vector fixed_pins; //TODO: INPUT - LscmRelax mesh_flattener(this->xyz_nodes.transpose(), this->tris.transpose(), fixed_pins); + lscmrelax::LscmRelax mesh_flattener(this->xyz_nodes.transpose(), this->tris.transpose(), fixed_pins); mesh_flattener.lscm(); for (int j=0; j -#include +#include #include #include #include @@ -39,6 +39,8 @@ // area constrained (scale the final unwrapped mesh to the original area) // FEM approach +namespace lscmrelax +{ typedef Eigen::Triplet trip; typedef Eigen::SparseMatrix spMat; @@ -565,3 +567,5 @@ std::vector LscmRelax::get_fem_fixed_pins() } return std::vector{min_x_index * 2, min_x_index * 2 + 1, max_x_index * 2 + 1}; } + +} diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h index c6bcccf890..cd967240cf 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h @@ -35,6 +35,8 @@ // 6: K.u=forces ->u // 7: x1, y1 += w * u +#include "MeshFlattening.h" + #include #include #include @@ -42,20 +44,14 @@ #include #include -#include "MeshFlatteningLscmRelax.h" - typedef Eigen::SparseMatrix spMat; - +namespace lscmrelax +{ + typedef Eigen::Vector3d Vector3; typedef Eigen::Vector2d Vector2; -template -using ColMat = Eigen::Matrix; - -template -using RowMat = Eigen::Matrix; - class LscmRelax{ private: ColMat q_l_g; // the position of the 3d triangles at there locale coord sys @@ -104,5 +100,6 @@ public: }; +} #endif diff --git a/src/Mod/MeshPart/App/MeshFlatteningPy.cpp b/src/Mod/MeshPart/App/MeshFlatteningPy.cpp index f382c77274..6d5851e37a 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningPy.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningPy.cpp @@ -50,7 +50,6 @@ #include - namespace py = pybind11; const TopoDS_Face& getTopoDSFace(py::object* face) @@ -101,29 +100,30 @@ ColMat interpolateFlatFacePy(FaceUnwrapper& instance, py::object* fac } + PYBIND11_MODULE(flatmesh, m) { m.doc() = "functions to unwrapp faces/ meshes"; - py::class_(m, "LscmRelax") + py::class_(m, "LscmRelax") .def(py::init, ColMat, std::vector>()) - .def("lscm", &LscmRelax::lscm) - .def("relax", &LscmRelax::relax) - .def("rotate_by_min_bound_area", &LscmRelax::rotate_by_min_bound_area) - .def("transform", &LscmRelax::transform) - .def_readonly("rhs", &LscmRelax::rhs) - .def_readonly("MATRIX", &LscmRelax::MATRIX) - .def_property_readonly("area", &LscmRelax::get_area) - .def_property_readonly("flat_area", &LscmRelax::get_flat_area) - .def_property_readonly("flat_vertices", [](LscmRelax& L){return L.flat_vertices.transpose();}, py::return_value_policy::copy) - .def_property_readonly("flat_vertices_3D", &LscmRelax::get_flat_vertices_3D); + .def("lscm", &lscmrelax::LscmRelax::lscm) + .def("relax", &lscmrelax::LscmRelax::relax) + .def("rotate_by_min_bound_area", &lscmrelax::LscmRelax::rotate_by_min_bound_area) + .def("transform", &lscmrelax::LscmRelax::transform) + .def_readonly("rhs", &lscmrelax::LscmRelax::rhs) + .def_readonly("MATRIX", &lscmrelax::LscmRelax::MATRIX) + .def_property_readonly("area", &lscmrelax::LscmRelax::get_area) + .def_property_readonly("flat_area", &lscmrelax::LscmRelax::get_flat_area) + .def_property_readonly("flat_vertices", [](lscmrelax::LscmRelax& L){return L.flat_vertices.transpose();}, py::return_value_policy::copy) + .def_property_readonly("flat_vertices_3D", &lscmrelax::LscmRelax::get_flat_vertices_3D); py::class_(m, "NurbsBase2D") .def(py::init()) .def_readonly("u_knots", &nurbs::NurbsBase2D::u_knots) .def_readonly("weights", &nurbs::NurbsBase2D::weights) .def_readonly("degree_u", &nurbs::NurbsBase2D::degree_u) - .def_readonly("v_knots", &nurbs::NurbsBase2D::u_knots) +// .def_readonly("v_knots", &nurbs::NurbsBase2D::u_knots) .def_readonly("degree_v", &nurbs::NurbsBase2D::degree_u) .def("getUVMesh", &nurbs::NurbsBase2D::getUVMesh) .def("computeFirstDerivatives", &nurbs::NurbsBase2D::computeFirstDerivatives)