diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 5f1cc3aebd..8811ae6a4b 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -79,6 +79,14 @@ %newobject IfcGeom::OpaqueNumber::operator*; %newobject IfcGeom::OpaqueNumber::operator/; +%inline %{ +template +std::pair vector_to_buffer(const T& t) { + using V = typename std::remove_reference::type; + return { reinterpret_cast(t.data()), t.size() * sizeof(V::value_type) }; +} +%} + %include "../ifcgeom/ifc_geom_api.h" %include "../ifcgeom/Converter.h" %include "../ifcgeom/ConversionResult.h" @@ -288,6 +296,31 @@ struct ShapeRTTI : public boost::static_visitor %} %extend IfcGeom::Representation::Triangulation { + + std::pair faces_buffer() const { + return vector_to_buffer(self->faces()); + } + + std::pair edges_buffer() const { + return vector_to_buffer(self->edges()); + } + + std::pair material_ids_buffer() const { + return vector_to_buffer(self->material_ids()); + } + + std::pair item_ids_buffer() const { + return vector_to_buffer(self->item_ids()); + } + + std::pair verts_buffer() const { + return vector_to_buffer(self->verts()); + } + + std::pair normals_buffer() const { + return vector_to_buffer(self->normals()); + } + %pythoncode %{ # Hide the getters with read-only property implementations id = property(id) @@ -298,6 +331,13 @@ struct ShapeRTTI : public boost::static_visitor verts = property(verts) normals = property(normals) item_ids = property(item_ids) + + faces_buffer = property(faces_buffer) + edges_buffer = property(edges_buffer) + material_ids_buffer = property(material_ids_buffer) + item_ids_buffer = property(item_ids_buffer) + verts_buffer = property(verts_buffer) + normals = property(normals) %} }; @@ -312,12 +352,17 @@ struct ShapeRTTI : public boost::static_visitor }; %extend IfcGeom::Element { + std::pair transformation_buffer() const { + // @todo check whether needs to be transposed + const double* data = self->transformation().data()->ccomponents().data(); + return { reinterpret_cast(data), 16 * sizeof(double) }; + } - const IfcUtil::IfcBaseClass* product_() const { - return $self->product(); - } + const IfcUtil::IfcBaseClass* product_() const { + return $self->product(); + } - %pythoncode %{ + %pythoncode %{ # Hide the getters with read-only property implementations id = property(id) parent_id = property(parent_id) @@ -328,8 +373,9 @@ struct ShapeRTTI : public boost::static_visitor unique_id = property(unique_id) transformation = property(transformation) product = property(product_) - %} + transformation_buffer = property(transformation_buffer) + %} }; %extend IfcGeom::TriangulationElement { diff --git a/src/ifcwrap/utils/typemaps_out.i b/src/ifcwrap/utils/typemaps_out.i index 579a94a237..9c821ed3b5 100644 --- a/src/ifcwrap/utils/typemaps_out.i +++ b/src/ifcwrap/utils/typemaps_out.i @@ -157,3 +157,7 @@ CREATE_VECTOR_TYPEMAP_OUT(IfcGeom::ConversionResultShape *) pythonizing_visitor vis; $result = $1.apply_visitor(vis); } + +%typemap(out) std::pair { + $result = PyBytes_FromStringAndSize($1.first, $1.second); +}