Skip to content

Commit

Permalink
Fix possibly missing tiles from the center of large & repetive volumes.
Browse files Browse the repository at this point in the history
Fix Makefile's usage of both OPENVDB_HOME & OPENVDB_ROOT
  • Loading branch information
rzulak committed Sep 19, 2018
1 parent bb7c138 commit c34338f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ifneq (${USE_OPENVDB},)
MY_CMAKE_FLAGS += -DUSE_OPENVDB:BOOL=${USE_OPENVDB}
endif

ifneq (${OPENVDB_HOME},)
ifneq (${OPENVDB_ROOT},)
MY_CMAKE_FLAGS += -DOPENVDB_ROOT:STRING=${OPENVDB_ROOT}
endif

Expand Down
26 changes: 15 additions & 11 deletions src/openvdb.imageio/openvdbinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,29 @@ struct VDBReader {
*data = value;
}

static void readTile(const TreeType& tree, int x, int y, int z,
static void readTile(const GridType& grid, int x, int y, int z,
ValueType *values) {
const openvdb::Coord xyz(x, y, z);
const Int2Type* intNode = tree.template probeConstNode<Int2Type>(xyz);
const LeafType* leafNode = tree.probeConstLeaf(xyz);
if (leafNode) {
CoordBBox bbox = leafNode->getNodeBoundingBox();
const RootType& root = grid.tree().root();
// Use the GridType::ConstAccessor so only one query needs to be done.
// From that query, check the node type from 'most interesting' to least
typename GridType::ConstAccessor cache = grid.getConstAccessor();
if (auto* leaf = root.probeConstLeafAndCache (xyz, cache)) {
CoordBBox bbox = leaf->getNodeBoundingBox();
ASSERT((bbox.min().x() == x &&
bbox.min().y() == y &&
bbox.min().z() == z) && "Tile access unaligned");
ASSERT((bbox.dim() == Coord(LeafType::DIM)) &&
"Unexpected tile dimensions");
// Have OpenVDB fill the dense block, into the values pointer
DenseT dense(bbox, values);
leafNode->copyToDense(bbox, dense);
} else if (intNode) {
setTile(values, intNode->getValue(xyz));
leaf->copyToDense(bbox, dense);
} else if (auto* i1Node = cache.template getNode<Int1Type>()) {
setTile(values, i1Node->getValue(xyz));
} else if (auto* i2Node = cache.template getNode<Int2Type>()) {
setTile(values, i2Node->getValue(xyz));
} else {
setTile(values, ValueType(0));
setTile(values, root.background());
}
}

Expand Down Expand Up @@ -485,12 +489,12 @@ OpenVDBInput::read_native_tile (int subimage, int miplevel,
const layerrecord &lay = m_layers[m_subimage];
if (lay.spec.format == TypeFloat) {
VDBReader<FloatGrid>::readTile(
gridPtrCast<ScalarGrid>(lay.grid)->tree(),
*gridPtrCast<ScalarGrid>(lay.grid),
x, y, z, reinterpret_cast<float*>(data));
return true;
} else if (lay.spec.format == TypeVector) {
VDBReader<Vec3fGrid>::readTile(
gridPtrCast<Vec3fGrid>(lay.grid)->tree(),
*gridPtrCast<Vec3fGrid>(lay.grid),
x, y, z, reinterpret_cast<Vec3f*>(data));
return true;
}
Expand Down

0 comments on commit c34338f

Please sign in to comment.