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>
19#include <numpy/arrayobject.h>
21#define PY_ARRAY_UNIQUE_SYMBOL GEOMETRY_ARRAY_API
22#define NO_IMPORT_ARRAY
36 if (self->getShapeXML().find(
"infinite") != std::string::npos) {
37 throw std::runtime_error(
"Cannot plot Shapes of infinite extent.");
40 const auto &vertices = localTriangulator.getTriangleVertices();
41 const auto &triangles = localTriangulator.getTriangleFaces();
42 const size_t &numberTriangles = localTriangulator.numTriangleFaces();
43 npy_intp dims[3] = {
static_cast<int>(numberTriangles), 3, 3};
44 auto *meshCoords =
new double[dims[0] * dims[1] * dims[2]];
45 for (
size_t corner_index = 0; corner_index < triangles.size(); ++corner_index) {
46 for (
size_t xyz = 0; xyz < 3; xyz++) {
47 meshCoords[3 * corner_index + xyz] = vertices[3 * triangles[corner_index] + xyz];
51 PyObject *ndarray =
Impl::wrapWithNDArray(meshCoords, 3, dims, NumpyWrapMode::ReadWrite, OwnershipMode::Python);
52 return object(handle<>(ndarray));
56 register_ptr_to_python<std::shared_ptr<CSGObject>>();
58 class_<CSGObject, boost::python::bases<IObject>, boost::noncopyable>(
"CSGObject", no_init)
60 return_value_policy<copy_const_reference>(),
"Return the axis-aligned bounding box for this shape")
62 .def(
"getShapeXML", &
CSGObject::getShapeXML, arg(
"self"),
"Returns the XML that was used to create this shape.")
64 .def(
"volume", &
CSGObject::volume, arg(
"self"),
"Returns the volume of this shape.")
66 .def(
"getMesh", &
wrapMeshWithNDArray, (arg(
"self")),
"Get the vertices, grouped by triangles, from mesh");
#define GET_POINTER_SPECIALIZATION(TYPE)
boost::python::object wrapMeshWithNDArray(const CSGObject *self)
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Constructive Solid Geometry object.
const BoundingBox & getBoundingBox() const override
Return cached value of axis-aligned bounding box.
double volume() const override
Calculates the volume of this object.
std::string getShapeXML() const
Getter for the shape xml.
IObject : Interface for geometry objects.
GeometryTriangulator : Triangulates object surfaces.
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.