AcademySoftwareFoundation / openvdb

OpenVDB - Sparse volume data structure and tools
http://www.openvdb.org/
Apache License 2.0
2.71k stars 660 forks source link

[REQUEST] Primitives for bottom-up traversal of a Tree #1779

Closed YoshuaNava closed 8 months ago

YoshuaNava commented 8 months ago

Is your feature request related to a problem? Please describe.

The OpenVDB library provides functions to traverse the tree from top to bottom, through leafs, through active nodes, etc.

However, it doesn't seem to provide any primitives that, given a voxel or a leaf node, allow you to traverse the tree up to the root. This would be very useful to propagate value updates from denser storage units to sparser ones.

Describe the solution you'd like

Functions that allow you to either:

  1. Retrieve the parent of a given node in a tree (e.g. which could be stored as a pointer in each tree node (Preferred)
  2. Navigate the tree from bottom to top (e.g. a nice NodeManager, or iterator to achieve that), or

Describe alternatives you've considered

Searching for the parent of a node using its Indices (integer coordinates). But this is inefficient, because it requires a search for each level we go up.

Additional context

I would warmly value feedback on the idea of having pointers to parent in the Tree. I would be happy to implement this feature and share it with the community if it's seen positively.

danrbailey commented 8 months ago

Hi @YoshuaNava, the decision was made early in the design of VDB to not store bi-directional pointers. Although there are some small memory benefits, this is mainly because any topology-changing operation would otherwise require additional bookkeeping work that we want to avoid.

Instead, we provide bottom-up traversal using the NodeManager which also offers parallel access to the nodes at each level of the tree:

https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/tree/NodeManager.h#L435

With an example of doing this being the pruning tools:

https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/tools/Prune.h

In all cases where an algorithm has needed the access pattern you describe, we've been able to re-engineer it to use an alternative approach like that provided by foreachBottomUp().

YoshuaNava commented 8 months ago

@danrbailey Thank you very much for the prompt reply. From our development team, we appreciate it a lot :pray: