From 4a08eb0707fc17e4e97430ffa33eb7d3e36db712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Barschkis?= Date: Sun, 9 Feb 2020 17:09:00 +0100 Subject: 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. --- extern/mantaflow/preprocessed/fileio/iogrids.cpp | 73 ++++++++++++++++++++++ .../mantaflow/preprocessed/fileio/ioparticles.cpp | 2 + extern/mantaflow/preprocessed/fluidsolver.cpp | 2 +- extern/mantaflow/preprocessed/gitinfo.h | 2 +- extern/mantaflow/preprocessed/plugin/flip.cpp | 1 - .../mantaflow/preprocessed/plugin/fluidguiding.cpp | 1 - .../preprocessed/plugin/secondaryparticles.cpp | 5 +- 7 files changed, 78 insertions(+), 8 deletions(-) (limited to 'extern/mantaflow/preprocessed') 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 void readGridVDB(const string &name, Grid *grid) 1); } +template<> void writeGridVDB(const string &name, Grid *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 *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(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 *grid) { debMsg("Writing real grid " << grid->getName() << " to vdb file " << name, 1); diff --git a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp index 432cbc9f100..a6cc7583327 100644 --- a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp +++ b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp @@ -310,6 +310,8 @@ template void readPdataUni(const std::string &name, ParticleDataImpl UniPartHeader head; assertMsg(gzread(gzf, &head, sizeof(UniPartHeader)) == sizeof(UniPartHeader), "can't read file, no header present"); + pdata->resize(head.dim); + assertMsg(head.dim == pdata->size(), "pdata size doesn't match"); # if FLOATINGPOINT_PRECISION != 1 ParticleDataImpl temp(pdata->getParent()); diff --git a/extern/mantaflow/preprocessed/fluidsolver.cpp b/extern/mantaflow/preprocessed/fluidsolver.cpp index 814d5444b15..8c48e60760b 100644 --- a/extern/mantaflow/preprocessed/fluidsolver.cpp +++ b/extern/mantaflow/preprocessed/fluidsolver.cpp @@ -136,9 +136,9 @@ FluidSolver::FluidSolver(Vec3i gridsize, int dim, int fourthDim) mDtMin(1.), mDtMax(1.), mFrameLength(1.), + mTimePerFrame(0.), mGridSize(gridsize), mDim(dim), - mTimePerFrame(0.), mLockDt(false), mFourthDim(fourthDim) { diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h index 6d3abd1e88e..943840958f6 100644 --- a/extern/mantaflow/preprocessed/gitinfo.h +++ b/extern/mantaflow/preprocessed/gitinfo.h @@ -1,3 +1,3 @@ -#define MANTA_GIT_VERSION "commit 3f5c7989fd82920f0c509844a06e97dd1069191c" +#define MANTA_GIT_VERSION "commit abfff159b5ea8cee93d858f4b8be2a308b58b51d" diff --git a/extern/mantaflow/preprocessed/plugin/flip.cpp b/extern/mantaflow/preprocessed/plugin/flip.cpp index f6d082900b5..4dfeff1d0ac 100644 --- a/extern/mantaflow/preprocessed/plugin/flip.cpp +++ b/extern/mantaflow/preprocessed/plugin/flip.cpp @@ -1407,7 +1407,6 @@ struct correctLevelset : public KernelBase { { if (rAcc(i, j, k) <= VECTOR_EPSILON) return; // outside nothing happens - Real x = pAcc(i, j, k).x; // create jacobian of pAcc via central differences Matrix3x3f jacobian = Matrix3x3f(0.5 * (pAcc(i + 1, j, k).x - pAcc(i - 1, j, k).x), diff --git a/extern/mantaflow/preprocessed/plugin/fluidguiding.cpp b/extern/mantaflow/preprocessed/plugin/fluidguiding.cpp index 13383581123..18a5a37771f 100644 --- a/extern/mantaflow/preprocessed/plugin/fluidguiding.cpp +++ b/extern/mantaflow/preprocessed/plugin/fluidguiding.cpp @@ -381,7 +381,6 @@ void getSpiralVelocity(const FlagGrid &flags, nz = flags.getSizeZ(); Real midX = 0.5 * (Real)(nx - 1); Real midY = 0.5 * (Real)(ny - 1); - Real midZ = 0.5 * (Real)(nz - 1); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { for (int k = 0; k < nz; k++) { diff --git a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp index 281e12ef04b..18582d57e64 100644 --- a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp +++ b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp @@ -1099,7 +1099,7 @@ void PbRegister_flipSampleSecondaryParticles() // evaluates cubic spline with radius h and distance l in dim dimensions Real cubicSpline(const Real h, const Real l, const int dim) { - const Real h2 = square(h), h3 = h2 * h, h4 = h3 * h, h5 = h4 * h; + const Real h2 = square(h), h3 = h2 * h; const Real c[] = { Real(2e0 / (3e0 * h)), Real(10e0 / (7e0 * M_PI * h2)), Real(1e0 / (M_PI * h3))}; const Real q = l / h; @@ -1175,9 +1175,6 @@ struct knFlipUpdateSecondaryParticlesLinear : public KernelBase { } Vec3i gridpos = toVec3i(pts_sec[idx].pos); - int i = gridpos.x; - int j = gridpos.y; - int k = gridpos.z; // spray particle if (neighborRatio(gridpos) < c_s) { -- cgit v1.2.3