13#include <boost/python/class.hpp>
14#include <boost/python/copy_const_reference.hpp>
15#include <boost/python/register_ptr_to_python.hpp>
16#include <boost/python/self.hpp>
17#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
18#define PY_ARRAY_UNIQUE_SYMBOL GEOMETRY_ARRAY_API
19#define NO_IMPORT_ARRAY
20#include <numpy/arrayobject.h>
31 const auto &vertices = self.getV3Ds();
32 const auto &triangles = self.getTriangles();
33 const size_t &numberTriangles = triangles.size() / 3;
34 npy_intp dims[3] = {
static_cast<int>(numberTriangles), 3, 3};
35 auto *meshCoords =
new double[dims[0] * dims[1] * dims[2]];
36 for (
size_t iTriangle = 0; iTriangle < numberTriangles; ++iTriangle) {
37 for (
size_t corner = 0; corner < 3; corner++) {
38 auto coords = std::vector<double>(vertices[triangles[(3 * iTriangle) + corner]]);
39 for (
size_t xyz = 0; xyz < 3; xyz++) {
40 meshCoords[iTriangle * 3 * 3 + corner * 3 + xyz] = coords[xyz];
44 PyObject *ndarray =
Impl::wrapWithNDArray(meshCoords, 3, dims, NumpyWrapMode::ReadWrite, OwnershipMode::Python);
46 return boost::python::object(handle<>(ndarray));
50 register_ptr_to_python<MeshObject *>();
52 class_<MeshObject, boost::python::bases<IObject>, boost::noncopyable>(
"MeshObject", no_init)
53 .def(
"getMesh", &
wrapMeshWithNDArray, (arg(
"self")),
"Get the vertices, grouped by triangles, from mesh");
#define GET_POINTER_SPECIALIZATION(TYPE)
boost::python::object wrapMeshWithNDArray(MeshObject &self)
IObject : Interface for geometry objects.
PyObject * wrapWithNDArray(const ElementType *, const int ndims, Py_intptr_t *dims, const NumpyWrapMode mode, const OwnershipMode oMode=OwnershipMode::Cpp)
Defines the wrapWithNDArray specialization for C array types.