This system is designed for analyzing and clustering three-dimensional objects (boxes):
Main class for working with three-dimensional objects (boxes).
def __init__(self, geometry):
Accepts a geometric object (box) and initializes all properties:
geometry
- original geometrycorners
- box corners (8 points)center
- object centerlongest_edge
- longest edgenormalized_vector
- normalized direction vectorcentered_longest_edge
- longest edge moved to centervolume
- volumedimensions
- dimensions (length, width, height)surface_area
- surface area_get_longest_edge()
Finds the longest edge of the box among 12 possible edges:
(0,1), (1,2), (2,3), (3,0)
(4,5), (5,6), (6,7), (7,4)
(0,4), (1,5), (2,6), (3,7)
_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.
filter_structures_by_z_alignment()
Filters structures based on perpendicularity to the Z axis:
normalized_vector
and Z vector (0,0,1)
create_spatial_grid()
Creates a three-dimensional grid for fast neighbor search:
grid_size
centered_longest_edge
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_structures_by_centered_edges()
Implements the DBSCAN algorithm for structure clustering:
Parameters:
eps
- neighbor search radiusmin_pts
- minimum number of neighbors for a core pointgrid_size
- spatial grid cell sizeAlgorithm:
region_query()
min_pts
, creates a new clusterDistance Function:
def structure_distance(structA, structB):
Computes the minimum distance between centered_longest_edge
of two structures through:
filter_clusters_by_properties()
Filters clusters based on object properties:
Filtering Criteria:
volume
: volume range (min, max)surface_area
: surface area range (min, max)dimensions
: dimension ranges (length, width, height)longest_edge_length
: longest edge length rangemin_cluster_size
: minimum number of objects in clustermax_cluster_size
: maximum number of objects in clusterfilter_clusters_by_z_height()
Filters objects in clusters by Z coordinate height:
get_cluster_statistics()
Computes detailed statistics for clusters:
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.
Z_TOLERANCE
- acceptable deviation for Z alignment filteringDBSCAN_EPS
- neighbor search radius for DBSCANDBSCAN_MIN_PTS
- minimum number of neighbors for a core pointGRID_SIZE
- spatial grid cell sizeMAX_HEIGHT_DIFFERENCE_PERCENT
- maximum height difference in percentageout_structure_clusters_box
- tree with cluster geometryout_structure_clusters_line
- tree with centered_longest_edge clusterscluster_statistics
- JSON statistics for clusters (optional)