mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Implement multiprocessing in shape creation for IFC drawings
This commit is contained in:
@@ -4,6 +4,7 @@ import time
|
|||||||
import numpy
|
import numpy
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
|
import multiprocessing
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from OCC.Core import (
|
from OCC.Core import (
|
||||||
@@ -293,9 +294,8 @@ class IfcCutter:
|
|||||||
# TODO: This should perhaps be configurable, e.g. spaces cut to show zones in the drawing
|
# TODO: This should perhaps be configurable, e.g. spaces cut to show zones in the drawing
|
||||||
products.extend(ifc_file.by_type('IfcElement'))
|
products.extend(ifc_file.by_type('IfcElement'))
|
||||||
|
|
||||||
total_products = len(products)
|
include_elements = []
|
||||||
for i, product in enumerate(products):
|
for i, product in enumerate(products):
|
||||||
print('{}/{} geometry processed ...'.format(i, total_products), end='\r', flush=True)
|
|
||||||
if product.is_a('IfcOpeningElement') \
|
if product.is_a('IfcOpeningElement') \
|
||||||
or product.is_a('IfcSite') \
|
or product.is_a('IfcSite') \
|
||||||
or product.Representation is None \
|
or product.Representation is None \
|
||||||
@@ -304,17 +304,33 @@ class IfcCutter:
|
|||||||
try:
|
try:
|
||||||
if self.should_recut_selected \
|
if self.should_recut_selected \
|
||||||
and product.GlobalId in self.selected_global_ids:
|
and product.GlobalId in self.selected_global_ids:
|
||||||
shape = ifcopenshell.geom.create_shape(settings, product).geometry
|
include_elements.append(product)
|
||||||
shape_map[product.GlobalId] = shape
|
|
||||||
elif product.GlobalId in shape_map:
|
elif product.GlobalId in shape_map:
|
||||||
shape = shape_map[product.GlobalId]
|
shape = shape_map[product.GlobalId]
|
||||||
|
self.product_shapes.append((product, shape))
|
||||||
else:
|
else:
|
||||||
shape = ifcopenshell.geom.create_shape(settings, product).geometry
|
include_elements.append(product)
|
||||||
shape_map[product.GlobalId] = shape
|
|
||||||
self.product_shapes.append((product, shape))
|
|
||||||
except:
|
except:
|
||||||
print('Failed to create shape for {}'.format(product))
|
print('Failed to create shape for {}'.format(product))
|
||||||
|
|
||||||
|
if include_elements:
|
||||||
|
total = 0
|
||||||
|
checkpoint = time.time()
|
||||||
|
iterator = ifcopenshell.geom.iterator(
|
||||||
|
settings, ifc_file, multiprocessing.cpu_count(), include=include_elements)
|
||||||
|
valid_file = iterator.initialize()
|
||||||
|
if valid_file:
|
||||||
|
while True:
|
||||||
|
total += 1
|
||||||
|
if total % 250 == 0:
|
||||||
|
print('{} elements processed in {:.2f}s ...'.format(total, time.time() - checkpoint))
|
||||||
|
checkpoint = time.time()
|
||||||
|
shape = iterator.get()
|
||||||
|
shape_map[shape.data.guid] = shape.geometry
|
||||||
|
self.product_shapes.append((ifc_file.by_guid(shape.data.guid), shape.geometry))
|
||||||
|
if not iterator.next():
|
||||||
|
break
|
||||||
|
|
||||||
with open(shape_pickle, 'wb') as shape_file:
|
with open(shape_pickle, 'wb') as shape_file:
|
||||||
pickle.dump(shape_map, shape_file, protocol=pickle.HIGHEST_PROTOCOL)
|
pickle.dump(shape_map, shape_file, protocol=pickle.HIGHEST_PROTOCOL)
|
||||||
|
|
||||||
@@ -688,7 +704,6 @@ class IfcCutter:
|
|||||||
def get_fresh_cut_polygons(self):
|
def get_fresh_cut_polygons(self):
|
||||||
process_data = [(p.GlobalId, s, self.section_box['face'], self.transformation_data) for p, s in self.product_shapes]
|
process_data = [(p.GlobalId, s, self.section_box['face'], self.transformation_data) for p, s in self.product_shapes]
|
||||||
|
|
||||||
import multiprocessing
|
|
||||||
import bpy
|
import bpy
|
||||||
multiprocessing.set_executable(bpy.app.binary_path_python)
|
multiprocessing.set_executable(bpy.app.binary_path_python)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user