|
4 | 4 | #ifndef OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED |
5 | 5 | #define OPENVDB_TOOLS_LEVELSETREBUILD_HAS_BEEN_INCLUDED |
6 | 6 |
|
| 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 | + |
7 | 17 | #include <openvdb/Grid.h> |
8 | 18 | #include <openvdb/Exceptions.h> |
9 | 19 | #include <openvdb/math/Math.h> |
10 | 20 | #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 |
11 | 26 | #include <openvdb/util/NullInterrupter.h> |
12 | 27 | #include <openvdb/util/Util.h> |
13 | 28 | #include <openvdb/openvdb.h> |
@@ -250,13 +265,36 @@ doLevelSetRebuild(const GridType& grid, typename GridType::ValueType iso, |
250 | 265 |
|
251 | 266 | QuadAndTriangleDataAdapter<Vec3s, Vec4I> mesh(points, primitives); |
252 | 267 |
|
| 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 | + |
253 | 283 | if (interrupter) { |
254 | 284 | 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 | + ); |
256 | 290 | } |
257 | 291 |
|
258 | 292 | 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 | + ); |
260 | 298 | } |
261 | 299 |
|
262 | 300 |
|
|
0 commit comments