mesh point coordinates as numpy - array

This commit is contained in:
Joachim Schoeberl 2022-04-12 07:05:32 +02:00
parent 8c7d69c1d1
commit c29e93dd2b

View File

@ -854,6 +854,26 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
static_cast<Mesh::T_POINTS&(Mesh::*)()> (&Mesh::Points),
py::return_value_policy::reference)
.def("Coordinates", [](Mesh & self) {
size_t shape[2] = { self.Points().Size(), size_t(self.GetDimension()) };
size_t stride[2] = { sizeof(self.Points()[0]), sizeof(double) };
return py::memoryview::from_buffer
(&self.Points()[PointIndex::BASE](0), sizeof(double),
py::format_descriptor<double>::value,
{ self.Points().Size(), size_t(self.GetDimension()) },
{ sizeof(self.Points()[1]), sizeof(double) } );
/*
// how to avoid copying array ?
return py::array
(
shape, stride,
&self.Points()[PointIndex::BASE](0) // , borrowed_t{} // how to use borrow ?
);
*/
})
.def("FaceDescriptor", static_cast<FaceDescriptor&(Mesh::*)(int)> (&Mesh::GetFaceDescriptor),
py::return_value_policy::reference)
.def("GetNFaceDescriptors", &Mesh::GetNFD)