diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseMeshTopology.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseMeshTopology.cpp index a291ca68..8ed12bd2 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseMeshTopology.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_BaseMeshTopology.cpp @@ -17,6 +17,7 @@ ******************************************************************************* * Contact information: contact@sofa-framework.org * ******************************************************************************/ +#include #include #include @@ -37,6 +38,56 @@ namespace sofapython3 { void moduleAddBaseMeshTopology(py::module& m) { py::class_> c (m, "BaseMeshTopology"); + + /// register the ContactListener binding in the downcasting subsystem + PythonFactory::registerType([](sofa::core::objectmodel::Base* object) + { + return py::cast(dynamic_cast(object)); + }); + + c.def("getNbPoints", &BaseMeshTopology::getNbPoints); + c.def("getNbLines", &BaseMeshTopology::getNbLines); + c.def("getNbEdges", &BaseMeshTopology::getNbEdges); + c.def("getNbTriangles", &BaseMeshTopology::getNbTriangles); + c.def("getNbTetrahedra", &BaseMeshTopology::getNbTetrahedra); + c.def("getNbHexahedra", &BaseMeshTopology::getNbHexahedra); + c.def("getNbQuads", &BaseMeshTopology::getNbQuads); + c.def("getNbTetras", &BaseMeshTopology::getNbTetras); + + c.def("getEdge", + [] (BaseMeshTopology &self, const sofa::Index & index) -> std::array { + const auto & e = self.getEdge(index); + return {{e[0], e[1]}}; + }, + py::arg("index") + ); + + c.def("getLocalEdgesInTetrahedron", + [] (const BaseMeshTopology & self, const sofa::Index & index) -> std::array { + const auto & e = self.getLocalEdgesInTetrahedron(index); + return {{e[0], e[1]}}; + }, + py::arg("index"), + "Returns for each index (between 0 and 5) the two vertex indices that are adjacent to that edge." + ); + + c.def("getEdgesInTetrahedron", + [] (BaseMeshTopology & self, const sofa::Index & index) -> std::array { + const auto & e = self.getEdgesInTetrahedron(index); + return {{e[0], e[1], e[2], e[3], e[4], e[5]}}; + }, + py::arg("index"), + "Returns the set of edges adjacent to a given tetrahedron." + ); + + c.def("getTetrahedron", + [] (BaseMeshTopology & self, const sofa::Index & index) -> std::array { + const auto & n = self.getTetrahedron(index); + return {{n[0], n[1], n[2], n[3]}}; + }, + py::arg("index"), + "Returns the vertices of Tetrahedron at index." + ); } } // namespace sofapython3