6#ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
7#define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
23#include <tbb/concurrent_hash_map.h>
55 template<
typename TreeType>
56 bool isType()
const {
return (this->
type() == TreeType::treeType()); }
105#if OPENVDB_ABI_VERSION_NUMBER >= 12
120#if OPENVDB_ABI_VERSION_NUMBER >= 12
128#if OPENVDB_ABI_VERSION_NUMBER >= 12
131 virtual std::vector<Index32>
nodeCount()
const = 0;
134#if OPENVDB_ABI_VERSION_NUMBER >= 12
160 virtual void readTopology(std::istream&,
bool saveFloatAsHalf =
false);
164 virtual void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const;
167 virtual void readBuffers(std::istream&,
bool saveFloatAsHalf =
false) = 0;
177 virtual void writeBuffers(std::ostream&,
bool saveFloatAsHalf =
false)
const = 0;
186 virtual void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const;
193template<
typename _RootNodeType>
218 template<
typename OtherValueType>
239 template<
typename OtherRootType>
254 template<
typename OtherTreeType>
255 Tree(
const OtherTreeType& other,
275 template<
typename OtherTreeType>
313 template<
typename OtherRootNodeType>
333 void readTopology(std::istream&,
bool saveFloatAsHalf =
false)
override;
337 void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
339 void readBuffers(std::istream&,
bool saveFloatAsHalf =
false)
override;
349 void writeBuffers(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
351 void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const override;
362#if OPENVDB_ABI_VERSION_NUMBER >= 12
365 Index32 leafCount()
const override {
return static_cast<Index32>(mRoot.leafCount()); }
370#if OPENVDB_ABI_VERSION_NUMBER >= 12
373 std::vector<Index64> vec(
DEPTH, 0);
374 mRoot.nodeCount( vec );
378 std::vector<Index32> nodeCount()
const override
380 std::vector<Index32> vec(DEPTH, 0);
382 mRoot.nodeCount( vec );
388#if OPENVDB_ABI_VERSION_NUMBER >= 12
391 Index32 nonLeafCount()
const override {
return static_cast<Index32>(mRoot.nonLeafCount()); }
457 template<
typename ModifyOp>
479 template<
typename ModifyOp>
503#if OPENVDB_ABI_VERSION_NUMBER >= 12
551 mRoot.prune(tolerance);
571 template<
typename NodeT>
620 template<
typename ArrayT>
void getNodes(ArrayT& array);
621 template<
typename ArrayT>
void getNodes(ArrayT& array)
const;
647 template<
typename ArrayT>
649 template<
typename ArrayT>
653 mRoot.stealNodes(array, value, state);
758 template<
typename OtherRootNodeType>
774 template<
typename OtherRootNodeType>
787 template<
typename OtherRootNodeType>
834 template<
typename CombineOp>
836 template<
typename CombineOp>
877 template<
typename ExtendedCombineOp>
879 template<
typename ExtendedCombineOp>
910 template<
typename CombineOp,
typename OtherTreeType >
912 template<
typename CombineOp,
typename OtherTreeType >
988 template<
typename ExtendedCombineOp,
typename OtherTreeType >
991 template<
typename ExtendedCombineOp,
typename OtherTreeType >
1077 template<
typename CIterT> CIterT
cbegin()
const;
1089 template<
typename NodeType>
1092 :
mNodes(nodes.
empty() ? nullptr : &nodes.front()) { }
1094 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
1114template<
typename T, Index N1=4, Index N2=3>
1124template<
typename T, Index N1=5, Index N2=4, Index N3=3>
1133template<
typename T, Index N1=6, Index N2=5, Index N3=4, Index N4=3>
1146 int32_t bufferCount;
1147 is.read(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1148 if (bufferCount != 1)
OPENVDB_LOG_WARN(
"multi-buffer trees are no longer supported");
1155 int32_t bufferCount = 1;
1156 os.write(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1163 os <<
" Tree Type: " <<
type()
1167 <<
" Leaf Node Count: " <<
leafCount() << std::endl
1168 <<
" Non-leaf Node Count: " <<
nonLeafCount() << std::endl;
1183template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1184 static typename TreeT::RootNodeType::ChildOnIter
begin(TreeT&
tree) {
1185 return tree.beginRootChildren();
1189template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1190 static typename TreeT::RootNodeType::ChildOnCIter
begin(
const TreeT&
tree) {
1191 return tree.cbeginRootChildren();
1195template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1196 static typename TreeT::RootNodeType::ChildOffIter
begin(TreeT&
tree) {
1197 return tree.beginRootTiles();
1201template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1202 static typename TreeT::RootNodeType::ChildOffCIter
begin(
const TreeT&
tree) {
1203 return tree.cbeginRootTiles();
1207template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1208 static typename TreeT::RootNodeType::ChildAllIter
begin(TreeT&
tree) {
1209 return tree.beginRootDense();
1213template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1214 static typename TreeT::RootNodeType::ChildAllCIter
begin(
const TreeT&
tree) {
1215 return tree.cbeginRootDense();
1224 static typename TreeT::NodeCIter
begin(
const TreeT&
tree) {
return tree.cbeginNode(); }
1232 static typename TreeT::LeafCIter
begin(
const TreeT&
tree) {
return tree.cbeginLeaf(); }
1236 static typename TreeT::ValueOnIter
begin(TreeT&
tree) {
return tree.beginValueOn(); }
1240 static typename TreeT::ValueOnCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueOn(); }
1244 static typename TreeT::ValueOffIter
begin(TreeT&
tree) {
return tree.beginValueOff(); }
1247template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1248 static typename TreeT::ValueOffCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueOff(); }
1252 static typename TreeT::ValueAllIter
begin(TreeT&
tree) {
return tree.beginValueAll(); }
1255template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1256 static typename TreeT::ValueAllCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueAll(); }
1260template<
typename RootNodeType>
1261template<
typename IterT>
1269template<
typename RootNodeType>
1270template<
typename IterT>
1281template<
typename RootNodeType>
1287 mRoot.readTopology(is, saveFloatAsHalf);
1291template<
typename RootNodeType>
1296 mRoot.writeTopology(os, saveFloatAsHalf);
1300template<
typename RootNodeType>
1305 mRoot.readBuffers(is, saveFloatAsHalf);
1309template<
typename RootNodeType>
1314 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1318template<
typename RootNodeType>
1324 it->getValue(
Index(0));
1329template<
typename RootNodeType>
1333 mRoot.writeBuffers(os, saveFloatAsHalf);
1337template<
typename RootNodeType>
1338template<
typename ArrayT>
1342 using NodeT =
typename std::remove_pointer<typename ArrayT::value_type>::type;
1343 static_assert(!std::is_same<NodeT, RootNodeType>::value,
1344 "getNodes() does not work for the RootNode. Use Tree::root()");
1345 mRoot.getNodes(array);
1349template<
typename RootNodeType>
1350template<
typename ArrayT>
1354 using NodeT =
typename std::remove_pointer<typename ArrayT::value_type>::type;
1355 static_assert(!std::is_same<NodeT, const RootNodeType>::value,
1356 "getNodes() does not work for the RootNode. Use Tree::root()");
1357 mRoot.getNodes(array);
1361template<
typename RootNodeType>
1365 std::vector<LeafNodeType*> leafnodes;
1368 tbb::parallel_for(tbb::blocked_range<size_t>(0, leafnodes.size()),
1371 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1374 tbb::parallel_for(tbb::blocked_range<size_t>(0, internalNodes.size()),
1386template<
typename RootNodeType>
1393template<
typename RootNodeType>
1400template<
typename RootNodeType>
1407template<
typename RootNodeType>
1414template<
typename RootNodeType>
1421template<
typename RootNodeType>
1425 typename AccessorRegistry::accessor a;
1430template<
typename RootNodeType>
1434 typename ConstAccessorRegistry::accessor a;
1439template<
typename RootNodeType>
1447template<
typename RootNodeType>
1455template<
typename RootNodeType>
1462 if (it->first) it->first->clear();
1468 if (it->first) it->first->clear();
1473template<
typename RootNodeType>
1481 it->first->release();
1489 it->first->release();
1498template<
typename RootNodeType>
1499inline const typename RootNodeType::ValueType&
1502 return mRoot.getValue(xyz);
1506template<
typename RootNodeType>
1507template<
typename AccessT>
1508inline const typename RootNodeType::ValueType&
1511 return accessor.getValue(xyz);
1515template<
typename RootNodeType>
1519 return mRoot.getValueDepth(xyz);
1523template<
typename RootNodeType>
1527 mRoot.setValueOff(xyz);
1531template<
typename RootNodeType>
1535 mRoot.setValueOff(xyz, value);
1539template<
typename RootNodeType>
1543 mRoot.setActiveState(xyz, on);
1547template<
typename RootNodeType>
1551 mRoot.setValueOn(xyz, value);
1554template<
typename RootNodeType>
1558 mRoot.setValueOnly(xyz, value);
1561template<
typename RootNodeType>
1562template<
typename AccessT>
1566 accessor.setValue(xyz, value);
1570template<
typename RootNodeType>
1574 mRoot.setActiveState(xyz,
true);
1578template<
typename RootNodeType>
1582 mRoot.setValueOn(xyz, value);
1586template<
typename RootNodeType>
1587template<
typename ModifyOp>
1591 mRoot.modifyValue(xyz, op);
1595template<
typename RootNodeType>
1596template<
typename ModifyOp>
1600 mRoot.modifyValueAndActiveState(xyz, op);
1604template<
typename RootNodeType>
1608 return mRoot.probeValue(xyz, value);
1615template<
typename RootNodeType>
1620 mRoot.addTile(level, xyz, value, active);
1624template<
typename RootNodeType>
1625template<
typename NodeT>
1634template<
typename RootNodeType>
1635inline typename RootNodeType::LeafNodeType*
1638 return mRoot.touchLeaf(xyz);
1642template<
typename RootNodeType>
1643inline typename RootNodeType::LeafNodeType*
1646 return mRoot.probeLeaf(xyz);
1650template<
typename RootNodeType>
1651inline const typename RootNodeType::LeafNodeType*
1654 return mRoot.probeConstLeaf(xyz);
1658template<
typename RootNodeType>
1659template<
typename NodeType>
1667template<
typename RootNodeType>
1668template<
typename NodeType>
1669inline const NodeType*
1676template<
typename RootNodeType>
1677template<
typename NodeType>
1678inline const NodeType*
1688template<
typename RootNodeType>
1693 return mRoot.clip(bbox);
1697template<
typename RootNodeType>
1705 if (!leaf->isAllocated()) {
1706 this->
addTile(0, leaf->origin(), this->background(),
false);
1711#if OPENVDB_ABI_VERSION_NUMBER >= 12
1712template<
typename RootNodeType>
1717 for (
auto it = this->
cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1721template<
typename RootNodeType>
1726 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1732template<
typename RootNodeType>
1737 return mRoot.sparseFill(bbox, value, active);
1741template<
typename RootNodeType>
1746 return mRoot.denseFill(bbox, value, active);
1750template<
typename RootNodeType>
1755 mRoot.voxelizeActiveTiles(threaded);
1759template<
typename RootNodeType>
1767 if (result->typeName() == MetadataT::staticTypeName()) {
1768 MetadataT* m =
static_cast<MetadataT*
>(result.get());
1769 m->value() =
mRoot.background();
1779template<
typename RootNodeType>
1796template<
typename RootNodeType>
1797template<
typename OtherRootNodeType>
1802 mRoot.topologyUnion(other.
root(), preserveTiles);
1805template<
typename RootNodeType>
1806template<
typename OtherRootNodeType>
1811 mRoot.topologyIntersection(other.
root());
1814template<
typename RootNodeType>
1815template<
typename OtherRootNodeType>
1828template<
typename AValueT,
typename CombineOp,
typename BValueT = AValueT>
1841template<
typename RootNodeType>
1842template<
typename CombineOp>
1853template<
typename RootNodeType>
1854template<
typename CombineOp>
1863template<
typename RootNodeType>
1864template<
typename ExtendedCombineOp>
1875template<
typename RootNodeType>
1876template<
typename ExtendedCombineOp>
1885template<
typename RootNodeType>
1886template<
typename CombineOp,
typename OtherTreeType>
1897template<
typename RootNodeType>
1898template<
typename CombineOp,
typename OtherTreeType>
1907template<
typename RootNodeType>
1908template<
typename ExtendedCombineOp,
typename OtherTreeType>
1911 ExtendedCombineOp& op,
bool prune)
1921template<
typename RootNodeType>
1922template<
typename ExtendedCombineOp,
typename OtherTreeType>
1925 const ExtendedCombineOp& op,
bool prune)
1935template<
typename RootNodeType>
1939 static std::string sTreeTypeName = []()
1942 std::vector<Index> dims;
1944 std::ostringstream ostr;
1946 for (
size_t i = 1, N = dims.size(); i < N; ++i) {
1947 ostr <<
"_" << dims[i];
1951 return sTreeTypeName;
1955template<
typename RootNodeType>
1956template<
typename OtherRootNodeType>
1960 return mRoot.hasSameTopology(other.
root());
1964template<
typename RootNodeType>
1970 if (this->
empty())
return false;
1972 mRoot.evalActiveBoundingBox(bbox,
false);
1974 return !bbox.
empty();
1977template<
typename RootNodeType>
1983 if (this->
empty())
return false;
1985 mRoot.evalActiveBoundingBox(bbox,
true);
1987 return !bbox.
empty();
1991template<
typename RootNodeType>
2002template<
typename RootNodeType>
2013template<
typename RootNodeType>
2018 RootNodeType::getNodeLog2Dims(dims);
2022template<
typename RootNodeType>
2026 if (verboseLevel <= 0)
return;
2031 std::streamsize savedPrecision;
2032 OnExit(std::ostream& _os): os(_os), savedPrecision(os.precision()) {}
2033 ~OnExit() { os.precision(savedPrecision); }
2035 OnExit restorePrecision(os);
2037 std::vector<Index> dims;
2040 os <<
"Information about Tree:\n"
2041 <<
" Type: " << this->
type() <<
"\n";
2043 os <<
" Configuration:\n";
2045 if (verboseLevel <= 1) {
2047 os <<
" Root(" <<
mRoot.getTableSize() <<
")";
2048 if (dims.size() > 1) {
2049 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
2050 os <<
", Internal(" << (1 << dims[i]) <<
"^3)";
2052 os <<
", Leaf(" << (1 << dims.back()) <<
"^3)\n";
2054 os <<
" Background value: " <<
mRoot.background() <<
"\n";
2061 if (verboseLevel > 3) {
2064 minVal = extrema.
min();
2065 maxVal = extrema.
max();
2076 os <<
" Root(1 x " <<
mRoot.getTableSize() <<
")";
2077 if (dims.size() >= 2) {
2078 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
2080 os <<
" x " << (1 << dims[i]) <<
"^3)";
2083 os <<
" x " << (1 << dims.back()) <<
"^3)\n";
2085 os <<
" Background value: " <<
mRoot.background() <<
"\n";
2089 if (verboseLevel > 3) {
2090 os <<
" Min value: " << minVal <<
"\n";
2091 os <<
" Max value: " << maxVal <<
"\n";
2104 if (numActiveVoxels) {
2108 totalVoxels = dim.
x() * uint64_t(dim.
y()) * dim.
z();
2110 os <<
" Bounding box of active voxels: " << bbox <<
"\n";
2111 os <<
" Dimensions of active voxels: "
2112 << dim[0] <<
" x " << dim[1] <<
" x " << dim[2] <<
"\n";
2114 const double activeRatio = (100.0 * double(numActiveVoxels)) /
double(totalVoxels);
2115 os <<
" Percentage of active voxels: " << std::setprecision(3) << activeRatio <<
"%\n";
2118 const double fillRatio = (100.0 * double(numActiveLeafVoxels))
2119 / (
double(
leafCount) *
double(LeafNodeType::NUM_VOXELS));
2120 os <<
" Average leaf node fill ratio: " << fillRatio <<
"%\n";
2123 if (verboseLevel > 2) {
2125 for (
auto it = this->
cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
2126 os <<
" Number of unallocated nodes: "
2128 << (100.0 * double(sum) / double(totalNodeCount)) <<
"%)\n";
2131 os <<
" Tree is empty!\n";
2135 if (verboseLevel == 2)
return;
2140 denseMem =
sizeof(
ValueType) * totalVoxels,
2141 voxelsMem =
sizeof(
ValueType) * numActiveLeafVoxels;
2144 os <<
"Memory footprint:\n";
2148 if (numActiveVoxels) {
2150 os <<
" Actual footprint is " << (100.0 * double(actualMem) / double(denseMem))
2151 <<
"% of an equivalent dense volume\n";
2152 os <<
" Leaf voxel footprint is " << (100.0 * double(voxelsMem) / double(actualMem))
2153 <<
"% of actual footprint\n";
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Functions to count tiles, nodes or voxels in a grid.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
The root node of an OpenVDB tree.
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:640
const AValueType & result() const
Get the output value.
Definition Types.h:684
const BValueType & b() const
Get the B input value.
Definition Types.h:681
const AValueType & a() const
Get the A input value.
Definition Types.h:679
Definition Exceptions.h:61
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:754
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
Coord extents() const
Definition Coord.h:385
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition Coord.h:359
void reset()
Definition Coord.h:330
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Int32 y() const
Definition Coord.h:132
Int32 x() const
Definition Coord.h:131
Int32 z() const
Definition Coord.h:133
double min() const
Return the minimum value.
Definition Stats.h:122
double max() const
Return the maximum value.
Definition Stats.h:125
Templated class to compute the minimum and maximum values.
Definition Stats.h:32
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels)
Definition TreeIterator.h:1188
Base class for tree-traversal iterators over all nodes.
Definition TreeIterator.h:937
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
virtual const Name & type() const =0
Return the name of this tree's type.
virtual void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const
Write the tree topology to a stream.
Definition Tree.h:1153
virtual Index64 unallocatedLeafCount() const =0
Return the total number of unallocated leaf nodes residing in this tree.
virtual ~TreeBase()=default
virtual Index64 activeLeafVoxelCount() const =0
Return the number of active voxels stored in leaf nodes.
virtual std::vector< Index64 > nodeCount() const =0
virtual void readBuffers(std::istream &, bool saveFloatAsHalf=false)=0
Read all data buffers for this tree.
bool isType() const
Return true if this tree is of the same type as the template parameter.
Definition Tree.h:56
virtual void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const =0
Write out all the data buffers for this tree.
virtual Index64 leafCount() const =0
Return the number of leaf nodes.
virtual Metadata::Ptr getBackgroundValue() const
Return this tree's background value wrapped as metadata.
Definition Tree.h:66
virtual Index64 nonLeafCount() const =0
Return the number of non-leaf nodes.
virtual void print(std::ostream &os=std::cout, int verboseLevel=1) const
Print statistics, memory usage and other information about this tree.
Definition Tree.h:1161
virtual void readBuffers(std::istream &, const CoordBBox &, bool saveFloatAsHalf=false)=0
Read all of this tree's data buffers that intersect the given bounding box.
virtual void getIndexRange(CoordBBox &bbox) const =0
virtual Index64 activeVoxelCount() const =0
Return the total number of active voxels.
virtual Index64 inactiveVoxelCount() const =0
Return the number of inactive voxels within the bounding box of all active voxels.
virtual void clipUnallocatedNodes()=0
Replace with background tiles any nodes whose voxel buffers have not yet been allocated.
virtual void readNonresidentBuffers() const =0
Read all of this tree's data buffers that are not yet resident in memory (because delayed loading is ...
virtual Index64 inactiveLeafVoxelCount() const =0
Return the number of inactive voxels stored in leaf nodes.
virtual Index64 memUsage() const
Return the total amount of memory in bytes occupied by this tree.
Definition Tree.h:151
virtual TreeBase::Ptr copy() const =0
Return a pointer to a deep copy of this tree.
SharedPtr< TreeBase > Ptr
Definition Tree.h:40
virtual bool evalLeafDim(Coord &dim) const =0
Return in dim the dimensions of the axis-aligned bounding box of all leaf nodes.
virtual bool evalActiveVoxelBoundingBox(CoordBBox &bbox) const =0
Return in bbox the axis-aligned bounding box of all active voxels and tiles.
virtual Index treeDepth() const =0
Return the depth of this tree.
virtual Index64 activeTileCount() const =0
Return the total number of active tiles.
SharedPtr< const TreeBase > ConstPtr
Definition Tree.h:41
virtual bool evalActiveVoxelDim(Coord &dim) const =0
Return in dim the dimensions of the axis-aligned bounding box of all active voxels....
virtual bool evalLeafBoundingBox(CoordBBox &bbox) const =0
Return in bbox the axis-aligned bounding box of all active tiles and leaf nodes with active values.
TreeBase & operator=(const TreeBase &)=delete
TreeBase(const TreeBase &)=default
virtual void readTopology(std::istream &, bool saveFloatAsHalf=false)
Read the tree topology from a stream.
Definition Tree.h:1144
Base class for tree-traversal iterators over tile and voxel values.
Definition TreeIterator.h:618
void readTopology(std::istream &, bool saveFloatAsHalf=false) override
Read the tree topology from a stream.
Definition Tree.h:1283
RootNodeType::ChildAllCIter beginRootDense() const
Return an iterator over all entries of the root node's table.
Definition Tree.h:1014
Metadata::Ptr getBackgroundValue() const override
Return this tree's background value wrapped as metadata.
Definition Tree.h:1761
int getValueDepth(const Coord &xyz) const
Return the tree depth (0 = root) at which the value of voxel (x, y, z) resides.
Definition Tree.h:1517
bool hasSameTopology(const Tree< OtherRootNodeType > &other) const
Return true if the given tree has the same node and active value topology as this tree,...
Definition Tree.h:1958
Index64 unallocatedLeafCount() const override
Return the total number of unallocated leaf nodes residing in this tree.
Definition Tree.h:1714
CIterT cbegin() const
Return a const iterator of type CIterT (for example, cbegin<ValueOnCIter>() is equivalent to cbeginVa...
bool evalActiveVoxelBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active voxels and tiles.
Definition Tree.h:1979
NodeT * stealNode(const Coord &xyz, const ValueType &value, bool active)
Return a pointer to the node of type NodeT that contains voxel (x, y, z) and replace it with a tile o...
Definition Tree.h:1627
void releaseAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition Tree.h:715
NodeType * probeNode(const Coord &xyz)
Return a pointer to the node of type NodeType that contains voxel (x, y, z). If no such node exists,...
Definition Tree.h:1661
const NodeType * probeNode(const Coord &xyz) const
Definition Tree.h:1670
void combine(Tree &other, CombineOp &op, bool prune=false)
Definition Tree.h:1844
const ValueType & getValue(const Coord &xyz, AccessT &) const
Return the value of the voxel at the given coordinates and update the given accessor's node cache.
void releaseAccessor(ValueAccessorBase< const Tree, false > &) const
Definition Tree.h:716
ConstAccessorRegistry mConstAccessorRegistry
Definition Tree.h:1106
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
Definition Tree.h:487
RootNodeType & root()
Definition Tree.h:303
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOffIter > ValueOffIter
Definition Tree.h:1050
Tree(const Tree &other)
Deep copy constructor.
Definition Tree.h:229
RootNodeType::ChildOffCIter cbeginRootTiles() const
Definition Tree.h:1008
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOffCIter > ValueOffCIter
Definition Tree.h:1051
LeafCIter beginLeaf() const
Definition Tree.h:1042
ValueAccessor< Tree, true > Accessor
Definition Tree.h:207
void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const override
Write out all data buffers for this tree.
Definition Tree.h:1331
void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const override
Write the tree topology to a stream.
Definition Tree.h:1293
ValueOffCIter cbeginValueOff() const
Definition Tree.h:1069
Tree(const Tree< OtherRootType > &other)
Value conversion deep copy constructor.
Definition Tree.h:240
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Definition Tree.h:1652
IterT begin()
Return an iterator of type IterT (for example, begin<ValueOnIter>() is equivalent to beginValueOn()).
Definition Tree.h:1263
Index64 memUsage() const override
Return the total amount of memory in bytes occupied by this tree.
Definition Tree.h:404
void merge(Tree &other, MergePolicy=MERGE_ACTIVE_STATES)
Efficiently merge another tree into this tree using one of several schemes.
Definition Tree.h:1781
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueAllCIter > ValueAllCIter
Definition Tree.h:1047
typename NodeChainT::Back RootNodeType
Definition Tree.h:200
RootNodeType::ChildAllIter beginRootDense()
Definition Tree.h:1016
Accessor getAccessor()
Return an accessor that provides random read and write access to this tree's voxels.
Definition Tree.h:1388
ValueAccessor< Tree, false > UnsafeAccessor
Definition Tree.h:209
LeafCIter cbeginLeaf() const
Definition Tree.h:1043
LeafIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > LeafCIter
Definition Tree.h:1029
const Name & type() const override
Return the name of this type of tree.
Definition Tree.h:296
static const Index DEPTH
Definition Tree.h:205
RootNodeType::ChildOffIter beginRootTiles()
Definition Tree.h:1009
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition Tree.h:1340
void readBuffers(std::istream &, const CoordBBox &, bool saveFloatAsHalf=false) override
Read all of this tree's data buffers that intersect the given bounding box.
Definition Tree.h:1311
static const Name & treeType()
Return the name of this type of tree.
Definition Tree.h:1937
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition Tree.h:1752
RootNodeType::ChildOnCIter beginRootChildren() const
Return an iterator over children of the root node.
Definition Tree.h:1000
void combine(Tree &other, const CombineOp &op, bool prune=false)
Definition Tree.h:1856
bool operator!=(const Tree &) const
Definition Tree.h:299
Tree()
Definition Tree.h:224
AccessorRegistry mAccessorRegistry
Definition Tree.h:1105
void clip(const CoordBBox &)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition Tree.h:1690
ValueAccessor< const Tree, true > ConstAccessor
Definition Tree.h:208
RootNodeType mRoot
Definition Tree.h:1104
ValueAllCIter cbeginValueAll() const
Definition Tree.h:1057
void prune(const ValueType &tolerance=zeroVal< ValueType >())
Reduce the memory footprint of this tree by replacing with tiles any nodes whose values are all the s...
Definition Tree.h:548
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists,...
Definition Tree.h:1644
void topologyIntersection(const Tree< OtherRootNodeType > &other)
Intersects this tree's set of active values with the active values of the other tree,...
Definition Tree.h:1808
void releaseAccessor(ValueAccessorBase< Tree, true > &) const
Deregister an accessor so that it is no longer automatically cleared.
Definition Tree.h:1441
LeafNodeType * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists,...
Definition Tree.h:1636
RootNodeType::ChildOnIter beginRootChildren()
Definition Tree.h:1002
Index64 leafCount() const override
Return the number of leaf nodes.
Definition Tree.h:363
ValueOnCIter beginValueOn() const
Definition Tree.h:1062
bool operator==(const Tree &) const
Definition Tree.h:298
SharedPtr< Tree > Ptr
Definition Tree.h:197
void attachAccessor(ValueAccessorBase< Tree, true > &) const
Register an accessor for this tree. Registered accessors are automatically cleared whenever one of th...
Definition Tree.h:1423
NodeIteratorBase< Tree, typename RootNodeType::ChildOnIter > NodeIter
Definition Tree.h:1022
Index64 activeLeafVoxelCount() const override
Return the number of active voxels stored in leaf nodes.
Definition Tree.h:394
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition Tree.h:1598
ConstUnsafeAccessor getConstUnsafeAccessor()
Return an unsafe accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1416
void combine2Extended(const Tree &a, const OtherTreeType &b, const ExtendedCombineOp &, bool prune=false)
Definition Tree.h:1924
Index64 inactiveVoxelCount() const override
Return the number of inactive voxels within the bounding box of all active voxels.
Definition Tree.h:400
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition Tree.h:1556
bool empty() const
Return true if this tree contains no nodes other than the root node and no tiles other than backgroun...
Definition Tree.h:661
Index64 activeVoxelCount() const override
Return the total number of active voxels.
Definition Tree.h:398
Index64 inactiveLeafVoxelCount() const override
Return the number of inactive voxels stored in leaf nodes.
Definition Tree.h:396
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Definition Tree.h:519
ValueOffCIter beginValueOff() const
Definition Tree.h:1068
void addLeaf(LeafNodeType *leaf)
Add the given leaf node to this tree, creating a new branch if necessary. If a leaf node with the sam...
Definition Tree.h:559
TreeValueIteratorBase< Tree, typename RootNodeType::ValueAllIter > ValueAllIter
Definition Tree.h:1046
RootNodeType::ChildOffCIter beginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Definition Tree.h:1007
void combineExtended(Tree &other, ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1866
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition Tree.h:1533
void addTile(Index level, const Coord &xyz, const ValueType &value, bool active)
Add a tile containing voxel (x, y, z) at the specified tree level, creating a new branch if necessary...
Definition Tree.h:1617
void releaseAccessor(ValueAccessorBase< const Tree, true > &) const
Definition Tree.h:1449
bool probeValue(const Coord &xyz, ValueType &value) const
Get the value of the voxel at the given coordinates.
Definition Tree.h:1606
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOnCIter > ValueOnCIter
Definition Tree.h:1049
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 Tree.h:1541
ValueOnIter beginValueOn()
Return an iterator over active values (tile and voxel) across all nodes.
Definition Tree.h:1061
void topologyDifference(const Tree< OtherRootNodeType > &other)
Difference this tree's set of active values with the active values of the other tree,...
Definition Tree.h:1817
void releaseAllAccessors()
typename RootNodeType::BuildType BuildType
Definition Tree.h:202
void setValue(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition Tree.h:1549
void combine2Extended(const Tree &a, const OtherTreeType &b, ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1910
Index64 activeTileCount() const override
Return the total number of active tiles.
Definition Tree.h:402
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition Tree.h:1525
tbb::concurrent_hash_map< ValueAccessorBase< const Tree, true > *, bool > ConstAccessorRegistry
Definition Tree.h:1082
ValueOnCIter cbeginValueOn() const
Definition Tree.h:1063
TreeBase::Ptr copy() const override
Return a pointer to a deep copy of this tree.
Definition Tree.h:288
typename RootNodeType::ValueType ValueType
Definition Tree.h:201
void attachAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition Tree.h:703
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition Tree.h:1500
const LeafNodeType * probeLeaf(const Coord &xyz) const
Definition Tree.h:594
void print(std::ostream &os=std::cout, int verboseLevel=1) const override
Print statistics, memory usage and other information about this tree.
Definition Tree.h:2024
void combineExtended(Tree &other, const ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1878
void attachAccessor(ValueAccessorBase< const Tree, false > &) const
Definition Tree.h:704
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this tree's voxels.
Definition Tree.h:1395
void combine2(const Tree &a, const OtherTreeType &b, const CombineOp &op, bool prune=false)
Definition Tree.h:1900
NodeCIter beginNode() const
Definition Tree.h:1035
ValueAccessor< const Tree, false > ConstUnsafeAccessor
Definition Tree.h:210
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 Tree.h:1589
LeafIteratorBase< Tree, typename RootNodeType::ChildOnIter > LeafIter
Definition Tree.h:1028
SharedPtr< const Tree > ConstPtr
Definition Tree.h:198
void readNonresidentBuffers() const override
Read all of this tree's data buffers that are not yet resident in memory (because delayed loading is ...
Definition Tree.h:1320
Tree(const OtherTreeType &other, const ValueType &background, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition Tree.h:276
RootNodeType::ChildAllCIter cbeginRootDense() const
Definition Tree.h:1015
void getNodes(ArrayT &array) const
Definition Tree.h:1352
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition Tree.h:1743
bool evalLeafBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active tiles and leaf nodes with active values.
Definition Tree.h:1966
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Definition Tree.h:650
bool evalLeafDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all leaf nodes.
Definition Tree.h:2004
RootNodeType::ChildOnCIter cbeginRootChildren() const
Definition Tree.h:1001
void setValue(const Coord &xyz, const ValueType &value, AccessT &)
Set the value of the voxel at the given coordinates, mark the voxel as active, and update the given a...
Definition Tree.h:1564
std::vector< Index64 > nodeCount() const override
Definition Tree.h:371
NodeCIter cbeginNode() const
Definition Tree.h:1036
const ValueType & background() const
Definition Tree.h:728
NodeIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > NodeCIter
Definition Tree.h:1023
Tree & operator=(const Tree &)=delete
static void getNodeLog2Dims(std::vector< Index > &dims)
Traverse the type hierarchy of nodes, and return, in dims, a list of the Log2Dims of nodes in order f...
Definition Tree.h:2015
ValueOffIter beginValueOff()
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition Tree.h:1067
void getIndexRange(CoordBBox &bbox) const override
Min and max are both inclusive.
Definition Tree.h:731
void attachAccessor(ValueAccessorBase< const Tree, true > &) const
Definition Tree.h:1432
void readBuffers(std::istream &, bool saveFloatAsHalf=false) override
Read all data buffers for this tree.
Definition Tree.h:1302
typename RootNodeType::LeafNodeType LeafNodeType
Definition Tree.h:203
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1409
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition Tree.h:1572
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition Tree.h:1041
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition Tree.h:1734
Tree(const OtherTreeType &other, const ValueType &inactiveValue, const ValueType &activeValue, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition Tree.h:255
bool evalActiveVoxelDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all active voxels....
Definition Tree.h:1993
~Tree() override
Definition Tree.h:285
const NodeType * probeConstNode(const Coord &xyz) const
Definition Tree.h:1679
bool hasActiveTiles() const
Return true if this tree has any active tiles.
Definition Tree.h:491
Tree(const ValueType &background)
Empty tree constructor.
Definition Tree.h:283
void clipUnallocatedNodes() override
Replace with background tiles any nodes whose voxel buffers have not yet been allocated.
Definition Tree.h:1699
void setValueOn(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition Tree.h:1580
bool isValueOff(const Coord &xyz) const
Return true if the value at the given coordinates is inactive.
Definition Tree.h:489
void stealNodes(ArrayT &array)
Steals all nodes of a certain type from the tree and adds them to a container with the following API:
Definition Tree.h:648
void topologyUnion(const Tree< OtherRootNodeType > &other, const bool preserveTiles=false)
Union this tree's set of active values with the active values of the other tree, whose ValueType may ...
Definition Tree.h:1799
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
Definition Tree.h:291
void combine2(const Tree &a, const OtherTreeType &b, CombineOp &op, bool prune=false)
Definition Tree.h:1888
Index treeDepth() const override
Return the depth of this tree.
Definition Tree.h:360
const RootNodeType & root() const
Definition Tree.h:304
ValueAllCIter beginValueAll() const
Definition Tree.h:1056
NodeIter beginNode()
Return an iterator over all nodes in this tree.
Definition Tree.h:1034
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1402
Index64 nonLeafCount() const override
Return the number of non-leaf nodes.
Definition Tree.h:389
tbb::concurrent_hash_map< ValueAccessorBase< Tree, true > *, bool > AccessorRegistry
Definition Tree.h:1081
ValueAllIter beginValueAll()
Return an iterator over all values (tile and voxel) across all nodes.
Definition Tree.h:1055
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOnIter > ValueOnIter
Definition Tree.h:1048
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
Definition ValueAccessor.h:152
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition logging.h:256
Definition PointDataGrid.h:170
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels > > ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
Definition ValueAccessor.h:86
FormattedInt< IntT > formattedInt(IntT n)
Definition Formats.h:118
OPENVDB_API int printBytes(std::ostream &os, uint64_t bytes, const std::string &head="", const std::string &tail="\n", bool exact=false, int width=8, int precision=3)
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:34
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
uint32_t Index32
Definition Types.h:32
uint64_t Index64
Definition Types.h:33
std::shared_ptr< T > SharedPtr
Definition Types.h:95
MergePolicy
Definition Types.h:577
@ MERGE_ACTIVE_STATES
Definition Types.h:578
@ MERGE_NODES
Definition Types.h:579
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:580
const char * typeNameAsString()
Definition Types.h:587
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
Helper class to adapt a three-argument (a, b, result) CombineOp functor into a single-argument functo...
Definition Tree.h:1830
void operator()(CombineArgs< AValueT, BValueT > &args) const
Definition Tree.h:1833
CombineOpAdapter(CombineOp &_op)
Definition Tree.h:1831
CombineOp & op
Definition Tree.h:1837
Tree3<T, N1, N2>::Type is the type of a three-level tree (Root, Internal, Leaf) with value type T and...
Definition Tree.h:1115
Tree< RootNode< InternalNode< LeafNode< T, N2 >, N1 > > > Type
Definition Tree.h:1116
Tree4<T, N1, N2, N3>::Type is the type of a four-level tree (Root, Internal, Internal,...
Definition Tree.h:1125
Tree< RootNode< InternalNode< InternalNode< LeafNode< bool, N3 >, N2 >, N1 > > > Type
Definition Tree.h:1126
Tree5<T, N1, N2, N3, N4>::Type is the type of a five-level tree (Root, Internal, Internal,...
Definition Tree.h:1134
Tree< RootNode< InternalNode< InternalNode< InternalNode< LeafNode< T, N4 >, N3 >, N2 >, N1 > > > Type
Definition Tree.h:1135
static TreeT::LeafCIter begin(const TreeT &tree)
Definition Tree.h:1232
static TreeT::LeafIter begin(TreeT &tree)
Definition Tree.h:1228
static TreeT::NodeCIter begin(const TreeT &tree)
Definition Tree.h:1224
static TreeT::NodeIter begin(TreeT &tree)
Definition Tree.h:1220
static TreeT::RootNodeType::ChildAllCIter begin(const TreeT &tree)
Definition Tree.h:1214
static TreeT::RootNodeType::ChildAllIter begin(TreeT &tree)
Definition Tree.h:1208
static TreeT::RootNodeType::ChildOffCIter begin(const TreeT &tree)
Definition Tree.h:1202
static TreeT::RootNodeType::ChildOffIter begin(TreeT &tree)
Definition Tree.h:1196
static TreeT::RootNodeType::ChildOnCIter begin(const TreeT &tree)
Definition Tree.h:1190
static TreeT::RootNodeType::ChildOnIter begin(TreeT &tree)
Definition Tree.h:1184
static TreeT::ValueAllCIter begin(const TreeT &tree)
Definition Tree.h:1256
static TreeT::ValueAllIter begin(TreeT &tree)
Definition Tree.h:1252
static TreeT::ValueOffCIter begin(const TreeT &tree)
Definition Tree.h:1248
static TreeT::ValueOffIter begin(TreeT &tree)
Definition Tree.h:1244
static TreeT::ValueOnCIter begin(const TreeT &tree)
Definition Tree.h:1240
static TreeT::ValueOnIter begin(TreeT &tree)
Definition Tree.h:1236
TreeIterTraits provides, for all tree iterators, a begin(tree) function that returns an iterator over...
Definition Tree.h:1181
DeallocateNodes(std::vector< NodeType * > &nodes)
Definition Tree.h:1091
NodeType **const mNodes
Definition Tree.h:1098
void operator()(const tbb::blocked_range< size_t > &range) const
Definition Tree.h:1093
ValueConverter<T>::Type is the type of a tree having the same hierarchy as this tree but a different ...
Definition Tree.h:219
Tree< typename RootNodeType::template ValueConverter< OtherValueType >::Type > Type
Definition Tree.h:220
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218