Skip to content

Commit

Permalink
Merge pull request #1525 from sideeffects/send_upstream_hollowmesh
Browse files Browse the repository at this point in the history
Support for hollow VDBs
  • Loading branch information
jmlait authored Jul 25, 2023
2 parents 23e5e7a + bc96671 commit da409c2
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 34 deletions.
42 changes: 40 additions & 2 deletions openvdb/openvdb/tools/LevelSetRebuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
#ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
#define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED

/// When rebuilding we convert from grid -> mesh -> grid.
/// The conversion from mesh -> grid will close any internal bubbles.
/// By using the original grid as an oracle we can set the sign of the
/// bubbles properly. Unfortunately, when increasing resolution the
/// rasterization of the mesh diverges too far from interpolated original
/// grid and results in incorrect sign choices. The likely correct solution
/// is to use a different approach for rebuilding when resolution is
/// increasing.
#define OPENVDB_USE_ORACLE_IN_REBUILD 0

#include <openvdb/Grid.h>
#include <openvdb/Exceptions.h>
#include <openvdb/math/Math.h>
#include <openvdb/math/Transform.h>
#if OPENVDB_USE_ORACLE_IN_REBUILD
#include <openvdb/tools/VolumeToMesh.h>
#include <openvdb/tools/MeshToVolume.h>
#include <openvdb/tools/Interpolation.h>
#endif
#include <openvdb/util/NullInterrupter.h>
#include <openvdb/util/Util.h>
#include <openvdb/openvdb.h>
Expand Down Expand Up @@ -250,13 +265,36 @@ doLevelSetRebuild(const GridType& grid, typename GridType::ValueType iso,

QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives);

#if OPENVDB_USE_ORACLE_IN_REBUILD
auto backToOldGrid = [&xform, &grid](const Coord& coord) -> openvdb::math::Vec3d {
return grid.transform().worldToIndex(xform->indexToWorld(coord));
};

auto interiorTest = [acc = grid.getConstAccessor(), &backToOldGrid, &xform](const Coord& coord) -> bool {
if (xform == nullptr) {
return acc.getValue(coord) <= 0 ? true : false;
} else {
float value = openvdb::tools::BoxSampler::sample(acc, backToOldGrid(coord));
return value <= 0 ? true : false;
}
};
#endif

if (interrupter) {
return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
DISABLE_RENORMALIZATION, nullptr);
DISABLE_RENORMALIZATION, nullptr
#if OPENVDB_USE_ORACLE_IN_REBUILD
, interiorTest, EVAL_EVERY_VOXEL
#endif
);
}

return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
DISABLE_RENORMALIZATION, nullptr);
DISABLE_RENORMALIZATION, nullptr
#if OPENVDB_USE_ORACLE_IN_REBUILD
, interiorTest, EVAL_EVERY_VOXEL
#endif
);
}


Expand Down
Loading

0 comments on commit da409c2

Please sign in to comment.