GHDoc-temp

Structure and Clustering Logic

System Overview

This system is designed for analyzing and clustering three-dimensional objects (boxes):

  1. StructureObjects.py - base class for working with geometric objects
  2. ClusteringAndFiltering.py - clustering and filtering algorithms

StructureObjects.py Module

Structure Class

Main class for working with three-dimensional objects (boxes).

Constructor

def __init__(self, geometry):

Accepts a geometric object (box) and initializes all properties:

Geometry Analysis Methods

_get_longest_edge()

Finds the longest edge of the box among 12 possible edges:

_get_normalized_vector()

Computes the normalized direction vector of the longest edge (length = 1).

_get_centered_longest_edge()

Moves the longest edge so that its center coincides with the object center.

_get_center()

Computes the box center as the arithmetic mean of all 8 corners.

_get_dimensions()

Computes box dimensions:

_get_surface_area()

Computes surface area using the formula: 2 * (length*width + length*height + width*height)

get_all_edges()

Returns all box edges with their lengths and indices.

ClusteringAndFiltering.py Module

Alignment Filtering

filter_structures_by_z_alignment()

Filters structures based on perpendicularity to the Z axis:

Spatial Optimization

create_spatial_grid()

Creates a three-dimensional grid for fast neighbor search:

get_neighboring_cells()

Returns coordinates of neighboring cells within a given radius.

get_candidate_neighbors_from_grid()

Gets a list of neighbor candidates for a given structure from the spatial grid.

DBSCAN Clustering Algorithm

dbscan_structures_by_centered_edges()

Implements the DBSCAN algorithm for structure clustering:

Parameters:

Algorithm:

  1. Creates a spatial grid for optimization
  2. For each structure, finds neighbors through region_query()
  3. If number of neighbors ≥ min_pts, creates a new cluster
  4. Expands cluster through breadth-first search
  5. Structures without sufficient neighbors are marked as noise (-1)

Distance Function:

def structure_distance(structA, structB):

Computes the minimum distance between centered_longest_edge of two structures through:

Cluster Filtering

filter_clusters_by_properties()

Filters clusters based on object properties:

Filtering Criteria:

filter_clusters_by_z_height()

Filters objects in clusters by Z coordinate height:

Analysis and Statistics

get_cluster_statistics()

Computes detailed statistics for clusters:

Grasshopper Export

create_structure_clusters_tree()

Creates a Grasshopper tree from object geometry, grouped by clusters.

create_centered_edges_tree()

Creates a Grasshopper tree from centered_longest_edge objects, grouped by clusters.

Main Execution Logic

  1. Creating Structure objects from input boxes
  2. Alignment filtering - only horizontally oriented structures remain
  3. DBSCAN clustering - grouping structures by spatial proximity
  4. Cluster filtering by properties (size, surface area, etc.)
  5. Height filtering - removing objects with significantly different heights
  6. Exporting results as Grasshopper trees

Configuration Parameters

Output Data