AcademySoftwareFoundation / AcademySoftwareFoundation/openvdb
`touchLeaf` should let you know if it did any work, ala `std::map::emplace` and `::try_emplace`.
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 774
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 34
Description
### Is your feature request related to a problem? Please describe.
Right now `touchLeaf(Coord)` returns a `LeafNodeT*` to the (possibly new) leaf.
### Describe the solution you'd like
I'd like to get a `std::pair` returned so I know if the leaf is new or not. (Better: Return a `std::pair` indicating how many levels it added to create the leaf.)
The function is
```
template
inline typename ChildT::LeafNodeType*
InternalNode::touchLeaf(const Coord& xyz)
{
const Index n = this->coordToOffset(xyz);
ChildT* child = nullptr;
if (mChildMask.isOff(n)) {
child = new ChildT(xyz, mNodes[n].getValue(), mValueMask.isOn(n));
this->setChildNode(n, child);
} else {
child = mNodes[n].getChild();
}
return child->touchLeaf(xyz);
}
```
https://www.openvdb.org/documentation/doxygen/InternalNode_8h_source.html
### Describe alternatives you've considered
I could write this as a free function, but it seems like the better for the function to return the `bool` that it trivially "knows". Maybe call it `emplaceLeaf` to match the std associative-containers:
```
template
std::pair
InternalNode::emplaceLeaf(const Coord& xyz)
{
const Index n = this->coordToOffset(xyz);
ChildT* child = nullptr;
std::uint8_t addedLevels = 0;
if (mChildMask.isOff(n)) {
addedLevels = 1;
child = new ChildT(xyz, mNodes[n].getValue(), mValueMask.isOn(n));
this->setChildNode(n, child);
} else {
child = mNodes[n].getChild();
}
auto result = child->touchLeaf(xyz);
result.second += addedLevels;
return result;
}
```
### Additional context
Again, it looks like I can write this as a free function just fine, but if we are going to have a function that can easily tell us if it did work, we may as well.
My use case is I'd like to touch a bunch of leaves before doing an algorithm, then consider only the leaves I added for pruning. Knowing if I added something would let me keep a `std::vector` of those added-for-bookeeping-only leaves so I could quickly revisit them after the algorithm to see if any should be removed.
Contributor guide
Research direction
Start with InternalNode::touchLeaf in InternalNode.h, using the linked OpenVDB source as the entry point. Trace the recursive touchLeaf calls and their callers to determine whether the result should report a new leaf or the number of levels added. Done means the API communicates that creation information without losing the returned leaf pointer and remains consistent across the tree levels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100