Skip to content

Expose per-grid dilation amounts in the Python dilate API #495

@blackencino

Description

@blackencino

Summary

The Python Grid.dilated_grid() and GridBatch.dilated_grid() methods currently accept a single int dilation value that is applied uniformly to every grid in the batch. The underlying C++ implementation (GridBatchImpl::dilate) already supports a std::vector<int64_t> overload that allows specifying a different dilation amount per grid in the batch.

Motivation

Per-grid dilation amounts would enable use cases where different grids in a batch need different dilation radii -- for example, adaptive resolution workflows or per-object morphological operations in a batched pipeline.

Proposed Change

Extend the Python API so that dilated_grid accepts either:

  • A single int (current behavior, applied to all grids), or
  • A list/sequence of int with one entry per grid in the batch.

This would require:

  1. Adding or overloading the pybind11 binding in GridBatchBinding.cpp to accept std::vector<int64_t>.
  2. Updating GridBatch.dilated_grid() in grid_batch.py and Grid.dilated_grid() in grid.py to accept int | list[int].
  3. Adding Python-level tests for the per-grid dilation path (including mixed zero/non-zero dilation amounts).

Additional Context

The C++ op dilateGrid in BuildDilatedGrid.cu already handles per-grid dilation correctly, including the edge case where individual dilation amounts are zero.

Metadata

Metadata

Assignees

Labels

Python APITopology OperationsIssues related to topology operations (prune, merge, dilate, etc.core libraryCore fVDB library. i.e. anything in the _Cpp module (C++) or fvdb python moduleenhancementNew feature or requestnew featureNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions