You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been wondering for a while about how to make it easy to convert from other sparse volume data structures to vdb or at least how to operate on other data structures using vdb tools.
One idea I had was to use a vdb tree as a 'wrapper' around already existing data. This at least would allow custom solvers to cheaply construct a vdb topolgy tree around their own structure in memory and serialize out with out too much hassle. Also, people writing plugins for host applications that support vdb grid natively (houdini etc) would be able to output them to the host without having to copy any voxel data or allocate any more memory.
So I started and quickly realised that I would have to dive into the library and enable access to private members or provide functions to do things like set the mData member on the LeafBuffer. Then I noticed that the LeafBuffer has a friend class ::TestLeaf that allows access. Now because I am prone to use hacks to get the job done (maybe from my previous experience as an fxtd), I wrote a little class called TestLeaf that could set that member. I also wrote a little wrapper around a vdb grid that forwards -> operator and has conversion operators to be able to use it as if it was a grid itself. (Edit: the reason for the redirection was that I needed a destructor that sets all of the mData pointers to null so that we don't get double free from the backing storage also trying to deallocate).
Here's my little fun experiment. It works and is able to write out a vdb file that I can read into houdini and the data looks good.
This is totally not something I am saying is a valid way to use the library. I thought it was an interesting test that maybe has an inkling of an idea in it to help interoperability with other software that write out vdbs and has the same 8^3 tile structure.
#include <openvdb/openvdb.h>
#include <vector>
// a hack class to be able to access private member of a leaf node's buffer
// this is used so we can build a 'view' vdb tree over an existing sparse tiled volume structure
using floatBufferType = openvdb::FloatGrid::TreeType::LeafNodeType::Buffer;
class TestLeaf : floatBufferType
{
public:
static void setData(floatBufferType &bufferToSet, float *newData)
{
bufferToSet.mData = newData;
}
};
using LeafBufferDataAccess = TestLeaf;
// class to be able to wrap a float grid that has storage backed elsewhere
// and then upon destruction clear pointers so we dont get double free.
// it essentially re-routes access through operator and add conversion functions
class clearViewGrid
{
public:
clearViewGrid(const openvdb::FloatGrid::Ptr grid) : internalGrid(grid) {}
~clearViewGrid()
{
for (auto iter = internalGrid->tree().beginLeaf(); iter; ++iter)
{
LeafBufferDataAccess::setData(iter->buffer(), nullptr);
}
}
openvdb::FloatGrid::Ptr operator->()
{
return internalGrid;
}
operator openvdb::FloatGrid::Ptr()
{
return internalGrid;
}
operator openvdb::GridBase::Ptr()
{
return internalGrid;
}
const openvdb::FloatGrid::Ptr internalGrid;
};
int main()
{
openvdb::initialize();
clearViewGrid grid(openvdb::FloatGrid::create());
std::vector<float> buf(512, 1.0f);
buf[0] = 0;
buf[1] = 0;
buf[12] = 0;
buf[511] = 0;
// create leafNode with partialCreate to make mData nullptr and let tree take ownership
auto leafNodePtr = new openvdb::FloatGrid::TreeType::LeafNodeType(openvdb::PartialCreate{}, openvdb::Coord{0, 0, 0});
grid->tree().addLeaf(leafNodePtr);
// set active only
leafNodePtr->setValuesOn();
LeafBufferDataAccess::setData(leafNodePtr->buffer(), buf.data());
openvdb::io::File file("/Users/danielelliott/vdbs/test.vdb");
openvdb::GridPtrVec grids;
grids.push_back(grid);
file.write(grids);
file.close();
}```
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all
I've been wondering for a while about how to make it easy to convert from other sparse volume data structures to vdb or at least how to operate on other data structures using vdb tools.
One idea I had was to use a vdb tree as a 'wrapper' around already existing data. This at least would allow custom solvers to cheaply construct a vdb topolgy tree around their own structure in memory and serialize out with out too much hassle. Also, people writing plugins for host applications that support vdb grid natively (houdini etc) would be able to output them to the host without having to copy any voxel data or allocate any more memory.
So I started and quickly realised that I would have to dive into the library and enable access to private members or provide functions to do things like set the mData member on the LeafBuffer. Then I noticed that the LeafBuffer has a friend class ::TestLeaf that allows access. Now because I am prone to use hacks to get the job done (maybe from my previous experience as an fxtd), I wrote a little class called TestLeaf that could set that member. I also wrote a little wrapper around a vdb grid that forwards -> operator and has conversion operators to be able to use it as if it was a grid itself. (Edit: the reason for the redirection was that I needed a destructor that sets all of the mData pointers to null so that we don't get double free from the backing storage also trying to deallocate).
Here's my little fun experiment. It works and is able to write out a vdb file that I can read into houdini and the data looks good.
This is totally not something I am saying is a valid way to use the library. I thought it was an interesting test that maybe has an inkling of an idea in it to help interoperability with other software that write out vdbs and has the same 8^3 tile structure.
Beta Was this translation helpful? Give feedback.
All reactions