Others
Spatial ordering, nearest-neighbour search and learnable superquadric primitives. 4 figures.

Morton ordering
Points before and after sorting by Morton code, coloured by their position in memory.
from conquer3d.data_structure import z_curve_sort
points = mesh.sample_points(100_000)[0].contiguous()
# Morton order: points close in space end up close in
# memory, which is what makes later tree builds coherent.
ordered = z_curve_sort(points)
Nearest neighbours
Five query points in a 24,000-point cloud sampled from the bunny, with one neighbourhood shown close up as k grows.
from conquer3d._C import KDTree
# The tree indexes points, never the triangles.
points = mesh.sample_points(24_000)[0].contiguous()
tree = KDTree(points)
# exclude_self drops the query point itself when the
# queries come from the cloud being searched.
distances, indices = tree.query(queries, k=12,
exclude_self=True)
Superquadric shape family
Both shape exponents swept across their range, from box through ellipsoid to pinched star.
import torch
from conquer3d.primitive import SuperQuadrics
from conquer3d.primitive.sq import (
MAX_EXPONENT, MIN_EXPONENT,
)
# e -> 0 is a box, e = 1 an ellipsoid, e -> 2 a star.
steps = 8
axis = torch.linspace(MIN_EXPONENT, MAX_EXPONENT, steps,
device="cuda")
count = steps * steps
sq = SuperQuadrics.from_values(
scales=torch.ones(count, 3, device="cuda"),
exponents=torch.stack([axis.repeat_interleave(steps),
axis.repeat(steps)], dim=-1),
quaternions=torch.eye(4, device="cuda")[0].repeat(
count, 1),
translations=torch.zeros(count, 3, device="cuda"),
learnable=False,
)
verts, faces = sq.get_mesh(resolution=64)
Superquadric fitting
Two thousand superquadrics fitted to a horse by gradient descent, and the union of their fields extracted as one watertight surface.
from conquer3d.data_structure import create_voxel_grid
from conquer3d.ops import marching_cubes
from conquer3d.primitive import (
SuperQuadrics, compute_sq_union,
)
sq = SuperQuadrics(num_quadrics=2000, device="cuda")
for step in range(600):
optimizer.zero_grad(set_to_none=True)
fields, union = sq(points, return_union=True)
union.abs().mean().backward()
optimizer.step()
# get_mesh() keeps surface buried inside overlapping
# primitives. The union boundary is the honest one, so
# extract it from the union field instead.
gv, vox, _ = create_voxel_grid(
grid_min=[-0.62] * 3, grid_max=[0.62] * 3,
res=[512] * 3, device="cuda")
field = compute_sq_union(sq(gv), tau=sq.union_tau,
mask=sq.mask)
verts, faces = marching_cubes(gv, vox, field, iso=0.0)[:2]