@@ -112,7 +112,7 @@ class Trunk(BasicWood):
112112 self.contour = create_noisy_circle_curve(3, 0.05, 30)
113113
114114 def is_bud_break(self, num_buds_segment):
115- if (rd.random() > 0.1*(1 - num_buds_segment/self.max_buds_segment)):
115+ if (rd.random() > 0.1*(1 - num_buds_segment/self.growth. max_buds_segment)):
116116 return False
117117 return True
118118
@@ -148,7 +148,7 @@ class NonTrunk(BasicWood):
148148 self.contour = create_noisy_circle_curve(1, .2, 30)
149149
150150 def is_bud_break(self, num_buds_segment):
151- return (rd.random() < 0.02 *(1 - num_buds_segment/self.max_buds_segment))
151+ return (rd.random() < 0.5 *(1 - num_buds_segment/self.growth .max_buds_segment))
152152
153153 def create_branch(self):
154154 if rd.random()>0.3:
@@ -166,10 +166,10 @@ growth_length = 0.1
166166bud_spacing_age = 2
167167#everything is relative to growth length
168168basicwood_prototypes = {}
169- basicwood_prototypes['trunk'] = Trunk(tie_axis = (0,1,1 ), max_length = 4, thickness = 0.01, growth_length = growth_length,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [255,0,0] )
170- basicwood_prototypes['branch'] = Branch(tie_axis = (0,1,1 ), max_length = 2.2, thickness = 0.01, growth_length = growth_length,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [255,150,0] )
171- basicwood_prototypes['nontrunk'] = NonTrunk(tie_axis = (0,1,1 ), max_length = 0.3, growth_length = growth_length/2, thickness = 0.003,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [0, 255, 0] )
172- basicwood_prototypes['spur'] = Spur(tie_axis = (0,1,1 ), max_length = 0.2, thickness = 0.003, growth_length = growth_length/2, thickness_increment = 0., prototype_dict = basicwood_prototypes, color = [0,255,0] )
169+ basicwood_prototypes['trunk'] = Trunk(tie_axis = (0,1,0 ), max_length = 4, thickness = 0.01, growth_length = growth_length,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [255,0,0] )
170+ basicwood_prototypes['branch'] = Branch(tie_axis = (1, 0, 0 ), max_length = 2.2, thickness = 0.01, growth_length = growth_length,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [255,150,0] )
171+ basicwood_prototypes['nontrunk'] = NonTrunk(tie_axis = (1, 0, 0 ), max_length = 0.3, growth_length = growth_length/2, thickness = 0.003,thickness_increment = 0.00001, prototype_dict = basicwood_prototypes, color = [0, 255, 0] )
172+ basicwood_prototypes['spur'] = Spur(tie_axis = (1, 0, 0 ), max_length = 0.2, thickness = 0.003, growth_length = growth_length/2, thickness_increment = 0., prototype_dict = basicwood_prototypes, color = [0,255,0] )
173173
174174
175175#init
@@ -191,7 +191,7 @@ def generate_points_v_trellis():
191191 return pts # Return the list of points
192192
193193# points, num_wires spacing wires trunk_wire_pt branch_axis trunk_axis
194- support = Support(generate_points_v_trellis(), 14 , 1 , None, (0,0,1), None )
194+ support = Support(generate_points_v_trellis(), 14 , 1 , None)
195195num_iteration_tie = 5
196196num_iteration_prune = 16
197197###Tying stuff begins
@@ -208,14 +208,14 @@ def get_energy_mat(branches, arch):
208208 energy_matrix = np.ones((num_branches, num_wires)) * np.inf # Initialize the energy matrix with infinity
209209
210210 for branch_id, branch in enumerate(branches): # Loop through each branch
211- if branch.has_tied or branch.cut: # If the branch is already tied, skip it
211+ if branch.tying. has_tied or branch.info .cut: # If the branch is already tied, skip it
212212 continue
213213 for wire_id, wire in arch.branch_supports.items(): # Loop through each wire
214214 # print(f"ID {wire_id} num branch {wire.num_branch}")
215215 if wire.num_branch >= 1: # If the wire already has a branch, skip it
216216 continue
217217 # Calculate the energy required to tie the branch to the wire
218- energy_matrix[branch_id][wire_id] = ed(wire.point, branch.start) / 2 #ed(wire.point, branch.end) / 2 +
218+ energy_matrix[branch_id][wire_id] = ed(wire.point, branch.location. start) / 2 #ed(wire.point, branch.location .end) / 2 +
219219
220220 return energy_matrix # Return the energy matrix
221221
@@ -225,8 +225,8 @@ def decide_guide(energy_matrix, branches, arch):
225225 min_arg = np.argwhere(energy_matrix == np.min(energy_matrix)) # Find the minimum energy branch to tie
226226 if (energy_matrix[min_arg[0][0]][min_arg[0][1]] == np.inf) or energy_matrix[min_arg[0][0]][min_arg[0][1]] > 0.25*math.exp(getIterationNb()/105):
227227 return # If the minimum energy is too high, stop the process
228- if not branches[min_arg[0][0]].has_tied and not branches[min_arg[0][0]].cut: # If the branch has not been tied before
229- branches[min_arg[0][0]].guide_target = arch.branch_supports[min_arg[0][1]] # Set the guide target to the wire
228+ if not branches[min_arg[0][0]].tying. has_tied and not branches[min_arg[0][0]].info .cut: # If the branch has not been tied before
229+ branches[min_arg[0][0]].tying. guide_target = arch.branch_supports[min_arg[0][1]] # Set the guide target to the wire
230230 arch.branch_supports[min_arg[0][1]].add_branch() # Increment the number of branches tied to the wire
231231 # print(f"Tying {min_arg[0][0]} to wire {min_arg[0][1]}")
232232 # Set the energy to tie as infinite (only tie 1 branch per wire)
@@ -239,11 +239,11 @@ def decide_guide(energy_matrix, branches, arch):
239239def tie(lstring):
240240 for j, i in enumerate(lstring): # Loop through each element in the lstring
241241 if i == 'C' and i[0].type.__class__.__name__ == 'Branch': # Check if the element is a branch
242- if i[0].type.tie_updated == False: # If the branch is not updated, skip it
242+ if i[0].type.tying. tie_updated == False: # If the branch is not updated, skip it
243243 continue
244244 curr = i[0] # Get the current branch
245- if i[0].type.guide_points: # If the branch has guide points
246- i[0].type.tie_updated = False # Set the tie_updated flag to False
245+ if i[0].type.tying. guide_points: # If the branch has guide points
246+ i[0].type.tying. tie_updated = False # Set the tie_updated flag to False
247247 #i[0].type.guide_target.add_branch() # Add the branch to the guide target
248248 lstring, count = i[0].type.tie_lstring(lstring, j) # Tie the branch
249249
@@ -254,7 +254,7 @@ def tie(lstring):
254254def pruning_strategy(lstring): # Remove remnants of cut
255255 cut = False # Initialize the cut flag
256256 for j, i in enumerate(lstring): # Loop through each element in the lstring
257- if i.name == 'C' and i[0].type.age > 6 and i[0].type.has_tied == False and i[0].type.cut == False and i[0].type.prunable and i[0].type.guide_target==-1:
257+ if i.name == 'C' and i[0].type.info. age > 6 and i[0].type.tying. has_tied == False and i[0].type.info. cut == False and i[0].type.info. prunable and i[0].type.tying .guide_target==-1:
258258 i[0].type.cut = True # Set the cut flag to True
259259 lstring = cut_from(j, lstring) # Cut the branch using string manipulation
260260 #TODO: Remove branch from parent_child dict and wire
@@ -267,7 +267,7 @@ def pruning_strategy(lstring): # Remove remnants of cut
267267def StartEach(lstring):
268268 global parent_child_dict
269269 for i in parent_child_dict[trunk_base.name]: # Loop through each child of the trunk base
270- if i.tie_updated == False: # If the branch is not updated
270+ if i.tying. tie_updated == False: # If the branch is not updated
271271 i.tie_update() # Update the branch
272272
273273# Function to end each iteration
@@ -278,7 +278,7 @@ def EndEach(lstring):
278278 energy_matrix = get_energy_mat(parent_child_dict[trunk_base.name], support) # Get the energy matrix
279279 decide_guide(energy_matrix, parent_child_dict[trunk_base.name], support) # Decide which branches to guide
280280 for branch in parent_child_dict[trunk_base.name]: # Loop through each branch
281- branch.update_guide(branch.guide_target) # Update the guide target for the branch
281+ branch.update_guide(branch.tying. guide_target) # Update the guide target for the branch
282282 while tie(lstring): # Tie branches until no more can be tied
283283 pass
284284 if (getIterationNb() + 1) % num_iteration_prune == 0:
@@ -309,20 +309,20 @@ def reset_contour():
309309
310310
311311curve = create_bezier_curve(x_range = (-1, 1), y_range = (-0.15, 0.15), z_range = (0, 10), seed_val=time.time())
312- Axiom: Attractors(support)SetGuide(curve, trunk_base.max_length)[grow_object(trunk_base)]
312+ Axiom: Attractors(support)SetGuide(curve, trunk_base.growth. max_length)[grow_object(trunk_base)]
313313derivation length: 128
314314production:
315315#Decide whether branch internode vs trunk internode need to be the same size.
316316grow_object(o) :
317317 if o == None:
318318 produce *
319319 else:
320- if o.length >= o.max_length:
321- o.age += 1
320+ if o.length >= o.growth. max_length:
321+ o.info. age += 1
322322 nproduce *
323323 else:
324324 # Get object's usual color and apply it
325- r, g, b = o.color
325+ r, g, b = o.info. color
326326 nproduce SetColor(r, g, b)
327327
328328 # This sets unique color IDs
@@ -342,11 +342,11 @@ grow_object(o) :
342342
343343 if 'Spur' in o.name:
344344 # note that the production of the buds is here with 'spiked_bud(o.thickness)'
345- produce I(o.growth_length, o.thickness, o) bud(ParameterSet(type=o, num_buds=0))grow_object(o) #spiked_bud(o.thickness)grow_object(o)
345+ produce I(o.growth. growth_length, o.growth. thickness, o) bud(ParameterSet(type=o, num_buds=0))grow_object(o) #spiked_bud(o.growth .thickness)grow_object(o)
346346 else:
347347 # If o is a Trunk, Branch, or NonTrunk, simply produce the internodes
348- nproduce I(o.growth_length, o.thickness, o)
349- if np.isclose(o.age%bud_spacing_age,0, atol = 0.01):
348+ nproduce I(o.growth. growth_length, o.growth .thickness, o)
349+ if np.isclose(o.info. age%bud_spacing_age,0, atol = 0.01):
350350 nproduce bud(ParameterSet(type=o, num_buds=0))
351351 produce grow_object(o)
352352
@@ -367,14 +367,14 @@ bud(t) :
367367 if 'NonTrunk' in new_object.name:
368368 import time
369369 curve = create_bezier_curve(x_range = (-.5,.5), y_range = (-.5,.5), z_range = (-1,1), seed_val=time.time())
370- nproduce [SetGuide(curve, new_object.max_length)
370+ nproduce [SetGuide(curve, new_object.growth. max_length)
371371 elif 'Spur' in new_object.name:
372372 import time
373373 curve = create_bezier_curve(x_range = (-.2,.2), y_range = (-.2,.2), z_range = (-1,1), seed_val=time.time())
374- nproduce [SetGuide(curve, new_object.max_length)
374+ nproduce [SetGuide(curve, new_object.growth. max_length)
375375 else:
376376 nproduce [
377- nproduce @RGetPos(new_object.start)C(ParameterSet(type = new_object))/(rd.random()*360)&(rd.random()*360)grow_object(new_object)GetPos(new_object.end)]bud(ParameterSet(type=t.type, num_buds=t.num_buds))
377+ nproduce @RGetPos(new_object.location. start)C(ParameterSet(type = new_object))/(rd.random()*360)&(rd.random()*360)grow_object(new_object)GetPos(new_object.location .end)]bud(ParameterSet(type=t.type, num_buds=t.num_buds))
378378
379379
380380# Simple set of productions to build apple bud. This bud is
@@ -397,8 +397,8 @@ A(bh, r):
397397 produce nF(bh, .01, r, base_curve) ^(180) nF(bh/5, .1, r, top_curve)^(180)#S(bh/2,r/15)
398398
399399
400- I(s,r,o) --> I(s,r+o.thickness_increment, o)
401- #_(r) --> _(r+o.thickness_increment)
400+ I(s,r,o) --> I(s,r+o.growth. thickness_increment, o)
401+ #_(r) --> _(r+o.growth. thickness_increment)
402402_(r) --> _(r)
403403homomorphism:
404404I(a,r,o) --> F(a,r)
0 commit comments