Tree geometry¶
gutenberg_kg.treegeom
¶
treegeom.py — where a book's tree goes, with nothing drawn yet.
The PyVista-free half of the scene layer. Corpus geometry is pure NumPy: the
schematic :class:ForestLayout that places a crown, the space-colonization
growth that reaches it, the foliage seasons, and the halo scatter. None of it
needs VTK, and hoisting it out of :mod:gutenberg_kg.scene is what lets a
second renderer exist — :mod:gutenberg_kg.povscene composes the same tree as
analytic POV-Ray primitives without a plotter, an OpenGL context, or an
installed PyVista.
:mod:gutenberg_kg.scene re-exports every public name here, so
from gutenberg_kg.scene import ForestLayout keeps working; new code should
import from whichever module matches what it needs, geometry or rendering.
Author: Eric G. Suchanek, PhD
ForestLayout(grove_inner_radius=80.0, grove_outer_radius=240.0, book_inner_radius=5.0, book_outer_radius=18.0, trunk_scale=4.0, max_trunk_height=45.0, branch_radius=5.0, leaf_radius=1.5, canopy_lift=4.0, book_genre_map=None, entry_times=None)
¶
Bases: Layout3D
3-D forest layout for a multi-book corpus.
Spatial structure¶
- Genres are placed in a large Fibonacci annulus in the XY plane (each genre → a grove at a fixed XY centre).
- Books within a genre are placed in a medium Fibonacci annulus around the genre centre.
- Per book (tree):
documentnode sits at the book's XY position,Z = 0(trunk base marker).sectionnodes are distributed on a Fibonacci upper hemisphere centred at the trunk apex(bx, by, trunk_height). Trunk height scales aslog2(1 + n_chunks).chunknodes cluster around their parent section node in a small Fibonacci sphere.entity/topicnodes float in a loose cloud above the canopy atZ = trunk_height + canopy_lift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grove_inner_radius
|
float
|
Inner radius for genre placement ring. |
80.0
|
grove_outer_radius
|
float
|
Minimum outer radius for genre ring. |
240.0
|
book_inner_radius
|
float
|
Inner radius for books within a genre grove. |
5.0
|
book_outer_radius
|
float
|
Minimum outer radius within a genre grove. |
18.0
|
trunk_scale
|
float
|
Multiplier for trunk height ( |
4.0
|
branch_radius
|
float
|
Base radius of the Fibonacci hemisphere for sections. |
5.0
|
leaf_radius
|
float
|
Base radius of the leaf sphere per section. |
1.5
|
canopy_lift
|
float
|
Z offset above trunk apex for entity / topic nodes. |
4.0
|
book_genre_map
|
dict[str, str] | None
|
|
None
|
entry_times
|
dict[str, str] | None
|
|
None
|
Store layout radii/scale parameters; see class docstring for their roles.
Source code in src/gutenberg_kg/treegeom.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
compute(nodes, edges)
¶
Compute 3-D positions for every node in the combined forest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[LayoutNode]
|
All nodes across all loaded books (IDs already namespaced). |
required |
edges
|
list[LayoutEdge]
|
All edges across all loaded books. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Mapping from node ID to |
Source code in src/gutenberg_kg/treegeom.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |
SceneFilters(show_sections=True, show_chunks=True, show_entities=False, show_topics=False, show_contains=False, show_similar=False, show_next=False)
dataclass
¶
Which node kinds and edge relations the scene should draw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_sections
|
bool
|
Draw |
True
|
show_chunks
|
bool
|
Draw |
True
|
show_entities
|
bool
|
Draw |
False
|
show_topics
|
bool
|
Draw |
False
|
show_contains
|
bool
|
Draw |
False
|
show_similar
|
bool
|
Draw |
False
|
show_next
|
bool
|
Draw |
False
|
visible_kinds()
¶
Node kinds this filter set admits (document is always drawn).
Source code in src/gutenberg_kg/treegeom.py
934 935 936 937 938 939 940 941 942 943 944 945 | |
visible_rels()
¶
Edge relations this filter set admits.
Source code in src/gutenberg_kg/treegeom.py
947 948 949 950 951 952 953 954 955 956 | |
Season(foliage, density=1.0, wood=WOOD_COLOR, sky=(SKY_BOTTOM, SKY_TOP))
dataclass
¶
A seasonal look for the foliage, wood, and sky.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
foliage
|
tuple[str, ...]
|
Leaf colours, sampled per leaf so a canopy varies the way a real one does rather than reading as one flat green. |
required |
density
|
float
|
Fraction of chunks that keep a leaf. Winter drops most of them, which is the point — bare wood is where the pipe model shows. |
1.0
|
wood
|
str
|
Branch colour. |
WOOD_COLOR
|
sky
|
tuple[str, str]
|
Background gradient, |
(SKY_BOTTOM, SKY_TOP)
|
TreeGeometry(skeleton, layout, positions, crown, palette, leaf_points, leaf_tint, leaf_radius, spores, title, counts, trunk_height, species=DEFAULT_SPECIES)
dataclass
¶
Where a book's wood, leaves and spores go, with nothing drawn yet.
The placement half of :func:build_tree_scene, separated out so a second
renderer can reach it. Everything here is plain NumPy and hex colour
strings: no pv.Plotter, no meshes, no tessellation. PyVista turns it
into actors; :mod:gutenberg_kg.povscene turns the same numbers into
POV-Ray primitives, and because both start here the two backends cannot
quietly grow different trees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
Skeleton
|
Grown skeleton, radii already assigned. |
required |
layout
|
ForestLayout
|
The :class: |
required |
positions
|
dict[str, ndarray]
|
Node ID → position, shifted so the tree stands at the origin. |
required |
crown
|
ndarray
|
|
required |
palette
|
Season
|
The :class: |
required |
leaf_points
|
ndarray
|
|
required |
leaf_tint
|
ndarray
|
|
required |
leaf_radius
|
float
|
Leaf radius after density scaling, in scene units. |
required |
spores
|
dict[str, tuple[ndarray, float]]
|
|
required |
title
|
str
|
One-line stats banner. |
required |
counts
|
Counter
|
Node count per kind. |
required |
trunk_height
|
float
|
Schematic trunk height, a useful focal-plane height. |
required |
species
|
str
|
The tree species (:data: |
DEFAULT_SPECIES
|
leaf_colors
property
¶
Returns:
| Type | Description |
|---|---|
list[str]
|
One hex colour per leaf, resolved through the palette. |
bark_texture_path(species)
¶
The species' bark colour map, shipped in gutenberg_kg/assets/bark/.
CC0 textures from ambientCG, the same files the Knowledge Press web
forest uses; see that directory's CREDITS.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species
|
str
|
A key of :data: |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
The image path, or |
Source code in src/gutenberg_kg/treegeom.py
221 222 223 224 225 226 227 228 229 230 231 232 | |
book_habit(slug, genre)
¶
One book's growth habit: its genre's species, nudged per book so a grove is not a row of clones. Deterministic in slug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Book slug. |
required |
genre
|
str
|
Genre name. |
required |
Returns:
| Type | Description |
|---|---|
Habit
|
The varied :class: |
Source code in src/gutenberg_kg/treegeom.py
235 236 237 238 239 240 241 242 243 244 | |
diary_periods(nodes, edges, entry_times=None, bins=PERIOD_BINS)
¶
A diary's period limbs, compact enough to ship to the web forest.
Groups entries exactly as :meth:ForestLayout.compute does (calendar years
when dated, equal runs of file order otherwise) and counts each period's
chunks into bins equal slices of its limb, by each entry's fraction along
it. The web forest rebuilds the same limbs from this without the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[LayoutNode]
|
Nodes of one book. |
required |
edges
|
list[LayoutEdge]
|
Edges of the same book. |
required |
entry_times
|
dict[str, str] | None
|
|
None
|
bins
|
int
|
Slices per limb. |
PERIOD_BINS
|
Returns:
| Type | Description |
|---|---|
list[dict[str, object]]
|
|
Source code in src/gutenberg_kg/treegeom.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
grow_tree_geometry(nodes, edges, *, slug, genre='unknown', entry_times=None, filters=None, season=DEFAULT_SEASON, tip_radius=0.05, leaf_size=0.32, progress=None)
¶
Lay out one book and grow a skeleton to reach it, without drawing anything.
The schematic layout places the crown; space colonization then grows a skeleton to reach it, so every limb is a real structural path and the canopy's shape is the book's shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[LayoutNode]
|
Nodes of one book (IDs namespaced by slug). |
required |
edges
|
list[LayoutEdge]
|
Edges of the same book. |
required |
slug
|
str
|
Book slug; seeds growth so the tree is reproducible. |
required |
genre
|
str
|
Genre name, which selects the tree species
(:data: |
'unknown'
|
entry_times
|
dict[str, str] | None
|
|
None
|
filters
|
SceneFilters | None
|
Only |
None
|
season
|
str
|
Key into :data: |
DEFAULT_SEASON
|
tip_radius
|
float
|
Radius of leaf-bearing twigs, in scene units. |
0.05
|
leaf_size
|
float
|
Leaf radius before density scaling. |
0.32
|
progress
|
Callable[[str], None] | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
TreeGeometry
|
The placed :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If season is unknown, or the book has no chunks to grow toward. |
Source code in src/gutenberg_kg/treegeom.py
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 | |
species_for(genre)
¶
The tree species a genre grows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genre
|
str
|
Genre name. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A key of :data: |
Source code in src/gutenberg_kg/treegeom.py
158 159 160 161 162 163 164 165 | |
species_leaf_frames(positions, skeleton, *, size, tint=None, n_tints=1)
¶
Where each species leaf goes and how it lies, as the web forest draws it.
Placement is :func:kg_utils.viz3d.hang_leaves: stalk on the nearest
twig, blade out and lifted, face to the sky. Size follows the web's
emitLeaves: half a leaf's length is 1.78 * r * jitter, with r
the web's leaf size and jitter from 0.78 to 1.28 by tint.
A species outline (:mod:gutenberg_kg.leafshapes, stalk at y = -1,
x across) lands in world space as
centre + half * (x * across + y * blade).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
ndarray
|
|
required |
skeleton
|
Skeleton
|
Grown skeleton. |
required |
size
|
float
|
Leaf size after density scaling ( |
required |
tint
|
ndarray | None
|
|
None
|
n_tints
|
int
|
Palette length the tints index into. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray, ndarray, ndarray]
|
|
Source code in src/gutenberg_kg/treegeom.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |