From d9247d094bc2fe6e0d9ab24b5d078c7f1a7b0e80 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 26 Aug 2024 11:49:35 +0200 Subject: [PATCH] netgen trafo.mat returns Mat<3,3> and takes Mat<3,3> --- libsrc/meshing/python_mesh.cpp | 36 ++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 024a56db..70b762e8 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -179,6 +179,34 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::implicitly_convertible>(); + py::class_>(m, "Mat33") + .def(py::init([](py::tuple m) + { + if(m.size() != 9) + throw std::length_error("Invalid dimension of input array!"); + Mat<3,3> mat; + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) + mat(i,j) = m[i*3+j].cast(); + return mat; + })) + .def("__getitem__", [](Mat<3,3>& mat, py::tuple index) + { + if(index.size() != 2) + throw std::length_error("Invalid dimension of input array!"); + return mat(index[0].cast(), index[1].cast()); + }) + .def("__setitem__", [](Mat<3,3>& mat, py::tuple index, double val) + { + if(index.size() != 2) + throw std::length_error("Invalid dimension of input array!"); + mat(index[0].cast(), index[1].cast()) = val; + }) + .def("__str__", &ToString>) + ; + + py::implicitly_convertible>(); + m.def ("Vec", FunctionPointer ([] (double x, double y, double z) { return global_trafo(Vec<3>(x,y,z)); })); m.def("Vec", [](py::array_t np_array) @@ -204,13 +232,9 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) { Transformation<3> res; res.Combine(a,b); return res; }) .def("__call__", [] (Transformation<3> trafo, Point<3> p) { return trafo(p); }) .def_property("mat", &Transformation<3>::GetMatrix, - [](Transformation<3>& self, py::array_t np_mat) + [](Transformation<3>& self, const Mat<3,3>& mat) { - if(np_mat.size() != 9) - throw Exception("Invalid dimension of input array!"); - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - self.GetMatrix()(i,j) = np_mat.at(i*3+j); + self.GetMatrix() = mat; }) ;