ordito.homology
Homology generators: the loops that make a surface's topology, found by tree-cotree.
On a closed genus-g surface there are 2 * g independent loops that cannot be contracted to a
point — two per handle, going around it and through it. They are what a cutting tool needs (cut
along them and the surface opens into a disk), and what tells a parametrizer where its seams have to
go.
The construction is Erickson & Whittlesey's tree-cotree decomposition, and it is a counting
argument as much as an algorithm: take a spanning tree of the vertex graph, then a spanning tree of
the dual graph that avoids the primal tree's edges, and every remaining edge closes exactly one
independent loop. Euler's formula fixes how many are left: E - (V - 1) - (F - 1) = 2 - chi,
which is 2 * g.
Unlike the rest of this package there is no reference implementation to compare against —
potpourri3d does not expose geometry-central's homology code — so the tests check structural
invariants instead: the loop count against
euler_characteristic, and that every loop is a closed
walk along real mesh edges that visits no vertex twice.
Functions:
| Name | Description |
|---|---|
homology_generators |
Non-contractible loops of the surface, as ordered vertex-index cycles. |
homology_generators_with_offsets |
Non-contractible loops of the surface, packed: every loop's vertices, then their offsets. |
homology_generators
homology_generators(
vertices: array[vec3],
faces: array[int32],
*,
root: int | None = None,
copy: bool = False,
unique_edges: Array2dInt32 | None = None,
edge_map: array[int32] | None = None,
) -> list[wp.array[wp.int32]]
Non-contractible loops of the surface, as ordered vertex-index cycles.
Returns 2 * g loops for a closed genus-g surface and none for a sphere. Each loop is a
closed walk along mesh edges: consecutive entries share an edge, and so do the last and first
(the start vertex is not repeated, matching
boundary_loops).
The loops are a basis, not canonical: any generating set is as valid as any other. This one
is the greedy system of loops through the root in the hop metric (Erickson and Whittlesey,
Greedy optimal homotopy and homology generators, SODA 2005): the primal tree is a
breadth-first tree from root, and the dual forest is a maximum spanning tree under the
length of each edge's loop through the root, so each generator is the shortest loop through the
root independent of the ones before it. A handle near the root therefore shows up as its own
short loop rather than as part of a combination; one far from it can still be represented only
through longer loops, so which loops come out depends on where the root is. The loops are as
jagged as the tree, which is what shorten_loop is for.
The basis is reproducible, and the same on every device: the primal tree resolves competing
claims by lowest vertex index and the dual forest breaks equal loop lengths by lowest edge
index, so neither depends on the order the threads ran in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
root
|
int | None
|
Vertex the loops are based at, or |
None
|
copy
|
bool
|
Return independent buffers instead of views into one packed allocation. |
False
|
unique_edges
|
Array2dInt32 | None
|
|
None
|
edge_map
|
Array2dInt32 | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[array[int32]]
|
One array of vertex indices per generator, on |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the mesh has a boundary, since a surface with boundary has a different homology basis
(every boundary loop contributes one, and the tree-cotree count no longer applies), or if
its referenced vertices are not all in one connected component, since the count is then a
sum over components that a single pair of spanning trees does not produce, if |
RuntimeError
|
If |
See Also
homology_generators_with_offsets
The same loops, packed into one buffer with their offsets.
shorten_loop
Shortens these loops within their homotopy class, keeping them on mesh edges.
euler_characteristic
Fixes how many loops there are: 2 * g == 2 - chi.
boundary_loops
Examples:
A torus has genus 1, so two loops: one around the tube and one around the hole. A sphere has none:
import ordito as od
vertices, faces = od.creation.torus(1.0, 0.3, major_sections=16, minor_sections=8)
loops = od.homology.homology_generators(vertices, faces)
print(len(loops)) # 2
print(sorted(loop.size for loop in loops)) # [8, 16]
vertices, faces = od.creation.icosphere(subdivisions=2)
print(len(od.homology.homology_generators(vertices, faces))) # 0
Referenced by 9 places
API Reference geodesic_walk › shorten_loop · heat › heat_signed_distance · measures · repair › remove_tunnels · homology › homology_generators_with_offsets · creation › parametric_surface
Examples Geodesics and tangent fields › Shortening non-contractible loops · Inspecting meshes › Homology generators: handles and tunnels · Parametrization and textures › Cutting a closed surface open along seams
Source code in ordito/homology.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
homology_generators_with_offsets
homology_generators_with_offsets(
vertices: array[vec3],
faces: array[int32],
*,
root: int | None = None,
unique_edges: Array2dInt32 | None = None,
edge_map: array[int32] | None = None,
) -> tuple[wp.array[wp.int32], wp.array[wp.int32]]
Non-contractible loops of the surface, packed: every loop's vertices, then their offsets.
The packed form of homology_generators: the same
basis in the same order, concatenated into one buffer with no per-loop Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
root
|
int | None
|
Vertex the loops are based at, or |
None
|
unique_edges
|
Array2dInt32 | None
|
|
None
|
edge_map
|
Array2dInt32 | None
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
loops |
array[int32]
|
|
offsets |
array[int32]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the mesh has a boundary, its referenced vertices are not all in one connected
component, |
RuntimeError
|
If |
See Also
homology_generators
The same loops, one array each.
shorten_loop_with_offsets
Shortens them in the packed form.
Examples:
import ordito as od
vertices, faces = od.creation.torus(1.0, 0.3, major_sections=16, minor_sections=8)
loops, offsets = od.homology.homology_generators_with_offsets(vertices, faces)
print(offsets.numpy().tolist()) # [0, 8, 24]
print(loops.shape) # (24,)
Referenced by 2 places
API Reference geodesic_walk › shorten_loop_with_offsets · homology › homology_generators
Source code in ordito/homology.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |