Loading...
Searching...
No Matches
LeafNode.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
#ifndef OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
#define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
#include <openvdb/Types.h>
#include <openvdb/util/NodeMasks.h>
#include <openvdb/io/Compression.h> // for io::readData(), etc.
#include "Iterator.h"
#include "LeafBuffer.h"
#include <algorithm> // for std::nth_element()
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
class TestLeaf;
template<typename> class TestLeafIO;
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace tree {
template<Index, typename> struct SameLeafConfig; // forward declaration
/// @brief Templated block class to hold specific data types and a fixed
/// number of values determined by Log2Dim. The actual coordinate
/// dimension of the block is 2^Log2Dim, i.e. Log2Dim=3 corresponds to
/// a LeafNode that spans a 8^3 block.
template<typename T, Index Log2Dim>
class LeafNode
{
public:
using BuildType = T;
using ValueType = T;
using Buffer = LeafBuffer<ValueType, Log2Dim>;
using LeafNodeType = LeafNode<ValueType, Log2Dim>;
using NodeMaskType = util::NodeMask<Log2Dim>;
using Ptr = SharedPtr<LeafNode>;
static const Index
LOG2DIM = Log2Dim, // needed by parent nodes
TOTAL = Log2Dim, // needed by parent nodes
DIM = 1 << TOTAL, // dimension along one coordinate direction
NUM_VALUES = 1 << 3 * Log2Dim,
NUM_VOXELS = NUM_VALUES, // total number of voxels represented by this node
SIZE = NUM_VALUES,
LEVEL = 0; // level 0 = leaf
/// @brief ValueConverter<T>::Type is the type of a LeafNode having the same
/// dimensions as this node but a different value type, T.
template<typename OtherValueType>
struct ValueConverter { using Type = LeafNode<OtherValueType, Log2Dim>; };
/// @brief SameConfiguration<OtherNodeType>::value is @c true if and only if
/// OtherNodeType is the type of a LeafNode with the same dimensions as this node.
template<typename OtherNodeType>
struct SameConfiguration {
static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
};
/// Default constructor
LeafNode();
/// @brief Constructor
/// @param coords the grid index coordinates of a voxel
/// @param value a value with which to fill the buffer
/// @param active the active state to which to initialize all voxels
explicit LeafNode(const Coord& coords,
const ValueType& value = zeroVal<ValueType>(),
bool active = false);
/// @brief "Partial creation" constructor used during file input
/// @param coords the grid index coordinates of a voxel
/// @param value a value with which to fill the buffer
/// @param active the active state to which to initialize all voxels
/// @details This constructor does not allocate memory for voxel values.
LeafNode(PartialCreate,
const Coord& coords,
const ValueType& value = zeroVal<ValueType>(),
bool active = false);
/// Deep copy constructor
LeafNode(const LeafNode&);
/// Deep assignment operator
LeafNode& operator=(const LeafNode&) = default;
/// Value conversion copy constructor
template<typename OtherValueType>
explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
/// Topology copy constructor
template<typename OtherValueType>
LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
const ValueType& offValue, const ValueType& onValue, TopologyCopy);
/// Topology copy constructor
template<typename OtherValueType>
LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
const ValueType& background, TopologyCopy);
/// Destructor.
~LeafNode();
//
// Statistics
//
/// Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3
static Index log2dim() { return Log2Dim; }
/// Return the number of voxels in each coordinate dimension.
static Index dim() { return DIM; }
/// Return the total number of voxels represented by this LeafNode
static Index size() { return SIZE; }
/// Return the total number of voxels represented by this LeafNode
static Index numValues() { return SIZE; }
/// Return the level of this node, which by definition is zero for LeafNodes
static Index getLevel() { return LEVEL; }
/// Append the Log2Dim of this LeafNode to the specified vector
static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
/// Return the dimension of child nodes of this LeafNode, which is one for voxels.
static Index getChildDim() { return 1; }
/// Return the leaf count for this node, which is one.
static Index32 leafCount() { return 1; }
/// no-op
void nodeCount(std::vector<Index32> &) const {}
/// Return the non-leaf count for this node, which is zero.
static Index32 nonLeafCount() { return 0; }
/// Return the child count for this node, which is zero.
static Index32 childCount() { return 0; }
/// Return the number of voxels marked On.
Index64 onVoxelCount() const { return mValueMask.countOn(); }
/// Return the number of voxels marked Off.
Index64 offVoxelCount() const { return mValueMask.countOff(); }
Index64 onLeafVoxelCount() const { return onVoxelCount(); }
Index64 offLeafVoxelCount() const { return offVoxelCount(); }
static Index64 onTileCount() { return 0; }
static Index64 offTileCount() { return 0; }
/// Return @c true if this node has no active voxels.
bool isEmpty() const { return mValueMask.isOff(); }
/// Return @c true if this node contains only active voxels.
bool isDense() const { return mValueMask.isOn(); }
/// Return @c true if memory for this node's buffer has been allocated.
bool isAllocated() const { return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
/// Allocate memory for this node's buffer if it has not already been allocated.
bool allocate() { return mBuffer.allocate(); }
/// Return the memory in bytes occupied by this node.
Index64 memUsage() const;
Index64 memUsageIfLoaded() const;
/// Expand the given bounding box so that it includes this leaf node's active voxels.
/// If visitVoxels is false this LeafNode will be approximated as dense, i.e. with all
/// voxels active. Else the individual active voxels are visited to produce a tight bbox.
void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
/// @brief Return the bounding box of this node, i.e., the full index space
/// spanned by this leaf node.
CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
/// Set the grid index coordinates of this node's local origin.
void setOrigin(const Coord& origin) { mOrigin = origin; }
//@{
/// Return the grid index coordinates of this node's local origin.
const Coord& origin() const { return mOrigin; }
void getOrigin(Coord& origin) const { origin = mOrigin; }
void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
//@}
/// Return the linear table offset of the given global or local coordinates.
static Index coordToOffset(const Coord& xyz);
/// @brief Return the local coordinates for a linear table offset,
/// where offset 0 has coordinates (0, 0, 0).
static Coord offsetToLocalCoord(Index n);
/// Return the global coordinates for a linear table offset.
Coord offsetToGlobalCoord(Index n) const;
/// Return the transient data value.
Index32 transientData() const { return mTransientData; }
/// Set the transient data value.
void setTransientData(Index32 transientData) { mTransientData = transientData; }
/// Return a string representation of this node.
std::string str() const;
/// @brief Return @c true if the given node (which may have a different @c ValueType
/// than this node) has the same active value topology as this node.
template<typename OtherType, Index OtherLog2Dim>
bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
/// Check for buffer, state and origin equivalence.
bool operator==(const LeafNode& other) const;
bool operator!=(const LeafNode& other) const { return !(other == *this); }
protected:
using MaskOnIterator = typename NodeMaskType::OnIterator;
using MaskOffIterator = typename NodeMaskType::OffIterator;
using MaskDenseIterator = typename NodeMaskType::DenseIterator;
// Type tags to disambiguate template instantiations
struct ValueOn {}; struct ValueOff {}; struct ValueAll {};
struct ChildOn {}; struct ChildOff {}; struct ChildAll {};
template<typename MaskIterT, typename NodeT, typename ValueT, typename TagT>
struct ValueIter:
// Derives from SparseIteratorBase, but can also be used as a dense iterator,
// if MaskIterT is a dense mask iterator type.
public SparseIteratorBase<
MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
{
using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
ValueIter() {}
ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
ValueT& getItem(Index pos) const { return this->parent().getValue(pos); }
ValueT& getValue() const { return this->parent().getValue(this->pos()); }
// Note: setItem() can't be called on const iterators.
void setItem(Index pos, const ValueT& value) const
{
this->parent().setValueOnly(pos, value);
}
// Note: setValue() can't be called on const iterators.
void setValue(const ValueT& value) const
{
this->parent().setValueOnly(this->pos(), value);
}
// Note: modifyItem() can't be called on const iterators.
template<typename ModifyOp>
void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
// Note: modifyValue() can't be called on const iterators.
template<typename ModifyOp>
void modifyValue(const ModifyOp& op) const { this->parent().modifyValue(this->pos(), op); }
};
/// Leaf nodes have no children, so their child iterators have no get/set accessors.
template<typename MaskIterT, typename NodeT, typename TagT>
struct ChildIter:
public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
{
ChildIter() {}
ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>(iter, parent) {}
};
template<typename NodeT, typename ValueT, typename TagT>
struct DenseIter: public DenseIteratorBase<
MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, /*ChildT=*/void, ValueT>
{
using BaseT = DenseIteratorBase<MaskDenseIterator, DenseIter, NodeT, void, ValueT>;
using NonConstValueT = typename BaseT::NonConstValueType;
DenseIter() {}
DenseIter(const MaskDenseIterator& iter, NodeT* parent): BaseT(iter, parent) {}
bool getItem(Index pos, void*& child, NonConstValueT& value) const
{
value = this->parent().getValue(pos);
child = nullptr;
return false; // no child
}
// Note: setItem() can't be called on const iterators.
//void setItem(Index pos, void* child) const {}
// Note: unsetItem() can't be called on const iterators.
void unsetItem(Index pos, const ValueT& value) const
{
this->parent().setValueOnly(pos, value);
}
};
public:
using ValueOnIter = ValueIter<MaskOnIterator, LeafNode, const ValueType, ValueOn>;
using ValueOnCIter = ValueIter<MaskOnIterator, const LeafNode, const ValueType, ValueOn>;
using ValueOffIter = ValueIter<MaskOffIterator, LeafNode, const ValueType, ValueOff>;
using ValueOffCIter = ValueIter<MaskOffIterator,const LeafNode,const ValueType,ValueOff>;
using ValueAllIter = ValueIter<MaskDenseIterator, LeafNode, const ValueType, ValueAll>;
using ValueAllCIter = ValueIter<MaskDenseIterator,const LeafNode,const ValueType,ValueAll>;
using ChildOnIter = ChildIter<MaskOnIterator, LeafNode, ChildOn>;
using ChildOnCIter = ChildIter<MaskOnIterator, const LeafNode, ChildOn>;
using ChildOffIter = ChildIter<MaskOffIterator, LeafNode, ChildOff>;
using ChildOffCIter = ChildIter<MaskOffIterator, const LeafNode, ChildOff>;
using ChildAllIter = DenseIter<LeafNode, ValueType, ChildAll>;
using ChildAllCIter = DenseIter<const LeafNode, const ValueType, ChildAll>;
ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
// Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
// because leaf nodes have no children.
ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
//
// Buffer management
//
/// @brief Exchange this node's data buffer with the given data buffer
/// without changing the active states of the values.
void swap(Buffer& other) { mBuffer.swap(other); }
const Buffer& buffer() const { return mBuffer; }
Buffer& buffer() { return mBuffer; }
//
// I/O methods
//
/// @brief Read in just the topology.
/// @param is the stream from which to read
/// @param fromHalf if true, floating-point input values are assumed to be 16-bit
void readTopology(std::istream& is, bool fromHalf = false);
/// @brief Write out just the topology.
/// @param os the stream to which to write
/// @param toHalf if true, output floating-point values as 16-bit half floats
void writeTopology(std::ostream& os, bool toHalf = false) const;
/// @brief Read buffers from a stream.
/// @param is the stream from which to read
/// @param fromHalf if true, floating-point input values are assumed to be 16-bit
void readBuffers(std::istream& is, bool fromHalf = false);
/// @brief Read buffers that intersect the given bounding box.
/// @param is the stream from which to read
/// @param bbox an index-space bounding box
/// @param fromHalf if true, floating-point input values are assumed to be 16-bit
void readBuffers(std::istream& is, const CoordBBox& bbox, bool fromHalf = false);
/// @brief Write buffers to a stream.
/// @param os the stream to which to write
/// @param toHalf if true, output floating-point values as 16-bit half floats
void writeBuffers(std::ostream& os, bool toHalf = false) const;
size_t streamingSize(bool toHalf = false) const;
//
// Accessor methods
//
/// Return the value of the voxel at the given coordinates.
const ValueType& getValue(const Coord& xyz) const;
/// Return the value of the voxel at the given linear offset.
const ValueType& getValue(Index offset) const;
/// @brief Return @c true if the voxel at the given coordinates is active.
/// @param xyz the coordinates of the voxel to be probed
/// @param[out] val the value of the voxel at the given coordinates
bool probeValue(const Coord& xyz, ValueType& val) const;
/// @brief Return @c true if the voxel at the given offset is active.
/// @param offset the linear offset of the voxel to be probed
/// @param[out] val the value of the voxel at the given coordinates
bool probeValue(Index offset, ValueType& val) const;
/// Return the level (i.e., 0) at which leaf node values reside.
static Index getValueLevel(const Coord&) { return LEVEL; }
/// Set the active state of the voxel at the given coordinates but don't change its value.
void setActiveState(const Coord& xyz, bool on);
/// Set the active state of the voxel at the given offset but don't change its value.
void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
/// Set the value of the voxel at the given coordinates but don't change its active state.
void setValueOnly(const Coord& xyz, const ValueType& val);
/// Set the value of the voxel at the given offset but don't change its active state.
void setValueOnly(Index offset, const ValueType& val);
/// Mark the voxel at the given coordinates as inactive but don't change its value.
void setValueOff(const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
/// Mark the voxel at the given offset as inactive but don't change its value.
void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
/// Set the value of the voxel at the given coordinates and mark the voxel as inactive.
void setValueOff(const Coord& xyz, const ValueType& val);
/// Set the value of the voxel at the given offset and mark the voxel as inactive.
void setValueOff(Index offset, const ValueType& val);
/// Mark the voxel at the given coordinates as active but don't change its value.
void setValueOn(const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
/// Mark the voxel at the given offset as active but don't change its value.
void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
/// Set the value of the voxel at the given coordinates and mark the voxel as active.
void setValueOn(const Coord& xyz, const ValueType& val) {
this->setValueOn(LeafNode::coordToOffset(xyz), val);
}
/// Set the value of the voxel at the given coordinates and mark the voxel as active.
void setValue(const Coord& xyz, const ValueType& val) { this->setValueOn(xyz, val); }
/// Set the value of the voxel at the given offset and mark the voxel as active.
void setValueOn(Index offset, const ValueType& val) {
mBuffer.setValue(offset, val);
mValueMask.setOn(offset);
}
/// @brief Apply a functor to the value of the voxel at the given offset
/// and mark the voxel as active.
template<typename ModifyOp>
void modifyValue(Index offset, const ModifyOp& op)
{
mBuffer.loadValues();
if (!mBuffer.empty()) {
// in-place modify value
ValueType& val = const_cast< ValueType&>(mBuffer[offset]);
op(val);
mValueMask.setOn(offset);
}
}
/// @brief Apply a functor to the value of the voxel at the given coordinates
/// and mark the voxel as active.
template<typename ModifyOp>
void modifyValue(const Coord& xyz, const ModifyOp& op)
{
this->modifyValue(this->coordToOffset(xyz), op);
}
/// Apply a functor to the voxel at the given coordinates.
template<typename ModifyOp>
void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
{
mBuffer.loadValues();
if (!mBuffer.empty()) {
const Index offset = this->coordToOffset(xyz);
bool state = mValueMask.isOn(offset);
// in-place modify value
ValueType& val = const_cast< ValueType&>(mBuffer[offset]);
op(val, state);
mValueMask.set(offset, state);
}
}
/// Mark all voxels as active but don't change their values.
void setValuesOn() { mValueMask.setOn(); }
/// Mark all voxels as inactive but don't change their values.
void setValuesOff() { mValueMask.setOff(); }
/// Return @c true if the voxel at the given coordinates is active.
bool isValueOn(const Coord& xyz) const {return this->isValueOn(LeafNode::coordToOffset(xyz));}
/// Return @c true if the voxel at the given offset is active.
bool isValueOn(Index offset) const { return mValueMask.isOn(offset); }
/// Return @c false since leaf nodes never contain tiles.
static bool hasActiveTiles() { return false; }
/// Set all voxels that lie outside the given axis-aligned box to the background.
void clip(const CoordBBox&, const ValueType& background);
/// Set all voxels within an axis-aligned box to the specified value and active state.
void fill(const CoordBBox& bbox, const ValueType&, bool active = true);
/// Set all voxels within an axis-aligned box to the specified value and active state.
void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true)
{
this->fill(bbox, value, active);
}
/// Set all voxels to the specified value but don't change their active states.
void fill(const ValueType& value);
/// Set all voxels to the specified value and active state.
void fill(const ValueType& value, bool active);
/// @brief Copy into a dense grid the values of the voxels that lie within
/// a given bounding box.
///
/// @param bbox inclusive bounding box of the voxels to be copied into the dense grid
/// @param dense dense grid with a stride in @e z of one (see tools::Dense
/// in tools/Dense.h for the required API)
///
/// @note @a bbox is assumed to be identical to or contained in the coordinate domains
/// of both the dense grid and this node, i.e., no bounds checking is performed.
/// @note Consider using tools::CopyToDense in tools/Dense.h
/// instead of calling this method directly.
template<typename DenseT>
void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
/// @brief Copy from a dense grid into this node the values of the voxels
/// that lie within a given bounding box.
/// @details Only values that are different (by more than the given tolerance)
/// from the background value will be active. Other values are inactive
/// and truncated to the background value.
///
/// @param bbox inclusive bounding box of the voxels to be copied into this node
/// @param dense dense grid with a stride in @e z of one (see tools::Dense
/// in tools/Dense.h for the required API)
/// @param background background value of the tree that this node belongs to
/// @param tolerance tolerance within which a value equals the background value
///
/// @note @a bbox is assumed to be identical to or contained in the coordinate domains
/// of both the dense grid and this node, i.e., no bounds checking is performed.
/// @note Consider using tools::CopyFromDense in tools/Dense.h
/// instead of calling this method directly.
template<typename DenseT>
void copyFromDense(const CoordBBox& bbox, const DenseT& dense,
const ValueType& background, const ValueType& tolerance);
/// @brief Return the value of the voxel at the given coordinates.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
const ValueType& getValueAndCache(const Coord& xyz, AccessorT&) const
{
return this->getValue(xyz);
}
/// @brief Return @c true if the voxel at the given coordinates is active.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
/// @brief Change the value of the voxel at the given coordinates and mark it as active.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
void setValueAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
{
this->setValueOn(xyz, val);
}
/// @brief Change the value of the voxel at the given coordinates
/// but preserve its state.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
void setValueOnlyAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
{
this->setValueOnly(xyz, val);
}
/// @brief Apply a functor to the value of the voxel at the given coordinates
/// and mark the voxel as active.
/// @note Used internally by ValueAccessor.
template<typename ModifyOp, typename AccessorT>
void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
{
this->modifyValue(xyz, op);
}
/// Apply a functor to the voxel at the given coordinates.
/// @note Used internally by ValueAccessor.
template<typename ModifyOp, typename AccessorT>
void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
{
this->modifyValueAndActiveState(xyz, op);
}
/// @brief Change the value of the voxel at the given coordinates and mark it as inactive.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
void setValueOffAndCache(const Coord& xyz, const ValueType& value, AccessorT&)
{
this->setValueOff(xyz, value);
}
/// @brief Set the active state of the voxel at the given coordinates
/// without changing its value.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
{
this->setActiveState(xyz, on);
}
/// @brief Return @c true if the voxel at the given coordinates is active
/// and return the voxel value in @a val.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
bool probeValueAndCache(const Coord& xyz, ValueType& val, AccessorT&) const
{
return this->probeValue(xyz, val);
}
/// @brief Return the value of the voxel at the given coordinates and return
/// its active state and level (i.e., 0) in @a state and @a level.
/// @note Used internally by ValueAccessor.
template<typename AccessorT>
const ValueType& getValue(const Coord& xyz, bool& state, int& level, AccessorT&) const
{
const Index offset = this->coordToOffset(xyz);
state = mValueMask.isOn(offset);
level = LEVEL;
return mBuffer[offset];
}
/// @brief Return the LEVEL (=0) at which leaf node values reside.
/// @note Used internally by ValueAccessor (note last argument is a dummy).
template<typename AccessorT>
static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
/// @brief Return a const reference to the first value in the buffer.
/// @note Though it is potentially risky you can convert this
/// to a non-const pointer by means of const_case<ValueType*>&.
const ValueType& getFirstValue() const { return mBuffer[0]; }
/// Return a const reference to the last value in the buffer.
const ValueType& getLastValue() const { return mBuffer[SIZE - 1]; }
/// @brief Replace inactive occurrences of @a oldBackground with @a newBackground,
/// and inactive occurrences of @a -oldBackground with @a -newBackground.
void resetBackground(const ValueType& oldBackground, const ValueType& newBackground);
void negate();
/// @brief No-op
/// @details This function exists only to enable template instantiation.
void voxelizeActiveTiles(bool = true) {}
template<MergePolicy Policy> void merge(const LeafNode&);
template<MergePolicy Policy> void merge(const ValueType& tileValue, bool tileActive);
template<MergePolicy Policy>
void merge(const LeafNode& other, const ValueType& /*bg*/, const ValueType& /*otherBG*/);
/// @brief Union this node's set of active values with the active values
/// of the other node, whose @c ValueType may be different. So a
/// resulting voxel will be active if either of the original voxels
/// were active.
///
/// @note This operation modifies only active states, not values.
template<typename OtherType>
void topologyUnion(const LeafNode<OtherType, Log2Dim>& other, const bool preserveTiles = false);
/// @brief Intersect this node's set of active values with the active values
/// of the other node, whose @c ValueType may be different. So a
/// resulting voxel will be active only if both of the original voxels
/// were active.
///
/// @details The last dummy argument is required to match the signature
/// for InternalNode::topologyIntersection.
///
/// @note This operation modifies only active states, not
/// values. Also note that this operation can result in all voxels
/// being inactive so consider subsequently calling prune.
template<typename OtherType>
void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
/// @brief Difference this node's set of active values with the active values
/// of the other node, whose @c ValueType may be different. So a
/// resulting voxel will be active only if the original voxel is
/// active in this LeafNode and inactive in the other LeafNode.
///
/// @details The last dummy argument is required to match the signature
/// for InternalNode::topologyDifference.
///
/// @note This operation modifies only active states, not values.
/// Also, because it can deactivate all of this node's voxels,
/// consider subsequently calling prune.
template<typename OtherType>
void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
template<typename CombineOp>
void combine(const LeafNode& other, CombineOp& op);
template<typename CombineOp>
void combine(const ValueType& value, bool valueIsActive, CombineOp& op);
template<typename CombineOp, typename OtherType /*= ValueType*/>
void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
void combine2(const ValueType&, const OtherNodeT& other, bool valueIsActive, CombineOp&);
template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
//@{
/// This function exists only to enable template instantiation.
void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
void addLeaf(LeafNode*) {}
template<typename AccessorT>
void addLeafAndCache(LeafNode*, AccessorT&) {}
template<typename NodeT>
NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
template<typename NodeT>
NodeT* probeNode(const Coord&) { return nullptr; }
template<typename NodeT>
const NodeT* probeConstNode(const Coord&) const { return nullptr; }
template<typename ArrayT> void getNodes(ArrayT&) const {}
template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
//@}
void addTile(Index level, const Coord&, const ValueType&, bool);
void addTile(Index offset, const ValueType&, bool);
template<typename AccessorT>
void addTileAndCache(Index, const Coord&, const ValueType&, bool, AccessorT&);
//@{
/// @brief Return a pointer to this node.
LeafNode* touchLeaf(const Coord&) { return this; }
template<typename AccessorT>
LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
template<typename NodeT, typename AccessorT>
NodeT* probeNodeAndCache(const Coord&, AccessorT&)
{
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
return reinterpret_cast<NodeT*>(this);
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
}
LeafNode* probeLeaf(const Coord&) { return this; }
template<typename AccessorT>
LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
//@}
//@{
/// @brief Return a @const pointer to this node.
const LeafNode* probeConstLeaf(const Coord&) const { return this; }
template<typename AccessorT>
const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
template<typename AccessorT>
const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
const LeafNode* probeLeaf(const Coord&) const { return this; }
template<typename NodeT, typename AccessorT>
const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
{
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
return reinterpret_cast<const NodeT*>(this);
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
}
//@}
/// Return @c true if all of this node's values have the same active state
/// and are in the range this->getFirstValue() +/- @a tolerance.
///
///
/// @param firstValue Is updated with the first value of this leaf node.
/// @param state Is updated with the state of all values IF method
/// returns @c true. Else the value is undefined!
/// @param tolerance The tolerance used to determine if values are
/// approximately equal to the for value.
bool isConstant(ValueType& firstValue, bool& state,
const ValueType& tolerance = zeroVal<ValueType>()) const;
/// Return @c true if all of this node's values have the same active state
/// and the range (@a maxValue - @a minValue) < @a tolerance.
///
/// @param minValue Is updated with the minimum of all values IF method
/// returns @c true. Else the value is undefined!
/// @param maxValue Is updated with the maximum of all values IF method
/// returns @c true. Else the value is undefined!
/// @param state Is updated with the state of all values IF method
/// returns @c true. Else the value is undefined!
/// @param tolerance The tolerance used to determine if values are
/// approximately constant.
bool isConstant(ValueType& minValue, ValueType& maxValue,
bool& state, const ValueType& tolerance = zeroVal<ValueType>()) const;
/// @brief Computes the median value of all the active AND inactive voxels in this node.
/// @return The median value of all values in this node.
///
/// @param tmp Optional temporary storage that can hold at least NUM_VALUES values
/// Use of this temporary storage can improve performance
/// when this method is called multiple times.
///
/// @note If tmp = this->buffer().data() then the median
/// value is computed very efficiently (in place) but
/// the voxel values in this node are re-shuffled!
///
/// @warning If tmp != nullptr then it is the responsibility of
/// the client code that it points to enough memory to
/// hold NUM_VALUES elements of type ValueType.
ValueType medianAll(ValueType *tmp = nullptr) const;
/// @brief Computes the median value of all the active voxels in this node.
/// @return The number of active voxels.
///
/// @param value If the return value is non zero @a value is updated
/// with the median value.
///
/// @param tmp Optional temporary storage that can hold at least
/// as many values as there are active voxels in this node.
/// Use of this temporary storage can improve performance
/// when this method is called multiple times.
///
/// @warning If tmp != nullptr then it is the responsibility of
/// the client code that it points to enough memory to
/// hold the number of active voxels of type ValueType.
Index medianOn(ValueType &value, ValueType *tmp = nullptr) const;
/// @brief Computes the median value of all the inactive voxels in this node.
/// @return The number of inactive voxels.
///
/// @param value If the return value is non zero @a value is updated
/// with the median value.
///
/// @param tmp Optional temporary storage that can hold at least
/// as many values as there are inactive voxels in this node.
/// Use of this temporary storage can improve performance
/// when this method is called multiple times.
///
/// @warning If tmp != nullptr then it is the responsibility of
/// the client code that it points to enough memory to
/// hold the number of inactive voxels of type ValueType.
Index medianOff(ValueType &value, ValueType *tmp = nullptr) const;
/// Return @c true if all of this node's values are inactive.
bool isInactive() const { return mValueMask.isOff(); }
protected:
friend class ::TestLeaf;
template<typename> friend class ::TestLeafIO;
// During topology-only construction, access is needed
// to protected/private members of other template instances.
template<typename, Index> friend class LeafNode;
friend struct ValueIter<MaskOnIterator, LeafNode, ValueType, ValueOn>;
friend struct ValueIter<MaskOffIterator, LeafNode, ValueType, ValueOff>;
friend struct ValueIter<MaskDenseIterator, LeafNode, ValueType, ValueAll>;
friend struct ValueIter<MaskOnIterator, const LeafNode, ValueType, ValueOn>;
friend struct ValueIter<MaskOffIterator, const LeafNode, ValueType, ValueOff>;
friend struct ValueIter<MaskDenseIterator, const LeafNode, ValueType, ValueAll>;
// Allow iterators to call mask accessor methods (see below).
/// @todo Make mask accessors public?
friend class IteratorBase<MaskOnIterator, LeafNode>;
friend class IteratorBase<MaskOffIterator, LeafNode>;
friend class IteratorBase<MaskDenseIterator, LeafNode>;
// Mask accessors
public:
bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
bool isValueMaskOn() const { return mValueMask.isOn(); }
bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
bool isValueMaskOff() const { return mValueMask.isOff(); }
const NodeMaskType& getValueMask() const { return mValueMask; }
NodeMaskType& getValueMask() { return mValueMask; }
const NodeMaskType& valueMask() const { return mValueMask; }
void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
bool isChildMaskOff(Index) const { return true; }
bool isChildMaskOff() const { return true; }
protected:
void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
void setValueMaskOn(Index n) { mValueMask.setOn(n); }
void setValueMaskOff(Index n) { mValueMask.setOff(n); }
inline void skipCompressedValues(bool seekable, std::istream&, bool fromHalf);
/// Compute the origin of the leaf node that contains the voxel with the given coordinates.
static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
private:
/// Buffer containing the actual data values
Buffer mBuffer;
/// Bitmask that determines which voxels are active
NodeMaskType mValueMask;
/// Global grid index coordinates (x,y,z) of the local origin of this node
Coord mOrigin;
/// Transient data (not serialized)
Index32 mTransientData = 0;
}; // end of LeafNode class
////////////////////////////////////////
//@{
/// Helper metafunction used to implement LeafNode::SameConfiguration
/// (which, as an inner class, can't be independently specialized)
template<Index Dim1, typename NodeT2>
struct SameLeafConfig { static const bool value = false; };
template<Index Dim1, typename T2>
struct SameLeafConfig<Dim1, LeafNode<T2, Dim1> > { static const bool value = true; };
//@}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline
LeafNode<T, Log2Dim>::LeafNode():
mValueMask(),//default is off!
mOrigin(0, 0, 0)
{
}
template<typename T, Index Log2Dim>
inline
LeafNode<T, Log2Dim>::LeafNode(const Coord& xyz, const ValueType& val, bool active):
mBuffer(val),
mValueMask(active),
mOrigin(xyz & (~(DIM - 1)))
{
}
template<typename T, Index Log2Dim>
inline
LeafNode<T, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, const ValueType& val, bool active):
mBuffer(PartialCreate(), val),
mValueMask(active),
mOrigin(xyz & (~(DIM - 1)))
{
}
template<typename T, Index Log2Dim>
inline
LeafNode<T, Log2Dim>::LeafNode(const LeafNode& other)
: mBuffer(other.mBuffer)
, mValueMask(other.valueMask())
, mOrigin(other.mOrigin)
, mTransientData(other.mTransientData)
{
}
// Copy-construct from a leaf node with the same configuration but a different ValueType.
template<typename T, Index Log2Dim>
template<typename OtherValueType>
inline
LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other)
: mValueMask(other.valueMask())
, mOrigin(other.mOrigin)
, mTransientData(other.mTransientData)
{
struct Local {
/// @todo Consider using a value conversion functor passed as an argument instead.
static inline ValueType convertValue(const OtherValueType& val) { return ValueType(val); }
};
for (Index i = 0; i < SIZE; ++i) {
mBuffer[i] = Local::convertValue(other.mBuffer[i]);
}
}
template<typename T, Index Log2Dim>
template<typename OtherValueType>
inline
LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
const ValueType& background, TopologyCopy)
: mBuffer(background)
, mValueMask(other.valueMask())
, mOrigin(other.mOrigin)
, mTransientData(other.mTransientData)
{
}
template<typename T, Index Log2Dim>
template<typename OtherValueType>
inline
LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
const ValueType& offValue, const ValueType& onValue, TopologyCopy)
: mValueMask(other.valueMask())
, mOrigin(other.mOrigin)
, mTransientData(other.mTransientData)
{
for (Index i = 0; i < SIZE; ++i) {
mBuffer[i] = (mValueMask.isOn(i) ? onValue : offValue);
}
}
template<typename T, Index Log2Dim>
inline
LeafNode<T, Log2Dim>::~LeafNode()
{
}
template<typename T, Index Log2Dim>
inline std::string
LeafNode<T, Log2Dim>::str() const
{
std::ostringstream ostr;
ostr << "LeafNode @" << mOrigin << ": " << mBuffer;
return ostr.str();
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline Index
LeafNode<T, Log2Dim>::coordToOffset(const Coord& xyz)
{
assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
+ ((xyz[1] & (DIM-1u)) << Log2Dim)
+ (xyz[2] & (DIM-1u));
}
template<typename T, Index Log2Dim>
inline Coord
LeafNode<T, Log2Dim>::offsetToLocalCoord(Index n)
{
assert(n<(1<< 3*Log2Dim));
Coord xyz;
xyz.setX(n >> 2*Log2Dim);
n &= ((1<<2*Log2Dim)-1);
xyz.setY(n >> Log2Dim);
xyz.setZ(n & ((1<<Log2Dim)-1));
return xyz;
}
template<typename T, Index Log2Dim>
inline Coord
LeafNode<T, Log2Dim>::offsetToGlobalCoord(Index n) const
{
return (this->offsetToLocalCoord(n) + this->origin());
}
////////////////////////////////////////
template<typename ValueT, Index Log2Dim>
inline const ValueT&
LeafNode<ValueT, Log2Dim>::getValue(const Coord& xyz) const
{
return this->getValue(LeafNode::coordToOffset(xyz));
}
template<typename ValueT, Index Log2Dim>
inline const ValueT&
LeafNode<ValueT, Log2Dim>::getValue(Index offset) const
{
assert(offset < SIZE);
return mBuffer[offset];
}
template<typename T, Index Log2Dim>
inline bool
LeafNode<T, Log2Dim>::probeValue(const Coord& xyz, ValueType& val) const
{
return this->probeValue(LeafNode::coordToOffset(xyz), val);
}
template<typename T, Index Log2Dim>
inline bool
LeafNode<T, Log2Dim>::probeValue(Index offset, ValueType& val) const
{
assert(offset < SIZE);
val = mBuffer[offset];
return mValueMask.isOn(offset);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::setValueOff(const Coord& xyz, const ValueType& val)
{
this->setValueOff(LeafNode::coordToOffset(xyz), val);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::setValueOff(Index offset, const ValueType& val)
{
assert(offset < SIZE);
mBuffer.setValue(offset, val);
mValueMask.setOff(offset);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::setActiveState(const Coord& xyz, bool on)
{
mValueMask.set(this->coordToOffset(xyz), on);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::setValueOnly(const Coord& xyz, const ValueType& val)
{
this->setValueOnly(LeafNode::coordToOffset(xyz), val);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::setValueOnly(Index offset, const ValueType& val)
{
assert(offset<SIZE); mBuffer.setValue(offset, val);
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::clip(const CoordBBox& clipBBox, const T& background)
{
CoordBBox nodeBBox = this->getNodeBoundingBox();
if (!clipBBox.hasOverlap(nodeBBox)) {
// This node lies completely outside the clipping region. Fill it with the background.
this->fill(background, /*active=*/false);
} else if (clipBBox.isInside(nodeBBox)) {
// This node lies completely inside the clipping region. Leave it intact.
return;
}
// This node isn't completely contained inside the clipping region.
// Set any voxels that lie outside the region to the background value.
// Construct a boolean mask that is on inside the clipping region and off outside it.
NodeMaskType mask;
nodeBBox.intersect(clipBBox);
Coord xyz;
int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
mask.setOn(static_cast< Index32 >(this->coordToOffset(xyz)));
}
}
}
// Set voxels that lie in the inactive region of the mask (i.e., outside
// the clipping region) to the background value.
for (MaskOffIterator maskIter = mask.beginOff(); maskIter; ++maskIter) {
this->setValueOff(maskIter.pos(), background);
}
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
{
if (!this->allocate()) return;
auto clippedBBox = this->getNodeBoundingBox();
clippedBBox.intersect(bbox);
if (!clippedBBox) return;
for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
const Index offset = offsetXY + (z & (DIM-1u));
mBuffer[offset] = value;
mValueMask.set(offset, active);
}
}
}
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::fill(const ValueType& value)
{
mBuffer.fill(value);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::fill(const ValueType& value, bool active)
{
mBuffer.fill(value);
mValueMask.set(active);
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
template<typename DenseT>
inline void
LeafNode<T, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
{
mBuffer.loadValues();
using DenseValueType = typename DenseT::ValueType;
const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
const Coord& min = dense.bbox().min();
DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
const T* s0 = &mBuffer[bbox.min()[2] & (DIM-1u)]; // source array
for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
DenseValueType* t1 = t0 + xStride * (x - min[0]);
const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
DenseValueType* t2 = t1 + yStride * (y - min[1]);
const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
*t2 = DenseValueType(*s2++);
}
}
}
}
template<typename T, Index Log2Dim>
template<typename DenseT>
inline void
LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
const ValueType& background, const ValueType& tolerance)
{
if (!this->allocate()) return;
using DenseValueType = typename DenseT::ValueType;
const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
const Coord& min = dense.bbox().min();
const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
const Int32 n0 = bbox.min()[2] & (DIM-1u);
for (Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
const DenseValueType* s1 = s0 + xStride * (x - min[0]);
const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
for (Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
const DenseValueType* s2 = s1 + yStride * (y - min[1]);
Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
if (math::isApproxEqual(background, ValueType(*s2), tolerance)) {
mValueMask.setOff(n2);
mBuffer[n2] = background;
} else {
mValueMask.setOn(n2);
mBuffer[n2] = ValueType(*s2);
}
}
}
}
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
{
mValueMask.load(is);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
{
mValueMask.save(os);
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T,Log2Dim>::skipCompressedValues(bool seekable, std::istream& is, bool fromHalf)
{
if (seekable) {
// Seek over voxel values.
io::readCompressedValues<ValueType, NodeMaskType>(
is, nullptr, SIZE, mValueMask, fromHalf);
} else {
// Read and discard voxel values.
Buffer temp;
io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
}
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T,Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
{
this->readBuffers(is, CoordBBox::inf(), fromHalf);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
{
SharedPtr<io::StreamMetadata> meta = io::getStreamMetadataPtr(is);
const bool seekable = meta && meta->seekable();
#ifdef OPENVDB_USE_DELAYED_LOADING
std::streamoff maskpos = is.tellg();
#endif
if (seekable) {
// Seek over the value mask.
mValueMask.seek(is);
} else {
// Read in the value mask.
mValueMask.load(is);
}
int8_t numBuffers = 1;
if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
// Read in the origin.
is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
// Read in the number of buffers, which should now always be one.
is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
}
CoordBBox nodeBBox = this->getNodeBoundingBox();
if (!clipBBox.hasOverlap(nodeBBox)) {
// This node lies completely outside the clipping region.
skipCompressedValues(seekable, is, fromHalf);
mValueMask.setOff();
mBuffer.setOutOfCore(false);
} else {
#ifdef OPENVDB_USE_DELAYED_LOADING
// If this node lies completely inside the clipping region and it is being read
// from a memory-mapped file, delay loading of its buffer until the buffer
// is actually accessed. (If this node requires clipping, its buffer
// must be accessed and therefore must be loaded.)
io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is);
const bool delayLoad = ((mappedFile.get() != nullptr) && clipBBox.isInside(nodeBBox));
if (delayLoad) {
mBuffer.setOutOfCore(true);
mBuffer.mFileInfo = new typename Buffer::FileInfo;
mBuffer.mFileInfo->meta = meta;
mBuffer.mFileInfo->bufpos = is.tellg();
mBuffer.mFileInfo->mapping = mappedFile;
// Save the offset to the value mask, because the in-memory copy
// might change before the value buffer gets read.
mBuffer.mFileInfo->maskpos = maskpos;
// Skip over voxel values.
skipCompressedValues(seekable, is, fromHalf);
} else {
#endif
mBuffer.allocate();
io::readCompressedValues(is, mBuffer.mData, SIZE, mValueMask, fromHalf);
mBuffer.setOutOfCore(false);
// Get this tree's background value.
T background = zeroVal<T>();
if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
background = *static_cast<const T*>(bgPtr);
}
this->clip(clipBBox, background);
#ifdef OPENVDB_USE_DELAYED_LOADING
}
#endif
}
if (numBuffers > 1) {
// Read in and discard auxiliary buffers that were created with earlier
// versions of the library. (Auxiliary buffers are not mask compressed.)
const bool zipped = io::getDataCompression(is) & io::COMPRESS_ZIP;
Buffer temp;
for (int i = 1; i < numBuffers; ++i) {
if (fromHalf) {
io::HalfReader<io::RealToHalf<T>::isReal, T>::read(is, temp.mData, SIZE, zipped);
} else {
io::readData<T>(is, temp.mData, SIZE, zipped);
}
}
}
// increment the leaf number
if (meta) meta->setLeaf(meta->leaf() + 1);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
{
// Write out the value mask.
mValueMask.save(os);
mBuffer.loadValues();
io::writeCompressedValues(os, mBuffer.mData, SIZE,
mValueMask, /*childMask=*/ NodeMaskType(), toHalf);
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline bool
LeafNode<T, Log2Dim>::operator==(const LeafNode& other) const
{
return mOrigin == other.mOrigin &&
mValueMask == other.valueMask() &&
mBuffer == other.mBuffer;
}
template<typename T, Index Log2Dim>
inline Index64
LeafNode<T, Log2Dim>::memUsage() const
{
// Use sizeof(*this) to capture alignment-related padding
// (but note that sizeof(*this) includes sizeof(mBuffer)).
return sizeof(*this) + mBuffer.memUsage() - sizeof(mBuffer);
}
template<typename T, Index Log2Dim>
inline Index64
LeafNode<T, Log2Dim>::memUsageIfLoaded() const
{
// Use sizeof(*this) to capture alignment-related padding
// (but note that sizeof(*this) includes sizeof(mBuffer)).
return sizeof(*this) + mBuffer.memUsageIfLoaded() - sizeof(mBuffer);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
{
CoordBBox this_bbox = this->getNodeBoundingBox();
if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
if (visitVoxels) {//use voxel granularity?
this_bbox.reset();
for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
this_bbox.translate(this->origin());
}
bbox.expand(this_bbox);
}
}
template<typename T, Index Log2Dim>
template<typename OtherType, Index OtherLog2Dim>
inline bool
LeafNode<T, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
{
assert(other);
return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
}
template<typename T, Index Log2Dim>
inline bool
LeafNode<T, Log2Dim>::isConstant(ValueType& firstValue,
bool& state,
const ValueType& tolerance) const
{
if (!mValueMask.isConstant(state)) return false;// early termination
firstValue = mBuffer[0];
for (Index i = 1; i < SIZE; ++i) {
if ( !math::isApproxEqual(mBuffer[i], firstValue, tolerance) ) return false;// early termination
}
return true;
}
template<typename T, Index Log2Dim>
inline bool
LeafNode<T, Log2Dim>::isConstant(ValueType& minValue,
ValueType& maxValue,
bool& state,
const ValueType& tolerance) const
{
if (!mValueMask.isConstant(state)) return false;// early termination
minValue = maxValue = mBuffer[0];
for (Index i = 1; i < SIZE; ++i) {
const T& v = mBuffer[i];
if (v < minValue) {
if ((maxValue - v) > tolerance) return false;// early termination
minValue = v;
} else if (v > maxValue) {
if ((v - minValue) > tolerance) return false;// early termination
maxValue = v;
}
}
return true;
}
template<typename T, Index Log2Dim>
inline T
LeafNode<T, Log2Dim>::medianAll(T *tmp) const
{
std::unique_ptr<T[]> data(nullptr);
if (tmp == nullptr) {//allocate temporary storage
data.reset(new T[NUM_VALUES]);
tmp = data.get();
}
if (tmp != mBuffer.data()) {
const T* src = mBuffer.data();
for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
}
static const size_t midpoint = (NUM_VALUES - 1) >> 1;
std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES);
return tmp[midpoint];
}
template<typename T, Index Log2Dim>
inline Index
LeafNode<T, Log2Dim>::medianOn(T &value, T *tmp) const
{
const Index count = mValueMask.countOn();
if (count == NUM_VALUES) {//special case: all voxels are active
value = this->medianAll(tmp);
return NUM_VALUES;
} else if (count == 0) {
return 0;
}
std::unique_ptr<T[]> data(nullptr);
if (tmp == nullptr) {//allocate temporary storage
data.reset(new T[count]);// 0 < count < NUM_VALUES
tmp = data.get();
}
for (auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
T *begin = tmp - count;
const size_t midpoint = (count - 1) >> 1;
std::nth_element(begin, begin + midpoint, tmp);
value = begin[midpoint];
return count;
}
template<typename T, Index Log2Dim>
inline Index
LeafNode<T, Log2Dim>::medianOff(T &value, T *tmp) const
{
const Index count = mValueMask.countOff();
if (count == NUM_VALUES) {//special case: all voxels are inactive
value = this->medianAll(tmp);
return NUM_VALUES;
} else if (count == 0) {
return 0;
}
std::unique_ptr<T[]> data(nullptr);
if (tmp == nullptr) {//allocate temporary storage
data.reset(new T[count]);// 0 < count < NUM_VALUES
tmp = data.get();
}
for (auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
T *begin = tmp - count;
const size_t midpoint = (count - 1) >> 1;
std::nth_element(begin, begin + midpoint, tmp);
value = begin[midpoint];
return count;
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, const ValueType& val, bool active)
{
this->addTile(this->coordToOffset(xyz), val, active);
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::addTile(Index offset, const ValueType& val, bool active)
{
assert(offset < SIZE);
setValueOnly(offset, val);
setActiveState(offset, active);
}
template<typename T, Index Log2Dim>
template<typename AccessorT>
inline void
LeafNode<T, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
const ValueType& val, bool active, AccessorT&)
{
this->addTile(level, xyz, val, active);
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::resetBackground(const ValueType& oldBackground,
const ValueType& newBackground)
{
if (!this->allocate()) return;
typename NodeMaskType::OffIterator iter;
// For all inactive values...
for (iter = this->mValueMask.beginOff(); iter; ++iter) {
ValueType &inactiveValue = mBuffer[iter.pos()];
if (math::isApproxEqual(inactiveValue, oldBackground)) {
inactiveValue = newBackground;
} else if (math::isApproxEqual(inactiveValue, math::negative(oldBackground))) {
inactiveValue = math::negative(newBackground);
}
}
}
template<typename T, Index Log2Dim>
template<MergePolicy Policy>
inline void
LeafNode<T, Log2Dim>::merge(const LeafNode& other)
{
if (!this->allocate()) return;
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
if (Policy == MERGE_NODES) return;
typename NodeMaskType::OnIterator iter = other.valueMask().beginOn();
for (; iter; ++iter) {
const Index n = iter.pos();
if (mValueMask.isOff(n)) {
mBuffer[n] = other.mBuffer[n];
mValueMask.setOn(n);
}
}
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
}
template<typename T, Index Log2Dim>
template<MergePolicy Policy>
inline void
LeafNode<T, Log2Dim>::merge(const LeafNode& other,
const ValueType& /*bg*/, const ValueType& /*otherBG*/)
{
this->template merge<Policy>(other);
}
template<typename T, Index Log2Dim>
template<MergePolicy Policy>
inline void
LeafNode<T, Log2Dim>::merge(const ValueType& tileValue, bool tileActive)
{
if (!this->allocate()) return;
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
if (!tileActive) return;
// Replace all inactive values with the active tile value.
for (typename NodeMaskType::OffIterator iter = mValueMask.beginOff(); iter; ++iter) {
const Index n = iter.pos();
mBuffer[n] = tileValue;
mValueMask.setOn(n);
}
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
}
template<typename T, Index Log2Dim>
template<typename OtherType>
inline void
LeafNode<T, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other, bool)
{
mValueMask |= other.valueMask();
}
template<typename T, Index Log2Dim>
template<typename OtherType>
inline void
LeafNode<T, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
const ValueType&)
{
mValueMask &= other.valueMask();
}
template<typename T, Index Log2Dim>
template<typename OtherType>
inline void
LeafNode<T, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
const ValueType&)
{
mValueMask &= !other.valueMask();
}
template<typename T, Index Log2Dim>
inline void
LeafNode<T, Log2Dim>::negate()
{
if (!this->allocate()) return;
for (Index i = 0; i < SIZE; ++i) {
mBuffer[i] = -mBuffer[i];
}
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
template<typename CombineOp>
inline void
LeafNode<T, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
{
if (!this->allocate()) return;
CombineArgs<T> args;
for (Index i = 0; i < SIZE; ++i) {
op(args.setARef(mBuffer[i])
.setAIsActive(mValueMask.isOn(i))
.setBRef(other.mBuffer[i])
.setBIsActive(other.valueMask().isOn(i))
.setResultRef(mBuffer[i]));
mValueMask.set(i, args.resultIsActive());
}
}
template<typename T, Index Log2Dim>
template<typename CombineOp>
inline void
LeafNode<T, Log2Dim>::combine(const ValueType& value, bool valueIsActive, CombineOp& op)
{
if (!this->allocate()) return;
CombineArgs<T> args;
args.setBRef(value).setBIsActive(valueIsActive);
for (Index i = 0; i < SIZE; ++i) {
op(args.setARef(mBuffer[i])
.setAIsActive(mValueMask.isOn(i))
.setResultRef(mBuffer[i]));
mValueMask.set(i, args.resultIsActive());
}
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
template<typename CombineOp, typename OtherType>
inline void
LeafNode<T, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
bool valueIsActive, CombineOp& op)
{
if (!this->allocate()) return;
CombineArgs<T, OtherType> args;
args.setBRef(value).setBIsActive(valueIsActive);
for (Index i = 0; i < SIZE; ++i) {
op(args.setARef(other.mBuffer[i])
.setAIsActive(other.valueMask().isOn(i))
.setResultRef(mBuffer[i]));
mValueMask.set(i, args.resultIsActive());
}
}
template<typename T, Index Log2Dim>
template<typename CombineOp, typename OtherNodeT>
inline void
LeafNode<T, Log2Dim>::combine2(const ValueType& value, const OtherNodeT& other,
bool valueIsActive, CombineOp& op)
{
if (!this->allocate()) return;
CombineArgs<T, typename OtherNodeT::ValueType> args;
args.setARef(value).setAIsActive(valueIsActive);
for (Index i = 0; i < SIZE; ++i) {
op(args.setBRef(other.mBuffer[i])
.setBIsActive(other.valueMask().isOn(i))
.setResultRef(mBuffer[i]));
mValueMask.set(i, args.resultIsActive());
}
}
template<typename T, Index Log2Dim>
template<typename CombineOp, typename OtherNodeT>
inline void
LeafNode<T, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
{
if (!this->allocate()) return;
CombineArgs<T, typename OtherNodeT::ValueType> args;
for (Index i = 0; i < SIZE; ++i) {
mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
op(args.setARef(b0.mBuffer[i])
.setAIsActive(b0.valueMask().isOn(i))
.setBRef(b1.mBuffer[i])
.setBIsActive(b1.valueMask().isOn(i))
.setResultRef(mBuffer[i]));
mValueMask.set(i, args.resultIsActive());
}
}
////////////////////////////////////////
template<typename T, Index Log2Dim>
inline std::ostream&
operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
{
for (Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] << ", ";
return os;
}
} // namespace tree
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
////////////////////////////////////////
// Specialization for LeafNodes of type bool
#include "LeafNodeBool.h"
// Specialization for LeafNodes with mask information only
#include "LeafNodeMask.h"
#endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
Compression.h
Iterator.h
LeafBuffer.h
LeafNodeBool.h
LeafNodeMask.h
NodeMasks.h
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition Platform.h:141
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition Platform.h:140
Types.h
TestLeafIO
Definition LeafNode.h:22
openvdb::v11_0::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:569
openvdb::v11_0::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:621
openvdb::v11_0::CombineArgs::setBIsActive
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:637
openvdb::v11_0::CombineArgs::setResultRef
CombineArgs & setResultRef(AValueType &val)
Redirect the result value to a new external destination.
Definition Types.h:625
openvdb::v11_0::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:623
openvdb::v11_0::CombineArgs::resultIsActive
bool resultIsActive() const
Definition Types.h:632
openvdb::v11_0::CombineArgs::setAIsActive
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:635
openvdb::v11_0::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:689
openvdb::v11_0::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:683
openvdb::v11_0::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:251
openvdb::v11_0::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:460
openvdb::v11_0::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:420
openvdb::v11_0::math::CoordBBox::min
const Coord & min() const
Definition Coord.h:323
openvdb::v11_0::math::CoordBBox::hasOverlap
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:414
openvdb::v11_0::math::CoordBBox::max
const Coord & max() const
Definition Coord.h:324
openvdb::v11_0::math::CoordBBox::inf
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition Coord.h:321
openvdb::v11_0::math::CoordBBox::isInside
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:402
openvdb::v11_0::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:446
openvdb::v11_0::math::CoordBBox::reset
void reset()
Definition Coord.h:329
openvdb::v11_0::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:25
openvdb::v11_0::math::Coord::ValueType
Int32 ValueType
Definition Coord.h:32
openvdb::v11_0::math::Coord::y
Int32 y() const
Definition Coord.h:131
openvdb::v11_0::math::Coord::x
Int32 x() const
Definition Coord.h:130
openvdb::v11_0::math::Coord::setZ
Coord & setZ(Int32 z)
Definition Coord.h:81
openvdb::v11_0::math::Coord::setY
Coord & setY(Int32 y)
Definition Coord.h:80
openvdb::v11_0::math::Coord::z
Int32 z() const
Definition Coord.h:132
openvdb::v11_0::math::Coord::setX
Coord & setX(Int32 x)
Definition Coord.h:79
openvdb::v11_0::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
openvdb::v11_0::tree::LeafBuffer< ValueType, Log2Dim >
openvdb::v11_0::tree::LeafBuffer::memUsage
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition LeafBuffer.h:319
openvdb::v11_0::tree::LeafBuffer::size
static Index size()
Return the number of values contained in this buffer.
Definition LeafBuffer.h:111
openvdb::v11_0::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition LeafNode.h:38
openvdb::v11_0::tree::LeafNode::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
Definition LeafNode.h:706
openvdb::v11_0::tree::LeafNode::operator=
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
openvdb::v11_0::tree::LeafNode::probeValueAndCache
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val.
Definition LeafNode.h:600
openvdb::v11_0::tree::LeafNode::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition LeafNode.h:477
openvdb::v11_0::tree::LeafNode::onTileCount
static Index64 onTileCount()
Definition LeafNode.h:145
openvdb::v11_0::tree::LeafNode::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition LeafNode.h:175
openvdb::v11_0::tree::LeafNode::offsetToLocalCoord
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition LeafNode.h:1020
openvdb::v11_0::tree::LeafNode::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition LeafNode.h:319
openvdb::v11_0::tree::LeafNode::Ptr
SharedPtr< LeafNode > Ptr
Definition LeafNode.h:45
openvdb::v11_0::tree::LeafNode::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition LeafNode.h:167
openvdb::v11_0::tree::LeafNode::getValueMask
NodeMaskType & getValueMask()
Definition LeafNode.h:855
openvdb::v11_0::tree::LeafNode::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition LeafNode.h:419
openvdb::v11_0::tree::LeafNode::isChildMaskOn
bool isChildMaskOn(Index) const
Definition LeafNode.h:858
openvdb::v11_0::tree::LeafNode::beginChildOn
ChildOnCIter beginChildOn() const
Definition LeafNode.h:320
openvdb::v11_0::tree::LeafNode::beginChildOn
ChildOnIter beginChildOn()
Definition LeafNode.h:321
openvdb::v11_0::tree::LeafNode::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:475
openvdb::v11_0::tree::LeafNode::endValueOn
ValueOnIter endValueOn()
Definition LeafNode.h:309
openvdb::v11_0::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition LeafNode.h:1276
openvdb::v11_0::tree::LeafNode::copyToDense
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition LeafNode.h:1204
openvdb::v11_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff() const
Definition LeafNode.h:860
openvdb::v11_0::tree::LeafNode::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition LeafNode.h:300
openvdb::v11_0::tree::LeafNode::transientData
Index32 transientData() const
Return the transient data value.
Definition LeafNode.h:187
openvdb::v11_0::tree::LeafNode::childCount
static Index32 childCount()
Return the child count for this node, which is zero.
Definition LeafNode.h:137
openvdb::v11_0::tree::LeafNode::setValue
void setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:425
openvdb::v11_0::tree::LeafNode::getChildDim
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition LeafNode.h:129
openvdb::v11_0::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition LeafNode.h:201
openvdb::v11_0::tree::LeafNode::copyFromDense
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box.
Definition LeafNode.h:1231
openvdb::v11_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:1045
openvdb::v11_0::tree::LeafNode::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition LeafNode.h:857
openvdb::v11_0::tree::LeafNode::endChildOn
ChildOnIter endChildOn()
Definition LeafNode.h:331
openvdb::v11_0::tree::LeafNode::endValueAll
ValueAllIter endValueAll()
Definition LeafNode.h:315
openvdb::v11_0::tree::LeafNode::touchLeaf
LeafNode * touchLeaf(const Coord &)
Return a pointer to this node.
Definition LeafNode.h:716
openvdb::v11_0::tree::LeafNode::setValueOnly
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition LeafNode.h:1103
openvdb::v11_0::tree::LeafNode::probeLeaf
LeafNode * probeLeaf(const Coord &)
Definition LeafNode.h:727
openvdb::v11_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff() const
Definition LeafNode.h:853
openvdb::v11_0::tree::LeafNode::prune
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition LeafNode.h:695
openvdb::v11_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn() const
Definition LeafNode.h:851
openvdb::v11_0::tree::LeafNode::topologyDifference
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1696
openvdb::v11_0::tree::LeafNode::getNodes
void getNodes(ArrayT &) const
Definition LeafNode.h:705
openvdb::v11_0::tree::LeafNode::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition LeafNode.h:472
openvdb::v11_0::tree::LeafNode::endValueAll
ValueAllCIter endValueAll() const
Definition LeafNode.h:314
openvdb::v11_0::tree::LeafNode::medianOff
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition LeafNode.h:1553
openvdb::v11_0::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:421
openvdb::v11_0::tree::LeafNode::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition LeafNode.h:143
openvdb::v11_0::tree::LeafNode::endChildOff
ChildOffCIter endChildOff() const
Definition LeafNode.h:333
openvdb::v11_0::tree::LeafNode::medianAll
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition LeafNode.h:1511
openvdb::v11_0::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition LeafNode.h:990
openvdb::v11_0::tree::LeafNode::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition LeafNode.h:303
openvdb::v11_0::tree::LeafNode::probeNode
NodeT * probeNode(const Coord &)
Definition LeafNode.h:702
openvdb::v11_0::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition LeafNode.h:1268
openvdb::v11_0::tree::LeafNode::beginValueOn
ValueOnCIter beginValueOn() const
Definition LeafNode.h:298
openvdb::v11_0::tree::LeafNode::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition LeafNode.h:869
openvdb::v11_0::tree::LeafNode::buffer
const Buffer & buffer() const
Definition LeafNode.h:345
openvdb::v11_0::tree::LeafNode::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:729
openvdb::v11_0::tree::LeafNode::setValueMaskOn
void setValueMaskOn(Index n)
Definition LeafNode.h:863
openvdb::v11_0::tree::LeafNode::medianOn
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition LeafNode.h:1529
openvdb::v11_0::tree::LeafNode::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition LeafNode.h:144
openvdb::v11_0::tree::LeafNode::probeLeaf
const LeafNode * probeLeaf(const Coord &) const
Definition LeafNode.h:738
openvdb::v11_0::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition LeafNode.h:1580
openvdb::v11_0::tree::LeafNode::resetBackground
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition LeafNode.h:1609
openvdb::v11_0::tree::LeafNode::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition LeafNode.h:170
openvdb::v11_0::tree::LeafNode::origin
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition LeafNode.h:173
openvdb::v11_0::tree::LeafNode::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition LeafNode.h:394
openvdb::v11_0::tree::LeafNode::isInactive
bool isInactive() const
Return true if all of this node's values are inactive.
Definition LeafNode.h:825
openvdb::v11_0::tree::LeafNode::modifyValueAndActiveState
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition LeafNode.h:456
openvdb::v11_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition LeafNode.h:852
openvdb::v11_0::tree::LeafNode::cendValueOn
ValueOnCIter cendValueOn() const
Definition LeafNode.h:307
openvdb::v11_0::tree::LeafNode::isAllocated
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition LeafNode.h:152
openvdb::v11_0::tree::LeafNode::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition LeafNode.h:620
openvdb::v11_0::tree::LeafNode::numValues
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:123
openvdb::v11_0::tree::LeafNode::beginValueOff
ValueOffCIter beginValueOff() const
Definition LeafNode.h:301
openvdb::v11_0::tree::LeafNode::setValueOffAndCache
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition LeafNode.h:582
openvdb::v11_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i....
Definition LeafNode.h:609
openvdb::v11_0::tree::LeafNode::getValueAndCache
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition LeafNode.h:535
openvdb::v11_0::tree::LeafNode::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition LeafNode.h:325
openvdb::v11_0::tree::LeafNode::topologyIntersection
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node,...
Definition LeafNode.h:1687
openvdb::v11_0::tree::LeafNode::endChildOff
ChildOffIter endChildOff()
Definition LeafNode.h:334
openvdb::v11_0::tree::LeafNode::clip
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition LeafNode.h:1121
openvdb::v11_0::tree::LeafNode::beginChildAll
ChildAllIter beginChildAll()
Definition LeafNode.h:327
openvdb::v11_0::tree::LeafNode::setValueOn
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition LeafNode.h:427
openvdb::v11_0::tree::LeafNode::getLevel
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition LeafNode.h:125
openvdb::v11_0::tree::LeafNode::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:543
openvdb::v11_0::tree::LeafNode::addLeaf
void addLeaf(LeafNode *)
Definition LeafNode.h:696
openvdb::v11_0::tree::LeafNode::setActiveState
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition LeafNode.h:1095
openvdb::v11_0::tree::LeafNode::beginValueOn
ValueOnIter beginValueOn()
Definition LeafNode.h:299
openvdb::v11_0::tree::LeafNode::modifyValueAndCache
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:566
openvdb::v11_0::tree::LeafNode::topologyUnion
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other, const bool preserveTiles=false)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition LeafNode.h:1679
openvdb::v11_0::tree::LeafNode::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:720
openvdb::v11_0::tree::LeafNode::getFirstValue
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition LeafNode.h:625
openvdb::v11_0::tree::LeafNode::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition LeafNode.h:322
openvdb::v11_0::tree::LeafNode::beginChildOff
ChildOffIter beginChildOff()
Definition LeafNode.h:324
openvdb::v11_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff(Index) const
Definition LeafNode.h:859
openvdb::v11_0::tree::LeafNode::onVoxelCount
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition LeafNode.h:140
openvdb::v11_0::tree::LeafNode::beginChildOff
ChildOffCIter beginChildOff() const
Definition LeafNode.h:323
openvdb::v11_0::tree::LeafNode::coordToOffset
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition LeafNode.h:1010
openvdb::v11_0::tree::LeafNode::offTileCount
static Index64 offTileCount()
Definition LeafNode.h:146
openvdb::v11_0::tree::LeafNode::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition LeafNode.h:407
openvdb::v11_0::tree::LeafNode::hasSameTopology
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition LeafNode.h:1467
openvdb::v11_0::tree::LeafNode::endValueOff
ValueOffIter endValueOff()
Definition LeafNode.h:312
openvdb::v11_0::tree::LeafNode::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition LeafNode.h:409
openvdb::v11_0::tree::LeafNode::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:735
openvdb::v11_0::tree::LeafNode::endChildAll
ChildAllCIter endChildAll() const
Definition LeafNode.h:336
openvdb::v11_0::tree::LeafNode::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:740
openvdb::v11_0::tree::LeafNode::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition LeafNode.h:297
openvdb::v11_0::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition LeafNode.h:1402
openvdb::v11_0::tree::LeafNode::log2dim
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition LeafNode.h:117
openvdb::v11_0::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition LeafNode.h:1720
openvdb::v11_0::tree::LeafNode::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition LeafNode.h:127
openvdb::v11_0::tree::LeafNode::endChildOn
ChildOnCIter endChildOn() const
Definition LeafNode.h:330
openvdb::v11_0::tree::LeafNode::probeConstLeaf
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition LeafNode.h:733
openvdb::v11_0::tree::LeafNode::nonLeafCount
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition LeafNode.h:135
openvdb::v11_0::tree::LeafNode::cendChildOn
ChildOnCIter cendChildOn() const
Definition LeafNode.h:329
openvdb::v11_0::tree::LeafNode::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition LeafNode.h:480
openvdb::v11_0::tree::LeafNode::cendChildAll
ChildAllCIter cendChildAll() const
Definition LeafNode.h:335
openvdb::v11_0::tree::LeafNode::memUsageIfLoaded
Index64 memUsageIfLoaded() const
Definition LeafNode.h:1439
openvdb::v11_0::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition LeafNode.h:1760
openvdb::v11_0::tree::LeafNode::fill
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition LeafNode.h:1161
openvdb::v11_0::tree::LeafNode::modifyValue
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition LeafNode.h:449
openvdb::v11_0::tree::LeafNode::endChildAll
ChildAllIter endChildAll()
Definition LeafNode.h:337
openvdb::v11_0::tree::LeafNode::streamingSize
size_t streamingSize(bool toHalf=false) const
openvdb::v11_0::tree::LeafNode::setValueMask
void setValueMask(Index n, bool on)
Definition LeafNode.h:862
openvdb::v11_0::tree::LeafNode::valueMask
const NodeMaskType & valueMask() const
Definition LeafNode.h:856
openvdb::v11_0::tree::LeafNode::offVoxelCount
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition LeafNode.h:142
openvdb::v11_0::tree::LeafNode::MaskOffIterator
typename NodeMaskType::OffIterator MaskOffIterator
Definition LeafNode.h:205
openvdb::v11_0::tree::LeafNode::swap
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition LeafNode.h:344
openvdb::v11_0::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition LeafNode.h:1304
openvdb::v11_0::tree::LeafNode::isConstant
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition LeafNode.h:1475
openvdb::v11_0::tree::LeafNode::BuildType
T BuildType
Definition LeafNode.h:40
openvdb::v11_0::tree::LeafNode::cendValueAll
ValueAllCIter cendValueAll() const
Definition LeafNode.h:313
openvdb::v11_0::tree::LeafNode::LeafNode
friend class LeafNode
Definition LeafNode.h:833
openvdb::v11_0::tree::LeafNode::denseFill
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition LeafNode.h:488
openvdb::v11_0::tree::LeafNode::negate
void negate()
Definition LeafNode.h:1704
openvdb::v11_0::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition LeafNode.h:1034
openvdb::v11_0::tree::LeafNode::beginChildAll
ChildAllCIter beginChildAll() const
Definition LeafNode.h:326
openvdb::v11_0::tree::LeafNode::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition LeafNode.h:737
openvdb::v11_0::tree::LeafNode::setActiveStateAndCache
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition LeafNode.h:591
openvdb::v11_0::tree::LeafNode::getOrigin
void getOrigin(Coord &origin) const
Definition LeafNode.h:174
openvdb::v11_0::tree::LeafNode::setValuesOn
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition LeafNode.h:470
openvdb::v11_0::tree::LeafNode::setTransientData
void setTransientData(Index32 transientData)
Set the transient data value.
Definition LeafNode.h:189
openvdb::v11_0::tree::LeafNode::nodeCount
void nodeCount(std::vector< Index32 > &) const
no-op
Definition LeafNode.h:133
openvdb::v11_0::tree::LeafNode::size
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition LeafNode.h:121
openvdb::v11_0::tree::LeafNode::cendChildOff
ChildOffCIter cendChildOff() const
Definition LeafNode.h:332
openvdb::v11_0::tree::LeafNode::skipCompressedValues
void skipCompressedValues(bool seekable, std::istream &, bool fromHalf)
Definition LeafNode.h:1288
openvdb::v11_0::tree::LeafNode::MaskOnIterator
typename NodeMaskType::OnIterator MaskOnIterator
Definition LeafNode.h:204
openvdb::v11_0::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition LeafNode.h:1419
openvdb::v11_0::tree::LeafNode::SIZE
static const Index SIZE
Definition LeafNode.h:53
openvdb::v11_0::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition LeafNode.h:1449
openvdb::v11_0::tree::LeafNode::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition LeafNode.h:148
openvdb::v11_0::tree::LeafNode::merge
void merge(const LeafNode &)
Definition LeafNode.h:1630
openvdb::v11_0::tree::LeafNode::beginValueOff
ValueOffIter beginValueOff()
Definition LeafNode.h:302
openvdb::v11_0::tree::LeafNode::probeConstNode
const NodeT * probeConstNode(const Coord &) const
Definition LeafNode.h:704
openvdb::v11_0::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition LeafNode.h:417
openvdb::v11_0::tree::LeafNode::buffer
Buffer & buffer()
Definition LeafNode.h:346
openvdb::v11_0::tree::LeafNode::setValueOnlyAndCache
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition LeafNode.h:557
openvdb::v11_0::tree::LeafNode::setActiveState
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition LeafNode.h:399
openvdb::v11_0::tree::LeafNode::leafCount
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition LeafNode.h:131
openvdb::v11_0::tree::LeafNode::allocate
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition LeafNode.h:154
openvdb::v11_0::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition LeafNode.h:854
openvdb::v11_0::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition LeafNode.h:1597
openvdb::v11_0::tree::LeafNode::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
Definition LeafNode.h:698
openvdb::v11_0::tree::LeafNode::modifyValue
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active.
Definition LeafNode.h:435
openvdb::v11_0::tree::LeafNode::cendValueOff
ValueOffCIter cendValueOff() const
Definition LeafNode.h:310
openvdb::v11_0::tree::LeafNode::setValueMaskOff
void setValueMaskOff(Index n)
Definition LeafNode.h:864
openvdb::v11_0::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition LeafNode.h:1429
openvdb::v11_0::tree::LeafNode::isDense
bool isDense() const
Return true if this node contains only active voxels.
Definition LeafNode.h:150
openvdb::v11_0::tree::LeafNode::endValueOff
ValueOffCIter endValueOff() const
Definition LeafNode.h:311
openvdb::v11_0::tree::LeafNode::setValueAndCache
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition LeafNode.h:548
openvdb::v11_0::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition LeafNode.h:997
openvdb::v11_0::tree::LeafNode::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition LeafNode.h:700
openvdb::v11_0::tree::LeafNode::ValueType
T ValueType
Definition LeafNode.h:41
openvdb::v11_0::tree::LeafNode::probeValue
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition LeafNode.h:1061
openvdb::v11_0::tree::LeafNode::endValueOn
ValueOnCIter endValueOn() const
Definition LeafNode.h:308
openvdb::v11_0::tree::LeafNode::MaskDenseIterator
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition LeafNode.h:206
openvdb::v11_0::tree::LeafNode::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition LeafNode.h:637
openvdb::v11_0::tree::LeafNode::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition LeafNode.h:574
openvdb::v11_0::tree::LeafNode::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition LeafNode.h:718
openvdb::v11_0::tree::LeafNode::getLastValue
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition LeafNode.h:627
openvdb::v11_0::tree::LeafNode::beginValueAll
ValueAllCIter beginValueAll() const
Definition LeafNode.h:304
openvdb::v11_0::tree::LeafNode::dim
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition LeafNode.h:119
openvdb::v11_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition LeafNode.h:850
openvdb::v11_0::tree::LeafNode::beginValueAll
ValueAllIter beginValueAll()
Definition LeafNode.h:305
openvdb::v11_0::util::BaseMaskIterator::pos
Index32 pos() const
Definition NodeMasks.h:200
openvdb::v11_0::util::DenseMaskIterator
Definition NodeMasks.h:271
openvdb::v11_0::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
openvdb::v11_0::util::NodeMask::beginOn
OnIterator beginOn() const
Definition NodeMasks.h:352
openvdb::v11_0::util::NodeMask::beginOff
OffIterator beginOff() const
Definition NodeMasks.h:354
openvdb::v11_0::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition NodeMasks.h:502
openvdb::v11_0::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition NodeMasks.h:452
openvdb::v11_0::util::OffMaskIterator
Definition NodeMasks.h:240
openvdb::v11_0::util::OnMaskIterator
Definition NodeMasks.h:209
openvdb::v11_0::io::getDataCompression
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
openvdb::v11_0::io::writeCompressedValues
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition Compression.h:645
openvdb::v11_0::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v11_0::io::COMPRESS_ZIP
@ COMPRESS_ZIP
Definition Compression.h:54
openvdb::v11_0::io::readCompressedValues
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition Compression.h:465
openvdb::v11_0::io::getGridBackgroundValuePtr
OPENVDB_API const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
openvdb::v11_0::io::getStreamMetadataPtr
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
openvdb::v11_0::math::isApproxEqual
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
openvdb::v11_0::math::negative
T negative(const T &val)
Return the unary negation of the given value.
Definition Math.h:128
openvdb::v11_0::tree::operator<<
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition LeafNode.h:1820
openvdb::v11_0::Index
Index32 Index
Definition Types.h:54
openvdb::v11_0::Index32
uint32_t Index32
Definition Types.h:52
openvdb::v11_0::OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition version.h.in:256
openvdb::v11_0::Int32
int32_t Int32
Definition Types.h:56
openvdb::v11_0::Index64
uint64_t Index64
Definition Types.h:53
openvdb::v11_0::SharedPtr
std::shared_ptr< T > SharedPtr
Definition Types.h:114
openvdb::v11_0::MERGE_NODES
@ MERGE_NODES
Definition Types.h:508
openvdb::v11_0::MERGE_ACTIVE_STATES_AND_NODES
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:509
openvdb
Definition Exceptions.h:13
allocate
static pnanovdb_uint32_t allocate(pnanovdb_uint32_t *poffset, pnanovdb_uint32_t size, pnanovdb_uint32_t alignment)
Definition pnanovdb_validate_strides.h:20
openvdb::v11_0::io::HalfReader
Definition Compression.h:292
openvdb::v11_0::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition Iterator.h:179
openvdb::v11_0::tree::DenseIteratorBase::NonConstValueType
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition Iterator.h:184
openvdb::v11_0::tree::LeafNode::ChildIter
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition LeafNode.h:250
openvdb::v11_0::tree::LeafNode::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:252
openvdb::v11_0::tree::LeafNode::ChildIter::ChildIter
ChildIter()
Definition LeafNode.h:251
openvdb::v11_0::tree::LeafNode::ChildOff
Definition LeafNode.h:210
openvdb::v11_0::tree::LeafNode::ChildOn
Definition LeafNode.h:210
openvdb::v11_0::tree::LeafNode::DenseIter
Definition LeafNode.h:259
openvdb::v11_0::tree::LeafNode::DenseIter::DenseIter
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition LeafNode.h:264
openvdb::v11_0::tree::LeafNode::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &value) const
Definition LeafNode.h:277
openvdb::v11_0::tree::LeafNode::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition LeafNode.h:266
openvdb::v11_0::tree::LeafNode::DenseIter::DenseIter
DenseIter()
Definition LeafNode.h:263
openvdb::v11_0::tree::LeafNode::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition LeafNode.h:261
openvdb::v11_0::tree::LeafNode::SameConfiguration
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition LeafNode.h:64
openvdb::v11_0::tree::LeafNode::ValueAll
Definition LeafNode.h:209
openvdb::v11_0::tree::LeafNode::ValueConverter
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition LeafNode.h:59
openvdb::v11_0::tree::LeafNode::ValueIter
Definition LeafNode.h:218
openvdb::v11_0::tree::LeafNode::ValueIter::setValue
void setValue(const ValueT &value) const
Definition LeafNode.h:233
openvdb::v11_0::tree::LeafNode::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition LeafNode.h:243
openvdb::v11_0::tree::LeafNode::ValueIter::getItem
ValueT & getItem(Index pos) const
Definition LeafNode.h:224
openvdb::v11_0::tree::LeafNode::ValueIter::setItem
void setItem(Index pos, const ValueT &value) const
Definition LeafNode.h:228
openvdb::v11_0::tree::LeafNode::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition LeafNode.h:222
openvdb::v11_0::tree::LeafNode::ValueIter::getValue
ValueT & getValue() const
Definition LeafNode.h:225
openvdb::v11_0::tree::LeafNode::ValueIter::ValueIter
ValueIter()
Definition LeafNode.h:221
openvdb::v11_0::tree::LeafNode::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition LeafNode.h:240
openvdb::v11_0::tree::LeafNode::ValueOff
Definition LeafNode.h:209
openvdb::v11_0::tree::LeafNode::ValueOn
Definition LeafNode.h:209
openvdb::v11_0::tree::SameLeafConfig
Definition LeafNode.h:890
openvdb::v11_0::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition Iterator.h:115
openvdb::v11_0::tree::SparseIteratorBase< MaskIterT, ChildIter< MaskIterT, NodeT, TagT >, NodeT, ValueType >::ValueType
ValueType ValueType
Definition Iterator.h:117
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212