Release GIL in some cases

This commit is contained in:
Thomas Krijnen
2024-02-18 12:03:53 +01:00
parent c72f97225f
commit d04357933b
+27 -4
View File
@@ -673,7 +673,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
%inline %{ %inline %{
IfcGeom::ConversionResultShape* nary_union(PyObject* sequence) { IfcGeom::ConversionResultShape* nary_union(PyObject* sequence) {
CGAL::Nef_nary_union_3< CGAL::Nef_polyhedron_3<CGAL::Epeck> > accum; std::vector<const CGAL::Nef_polyhedron_3<CGAL::Epeck>*> nefs;
for(Py_ssize_t i = 0; i < PySequence_Size(sequence); ++i) { for(Py_ssize_t i = 0; i < PySequence_Size(sequence); ++i) {
PyObject* element = PySequence_GetItem(sequence, i); PyObject* element = PySequence_GetItem(sequence, i);
void* argp1 = nullptr; void* argp1 = nullptr;
@@ -682,30 +682,53 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
auto arg1 = reinterpret_cast<IfcGeom::ConversionResultShape*>(argp1); auto arg1 = reinterpret_cast<IfcGeom::ConversionResultShape*>(argp1);
auto cgs = dynamic_cast<ifcopenshell::geometry::CgalShape*>(arg1); auto cgs = dynamic_cast<ifcopenshell::geometry::CgalShape*>(arg1);
if (cgs) { if (cgs) {
accum.add_polyhedron(cgs->nef()); nefs.push_back(&cgs->nef());
} }
} }
} }
return new ifcopenshell::geometry::CgalShape(accum.get_union()); ifcopenshell::geometry::CgalShape* shp;
Py_BEGIN_ALLOW_THREADS;
CGAL::Nef_nary_union_3< CGAL::Nef_polyhedron_3<CGAL::Epeck> > accum;
for (auto& n : nefs) {
accum.add_polyhedron(*n);
}
shp = new ifcopenshell::geometry::CgalShape(accum.get_union());
Py_END_ALLOW_THREADS;
return shp;
} }
%} %}
%extend IfcGeom::ConversionResultShape { %extend IfcGeom::ConversionResultShape {
std::string serialize_obj() { std::string serialize_obj() {
std::ostringstream result; std::ostringstream result;
auto cgs = dynamic_cast<ifcopenshell::geometry::CgalShape*>(self); auto cgs = dynamic_cast<ifcopenshell::geometry::CgalShape*>($self);
if (cgs) { if (cgs) {
write_to_obj(cgs->nef(), result, std::numeric_limits<size_t>::max()); write_to_obj(cgs->nef(), result, std::numeric_limits<size_t>::max());
} }
return result.str(); return result.str();
} }
void convex_tag(bool b) {
auto cgs = dynamic_cast<ifcopenshell::geometry::CgalShape*>($self);
if (cgs) {
cgs->convex_tag() = b;
}
}
std::string serialize() { std::string serialize() {
std::string result; std::string result;
ifcopenshell::geometry::taxonomy::matrix4 iden; ifcopenshell::geometry::taxonomy::matrix4 iden;
$self->Serialize(iden, result); $self->Serialize(iden, result);
return result; return result;
} }
ConversionResultShape* solid_mt() {
IfcGeom::ConversionResultShape* r;
Py_BEGIN_ALLOW_THREADS;
r = $self->solid();
Py_END_ALLOW_THREADS;
return r;
}
} }
%naturalvar svgfill::polygon_2::boundary; %naturalvar svgfill::polygon_2::boundary;