Skip to content

Commit 9d65b55

Browse files
author
Gemini
committed
Refactored helper.py
1 parent 3cd69d1 commit 9d65b55

File tree

9 files changed

+500
-389
lines changed

9 files changed

+500
-389
lines changed

examples/UFO/UFO.lpy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import time
88
from helper import *
99
import numpy as np
1010
import random as rd
11-
from examples.UFO.UFOconfigs import basicwood_prototypes, Trunk, Branch, TertiaryBranch, Spur, UFOSimulationConfig, generate_points_ufo
11+
from examples.UFO.UFO_prototypes import basicwood_prototypes, Trunk
12+
from examples.UFO.UFO_simulation import UFOSimulationConfig, generate_points_ufo, get_energy_mat, decide_guide, tie, prune
1213
from dataclasses import dataclass
1314

1415

@@ -20,7 +21,7 @@ simulation_config = UFOSimulationConfig()
2021

2122

2223

23-
trellis_support = Support(generate_points_ufo(), simulation_config.support_num_wires, simulation_config.support_spacing_wires, simulation_config.support_trunk_wire_point)
24+
trellis_support = Support(generate_points_ufo(simulation_config), simulation_config.support_num_wires, simulation_config.support_spacing_wires, simulation_config.support_trunk_wire_point)
2425
tying_interval_iterations = simulation_config.num_iteration_tie
2526
pruning_interval_iterations = simulation_config.num_iteration_prune
2627
main_trunk.tying.guide_target = trellis_support.trunk_wire
@@ -150,7 +151,7 @@ module WoodStart # Starting point of wood segments (used for tying operation
150151
# GLOBAL L-SYSTEM PARAMETERS
151152
# -----------------------------------------------------------------------------
152153
# Create a growth guide curve for the initial trunk development
153-
trunk_guide_curve = create_bezier_curve(x_range = (-1, 1), y_range = (-1, 1), z_range = (0, 10), seed_val=time.time())
154+
trunk_guide_curve = create_bezier_curve(x_range = (-1, 1), y_range = (-1, 1), z_range = (0, 10), seed_value=time.time())
154155

155156
# -----------------------------------------------------------------------------
156157
# AXIOM (STARTING STRING)
@@ -223,7 +224,7 @@ bud(bud_parameters) :
223224
if hasattr(new_branch, 'curve_x_range'):
224225
# Curved branches: set up custom growth guide curve
225226
import time
226-
curve = create_bezier_curve(x_range=new_branch.curve_x_range, y_range=new_branch.curve_y_range, z_range=new_branch.curve_z_range, seed_val=time.time())
227+
curve = create_bezier_curve(x_range=new_branch.curve_x_range, y_range=new_branch.curve_y_range, z_range=new_branch.curve_z_range, seed_value=time.time())
227228
nproduce[@GcSetGuide(curve, new_branch.growth.max_length)
228229
else:
229230
# Straight branches: use default orientation

examples/UFO/UFOconfigs.py renamed to examples/UFO/UFO_prototypes.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -146,75 +146,4 @@ def create_branch(self):
146146

147147

148148

149-
@dataclass
150-
class UFOSimulationConfig:
151-
"""Configuration for UFO trellis tree simulation parameters."""
152-
153-
# Tying and Pruning
154-
num_iteration_tie: int = 8
155-
num_iteration_prune: int = 16
156-
157-
# Display
158-
label: bool = True
159-
160-
# Support Structure
161-
support_trunk_wire_point: tuple = (0.6, 0, 0.4)
162-
support_num_wires: int = 7
163-
support_spacing_wires: int = 1
164-
165-
# Point Generation
166-
ufo_x_range: tuple = (0.65, 3)
167-
ufo_x_spacing: float = 0.3
168-
ufo_z_value: float = 1.4
169-
ufo_y_value: float = 0
170-
171-
# Energy and Tying Parameters
172-
energy_distance_weight: float = 0.5 # Weight for distance in energy calculation (was hardcoded /2)
173-
energy_threshold: float = 1.0 # Maximum energy threshold for tying
174-
175-
# Pruning Parameters
176-
pruning_age_threshold: int = 8 # Age threshold for pruning untied branches
177-
178-
# L-System Parameters
179-
derivation_length: int = 160 # Number of derivation steps
180-
181-
# Growth Parameters
182-
thickness_multiplier: float = 1.2 # Multiplier for internode thickness
183-
bud_age_tolerance: float = 0.01 # Tolerance for age-based bud spacing
184-
185-
# Visualization Parameters
186-
attractor_point_width: int = 10 # Width of attractor points in visualization
187-
188-
def generate_points_ufo():
189-
"""
190-
Generate 3D points for the UFO trellis wire structure.
191-
192-
Creates a linear array of wire attachment points along the x-axis at a fixed
193-
height (z) and depth (y). The points are spaced evenly within the configured
194-
x-range and used to construct the trellis support structure.
195-
196-
Returns:
197-
list: List of (x, y, z) tuples representing wire attachment points,
198-
where all points share the same y and z coordinates.
199-
200-
Configuration parameters used:
201-
- ufo_x_range: Tuple (min_x, max_x) defining the range of x coordinates
202-
- ufo_x_spacing: Spacing between consecutive x coordinates
203-
- ufo_z_value: Fixed z-coordinate (height) for all points
204-
- ufo_y_value: Fixed y-coordinate (depth) for all points
205-
"""
206-
x = np.arange(
207-
simulation_config.ufo_x_range[0],
208-
simulation_config.ufo_x_range[1],
209-
simulation_config.ufo_x_spacing
210-
).astype(float)
211-
z = np.full((x.shape[0],), simulation_config.ufo_z_value).astype(float)
212-
y = np.full((x.shape[0],), simulation_config.ufo_y_value).astype(float)
213-
214-
wire_attachment_points = []
215-
for point_index in range(x.shape[0]):
216-
wire_attachment_points.append((x[point_index], y[point_index], z[point_index]))
217-
218-
return wire_attachment_points
219-
220149

0 commit comments

Comments
 (0)