/*************************************************************************** * 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 "MeshFlattening.h" #include "MeshFlatteningLscmRelax.h" #include "MeshFlatteningNurbs.h" #include #include namespace py = pybind11; // void FaceUnwrapper_constructor(FaceUnwrapper& instance, Part::TopoShapeFacePy Face) FaceUnwrapper* FaceUnwrapper_constructor(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 new FaceUnwrapper(myFace); } else throw std::invalid_argument("FaceUnwrapper should be initialized with Part.Face"); } ColMat interpolateNurbsFacePy(FaceUnwrapper& instance, py::object face) { std::cout << face.ptr()->ob_type->tp_name << std::endl; std::cout << Part::TopoShapeFacePy::Type.tp_name << std::endl; 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 instance.interpolateNurbsFace(myFace); } else throw std::invalid_argument("FaceUnwrapper.interpolateNurbs should be initialized with Part.Face"); } PYBIND11_MODULE(flatmesh, m) { m.doc() = "functions to unwrapp faces/ meshes"; 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); py::class_(m, "NurbsBase2D") .def(py::init()) .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); py::class_(m, "NurbsBase1D") .def(py::init()) .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); py::class_(m, "FaceUnwrapper") .def(py::init(&FaceUnwrapper_constructor)) .def("findFlatNodes", &FaceUnwrapper::findFlatNodes) .def("interpolateNurbsFace", &interpolateNurbsFacePy) .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); };