Skip to content

Expose marching cubes lookup tables for custom implementations #1151

@shi-eric

Description

@shi-eric

Description

Problem

Projects implementing custom marching cubes variants need access to the fundamental lookup tables (case-to-triangle mappings, corner offsets, etc.), but these are currently private in warp.marching_cubes.

For example, Newton implements a specialized MC variant for SDF isosurface extraction in hydroelastic contact. It works with wp.Volume data and computes physics properties per-triangle in GPU kernels. This requires the lookup tables but not Warp's extraction functions.

Currently, Newton accesses private internals:

tri_range_table = wp.marching_cubes._get_mc_case_to_tri_range_table(device)
tri_local_inds_table = wp.marching_cubes._get_mc_tri_local_inds_table(device)
corner_offsets_table = wp.array(wp.marching_cubes.mc_cube_corner_offsets, ...)

Proposed Solution

Expose the lookup tables as public constants using native Python lists:

from warp.marching_cubes import (
    MC_CUBE_CORNER_OFFSETS,   # 8 corners: [[0,0,0], [1,0,0], ...]
    MC_EDGE_TO_CORNERS,       # 12 edges: [[0,1], [1,2], ...] (NEW)
    MC_CASE_TO_TRI_RANGE,     # 257 ints
    MC_TRI_LOCAL_INDICES,     # 820 ints
)

# Users create wp.array with desired dtype/device
corner_offsets = wp.array(MC_CUBE_CORNER_OFFSETS, dtype=wp.vec3ub, device=device)

Tables to Expose

Constant Size Description
MC_CUBE_CORNER_OFFSETS 8×3 3D offsets for cube corners
MC_EDGE_TO_CORNERS 12×2 Corner pairs for each edge (new)
MC_CASE_TO_TRI_RANGE 257 Case → triangle range indices
MC_TRI_LOCAL_INDICES 820 Edge indices for triangle vertices

Why Python Lists?

  • wp.array() accepts lists directly
  • Users can work with the data using their preferred framework without converting from numpy
  • Consistent with existing mc_cube_corner_offsets which is already a list

What NOT to Expose

The caching functions (_get_mc_*_table), extraction functions, and kernels should remain private—they're implementation details.


Additional Context

  • MC_EDGE_TO_CORNERS doesn't currently exist in Warp; Newton manually recreates it

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions