diff --git a/src/Mesh.hh b/src/Mesh.hh index c17f77b11d9d104f649d943d1ff1a7e14f811aee..f02acd20bc9650b93237a2353b9047b48fb7183f 100644 --- a/src/Mesh.hh +++ b/src/Mesh.hh @@ -10,6 +10,7 @@ #include #include +#include namespace py = pybind11; namespace OM = OpenMesh; @@ -129,26 +130,6 @@ void garbage_collection(Mesh& _self, py::list& _vh_to_update, py::list& _hh_to_u _self.garbage_collection(vh_vector, hh_vector, fh_vector, _v, _e, _f); } -/** - * Add a new face from a %Python list of vertex handles. - * - * @tparam Mesh A Mesh type. - * - * @param _self The mesh instance that is to be used. - * @param _vhandles The list of vertex handles. - */ -template -OM::FaceHandle add_face(Mesh& _self, const py::list& _vhandles) { - // TODO Use automatic conversion instead? - std::vector vector; - for (auto item : _vhandles) { - if (py::isinstance(item)) { - vector.push_back(item.cast()); - } - } - return _self.add_face(vector); -} - /** * Converts OpenMesh vectors to numpy arrays. * @@ -381,14 +362,10 @@ void expose_type_specific_functions(py::class_& _class) { typedef py::array_t np_point_t; - OM::FaceHandle (PolyMesh::*add_face_3_vh)(OM::VertexHandle, OM::VertexHandle, OM::VertexHandle ) = &PolyMesh::add_face; OM::FaceHandle (PolyMesh::*add_face_4_vh)(OM::VertexHandle, OM::VertexHandle, OM::VertexHandle, OM::VertexHandle) = &PolyMesh::add_face; - OM::FaceHandle (*add_face_list)(PolyMesh&, const py::list&) = &add_face; _class - .def("add_face", add_face_3_vh) .def("add_face", add_face_4_vh) - .def("add_face", add_face_list) .def("split", [](PolyMesh& _self, OM::EdgeHandle _eh, np_point_t _arr) { _self.split(_eh, Point(_arr.at(0), _arr.at(1), _arr.at(2))); @@ -424,16 +401,10 @@ void expose_type_specific_functions(py::class_& _class) { typedef py::array_t np_point_t; - OM::FaceHandle (TriMesh::*add_face_3_vh)(OM::VertexHandle, OM::VertexHandle, OM::VertexHandle) = &TriMesh::add_face; - OM::FaceHandle (*add_face_list)(TriMesh&, const py::list&) = &add_face; - void (TriMesh::*split_copy_eh_vh)(OM::EdgeHandle, OM::VertexHandle) = &TriMesh::split_copy; OM::HalfedgeHandle (TriMesh::*vertex_split_vh)(OM::VertexHandle, OM::VertexHandle, OM::VertexHandle, OM::VertexHandle) = &TriMesh::vertex_split; _class - .def("add_face", add_face_3_vh) - .def("add_face", add_face_list) - .def("split", [](TriMesh& _self, OM::EdgeHandle _eh, np_point_t _arr) { return _self.split(_eh, Point(_arr.at(0), _arr.at(1), _arr.at(2))); }) @@ -578,6 +549,10 @@ void expose_mesh(py::module& m, const char *_name) { void (*assign_connectivity_poly)(Mesh&, const PolyMesh&) = &assign_connectivity; void (*assign_connectivity_tri )(Mesh&, const TriMesh& ) = &assign_connectivity; + // Adding items to a mesh + OM::FaceHandle (Mesh::*add_face_3_vh)(OM::VertexHandle, OM::VertexHandle, OM::VertexHandle) = &Mesh::add_face; + OM::FaceHandle (Mesh::*add_face_list)(const std::vector&) = &Mesh::add_face; + // Vertex and face valence unsigned int (Mesh::*valence_vh)(OM::VertexHandle) const = &Mesh::valence; unsigned int (Mesh::*valence_fh)(OM::FaceHandle ) const = &Mesh::valence; @@ -807,6 +782,9 @@ void expose_mesh(py::module& m, const char *_name) { .def("assign_connectivity", assign_connectivity_poly) .def("assign_connectivity", assign_connectivity_tri) + .def("add_face", add_face_3_vh) + .def("add_face", add_face_list) + .def("opposite_face_handle", &Mesh::opposite_face_handle) .def("adjust_outgoing_halfedge", &Mesh::adjust_outgoing_halfedge) .def("find_halfedge", &Mesh::find_halfedge) diff --git a/tests/test_python.py b/tests/test_python.py index af555195062e7146056b211e9bd9e228172bc468..1332793ff328d2cb6822fbe7618949f640b38995 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -35,7 +35,9 @@ class Python(unittest.TestCase): # | / \ | # |/ 1 \| # 3 ==== 4 - + + self.assertEqual(self.mesh.n_faces(), 4) + def test_python_iterator(self): # Iterate over all vertices indices = [0, 1, 2, 3, 4]