Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*******************************************************************************
* Contact information: [email protected] *
******************************************************************************/
#include <pybind11/stl.h>

#include <SofaPython3/Sofa/Core/Binding_Base.h>
#include <SofaPython3/Sofa/Core/Binding_BaseContext.h>
Expand All @@ -37,6 +38,56 @@ namespace sofapython3 {

void moduleAddBaseMeshTopology(py::module& m) {
py::class_<BaseMeshTopology, Base, py_shared_ptr<BaseMeshTopology>> c (m, "BaseMeshTopology");

/// register the ContactListener binding in the downcasting subsystem
PythonFactory::registerType<BaseMeshTopology>([](sofa::core::objectmodel::Base* object)
{
return py::cast(dynamic_cast<BaseMeshTopology*>(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<sofa::Index, 2> {
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<sofa::Index, 2> {
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<sofa::Index, 6> {
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<sofa::Index, 4> {
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