Skip to content

Commit 6a81e81

Browse files
authored
Merge pull request #14 from zasexton/main
Improving API documentation for Forest and Simulation objects
2 parents 68dc61d + 9ece5a2 commit 6a81e81

File tree

5 files changed

+150
-131
lines changed

5 files changed

+150
-131
lines changed

docs/api/domain.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ <h3>Mesh Generation</h3>
335335
<h4>Parameters</h4>
336336
<ul>
337337
<li><code>resolution</code> (int): Grid resolution for marching cubes/squares</li>
338-
<li><code>get_largest</code> (bool, default=True): Extract only largest connected component</li>
338+
<li><code>get_largest</code> (bool, default=True): Reserved (current implementation always returns the largest connected component)</li>
339339
</ul>
340340
<h4>Returns</h4>
341341
<ul>
@@ -664,4 +664,4 @@ <h4 class="sidebar-title">On This Page</h4>
664664
<script defer src="../script.js"></script>
665665
<script defer src="script_api.js"></script>
666666
</body>
667-
</html>
667+
</html>

docs/api/forest.html

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ <h2>Quick Example</h2>
100100
# Grow networks
101101
forest.add(100) # Add 100 vessels to each tree
102102

103-
# Connect trees within networks
104-
forest.connect(degree=3) # Bezier connections
103+
# Connect trees within networks (start with cubic curves)
104+
forest.connect(3)
105105

106106
# Visualize
107-
forest.show()</code></pre>
107+
forest.show(plot_domain=True)</code></pre>
108108
</div>
109109

110110
<!-- Main Documentation Grid -->
@@ -333,18 +333,20 @@ <h2>Connection Methods</h2>
333333

334334
<div class="api-method">
335335
<div class="api-method-signature">
336-
<code>connect(degree=3, **kwargs)</code>
336+
<code>connect(*args, **kwargs)</code>
337337
</div>
338-
<p>Create connections between trees within networks.</p>
338+
<p>Create connections between trees within each network.</p>
339339
<div class="api-method-params">
340-
<h4>Parameters</h4>
340+
<h4>Usage</h4>
341341
<ul>
342-
<li><code>degree</code> (int, optional): Polynomial degree for Bezier connections</li>
343-
<li><code>**kwargs</code>: Additional parameters for connection algorithm</li>
342+
<li><code>forest.connect()</code>: start with linear connections</li>
343+
<li><code>forest.connect(3)</code>: start optimization with cubic curves</li>
344+
<li><code>forest.connect(curve_type='NURBS')</code>: switch curve family</li>
344345
</ul>
345346
<h4>Notes</h4>
346-
<p>Creates a ForestConnection object that manages inter-tree connections using various
347-
algorithms (Bezier, NURBS, geodesic, etc.).</p>
347+
<p>The method instantiates a <code>ForestConnection</code> that orchestrates
348+
<code>TreeConnection</code> and <code>VesselConnection</code> objects to build
349+
collision-free connecting vessels.</p>
348350
</div>
349351
</div>
350352
</section>
@@ -373,11 +375,14 @@ <h4>Notes</h4>
373375
<div class="api-method-signature">
374376
<code>show(**kwargs)</code>
375377
</div>
376-
<p>Visualize the entire forest with different networks colored separately.</p>
378+
<p>Visualize the entire forest with PyVista.</p>
377379
<div class="api-method-params">
378380
<h4>Parameters</h4>
379381
<ul>
380-
<li><code>**kwargs</code>: PyVista plotting parameters</li>
382+
<li><code>colors</code> (list[str], optional): Cycle of colors for each tree</li>
383+
<li><code>plot_domain</code> (bool): Overlay the domain boundary (default: False)</li>
384+
<li><code>return_plotter</code> (bool): Return the PyVista plotter instead of showing</li>
385+
<li><code>**kwargs</code>: Additional PyVista plotting parameters</li>
381386
</ul>
382387
</div>
383388
</div>
@@ -425,10 +430,10 @@ <h3>Arterial-Venous Network</h3>
425430
f"Venous terminals: {forest.networks[1][0].n_terminals}")
426431

427432
# Connect within networks if multiple trees
428-
forest.connect(degree=3)
433+
forest.connect(3)
429434

430435
# Visualize with different colors
431-
forest.show(arterial_color='red', venous_color='blue')</code></pre>
436+
forest.show(colors=['red', 'blue'], plot_domain=True)</code></pre>
432437
</div>
433438

434439
<div class="api-example">
@@ -457,11 +462,11 @@ <h3>Multi-Tree Network with Connections</h3>
457462
forest.add(50)
458463

459464
# Create inter-tree connections
460-
forest.connect(degree=5) # Higher degree for smoother connections
465+
forest.connect(5) # Higher degree for smoother connections
461466

462467
# Access connection data
463468
if forest.connections:
464-
print(f"Number of connections: {len(forest.connections.paths)}")
469+
print(f"Tree connections solved: {len(forest.connections.tree_connections)}")
465470

466471
# Export connected network
467472
forest.export_solid(outdir='connected_network')</code></pre>
@@ -470,44 +475,37 @@ <h3>Multi-Tree Network with Connections</h3>
470475
<div class="api-example">
471476
<h3>Competitive Growth Pattern</h3>
472477
<pre data-copy><code class="language-python"># Enable competition between networks
478+
import numpy as np
473479
forest = Forest(
474480
domain=domain,
475481
n_networks=3, # Three competing networks
476482
n_trees_per_network=[1, 1, 1],
477-
physical_clearance=0.3,
483+
physical_clearance=0.1,
478484
compete=True # Enable competition
479485
)
480486

481487
# Set starting points
482488
starts = [
483-
[np.array([0, -20, 0])], # Network 1
489+
[np.array([0, -20, 0])], # Network 1
484490
[np.array([17, 10, 0])], # Network 2
485491
[np.array([-17, 10, 0])] # Network 3
486492
]
487493

488494
forest.set_roots(start_points=starts)
489495

490-
# Track growth statistics
491-
stats = {'network_0': [], 'network_1': [], 'network_2': []}
492-
493-
# Competitive growth
494-
for step in range(150):
495-
forest.add(1, decay_probability=0.85) # Stronger decay
496-
497-
# Record statistics
498-
for i in range(3):
499-
stats[f'network_{i}'].append(forest.networks[i][0].n_terminals)
500-
501-
# Check dominance
502-
if step % 30 == 0:
503-
volumes = [forest.networks[i][0].tree_scale for i in range(3)]
504-
dominant = np.argmax(volumes)
505-
print(f"Step {step}: Network {dominant} dominates with volume {volumes[dominant]:.2f}")
496+
forest.add(50)
506497

507498
# Analyze competition results
508499
import matplotlib.pyplot as plt
509-
for i in range(3):
510-
plt.plot(stats[f'network_{i}'], label=f'Network {i}')
500+
# Track terminal counts over time
501+
terminal_history = []
502+
for _ in range(50):
503+
forest.add(1)
504+
terminal_history.append([forest.networks[i][0].n_terminals for i in range(3)])
505+
506+
terminal_history = np.array(terminal_history)
507+
for i in range(terminal_history.shape[1]):
508+
plt.plot(terminal_history[:, i], label=f'Network {i}')
511509
plt.xlabel('Growth Step')
512510
plt.ylabel('Number of Terminals')
513511
plt.legend()
@@ -527,9 +525,9 @@ <h2>Algorithms</h2>
527525
</div>
528526

529527
<div class="admonition note">
530-
<p><strong>Space Competition:</strong> When <code>compete=True</code>, trees compete for space through
531-
probability decay. Regions occupied by one network become less likely to be selected by others,
532-
creating natural territorial boundaries.</p>
528+
<p><strong>Space Sampling:</strong> When sampling space for new terminal selection the probability
529+
that a region which has been previously sampled is drawn again for another terminal decays by the
530+
indicated value to encourage the vascular growth into unvisited territories.</p>
533531
</div>
534532

535533
<div class="admonition warning">
@@ -636,4 +634,4 @@ <h4 class="sidebar-title">On This Page</h4>
636634
<script defer src="../script.js"></script>
637635
<script defer src="script_api.js"></script>
638636
</body>
639-
</html>
637+
</html>

0 commit comments

Comments
 (0)