Skip to content

Commit 072a501

Browse files
committed
Guard the levelset rebuild oracle behind a #define. There are issues
when increasing resolution. We still include it because we want anyone who thinks of trying this approach in the future to have an example and some documentation of what goes wrong. Add explicit instantiation for oracle-less meshToVolume, which should allow the explicit template builds to work. Signed-off-by: Jeff Lait <jlait@andorra.sidefx.com>
1 parent d4bdeb5 commit 072a501

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

openvdb/openvdb/tools/LevelSetRebuild.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +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
1122
#include <openvdb/tools/VolumeToMesh.h>
1223
#include <openvdb/tools/MeshToVolume.h>
1324
#include <openvdb/tools/Interpolation.h>
25+
#endif
1426
#include <openvdb/util/NullInterrupter.h>
1527
#include <openvdb/util/Util.h>
1628
#include <openvdb/openvdb.h>
@@ -253,6 +265,7 @@ doLevelSetRebuild(const GridType& grid, typename GridType::ValueType iso,
253265

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

268+
#if OPENVDB_USE_ORACLE_IN_REBUILD
256269
auto backToOldGrid = [&xform, &grid](const Coord& coord) -> openvdb::math::Vec3d {
257270
return grid.transform().worldToIndex(xform->indexToWorld(coord));
258271
};
@@ -265,14 +278,23 @@ doLevelSetRebuild(const GridType& grid, typename GridType::ValueType iso,
265278
return value <= 0 ? true : false;
266279
}
267280
};
281+
#endif
268282

269283
if (interrupter) {
270284
return meshToVolume<GridType>(*interrupter, mesh, *transform, exBandWidth, inBandWidth,
271-
DISABLE_RENORMALIZATION, nullptr, interiorTest, EVAL_EVERY_VOXEL);
285+
DISABLE_RENORMALIZATION, nullptr
286+
#if OPENVDB_USE_ORACLE_IN_REBUILD
287+
, interiorTest, EVAL_EVERY_VOXEL
288+
#endif
289+
);
272290
}
273291

274292
return meshToVolume<GridType>(mesh, *transform, exBandWidth, inBandWidth,
275-
DISABLE_RENORMALIZATION, nullptr, interiorTest, EVAL_EVERY_VOXEL);
293+
DISABLE_RENORMALIZATION, nullptr
294+
#if OPENVDB_USE_ORACLE_IN_REBUILD
295+
, interiorTest, EVAL_EVERY_VOXEL
296+
#endif
297+
);
276298
}
277299

278300

openvdb/openvdb/tools/MeshToVolume.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4448,14 +4448,14 @@ createLevelSetBox(const math::BBox<VecType>& bbox,
44484448
#define _FUNCTION(TreeT) \
44494449
Grid<TreeT>::Ptr meshToVolume<Grid<TreeT>>(util::NullInterrupter&, \
44504450
const QuadAndTriangleDataAdapter<Vec3s, Vec3I>&, const openvdb::math::Transform&, \
4451-
float, float, int, Grid<TreeT>::ValueConverter<Int32>::Type*)
4451+
float, float, int, Grid<TreeT>::ValueConverter<Int32>::Type*, std::nullptr_t, InteriorTestStrategy)
44524452
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
44534453
#undef _FUNCTION
44544454

44554455
#define _FUNCTION(TreeT) \
44564456
Grid<TreeT>::Ptr meshToVolume<Grid<TreeT>>(util::NullInterrupter&, \
44574457
const QuadAndTriangleDataAdapter<Vec3s, Vec4I>&, const openvdb::math::Transform&, \
4458-
float, float, int, Grid<TreeT>::ValueConverter<Int32>::Type*)
4458+
float, float, int, Grid<TreeT>::ValueConverter<Int32>::Type*, std::nullptr_t, InteriorTestStrategy)
44594459
OPENVDB_REAL_TREE_INSTANTIATE(_FUNCTION)
44604460
#undef _FUNCTION
44614461

0 commit comments

Comments
 (0)