I have an openvdb grid that I would like to iterate using a functor and openvdb::tools::foreach.
//the grid I am iterating on
Grid G;
//the operator used to update each single voxel of G
struct Functor{
inline void operator()(const Grid::ValueOnCIter& iter) const {
}
};
If the operation involved only G I could have simply called
Functor op;
openvdb::tools::foreach(visibleGrid->cbeginValueOn(), op, true, true);
At each voxel (iteration) though I need to access and modify additional grid(s) based on the computed value of the iteration step.
My inital solution involved providing to the functor the accessor of the additional grid(s):
struct Functor{
Grid2::Accessor grid2_accessor;
Functor( Grid2::Accessor& a) : grid2_accessor(a){}
inline void operator()(const Grid::ValueOnCIter& iter) const {
//use grid2_accessor based on iter.getCoord()
}
};
the accessor is provided to Functor at construction time and moreover each thread of the parallel for get a copy of the functor:
Functor op(G2->getAccessor() );
openvdb::tools::foreach(G1->cbeginValueOn(), op, true, **false**);
Unfortunately this solution does not work since:
- the accessor must not be const to be accessed
- but Functor::operator() must be a const method to be used by tools::foreach
A second dirty solution was to declare the Functor accessor copy as mutable. This solution does not work in Debug due to an openvdb assertion failing (most probably a memory leak).
Is there a solution to the problem? E.g. a tools::foreach that does not require operator() to be const.