47 if (self->
getShapeXML().find(
"infinite") != std::string::npos) {
48 throw std::runtime_error(
"Cannot plot Shapes of infinite extent.");
52 const auto &vertices = localTriangulator.getTriangleVertices();
53 const auto &triangles = localTriangulator.getTriangleFaces();
54 const size_t &numberTriangles = localTriangulator.numTriangleFaces();
55 npy_intp dims[3] = {
static_cast<npy_intp
>(numberTriangles), 3, 3};
57 if (numberTriangles == 0 || vertices.empty() || triangles.empty()) {
61 size_t totalSize = dims[0] * dims[1] * dims[2];
62 auto *meshCoords =
new double[totalSize];
63 std::fill(meshCoords, meshCoords + totalSize, 0.0);
66 for (
size_t corner_index = 0; corner_index < triangles.size() && corner_index < totalSize; ++corner_index) {
67 for (
size_t xyz = 0; xyz < 3; xyz++) {
68 size_t vertex_idx = triangles[corner_index];
69 if (vertex_idx * 3 + xyz < vertices.size()) {
70 meshCoords[3 * corner_index + xyz] = vertices[3 * vertex_idx + xyz];
74 PyObject *ndarray =
Impl::wrapWithNDArray(meshCoords, 3, dims, NumpyWrapMode::ReadOnly, OwnershipMode::Python);
75 return object(handle<>(ndarray));
77 }
catch (
const std::exception &e) {
79 g_log.
error(e.what());
85 register_ptr_to_python<std::shared_ptr<CSGObject>>();
87 class_<CSGObject, boost::python::bases<IObject>, boost::noncopyable>(
"CSGObject", no_init)
89 return_value_policy<copy_const_reference>(),
"Return the axis-aligned bounding box for this shape")
91 .def(
"getShapeXML", &
CSGObject::getShapeXML, arg(
"self"),
"Returns the XML that was used to create this shape.")
93 .def(
"volume", &
CSGObject::volume, arg(
"self"),
"Returns the volume of this shape.")
95 .def(
"getMesh", &
wrapMeshWithNDArray, (arg(
"self")),
"Get the vertices, grouped by triangles, from mesh")
97 .def(
"shapeInfo", &
CSGObject::shapeInfo, arg(
"self"), return_value_policy<copy_const_reference>(),
98 "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.