From 0fcf99dc566d7098d3d170fa1ef12586002e17d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 4 Sep 2019 15:24:37 +0200 Subject: [PATCH] some native mesh access functions --- libsrc/meshing/python_mesh.cpp | 108 +++++++++++++++++---------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index dc28bab1..1717d56a 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -250,24 +250,24 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init>()) .def("__str__", &ToString) .def("__repr__", &ToString) - .def_property_readonly("p", FunctionPointer([](const MeshPoint & self) - { - py::list l; - l.append ( py::cast(self[0]) ); - l.append ( py::cast(self[1]) ); - l.append ( py::cast(self[2]) ); - return py::tuple(l); - })) - .def("__getitem__", FunctionPointer([](const MeshPoint & self, int index) { + .def_property_readonly("p", [](const MeshPoint & self) + { + py::list l; + l.append ( py::cast(self[0]) ); + l.append ( py::cast(self[1]) ); + l.append ( py::cast(self[2]) ); + return py::tuple(l); + }) + .def("__getitem__", [](const MeshPoint & self, int index) { if(index<0 || index>2) throw py::index_error(); return self[index]; - })) - .def("__setitem__", FunctionPointer([](MeshPoint & self, int index, double val) { + }) + .def("__setitem__", [](MeshPoint & self, int index, double val) { if(index<0 || index>2) throw py::index_error(); self(index) = val; - })) + }) ; py::class_(m, "Element3D") @@ -753,52 +753,54 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def("GetNCD2Names", &Mesh::GetNCD2Names) - .def("__getitem__", FunctionPointer ([](const Mesh & self, PointIndex pi) - { - return self[pi]; - })) + .def("__getitem__", [](const Mesh & self, PointIndex id) { return self[id]; }) + .def("__getitem__", [](const Mesh & self, ElementIndex id) { return self[id]; }) + .def("__getitem__", [](const Mesh & self, SurfaceElementIndex id) { return self[id]; }) + .def("__getitem__", [](const Mesh & self, SegmentIndex id) { return self[id]; }) - .def ("Add", FunctionPointer ([](Mesh & self, MeshPoint p) - { - return self.AddPoint (Point3d(p)); - })) - - .def ("Add", FunctionPointer ([](Mesh & self, const Element & el) - { - return self.AddVolumeElement (el); - })) - - .def ("Add", FunctionPointer ([](Mesh & self, const Element2d & el) - { - return self.AddSurfaceElement (el); - })) - - .def ("Add", FunctionPointer ([](Mesh & self, const Segment & el) - { - return self.AddSegment (el); - })) + .def("__setitem__", [](Mesh & self, PointIndex id, const MeshPoint & mp) { return self[id] = mp; }) - .def ("Add", FunctionPointer ([](Mesh & self, const Element0d & el) - { - return self.pointelements.Append (el); - })) + .def ("Add", [](Mesh & self, MeshPoint p) + { + return self.AddPoint (Point3d(p)); + }) + + .def ("Add", [](Mesh & self, const Element & el) + { + return self.AddVolumeElement (el); + }) + + .def ("Add", [](Mesh & self, const Element2d & el) + { + return self.AddSurfaceElement (el); + }) - .def ("Add", FunctionPointer ([](Mesh & self, const FaceDescriptor & fd) - { - return self.AddFaceDescriptor (fd); - })) + .def ("Add", [](Mesh & self, const Segment & el) + { + return self.AddSegment (el); + }) + + .def ("Add", [](Mesh & self, const Element0d & el) + { + return self.pointelements.Append (el); + }) + + .def ("Add", [](Mesh & self, const FaceDescriptor & fd) + { + return self.AddFaceDescriptor (fd); + }) .def ("DeleteSurfaceElement", - FunctionPointer ([](Mesh & self, SurfaceElementIndex i) - { - return self.Delete(i); - })) - - .def ("Compress", FunctionPointer ([](Mesh & self) - { - return self.Compress (); - }),py::call_guard()) - + [](Mesh & self, SurfaceElementIndex i) + { + return self.Delete(i); + }) + + .def ("Compress", [](Mesh & self) + { + return self.Compress (); + } ,py::call_guard()) + .def ("SetBCName", &Mesh::SetBCName) .def ("GetBCName", FunctionPointer([](Mesh & self, int bc)->string