diff options
author | Sebastián Barschkis <sebbas@sebbas.org> | 2020-02-09 19:09:00 +0300 |
---|---|---|
committer | Sebastián Barschkis <sebbas@sebbas.org> | 2020-02-09 19:09:00 +0300 |
commit | 4a08eb0707fc17e4e97430ffa33eb7d3e36db712 (patch) | |
tree | 5139566839e9544077f203eccfb2e7f58da0e332 /extern/mantaflow/preprocessed/fileio/iogrids.cpp | |
parent | 68221b7ebafe58a2bbf612ad8c59e24569489be5 (diff) |
Fluid: Updated manta pp files
Includes the OpenVDB read/write functions for int grids. This essential for the resume bake functionality in modular fluid caches.
Diffstat (limited to 'extern/mantaflow/preprocessed/fileio/iogrids.cpp')
-rw-r--r-- | extern/mantaflow/preprocessed/fileio/iogrids.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/extern/mantaflow/preprocessed/fileio/iogrids.cpp b/extern/mantaflow/preprocessed/fileio/iogrids.cpp index 2f6cdaa6209..2b8ee905f99 100644 --- a/extern/mantaflow/preprocessed/fileio/iogrids.cpp +++ b/extern/mantaflow/preprocessed/fileio/iogrids.cpp @@ -954,6 +954,79 @@ template<class T> void readGridVDB(const string &name, Grid<T> *grid) 1); } +template<> void writeGridVDB(const string &name, Grid<int> *grid) +{ + debMsg("Writing int grid " << grid->getName() << " to vdb file " << name, 1); + + // Create an empty int32-point grid with background value 0. + openvdb::initialize(); + openvdb::Int32Grid::Ptr gridVDB = openvdb::Int32Grid::create(); + gridVDB->setTransform( + openvdb::math::Transform::createLinearTransform(1. / grid->getSizeX())); // voxel size + + // Get an accessor for coordinate-based access to voxels. + openvdb::Int32Grid::Accessor accessor = gridVDB->getAccessor(); + + gridVDB->setGridClass(openvdb::GRID_UNKNOWN); + + // Name the grid "density". + gridVDB->setName(grid->getName()); + + openvdb::io::File file(name); + + FOR_IJK(*grid) + { + openvdb::Coord xyz(i, j, k); + accessor.setValue(xyz, (*grid)(i, j, k)); + } + + // Add the grid pointer to a container. + openvdb::GridPtrVec gridsVDB; + gridsVDB.push_back(gridVDB); + + // Write out the contents of the container. + file.write(gridsVDB); + file.close(); +} + +template<> void readGridVDB(const string &name, Grid<int> *grid) +{ + debMsg("Reading int grid " << grid->getName() << " from vdb file " << name, 1); + + openvdb::initialize(); + openvdb::io::File file(name); + file.open(); + + openvdb::GridBase::Ptr baseGrid; + for (openvdb::io::File::NameIterator nameIter = file.beginName(); nameIter != file.endName(); + ++nameIter) { +# ifndef BLENDER + // Read in only the grid we are interested in. + if (nameIter.gridName() == grid->getName()) { + baseGrid = file.readGrid(nameIter.gridName()); + } + else { + debMsg("skipping grid " << nameIter.gridName(), 1); + } +# else + // For Blender, skip name check and pick first grid from loop + baseGrid = file.readGrid(nameIter.gridName()); + break; +# endif + } + file.close(); + openvdb::Int32Grid::Ptr gridVDB = openvdb::gridPtrCast<openvdb::Int32Grid>(baseGrid); + + openvdb::Int32Grid::Accessor accessor = gridVDB->getAccessor(); + + FOR_IJK(*grid) + { + openvdb::Coord xyz(i, j, k); + int v = accessor.getValue(xyz); + (*grid)(i, j, k) = v; + } +} + template<> void writeGridVDB(const string &name, Grid<Real> *grid) { debMsg("Writing real grid " << grid->getName() << " to vdb file " << name, 1); |