47 if (self->
getShapeXML().find(
"infinite") != std::string::npos) {
48 throw std::runtime_error(
"Cannot plot Shapes of infinite extent.");
53 std::unique_ptr<GeometryTriangulator> localTriangulator;
55 if (triangleFaces->empty() || vertices->empty()) {
56 localTriangulator = std::make_unique<GeometryTriangulator>(self);
57 vertices = &localTriangulator->getTriangleVertices();
58 triangleFaces = &localTriangulator->getTriangleFaces();
59 if (triangleFaces->empty() || vertices->empty()) {
64 const size_t numberTriangles = triangleFaces->size() / 3;
65 npy_intp dims[3] = {
static_cast<npy_intp
>(numberTriangles), 3, 3};
66 auto *meshCoords =
new double[numberTriangles * 9];
68 const size_t vertexCapacity = vertices->size();
69 for (
size_t corner = 0; corner < triangleFaces->size(); ++corner) {
70 const size_t src =
static_cast<size_t>((*triangleFaces)[corner]) * 3;
71 const size_t dst = corner * 3;
72 if (src + 2 < vertexCapacity) {
73 meshCoords[dst] = (*vertices)[src];
74 meshCoords[dst + 1] = (*vertices)[src + 1];
75 meshCoords[dst + 2] = (*vertices)[src + 2];
77 meshCoords[dst] = 0.0;
78 meshCoords[dst + 1] = 0.0;
79 meshCoords[dst + 2] = 0.0;
83 PyObject *ndarray =
Impl::wrapWithNDArray(meshCoords, 3, dims, NumpyWrapMode::ReadOnly, OwnershipMode::Python);
84 return object(handle<>(ndarray));
86 }
catch (
const std::exception &e) {
87 g_log.
error(e.what());
93 register_ptr_to_python<std::shared_ptr<CSGObject>>();
95 class_<CSGObject, boost::python::bases<IObject>, boost::noncopyable>(
"CSGObject", no_init)
97 return_value_policy<copy_const_reference>(),
"Return the axis-aligned bounding box for this shape")
99 .def(
"getShapeXML", &
CSGObject::getShapeXML, arg(
"self"),
"Returns the XML that was used to create this shape.")
101 .def(
"volume", &
CSGObject::volume, arg(
"self"),
"Returns the volume of this shape.")
103 .def(
"getMesh", &
wrapMeshWithNDArray, (arg(
"self")),
"Get the vertices, grouped by triangles, from mesh")
105 .def(
"shapeInfo", &
CSGObject::shapeInfo, arg(
"self"), return_value_policy<copy_const_reference>(),
106 "Get the shape information for this object");
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.