6 #ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
7 #define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
22 #include <tbb/concurrent_hash_map.h>
54 template<
typename TreeType>
55 bool isType()
const {
return (this->type() == TreeType::treeType()); }
143 virtual void readTopology(std::istream&,
bool saveFloatAsHalf =
false);
147 virtual void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const;
150 virtual void readBuffers(std::istream&,
bool saveFloatAsHalf =
false) = 0;
160 virtual void writeBuffers(std::ostream&,
bool saveFloatAsHalf =
false)
const = 0;
169 virtual void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const;
176 template<
typename _RootNodeType>
188 static const Index DEPTH = RootNodeType::LEVEL + 1;
196 template<
typename OtherValueType>
217 template<
typename OtherRootType>
232 template<
typename OtherTreeType>
233 Tree(
const OtherTreeType& other,
238 mRoot(other.root(), inactiveValue, activeValue,
TopologyCopy())
253 template<
typename OtherTreeType>
263 ~Tree()
override { this->clear(); releaseAllAccessors(); }
272 static const Name& treeType();
274 const Name&
type()
const override {
return this->treeType(); }
291 template<
typename OtherRootNodeType>
294 bool evalLeafBoundingBox(
CoordBBox& bbox)
const override;
295 bool evalActiveVoxelBoundingBox(
CoordBBox& bbox)
const override;
296 bool evalActiveVoxelDim(
Coord& dim)
const override;
297 bool evalLeafDim(
Coord& dim)
const override;
302 static void getNodeLog2Dims(std::vector<Index>& dims);
311 void readTopology(std::istream&,
bool saveFloatAsHalf =
false)
override;
315 void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
317 void readBuffers(std::istream&,
bool saveFloatAsHalf =
false)
override;
319 void readBuffers(std::istream&,
const CoordBBox&,
bool saveFloatAsHalf =
false)
override;
325 void readNonresidentBuffers()
const override;
327 void writeBuffers(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
329 void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const override;
346 std::vector<Index32> vec(DEPTH, 0);
347 mRoot.nodeCount( vec );
374 const ValueType& getValue(
const Coord& xyz)
const;
382 int getValueDepth(
const Coord& xyz)
const;
385 void setActiveState(
const Coord& xyz,
bool on);
389 void setValueOn(
const Coord& xyz);
396 template<
typename AccessT>
void setValue(
const Coord& xyz,
const ValueType&
value, AccessT&);
398 void setValueOff(
const Coord& xyz);
420 template<
typename ModifyOp>
421 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
442 template<
typename ModifyOp>
443 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
463 void clipUnallocatedNodes()
override;
466 Index32 unallocatedLeafCount()
const override;
477 void sparseFill(
const CoordBBox& bbox,
const ValueType&
value,
bool active =
true);
480 this->sparseFill(bbox,
value, active);
491 void denseFill(
const CoordBBox& bbox,
const ValueType&
value,
bool active =
true);
501 void voxelizeActiveTiles(
bool threaded =
true);
509 this->clearAllAccessors();
510 mRoot.prune(tolerance);
524 void addTile(
Index level,
const Coord& xyz,
const ValueType&
value,
bool active);
530 template<
typename NodeT>
531 NodeT* stealNode(
const Coord& xyz,
const ValueType&
value,
bool active);
538 LeafNodeType* touchLeaf(
const Coord& xyz);
543 template<
typename NodeType> NodeType* probeNode(
const Coord& xyz);
544 template<
typename NodeType>
const NodeType* probeConstNode(
const Coord& xyz)
const;
545 template<
typename NodeType>
const NodeType* probeNode(
const Coord& xyz)
const;
551 LeafNodeType* probeLeaf(
const Coord& xyz);
552 const LeafNodeType* probeConstLeaf(
const Coord& xyz)
const;
579 template<
typename ArrayT>
void getNodes(ArrayT& array) { mRoot.getNodes(array); }
580 template<
typename ArrayT>
void getNodes(ArrayT& array)
const { mRoot.getNodes(array); }
606 template<
typename ArrayT>
607 void stealNodes(ArrayT& array) { this->clearAllAccessors(); mRoot.stealNodes(array); }
608 template<
typename ArrayT>
611 this->clearAllAccessors();
612 mRoot.stealNodes(array,
value, state);
620 bool empty()
const {
return mRoot.empty(); }
626 void clearAllAccessors();
692 template<
typename OtherRootNodeType>
708 template<
typename OtherRootNodeType>
721 template<
typename OtherRootNodeType>
768 template<
typename CombineOp>
771 template<
typename CombineOp>
813 template<
typename ExtendedCombineOp>
814 void combineExtended(
Tree& other, ExtendedCombineOp& op,
bool prune =
false);
816 template<
typename ExtendedCombineOp>
817 void combineExtended(
Tree& other,
const ExtendedCombineOp& op,
bool prune =
false);
848 template<
typename CombineOp,
typename OtherTreeType >
849 void combine2(
const Tree& a,
const OtherTreeType& b, CombineOp& op,
bool prune =
false);
851 template<
typename CombineOp,
typename OtherTreeType >
852 void combine2(
const Tree& a,
const OtherTreeType& b,
const CombineOp& op,
bool prune =
false);
928 template<
typename ExtendedCombineOp,
typename OtherTreeType >
929 void combine2Extended(
const Tree& a,
const OtherTreeType& b, ExtendedCombineOp& op,
932 template<
typename ExtendedCombineOp,
typename OtherTreeType >
933 void combine2Extended(
const Tree& a,
const OtherTreeType& b,
const ExtendedCombineOp&,
937 template<
typename BBoxOp>
939 void visitActiveBBox(BBoxOp& op)
const { mRoot.visitActiveBBox(op); }
941 template<
typename VisitorOp>
943 void visit(VisitorOp& op);
944 template<typename VisitorOp>
946 void visit(const VisitorOp& op);
948 template<typename VisitorOp>
950 void visit(VisitorOp& op) const;
951 template<typename VisitorOp>
953 void visit(const VisitorOp& op) const;
955 template<typename OtherTreeType, typename VisitorOp>
957 void visit2(OtherTreeType& other, VisitorOp& op);
958 template<typename OtherTreeType, typename VisitorOp>
960 void visit2(OtherTreeType& other, const VisitorOp& op);
962 template<typename OtherTreeType, typename VisitorOp>
964 void visit2(OtherTreeType& other, VisitorOp& op) const;
965 template<typename OtherTreeType, typename VisitorOp>
967 void visit2(OtherTreeType& other, const VisitorOp& op) const;
975 typename
RootNodeType::ChildOnCIter beginRootChildren()
const {
return mRoot.cbeginChildOn(); }
982 typename RootNodeType::ChildOffCIter
beginRootTiles()
const {
return mRoot.cbeginChildOff(); }
983 typename RootNodeType::ChildOffCIter
cbeginRootTiles()
const {
return mRoot.cbeginChildOff(); }
984 typename RootNodeType::ChildOffIter
beginRootTiles() {
return mRoot.beginChildOff(); }
989 typename RootNodeType::ChildAllCIter
beginRootDense()
const {
return mRoot.cbeginChildAll(); }
990 typename RootNodeType::ChildAllCIter
cbeginRootDense()
const {
return mRoot.cbeginChildAll(); }
991 typename RootNodeType::ChildAllIter
beginRootDense() {
return mRoot.beginChildAll(); }
1049 template<
typename IterT> IterT begin();
1052 template<
typename CIterT> CIterT
cbegin()
const;
1061 void releaseAllAccessors();
1064 template<
typename NodeType>
1067 : mNodes(nodes.empty() ? nullptr : &nodes.front()) { }
1069 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
1070 delete mNodes[n]; mNodes[n] =
nullptr;
1086 template<
typename _RootNodeType>
1094 template<
typename T, Index N1=4, Index N2=3>
1104 template<
typename T, Index N1=5, Index N2=4, Index N3=3>
1113 template<
typename T, Index N1=6, Index N2=5, Index N3=4, Index N4=3>
1126 int32_t bufferCount;
1127 is.read(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1128 if (bufferCount != 1)
OPENVDB_LOG_WARN(
"multi-buffer trees are no longer supported");
1135 int32_t bufferCount = 1;
1136 os.write(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1143 os <<
" Tree Type: " << type()
1144 <<
" Active Voxel Count: " << activeVoxelCount() << std::endl
1145 <<
" Active tile Count: " << activeTileCount() << std::endl
1146 <<
" Inactive Voxel Count: " << inactiveVoxelCount() << std::endl
1147 <<
" Leaf Node Count: " << leafCount() << std::endl
1148 <<
" Non-leaf Node Count: " << nonLeafCount() << std::endl;
1163 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1164 static typename TreeT::RootNodeType::ChildOnIter
begin(TreeT& tree) {
1165 return tree.beginRootChildren();
1169 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1170 static typename TreeT::RootNodeType::ChildOnCIter
begin(
const TreeT& tree) {
1171 return tree.cbeginRootChildren();
1175 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1176 static typename TreeT::RootNodeType::ChildOffIter
begin(TreeT& tree) {
1177 return tree.beginRootTiles();
1181 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1182 static typename TreeT::RootNodeType::ChildOffCIter
begin(
const TreeT& tree) {
1183 return tree.cbeginRootTiles();
1187 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1188 static typename TreeT::RootNodeType::ChildAllIter
begin(TreeT& tree) {
1189 return tree.beginRootDense();
1193 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1194 static typename TreeT::RootNodeType::ChildAllCIter
begin(
const TreeT& tree) {
1195 return tree.cbeginRootDense();
1200 static typename TreeT::NodeIter
begin(TreeT& tree) {
return tree.beginNode(); }
1204 static typename TreeT::NodeCIter
begin(
const TreeT& tree) {
return tree.cbeginNode(); }
1208 static typename TreeT::LeafIter
begin(TreeT& tree) {
return tree.beginLeaf(); }
1212 static typename TreeT::LeafCIter
begin(
const TreeT& tree) {
return tree.cbeginLeaf(); }
1216 static typename TreeT::ValueOnIter
begin(TreeT& tree) {
return tree.beginValueOn(); }
1219 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOnCIter> {
1220 static typename TreeT::ValueOnCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOn(); }
1223 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffIter> {
1224 static typename TreeT::ValueOffIter
begin(TreeT& tree) {
return tree.beginValueOff(); }
1227 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1228 static typename TreeT::ValueOffCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOff(); }
1231 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllIter> {
1232 static typename TreeT::ValueAllIter
begin(TreeT& tree) {
return tree.beginValueAll(); }
1235 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1236 static typename TreeT::ValueAllCIter
begin(
const TreeT& tree) {
return tree.cbeginValueAll(); }
1240 template<
typename RootNodeType>
1241 template<
typename IterT>
1249 template<
typename RootNodeType>
1250 template<
typename IterT>
1261 template<
typename RootNodeType>
1265 this->clearAllAccessors();
1267 mRoot.readTopology(is, saveFloatAsHalf);
1271 template<
typename RootNodeType>
1276 mRoot.writeTopology(os, saveFloatAsHalf);
1280 template<
typename RootNodeType>
1284 this->clearAllAccessors();
1285 mRoot.readBuffers(is, saveFloatAsHalf);
1289 template<
typename RootNodeType>
1293 this->clearAllAccessors();
1294 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1298 template<
typename RootNodeType>
1302 for (
LeafCIter it = this->cbeginLeaf(); it; ++it) {
1309 template<
typename RootNodeType>
1317 template<
typename RootNodeType>
1321 std::vector<LeafNodeType*> leafnodes;
1322 this->stealNodes(leafnodes);
1324 tbb::parallel_for(tbb::blocked_range<size_t>(0, leafnodes.size()),
1327 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1328 this->stealNodes(internalNodes);
1330 tbb::parallel_for(tbb::blocked_range<size_t>(0, internalNodes.size()),
1335 this->clearAllAccessors();
1342 template<
typename RootNodeType>
1346 typename AccessorRegistry::accessor a;
1347 mAccessorRegistry.insert(a, &accessor);
1351 template<
typename RootNodeType>
1355 typename ConstAccessorRegistry::accessor a;
1356 mConstAccessorRegistry.insert(a, &accessor);
1360 template<
typename RootNodeType>
1364 mAccessorRegistry.erase(&accessor);
1368 template<
typename RootNodeType>
1372 mConstAccessorRegistry.erase(&accessor);
1376 template<
typename RootNodeType>
1380 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1381 it != mAccessorRegistry.end(); ++it)
1383 if (it->first) it->first->
clear();
1386 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1387 it != mConstAccessorRegistry.end(); ++it)
1389 if (it->first) it->first->clear();
1394 template<
typename RootNodeType>
1398 mAccessorRegistry.erase(
nullptr);
1399 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1400 it != mAccessorRegistry.end(); ++it)
1402 it->first->release();
1404 mAccessorRegistry.
clear();
1406 mAccessorRegistry.erase(
nullptr);
1407 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1408 it != mConstAccessorRegistry.end(); ++it)
1410 it->first->release();
1412 mConstAccessorRegistry.clear();
1419 template<
typename RootNodeType>
1420 inline const typename RootNodeType::ValueType&
1427 template<
typename RootNodeType>
1428 template<
typename AccessT>
1429 inline const typename RootNodeType::ValueType&
1436 template<
typename RootNodeType>
1444 template<
typename RootNodeType>
1452 template<
typename RootNodeType>
1460 template<
typename RootNodeType>
1468 template<
typename RootNodeType>
1475 template<
typename RootNodeType>
1482 template<
typename RootNodeType>
1483 template<
typename AccessT>
1491 template<
typename RootNodeType>
1499 template<
typename RootNodeType>
1507 template<
typename RootNodeType>
1508 template<
typename ModifyOp>
1516 template<
typename RootNodeType>
1517 template<
typename ModifyOp>
1525 template<
typename RootNodeType>
1536 template<
typename RootNodeType>
1545 template<
typename RootNodeType>
1546 template<
typename NodeT>
1550 this->clearAllAccessors();
1551 return mRoot.template stealNode<NodeT>(xyz,
value, active);
1555 template<
typename RootNodeType>
1556 inline typename RootNodeType::LeafNodeType*
1563 template<
typename RootNodeType>
1564 inline typename RootNodeType::LeafNodeType*
1571 template<
typename RootNodeType>
1572 inline const typename RootNodeType::LeafNodeType*
1579 template<
typename RootNodeType>
1580 template<
typename NodeType>
1584 return mRoot.template probeNode<NodeType>(xyz);
1588 template<
typename RootNodeType>
1589 template<
typename NodeType>
1590 inline const NodeType*
1593 return this->
template probeConstNode<NodeType>(xyz);
1597 template<
typename RootNodeType>
1598 template<
typename NodeType>
1599 inline const NodeType*
1602 return mRoot.template probeConstNode<NodeType>(xyz);
1609 template<
typename RootNodeType>
1613 this->clearAllAccessors();
1614 return mRoot.clip(bbox);
1618 template<
typename RootNodeType>
1622 this->clearAllAccessors();
1623 for (
LeafIter it = this->beginLeaf(); it; ) {
1626 if (!leaf->isAllocated()) {
1627 this->addTile(0, leaf->origin(), this->background(),
false);
1632 template<
typename RootNodeType>
1637 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1642 template<
typename RootNodeType>
1646 this->clearAllAccessors();
1647 return mRoot.sparseFill(bbox,
value, active);
1651 template<
typename RootNodeType>
1655 this->clearAllAccessors();
1656 return mRoot.denseFill(bbox,
value, active);
1660 template<
typename RootNodeType>
1664 this->clearAllAccessors();
1665 mRoot.voxelizeActiveTiles(threaded);
1669 template<
typename RootNodeType>
1677 if (result->typeName() == MetadataT::staticTypeName()) {
1678 MetadataT* m =
static_cast<MetadataT*
>(result.get());
1679 m->value() = mRoot.background();
1689 template<
typename RootNodeType>
1693 this->clearAllAccessors();
1697 mRoot.template merge<MERGE_ACTIVE_STATES>(other.
mRoot);
break;
1699 mRoot.template merge<MERGE_NODES>(other.
mRoot);
break;
1701 mRoot.template merge<MERGE_ACTIVE_STATES_AND_NODES>(other.
mRoot);
break;
1706 template<
typename RootNodeType>
1707 template<
typename OtherRootNodeType>
1711 this->clearAllAccessors();
1712 mRoot.topologyUnion(other.
root(), preserveTiles);
1715 template<
typename RootNodeType>
1716 template<
typename OtherRootNodeType>
1720 this->clearAllAccessors();
1721 mRoot.topologyIntersection(other.
root());
1724 template<
typename RootNodeType>
1725 template<
typename OtherRootNodeType>
1729 this->clearAllAccessors();
1730 mRoot.topologyDifference(other.
root());
1738 template<
typename AValueT,
typename CombineOp,
typename BValueT = AValueT>
1744 op(args.
a(), args.
b(), args.
result());
1751 template<
typename RootNodeType>
1752 template<
typename CombineOp>
1757 this->combineExtended(other, extendedOp,
prune);
1764 template<
typename RootNodeType>
1765 template<
typename CombineOp>
1770 this->combineExtended(other, extendedOp,
prune);
1775 template<
typename RootNodeType>
1776 template<
typename ExtendedCombineOp>
1780 this->clearAllAccessors();
1788 template<
typename RootNodeType>
1789 template<
typename ExtendedCombineOp>
1793 this->clearAllAccessors();
1794 mRoot.template combine<const ExtendedCombineOp>(other.
mRoot, op,
prune);
1799 template<
typename RootNodeType>
1800 template<
typename CombineOp,
typename OtherTreeType>
1805 this->combine2Extended(a, b, extendedOp,
prune);
1812 template<
typename RootNodeType>
1813 template<
typename CombineOp,
typename OtherTreeType>
1818 this->combine2Extended(a, b, extendedOp,
prune);
1823 template<
typename RootNodeType>
1824 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1827 ExtendedCombineOp& op,
bool prune)
1829 this->clearAllAccessors();
1830 mRoot.combine2(a.
root(), b.root(), op,
prune);
1838 template<
typename RootNodeType>
1839 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1842 const ExtendedCombineOp& op,
bool prune)
1844 this->clearAllAccessors();
1845 mRoot.template combine2<const ExtendedCombineOp>(a.
root(), b.root(), op,
prune);
1853 template<
typename RootNodeType>
1854 template<
typename VisitorOp>
1858 this->clearAllAccessors();
1859 mRoot.template visit<VisitorOp>(op);
1863 template<
typename RootNodeType>
1864 template<
typename VisitorOp>
1868 mRoot.template visit<VisitorOp>(op);
1874 template<
typename RootNodeType>
1875 template<
typename VisitorOp>
1879 this->clearAllAccessors();
1880 mRoot.template visit<const VisitorOp>(op);
1886 template<
typename RootNodeType>
1887 template<
typename VisitorOp>
1891 mRoot.template visit<const VisitorOp>(op);
1898 template<
typename RootNodeType>
1899 template<
typename OtherTreeType,
typename VisitorOp>
1903 this->clearAllAccessors();
1904 using OtherRootNodeType =
typename OtherTreeType::RootNodeType;
1905 mRoot.template visit2<OtherRootNodeType, VisitorOp>(other.root(), op);
1909 template<
typename RootNodeType>
1910 template<
typename OtherTreeType,
typename VisitorOp>
1914 using OtherRootNodeType =
typename OtherTreeType::RootNodeType;
1915 mRoot.template visit2<OtherRootNodeType, VisitorOp>(other.root(), op);
1921 template<
typename RootNodeType>
1922 template<
typename OtherTreeType,
typename VisitorOp>
1926 this->clearAllAccessors();
1927 using OtherRootNodeType =
typename OtherTreeType::RootNodeType;
1928 mRoot.template visit2<OtherRootNodeType, const VisitorOp>(other.root(), op);
1934 template<
typename RootNodeType>
1935 template<
typename OtherTreeType,
typename VisitorOp>
1939 using OtherRootNodeType =
typename OtherTreeType::RootNodeType;
1940 mRoot.template visit2<OtherRootNodeType, const VisitorOp>(other.root(), op);
1947 template<
typename RootNodeType>
1951 static std::once_flag once;
1952 std::call_once(once, []()
1954 std::vector<Index> dims;
1955 Tree::getNodeLog2Dims(dims);
1956 std::ostringstream ostr;
1957 ostr <<
"Tree_" << typeNameAsString<BuildType>();
1958 for (
size_t i = 1, N = dims.size(); i < N; ++i) {
1959 ostr <<
"_" << dims[i];
1961 sTreeTypeName.reset(
new Name(ostr.str()));
1963 return *sTreeTypeName;
1967 template<
typename RootNodeType>
1968 template<
typename OtherRootNodeType>
1976 template<
typename RootNodeType>
1982 if (this->empty())
return false;
1984 mRoot.evalActiveBoundingBox(bbox,
false);
1986 return !bbox.
empty();
1989 template<
typename RootNodeType>
1995 if (this->empty())
return false;
1997 mRoot.evalActiveBoundingBox(bbox,
true);
1999 return !bbox.
empty();
2003 template<
typename RootNodeType>
2008 bool notEmpty = this->evalActiveVoxelBoundingBox(bbox);
2014 template<
typename RootNodeType>
2019 bool notEmpty = this->evalLeafBoundingBox(bbox);
2025 template<
typename RootNodeType>
2029 minVal = maxVal = zeroVal<ValueType>();
2031 minVal = maxVal = *iter;
2032 for (++iter; iter; ++iter) {
2041 template<
typename RootNodeType>
2046 RootNodeType::getNodeLog2Dims(dims);
2050 template<
typename RootNodeType>
2054 if (verboseLevel <= 0)
return;
2059 std::streamsize savedPrecision;
2060 OnExit(std::ostream& _os): os(_os), savedPrecision(os.precision()) {}
2061 ~OnExit() { os.precision(savedPrecision); }
2063 OnExit restorePrecision(os);
2065 std::vector<Index> dims;
2066 Tree::getNodeLog2Dims(dims);
2068 os <<
"Information about Tree:\n"
2069 <<
" Type: " << this->type() <<
"\n";
2071 os <<
" Configuration:\n";
2073 if (verboseLevel <= 1) {
2075 os <<
" Root(" << mRoot.getTableSize() <<
")";
2076 if (dims.size() > 1) {
2077 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
2078 os <<
", Internal(" << (1 << dims[i]) <<
"^3)";
2080 os <<
", Leaf(" << (1 << dims.back()) <<
"^3)\n";
2082 os <<
" Background value: " << mRoot.background() <<
"\n";
2088 ValueType minVal = zeroVal<ValueType>(), maxVal = zeroVal<ValueType>();
2089 if (verboseLevel > 3) {
2096 const auto nodeCount = this->nodeCount();
2097 const Index32 leafCount = nodeCount.front();
2098 assert(dims.size() == nodeCount.size());
2101 for (
size_t i = 0; i < nodeCount.size(); ++i) totalNodeCount += nodeCount[i];
2104 os <<
" Root(1 x " << mRoot.getTableSize() <<
")";
2105 if (dims.size() >= 2) {
2106 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
2108 os <<
" x " << (1 << dims[i]) <<
"^3)";
2111 os <<
" x " << (1 << dims.back()) <<
"^3)\n";
2113 os <<
" Background value: " << mRoot.background() <<
"\n";
2117 if (verboseLevel > 3) {
2118 os <<
" Min value: " << minVal <<
"\n";
2119 os <<
" Max value: " << maxVal <<
"\n";
2123 numActiveVoxels = this->activeVoxelCount(),
2124 numActiveLeafVoxels = this->activeLeafVoxelCount(),
2125 numActiveTiles = this->activeTileCount();
2132 if (numActiveVoxels) {
2134 this->evalActiveVoxelBoundingBox(bbox);
2136 totalVoxels = dim.
x() * uint64_t(dim.
y()) * dim.
z();
2138 os <<
" Bounding box of active voxels: " << bbox <<
"\n";
2139 os <<
" Dimensions of active voxels: "
2140 << dim[0] <<
" x " << dim[1] <<
" x " << dim[2] <<
"\n";
2142 const double activeRatio = (100.0 * double(numActiveVoxels)) /
double(totalVoxels);
2143 os <<
" Percentage of active voxels: " << std::setprecision(3) << activeRatio <<
"%\n";
2145 if (leafCount > 0) {
2146 const double fillRatio = (100.0 * double(numActiveLeafVoxels))
2147 / (
double(leafCount) * double(LeafNodeType::NUM_VOXELS));
2148 os <<
" Average leaf node fill ratio: " << fillRatio <<
"%\n";
2151 if (verboseLevel > 2) {
2153 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
2154 os <<
" Number of unallocated nodes: "
2156 << (100.0 * double(sum) / double(totalNodeCount)) <<
"%)\n";
2159 os <<
" Tree is empty!\n";
2163 if (verboseLevel == 2)
return;
2168 denseMem =
sizeof(
ValueType) * totalVoxels,
2169 voxelsMem =
sizeof(
ValueType) * numActiveLeafVoxels;
2172 os <<
"Memory footprint:\n";
2176 if (numActiveVoxels) {
2178 os <<
" Actual footprint is " << (100.0 * double(actualMem) / double(denseMem))
2179 <<
"% of an equivalent dense volume\n";
2180 os <<
" Leaf voxel footprint is " << (100.0 * double(voxelsMem) / double(actualMem))
2181 <<
"% of actual footprint\n";
Functions to count tiles, nodes or voxels in a grid.
ValueT value
Definition: GridBuilder.h:1287
Internal table nodes for OpenVDB trees.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
The root node of an OpenVDB tree.
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:530
const AValueType & a() const
Get the A input value.
Definition: Types.h:569
const BValueType & b() const
Get the B input value.
Definition: Types.h:571
const AValueType & result() const
Get the output value.
Definition: Types.h:574
Definition: Exceptions.h:61
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:644
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
Coord extents() const
Definition: Coord.h:382
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:356
void reset()
Definition: Coord.h:327
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
Int32 y() const
Definition: Coord.h:131
Int32 x() const
Definition: Coord.h:130
Int32 z() const
Definition: Coord.h:132
double min() const
Return the minimum value.
Definition: Stats.h:125
double max() const
Return the maximum value.
Definition: Stats.h:128
Templated class to compute the minimum and maximum values.
Definition: Stats.h:31
Definition: NodeManager.h:890
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels)
Definition: TreeIterator.h:1187
Base class for tree-traversal iterators over all nodes.
Definition: TreeIterator.h:936
Base class for typed trees.
Definition: Tree.h:37
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
virtual Index32 nonLeafCount() const =0
Return the number of non-leaf nodes.
virtual void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const
Write the tree topology to a stream.
Definition: Tree.h:1133
virtual ~TreeBase()=default
virtual Index64 activeLeafVoxelCount() const =0
Return the number of active voxels stored in leaf nodes.
virtual std::vector< Index32 > 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:55
virtual void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const =0
Write out all the data buffers for this tree.
virtual Metadata::Ptr getBackgroundValue() const
Return this tree's background value wrapped as metadata.
Definition: Tree.h:65
virtual const Name & type() const =0
Return the name of this tree's type.
TreeBase & operator=(const TreeBase &)=delete
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:1141
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 Index32 leafCount() const =0
Return the number of leaf nodes.
virtual Index32 unallocatedLeafCount() const =0
Return the total number of unallocated leaf nodes residing in this tree.
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:134
virtual TreeBase::Ptr copy() const =0
Return a pointer to a deep copy of this tree.
SharedPtr< TreeBase > Ptr
Definition: Tree.h:39
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:40
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(const TreeBase &)=default
virtual void readTopology(std::istream &, bool saveFloatAsHalf=false)
Read the tree topology from a stream.
Definition: Tree.h:1124
Base class for tree-traversal iterators over tile and voxel values.
Definition: TreeIterator.h:617
RootNodeType::ChildAllCIter beginRootDense() const
Return an iterator over all entries of the root node's table.
Definition: Tree.h:989
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:1438
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:1970
CIterT cbegin() const
Return a const iterator of type CIterT (for example, cbegin<ValueOnCIter>() is equivalent to cbeginVa...
void releaseAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition: Tree.h:649
void releaseAccessor(ValueAccessorBase< const Tree, false > &) const
Definition: Tree.h:650
ConstAccessorRegistry mConstAccessorRegistry
Definition: Tree.h:1081
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
Definition: Tree.h:450
Tree(const Tree &other)
Deep copy constructor.
Definition: Tree.h:207
RootNodeType::ChildOffCIter cbeginRootTiles() const
Definition: Tree.h:983
LeafCIter beginLeaf() const
Definition: Tree.h:1017
RootNodeType & root()
Return this tree's root node.
Definition: Tree.h:281
const ValueType & background() const
Return this tree's background value.
Definition: Tree.h:662
void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const override
Write out all data buffers for this tree.
Definition: Tree.h:1311
ValueOffCIter cbeginValueOff() const
Definition: Tree.h:1044
Tree(const Tree< OtherRootType > &other)
Value conversion deep copy constructor.
Definition: Tree.h:218
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Definition: Tree.h:1573
void clearAllAccessors()
Clear all registered accessors.
Definition: Tree.h:1378
_RootNodeType RootNodeType
Definition: Tree.h:183
RootNodeType::ChildAllIter beginRootDense()
Definition: Tree.h:991
LeafCIter cbeginLeaf() const
Definition: Tree.h:1018
RootNodeType::ChildOffIter beginRootTiles()
Definition: Tree.h:984
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition: Tree.h:579
bool operator!=(const Tree &) const
Definition: Tree.h:277
Tree()
Definition: Tree.h:202
AccessorRegistry mAccessorRegistry
Definition: Tree.h:1080
RootNodeType mRoot
Definition: Tree.h:1079
ValueAllCIter cbeginValueAll() const
Definition: Tree.h:1032
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:507
static std::unique_ptr< const Name > sTreeTypeName
Definition: Tree.h:1083
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:1565
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:1557
RootNodeType::ChildOnIter beginRootChildren()
Definition: Tree.h:977
Tree & operator=(const Tree &)=delete
ValueOnCIter beginValueOn() const
Definition: Tree.h:1037
bool operator==(const Tree &) const
Definition: Tree.h:276
Index64 activeLeafVoxelCount() const override
Return the number of active voxels stored in leaf nodes.
Definition: Tree.h:353
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: Tree.h:1519
Index32 leafCount() const override
Return the number of leaf nodes.
Definition: Tree.h:340
Index64 inactiveVoxelCount() const override
Return the number of inactive voxels within the bounding box of all active voxels.
Definition: Tree.h:359
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:1477
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:620
Index64 activeVoxelCount() const override
Return the total number of active voxels.
Definition: Tree.h:357
Index64 inactiveLeafVoxelCount() const override
Return the number of inactive voxels stored in leaf nodes.
Definition: Tree.h:355
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Definition: Tree.h:478
ValueOffCIter beginValueOff() const
Definition: Tree.h:1043
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:518
RootNodeType::ChildOffCIter beginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Definition: Tree.h:982
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:1538
bool probeValue(const Coord &xyz, ValueType &value) const
Get the value of the voxel at the given coordinates.
Definition: Tree.h:1527
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:1462
ValueOnIter beginValueOn()
Return an iterator over active values (tile and voxel) across all nodes.
Definition: Tree.h:1036
std::vector< Index32 > nodeCount() const override
Definition: Tree.h:344
typename RootNodeType::BuildType BuildType
Definition: Tree.h:185
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:1470
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.
Index64 activeTileCount() const override
Return the total number of active tiles.
Definition: Tree.h:361
const Name & type() const override
Return the name of this type of tree.
Definition: Tree.h:274
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: Tree.h:1446
tbb::concurrent_hash_map< ValueAccessorBase< const Tree, true > *, bool > ConstAccessorRegistry
Definition: Tree.h:1057
ValueOnCIter cbeginValueOn() const
Definition: Tree.h:1038
TreeBase::Ptr copy() const override
Return a pointer to a deep copy of this tree.
Definition: Tree.h:266
typename RootNodeType::ValueType ValueType
Definition: Tree.h:184
void attachAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition: Tree.h:637
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: Tree.h:1421
void attachAccessor(ValueAccessorBase< const Tree, false > &) const
Definition: Tree.h:638
NodeCIter beginNode() const
Definition: Tree.h:1010
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:1510
Tree(const OtherTreeType &other, const ValueType &background, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition: Tree.h:254
RootNodeType::ChildAllCIter cbeginRootDense() const
Definition: Tree.h:990
void getNodes(ArrayT &array) const
Definition: Tree.h:580
const LeafNodeType * probeLeaf(const Coord &xyz) const
Definition: Tree.h:553
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Definition: Tree.h:609
void clear()
Remove all tiles from this tree and all nodes other than the root node.
Definition: Tree.h:1319
RootNodeType::ChildOnCIter cbeginRootChildren() const
Definition: Tree.h:976
NodeCIter cbeginNode() const
Definition: Tree.h:1011
ValueOffIter beginValueOff()
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition: Tree.h:1042
void getIndexRange(CoordBBox &bbox) const override
Min and max are both inclusive.
Definition: Tree.h:665
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:186
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: Tree.h:1493
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:1016
Tree(const OtherTreeType &other, const ValueType &inactiveValue, const ValueType &activeValue, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition: Tree.h:233
~Tree() override
Definition: Tree.h:263
bool hasActiveTiles() const
Return true if this tree has any active tiles.
Definition: Tree.h:454
Tree(const ValueType &background)
Empty tree constructor.
Definition: Tree.h:261
bool isValueOff(const Coord &xyz) const
Return true if the value at the given coordinates is inactive.
Definition: Tree.h:452
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:607
Index32 nonLeafCount() const override
Return the number of non-leaf nodes.
Definition: Tree.h:351
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
Definition: Tree.h:269
const RootNodeType & root() const
Definition: Tree.h:282
Index treeDepth() const override
Return the depth of this tree.
Definition: Tree.h:338
ValueAllCIter beginValueAll() const
Definition: Tree.h:1031
NodeIter beginNode()
Return an iterator over all nodes in this tree.
Definition: Tree.h:1009
tbb::concurrent_hash_map< ValueAccessorBase< Tree, true > *, bool > AccessorRegistry
Definition: Tree.h:1056
ValueAllIter beginValueAll()
Return an iterator over all values (tile and voxel) across all nodes.
Definition: Tree.h:1030
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
Definition: ValueAccessor.h:85
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
OPENVDB_AX_API void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition: Mat.h:1051
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition: Mat.h:1037
std::pair< ValueT, ValueT > evalMinMax(const PointDataTreeT &points, const std::string &attribute, const FilterT &filter=NullFilter())
Evaluates the minimum and maximum values of a point attribute.
Definition: PointStatistics.h:697
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:17
Index32 Index
Definition: Types.h:54
uint32_t Index32
Definition: Types.h:52
uint64_t Index64
Definition: Types.h:53
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
MergePolicy
Definition: Types.h:467
@ MERGE_ACTIVE_STATES
Definition: Types.h:468
@ MERGE_NODES
Definition: Types.h:469
@ MERGE_ACTIVE_STATES_AND_NODES
Definition: Types.h:470
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:141
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:1740
void operator()(CombineArgs< AValueT, BValueT > &args) const
Definition: Tree.h:1743
CombineOpAdapter(CombineOp &_op)
Definition: Tree.h:1741
CombineOp & op
Definition: Tree.h:1747
Tree3<T, N1, N2>::Type is the type of a three-level tree (Root, Internal, Leaf) with value type T and...
Definition: Tree.h:1095
Tree4<T, N1, N2, N3>::Type is the type of a four-level tree (Root, Internal, Internal,...
Definition: Tree.h:1105
Tree5<T, N1, N2, N3, N4>::Type is the type of a five-level tree (Root, Internal, Internal,...
Definition: Tree.h:1114
static TreeT::LeafCIter begin(const TreeT &tree)
Definition: Tree.h:1212
static TreeT::LeafIter begin(TreeT &tree)
Definition: Tree.h:1208
static TreeT::NodeCIter begin(const TreeT &tree)
Definition: Tree.h:1204
static TreeT::NodeIter begin(TreeT &tree)
Definition: Tree.h:1200
static TreeT::RootNodeType::ChildAllCIter begin(const TreeT &tree)
Definition: Tree.h:1194
static TreeT::RootNodeType::ChildAllIter begin(TreeT &tree)
Definition: Tree.h:1188
static TreeT::RootNodeType::ChildOffCIter begin(const TreeT &tree)
Definition: Tree.h:1182
static TreeT::RootNodeType::ChildOffIter begin(TreeT &tree)
Definition: Tree.h:1176
static TreeT::RootNodeType::ChildOnCIter begin(const TreeT &tree)
Definition: Tree.h:1170
static TreeT::RootNodeType::ChildOnIter begin(TreeT &tree)
Definition: Tree.h:1164
static TreeT::ValueAllCIter begin(const TreeT &tree)
Definition: Tree.h:1236
static TreeT::ValueAllIter begin(TreeT &tree)
Definition: Tree.h:1232
static TreeT::ValueOffCIter begin(const TreeT &tree)
Definition: Tree.h:1228
static TreeT::ValueOffIter begin(TreeT &tree)
Definition: Tree.h:1224
static TreeT::ValueOnCIter begin(const TreeT &tree)
Definition: Tree.h:1220
static TreeT::ValueOnIter begin(TreeT &tree)
Definition: Tree.h:1216
TreeIterTraits provides, for all tree iterators, a begin(tree) function that returns an iterator over...
Definition: Tree.h:1161
DeallocateNodes(std::vector< NodeType * > &nodes)
Definition: Tree.h:1066
NodeType **const mNodes
Definition: Tree.h:1073
void operator()(const tbb::blocked_range< size_t > &range) const
Definition: Tree.h:1068
ValueConverter<T>::Type is the type of a tree having the same hierarchy as this tree but a different ...
Definition: Tree.h:197
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202