6 #ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED 7 #define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED 22 #include <tbb/concurrent_hash_map.h> 48 virtual const Name& type()
const = 0;
51 virtual Name valueType()
const = 0;
54 template<
typename TreeType>
55 bool isType()
const {
return (this->type() == TreeType::treeType()); }
74 virtual bool evalLeafBoundingBox(
CoordBBox& bbox)
const = 0;
79 virtual bool evalLeafDim(
Coord& dim)
const = 0;
88 virtual bool evalActiveVoxelBoundingBox(
CoordBBox& bbox)
const = 0;
93 virtual bool evalActiveVoxelDim(
Coord& dim)
const = 0;
95 virtual void getIndexRange(
CoordBBox& bbox)
const = 0;
102 virtual void clipUnallocatedNodes() = 0;
104 virtual Index32 unallocatedLeafCount()
const = 0;
113 virtual Index treeDepth()
const = 0;
115 virtual Index32 leafCount()
const = 0;
119 virtual std::vector<Index32> nodeCount()
const = 0;
121 virtual Index32 nonLeafCount()
const = 0;
123 virtual Index64 activeLeafVoxelCount()
const = 0;
125 virtual Index64 inactiveLeafVoxelCount()
const = 0;
127 virtual Index64 activeVoxelCount()
const = 0;
129 virtual Index64 inactiveVoxelCount()
const = 0;
131 virtual Index64 activeTileCount()
const = 0;
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;
152 virtual void readBuffers(std::istream&,
const CoordBBox&,
bool saveFloatAsHalf =
false) = 0;
158 virtual void readNonresidentBuffers()
const = 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>
204 Tree& operator=(
const Tree&) =
delete;
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;
377 template<
typename AccessT>
const ValueType& getValue(
const Coord& xyz, AccessT&)
const;
382 int getValueDepth(
const Coord& xyz)
const;
385 void setActiveState(
const Coord& xyz,
bool on);
387 void setValueOnly(
const Coord& xyz,
const ValueType&
value);
389 void setValueOn(
const Coord& xyz);
391 void setValueOn(
const Coord& xyz,
const ValueType&
value);
393 void setValue(
const Coord& xyz,
const ValueType&
value);
396 template<
typename AccessT>
void setValue(
const Coord& xyz,
const ValueType&
value, AccessT&);
398 void setValueOff(
const Coord& xyz);
400 void setValueOff(
const Coord& xyz,
const ValueType&
value);
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);
447 bool probeValue(
const Coord& xyz, ValueType&
value)
const;
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>
770 template<
typename CombineOp>
811 template<
typename ExtendedCombineOp>
812 void combineExtended(
Tree& other, ExtendedCombineOp& op,
bool prune =
false);
813 template<
typename ExtendedCombineOp>
814 void combineExtended(
Tree& other,
const ExtendedCombineOp& op,
bool prune =
false);
844 template<
typename CombineOp,
typename OtherTreeType >
845 void combine2(
const Tree& a,
const OtherTreeType& b, CombineOp& op,
bool prune =
false);
846 template<
typename CombineOp,
typename OtherTreeType >
847 void combine2(
const Tree& a,
const OtherTreeType& b,
const CombineOp& op,
bool prune =
false);
922 template<
typename ExtendedCombineOp,
typename OtherTreeType >
923 void combine2Extended(
const Tree& a,
const OtherTreeType& b, ExtendedCombineOp& op,
925 template<
typename ExtendedCombineOp,
typename OtherTreeType >
926 void combine2Extended(
const Tree& a,
const OtherTreeType& b,
const ExtendedCombineOp&,
941 typename RootNodeType::ChildOffCIter
beginRootTiles()
const {
return mRoot.cbeginChildOff(); }
942 typename RootNodeType::ChildOffCIter
cbeginRootTiles()
const {
return mRoot.cbeginChildOff(); }
943 typename RootNodeType::ChildOffIter
beginRootTiles() {
return mRoot.beginChildOff(); }
948 typename RootNodeType::ChildAllCIter
beginRootDense()
const {
return mRoot.cbeginChildAll(); }
949 typename RootNodeType::ChildAllCIter
cbeginRootDense()
const {
return mRoot.cbeginChildAll(); }
950 typename RootNodeType::ChildAllIter
beginRootDense() {
return mRoot.beginChildAll(); }
1008 template<
typename IterT> IterT begin();
1011 template<
typename CIterT> CIterT cbegin()
const;
1020 void releaseAllAccessors();
1023 template<
typename NodeType>
1026 : mNodes(nodes.empty() ? nullptr : &nodes.front()) { }
1028 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
1029 delete mNodes[n]; mNodes[n] =
nullptr;
1045 template<
typename _RootNodeType>
1053 template<
typename T, Index N1=4, Index N2=3>
1063 template<
typename T, Index N1=5, Index N2=4, Index N3=3>
1072 template<
typename T, Index N1=6, Index N2=5, Index N3=4, Index N4=3>
1085 int32_t bufferCount;
1086 is.read(reinterpret_cast<char*>(&bufferCount),
sizeof(int32_t));
1087 if (bufferCount != 1)
OPENVDB_LOG_WARN(
"multi-buffer trees are no longer supported");
1094 int32_t bufferCount = 1;
1095 os.write(reinterpret_cast<char*>(&bufferCount),
sizeof(int32_t));
1102 os <<
" Tree Type: " << type()
1103 <<
" Active Voxel Count: " << activeVoxelCount() << std::endl
1104 <<
" Active tile Count: " << activeTileCount() << std::endl
1105 <<
" Inactive Voxel Count: " << inactiveVoxelCount() << std::endl
1106 <<
" Leaf Node Count: " << leafCount() << std::endl
1107 <<
" Non-leaf Node Count: " << nonLeafCount() << std::endl;
1122 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1123 static typename TreeT::RootNodeType::ChildOnIter
begin(TreeT& tree) {
1124 return tree.beginRootChildren();
1128 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1129 static typename TreeT::RootNodeType::ChildOnCIter
begin(
const TreeT& tree) {
1130 return tree.cbeginRootChildren();
1134 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1135 static typename TreeT::RootNodeType::ChildOffIter
begin(TreeT& tree) {
1136 return tree.beginRootTiles();
1140 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1141 static typename TreeT::RootNodeType::ChildOffCIter
begin(
const TreeT& tree) {
1142 return tree.cbeginRootTiles();
1146 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1147 static typename TreeT::RootNodeType::ChildAllIter
begin(TreeT& tree) {
1148 return tree.beginRootDense();
1152 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1153 static typename TreeT::RootNodeType::ChildAllCIter
begin(
const TreeT& tree) {
1154 return tree.cbeginRootDense();
1159 static typename TreeT::NodeIter
begin(TreeT& tree) {
return tree.beginNode(); }
1163 static typename TreeT::NodeCIter
begin(
const TreeT& tree) {
return tree.cbeginNode(); }
1167 static typename TreeT::LeafIter
begin(TreeT& tree) {
return tree.beginLeaf(); }
1171 static typename TreeT::LeafCIter
begin(
const TreeT& tree) {
return tree.cbeginLeaf(); }
1175 static typename TreeT::ValueOnIter
begin(TreeT& tree) {
return tree.beginValueOn(); }
1178 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOnCIter> {
1179 static typename TreeT::ValueOnCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOn(); }
1182 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffIter> {
1183 static typename TreeT::ValueOffIter
begin(TreeT& tree) {
return tree.beginValueOff(); }
1186 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1187 static typename TreeT::ValueOffCIter
begin(
const TreeT& tree) {
return tree.cbeginValueOff(); }
1190 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllIter> {
1191 static typename TreeT::ValueAllIter
begin(TreeT& tree) {
return tree.beginValueAll(); }
1194 template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1195 static typename TreeT::ValueAllCIter
begin(
const TreeT& tree) {
return tree.cbeginValueAll(); }
1199 template<
typename RootNodeType>
1200 template<
typename IterT>
1208 template<
typename RootNodeType>
1209 template<
typename IterT>
1220 template<
typename RootNodeType>
1224 this->clearAllAccessors();
1226 mRoot.readTopology(is, saveFloatAsHalf);
1230 template<
typename RootNodeType>
1235 mRoot.writeTopology(os, saveFloatAsHalf);
1239 template<
typename RootNodeType>
1243 this->clearAllAccessors();
1244 mRoot.readBuffers(is, saveFloatAsHalf);
1248 template<
typename RootNodeType>
1252 this->clearAllAccessors();
1253 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1257 template<
typename RootNodeType>
1261 for (
LeafCIter it = this->cbeginLeaf(); it; ++it) {
1268 template<
typename RootNodeType>
1276 template<
typename RootNodeType>
1280 std::vector<LeafNodeType*> leafnodes;
1281 this->stealNodes(leafnodes);
1283 tbb::parallel_for(tbb::blocked_range<size_t>(0, leafnodes.size()),
1286 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1287 this->stealNodes(internalNodes);
1289 tbb::parallel_for(tbb::blocked_range<size_t>(0, internalNodes.size()),
1294 this->clearAllAccessors();
1301 template<
typename RootNodeType>
1305 typename AccessorRegistry::accessor a;
1306 mAccessorRegistry.insert(a, &accessor);
1310 template<
typename RootNodeType>
1314 typename ConstAccessorRegistry::accessor a;
1315 mConstAccessorRegistry.insert(a, &accessor);
1319 template<
typename RootNodeType>
1323 mAccessorRegistry.erase(&accessor);
1327 template<
typename RootNodeType>
1331 mConstAccessorRegistry.erase(&accessor);
1335 template<
typename RootNodeType>
1339 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1340 it != mAccessorRegistry.end(); ++it)
1342 if (it->first) it->first->
clear();
1345 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1346 it != mConstAccessorRegistry.end(); ++it)
1348 if (it->first) it->first->clear();
1353 template<
typename RootNodeType>
1357 mAccessorRegistry.erase(
nullptr);
1358 for (
typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1359 it != mAccessorRegistry.end(); ++it)
1361 it->first->release();
1363 mAccessorRegistry.
clear();
1365 mAccessorRegistry.erase(
nullptr);
1366 for (
typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1367 it != mConstAccessorRegistry.end(); ++it)
1369 it->first->release();
1371 mConstAccessorRegistry.clear();
1378 template<
typename RootNodeType>
1379 inline const typename RootNodeType::ValueType&
1386 template<
typename RootNodeType>
1387 template<
typename AccessT>
1388 inline const typename RootNodeType::ValueType&
1395 template<
typename RootNodeType>
1403 template<
typename RootNodeType>
1411 template<
typename RootNodeType>
1419 template<
typename RootNodeType>
1427 template<
typename RootNodeType>
1434 template<
typename RootNodeType>
1441 template<
typename RootNodeType>
1442 template<
typename AccessT>
1450 template<
typename RootNodeType>
1458 template<
typename RootNodeType>
1466 template<
typename RootNodeType>
1467 template<
typename ModifyOp>
1475 template<
typename RootNodeType>
1476 template<
typename ModifyOp>
1484 template<
typename RootNodeType>
1495 template<
typename RootNodeType>
1504 template<
typename RootNodeType>
1505 template<
typename NodeT>
1509 this->clearAllAccessors();
1510 return mRoot.template stealNode<NodeT>(xyz,
value, active);
1514 template<
typename RootNodeType>
1515 inline typename RootNodeType::LeafNodeType*
1522 template<
typename RootNodeType>
1523 inline typename RootNodeType::LeafNodeType*
1530 template<
typename RootNodeType>
1531 inline const typename RootNodeType::LeafNodeType*
1538 template<
typename RootNodeType>
1539 template<
typename NodeType>
1543 return mRoot.template probeNode<NodeType>(xyz);
1547 template<
typename RootNodeType>
1548 template<
typename NodeType>
1549 inline const NodeType*
1552 return this->
template probeConstNode<NodeType>(xyz);
1556 template<
typename RootNodeType>
1557 template<
typename NodeType>
1558 inline const NodeType*
1561 return mRoot.template probeConstNode<NodeType>(xyz);
1568 template<
typename RootNodeType>
1572 this->clearAllAccessors();
1573 return mRoot.clip(bbox);
1577 template<
typename RootNodeType>
1581 this->clearAllAccessors();
1582 for (
LeafIter it = this->beginLeaf(); it; ) {
1585 if (!leaf->isAllocated()) {
1586 this->addTile(0, leaf->origin(), this->background(),
false);
1591 template<
typename RootNodeType>
1596 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1601 template<
typename RootNodeType>
1605 this->clearAllAccessors();
1606 return mRoot.sparseFill(bbox,
value, active);
1610 template<
typename RootNodeType>
1614 this->clearAllAccessors();
1615 return mRoot.denseFill(bbox,
value, active);
1619 template<
typename RootNodeType>
1623 this->clearAllAccessors();
1624 mRoot.voxelizeActiveTiles(threaded);
1628 template<
typename RootNodeType>
1636 if (result->typeName() == MetadataT::staticTypeName()) {
1637 MetadataT* m =
static_cast<MetadataT*
>(result.get());
1638 m->value() = mRoot.background();
1648 template<
typename RootNodeType>
1652 this->clearAllAccessors();
1656 mRoot.template merge<MERGE_ACTIVE_STATES>(other.
mRoot);
break;
1658 mRoot.template merge<MERGE_NODES>(other.
mRoot);
break;
1660 mRoot.template merge<MERGE_ACTIVE_STATES_AND_NODES>(other.
mRoot);
break;
1665 template<
typename RootNodeType>
1666 template<
typename OtherRootNodeType>
1670 this->clearAllAccessors();
1671 mRoot.topologyUnion(other.
root(), preserveTiles);
1674 template<
typename RootNodeType>
1675 template<
typename OtherRootNodeType>
1679 this->clearAllAccessors();
1680 mRoot.topologyIntersection(other.
root());
1683 template<
typename RootNodeType>
1684 template<
typename OtherRootNodeType>
1688 this->clearAllAccessors();
1689 mRoot.topologyDifference(other.
root());
1697 template<
typename AValueT,
typename CombineOp,
typename BValueT = AValueT>
1703 op(args.
a(), args.
b(), args.
result());
1710 template<
typename RootNodeType>
1711 template<
typename CombineOp>
1716 this->combineExtended(other, extendedOp,
prune);
1722 template<
typename RootNodeType>
1723 template<
typename CombineOp>
1728 this->combineExtended(other, extendedOp,
prune);
1732 template<
typename RootNodeType>
1733 template<
typename ExtendedCombineOp>
1737 this->clearAllAccessors();
1744 template<
typename RootNodeType>
1745 template<
typename ExtendedCombineOp>
1749 this->clearAllAccessors();
1750 mRoot.template combine<const ExtendedCombineOp>(other.
mRoot, op,
prune);
1754 template<
typename RootNodeType>
1755 template<
typename CombineOp,
typename OtherTreeType>
1760 this->combine2Extended(a, b, extendedOp,
prune);
1766 template<
typename RootNodeType>
1767 template<
typename CombineOp,
typename OtherTreeType>
1772 this->combine2Extended(a, b, extendedOp,
prune);
1776 template<
typename RootNodeType>
1777 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1780 ExtendedCombineOp& op,
bool prune)
1782 this->clearAllAccessors();
1783 mRoot.combine2(a.
root(), b.root(), op,
prune);
1790 template<
typename RootNodeType>
1791 template<
typename ExtendedCombineOp,
typename OtherTreeType>
1794 const ExtendedCombineOp& op,
bool prune)
1796 this->clearAllAccessors();
1797 mRoot.template combine2<const ExtendedCombineOp>(a.
root(), b.root(), op,
prune);
1804 template<
typename RootNodeType>
1808 static std::once_flag once;
1809 std::call_once(once, []()
1811 std::vector<Index> dims;
1812 Tree::getNodeLog2Dims(dims);
1813 std::ostringstream ostr;
1814 ostr <<
"Tree_" << typeNameAsString<BuildType>();
1815 for (
size_t i = 1, N = dims.size(); i < N; ++i) {
1816 ostr <<
"_" << dims[i];
1818 sTreeTypeName.reset(
new Name(ostr.str()));
1820 return *sTreeTypeName;
1824 template<
typename RootNodeType>
1825 template<
typename OtherRootNodeType>
1833 template<
typename RootNodeType>
1839 if (this->empty())
return false;
1841 mRoot.evalActiveBoundingBox(bbox,
false);
1843 return !bbox.
empty();
1846 template<
typename RootNodeType>
1852 if (this->empty())
return false;
1854 mRoot.evalActiveBoundingBox(bbox,
true);
1856 return !bbox.
empty();
1860 template<
typename RootNodeType>
1865 bool notEmpty = this->evalActiveVoxelBoundingBox(bbox);
1871 template<
typename RootNodeType>
1876 bool notEmpty = this->evalLeafBoundingBox(bbox);
1882 template<
typename RootNodeType>
1886 minVal = maxVal = zeroVal<ValueType>();
1888 minVal = maxVal = *iter;
1889 for (++iter; iter; ++iter) {
1898 template<
typename RootNodeType>
1903 RootNodeType::getNodeLog2Dims(dims);
1907 template<
typename RootNodeType>
1911 if (verboseLevel <= 0)
return;
1916 std::streamsize savedPrecision;
1917 OnExit(std::ostream& _os): os(_os), savedPrecision(os.precision()) {}
1918 ~OnExit() { os.precision(savedPrecision); }
1920 OnExit restorePrecision(os);
1922 std::vector<Index> dims;
1923 Tree::getNodeLog2Dims(dims);
1925 os <<
"Information about Tree:\n" 1926 <<
" Type: " << this->type() <<
"\n";
1928 os <<
" Configuration:\n";
1930 if (verboseLevel <= 1) {
1932 os <<
" Root(" << mRoot.getTableSize() <<
")";
1933 if (dims.size() > 1) {
1934 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
1935 os <<
", Internal(" << (1 << dims[i]) <<
"^3)";
1937 os <<
", Leaf(" << (1 << dims.back()) <<
"^3)\n";
1939 os <<
" Background value: " << mRoot.background() <<
"\n";
1945 ValueType minVal = zeroVal<ValueType>(), maxVal = zeroVal<ValueType>();
1946 if (verboseLevel > 3) {
1953 const auto nodeCount = this->nodeCount();
1954 const Index32 leafCount = nodeCount.front();
1955 assert(dims.size() == nodeCount.size());
1958 for (
size_t i = 0; i < nodeCount.size(); ++i) totalNodeCount += nodeCount[i];
1961 os <<
" Root(1 x " << mRoot.getTableSize() <<
")";
1962 if (dims.size() >= 2) {
1963 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
1965 os <<
" x " << (1 << dims[i]) <<
"^3)";
1968 os <<
" x " << (1 << dims.back()) <<
"^3)\n";
1970 os <<
" Background value: " << mRoot.background() <<
"\n";
1974 if (verboseLevel > 3) {
1975 os <<
" Min value: " << minVal <<
"\n";
1976 os <<
" Max value: " << maxVal <<
"\n";
1980 numActiveVoxels = this->activeVoxelCount(),
1981 numActiveLeafVoxels = this->activeLeafVoxelCount(),
1982 numActiveTiles = this->activeTileCount();
1989 if (numActiveVoxels) {
1991 this->evalActiveVoxelBoundingBox(bbox);
1993 totalVoxels = dim.
x() * uint64_t(dim.
y()) * dim.
z();
1995 os <<
" Bounding box of active voxels: " << bbox <<
"\n";
1996 os <<
" Dimensions of active voxels: " 1997 << dim[0] <<
" x " << dim[1] <<
" x " << dim[2] <<
"\n";
1999 const double activeRatio = (100.0 * double(numActiveVoxels)) /
double(totalVoxels);
2000 os <<
" Percentage of active voxels: " << std::setprecision(3) << activeRatio <<
"%\n";
2002 if (leafCount > 0) {
2003 const double fillRatio = (100.0 * double(numActiveLeafVoxels))
2004 / (
double(leafCount) * double(LeafNodeType::NUM_VOXELS));
2005 os <<
" Average leaf node fill ratio: " << fillRatio <<
"%\n";
2008 if (verboseLevel > 2) {
2010 for (
auto it = this->cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
2011 os <<
" Number of unallocated nodes: " 2013 << (100.0 * double(sum) / double(totalNodeCount)) <<
"%)\n";
2016 os <<
" Tree is empty!\n";
2020 if (verboseLevel == 2)
return;
2025 denseMem =
sizeof(
ValueType) * totalVoxels,
2026 voxelsMem =
sizeof(
ValueType) * numActiveLeafVoxels;
2029 os <<
"Memory footprint:\n";
2033 if (numActiveVoxels) {
2035 os <<
" Actual footprint is " << (100.0 * double(actualMem) / double(denseMem))
2036 <<
"% of an equivalent dense volume\n";
2037 os <<
" Leaf voxel footprint is " << (100.0 * double(voxelsMem) / double(actualMem))
2038 <<
"% of actual footprint\n";
2046 #endif // OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED void reset()
Definition: Coord.h:327
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition: Tree.h:579
Index32 Index
Definition: Types.h:54
const AValueType & a() const
Get the A input value.
Definition: Types.h:569
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.
Definition: Tree.h:1064
void fill(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:478
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 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
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
uint64_t Index64
Definition: Types.h:53
SharedPtr< TreeBase > Ptr
Definition: Tree.h:39
ValueAllIter beginValueAll()
Return an iterator over all values (tile and voxel) across all nodes.
Definition: Tree.h:989
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: Tree.h:1405
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:248
Index64 activeVoxelCount() const override
Return the total number of active voxels.
Definition: Tree.h:357
void getNodes(ArrayT &array) const
Adds all nodes of a certain type to a container with the following API:
Definition: Tree.h:580
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
static TreeT::NodeCIter begin(const TreeT &tree)
Definition: Tree.h:1163
TreeIterTraits provides, for all tree iterators, a begin(tree) function that returns an iterator over...
Definition: Tree.h:1120
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: Tree.h:1380
RootNodeType::ChildOnCIter beginRootChildren() const
Return an iterator over children of the root node.
Definition: Tree.h:934
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.
Definition: Tree.h:1532
ValueOnCIter cbeginValueOn() const
Return an iterator over active values (tile and voxel) across all nodes.
Definition: Tree.h:997
virtual void readTopology(std::istream &, bool saveFloatAsHalf=false)
Read the tree topology from a stream.
Definition: Tree.h:1083
NodeIter beginNode()
Return an iterator over all nodes in this tree.
Definition: Tree.h:968
FormattedInt< IntT > formattedInt(IntT n)
Definition: Formats.h:118
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:24
ConstAccessorRegistry mConstAccessorRegistry
Definition: Tree.h:1040
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition: Mat.h:1015
static TreeT::LeafIter begin(TreeT &tree)
Definition: Tree.h:1167
Templated class to compute the minimum and maximum values.
Definition: Stats.h:30
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
Definition: Mat.h:1029
RootNodeType mRoot
Definition: Tree.h:1038
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
Definition: Tree.h:450
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
CombineOp & op
Definition: Tree.h:1706
ValueOnCIter beginValueOn() const
Return an iterator over active values (tile and voxel) across all nodes.
Definition: Tree.h:996
OPENVDB_API int printBytes(std::ostream &os, uint64_t bytes, const std::string &head="", const std::string &tail="\, bool exact=false, int width=8, int precision=3)
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:1100
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.
Definition: Tree.h:1073
static TreeT::RootNodeType::ChildAllCIter begin(const TreeT &tree)
Definition: Tree.h:1153
_RootNodeType RootNodeType
Definition: Tree.h:183
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
Definition: ValueAccessor.h:92
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:1429
Index32 nonLeafCount() const override
Return the number of non-leaf nodes.
Definition: Tree.h:351
void clear()
Remove all tiles from this tree and all nodes other than the root node.
Definition: Tree.h:1278
tbb::concurrent_hash_map< ValueAccessorBase< const Tree, true > *, bool > ConstAccessorRegistry
Definition: Tree.h:1016
bool probeValue(const Coord &xyz, ValueType &value) const
Get the value of the voxel at the given coordinates.
Definition: Tree.h:1486
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Definition: TreeIterator.h:1186
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:1436
double min() const
Return the minimum value.
Definition: Stats.h:125
static TreeT::ValueOnIter begin(TreeT &tree)
Definition: Tree.h:1175
typename RootNodeType::BuildType BuildType
Definition: Tree.h:185
Index32 leafCount() const override
Return the number of leaf nodes.
Definition: Tree.h:340
static std::unique_ptr< const Name > sTreeTypeName
Definition: Tree.h:1042
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:1397
Tree(const ValueType &background)
Empty tree constructor.
Definition: Tree.h:261
static TreeT::RootNodeType::ChildOnCIter begin(const TreeT &tree)
Definition: Tree.h:1129
static TreeT::ValueOffCIter begin(const TreeT &tree)
Definition: Tree.h:1187
void operator()(CombineArgs< AValueT, BValueT > &args) const
Definition: Tree.h:1702
static TreeT::RootNodeType::ChildOffIter begin(TreeT &tree)
Definition: Tree.h:1135
void clearAllAccessors()
Clear all registered accessors.
Definition: Tree.h:1337
RootNodeType::ChildAllCIter beginRootDense() const
Return an iterator over all entries of the root node's table.
Definition: Tree.h:948
const RootNodeType & root() const
Return this tree's root node.
Definition: Tree.h:282
LeafCIter beginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:976
static TreeT::LeafCIter begin(const TreeT &tree)
Definition: Tree.h:1171
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:40
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: Tree.h:1452
virtual Metadata::Ptr getBackgroundValue() const
Return this tree's background value wrapped as metadata.
Definition: Tree.h:65
Base class for typed trees.
Definition: Tree.h:36
ValueAllCIter beginValueAll() const
Return an iterator over all values (tile and voxel) across all nodes.
Definition: Tree.h:990
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:975
Tree(const Tree< OtherRootType > &other)
Value conversion deep copy constructor.
Definition: Tree.h:218
Internal table nodes for OpenVDB trees.
NodeType **const mNodes
Definition: Tree.h:1032
static TreeT::NodeIter begin(TreeT &tree)
Definition: Tree.h:1159
void operator()(const tbb::blocked_range< size_t > &range) const
Definition: Tree.h:1027
Int32 y() const
Definition: Coord.h:131
double max() const
Return the maximum value.
Definition: Stats.h:128
bool isValueOff(const Coord &xyz) const
Return true if the value at the given coordinates is inactive.
Definition: Tree.h:452
Index64 activeTileCount() const override
Return the total number of active tiles.
Definition: Tree.h:361
void attachAccessor(ValueAccessorBase< const Tree, false > &) const
Dummy implementations.
Definition: Tree.h:638
const AValueType & result() const
Get the output value.
Definition: Types.h:574
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:256
virtual void writeTopology(std::ostream &, bool saveFloatAsHalf=false) const
Write the tree topology to a stream.
Definition: Tree.h:1092
typename RootNodeType::LeafNodeType LeafNodeType
Definition: Tree.h:186
static TreeT::RootNodeType::ChildOffCIter begin(const TreeT &tree)
Definition: Tree.h:1141
static TreeT::ValueAllIter begin(TreeT &tree)
Definition: Tree.h:1191
Int32 x() const
Definition: Coord.h:130
Base class for tree-traversal iterators over tile and voxel values.
Definition: TreeIterator.h:616
static TreeT::ValueOnCIter begin(const TreeT &tree)
Definition: Tree.h:1179
Tree(const OtherTreeType &other, const ValueType &background, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition: Tree.h:254
Definition: Exceptions.h:13
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: Tree.h:1478
RootNodeType::ChildOnCIter cbeginRootChildren() const
Return an iterator over children of the root node.
Definition: Tree.h:935
RootNodeType::ChildOffCIter beginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Definition: Tree.h:941
ValueT value
Definition: GridBuilder.h:1290
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
Definition: Tree.h:269
ValueOffIter beginValueOff()
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition: Tree.h:1001
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.
Definition: Tree.h:553
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:1827
RootNodeType::ChildOffCIter cbeginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Definition: Tree.h:942
void writeBuffers(std::ostream &, bool saveFloatAsHalf=false) const override
Write out all data buffers for this tree.
Definition: Tree.h:1270
ValueOffCIter cbeginValueOff() const
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition: Tree.h:1003
RootNodeType::ChildOnIter beginRootChildren()
Return an iterator over children of the root node.
Definition: Tree.h:936
Coord extents() const
Definition: Coord.h:382
Index treeDepth() const override
Return the depth of this tree.
Definition: Tree.h:338
uint32_t Index32
Definition: Types.h:52
Tree()
Definition: Tree.h:202
const ValueType & background() const
Return this tree's background value.
Definition: Tree.h:662
ValueConverter<T>::Type is the type of a tree having the same hierarchy as this tree but a different ...
Definition: Tree.h:197
MergePolicy
Definition: Types.h:467
ValueAllCIter cbeginValueAll() const
Return an iterator over all values (tile and voxel) across all nodes.
Definition: Tree.h:991
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
ValueOffCIter beginValueOff() const
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition: Tree.h:1002
Functions to count tiles, nodes or voxels in a grid.
static TreeT::ValueAllCIter begin(const TreeT &tree)
Definition: Tree.h:1195
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.
Definition: Tree.h:1516
static TreeT::ValueOffIter begin(TreeT &tree)
Definition: Tree.h:1183
RootNodeType & root()
Return this tree's root node.
Definition: Tree.h:281
bool isType() const
Return true if this tree is of the same type as the template parameter.
Definition: Tree.h:55
tree::TreeBase TreeBase
Definition: Grid.h:26
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:1497
Int32 z() const
Definition: Coord.h:132
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:1469
void getIndexRange(CoordBBox &bbox) const override
Min and max are both inclusive.
Definition: Tree.h:665
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
bool operator!=(const Tree &) const
Definition: Tree.h:277
tbb::concurrent_hash_map< ValueAccessorBase< Tree, true > *, bool > AccessorRegistry
Definition: Tree.h:1015
Definition: Exceptions.h:61
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:1421
Base class for tree-traversal iterators over all nodes.
Definition: TreeIterator.h:935
Index64 activeLeafVoxelCount() const override
Return the number of active voxels stored in leaf nodes.
Definition: Tree.h:353
~Tree() override
Definition: Tree.h:263
The root node of an OpenVDB tree.
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Definition: Tree.h:609
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:644
NodeCIter beginNode() const
Return an iterator over all nodes in this tree.
Definition: Tree.h:969
Helper class to adapt a three-argument (a, b, result) CombineOp functor into a single-argument functo...
Definition: Tree.h:1698
const Name & type() const override
Return the name of this type of tree.
Definition: Tree.h:274
void releaseAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition: Tree.h:649
static TreeT::RootNodeType::ChildOnIter begin(TreeT &tree)
Definition: Tree.h:1123
Index64 inactiveLeafVoxelCount() const override
Return the number of inactive voxels stored in leaf nodes.
Definition: Tree.h:355
RootNodeType::ChildOffIter beginRootTiles()
Return an iterator over non-child entries of the root node's table.
Definition: Tree.h:943
RootNodeType::ChildAllCIter cbeginRootDense() const
Return an iterator over all entries of the root node's table.
Definition: Tree.h:949
Tree3<T, N1, N2>::Type is the type of a three-level tree (Root, Internal, Leaf) with value type T and...
Definition: Tree.h:1054
void releaseAccessor(ValueAccessorBase< const Tree, false > &) const
Dummy implementations.
Definition: Tree.h:650
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
TreeBase::Ptr copy() const override
Return a pointer to a deep copy of this tree.
Definition: Tree.h:266
const BValueType & b() const
Get the B input value.
Definition: Types.h:571
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition: Coord.h:356
typename RootNodeType::ValueType ValueType
Definition: Tree.h:184
ValueOnIter beginValueOn()
Return an iterator over active values (tile and voxel) across all nodes.
Definition: Tree.h:995
LeafCIter cbeginLeaf() const
Return an iterator over all leaf nodes in this tree.
Definition: Tree.h:977
bool hasActiveTiles() const
Return true if this tree has any active tiles.
Definition: Tree.h:454
RootNodeType::ChildAllIter beginRootDense()
Return an iterator over all entries of the root node's table.
Definition: Tree.h:950
std::vector< Index32 > nodeCount() const override
Definition: Tree.h:344
virtual Index64 memUsage() const
Return the total amount of memory in bytes occupied by this tree.
Definition: Tree.h:134
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:529
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
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:141
Tree(const Tree &other)
Deep copy constructor.
Definition: Tree.h:207
bool operator==(const Tree &) const
Definition: Tree.h:276
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.
Definition: Tree.h:1524
Index64 inactiveVoxelCount() const override
Return the number of inactive voxels within the bounding box of all active voxels.
Definition: Tree.h:359
CombineOpAdapter(CombineOp &_op)
Definition: Tree.h:1700
void attachAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition: Tree.h:637
NodeCIter cbeginNode() const
Return an iterator over all nodes in this tree.
Definition: Tree.h:970
std::string Name
Definition: Name.h:17
DeallocateNodes(std::vector< NodeType *> &nodes)
Definition: Tree.h:1025
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212
static TreeT::RootNodeType::ChildAllIter begin(TreeT &tree)
Definition: Tree.h:1147
AccessorRegistry mAccessorRegistry
Definition: Tree.h:1039