diff --git a/src/Mod/MeshPart/App/CMakeLists.txt b/src/Mod/MeshPart/App/CMakeLists.txt index fe3e1d124a..3541a82d4b 100644 --- a/src/Mod/MeshPart/App/CMakeLists.txt +++ b/src/Mod/MeshPart/App/CMakeLists.txt @@ -92,5 +92,41 @@ if (FREECAD_USE_PYBIND11) SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) +else() + if(NOT FREECAD_LIBPACK_USE OR FREECAD_LIBPACK_CHECKFILE_CLBUNDLER) + # boost-python >= 1.67 on some platforms has suffix + set(BOOST_PY_SUFFIX ${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}) + + find_package( Boost COMPONENTS python${BOOST_PY_SUFFIX} ) + if (NOT Boost_PYTHON${BOOST_PY_SUFFIX}_FOUND) + # try just the major version + find_package( Boost COMPONENTS python${PYTHON_VERSION_MAJOR} ) + if (NOT Boost_PYTHON${PYTHON_VERSION_MAJOR}_FOUND) + # unversioned + find_package( Boost COMPONENTS python REQUIRED) + endif() + endif() + + if(Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) + SET(FLATMESH_SRCS + MeshFlattening.cpp + MeshFlattening.h + MeshFlatteningNurbs.h + MeshFlatteningNurbs.cpp + MeshFlatteningLscmRelax.h + MeshFlatteningLscmRelax.cpp + MeshFlatteningBoostPython.cpp + ) + + + add_library(flatmesh SHARED ${FLATMESH_SRCS}) + SET_PYTHON_PREFIX_SUFFIX(flatmesh) + target_link_libraries(flatmesh ${PYTHON_LIBRARIES} ${MeshPart_LIBS} ${Boost_LIBRARIES}) + + SET_BIN_DIR(flatmesh flatmesh /Mod/MeshPart) + install(TARGETS flatmesh DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + endif() endif() ############################################################################ diff --git a/src/Mod/MeshPart/App/MeshFlattening.cpp b/src/Mod/MeshPart/App/MeshFlattening.cpp index a185d2b16b..b5606a5b82 100644 --- a/src/Mod/MeshPart/App/MeshFlattening.cpp +++ b/src/Mod/MeshPart/App/MeshFlattening.cpp @@ -21,6 +21,7 @@ ***************************************************************************/ +#include "PreCompiled.h" #include "MeshFlattening.h" #include "MeshFlatteningLscmRelax.h" #include diff --git a/src/Mod/MeshPart/App/MeshFlattening.h b/src/Mod/MeshPart/App/MeshFlattening.h index 4984ae64b6..2a91b2f10b 100644 --- a/src/Mod/MeshPart/App/MeshFlattening.h +++ b/src/Mod/MeshPart/App/MeshFlattening.h @@ -61,6 +61,7 @@ std::vector> getBoundaries(ColMat vertices, ColMat< class FaceUnwrapper{ nurbs::NurbsBase2D nu; public: + FaceUnwrapper(){} FaceUnwrapper(const TopoDS_Face & face); FaceUnwrapper(ColMat xyz_nodes, ColMat tris); void findFlatNodes(int steps, double val); diff --git a/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp b/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp new file mode 100644 index 0000000000..4ad34352f1 --- /dev/null +++ b/src/Mod/MeshPart/App/MeshFlatteningBoostPython.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** + * Copyright (c) 2017 Lorenz Lechner * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + + +#include "PreCompiled.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "MeshFlattening.h" +#include "MeshFlatteningLscmRelax.h" +#include "MeshFlatteningNurbs.h" + +#include +#include +#include +#include + + + +namespace py = boost::python; + +const TopoDS_Face& getTopoDSFace(const py::object& face) +{ + if (PyObject_TypeCheck(face.ptr(), &(Part::TopoShapeFacePy::Type))) + { + const Part::TopoShapeFacePy* f = static_cast(face.ptr()); + const TopoDS_Face& myFace = TopoDS::Face(f->getTopoShapePtr()->getShape()); + return myFace; + } + else + throw std::invalid_argument("must be a face"); +} + +const TopoDS_Edge& getTopoDSEdge(py::object* edge) +{ + if (PyObject_TypeCheck(edge->ptr(), &(Part::TopoShapeEdgePy::Type))) + { + const Part::TopoShapeEdgePy* e = static_cast(edge->ptr()); + const TopoDS_Edge& myEdge = TopoDS::Edge(e->getTopoShapePtr()->getShape()); + return myEdge; + } + else + throw std::invalid_argument("must be an edge"); +} + +Py::Object makeEdge(const TopoDS_Edge& edge) +{ + return Py::asObject(new Part::TopoShapeEdgePy(new Part::TopoShape(edge))); +} + +boost::shared_ptr FaceUnwrapper_face(const py::object& face) +{ + const TopoDS_Face& myFace = getTopoDSFace(face); + return boost::shared_ptr(new FaceUnwrapper(myFace)); +} + +boost::shared_ptr FaceUnwrapper_mesh(const py::object& points, + const py::object& facets) +{ + try { + Py::Sequence l1(points.ptr()); + ColMat coords; + coords.resize(l1.size(), 3); + int row = 0; + for (Py::Sequence::iterator it = l1.begin(); it != l1.end(); ++it) { + Py::Sequence c(*it); + int col = 0; + for (Py::Sequence::iterator jt = c.begin(); jt != c.end(); ++jt, ++col) { + double v = static_cast(Py::Float(*jt)); + coords(row, col) = v; + } + } + + Py::Sequence l2(facets.ptr()); + ColMat triangles; + triangles.resize(l2.size(), 3); + for (Py::Sequence::iterator it = l2.begin(); it != l2.end(); ++it) { + Py::Sequence c(*it); + int col = 0; + for (Py::Sequence::iterator jt = c.begin(); jt != c.end(); ++jt, ++col) { + long v = static_cast(Py::Long(*jt)); + triangles(row, col) = v; + } + } + + return boost::shared_ptr(new FaceUnwrapper(coords, triangles)); + } + catch (const Py::Exception&) { + Base::PyException e; + throw std::invalid_argument(e.what()); + } +} + +boost::python::list interpolateFlatFacePy(FaceUnwrapper& instance, const py::object& face) +{ + const TopoDS_Face& myFace = getTopoDSFace(face); + ColMat mat = instance.interpolateFlatFace(myFace); + boost::python::list plist; + auto cols = mat.cols(); + auto rows = mat.rows(); + for (int i=0; i("LscmRelax") + .def(py::init, ColMat, std::vector>()) + .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_readonly("area", &lscmrelax::LscmRelax::get_area) + .def_readonly("flat_area", &lscmrelax::LscmRelax::get_flat_area) +// .def_readonly("flat_vertices", [](lscmrelax::LscmRelax& L){return L.flat_vertices.transpose();}, py::return_value_policy()) + .def_readonly("flat_vertices_3D", &lscmrelax::LscmRelax::get_flat_vertices_3D); + + py::class_("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("degree_v", &nurbs::NurbsBase2D::degree_u) + .def("getUVMesh", &nurbs::NurbsBase2D::getUVMesh) + .def("computeFirstDerivatives", &nurbs::NurbsBase2D::computeFirstDerivatives) + .def("getInfluenceVector", &nurbs::NurbsBase2D::getInfluenceVector) + .def("getInfluenceMatrix", &nurbs::NurbsBase2D::getInfluenceMatrix) + .def("getDuVector", &nurbs::NurbsBase2D::getDuVector) + .def("getDuMatrix", &nurbs::NurbsBase2D::getDuMatrix) + .def("getDvVector", &nurbs::NurbsBase2D::getDvVector) + .def("getDvMatrix", &nurbs::NurbsBase2D::getDvMatrix) + .def("interpolateUBS", &nurbs::NurbsBase2D::interpolateUBS); + + py::class_("NurbsBase1D") + .def(py::init()) + .def_readonly("u_knots", &nurbs::NurbsBase1D::u_knots) + .def_readonly("weights", &nurbs::NurbsBase1D::weights) + .def_readonly("degree_u", &nurbs::NurbsBase1D::degree_u) + .def("getUMesh", &nurbs::NurbsBase1D::getUMesh) + .def("computeFirstDerivatives", &nurbs::NurbsBase1D::computeFirstDerivatives) + .def("getInfluenceVector", &nurbs::NurbsBase1D::getInfluenceVector) + .def("getInfluenceMatrix", &nurbs::NurbsBase1D::getInfluenceMatrix) + .def("getDuVector", &nurbs::NurbsBase1D::getDuVector) + .def("getDuMatrix", &nurbs::NurbsBase1D::getDuMatrix) + .add_static_property("getKnotSequence", &nurbs::NurbsBase1D::getKnotSequence) + .add_static_property("getWeightList", &nurbs::NurbsBase1D::getWeightList); + + py::class_("FaceUnwrapper") + .def("__init__", py::make_constructor(&FaceUnwrapper_face)) + .def("__init__", py::make_constructor(&FaceUnwrapper_mesh)) + .def(py::init, ColMat>()) + .def("findFlatNodes", &FaceUnwrapper::findFlatNodes) + .def("interpolateFlatFace", &interpolateFlatFacePy) + .def("getFlatBoundaryNodes", &FaceUnwrapper::getFlatBoundaryNodes) + .def_readonly("tris", &FaceUnwrapper::tris) + .def_readonly("nodes", &FaceUnwrapper::xyz_nodes) + .def_readonly("uv_nodes", &FaceUnwrapper::uv_nodes) + .def_readonly("ze_nodes", &FaceUnwrapper::ze_nodes) + .def_readonly("ze_poles", &FaceUnwrapper::ze_poles) + .def_readonly("A", &FaceUnwrapper::A); +} diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp index eac6bb828c..6536608f5c 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp @@ -21,6 +21,7 @@ ***************************************************************************/ +#include "PreCompiled.h" #include "MeshFlatteningLscmRelax.h" #include #include diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h index fee5c04727..26ab4faee4 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.h @@ -91,6 +91,7 @@ private: Eigen::MatrixXd get_nullspace(); public: + LscmRelax() {} LscmRelax( RowMat vertices, RowMat triangles, diff --git a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp index 63eb5409e8..bc7fa286e9 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningNurbs.cpp @@ -21,6 +21,7 @@ ***************************************************************************/ +#include "PreCompiled.h" #include "MeshFlatteningNurbs.h" #include #include "math.h" diff --git a/src/Mod/MeshPart/App/PreCompiled.h b/src/Mod/MeshPart/App/PreCompiled.h index e7463d3b8d..60f7148f32 100644 --- a/src/Mod/MeshPart/App/PreCompiled.h +++ b/src/Mod/MeshPart/App/PreCompiled.h @@ -38,8 +38,10 @@ #endif #ifdef _MSC_VER +# pragma warning(disable : 4244) # pragma warning(disable : 4275) # pragma warning(disable : 4290) +# pragma warning(disable : 4522) #endif #ifdef _PreComp_