6 #ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
7 #define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
23 #include <tbb/concurrent_hash_map.h>
49 virtual const Name&
type()
const = 0;
52 virtual Name valueType()
const = 0;
55 template<
typename TreeType>
56 bool isType()
const {
return (this->
type() == TreeType::treeType()); }
75 virtual bool evalLeafBoundingBox(
CoordBBox& bbox)
const = 0;
80 virtual bool evalLeafDim(Coord& dim)
const = 0;
89 virtual bool evalActiveVoxelBoundingBox(
CoordBBox& bbox)
const = 0;
94 virtual bool evalActiveVoxelDim(Coord& dim)
const = 0;
96 virtual void getIndexRange(
CoordBBox& bbox)
const = 0;
103 virtual void clipUnallocatedNodes() = 0;
105 #if OPENVDB_ABI_VERSION_NUMBER >= 12
106 virtual Index64 unallocatedLeafCount()
const = 0;
108 virtual Index32 unallocatedLeafCount()
const = 0;
118 virtual Index treeDepth()
const = 0;
120 #if OPENVDB_ABI_VERSION_NUMBER >= 12
121 virtual Index64 leafCount()
const = 0;
123 virtual Index32 leafCount()
const = 0;
128 #if OPENVDB_ABI_VERSION_NUMBER >= 12
129 virtual std::vector<Index64> nodeCount()
const = 0;
131 virtual std::vector<Index32> nodeCount()
const = 0;
134 #if OPENVDB_ABI_VERSION_NUMBER >= 12
135 virtual Index64 nonLeafCount()
const = 0;
137 virtual Index32 nonLeafCount()
const = 0;
140 virtual Index64 activeLeafVoxelCount()
const = 0;
142 virtual Index64 inactiveLeafVoxelCount()
const = 0;
144 virtual Index64 activeVoxelCount()
const = 0;
146 virtual Index64 inactiveVoxelCount()
const = 0;
148 virtual Index64 activeTileCount()
const = 0;
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;
169 virtual void readBuffers(std::istream&,
const CoordBBox&,
bool saveFloatAsHalf =
false) = 0;
175 virtual void readNonresidentBuffers()
const = 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;
193 template<
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
370 #if OPENVDB_ABI_VERSION_NUMBER >= 12
371 std::vector<Index64>
nodeCount()
const override
373 std::vector<Index64> vec(
DEPTH, 0);
374 mRoot.nodeCount( vec );
380 std::vector<Index32> vec(
DEPTH, 0);
382 mRoot.nodeCount( vec );
388 #if OPENVDB_ABI_VERSION_NUMBER >= 12
414 template<
typename AccessT>
const ValueType&
getValue(
const Coord& xyz, AccessT&)
const;
457 template<
typename ModifyOp>
479 template<
typename ModifyOp>
503 #if OPENVDB_ABI_VERSION_NUMBER >= 12
551 mRoot.prune(tolerance);
571 template<
typename NodeT>
584 template<
typename NodeType> NodeType*
probeNode(
const Coord& xyz);
585 template<
typename NodeType>
const NodeType*
probeConstNode(
const Coord& xyz)
const;
586 template<
typename NodeType>
const NodeType*
probeNode(
const Coord& xyz)
const;
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 >
1074 template<
typename IterT> IterT
begin();
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) {
1114 template<
typename T, Index N1=4, Index N2=3>
1124 template<
typename T, Index N1=5, Index N2=4, Index N3=3>
1133 template<
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;
1183 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1184 static typename TreeT::RootNodeType::ChildOnIter
begin(TreeT& tree) {
1185 return tree.beginRootChildren();
1189 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1190 static typename TreeT::RootNodeType::ChildOnCIter
begin(
const TreeT& tree) {
1191 return tree.cbeginRootChildren();
1195 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1196 static typename TreeT::RootNodeType::ChildOffIter
begin(TreeT& tree) {
1197 return tree.beginRootTiles();
1201 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1202 static typename TreeT::RootNodeType::ChildOffCIter
begin(
const TreeT& tree) {
1203 return tree.cbeginRootTiles();
1207 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1208 static typename TreeT::RootNodeType::ChildAllIter
begin(TreeT& tree) {
1209 return tree.beginRootDense();
1213 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1214 static typename TreeT::RootNodeType::ChildAllCIter
begin(
const TreeT& tree) {
1215 return tree.cbeginRootDense();
1220 static typename TreeT::NodeIter
begin(TreeT& tree) {
return tree.beginNode(); }
1224 static typename TreeT::NodeCIter
begin(
const TreeT& tree) {
return tree.cbeginNode(); }
1228 static typename TreeT::LeafIter
begin(TreeT& tree) {
return tree.beginLeaf(); }
1232 static typename TreeT::LeafCIter
begin(
const TreeT& tree) {
return tree.cbeginLeaf(); }
1236 static typename TreeT::ValueOnIter
begin(TreeT& tree) {
return tree.beginValueOn(); }
1239 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOnCIter> {
1240 static typename TreeT::ValueOnCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOn(); }
1243 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffIter> {
1244 static typename TreeT::ValueOffIter
begin(TreeT& tree) {
return tree.beginValueOff(); }
1247 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1248 static typename TreeT::ValueOffCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOff(); }
1251 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllIter> {
1252 static typename TreeT::ValueAllIter
begin(TreeT& tree) {
return tree.beginValueAll(); }
1255 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1256 static typename TreeT::ValueAllCIter
begin(
const TreeT& tree) {
return tree.cbeginValueAll(); }
1260 template<
typename RootNodeType>
1261 template<
typename IterT>
1269 template<
typename RootNodeType>
1270 template<
typename IterT>
1281 template<
typename RootNodeType>
1285 this->clearAllAccessors();
1287 mRoot.readTopology(is, saveFloatAsHalf);
1291 template<
typename RootNodeType>
1296 mRoot.writeTopology(os, saveFloatAsHalf);
1300 template<
typename RootNodeType>
1304 this->clearAllAccessors();
1305 mRoot.readBuffers(is, saveFloatAsHalf);
1309 template<
typename RootNodeType>
1313 this->clearAllAccessors();
1314 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1318 template<
typename RootNodeType>
1322 for (
LeafCIter it = this->cbeginLeaf(); it; ++it) {
1324 it->getValue(
Index(0));
1329 template<
typename RootNodeType>
1333 mRoot.writeBuffers(os, saveFloatAsHalf);
1337 template<
typename RootNodeType>
1338 template<
typename ArrayT>
1344 "getNodes() does not work for the RootNode. Use Tree::root()");
1345 mRoot.getNodes(array);
1349 template<
typename RootNodeType>
1350 template<
typename ArrayT>
1356 "getNodes() does not work for the RootNode. Use Tree::root()");
1357 mRoot.getNodes(array);
1361 template<
typename RootNodeType>
1365 std::vector<LeafNodeType*> leafnodes;
1366 this->stealNodes(leafnodes);
1371 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1372 this->stealNodes(internalNodes);
1379 this->clearAllAccessors();
1386 template<
typename RootNodeType>
1393 template<
typename RootNodeType>
1400 template<
typename RootNodeType>
1407 template<
typename RootNodeType>
1414 template<
typename RootNodeType>
1421 template<
typename RootNodeType>
1425 typename AccessorRegistry::accessor
a;
1426 mAccessorRegistry.insert(a, &accessor);
1430 template<
typename RootNodeType>
1434 typename ConstAccessorRegistry::accessor
a;
1435 mConstAccessorRegistry.insert(a, &accessor);
1439 template<
typename RootNodeType>
1443 mAccessorRegistry.erase(&accessor);
1447 template<
typename RootNodeType>
1451 mConstAccessorRegistry.erase(&accessor);
1455 template<
typename RootNodeType>
1459 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1460 it != mAccessorRegistry.end(); ++it)
1462 if (it->first) it->first->clear();
1465 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1466 it != mConstAccessorRegistry.end(); ++it)
1468 if (it->first) it->first->clear();
1473 template<
typename RootNodeType>
1477 mAccessorRegistry.erase(
nullptr);
1478 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1479 it != mAccessorRegistry.end(); ++it)
1481 it->first->release();
1483 mAccessorRegistry.clear();
1485 mAccessorRegistry.erase(
nullptr);
1486 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1487 it != mConstAccessorRegistry.end(); ++it)
1489 it->first->release();
1491 mConstAccessorRegistry.clear();
1498 template<
typename RootNodeType>
1502 return mRoot.getValue(xyz);
1506 template<
typename RootNodeType>
1507 template<
typename AccessT>
1511 return accessor.getValue(xyz);
1515 template<
typename RootNodeType>
1519 return mRoot.getValueDepth(xyz);
1523 template<
typename RootNodeType>
1527 mRoot.setValueOff(xyz);
1531 template<
typename RootNodeType>
1535 mRoot.setValueOff(xyz, value);
1539 template<
typename RootNodeType>
1543 mRoot.setActiveState(xyz, on);
1547 template<
typename RootNodeType>
1551 mRoot.setValueOn(xyz, value);
1554 template<
typename RootNodeType>
1558 mRoot.setValueOnly(xyz, value);
1561 template<
typename RootNodeType>
1562 template<
typename AccessT>
1566 accessor.setValue(xyz, value);
1570 template<
typename RootNodeType>
1574 mRoot.setActiveState(xyz,
true);
1578 template<
typename RootNodeType>
1582 mRoot.setValueOn(xyz, value);
1586 template<
typename RootNodeType>
1587 template<
typename ModifyOp>
1591 mRoot.modifyValue(xyz, op);
1595 template<
typename RootNodeType>
1596 template<
typename ModifyOp>
1600 mRoot.modifyValueAndActiveState(xyz, op);
1604 template<
typename RootNodeType>
1608 return mRoot.probeValue(xyz, value);
1615 template<
typename RootNodeType>
1620 mRoot.addTile(level, xyz, value, active);
1624 template<
typename RootNodeType>
1625 template<
typename NodeT>
1629 this->clearAllAccessors();
1630 return mRoot.template stealNode<NodeT>(xyz,
value,
active);
1634 template<
typename RootNodeType>
1635 inline typename RootNodeType::LeafNodeType*
1638 return mRoot.touchLeaf(xyz);
1642 template<
typename RootNodeType>
1643 inline typename RootNodeType::LeafNodeType*
1646 return mRoot.probeLeaf(xyz);
1650 template<
typename RootNodeType>
1651 inline const typename RootNodeType::LeafNodeType*
1654 return mRoot.probeConstLeaf(xyz);
1658 template<
typename RootNodeType>
1659 template<
typename NodeType>
1663 return mRoot.template probeNode<NodeType>(xyz);
1667 template<
typename RootNodeType>
1668 template<
typename NodeType>
1669 inline const NodeType*
1672 return this->
template probeConstNode<NodeType>(xyz);
1676 template<
typename RootNodeType>
1677 template<
typename NodeType>
1678 inline const NodeType*
1681 return mRoot.template probeConstNode<NodeType>(xyz);
1688 template<
typename RootNodeType>
1692 this->clearAllAccessors();
1693 return mRoot.clip(bbox);
1697 template<
typename RootNodeType>
1701 this->clearAllAccessors();
1702 for (
LeafIter it = this->beginLeaf(); it; ) {
1705 if (!leaf->isAllocated()) {
1706 this->addTile(0, leaf->origin(), this->background(),
false);
1711 #if OPENVDB_ABI_VERSION_NUMBER >= 12
1712 template<
typename RootNodeType>
1717 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1721 template<
typename RootNodeType>
1726 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1732 template<
typename RootNodeType>
1736 this->clearAllAccessors();
1737 return mRoot.sparseFill(bbox, value, active);
1741 template<
typename RootNodeType>
1745 this->clearAllAccessors();
1746 return mRoot.denseFill(bbox, value, active);
1750 template<
typename RootNodeType>
1754 this->clearAllAccessors();
1755 mRoot.voxelizeActiveTiles(threaded);
1759 template<
typename RootNodeType>
1767 if (result->typeName() == MetadataT::staticTypeName()) {
1768 MetadataT* m =
static_cast<MetadataT*
>(result.get());
1769 m->value() = mRoot.background();
1779 template<
typename RootNodeType>
1783 this->clearAllAccessors();
1787 mRoot.template merge<MERGE_ACTIVE_STATES>(other.
mRoot);
break;
1789 mRoot.template merge<MERGE_NODES>(other.
mRoot);
break;
1791 mRoot.template merge<MERGE_ACTIVE_STATES_AND_NODES>(other.
mRoot);
break;
1796 template<
typename RootNodeType>
1797 template<
typename OtherRootNodeType>
1801 this->clearAllAccessors();
1802 mRoot.topologyUnion(other.
root(), preserveTiles);
1805 template<
typename RootNodeType>
1806 template<
typename OtherRootNodeType>
1810 this->clearAllAccessors();
1811 mRoot.topologyIntersection(other.
root());
1814 template<
typename RootNodeType>
1815 template<
typename OtherRootNodeType>
1819 this->clearAllAccessors();
1820 mRoot.topologyDifference(other.
root());
1828 template<
typename AValueT,
typename CombineOp,
typename BValueT = AValueT>
1841 template<
typename RootNodeType>
1842 template<
typename CombineOp>
1847 this->combineExtended(other, extendedOp, prune);
1853 template<
typename RootNodeType>
1854 template<
typename CombineOp>
1859 this->combineExtended(other, extendedOp, prune);
1863 template<
typename RootNodeType>
1864 template<
typename ExtendedCombineOp>
1868 this->clearAllAccessors();
1875 template<
typename RootNodeType>
1876 template<
typename ExtendedCombineOp>
1880 this->clearAllAccessors();
1881 mRoot.template combine<const ExtendedCombineOp>(other.
mRoot,
op,
prune);
1885 template<
typename RootNodeType>
1886 template<
typename CombineOp,
typename OtherTreeType>
1891 this->combine2Extended(a, b, extendedOp, prune);
1897 template<
typename RootNodeType>
1898 template<
typename CombineOp,
typename OtherTreeType>
1903 this->combine2Extended(a, b, extendedOp, prune);
1907 template<
typename RootNodeType>
1908 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1911 ExtendedCombineOp&
op,
bool prune)
1913 this->clearAllAccessors();
1921 template<
typename RootNodeType>
1922 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1925 const ExtendedCombineOp&
op,
bool prune)
1927 this->clearAllAccessors();
1928 mRoot.template combine2<const ExtendedCombineOp>(a.
root(), b.root(),
op,
prune);
1935 template<
typename RootNodeType>
1939 static std::string sTreeTypeName = []()
1942 std::vector<Index> dims;
1944 std::ostringstream ostr;
1945 ostr <<
"Tree_" << typeNameAsString<BuildType>();
1946 for (
size_t i = 1,
N = dims.size(); i <
N; ++i) {
1947 ostr <<
"_" << dims[i];
1951 return sTreeTypeName;
1955 template<
typename RootNodeType>
1956 template<
typename OtherRootNodeType>
1960 return mRoot.hasSameTopology(other.
root());
1964 template<
typename RootNodeType>
1970 if (this->empty())
return false;
1972 mRoot.evalActiveBoundingBox(bbox,
false);
1974 return !bbox.empty();
1977 template<
typename RootNodeType>
1983 if (this->empty())
return false;
1985 mRoot.evalActiveBoundingBox(bbox,
true);
1987 return !bbox.empty();
1991 template<
typename RootNodeType>
1996 bool notEmpty = this->evalActiveVoxelBoundingBox(bbox);
1997 dim = bbox.extents();
2002 template<
typename RootNodeType>
2007 bool notEmpty = this->evalLeafBoundingBox(bbox);
2008 dim = bbox.extents();
2013 template<
typename RootNodeType>
2018 RootNodeType::getNodeLog2Dims(dims);
2022 template<
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";
2060 ValueType minVal = zeroVal<ValueType>(), maxVal = zeroVal<ValueType>();
2061 if (verboseLevel > 3) {
2064 minVal = extrema.
min();
2065 maxVal = extrema.
max();
2068 const auto nodeCount = this->nodeCount();
2069 const Index64 leafCount = nodeCount.front();
2073 for (
size_t i = 0; i < nodeCount.size(); ++i) totalNodeCount += nodeCount[i];
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";
2095 numActiveVoxels = this->activeVoxelCount(),
2096 numActiveLeafVoxels = this->activeLeafVoxelCount(),
2097 numActiveTiles = this->activeTileCount();
2104 if (numActiveVoxels) {
2106 this->evalActiveVoxelBoundingBox(bbox);
2107 dim = bbox.extents();
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";
2117 if (leafCount > 0) {
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;
2139 actualMem = this->memUsage(),
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";
2161 #endif // OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
virtual Index64 activeTileCount() const =0
Return the total number of active tiles.
const AValueType & result() const
Get the output value.
tbb::concurrent_hash_map< ValueAccessorBase< Tree, true > *, bool > AccessorRegistry
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOnCIter > ValueOnCIter
virtual void readTopology(std::istream &, bool saveFloatAsHalf=false)
Read the tree topology from a stream.
ValueOffIter beginValueOff()
Return an iterator over inactive values (tile and voxel) across all nodes.
void releaseAccessor(ValueAccessorBase< Tree, true > &) const
Deregister an accessor so that it is no longer automatically cleared.
AccessorRegistry mAccessorRegistry
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this tree's voxels...
bool operator==(const Tree &) const
virtual void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const
Write the tree topology to a stream.
bool hasSameTopology(const Tree< OtherRootNodeType > &other) const
Return true if the given tree has the same node and active value topology as this tree...
void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const override
Write out all data buffers for this tree.
SharedPtr< TreeBase > Ptr
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
virtual Index64 memUsage() const
Return the total amount of memory in bytes occupied by this tree.
LeafIteratorBase< Tree, typename RootNodeType::ChildOnIter > LeafIter
Iterator over all leaf nodes in this tree.
static TreeT::ValueAllIter begin(TreeT &tree)
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
void stealNodes(ArrayT &array, const ValueType &value, bool state)
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
ValueAccessor< Tree, false > UnsafeAccessor
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
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...
virtual Metadata::Ptr getBackgroundValue() const
Return this tree's background value wrapped as metadata.
void attachAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
static const Name & treeType()
Return the name of this type of tree.
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOnIter > ValueOnIter
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...
RootNodeType::ChildOffCIter cbeginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Index64 inactiveVoxelCount() const override
Return the number of inactive voxels within the bounding box of all active voxels.
void stealNodes(ArrayT &array)
Steals all nodes of a certain type from the tree and adds them to a container with the following API:...
GLsizei const GLfloat * value
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...
int getValueDepth(const Coord &xyz) const
Return the tree depth (0 = root) at which the value of voxel (x, y, z) resides.
TreeIterTraits provides, for all tree iterators, a begin(tree) function that returns an iterator over...
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Base class for tree-traversal iterators over all nodes.
static TreeT::NodeCIter begin(const TreeT &tree)
#define OPENVDB_LOG_WARN(mesg)
ValueAllCIter beginValueAll() const
Return an iterator over all values (tile and voxel) across all nodes.
DeallocateNodes(std::vector< NodeType * > &nodes)
RootNodeType::ChildOffCIter beginRootTiles() const
Return an iterator over non-child entries of the root node's table.
NodeIteratorBase< Tree, typename RootNodeType::ChildOnIter > NodeIter
Iterator over all nodes in this tree.
static TreeT::LeafCIter begin(const TreeT &tree)
GLboolean GLboolean GLboolean GLboolean a
Tree(const OtherTreeType &other, const ValueType &inactiveValue, const ValueType &activeValue, TopologyCopy)
Topology copy constructor from a tree of a different type.
RootNodeType::ChildAllCIter cbeginRootDense() const
Return an iterator over all entries of the root node's table.
RootNodeType & root()
Return this tree's root node.
#define OPENVDB_USE_VERSION_NAMESPACE
The Value Accessor Implementation and API methods. The majoirty of the API matches the API of a compa...
virtual Index64 activeVoxelCount() const =0
Return the total number of active voxels.
static TreeT::RootNodeType::ChildOffIter begin(TreeT &tree)
**But if you need a result
TreeValueIteratorBase< Tree, typename RootNodeType::ValueAllIter > ValueAllIter
virtual Index32 leafCount() const =0
Return the number of leaf nodes.
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueAllCIter > ValueAllCIter
Tree(const ValueType &background)
Empty tree constructor.
bool isValueOff(const Coord &xyz) const
Return true if the value at the given coordinates is inactive.
Index32 unallocatedLeafCount() const override
Return the total number of unallocated leaf nodes residing in this tree.
void readNonresidentBuffers() const override
Read all of this tree's data buffers that are not yet resident in memory (because delayed loading is ...
ValueAccessor< Tree, true > Accessor
void clip(const CoordBBox &)
Set all voxels that lie outside the given axis-aligned box to the background.
Index64 memUsage() const override
Return the total amount of memory in bytes occupied by this tree.
ValueOffCIter cbeginValueOff() const
Return an iterator over inactive values (tile and voxel) across all nodes.
RootNodeType::ChildOffIter beginRootTiles()
Return an iterator over non-child entries of the root node's table.
static TreeT::LeafIter begin(TreeT &tree)
bool operator!=(const Tree &) const
void topologyIntersection(const Tree< OtherRootNodeType > &other)
Intersects this tree's set of active values with the active values of the other tree, whose ValueType may be different.
void releaseAllAccessors()
Notify all registered accessors, by calling ValueAccessor::release(), that this tree is about to be d...
virtual Index64 inactiveVoxelCount() const =0
Return the number of inactive voxels within the bounding box of all active voxels.
Tree4<T, N1, N2, N3>::Type is the type of a four-level tree (Root, Internal, Internal, Leaf) with value type T and internal and leaf node log dimensions N1, N2 and N3, respectively.
bool evalActiveVoxelBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active voxels and tiles.
ConstUnsafeAccessor getConstUnsafeAccessor()
Return an unsafe accessor that provides random read-only access to this tree's voxels.
ValueAllIter beginValueAll()
Return an iterator over all values (tile and voxel) across all nodes.
Tree & operator=(const Tree &)=delete
#define OPENVDB_ASSERT(X)
CombineOpAdapter(CombineOp &_op)
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
std::shared_ptr< T > SharedPtr
void clear()
Remove all tiles from this tree and all nodes other than the root node.
void topologyDifference(const Tree< OtherRootNodeType > &other)
Difference this tree's set of active values with the active values of the other tree, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this tree and inactive in the other tree.
SYS_FORCE_INLINE const_iterator end() const
const AValueType & a() const
Get the A input value.
RootNodeType::ChildOnCIter beginRootChildren() const
Return an iterator over children of the root node.
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
void readBuffers(std::istream &, bool saveFloatAsHalf=false) override
Read all data buffers for this tree.
const ValueType & background() const
Return this tree's background value.
bool isType() const
Return true if this tree is of the same type as the template parameter.
static TreeT::RootNodeType::ChildOnCIter begin(const TreeT &tree)
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this tree's voxels.
tbb::concurrent_hash_map< ValueAccessorBase< const Tree, true > *, bool > ConstAccessorRegistry
LeafCIter beginLeaf() const
Return an iterator over all leaf nodes in this tree.
void operator()(CombineArgs< AValueT, BValueT > &args) const
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
void print(std::ostream &os=std::cout, int verboseLevel=1) const override
Print statistics, memory usage and other information about this tree.
void merge(Tree &other, MergePolicy=MERGE_ACTIVE_STATES)
Efficiently merge another tree into this tree using one of several schemes.
Index64 activeTileCount() const override
Return the total number of active tiles.
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
TreeBase::Ptr copy() const override
Return a pointer to a deep copy of this tree.
Index64 activeLeafVoxelCount() const override
Return the number of active voxels stored in leaf nodes.
void releaseAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
LeafIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > LeafCIter
Iterator over all leaf nodes in this tree.
Index32 leafCount() const override
Return the number of leaf nodes.
void attachAccessor(ValueAccessorBase< Tree, true > &) const
Register an accessor for this tree. Registered accessors are automatically cleared whenever one of th...
NodeCIter beginNode() const
Return an iterator over all nodes in this tree.
OIIO_UTIL_API void parallel_for(int32_t begin, int32_t end, function_view< void(int32_t)> task, paropt opt=0)
bool evalActiveVoxelDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all active voxels. This is a tighter bounding box than the leaf node bounding box.
ValueConverter<T>::Type is the type of a tree having the same hierarchy as this tree but a different ...
const RootNodeType & root() const
Return this tree's root node.
Functions to count tiles, nodes or voxels in a grid.
Tree3<T, N1, N2>::Type is the type of a three-level tree (Root, Internal, Leaf) with value type T and...
const ValueType & max() const
Return the maximum value.
Helper class to adapt a three-argument (a, b, result) CombineOp functor into a single-argument functo...
bool probeValue(const Coord &xyz, ValueType &value) const
Get the value of the voxel at the given coordinates.
ValueOffCIter beginValueOff() const
Return an iterator over inactive values (tile and voxel) across all nodes.
const NodeType * probeConstNode(const Coord &xyz) const
Return a pointer to the node of type NodeType that contains voxel (x, y, z). If no such node exists...
Index64 inactiveLeafVoxelCount() const override
Return the number of inactive voxels stored in leaf nodes.
const LeafNodeType * probeLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return nullptr.
Templated class to compute the minimum and maximum values.
void attachAccessor(ValueAccessorBase< const Tree, false > &) const
Dummy implementations.
static TreeT::ValueOffCIter begin(const TreeT &tree)
GLboolean GLboolean GLboolean b
void operator()(const tbb::blocked_range< size_t > &range) const
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
static TreeT::ValueAllCIter begin(const TreeT &tree)
bool evalLeafBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active tiles and leaf nodes with active values...
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
typename RootNodeType::ValueType ValueType
NodeIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > NodeCIter
Iterator over all nodes in this tree.
static TreeT::RootNodeType::ChildOnIter begin(TreeT &tree)
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOffIter > ValueOffIter
The root node of an OpenVDB tree.
bool hasActiveTiles() const
Return true if this tree has any active tiles.
void releaseAccessor(ValueAccessorBase< const Tree, false > &) const
Dummy implementations.
CIterT cbegin() const
Return a const iterator of type CIterT (for example, cbegin<ValueOnCIter>() is equivalent to cbeginVa...
ValueAllCIter cbeginValueAll() const
Return an iterator over all values (tile and voxel) across all nodes.
Base class for typed trees.
static TreeT::NodeIter begin(TreeT &tree)
static TreeT::ValueOffIter begin(TreeT &tree)
Index64 activeVoxelCount() const override
Return the total number of active voxels.
Index32 nonLeafCount() const override
Return the number of non-leaf nodes.
virtual Index32 nonLeafCount() const =0
Return the number of non-leaf nodes.
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOffCIter > ValueOffCIter
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...
Accessor getAccessor()
Return an accessor that provides random read and write access to this tree's voxels.
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
typename RootNodeType::LeafNodeType LeafNodeType
Tree(const Tree &other)
Deep copy constructor.
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
ConstAccessorRegistry mConstAccessorRegistry
ValueOnCIter beginValueOn() const
Return an iterator over active values (tile and voxel) across all nodes.
void readTopology(std::istream &, bool saveFloatAsHalf=false) override
Read the tree topology from a stream.
virtual void print(std::ostream &os=std::cout, int verboseLevel=1) const
Print statistics, memory usage and other information about this tree.
const ValueType & min() const
Return the minimum value.
LeafData & operator=(const LeafData &)=delete
typename RootNodeType::BuildType BuildType
ValueAccessor< const Tree, true > ConstAccessor
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return nullptr.
static TreeT::RootNodeType::ChildAllIter begin(TreeT &tree)
ValueOnIter beginValueOn()
Return an iterator over active values (tile and voxel) across all nodes.
Base class for tree-traversal iterators over tile and voxel values.
void setValue(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
RootNodeType::ChildAllIter beginRootDense()
Return an iterator over all entries of the root node's table.
NodeCIter cbeginNode() const
Return an iterator over all nodes in this tree.
RootNodeType::ChildOnIter beginRootChildren()
Return an iterator over children of the root node.
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...
void getIndexRange(CoordBBox &bbox) const override
Min and max are both inclusive.
GA_API const UT_StringHolder N
_RootNodeType RootNodeType
FormattedInt< IntT > formattedInt(IntT n)
ValueAccessor< const Tree, false > ConstUnsafeAccessor
SharedPtr< const TreeBase > ConstPtr
static TreeT::ValueOnCIter begin(const TreeT &tree)
void combine2Extended(const Tree &a, const OtherTreeType &b, ExtendedCombineOp &op, bool prune=false)
**If you just want to fire and args
RootNodeType::ChildOnCIter cbeginRootChildren() const
Return an iterator over children of the root node.
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return nullptr.
void combine2(const Tree &a, const OtherTreeType &b, CombineOp &op, bool prune=false)
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)
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...
const Name & type() const override
Return the name of this type of tree.
void clipUnallocatedNodes() override
Replace with background tiles any nodes whose voxel buffers have not yet been allocated.
RootNodeType::ChildAllCIter beginRootDense() const
Return an iterator over all entries of the root node's table.
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
const BValueType & b() const
Get the B input value.
ValueOnCIter cbeginValueOn() const
Return an iterator over active values (tile and voxel) across all nodes.
virtual const Name & type() const =0
Return the name of this tree's type.
Metadata::Ptr getBackgroundValue() const override
Return this tree's background value wrapped as metadata.
NodeIter beginNode()
Return an iterator over all nodes in this tree.
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
bool evalLeafDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all leaf nodes.
IterT begin()
Return an iterator of type IterT (for example, begin<ValueOnIter>() is equivalent to beginValueOn())...
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...
LeafNodeType * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, create one that preserves the values and active states of all voxels.
Tree(const OtherTreeType &other, const ValueType &background, TopologyCopy)
Topology copy constructor from a tree of a different type.
bool empty() const
Return true if this tree contains no nodes other than the root node and no tiles other than backgroun...
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
std::vector< Index32 > nodeCount() const override
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...
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 ...
static TreeT::RootNodeType::ChildOffCIter begin(const TreeT &tree)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
static TreeT::RootNodeType::ChildAllCIter begin(const TreeT &tree)
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.
Tree5<T, N1, N2, N3, N4>::Type is the type of a five-level tree (Root, Internal, Internal, Internal, Leaf) with value type T and internal and leaf node log dimensions N1, N2, N3 and N4, respectively.
void combine(Tree &other, CombineOp &op, bool prune=false)
Internal table nodes for OpenVDB trees.
Index treeDepth() const override
Return the depth of this tree.
#define OPENVDB_THROW(exception, message)
void combineExtended(Tree &other, ExtendedCombineOp &op, bool prune=false)
void clearAllAccessors()
Clear all registered accessors.
void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const override
Write the tree topology to a stream.
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Tree(const Tree< OtherRootType > &other)
Value conversion deep copy constructor.
static TreeT::ValueOnIter begin(TreeT &tree)