6#ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
7#define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
23#include <tbb/concurrent_hash_map.h>
55 template<
typename TreeType>
56 bool isType()
const {
return (this->
type() == TreeType::treeType()); }
131#if OPENVDB_ABI_VERSION_NUMBER < 14
138 virtual void readTopology(std::istream&,
bool saveFloatAsHalf =
false) = 0;
142 virtual void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const = 0;
145 virtual void readBuffers(std::istream&,
bool saveFloatAsHalf =
false) = 0;
147 virtual void readBuffers(std::istream&,
const CoordBBox&,
bool saveFloatAsHalf =
false) = 0;
150 virtual
void readNonresidentBuffers() const = 0;
153 virtual
void writeBuffers(
std::ostream&,
bool saveFloatAsHalf = false) const = 0;
163 virtual void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const;
170template<
typename _RootNodeType>
195 template<
typename OtherValueType>
216 template<
typename OtherRootType>
231 template<
typename OtherTreeType>
232 Tree(
const OtherTreeType& other,
252 template<
typename OtherTreeType>
290 template<
typename OtherRootNodeType>
303#if OPENVDB_ABI_VERSION_NUMBER < 14
310 void readTopology(std::istream&,
bool saveFloatAsHalf =
false)
override;
314 void writeTopology(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
316 void readBuffers(std::istream&,
bool saveFloatAsHalf =
false)
override;
318 void readBuffers(std::istream&,
const CoordBBox&,
bool saveFloatAsHalf =
false)
override;
321 void readNonresidentBuffers()
const override { }
324 void writeBuffers(std::ostream&,
bool saveFloatAsHalf =
false)
const override;
327 void print(std::ostream& os = std::cout,
int verboseLevel = 1)
const override;
344 std::vector<Index64> vec(
DEPTH, 0);
345 mRoot.nodeCount( vec );
414 template<
typename ModifyOp>
436 template<
typename ModifyOp>
501 mRoot.prune(tolerance);
521 template<
typename NodeT>
570 template<
typename ArrayT>
void getNodes(ArrayT& array);
571 template<
typename ArrayT>
void getNodes(ArrayT& array)
const;
597 template<
typename ArrayT>
599 template<
typename ArrayT>
603 mRoot.stealNodes(array, value, state);
708 template<
typename OtherRootNodeType>
724 template<
typename OtherRootNodeType>
737 template<
typename OtherRootNodeType>
784 template<
typename CombineOp>
786 template<
typename CombineOp>
827 template<
typename ExtendedCombineOp>
829 template<
typename ExtendedCombineOp>
860 template<
typename CombineOp,
typename OtherTreeType >
862 template<
typename CombineOp,
typename OtherTreeType >
938 template<
typename ExtendedCombineOp,
typename OtherTreeType >
941 template<
typename ExtendedCombineOp,
typename OtherTreeType >
1027 template<
typename CIterT> CIterT
cbegin()
const;
1039 template<
typename NodeType>
1042 :
mNodes(nodes.
empty() ? nullptr : &nodes.front()) { }
1044 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
1064template<
typename T, Index N1=4, Index N2=3>
1074template<
typename T, Index N1=5, Index N2=4, Index N3=3>
1083template<
typename T, Index N1=6, Index N2=5, Index N3=4, Index N4=3>
1096 os <<
" Tree Type: " <<
type()
1100 <<
" Leaf Node Count: " <<
leafCount() << std::endl
1101 <<
" Non-leaf Node Count: " <<
nonLeafCount() << std::endl;
1116template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1117 static typename TreeT::RootNodeType::ChildOnIter
begin(TreeT&
tree) {
1118 return tree.beginRootChildren();
1122template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1123 static typename TreeT::RootNodeType::ChildOnCIter
begin(
const TreeT&
tree) {
1124 return tree.cbeginRootChildren();
1128template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1129 static typename TreeT::RootNodeType::ChildOffIter
begin(TreeT&
tree) {
1130 return tree.beginRootTiles();
1134template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1135 static typename TreeT::RootNodeType::ChildOffCIter
begin(
const TreeT&
tree) {
1136 return tree.cbeginRootTiles();
1140template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1141 static typename TreeT::RootNodeType::ChildAllIter
begin(TreeT&
tree) {
1142 return tree.beginRootDense();
1146template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1147 static typename TreeT::RootNodeType::ChildAllCIter
begin(
const TreeT&
tree) {
1148 return tree.cbeginRootDense();
1157 static typename TreeT::NodeCIter
begin(
const TreeT&
tree) {
return tree.cbeginNode(); }
1165 static typename TreeT::LeafCIter
begin(
const TreeT&
tree) {
return tree.cbeginLeaf(); }
1169 static typename TreeT::ValueOnIter
begin(TreeT&
tree) {
return tree.beginValueOn(); }
1173 static typename TreeT::ValueOnCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueOn(); }
1177 static typename TreeT::ValueOffIter
begin(TreeT&
tree) {
return tree.beginValueOff(); }
1180template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1181 static typename TreeT::ValueOffCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueOff(); }
1185 static typename TreeT::ValueAllIter
begin(TreeT&
tree) {
return tree.beginValueAll(); }
1188template<
typename TreeT>
struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1189 static typename TreeT::ValueAllCIter
begin(
const TreeT&
tree) {
return tree.cbeginValueAll(); }
1193template<
typename RootNodeType>
1194template<
typename IterT>
1202template<
typename RootNodeType>
1203template<
typename IterT>
1214#if OPENVDB_ABI_VERSION_NUMBER < 14
1216template<
typename RootNodeType>
1220 this->clearAllAccessors();
1221 int32_t bufferCount;
1222 is.read(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1223 if (bufferCount != 1)
OPENVDB_LOG_WARN(
"multi-buffer trees are no longer supported");
1224 mRoot.readTopology(is, saveFloatAsHalf);
1228template<
typename RootNodeType>
1230Tree<RootNodeType>::writeTopology(std::ostream& os,
bool saveFloatAsHalf)
const
1232 int32_t bufferCount = 1;
1233 os.write(
reinterpret_cast<char*
>(&bufferCount),
sizeof(int32_t));
1234 mRoot.writeTopology(os, saveFloatAsHalf);
1238template<
typename RootNodeType>
1240Tree<RootNodeType>::readBuffers(std::istream &is,
bool saveFloatAsHalf)
1242 this->clearAllAccessors();
1243 mRoot.readBuffers(is, saveFloatAsHalf);
1247template<
typename RootNodeType>
1249Tree<RootNodeType>::readBuffers(std::istream &is,
const CoordBBox& bbox,
bool saveFloatAsHalf)
1251 this->clearAllAccessors();
1252 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1256template<
typename RootNodeType>
1258Tree<RootNodeType>::writeBuffers(std::ostream &os,
bool saveFloatAsHalf)
const
1260 mRoot.writeBuffers(os, saveFloatAsHalf);
1266template<
typename RootNodeType>
1267template<
typename ArrayT>
1271 using NodeT =
typename std::remove_pointer<typename ArrayT::value_type>::type;
1272 static_assert(!std::is_same<NodeT, RootNodeType>::value,
1273 "getNodes() does not work for the RootNode. Use Tree::root()");
1274 mRoot.getNodes(array);
1278template<
typename RootNodeType>
1279template<
typename ArrayT>
1283 using NodeT =
typename std::remove_pointer<typename ArrayT::value_type>::type;
1284 static_assert(!std::is_same<NodeT, const RootNodeType>::value,
1285 "getNodes() does not work for the RootNode. Use Tree::root()");
1286 mRoot.getNodes(array);
1290template<
typename RootNodeType>
1294 std::vector<LeafNodeType*> leafnodes;
1297 tbb::parallel_for(tbb::blocked_range<size_t>(0, leafnodes.size()),
1300 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1303 tbb::parallel_for(tbb::blocked_range<size_t>(0, internalNodes.size()),
1315template<
typename RootNodeType>
1322template<
typename RootNodeType>
1329template<
typename RootNodeType>
1336template<
typename RootNodeType>
1343template<
typename RootNodeType>
1350template<
typename RootNodeType>
1354 typename AccessorRegistry::accessor a;
1359template<
typename RootNodeType>
1363 typename ConstAccessorRegistry::accessor a;
1368template<
typename RootNodeType>
1376template<
typename RootNodeType>
1384template<
typename RootNodeType>
1391 if (it->first) it->first->clear();
1397 if (it->first) it->first->clear();
1402template<
typename RootNodeType>
1410 it->first->release();
1418 it->first->release();
1427template<
typename RootNodeType>
1428inline const typename RootNodeType::ValueType&
1431 return mRoot.getValue(xyz);
1435template<
typename RootNodeType>
1436template<
typename AccessT>
1437inline const typename RootNodeType::ValueType&
1440 return accessor.getValue(xyz);
1444template<
typename RootNodeType>
1448 return mRoot.getValueDepth(xyz);
1452template<
typename RootNodeType>
1456 mRoot.setValueOff(xyz);
1460template<
typename RootNodeType>
1464 mRoot.setValueOff(xyz, value);
1468template<
typename RootNodeType>
1472 mRoot.setActiveState(xyz, on);
1476template<
typename RootNodeType>
1480 mRoot.setValueOn(xyz, value);
1483template<
typename RootNodeType>
1487 mRoot.setValueOnly(xyz, value);
1490template<
typename RootNodeType>
1491template<
typename AccessT>
1495 accessor.setValue(xyz, value);
1499template<
typename RootNodeType>
1503 mRoot.setActiveState(xyz,
true);
1507template<
typename RootNodeType>
1511 mRoot.setValueOn(xyz, value);
1515template<
typename RootNodeType>
1516template<
typename ModifyOp>
1520 mRoot.modifyValue(xyz, op);
1524template<
typename RootNodeType>
1525template<
typename ModifyOp>
1529 mRoot.modifyValueAndActiveState(xyz, op);
1533template<
typename RootNodeType>
1537 return mRoot.probeValue(xyz, value);
1544template<
typename RootNodeType>
1549 mRoot.addTile(level, xyz, value, active);
1553template<
typename RootNodeType>
1554template<
typename NodeT>
1563template<
typename RootNodeType>
1564inline typename RootNodeType::LeafNodeType*
1567 return mRoot.touchLeaf(xyz);
1571template<
typename RootNodeType>
1572inline typename RootNodeType::LeafNodeType*
1575 return mRoot.probeLeaf(xyz);
1579template<
typename RootNodeType>
1580inline const typename RootNodeType::LeafNodeType*
1583 return mRoot.probeConstLeaf(xyz);
1587template<
typename RootNodeType>
1588template<
typename NodeType>
1596template<
typename RootNodeType>
1597template<
typename NodeType>
1598inline const NodeType*
1605template<
typename RootNodeType>
1606template<
typename NodeType>
1607inline const NodeType*
1617template<
typename RootNodeType>
1622 return mRoot.clip(bbox);
1626template<
typename RootNodeType>
1634 if (!leaf->isAllocated()) {
1635 this->
addTile(0, leaf->origin(), this->background(),
false);
1640template<
typename RootNodeType>
1645 for (
auto it = this->
cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
1650template<
typename RootNodeType>
1655 return mRoot.sparseFill(bbox, value, active);
1659template<
typename RootNodeType>
1664 return mRoot.denseFill(bbox, value, active);
1668template<
typename RootNodeType>
1673 mRoot.voxelizeActiveTiles(threaded);
1677template<
typename RootNodeType>
1685 if (result->typeName() == MetadataT::staticTypeName()) {
1686 MetadataT* m =
static_cast<MetadataT*
>(result.get());
1687 m->value() =
mRoot.background();
1697template<
typename RootNodeType>
1714template<
typename RootNodeType>
1715template<
typename OtherRootNodeType>
1720 mRoot.topologyUnion(other.
root(), preserveTiles);
1723template<
typename RootNodeType>
1724template<
typename OtherRootNodeType>
1729 mRoot.topologyIntersection(other.
root());
1732template<
typename RootNodeType>
1733template<
typename OtherRootNodeType>
1746template<
typename AValueT,
typename CombineOp,
typename BValueT = AValueT>
1759template<
typename RootNodeType>
1760template<
typename CombineOp>
1771template<
typename RootNodeType>
1772template<
typename CombineOp>
1781template<
typename RootNodeType>
1782template<
typename ExtendedCombineOp>
1793template<
typename RootNodeType>
1794template<
typename ExtendedCombineOp>
1803template<
typename RootNodeType>
1804template<
typename CombineOp,
typename OtherTreeType>
1815template<
typename RootNodeType>
1816template<
typename CombineOp,
typename OtherTreeType>
1825template<
typename RootNodeType>
1826template<
typename ExtendedCombineOp,
typename OtherTreeType>
1829 ExtendedCombineOp& op,
bool prune)
1839template<
typename RootNodeType>
1840template<
typename ExtendedCombineOp,
typename OtherTreeType>
1843 const ExtendedCombineOp& op,
bool prune)
1853template<
typename RootNodeType>
1857 static std::string sTreeTypeName = []()
1860 std::vector<Index> dims;
1862 std::ostringstream ostr;
1864 for (
size_t i = 1, N = dims.size(); i < N; ++i) {
1865 ostr <<
"_" << dims[i];
1869 return sTreeTypeName;
1873template<
typename RootNodeType>
1874template<
typename OtherRootNodeType>
1878 return mRoot.hasSameTopology(other.
root());
1882template<
typename RootNodeType>
1888 if (this->
empty())
return false;
1890 mRoot.evalActiveBoundingBox(bbox,
false);
1892 return !bbox.
empty();
1895template<
typename RootNodeType>
1901 if (this->
empty())
return false;
1903 mRoot.evalActiveBoundingBox(bbox,
true);
1905 return !bbox.
empty();
1909template<
typename RootNodeType>
1920template<
typename RootNodeType>
1931template<
typename RootNodeType>
1936 RootNodeType::getNodeLog2Dims(dims);
1940template<
typename RootNodeType>
1944 if (verboseLevel <= 0)
return;
1948 std::streamsize savedPrecision;
1949 OnExit(std::ostream& _os): os(_os), savedPrecision(os.precision()) {}
1950 ~OnExit() { os.precision(savedPrecision); }
1952 OnExit restorePrecision(os);
1954 std::vector<Index> dims;
1957 os <<
"Information about Tree:\n"
1958 <<
" Type: " << this->
type() <<
"\n";
1960 os <<
" Configuration:\n";
1962 if (verboseLevel <= 1) {
1964 os <<
" Root(" <<
mRoot.getTableSize() <<
")";
1965 if (dims.size() > 1) {
1966 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
1967 os <<
", Internal(" << (1 << dims[i]) <<
"^3)";
1969 os <<
", Leaf(" << (1 << dims.back()) <<
"^3)\n";
1971 os <<
" Background value: " <<
mRoot.background() <<
"\n";
1978 if (verboseLevel > 3) {
1981 minVal = extrema.
min();
1982 maxVal = extrema.
max();
1993 os <<
" Root(1 x " <<
mRoot.getTableSize() <<
")";
1994 if (dims.size() >= 2) {
1995 for (
size_t i = 1, N = dims.size() - 1; i < N; ++i) {
1997 os <<
" x " << (1 << dims[i]) <<
"^3)";
2000 os <<
" x " << (1 << dims.back()) <<
"^3)\n";
2002 os <<
" Background value: " <<
mRoot.background() <<
"\n";
2006 if (verboseLevel > 3) {
2007 os <<
" Min value: " << minVal <<
"\n";
2008 os <<
" Max value: " << maxVal <<
"\n";
2021 if (numActiveVoxels) {
2025 totalVoxels = dim.
x() * uint64_t(dim.
y()) * dim.
z();
2027 os <<
" Bounding box of active voxels: " << bbox <<
"\n";
2028 os <<
" Dimensions of active voxels: "
2029 << dim[0] <<
" x " << dim[1] <<
" x " << dim[2] <<
"\n";
2031 const double activeRatio = (100.0 * double(numActiveVoxels)) /
double(totalVoxels);
2032 os <<
" Percentage of active voxels: " << std::setprecision(3) << activeRatio <<
"%\n";
2035 const double fillRatio = (100.0 * double(numActiveLeafVoxels))
2036 / (
double(
leafCount) *
double(LeafNodeType::NUM_VOXELS));
2037 os <<
" Average leaf node fill ratio: " << fillRatio <<
"%\n";
2040 if (verboseLevel > 2) {
2042 for (
auto it = this->
cbeginLeaf(); it; ++it)
if (!it->isAllocated()) ++sum;
2043 os <<
" Number of unallocated nodes: "
2045 << (100.0 * double(sum) / double(totalNodeCount)) <<
"%)\n";
2048 os <<
" Tree is empty!\n";
2052 if (verboseLevel == 2)
return;
2057 denseMem =
sizeof(
ValueType) * totalVoxels,
2058 voxelsMem =
sizeof(
ValueType) * numActiveLeafVoxels;
2061 os <<
"Memory footprint:\n";
2065 if (numActiveVoxels) {
2067 os <<
" Actual footprint is " << (100.0 * double(actualMem) / double(denseMem))
2068 <<
"% of an equivalent dense volume\n";
2069 os <<
" Leaf voxel footprint is " << (100.0 * double(voxelsMem) / double(actualMem))
2070 <<
"% of actual footprint\n";
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Functions to count tiles, nodes or voxels in a grid.
Internal table nodes for OpenVDB trees.
The root node of an OpenVDB tree.
ValueAccessors are designed to help accelerate accesses into the OpenVDB Tree structures by storing c...
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:640
const AValueType & result() const
Get the output value.
Definition Types.h:684
const BValueType & b() const
Get the B input value.
Definition Types.h:681
const AValueType & a() const
Get the A input value.
Definition Types.h:679
Definition Exceptions.h:61
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:754
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
Coord extents() const
Definition Coord.h:385
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition Coord.h:359
void reset()
Definition Coord.h:330
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Int32 y() const
Definition Coord.h:132
Int32 x() const
Definition Coord.h:131
Int32 z() const
Definition Coord.h:133
double min() const
Return the minimum value.
Definition Stats.h:122
double max() const
Return the maximum value.
Definition Stats.h:125
Templated class to compute the minimum and maximum values.
Definition Stats.h:32
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels)
Definition TreeIterator.h:1188
Base class for tree-traversal iterators over all nodes.
Definition TreeIterator.h:937
DenseIter< RootNode, MapIter, ChildType, ValueType > ChildAllIter
Definition RootNode.h:365
typename ChildType::LeafNodeType LeafNodeType
Definition RootNode.h:42
ChildIter< RootNode, MapIter, ChildOnPred, ChildType > ChildOnIter
Definition RootNode.h:361
ValueIter< const RootNode, MapCIter, ChildOffPred, ValueType > ChildOffCIter
Definition RootNode.h:364
static const Index LEVEL
Definition RootNode.h:46
typename ChildType::ValueType ValueType
Definition RootNode.h:43
typename ChildType::BuildType BuildType
Definition RootNode.h:44
DenseIter< const RootNode, MapCIter, const ChildType, const ValueType > ChildAllCIter
Definition RootNode.h:366
ValueIter< RootNode, MapIter, ChildOffPred, const ValueType > ChildOffIter
Definition RootNode.h:363
ChildIter< const RootNode, MapCIter, ChildOnPred, const ChildType > ChildOnCIter
Definition RootNode.h:362
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
virtual const Name & type() const =0
Return the name of this tree's type.
virtual Index64 unallocatedLeafCount() const =0
virtual ~TreeBase()=default
virtual Index64 activeLeafVoxelCount() const =0
Return the number of active voxels stored in leaf nodes.
virtual std::vector< Index64 > nodeCount() const =0
bool isType() const
Return true if this tree is of the same type as the template parameter.
Definition Tree.h:56
virtual Index64 leafCount() const =0
Return the number of leaf nodes.
virtual Metadata::Ptr getBackgroundValue() const
Return this tree's background value wrapped as metadata.
Definition Tree.h:66
virtual Index64 nonLeafCount() const =0
Return the number of non-leaf nodes.
virtual void print(std::ostream &os=std::cout, int verboseLevel=1) const
Print statistics, memory usage and other information about this tree.
Definition Tree.h:1094
virtual void getIndexRange(CoordBBox &bbox) const =0
virtual Index64 activeVoxelCount() const =0
Return the total number of active voxels.
virtual Index64 inactiveVoxelCount() const =0
Return the number of inactive voxels within the bounding box of all active voxels.
virtual void clipUnallocatedNodes()=0
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:129
virtual TreeBase::Ptr copy() const =0
Return a pointer to a deep copy of this tree.
SharedPtr< TreeBase > Ptr
Definition Tree.h:40
virtual bool evalLeafDim(Coord &dim) const =0
Return in dim the dimensions of the axis-aligned bounding box of all leaf nodes.
virtual bool evalActiveVoxelBoundingBox(CoordBBox &bbox) const =0
Return in bbox the axis-aligned bounding box of all active voxels and tiles.
virtual Index treeDepth() const =0
Return the depth of this tree.
virtual Index64 activeTileCount() const =0
Return the total number of active tiles.
SharedPtr< const TreeBase > ConstPtr
Definition Tree.h:41
virtual bool evalActiveVoxelDim(Coord &dim) const =0
Return in dim the dimensions of the axis-aligned bounding box of all active voxels....
virtual bool evalLeafBoundingBox(CoordBBox &bbox) const =0
Return in bbox the axis-aligned bounding box of all active tiles and leaf nodes with active values.
TreeBase & operator=(const TreeBase &)=delete
TreeBase(const TreeBase &)=default
Base class for tree-traversal iterators over tile and voxel values.
Definition TreeIterator.h:618
RootNodeType::ChildAllCIter beginRootDense() const
Return an iterator over all entries of the root node's table.
Definition Tree.h:964
Metadata::Ptr getBackgroundValue() const override
Return this tree's background value wrapped as metadata.
Definition Tree.h:1679
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:1446
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:1876
Index64 unallocatedLeafCount() const override
Return the total number of unallocated leaf nodes residing in this tree.
Definition Tree.h:1642
CIterT cbegin() const
Return a const iterator of type CIterT (for example, cbegin<ValueOnCIter>() is equivalent to cbeginVa...
bool evalActiveVoxelBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active voxels and tiles.
Definition Tree.h:1897
NodeT * stealNode(const Coord &xyz, const ValueType &value, bool active)
Return a pointer to the node of type NodeT that contains voxel (x, y, z) and replace it with a tile o...
Definition Tree.h:1556
void releaseAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition Tree.h:665
NodeType * probeNode(const Coord &xyz)
Return a pointer to the node of type NodeType that contains voxel (x, y, z). If no such node exists,...
Definition Tree.h:1590
const NodeType * probeNode(const Coord &xyz) const
Definition Tree.h:1599
void combine(Tree &other, CombineOp &op, bool prune=false)
Definition Tree.h:1762
const ValueType & getValue(const Coord &xyz, AccessT &) const
Return the value of the voxel at the given coordinates and update the given accessor's node cache.
void releaseAccessor(ValueAccessorBase< const Tree, false > &) const
Definition Tree.h:666
ConstAccessorRegistry mConstAccessorRegistry
Definition Tree.h:1056
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
Definition Tree.h:444
RootNodeType & root()
Definition Tree.h:280
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOffIter > ValueOffIter
Definition Tree.h:1000
Tree(const Tree &other)
Deep copy constructor.
Definition Tree.h:206
RootNodeType::ChildOffCIter cbeginRootTiles() const
Definition Tree.h:958
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOffCIter > ValueOffCIter
Definition Tree.h:1001
LeafCIter beginLeaf() const
Definition Tree.h:992
ValueAccessor< Tree, true > Accessor
Definition Tree.h:184
ValueOffCIter cbeginValueOff() const
Definition Tree.h:1019
Tree(const Tree< OtherRootType > &other)
Value conversion deep copy constructor.
Definition Tree.h:217
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Definition Tree.h:1581
IterT begin()
Return an iterator of type IterT (for example, begin<ValueOnIter>() is equivalent to beginValueOn()).
Definition Tree.h:1196
Index64 memUsage() const override
Return the total amount of memory in bytes occupied by this tree.
Definition Tree.h:361
void merge(Tree &other, MergePolicy=MERGE_ACTIVE_STATES)
Efficiently merge another tree into this tree using one of several schemes.
Definition Tree.h:1699
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueAllCIter > ValueAllCIter
Definition Tree.h:997
tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > > RootNodeType
Definition Tree.h:177
RootNodeType::ChildAllIter beginRootDense()
Definition Tree.h:966
Accessor getAccessor()
Return an accessor that provides random read and write access to this tree's voxels.
Definition Tree.h:1317
ValueAccessor< Tree, false > UnsafeAccessor
Definition Tree.h:186
LeafCIter cbeginLeaf() const
Definition Tree.h:993
LeafIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > LeafCIter
Definition Tree.h:979
const Name & type() const override
Return the name of this type of tree.
Definition Tree.h:273
static const Index DEPTH
Definition Tree.h:182
RootNodeType::ChildOffIter beginRootTiles()
Definition Tree.h:959
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition Tree.h:1269
static const Name & treeType()
Return the name of this type of tree.
Definition Tree.h:1855
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition Tree.h:1670
RootNodeType::ChildOnCIter beginRootChildren() const
Return an iterator over children of the root node.
Definition Tree.h:950
void combine(Tree &other, const CombineOp &op, bool prune=false)
Definition Tree.h:1774
bool operator!=(const Tree &) const
Definition Tree.h:276
Tree()
Definition Tree.h:201
AccessorRegistry mAccessorRegistry
Definition Tree.h:1055
void clip(const CoordBBox &)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition Tree.h:1619
ValueAccessor< const Tree, true > ConstAccessor
Definition Tree.h:185
RootNodeType mRoot
Definition Tree.h:1054
ValueAllCIter cbeginValueAll() const
Definition Tree.h:1007
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:498
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:1573
void topologyIntersection(const Tree< OtherRootNodeType > &other)
Intersects this tree's set of active values with the active values of the other tree,...
Definition Tree.h:1726
void releaseAccessor(ValueAccessorBase< Tree, true > &) const
Deregister an accessor so that it is no longer automatically cleared.
Definition Tree.h:1370
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:1565
RootNodeType::ChildOnIter beginRootChildren()
Definition Tree.h:952
Index64 leafCount() const override
Return the number of leaf nodes.
Definition Tree.h:338
ValueOnCIter beginValueOn() const
Definition Tree.h:1012
bool operator==(const Tree &) const
Definition Tree.h:275
SharedPtr< Tree > Ptr
Definition Tree.h:174
void attachAccessor(ValueAccessorBase< Tree, true > &) const
Register an accessor for this tree. Registered accessors are automatically cleared whenever one of th...
Definition Tree.h:1352
NodeIteratorBase< Tree, typename RootNodeType::ChildOnIter > NodeIter
Definition Tree.h:972
Index64 activeLeafVoxelCount() const override
Return the number of active voxels stored in leaf nodes.
Definition Tree.h:351
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition Tree.h:1527
ConstUnsafeAccessor getConstUnsafeAccessor()
Return an unsafe accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1345
void combine2Extended(const Tree &a, const OtherTreeType &b, const ExtendedCombineOp &, bool prune=false)
Definition Tree.h:1842
Index64 inactiveVoxelCount() const override
Return the number of inactive voxels within the bounding box of all active voxels.
Definition Tree.h:357
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:1485
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:611
Index64 activeVoxelCount() const override
Return the total number of active voxels.
Definition Tree.h:355
Index64 inactiveLeafVoxelCount() const override
Return the number of inactive voxels stored in leaf nodes.
Definition Tree.h:353
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Definition Tree.h:469
ValueOffCIter beginValueOff() const
Definition Tree.h:1018
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:509
TreeValueIteratorBase< Tree, typename RootNodeType::ValueAllIter > ValueAllIter
Definition Tree.h:996
RootNodeType::ChildOffCIter beginRootTiles() const
Return an iterator over non-child entries of the root node's table.
Definition Tree.h:957
void combineExtended(Tree &other, ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1784
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition Tree.h:1462
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:1546
void releaseAccessor(ValueAccessorBase< const Tree, true > &) const
Definition Tree.h:1378
bool probeValue(const Coord &xyz, ValueType &value) const
Get the value of the voxel at the given coordinates.
Definition Tree.h:1535
TreeValueIteratorBase< const Tree, typename RootNodeType::ValueOnCIter > ValueOnCIter
Definition Tree.h:999
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:1470
ValueOnIter beginValueOn()
Return an iterator over active values (tile and voxel) across all nodes.
Definition Tree.h:1011
void topologyDifference(const Tree< OtherRootNodeType > &other)
Difference this tree's set of active values with the active values of the other tree,...
Definition Tree.h:1735
void releaseAllAccessors()
typename RootNodeType::BuildType BuildType
Definition Tree.h:179
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:1478
void combine2Extended(const Tree &a, const OtherTreeType &b, ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1828
Index64 activeTileCount() const override
Return the total number of active tiles.
Definition Tree.h:359
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition Tree.h:1454
tbb::concurrent_hash_map< ValueAccessorBase< const Tree, true > *, bool > ConstAccessorRegistry
Definition Tree.h:1032
ValueOnCIter cbeginValueOn() const
Definition Tree.h:1013
TreeBase::Ptr copy() const override
Return a pointer to a deep copy of this tree.
Definition Tree.h:265
typename RootNodeType::ValueType ValueType
Definition Tree.h:178
void attachAccessor(ValueAccessorBase< Tree, false > &) const
Dummy implementations.
Definition Tree.h:653
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition Tree.h:1429
const LeafNodeType * probeLeaf(const Coord &xyz) const
Definition Tree.h:544
void print(std::ostream &os=std::cout, int verboseLevel=1) const override
Print statistics, memory usage and other information about this tree.
Definition Tree.h:1942
void combineExtended(Tree &other, const ExtendedCombineOp &op, bool prune=false)
Definition Tree.h:1796
void attachAccessor(ValueAccessorBase< const Tree, false > &) const
Definition Tree.h:654
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this tree's voxels.
Definition Tree.h:1324
void combine2(const Tree &a, const OtherTreeType &b, const CombineOp &op, bool prune=false)
Definition Tree.h:1818
NodeCIter beginNode() const
Definition Tree.h:985
ValueAccessor< const Tree, false > ConstUnsafeAccessor
Definition Tree.h:187
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:1518
LeafIteratorBase< Tree, typename RootNodeType::ChildOnIter > LeafIter
Definition Tree.h:978
SharedPtr< const Tree > ConstPtr
Definition Tree.h:175
Tree(const OtherTreeType &other, const ValueType &background, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition Tree.h:253
RootNodeType::ChildAllCIter cbeginRootDense() const
Definition Tree.h:965
void getNodes(ArrayT &array) const
Definition Tree.h:1281
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition Tree.h:1661
bool evalLeafBoundingBox(CoordBBox &bbox) const override
Return in bbox the axis-aligned bounding box of all active tiles and leaf nodes with active values.
Definition Tree.h:1884
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Definition Tree.h:600
bool evalLeafDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all leaf nodes.
Definition Tree.h:1922
RootNodeType::ChildOnCIter cbeginRootChildren() const
Definition Tree.h:951
void setValue(const Coord &xyz, const ValueType &value, AccessT &)
Set the value of the voxel at the given coordinates, mark the voxel as active, and update the given a...
Definition Tree.h:1493
std::vector< Index64 > nodeCount() const override
Definition Tree.h:342
NodeCIter cbeginNode() const
Definition Tree.h:986
const ValueType & background() const
Definition Tree.h:678
NodeIteratorBase< const Tree, typename RootNodeType::ChildOnCIter > NodeCIter
Definition Tree.h:973
Tree & operator=(const Tree &)=delete
static void getNodeLog2Dims(std::vector< Index > &dims)
Traverse the type hierarchy of nodes, and return, in dims, a list of the Log2Dims of nodes in order f...
Definition Tree.h:1933
ValueOffIter beginValueOff()
Return an iterator over inactive values (tile and voxel) across all nodes.
Definition Tree.h:1017
void getIndexRange(CoordBBox &bbox) const override
Min and max are both inclusive.
Definition Tree.h:681
void attachAccessor(ValueAccessorBase< const Tree, true > &) const
Definition Tree.h:1361
typename RootNodeType::LeafNodeType LeafNodeType
Definition Tree.h:180
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1338
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition Tree.h:1501
LeafIter beginLeaf()
Return an iterator over all leaf nodes in this tree.
Definition Tree.h:991
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition Tree.h:1652
Tree(const OtherTreeType &other, const ValueType &inactiveValue, const ValueType &activeValue, TopologyCopy)
Topology copy constructor from a tree of a different type.
Definition Tree.h:232
bool evalActiveVoxelDim(Coord &dim) const override
Return in dim the dimensions of the axis-aligned bounding box of all active voxels....
Definition Tree.h:1911
~Tree() override
Definition Tree.h:262
const NodeType * probeConstNode(const Coord &xyz) const
Definition Tree.h:1608
bool hasActiveTiles() const
Return true if this tree has any active tiles.
Definition Tree.h:448
Tree(const ValueType &background)
Empty tree constructor.
Definition Tree.h:260
void clipUnallocatedNodes() override
Replace with background tiles any nodes whose voxel buffers have not yet been allocated.
Definition Tree.h:1628
void setValueOn(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition Tree.h:1509
bool isValueOff(const Coord &xyz) const
Return true if the value at the given coordinates is inactive.
Definition Tree.h:446
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:598
void topologyUnion(const Tree< OtherRootNodeType > &other, const bool preserveTiles=false)
Union this tree's set of active values with the active values of the other tree, whose ValueType may ...
Definition Tree.h:1717
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
Definition Tree.h:268
void combine2(const Tree &a, const OtherTreeType &b, CombineOp &op, bool prune=false)
Definition Tree.h:1806
Index treeDepth() const override
Return the depth of this tree.
Definition Tree.h:336
const RootNodeType & root() const
Definition Tree.h:281
ValueAllCIter beginValueAll() const
Definition Tree.h:1006
NodeIter beginNode()
Return an iterator over all nodes in this tree.
Definition Tree.h:984
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this tree's voxels.
Definition Tree.h:1331
Index64 nonLeafCount() const override
Return the number of non-leaf nodes.
Definition Tree.h:349
tbb::concurrent_hash_map< ValueAccessorBase< Tree, true > *, bool > AccessorRegistry
Definition Tree.h:1031
ValueAllIter beginValueAll()
Return an iterator over all values (tile and voxel) across all nodes.
Definition Tree.h:1005
TreeValueIteratorBase< Tree, typename RootNodeType::ValueOnIter > ValueOnIter
Definition Tree.h:998
This base class for ValueAccessors manages registration of an accessor with a tree so that the tree c...
Definition ValueAccessor.h:152
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition logging.h:163
Definition PointDataGrid.h:48
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels > > ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
Definition ValueAccessor.h:86
FormattedInt< IntT > formattedInt(IntT n)
Definition Formats.h:118
int printBytes(std::ostream &os, uint64_t bytes, const std::string &head="", const std::string &tail="\n", bool exact=false, int width=8, int precision=3)
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:34
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:71
uint64_t Index64
Definition Types.h:33
std::shared_ptr< T > SharedPtr
Definition Types.h:95
MergePolicy
Definition Types.h:577
@ MERGE_ACTIVE_STATES
Definition Types.h:578
@ MERGE_NODES
Definition Types.h:579
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:580
const char * typeNameAsString()
Definition Types.h:587
Definition Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Helper class to adapt a three-argument (a, b, result) CombineOp functor into a single-argument functo...
Definition Tree.h:1748
void operator()(CombineArgs< AValueT, BValueT > &args) const
Definition Tree.h:1751
CombineOpAdapter(CombineOp &_op)
Definition Tree.h:1749
CombineOp & op
Definition Tree.h:1755
Tree3<T, N1, N2>::Type is the type of a three-level tree (Root, Internal, Leaf) with value type T and...
Definition Tree.h:1065
Tree< RootNode< InternalNode< LeafNode< T, N2 >, N1 > > > Type
Definition Tree.h:1066
Tree4<T, N1, N2, N3>::Type is the type of a four-level tree (Root, Internal, Internal,...
Definition Tree.h:1075
Tree< RootNode< InternalNode< InternalNode< LeafNode< bool, N3 >, N2 >, N1 > > > Type
Definition Tree.h:1076
Tree5<T, N1, N2, N3, N4>::Type is the type of a five-level tree (Root, Internal, Internal,...
Definition Tree.h:1084
Tree< RootNode< InternalNode< InternalNode< InternalNode< LeafNode< T, N4 >, N3 >, N2 >, N1 > > > Type
Definition Tree.h:1085
static TreeT::LeafCIter begin(const TreeT &tree)
Definition Tree.h:1165
static TreeT::LeafIter begin(TreeT &tree)
Definition Tree.h:1161
static TreeT::NodeCIter begin(const TreeT &tree)
Definition Tree.h:1157
static TreeT::NodeIter begin(TreeT &tree)
Definition Tree.h:1153
static TreeT::RootNodeType::ChildAllCIter begin(const TreeT &tree)
Definition Tree.h:1147
static TreeT::RootNodeType::ChildAllIter begin(TreeT &tree)
Definition Tree.h:1141
static TreeT::RootNodeType::ChildOffCIter begin(const TreeT &tree)
Definition Tree.h:1135
static TreeT::RootNodeType::ChildOffIter begin(TreeT &tree)
Definition Tree.h:1129
static TreeT::RootNodeType::ChildOnCIter begin(const TreeT &tree)
Definition Tree.h:1123
static TreeT::RootNodeType::ChildOnIter begin(TreeT &tree)
Definition Tree.h:1117
static TreeT::ValueAllCIter begin(const TreeT &tree)
Definition Tree.h:1189
static TreeT::ValueAllIter begin(TreeT &tree)
Definition Tree.h:1185
static TreeT::ValueOffCIter begin(const TreeT &tree)
Definition Tree.h:1181
static TreeT::ValueOffIter begin(TreeT &tree)
Definition Tree.h:1177
static TreeT::ValueOnCIter begin(const TreeT &tree)
Definition Tree.h:1173
static TreeT::ValueOnIter begin(TreeT &tree)
Definition Tree.h:1169
TreeIterTraits provides, for all tree iterators, a begin(tree) function that returns an iterator over...
Definition Tree.h:1114
DeallocateNodes(std::vector< NodeType * > &nodes)
Definition Tree.h:1041
NodeType **const mNodes
Definition Tree.h:1048
void operator()(const tbb::blocked_range< size_t > &range) const
Definition Tree.h:1043
ValueConverter<T>::Type is the type of a tree having the same hierarchy as this tree but a different ...
Definition Tree.h:196
Tree< typename RootNodeType::template ValueConverter< OtherValueType >::Type > Type
Definition Tree.h:197
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:291