From b407b815e25db4f11391d0f5a81cee9cc71fe275 Mon Sep 17 00:00:00 2001 From: Vincent Cadoret Date: Sat, 21 Nov 2020 19:17:29 -0500 Subject: [PATCH] Allow selection of max grouping distance in UI --- src/ifcblenderexport/blenderbim/bim/operator.py | 4 ++-- src/ifcblenderexport/blenderbim/bim/prop.py | 1 + src/ifcblenderexport/blenderbim/bim/ui.py | 3 +++ src/ifcclash/ifcclash.py | 8 ++++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 835988c13b..983d804a2d 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1921,7 +1921,7 @@ class SmartClashGroup(bpy.types.Operator): # execute the smart grouping save_path = bpy.path.ensure_ext(bpy.context.scene.BIMProperties.smart_grouped_clashes_path, ".json") - smart_grouped_clashes = ifc_clasher.smart_group_clashes(clash_sets) + smart_grouped_clashes = ifc_clasher.smart_group_clashes(clash_sets, bpy.context.scene.BIMProperties.smart_clash_grouping_max_distance) # save smart_groups to json with open(save_path, 'w') as f: @@ -1965,7 +1965,7 @@ class LoadSmartGroupsForActiveClashSet(bpy.types.Operator): with open(smart_groups_path) as f: smart_grouped_clashes = json.load(f) - # Reset the list of smart_clash_groups for the UI + # Reset the list of smart_clash_groups for the UI bpy.context.scene.BIMProperties.smart_clash_groups.clear() for clash_set, smart_groups in smart_grouped_clashes.items(): diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 62d8baf7ff..2d08aceda3 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -1527,6 +1527,7 @@ class BIMProperties(PropertyGroup): active_clash_set_index: IntProperty(name="Active Clash Set Index") smart_clash_groups: CollectionProperty(name="Smart Clash Groups", type=SmartClashGroup) active_smart_group_index: IntProperty(name="Active Smart Group Index") + smart_clash_grouping_max_distance: IntProperty(name="Smart Clash Grouping Max Distance", default=3, soft_min=1, soft_max=10) constraints: CollectionProperty(name="Constraints", type=Constraint) active_constraint_index: IntProperty(name="Active Constraint Index") eastings: StringProperty(name="Eastings") diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 5162830fa0..799ba296d7 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -2389,6 +2389,9 @@ class BIM_PT_clash_manager(Panel): row.prop(props, "smart_grouped_clashes_path", text="") op = row.operator("bim.select_smart_grouped_clashes_path", icon="FILE_FOLDER", text="") + row = layout.row(align=True) + row.prop(props, "smart_clash_grouping_max_distance") + row = layout.row(align=True) row.operator("bim.smart_clash_group") diff --git a/src/ifcclash/ifcclash.py b/src/ifcclash/ifcclash.py index 0233b6b84a..2e8210dc0d 100644 --- a/src/ifcclash/ifcclash.py +++ b/src/ifcclash/ifcclash.py @@ -268,7 +268,7 @@ class IfcClasher: if element.ObjectPlacement.RelativePlacement.RefDirection: element.ObjectPlacement.RelativePlacement.RefDirection.DirectionRatios = (1.0, 0.0, 0.0) - def smart_group_clashes(self, clash_sets): + def smart_group_clashes(self, clash_sets, max_clustering_distance): count_of_input_clashes = 0 count_of_clash_sets = 0 count_of_smart_groups = 0 @@ -291,7 +291,11 @@ class IfcClasher: # INPUTS # set the desired maximum distance between the grouped points - max_distance_between_grouped_points = 3 + if max_clustering_distance > 0: + max_distance_between_grouped_points = max_clustering_distance + else: + max_distance_between_grouped_points = 3 + model = OPTICS(min_samples=2, max_eps=max_distance_between_grouped_points) model.fit_predict(data) pred = model.fit_predict(data)