Skip to content

Commit da409c2

Browse files
authored
Merge pull request #1525 from sideeffects/send_upstream_hollowmesh
Support for hollow VDBs
2 parents 23e5e7a + bc96671 commit da409c2

File tree

4 files changed

+347
-34
lines changed

4 files changed

+347
-34
lines changed

openvdb/openvdb/tools/LevelSetRebuild.h

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@
44
#ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
55
#define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED
66

7+
/// When rebuilding we convert from grid -> mesh -> grid.
8+
/// The conversion from mesh -> grid will close any internal bubbles.
9+
/// By using the original grid as an oracle we can set the sign of the
10+
/// bubbles properly. Unfortunately, when increasing resolution the
11+
/// rasterization of the mesh diverges too far from interpolated original
12+
/// grid and results in incorrect sign choices. The likely correct solution
13+
/// is to use a different approach for rebuilding when resolution is
14+
/// increasing.
15+
#define OPENVDB_USE_ORACLE_IN_REBUILD 0
16+
717
#include <openvdb/Grid.h>
818
#include <openvdb/Exceptions.h>
919
#include <openvdb/math/Math.h>
1020
#include <openvdb/math/Transform.h>
21+
#if OPENVDB_USE_ORACLE_IN_REBUILD
22+
#include <openvdb/tools/VolumeToMesh.h>
23+
#include <openvdb/tools/MeshToVolume.h>
24+
#include <openvdb/tools/Interpolation.h>
25+
#endif
1126
#include <openvdb/util/NullInterrupter.h>
1227
#include <openvdb/util/Util.h>
1328
#include <openvdb/openvdb.h>
@@ -250,13 +265,36 @@ doLevelSetRebuild(const GridType& grid, typename GridType::ValueType iso,
250265

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

268+
#if OPENVDB_USE_ORACLE_IN_REBUILD
269+
auto backToOldGrid = [&xform, &grid](const Coord& coord) -> openvdb::math::Vec3d {
270+
return grid.transform().worldToIndex(xform->indexToWorld(coord));
271+
};
272+
273+
auto interiorTest = [acc = grid.getConstAccessor(), &backToOldGrid, &xform](const Coord& coord) -> bool {
274+
if (xform == nullptr) {
275+
return acc.getValue(coord) <= 0 ? true : false;
276+
} else {
277+
float value = openvdb::tools::BoxSampler::sample(acc, backToOldGrid(coord));
278+
return value <= 0 ? true : false;
279+
}
280+
};
281+
#endif
282+
253283
if (interrupter) {
254284
return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
255-
DISABLE_RENORMALIZATION, nullptr);
285+
DISABLE_RENORMALIZATION, nullptr
286+
#if OPENVDB_USE_ORACLE_IN_REBUILD
287+
, interiorTest, EVAL_EVERY_VOXEL
288+
#endif
289+
);
256290
}
257291

258292
return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
259-
DISABLE_RENORMALIZATION, nullptr);
293+
DISABLE_RENORMALIZATION, nullptr
294+
#if OPENVDB_USE_ORACLE_IN_REBUILD
295+
, interiorTest, EVAL_EVERY_VOXEL
296+
#endif
297+
);
260298
}
261299

262300

0 commit comments

Comments
 (0)