Skip to content

Commit abfa6ed

Browse files
committed
Add buffer (bytestring) accessors to geometry data
1 parent e3a1c29 commit abfa6ed

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/ifcwrap/IfcGeomWrapper.i

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
}
5959
}
6060

61+
%inline %{
62+
template <typename T>
63+
std::pair<char const*, size_t> vector_to_buffer(const T& t) {
64+
using V = typename std::remove_reference<decltype(t)>::type;
65+
return { reinterpret_cast<const char*>(t.data()), t.size() * sizeof(V::value_type) };
66+
}
67+
%}
68+
6169
%include "../ifcgeom_schema_agnostic/ifc_geom_api.h"
6270
%include "../ifcgeom_schema_agnostic/IfcGeomIteratorSettings.h"
6371
%include "../ifcgeom_schema_agnostic/IfcGeomElement.h"
@@ -234,6 +242,31 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
234242
%}
235243

236244
%extend IfcGeom::Representation::Triangulation {
245+
246+
std::pair<const char*, size_t> faces_buffer() const {
247+
return vector_to_buffer(self->faces());
248+
}
249+
250+
std::pair<const char*, size_t> edges_buffer() const {
251+
return vector_to_buffer(self->edges());
252+
}
253+
254+
std::pair<const char*, size_t> material_ids_buffer() const {
255+
return vector_to_buffer(self->material_ids());
256+
}
257+
258+
std::pair<const char*, size_t> item_ids_buffer() const {
259+
return vector_to_buffer(self->item_ids());
260+
}
261+
262+
std::pair<const char*, size_t> verts_buffer() const {
263+
return vector_to_buffer(self->verts());
264+
}
265+
266+
std::pair<const char*, size_t> normals_buffer() const {
267+
return vector_to_buffer(self->normals());
268+
}
269+
237270
%pythoncode %{
238271
# Hide the getters with read-only property implementations
239272
id = property(id)
@@ -242,16 +275,16 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
242275
material_ids = property(material_ids)
243276
materials = property(materials)
244277
item_ids = property(item_ids)
245-
%}
246-
};
247-
248-
// Specialized accessors follow later, for otherwise property definitions
249-
// would appear before templated getter functions are defined.
250-
%extend IfcGeom::Representation::Triangulation {
251-
%pythoncode %{
252278
# Hide the getters with read-only property implementations
253279
verts = property(verts)
254280
normals = property(normals)
281+
282+
faces_buffer = property(faces_buffer)
283+
edges_buffer = property(edges_buffer)
284+
material_ids_buffer = property(material_ids_buffer)
285+
item_ids_buffer = property(item_ids_buffer)
286+
verts_buffer = property(verts_buffer)
287+
normals = property(normals)
255288
%}
256289
};
257290

@@ -266,6 +299,9 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
266299
};
267300

268301
%extend IfcGeom::Element {
302+
std::pair<const char*, size_t> transformation_buffer() const {
303+
return vector_to_buffer(self->transformation().matrix().data());
304+
}
269305

270306
IfcUtil::IfcBaseClass* product_() const {
271307
return $self->product();
@@ -282,6 +318,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
282318
unique_id = property(unique_id)
283319
transformation = property(transformation)
284320
product = property(product_)
321+
transformation_buffer = property(transformation_buffer)
285322
%}
286323

287324
};

src/ifcwrap/utils/typemaps_out.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@ CREATE_VECTOR_TYPEMAP_OUT(IfcParse::attribute const *)
146146
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::inverse_attribute const *)
147147
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::entity const *)
148148
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::declaration const *)
149+
150+
%typemap(out) std::pair<const char*, size_t> {
151+
$result = PyBytes_FromStringAndSize($1.first, $1.second);
152+
}

0 commit comments

Comments
 (0)