From 4013a7e8b7e7b9ce3657dd87b8ccdc1c01eab549 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 22 Oct 2020 13:01:04 +1100 Subject: [PATCH] IFC Clash now uses iterator filters for faster clashing when using filters --- src/ifcclash/ifcclash.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/ifcclash/ifcclash.py b/src/ifcclash/ifcclash.py index 2db8a567b6..9a10a650b5 100644 --- a/src/ifcclash/ifcclash.py +++ b/src/ifcclash/ifcclash.py @@ -37,8 +37,6 @@ class IfcClasher: for data in clash_set[ab]: data['ifc'] = ifcopenshell.open(data['file']) self.patch_ifc(data['ifc']) - self.settings.logger.info(f'Purging unnecessary elements {ab} ...') - self.purge_elements(data) self.settings.logger.info(f'Creating collision data for {ab} ...') if len(data['ifc'].by_type('IfcElement')) > 0: self.add_collision_objects(data, clash_set[f'{ab}_cm']) @@ -170,27 +168,18 @@ class IfcClasher: except: pass - def purge_elements(self, data): - if 'selector' not in data: - for element in data['ifc'].by_type('IfcSpace'): - data['ifc'].remove(element) - return - - selector = ifcopenshell.util.selector.Selector() - elements = selector.parse(data['ifc'], data['selector']) - - if data['mode'] == 'e': - for element in data['ifc'].by_type('IfcElement') + data['ifc'].by_type('IfcSpatialStructureElement'): - if element in elements: - data['ifc'].remove(element) - elif data['mode'] == 'i': - for element in data['ifc'].by_type('IfcElement') + data['ifc'].by_type('IfcSpatialStructureElement'): - if element not in elements: - data['ifc'].remove(element) - def add_collision_objects(self, data, cm): self.clash_data['meshes'] = {} - iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count()) + selector = ifcopenshell.util.selector.Selector() + if 'selector' not in data: + iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count(), + exclude=(data['ifc'].by_type('IfcSpatialStructureElement'))) + elif data['mode'] == 'e': + iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count(), + exclude=selector.parse(data['ifc'], data['selector'])) + elif data['mode'] == 'i': + iterator = ifcopenshell.geom.iterator(self.geom_settings, data['ifc'], multiprocessing.cpu_count(), + include=selector.parse(data['ifc'], data['selector'])) valid_file = iterator.initialize() if not valid_file: return False