OpenVDB 14.0.0
Loading...
Searching...
No Matches
Tree.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @file tree/Tree.h
5
6#ifndef OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
7#define OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
8
9#include <openvdb/Types.h>
10#include <openvdb/Metadata.h>
11#include <openvdb/math/Math.h>
12#include <openvdb/math/BBox.h>
13#include <openvdb/tools/Count.h> // tools::countActiveVoxels(), tools::memUsage(), tools::minMax()
16#include <openvdb/util/Assert.h>
17#include <openvdb/Platform.h>
18#include "RootNode.h"
19#include "InternalNode.h"
20#include "LeafNode.h"
21#include "TreeIterator.h"
22#include "ValueAccessor.h"
23#include <tbb/concurrent_hash_map.h>
24#include <cstdint>
25#include <iostream>
26#include <mutex>
27#include <sstream>
28#include <vector>
29
30
31namespace openvdb {
33namespace OPENVDB_VERSION_NAME {
34namespace tree {
35
36/// @brief Base class for typed trees
38{
39public:
42
43 TreeBase() = default;
44 TreeBase(const TreeBase&) = default;
45 TreeBase& operator=(const TreeBase&) = delete; // disallow assignment
46 virtual ~TreeBase() = default;
47
48 /// Return the name of this tree's type.
49 virtual const Name& type() const = 0;
50
51 /// Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
52 virtual Name valueType() const = 0;
53
54 /// Return @c true if this tree is of the same type as the template parameter.
55 template<typename TreeType>
56 bool isType() const { return (this->type() == TreeType::treeType()); }
57
58 /// Return a pointer to a deep copy of this tree
59 virtual TreeBase::Ptr copy() const = 0;
60
61 //
62 // Tree methods
63 //
64 /// @brief Return this tree's background value wrapped as metadata.
65 /// @note Query the metadata object for the value's type.
66 virtual Metadata::Ptr getBackgroundValue() const { return Metadata::Ptr(); }
67
68 /// @brief Return in @a bbox the axis-aligned bounding box of all
69 /// active tiles and leaf nodes with active values.
70 /// @details This is faster than calling evalActiveVoxelBoundingBox,
71 /// which visits the individual active voxels, and hence
72 /// evalLeafBoundingBox produces a less tight, i.e. approximate, bbox.
73 /// @return @c false if the bounding box is empty (in which case
74 /// the bbox is set to its default value).
75 virtual bool evalLeafBoundingBox(CoordBBox& bbox) const = 0;
76
77 /// @brief Return in @a dim the dimensions of the axis-aligned bounding box
78 /// of all leaf nodes.
79 /// @return @c false if the bounding box is empty.
80 virtual bool evalLeafDim(Coord& dim) const = 0;
81
82 /// @brief Return in @a bbox the axis-aligned bounding box of all
83 /// active voxels and tiles.
84 /// @details This method produces a more accurate, i.e. tighter,
85 /// bounding box than evalLeafBoundingBox which is approximate but
86 /// faster.
87 /// @return @c false if the bounding box is empty (in which case
88 /// the bbox is set to its default value).
89 virtual bool evalActiveVoxelBoundingBox(CoordBBox& bbox) const = 0;
90
91 /// @brief Return in @a dim the dimensions of the axis-aligned bounding box of all
92 /// active voxels. This is a tighter bounding box than the leaf node bounding box.
93 /// @return @c false if the bounding box is empty.
94 virtual bool evalActiveVoxelDim(Coord& dim) const = 0;
95
96 virtual void getIndexRange(CoordBBox& bbox) const = 0;
97
98 virtual void clipUnallocatedNodes() = 0;
99 virtual Index64 unallocatedLeafCount() const = 0;
100
101
102 //
103 // Statistics
104 //
105 /// @brief Return the depth of this tree.
106 ///
107 /// A tree with only a root node and leaf nodes has depth 2, for example.
108 virtual Index treeDepth() const = 0;
109 /// Return the number of leaf nodes.
110 virtual Index64 leafCount() const = 0;
111 /// Return a vector with node counts. The number of nodes of type NodeType
112 /// is given as element NodeType::LEVEL in the return vector. Thus, the size
113 /// of this vector corresponds to the height (or depth) of this tree.
114 virtual std::vector<Index64> nodeCount() const = 0;
115 /// Return the number of non-leaf nodes.
116 virtual Index64 nonLeafCount() const = 0;
117 /// Return the number of active voxels stored in leaf nodes.
118 virtual Index64 activeLeafVoxelCount() const = 0;
119 /// Return the number of inactive voxels stored in leaf nodes.
120 virtual Index64 inactiveLeafVoxelCount() const = 0;
121 /// Return the total number of active voxels.
122 virtual Index64 activeVoxelCount() const = 0;
123 /// Return the number of inactive voxels within the bounding box of all active voxels.
124 virtual Index64 inactiveVoxelCount() const = 0;
125 /// Return the total number of active tiles.
126 virtual Index64 activeTileCount() const = 0;
127
128 /// Return the total amount of memory in bytes occupied by this tree.
129 virtual Index64 memUsage() const { return 0; }
130
131#if OPENVDB_ABI_VERSION_NUMBER < 14
132 //
133 // I/O methods
134 //
135 /// @brief Read the tree topology from a stream.
136 ///
137 /// This will read the tree structure and tile values, but not voxel data.
138 virtual void readTopology(std::istream&, bool saveFloatAsHalf = false) = 0;
139 /// @brief Write the tree topology to a stream.
140 ///
141 /// This will write the tree structure and tile values, but not voxel data.
142 virtual void writeTopology(std::ostream&, bool saveFloatAsHalf = false) const = 0;
143
144 /// Read all data buffers for this tree.
145 virtual void readBuffers(std::istream&, bool saveFloatAsHalf = false) = 0;
146 /// Read all of this tree's data buffers that intersect the given bounding box.
147 virtual void readBuffers(std::istream&, const CoordBBox&, bool saveFloatAsHalf = false) = 0;
148
149 OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
150 virtual void readNonresidentBuffers() const = 0;
151
152 /// Write out all the data buffers for this tree.
153 virtual void writeBuffers(std::ostream&, bool saveFloatAsHalf = false) const = 0;
154#endif
155
156 /// @brief Print statistics, memory usage and other information about this tree.
157 /// @param os a stream to which to write textual information
158 /// @param verboseLevel 1: print tree configuration only;
159 /// 2: include node and voxel statistics;
160 /// 3: include memory usage;
161 /// 4: include minimum and maximum voxel values
162 /// @warning @a verboseLevel 4 forces loading of any unallocated nodes.
163 virtual void print(std::ostream& os = std::cout, int verboseLevel = 1) const;
164};
165
166
167////////////////////////////////////////
168
169
170template<typename _RootNodeType>
171class Tree: public TreeBase
172{
173public:
176
177 using RootNodeType = _RootNodeType;
181
182 static const Index DEPTH = RootNodeType::LEVEL + 1;
183
188
189 /// @brief ValueConverter<T>::Type is the type of a tree having the same
190 /// hierarchy as this tree but a different value type, T.
191 ///
192 /// For example, FloatTree::ValueConverter<double>::Type is equivalent to DoubleTree.
193 /// @note If the source tree type is a template argument, it might be necessary
194 /// to write "typename SourceTree::template ValueConverter<T>::Type".
195 template<typename OtherValueType>
199
200
201 Tree() {}
202
203 Tree& operator=(const Tree&) = delete; // disallow assignment
204
205 /// Deep copy constructor
206 Tree(const Tree& other): TreeBase(other), mRoot(other.mRoot)
207 {
208 }
209
210 /// @brief Value conversion deep copy constructor
211 ///
212 /// Deep copy a tree of the same configuration as this tree type but a different
213 /// ValueType, casting the other tree's values to this tree's ValueType.
214 /// @throw TypeError if the other tree's configuration doesn't match this tree's
215 /// or if this tree's ValueType is not constructible from the other tree's ValueType.
216 template<typename OtherRootType>
217 explicit Tree(const Tree<OtherRootType>& other): TreeBase(other), mRoot(other.root())
218 {
219 }
220
221 /// @brief Topology copy constructor from a tree of a different type
222 ///
223 /// Copy the structure, i.e., the active states of tiles and voxels, of another
224 /// tree of a possibly different type, but don't copy any tile or voxel values.
225 /// Instead, initialize tiles and voxels with the given active and inactive values.
226 /// @param other a tree having (possibly) a different ValueType
227 /// @param inactiveValue background value for this tree, and the value to which
228 /// all inactive tiles and voxels are initialized
229 /// @param activeValue value to which active tiles and voxels are initialized
230 /// @throw TypeError if the other tree's configuration doesn't match this tree's.
231 template<typename OtherTreeType>
232 Tree(const OtherTreeType& other,
233 const ValueType& inactiveValue,
234 const ValueType& activeValue,
236 TreeBase(other),
237 mRoot(other.root(), inactiveValue, activeValue, TopologyCopy())
238 {
239 }
240
241 /// @brief Topology copy constructor from a tree of a different type
242 ///
243 /// @note This topology copy constructor is generally faster than
244 /// the one that takes both a foreground and a background value.
245 ///
246 /// Copy the structure, i.e., the active states of tiles and voxels, of another
247 /// tree of a possibly different type, but don't copy any tile or voxel values.
248 /// Instead, initialize tiles and voxels with the given background value.
249 /// @param other a tree having (possibly) a different ValueType
250 /// @param background the value to which tiles and voxels are initialized
251 /// @throw TypeError if the other tree's configuration doesn't match this tree's.
252 template<typename OtherTreeType>
253 Tree(const OtherTreeType& other, const ValueType& background, TopologyCopy):
254 TreeBase(other),
255 mRoot(other.root(), background, TopologyCopy())
256 {
257 }
258
259 /// Empty tree constructor
261
262 ~Tree() override { this->clear(); releaseAllAccessors(); }
263
264 /// Return a pointer to a deep copy of this tree
265 TreeBase::Ptr copy() const override { return TreeBase::Ptr(new Tree(*this)); }
266
267 /// Return the name of the type of a voxel's value (e.g., "float" or "vec3d")
268 Name valueType() const override { return typeNameAsString<ValueType>(); }
269
270 /// Return the name of this type of tree.
271 static const Name& treeType();
272 /// Return the name of this type of tree.
273 const Name& type() const override { return this->treeType(); }
274
277
278 //@{
279 /// Return this tree's root node.
280 RootNodeType& root() { return mRoot; }
281 const RootNodeType& root() const { return mRoot; }
282 //@}
283
284
285 //
286 // Tree methods
287 //
288 /// @brief Return @c true if the given tree has the same node and active value
289 /// topology as this tree, whether or not it has the same @c ValueType.
290 template<typename OtherRootNodeType>
291 bool hasSameTopology(const Tree<OtherRootNodeType>& other) const;
292
293 bool evalLeafBoundingBox(CoordBBox& bbox) const override;
294 bool evalActiveVoxelBoundingBox(CoordBBox& bbox) const override;
295 bool evalActiveVoxelDim(Coord& dim) const override;
296 bool evalLeafDim(Coord& dim) const override;
297
298 /// @brief Traverse the type hierarchy of nodes, and return, in @a dims, a list
299 /// of the Log2Dims of nodes in order from RootNode to LeafNode.
300 /// @note Because RootNodes are resizable, the RootNode Log2Dim is 0 for all trees.
301 static void getNodeLog2Dims(std::vector<Index>& dims);
302
303#if OPENVDB_ABI_VERSION_NUMBER < 14
304 //
305 // I/O methods
306 //
307 /// @brief Read the tree topology from a stream.
308 ///
309 /// This will read the tree structure and tile values, but not voxel data.
310 void readTopology(std::istream&, bool saveFloatAsHalf = false) override;
311 /// @brief Write the tree topology to a stream.
312 ///
313 /// This will write the tree structure and tile values, but not voxel data.
314 void writeTopology(std::ostream&, bool saveFloatAsHalf = false) const override;
315 /// Read all data buffers for this tree.
316 void readBuffers(std::istream&, bool saveFloatAsHalf = false) override;
317 /// Read all of this tree's data buffers that intersect the given bounding box.
318 void readBuffers(std::istream&, const CoordBBox&, bool saveFloatAsHalf = false) override;
319
320 OPENVDB_DEPRECATED_MESSAGE("This method is deprecated and will be removed. Delayed loading is no longer supported.")
321 void readNonresidentBuffers() const override { }
322
323 /// Write out all data buffers for this tree.
324 void writeBuffers(std::ostream&, bool saveFloatAsHalf = false) const override;
325#endif // OPENVDB_ABI_VERSION_NUMBER < 14
326
327 void print(std::ostream& os = std::cout, int verboseLevel = 1) const override;
328
329
330 //
331 // Statistics
332 //
333 /// @brief Return the depth of this tree.
334 ///
335 /// A tree with only a root node and leaf nodes has depth 2, for example.
336 Index treeDepth() const override { return DEPTH; }
337 /// Return the number of leaf nodes.
338 Index64 leafCount() const override { return mRoot.leafCount(); }
339 /// Return a vector with node counts. The number of nodes of type NodeType
340 /// is given as element NodeType::LEVEL in the return vector. Thus, the size
341 /// of this vector corresponds to the height (or depth) of this tree.
342 std::vector<Index64> nodeCount() const override
343 {
344 std::vector<Index64> vec(DEPTH, 0);
345 mRoot.nodeCount( vec );
346 return vec;// Named Return Value Optimization
347 }
348 /// Return the number of non-leaf nodes.
349 Index64 nonLeafCount() const override { return mRoot.nonLeafCount(); }
350 /// Return the number of active voxels stored in leaf nodes.
352 /// Return the number of inactive voxels stored in leaf nodes.
354 /// Return the total number of active voxels.
355 Index64 activeVoxelCount() const override { return tools::countActiveVoxels(*this); }
356 /// Return the number of inactive voxels within the bounding box of all active voxels.
357 Index64 inactiveVoxelCount() const override { return tools::countInactiveVoxels(*this); }
358 /// Return the total number of active tiles.
359 Index64 activeTileCount() const override { return tools::countActiveTiles(*this); }
360
361 Index64 memUsage() const override { return tools::memUsage(*this); }
362
363
364 //
365 // Voxel access methods (using signed indexing)
366 //
367 /// Return the value of the voxel at the given coordinates.
368 const ValueType& getValue(const Coord& xyz) const;
369 /// @brief Return the value of the voxel at the given coordinates
370 /// and update the given accessor's node cache.
371 template<typename AccessT> const ValueType& getValue(const Coord& xyz, AccessT&) const;
372
373 /// @brief Return the tree depth (0 = root) at which the value of voxel (x, y, z) resides.
374 /// @details If (x, y, z) isn't explicitly represented in the tree (i.e., it is
375 /// implicitly a background voxel), return -1.
376 int getValueDepth(const Coord& xyz) const;
377
378 /// Set the active state of the voxel at the given coordinates but don't change its value.
379 void setActiveState(const Coord& xyz, bool on);
380 /// Set the value of the voxel at the given coordinates but don't change its active state.
381 void setValueOnly(const Coord& xyz, const ValueType& value);
382 /// Mark the voxel at the given coordinates as active but don't change its value.
383 void setValueOn(const Coord& xyz);
384 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
385 void setValueOn(const Coord& xyz, const ValueType& value);
386 /// Set the value of the voxel at the given coordinates and mark the voxel as active.
387 void setValue(const Coord& xyz, const ValueType& value);
388 /// @brief Set the value of the voxel at the given coordinates, mark the voxel as active,
389 /// and update the given accessor's node cache.
390 template<typename AccessT> void setValue(const Coord& xyz, const ValueType& value, AccessT&);
391 /// Mark the voxel at the given coordinates as inactive but don't change its value.
392 void setValueOff(const Coord& xyz);
393 /// Set the value of the voxel at the given coordinates and mark the voxel as inactive.
394 void setValueOff(const Coord& xyz, const ValueType& value);
395
396 /// @brief Apply a functor to the value of the voxel at the given coordinates
397 /// and mark the voxel as active.
398 /// @details Provided that the functor can be inlined, this is typically
399 /// significantly faster than calling getValue() followed by setValueOn().
400 /// @param xyz the coordinates of a voxel whose value is to be modified
401 /// @param op a functor of the form <tt>void op(ValueType&) const</tt> that modifies
402 /// its argument in place
403 /// @par Example:
404 /// @code
405 /// Coord xyz(1, 0, -2);
406 /// // Multiply the value of a voxel by a constant and mark the voxel as active.
407 /// floatTree.modifyValue(xyz, [](float& f) { f *= 0.25; }); // C++11
408 /// // Set the value of a voxel to the maximum of its current value and 0.25,
409 /// // and mark the voxel as active.
410 /// floatTree.modifyValue(xyz, [](float& f) { f = std::max(f, 0.25f); }); // C++11
411 /// @endcode
412 /// @note The functor is not guaranteed to be called only once.
413 /// @see tools::foreach()
414 template<typename ModifyOp>
415 void modifyValue(const Coord& xyz, const ModifyOp& op);
416
417 /// @brief Apply a functor to the voxel at the given coordinates.
418 /// @details Provided that the functor can be inlined, this is typically
419 /// significantly faster than calling getValue() followed by setValue().
420 /// @param xyz the coordinates of a voxel to be modified
421 /// @param op a functor of the form <tt>void op(ValueType&, bool&) const</tt> that
422 /// modifies its arguments, a voxel's value and active state, in place
423 /// @par Example:
424 /// @code
425 /// Coord xyz(1, 0, -2);
426 /// // Multiply the value of a voxel by a constant and mark the voxel as inactive.
427 /// floatTree.modifyValueAndActiveState(xyz,
428 /// [](float& f, bool& b) { f *= 0.25; b = false; }); // C++11
429 /// // Set the value of a voxel to the maximum of its current value and 0.25,
430 /// // but don't change the voxel's active state.
431 /// floatTree.modifyValueAndActiveState(xyz,
432 /// [](float& f, bool&) { f = std::max(f, 0.25f); }); // C++11
433 /// @endcode
434 /// @note The functor is not guaranteed to be called only once.
435 /// @see tools::foreach()
436 template<typename ModifyOp>
437 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
438
439 /// @brief Get the value of the voxel at the given coordinates.
440 /// @return @c true if the value is active.
441 bool probeValue(const Coord& xyz, ValueType& value) const;
442
443 /// Return @c true if the value at the given coordinates is active.
444 bool isValueOn(const Coord& xyz) const { return mRoot.isValueOn(xyz); }
445 /// Return @c true if the value at the given coordinates is inactive.
446 bool isValueOff(const Coord& xyz) const { return !this->isValueOn(xyz); }
447 /// Return @c true if this tree has any active tiles.
448 bool hasActiveTiles() const { return mRoot.hasActiveTiles(); }
449
450 /// Set all voxels that lie outside the given axis-aligned box to the background.
451 void clip(const CoordBBox&);
452 /// @brief Replace with background tiles any nodes whose voxel buffers
453 /// have not yet been allocated.
454 void clipUnallocatedNodes() override;
455
456 /// Return the total number of unallocated leaf nodes residing in this tree.
458
459 //@{
460 /// @brief Set all voxels within a given axis-aligned box to a constant value.
461 /// @param bbox inclusive coordinates of opposite corners of an axis-aligned box
462 /// @param value the value to which to set voxels within the box
463 /// @param active if true, mark voxels within the box as active,
464 /// otherwise mark them as inactive
465 /// @note This operation generates a sparse, but not always optimally sparse,
466 /// representation of the filled box. Follow fill operations with a prune()
467 /// operation for optimal sparseness.
468 void sparseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
469 void fill(const CoordBBox& bbox, const ValueType& value, bool active = true)
470 {
471 this->sparseFill(bbox, value, active);
472 }
473 //@}
474
475 /// @brief Set all voxels within a given axis-aligned box to a constant value
476 /// and ensure that those voxels are all represented at the leaf level.
477 /// @param bbox inclusive coordinates of opposite corners of an axis-aligned box.
478 /// @param value the value to which to set voxels within the box.
479 /// @param active if true, mark voxels within the box as active,
480 /// otherwise mark them as inactive.
481 /// @sa voxelizeActiveTiles()
482 void denseFill(const CoordBBox& bbox, const ValueType& value, bool active = true);
483
484 /// @brief Densify active tiles, i.e., replace them with leaf-level active voxels.
485 ///
486 /// @param threaded if true, this operation is multi-threaded (over the internal nodes).
487 ///
488 /// @warning This method can explode the tree's memory footprint, especially if it
489 /// contains active tiles at the upper levels (in particular the root level)!
490 ///
491 /// @sa denseFill()
492 void voxelizeActiveTiles(bool threaded = true);
493
494 /// @brief Reduce the memory footprint of this tree by replacing with tiles
495 /// any nodes whose values are all the same (optionally to within a tolerance)
496 /// and have the same active state.
497 /// @warning Will soon be deprecated!
498 void prune(const ValueType& tolerance = zeroVal<ValueType>())
499 {
500 this->clearAllAccessors();
501 mRoot.prune(tolerance);
502 }
503
504 /// @brief Add the given leaf node to this tree, creating a new branch if necessary.
505 /// If a leaf node with the same origin already exists, replace it.
506 ///
507 /// @warning Ownership of the leaf is transferred to the tree so
508 /// the client code should not attempt to delete the leaf pointer!
509 void addLeaf(LeafNodeType* leaf) { OPENVDB_ASSERT(leaf); mRoot.addLeaf(leaf); }
510
511 /// @brief Add a tile containing voxel (x, y, z) at the specified tree level,
512 /// creating a new branch if necessary. Delete any existing lower-level nodes
513 /// that contain (x, y, z).
514 /// @note @a level must be less than this tree's depth.
515 void addTile(Index level, const Coord& xyz, const ValueType& value, bool active);
516
517 /// @brief Return a pointer to the node of type @c NodeT that contains voxel (x, y, z)
518 /// and replace it with a tile of the specified value and state.
519 /// If no such node exists, leave the tree unchanged and return @c nullptr.
520 /// @note The caller takes ownership of the node and is responsible for deleting it.
521 template<typename NodeT>
522 NodeT* stealNode(const Coord& xyz, const ValueType& value, bool active);
523
524 /// @brief Return a pointer to the leaf node that contains voxel (x, y, z).
525 /// If no such node exists, create one that preserves the values and
526 /// active states of all voxels.
527 /// @details Use this method to preallocate a static tree topology over which to
528 /// safely perform multithreaded processing.
530
531 //@{
532 /// @brief Return a pointer to the node of type @c NodeType that contains
533 /// voxel (x, y, z). If no such node exists, return @c nullptr.
534 template<typename NodeType> NodeType* probeNode(const Coord& xyz);
535 template<typename NodeType> const NodeType* probeConstNode(const Coord& xyz) const;
536 template<typename NodeType> const NodeType* probeNode(const Coord& xyz) const;
537 //@}
538
539 //@{
540 /// @brief Return a pointer to the leaf node that contains voxel (x, y, z).
541 /// If no such node exists, return @c nullptr.
543 const LeafNodeType* probeConstLeaf(const Coord& xyz) const;
544 const LeafNodeType* probeLeaf(const Coord& xyz) const { return this->probeConstLeaf(xyz); }
545 //@}
546
547 //@{
548 /// @brief Adds all nodes of a certain type to a container with the following API:
549 /// @code
550 /// struct ArrayT {
551 /// using value_type = ...; // the type of node to be added to the array
552 /// void push_back(value_type nodePtr); // add a node to the array
553 /// };
554 /// @endcode
555 /// @details An example of a wrapper around a c-style array is:
556 /// @code
557 /// struct MyArray {
558 /// using value_type = LeafType*;
559 /// value_type* ptr;
560 /// MyArray(value_type* array) : ptr(array) {}
561 /// void push_back(value_type leaf) { *ptr++ = leaf; }
562 ///};
563 /// @endcode
564 /// @details An example that constructs a list of pointer to all leaf nodes is:
565 /// @code
566 /// std::vector<const LeafNodeType*> array;//most std contains have the required API
567 /// array.reserve(tree.leafCount());//this is a fast preallocation.
568 /// tree.getNodes(array);
569 /// @endcode
570 template<typename ArrayT> void getNodes(ArrayT& array);
571 template<typename ArrayT> void getNodes(ArrayT& array) const;
572 //@}
573
574 /// @brief Steals all nodes of a certain type from the tree and
575 /// adds them to a container with the following API:
576 /// @code
577 /// struct ArrayT {
578 /// using value_type = ...; // the type of node to be added to the array
579 /// void push_back(value_type nodePtr); // add a node to the array
580 /// };
581 /// @endcode
582 /// @details An example of a wrapper around a c-style array is:
583 /// @code
584 /// struct MyArray {
585 /// using value_type = LeafType*;
586 /// value_type* ptr;
587 /// MyArray(value_type* array) : ptr(array) {}
588 /// void push_back(value_type leaf) { *ptr++ = leaf; }
589 ///};
590 /// @endcode
591 /// @details An example that constructs a list of pointer to all leaf nodes is:
592 /// @code
593 /// std::vector<const LeafNodeType*> array;//most std contains have the required API
594 /// array.reserve(tree.leafCount());//this is a fast preallocation.
595 /// tree.stealNodes(array);
596 /// @endcode
597 template<typename ArrayT>
598 void stealNodes(ArrayT& array) { this->clearAllAccessors(); mRoot.stealNodes(array); }
599 template<typename ArrayT>
600 void stealNodes(ArrayT& array, const ValueType& value, bool state)
601 {
602 this->clearAllAccessors();
603 mRoot.stealNodes(array, value, state);
604 }
605
606 //
607 // Aux methods
608 //
609 /// @brief Return @c true if this tree contains no nodes other than
610 /// the root node and no tiles other than background tiles.
611 bool empty() const { return mRoot.empty(); }
612
613 /// Remove all tiles from this tree and all nodes other than the root node.
614 void clear();
615
616 /// @brief Return an accessor that provides random read and write access
617 /// to this tree's voxels.
618 /// @details The accessor is safe in the sense that it is registered with this tree.
620 /// @brief Return an unsafe accessor that provides random read and write access
621 /// to this tree's voxels.
622 /// @details The accessor is unsafe in the sense that it is not registered
623 /// with this tree's tree. In some rare cases this can give a performance advantage
624 /// over a registered accessor, but it is unsafe if the tree topology is modified.
625 /// @warning Only use this method if you're an expert and know the
626 /// risks of using an unregistered accessor (see tree/ValueAccessor.h)
628 /// Return an accessor that provides random read-only access to this tree's voxels.
630 /// Return an accessor that provides random read-only access to this tree's voxels.
632 /// @brief Return an unsafe accessor that provides random read-only access
633 /// to this tree's voxels.
634 /// @details The accessor is unsafe in the sense that it is not registered
635 /// with this tree. In some rare cases this can give a performance advantage
636 /// over a registered accessor, but it is unsafe if the tree topology is modified.
637 /// @warning Only use this method if you're an expert and know the
638 /// risks of using an unregistered accessor (see tree/ValueAccessor.h)
640
641 /// Clear all registered accessors.
643
644 //@{
645 /// @brief Register an accessor for this tree. Registered accessors are
646 /// automatically cleared whenever one of this tree's nodes is deleted.
649 //@}
650
651 //@{
652 /// Dummy implementations
655 //@}
656
657 //@{
658 /// Deregister an accessor so that it is no longer automatically cleared.
661 //@}
662
663 //@{
664 /// Dummy implementations
667 //@}
668
669 /// @brief Return this tree's background value wrapped as metadata.
670 /// @note Query the metadata object for the value's type.
672
673 /// @brief Return this tree's background value.
674 ///
675 /// @note Use tools::changeBackground to efficiently modify the
676 /// background values. Else use tree.root().setBackground, which
677 /// is serial and hence slower.
678 const ValueType& background() const { return mRoot.background(); }
679
680 /// Min and max are both inclusive.
681 void getIndexRange(CoordBBox& bbox) const override { mRoot.getIndexRange(bbox); }
682
683 /// @brief Efficiently merge another tree into this tree using one of several schemes.
684 /// @details This operation is primarily intended to combine trees that are mostly
685 /// non-overlapping (for example, intermediate trees from computations that are
686 /// parallelized across disjoint regions of space).
687 /// @note This operation is not guaranteed to produce an optimally sparse tree.
688 /// Follow merge() with prune() for optimal sparseness.
689 /// @warning This operation always empties the other tree.
691
692 /// @brief Union this tree's set of active values with the active values
693 /// of the other tree, whose @c ValueType may be different.
694 /// @details The resulting state of a value is active if the corresponding value
695 /// was already active OR if it is active in the other tree. Also, a resulting
696 /// value maps to a voxel if the corresponding value already mapped to a voxel
697 /// OR if it is a voxel in the other tree. Thus, a resulting value can only
698 /// map to a tile if the corresponding value already mapped to a tile
699 /// AND if it is a tile value in other tree.
700 ///
701 /// @note This operation modifies only active states, not values.
702 /// Specifically, active tiles and voxels in this tree are not changed, and
703 /// tiles or voxels that were inactive in this tree but active in the other tree
704 /// are marked as active in this tree but left with their original values.
705 ///
706 /// @note If preserveTiles is true, any active tile in this topology
707 /// will not be densified by overlapping child topology.
708 template<typename OtherRootNodeType>
709 void topologyUnion(const Tree<OtherRootNodeType>& other, const bool preserveTiles = false);
710
711 /// @brief Intersects this tree's set of active values with the active values
712 /// of the other tree, whose @c ValueType may be different.
713 /// @details The resulting state of a value is active only if the corresponding
714 /// value was already active AND if it is active in the other tree. Also, a
715 /// resulting value maps to a voxel if the corresponding value
716 /// already mapped to an active voxel in either of the two grids
717 /// and it maps to an active tile or voxel in the other grid.
718 ///
719 /// @note This operation can delete branches in this grid if they
720 /// overlap with inactive tiles in the other grid. Likewise active
721 /// voxels can be turned into inactive voxels resulting in leaf
722 /// nodes with no active values. Thus, it is recommended to
723 /// subsequently call tools::pruneInactive.
724 template<typename OtherRootNodeType>
726
727 /// @brief Difference this tree's set of active values with the active values
728 /// of the other tree, whose @c ValueType may be different. So a
729 /// resulting voxel will be active only if the original voxel is
730 /// active in this tree and inactive in the other tree.
731 ///
732 /// @note This operation can delete branches in this grid if they
733 /// overlap with active tiles in the other grid. Likewise active
734 /// voxels can be turned into inactive voxels resulting in leaf
735 /// nodes with no active values. Thus, it is recommended to
736 /// subsequently call tools::pruneInactive.
737 template<typename OtherRootNodeType>
739
740 /// For a given function @c f, use sparse traversal to compute <tt>f(this, other)</tt>
741 /// over all corresponding pairs of values (tile or voxel) of this tree and the other tree
742 /// and store the result in this tree.
743 /// This method is typically more space-efficient than the two-tree combine2(),
744 /// since it moves rather than copies nodes from the other tree into this tree.
745 /// @note This operation always empties the other tree.
746 /// @param other a tree of the same type as this tree
747 /// @param op a functor of the form <tt>void op(const T& a, const T& b, T& result)</tt>,
748 /// where @c T is this tree's @c ValueType, that computes
749 /// <tt>result = f(a, b)</tt>
750 /// @param prune if true, prune the resulting tree one branch at a time (this is usually
751 /// more space-efficient than pruning the entire tree in one pass)
752 ///
753 /// @par Example:
754 /// Compute the per-voxel difference between two floating-point trees,
755 /// @c aTree and @c bTree, and store the result in @c aTree (leaving @c bTree empty).
756 /// @code
757 /// {
758 /// struct Local {
759 /// static inline void diff(const float& a, const float& b, float& result) {
760 /// result = a - b;
761 /// }
762 /// };
763 /// aTree.combine(bTree, Local::diff);
764 /// }
765 /// @endcode
766 ///
767 /// @par Example:
768 /// Compute <tt>f * a + (1 - f) * b</tt> over all voxels of two floating-point trees,
769 /// @c aTree and @c bTree, and store the result in @c aTree (leaving @c bTree empty).
770 /// @code
771 /// namespace {
772 /// struct Blend {
773 /// Blend(float f): frac(f) {}
774 /// inline void operator()(const float& a, const float& b, float& result) const {
775 /// result = frac * a + (1.0 - frac) * b;
776 /// }
777 /// float frac;
778 /// };
779 /// }
780 /// {
781 /// aTree.combine(bTree, Blend(0.25)); // 0.25 * a + 0.75 * b
782 /// }
783 /// @endcode
784 template<typename CombineOp>
785 void combine(Tree& other, CombineOp& op, bool prune = false);
786 template<typename CombineOp>
787 void combine(Tree& other, const CombineOp& op, bool prune = false);
788
789 /// Like combine(), but with
790 /// @param other a tree of the same type as this tree
791 /// @param op a functor of the form <tt>void op(CombineArgs<ValueType>& args)</tt> that
792 /// computes <tt>args.setResult(f(args.a(), args.b()))</tt> and, optionally,
793 /// <tt>args.setResultIsActive(g(args.aIsActive(), args.bIsActive()))</tt>
794 /// for some functions @c f and @c g
795 /// @param prune if true, prune the resulting tree one branch at a time (this is usually
796 /// more space-efficient than pruning the entire tree in one pass)
797 ///
798 /// This variant passes not only the @em a and @em b values but also the active states
799 /// of the @em a and @em b values to the functor, which may then return, by calling
800 /// @c args.setResultIsActive(), a computed active state for the result value.
801 /// By default, the result is active if either the @em a or the @em b value is active.
802 ///
803 /// @see openvdb/Types.h for the definition of the CombineArgs struct.
804 ///
805 /// @par Example:
806 /// Replace voxel values in floating-point @c aTree with corresponding values
807 /// from floating-point @c bTree (leaving @c bTree empty) wherever the @c bTree
808 /// values are larger. Also, preserve the active states of any transferred values.
809 /// @code
810 /// {
811 /// struct Local {
812 /// static inline void max(CombineArgs<float>& args) {
813 /// if (args.b() > args.a()) {
814 /// // Transfer the B value and its active state.
815 /// args.setResult(args.b());
816 /// args.setResultIsActive(args.bIsActive());
817 /// } else {
818 /// // Preserve the A value and its active state.
819 /// args.setResult(args.a());
820 /// args.setResultIsActive(args.aIsActive());
821 /// }
822 /// }
823 /// };
824 /// aTree.combineExtended(bTree, Local::max);
825 /// }
826 /// @endcode
827 template<typename ExtendedCombineOp>
828 void combineExtended(Tree& other, ExtendedCombineOp& op, bool prune = false);
829 template<typename ExtendedCombineOp>
830 void combineExtended(Tree& other, const ExtendedCombineOp& op, bool prune = false);
831
832 /// For a given function @c f, use sparse traversal to compute <tt>f(a, b)</tt> over all
833 /// corresponding pairs of values (tile or voxel) of trees A and B and store the result
834 /// in this tree.
835 /// @param a,b two trees with the same configuration (levels and node dimensions)
836 /// as this tree but with the B tree possibly having a different value type
837 /// @param op a functor of the form <tt>void op(const T1& a, const T2& b, T1& result)</tt>,
838 /// where @c T1 is this tree's and the A tree's @c ValueType and @c T2 is the
839 /// B tree's @c ValueType, that computes <tt>result = f(a, b)</tt>
840 /// @param prune if true, prune the resulting tree one branch at a time (this is usually
841 /// more space-efficient than pruning the entire tree in one pass)
842 ///
843 /// @throw TypeError if the B tree's configuration doesn't match this tree's
844 /// or if this tree's ValueType is not constructible from the B tree's ValueType.
845 ///
846 /// @par Example:
847 /// Compute the per-voxel difference between two floating-point trees,
848 /// @c aTree and @c bTree, and store the result in a third tree.
849 /// @code
850 /// {
851 /// struct Local {
852 /// static inline void diff(const float& a, const float& b, float& result) {
853 /// result = a - b;
854 /// }
855 /// };
856 /// FloatTree resultTree;
857 /// resultTree.combine2(aTree, bTree, Local::diff);
858 /// }
859 /// @endcode
860 template<typename CombineOp, typename OtherTreeType /*= Tree*/>
861 void combine2(const Tree& a, const OtherTreeType& b, CombineOp& op, bool prune = false);
862 template<typename CombineOp, typename OtherTreeType /*= Tree*/>
863 void combine2(const Tree& a, const OtherTreeType& b, const CombineOp& op, bool prune = false);
864
865 /// Like combine2(), but with
866 /// @param a,b two trees with the same configuration (levels and node dimensions)
867 /// as this tree but with the B tree possibly having a different value type
868 /// @param op a functor of the form <tt>void op(CombineArgs<T1, T2>& args)</tt>, where
869 /// @c T1 is this tree's and the A tree's @c ValueType and @c T2 is the B tree's
870 /// @c ValueType, that computes <tt>args.setResult(f(args.a(), args.b()))</tt>
871 /// and, optionally,
872 /// <tt>args.setResultIsActive(g(args.aIsActive(), args.bIsActive()))</tt>
873 /// for some functions @c f and @c g
874 /// @param prune if true, prune the resulting tree one branch at a time (this is usually
875 /// more space-efficient than pruning the entire tree in one pass)
876 /// This variant passes not only the @em a and @em b values but also the active states
877 /// of the @em a and @em b values to the functor, which may then return, by calling
878 /// <tt>args.setResultIsActive()</tt>, a computed active state for the result value.
879 /// By default, the result is active if either the @em a or the @em b value is active.
880 ///
881 /// @throw TypeError if the B tree's configuration doesn't match this tree's
882 /// or if this tree's ValueType is not constructible from the B tree's ValueType.
883 ///
884 /// @see openvdb/Types.h for the definition of the CombineArgs struct.
885 ///
886 /// @par Example:
887 /// Compute the per-voxel maximum values of two single-precision floating-point trees,
888 /// @c aTree and @c bTree, and store the result in a third tree. Set the active state
889 /// of each output value to that of the larger of the two input values.
890 /// @code
891 /// {
892 /// struct Local {
893 /// static inline void max(CombineArgs<float>& args) {
894 /// if (args.b() > args.a()) {
895 /// // Transfer the B value and its active state.
896 /// args.setResult(args.b());
897 /// args.setResultIsActive(args.bIsActive());
898 /// } else {
899 /// // Preserve the A value and its active state.
900 /// args.setResult(args.a());
901 /// args.setResultIsActive(args.aIsActive());
902 /// }
903 /// }
904 /// };
905 /// FloatTree aTree = ...;
906 /// FloatTree bTree = ...;
907 /// FloatTree resultTree;
908 /// resultTree.combine2Extended(aTree, bTree, Local::max);
909 /// }
910 /// @endcode
911 ///
912 /// @par Example:
913 /// Compute the per-voxel maximum values of a double-precision and a single-precision
914 /// floating-point tree, @c aTree and @c bTree, and store the result in a third,
915 /// double-precision tree. Set the active state of each output value to that of
916 /// the larger of the two input values.
917 /// @code
918 /// {
919 /// struct Local {
920 /// static inline void max(CombineArgs<double, float>& args) {
921 /// if (args.b() > args.a()) {
922 /// // Transfer the B value and its active state.
923 /// args.setResult(args.b());
924 /// args.setResultIsActive(args.bIsActive());
925 /// } else {
926 /// // Preserve the A value and its active state.
927 /// args.setResult(args.a());
928 /// args.setResultIsActive(args.aIsActive());
929 /// }
930 /// }
931 /// };
932 /// DoubleTree aTree = ...;
933 /// FloatTree bTree = ...;
934 /// DoubleTree resultTree;
935 /// resultTree.combine2Extended(aTree, bTree, Local::max);
936 /// }
937 /// @endcode
938 template<typename ExtendedCombineOp, typename OtherTreeType /*= Tree*/>
939 void combine2Extended(const Tree& a, const OtherTreeType& b, ExtendedCombineOp& op,
940 bool prune = false);
941 template<typename ExtendedCombineOp, typename OtherTreeType /*= Tree*/>
942 void combine2Extended(const Tree& a, const OtherTreeType& b, const ExtendedCombineOp&,
943 bool prune = false);
944
945 //
946 // Iteration
947 //
948 //@{
949 /// Return an iterator over children of the root node.
950 typename RootNodeType::ChildOnCIter beginRootChildren() const { return mRoot.cbeginChildOn(); }
951 typename RootNodeType::ChildOnCIter cbeginRootChildren() const { return mRoot.cbeginChildOn(); }
952 typename RootNodeType::ChildOnIter beginRootChildren() { return mRoot.beginChildOn(); }
953 //@}
954
955 //@{
956 /// Return an iterator over non-child entries of the root node's table.
957 typename RootNodeType::ChildOffCIter beginRootTiles() const { return mRoot.cbeginChildOff(); }
958 typename RootNodeType::ChildOffCIter cbeginRootTiles() const { return mRoot.cbeginChildOff(); }
959 typename RootNodeType::ChildOffIter beginRootTiles() { return mRoot.beginChildOff(); }
960 //@}
961
962 //@{
963 /// Return an iterator over all entries of the root node's table.
964 typename RootNodeType::ChildAllCIter beginRootDense() const { return mRoot.cbeginChildAll(); }
965 typename RootNodeType::ChildAllCIter cbeginRootDense() const { return mRoot.cbeginChildAll(); }
966 typename RootNodeType::ChildAllIter beginRootDense() { return mRoot.beginChildAll(); }
967 //@}
968
969
970 //@{
971 /// Iterator over all nodes in this tree
974 //@}
975
976 //@{
977 /// Iterator over all leaf nodes in this tree
980 //@}
981
982 //@{
983 /// Return an iterator over all nodes in this tree.
984 NodeIter beginNode() { return NodeIter(*this); }
985 NodeCIter beginNode() const { return NodeCIter(*this); }
986 NodeCIter cbeginNode() const { return NodeCIter(*this); }
987 //@}
988
989 //@{
990 /// Return an iterator over all leaf nodes in this tree.
991 LeafIter beginLeaf() { return LeafIter(*this); }
992 LeafCIter beginLeaf() const { return LeafCIter(*this); }
993 LeafCIter cbeginLeaf() const { return LeafCIter(*this); }
994 //@}
995
1002
1003 //@{
1004 /// Return an iterator over all values (tile and voxel) across all nodes.
1006 ValueAllCIter beginValueAll() const { return ValueAllCIter(*this); }
1007 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(*this); }
1008 //@}
1009 //@{
1010 /// Return an iterator over active values (tile and voxel) across all nodes.
1012 ValueOnCIter beginValueOn() const { return ValueOnCIter(*this); }
1013 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(*this); }
1014 //@}
1015 //@{
1016 /// Return an iterator over inactive values (tile and voxel) across all nodes.
1018 ValueOffCIter beginValueOff() const { return ValueOffCIter(*this); }
1019 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(*this); }
1020 //@}
1021
1022 /// @brief Return an iterator of type @c IterT (for example, begin<ValueOnIter>() is
1023 /// equivalent to beginValueOn()).
1024 template<typename IterT> IterT begin();
1025 /// @brief Return a const iterator of type CIterT (for example, cbegin<ValueOnCIter>()
1026 /// is equivalent to cbeginValueOn()).
1027 template<typename CIterT> CIterT cbegin() const;
1028
1029
1030protected:
1031 using AccessorRegistry = tbb::concurrent_hash_map<ValueAccessorBase<Tree, true>*, bool>;
1032 using ConstAccessorRegistry = tbb::concurrent_hash_map<ValueAccessorBase<const Tree, true>*, bool>;
1033
1034 /// @brief Notify all registered accessors, by calling ValueAccessor::release(),
1035 /// that this tree is about to be deleted.
1037
1038 // TBB body object used to deallocates nodes in parallel.
1039 template<typename NodeType>
1041 DeallocateNodes(std::vector<NodeType*>& nodes)
1042 : mNodes(nodes.empty() ? nullptr : &nodes.front()) { }
1043 void operator()(const tbb::blocked_range<size_t>& range) const {
1044 for (size_t n = range.begin(), N = range.end(); n < N; ++n) {
1045 delete mNodes[n]; mNodes[n] = nullptr;
1046 }
1047 }
1048 NodeType ** const mNodes;
1049 };
1050
1051 //
1052 // Data members
1053 //
1054 RootNodeType mRoot; // root node of the tree
1057}; // end of Tree class
1058
1059
1060/// @brief Tree3<T, N1, N2>::Type is the type of a three-level tree
1061/// (Root, Internal, Leaf) with value type T and
1062/// internal and leaf node log dimensions N1 and N2, respectively.
1063/// @note This is NOT the standard tree configuration (Tree4 is).
1064template<typename T, Index N1=4, Index N2=3>
1068
1069
1070/// @brief Tree4<T, N1, N2, N3>::Type is the type of a four-level tree
1071/// (Root, Internal, Internal, Leaf) with value type T and
1072/// internal and leaf node log dimensions N1, N2 and N3, respectively.
1073/// @note This is the standard tree configuration.
1074template<typename T, Index N1=5, Index N2=4, Index N3=3>
1078
1079/// @brief Tree5<T, N1, N2, N3, N4>::Type is the type of a five-level tree
1080/// (Root, Internal, Internal, Internal, Leaf) with value type T and
1081/// internal and leaf node log dimensions N1, N2, N3 and N4, respectively.
1082/// @note This is NOT the standard tree configuration (Tree4 is).
1083template<typename T, Index N1=6, Index N2=5, Index N3=4, Index N4=3>
1088
1089
1090////////////////////////////////////////
1091
1092
1093inline void
1094TreeBase::print(std::ostream& os, int /*verboseLevel*/) const
1095{
1096 os << " Tree Type: " << type()
1097 << " Active Voxel Count: " << activeVoxelCount() << std::endl
1098 << " Active tile Count: " << activeTileCount() << std::endl
1099 << " Inactive Voxel Count: " << inactiveVoxelCount() << std::endl
1100 << " Leaf Node Count: " << leafCount() << std::endl
1101 << " Non-leaf Node Count: " << nonLeafCount() << std::endl;
1102}
1103
1104
1105////////////////////////////////////////
1106
1107
1108//
1109// Type traits for tree iterators
1110//
1111
1112/// @brief TreeIterTraits provides, for all tree iterators, a begin(tree) function
1113/// that returns an iterator over a tree of arbitrary type.
1114template<typename TreeT, typename IterT> struct TreeIterTraits;
1115
1116template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnIter> {
1117 static typename TreeT::RootNodeType::ChildOnIter begin(TreeT& tree) {
1118 return tree.beginRootChildren();
1119 }
1120};
1121
1122template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOnCIter> {
1123 static typename TreeT::RootNodeType::ChildOnCIter begin(const TreeT& tree) {
1124 return tree.cbeginRootChildren();
1125 }
1126};
1127
1128template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffIter> {
1129 static typename TreeT::RootNodeType::ChildOffIter begin(TreeT& tree) {
1130 return tree.beginRootTiles();
1131 }
1132};
1133
1134template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildOffCIter> {
1135 static typename TreeT::RootNodeType::ChildOffCIter begin(const TreeT& tree) {
1136 return tree.cbeginRootTiles();
1137 }
1138};
1139
1140template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllIter> {
1141 static typename TreeT::RootNodeType::ChildAllIter begin(TreeT& tree) {
1142 return tree.beginRootDense();
1143 }
1144};
1145
1146template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::RootNodeType::ChildAllCIter> {
1147 static typename TreeT::RootNodeType::ChildAllCIter begin(const TreeT& tree) {
1148 return tree.cbeginRootDense();
1149 }
1150};
1151
1152template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::NodeIter> {
1153 static typename TreeT::NodeIter begin(TreeT& tree) { return tree.beginNode(); }
1154};
1155
1156template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::NodeCIter> {
1157 static typename TreeT::NodeCIter begin(const TreeT& tree) { return tree.cbeginNode(); }
1158};
1159
1160template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::LeafIter> {
1161 static typename TreeT::LeafIter begin(TreeT& tree) { return tree.beginLeaf(); }
1162};
1163
1164template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::LeafCIter> {
1165 static typename TreeT::LeafCIter begin(const TreeT& tree) { return tree.cbeginLeaf(); }
1166};
1167
1168template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueOnIter> {
1169 static typename TreeT::ValueOnIter begin(TreeT& tree) { return tree.beginValueOn(); }
1170};
1171
1172template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueOnCIter> {
1173 static typename TreeT::ValueOnCIter begin(const TreeT& tree) { return tree.cbeginValueOn(); }
1174};
1175
1176template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueOffIter> {
1177 static typename TreeT::ValueOffIter begin(TreeT& tree) { return tree.beginValueOff(); }
1178};
1179
1180template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueOffCIter> {
1181 static typename TreeT::ValueOffCIter begin(const TreeT& tree) { return tree.cbeginValueOff(); }
1182};
1183
1184template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueAllIter> {
1185 static typename TreeT::ValueAllIter begin(TreeT& tree) { return tree.beginValueAll(); }
1186};
1187
1188template<typename TreeT> struct TreeIterTraits<TreeT, typename TreeT::ValueAllCIter> {
1189 static typename TreeT::ValueAllCIter begin(const TreeT& tree) { return tree.cbeginValueAll(); }
1190};
1191
1192
1193template<typename RootNodeType>
1194template<typename IterT>
1195inline IterT
1200
1201
1202template<typename RootNodeType>
1203template<typename IterT>
1204inline IterT
1209
1210
1211////////////////////////////////////////
1212
1213
1214#if OPENVDB_ABI_VERSION_NUMBER < 14
1215
1216template<typename RootNodeType>
1217void
1218Tree<RootNodeType>::readTopology(std::istream& is, bool saveFloatAsHalf)
1219{
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);
1225}
1226
1227
1228template<typename RootNodeType>
1229void
1230Tree<RootNodeType>::writeTopology(std::ostream& os, bool saveFloatAsHalf) const
1231{
1232 int32_t bufferCount = 1;
1233 os.write(reinterpret_cast<char*>(&bufferCount), sizeof(int32_t));
1234 mRoot.writeTopology(os, saveFloatAsHalf);
1235}
1236
1237
1238template<typename RootNodeType>
1239inline void
1240Tree<RootNodeType>::readBuffers(std::istream &is, bool saveFloatAsHalf)
1241{
1242 this->clearAllAccessors();
1243 mRoot.readBuffers(is, saveFloatAsHalf);
1244}
1245
1246
1247template<typename RootNodeType>
1248inline void
1249Tree<RootNodeType>::readBuffers(std::istream &is, const CoordBBox& bbox, bool saveFloatAsHalf)
1250{
1251 this->clearAllAccessors();
1252 mRoot.readBuffers(is, bbox, saveFloatAsHalf);
1253}
1254
1255
1256template<typename RootNodeType>
1257inline void
1258Tree<RootNodeType>::writeBuffers(std::ostream &os, bool saveFloatAsHalf) const
1259{
1260 mRoot.writeBuffers(os, saveFloatAsHalf);
1261}
1262
1263#endif // OPENVDB_ABI_VERSION_NUMBER < 14
1264
1265
1266template<typename RootNodeType>
1267template<typename ArrayT>
1268inline void
1270{
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);
1275}
1276
1277
1278template<typename RootNodeType>
1279template<typename ArrayT>
1280inline void
1282{
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);
1287}
1288
1289
1290template<typename RootNodeType>
1291inline void
1293{
1294 std::vector<LeafNodeType*> leafnodes;
1295 this->stealNodes(leafnodes);
1296
1297 tbb::parallel_for(tbb::blocked_range<size_t>(0, leafnodes.size()),
1299
1300 std::vector<typename RootNodeType::ChildNodeType*> internalNodes;
1301 this->stealNodes(internalNodes);
1302
1303 tbb::parallel_for(tbb::blocked_range<size_t>(0, internalNodes.size()),
1305
1306 mRoot.clear();
1307
1308 this->clearAllAccessors();
1309}
1310
1311
1312////////////////////////////////////////
1313
1314
1315template<typename RootNodeType>
1318{
1319 return Accessor(*this);
1320}
1321
1322template<typename RootNodeType>
1328
1329template<typename RootNodeType>
1332{
1333 return ConstAccessor(*this);
1334}
1335
1336template<typename RootNodeType>
1339{
1340 return ConstAccessor(*this);
1341}
1342
1343template<typename RootNodeType>
1349
1350template<typename RootNodeType>
1351inline void
1353{
1354 typename AccessorRegistry::accessor a;
1355 mAccessorRegistry.insert(a, &accessor);
1356}
1357
1358
1359template<typename RootNodeType>
1360inline void
1362{
1363 typename ConstAccessorRegistry::accessor a;
1364 mConstAccessorRegistry.insert(a, &accessor);
1365}
1366
1367
1368template<typename RootNodeType>
1369inline void
1374
1375
1376template<typename RootNodeType>
1377inline void
1382
1383
1384template<typename RootNodeType>
1385inline void
1387{
1388 for (typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1389 it != mAccessorRegistry.end(); ++it)
1390 {
1391 if (it->first) it->first->clear();
1392 }
1393
1394 for (typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1395 it != mConstAccessorRegistry.end(); ++it)
1396 {
1397 if (it->first) it->first->clear();
1398 }
1399}
1400
1401
1402template<typename RootNodeType>
1403inline void
1405{
1406 mAccessorRegistry.erase(nullptr);
1407 for (typename AccessorRegistry::iterator it = mAccessorRegistry.begin();
1408 it != mAccessorRegistry.end(); ++it)
1409 {
1410 it->first->release();
1411 }
1412 mAccessorRegistry.clear();
1413
1414 mAccessorRegistry.erase(nullptr);
1415 for (typename ConstAccessorRegistry::iterator it = mConstAccessorRegistry.begin();
1416 it != mConstAccessorRegistry.end(); ++it)
1417 {
1418 it->first->release();
1419 }
1420 mConstAccessorRegistry.clear();
1421}
1422
1423
1424////////////////////////////////////////
1425
1426
1427template<typename RootNodeType>
1428inline const typename RootNodeType::ValueType&
1430{
1431 return mRoot.getValue(xyz);
1432}
1433
1434
1435template<typename RootNodeType>
1436template<typename AccessT>
1437inline const typename RootNodeType::ValueType&
1438Tree<RootNodeType>::getValue(const Coord& xyz, AccessT& accessor) const
1439{
1440 return accessor.getValue(xyz);
1441}
1442
1443
1444template<typename RootNodeType>
1445inline int
1447{
1448 return mRoot.getValueDepth(xyz);
1449}
1450
1451
1452template<typename RootNodeType>
1453inline void
1455{
1456 mRoot.setValueOff(xyz);
1457}
1458
1459
1460template<typename RootNodeType>
1461inline void
1463{
1464 mRoot.setValueOff(xyz, value);
1465}
1466
1467
1468template<typename RootNodeType>
1469inline void
1471{
1472 mRoot.setActiveState(xyz, on);
1473}
1474
1475
1476template<typename RootNodeType>
1477inline void
1479{
1480 mRoot.setValueOn(xyz, value);
1481}
1482
1483template<typename RootNodeType>
1484inline void
1486{
1487 mRoot.setValueOnly(xyz, value);
1488}
1489
1490template<typename RootNodeType>
1491template<typename AccessT>
1492inline void
1493Tree<RootNodeType>::setValue(const Coord& xyz, const ValueType& value, AccessT& accessor)
1494{
1495 accessor.setValue(xyz, value);
1496}
1497
1498
1499template<typename RootNodeType>
1500inline void
1502{
1503 mRoot.setActiveState(xyz, true);
1504}
1505
1506
1507template<typename RootNodeType>
1508inline void
1510{
1511 mRoot.setValueOn(xyz, value);
1512}
1513
1514
1515template<typename RootNodeType>
1516template<typename ModifyOp>
1517inline void
1518Tree<RootNodeType>::modifyValue(const Coord& xyz, const ModifyOp& op)
1519{
1520 mRoot.modifyValue(xyz, op);
1521}
1522
1523
1524template<typename RootNodeType>
1525template<typename ModifyOp>
1526inline void
1528{
1529 mRoot.modifyValueAndActiveState(xyz, op);
1530}
1531
1532
1533template<typename RootNodeType>
1534inline bool
1536{
1537 return mRoot.probeValue(xyz, value);
1538}
1539
1540
1541////////////////////////////////////////
1542
1543
1544template<typename RootNodeType>
1545inline void
1547 const ValueType& value, bool active)
1548{
1549 mRoot.addTile(level, xyz, value, active);
1550}
1551
1552
1553template<typename RootNodeType>
1554template<typename NodeT>
1555inline NodeT*
1556Tree<RootNodeType>::stealNode(const Coord& xyz, const ValueType& value, bool active)
1557{
1558 this->clearAllAccessors();
1559 return mRoot.template stealNode<NodeT>(xyz, value, active);
1560}
1561
1562
1563template<typename RootNodeType>
1564inline typename RootNodeType::LeafNodeType*
1566{
1567 return mRoot.touchLeaf(xyz);
1568}
1569
1570
1571template<typename RootNodeType>
1572inline typename RootNodeType::LeafNodeType*
1574{
1575 return mRoot.probeLeaf(xyz);
1576}
1577
1578
1579template<typename RootNodeType>
1580inline const typename RootNodeType::LeafNodeType*
1582{
1583 return mRoot.probeConstLeaf(xyz);
1584}
1585
1586
1587template<typename RootNodeType>
1588template<typename NodeType>
1589inline NodeType*
1591{
1592 return mRoot.template probeNode<NodeType>(xyz);
1593}
1594
1595
1596template<typename RootNodeType>
1597template<typename NodeType>
1598inline const NodeType*
1600{
1601 return this->template probeConstNode<NodeType>(xyz);
1602}
1603
1604
1605template<typename RootNodeType>
1606template<typename NodeType>
1607inline const NodeType*
1609{
1610 return mRoot.template probeConstNode<NodeType>(xyz);
1611}
1612
1613
1614////////////////////////////////////////
1615
1616
1617template<typename RootNodeType>
1618inline void
1620{
1621 this->clearAllAccessors();
1622 return mRoot.clip(bbox);
1623}
1624
1625
1626template<typename RootNodeType>
1627inline void
1629{
1630 this->clearAllAccessors();
1631 for (LeafIter it = this->beginLeaf(); it; ) {
1632 const LeafNodeType* leaf = it.getLeaf();
1633 ++it; // advance the iterator before deleting the leaf node
1634 if (!leaf->isAllocated()) {
1635 this->addTile(/*level=*/0, leaf->origin(), this->background(), /*active=*/false);
1636 }
1637 }
1638}
1639
1640template<typename RootNodeType>
1641inline Index64
1643{
1644 Index64 sum = 0;
1645 for (auto it = this->cbeginLeaf(); it; ++it) if (!it->isAllocated()) ++sum;
1646 return sum;
1647}
1648
1649
1650template<typename RootNodeType>
1651inline void
1652Tree<RootNodeType>::sparseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1653{
1654 this->clearAllAccessors();
1655 return mRoot.sparseFill(bbox, value, active);
1656}
1657
1658
1659template<typename RootNodeType>
1660inline void
1661Tree<RootNodeType>::denseFill(const CoordBBox& bbox, const ValueType& value, bool active)
1662{
1663 this->clearAllAccessors();
1664 return mRoot.denseFill(bbox, value, active);
1665}
1666
1667
1668template<typename RootNodeType>
1669inline void
1671{
1672 this->clearAllAccessors();
1673 mRoot.voxelizeActiveTiles(threaded);
1674}
1675
1676
1677template<typename RootNodeType>
1680{
1681 Metadata::Ptr result;
1683 using MetadataT = TypedMetadata<ValueType>;
1685 if (result->typeName() == MetadataT::staticTypeName()) {
1686 MetadataT* m = static_cast<MetadataT*>(result.get());
1687 m->value() = mRoot.background();
1688 }
1689 }
1690 return result;
1691}
1692
1693
1694////////////////////////////////////////
1695
1696
1697template<typename RootNodeType>
1698inline void
1700{
1701 this->clearAllAccessors();
1702 other.clearAllAccessors();
1703 switch (policy) {
1705 mRoot.template merge<MERGE_ACTIVE_STATES>(other.mRoot); break;
1706 case MERGE_NODES:
1707 mRoot.template merge<MERGE_NODES>(other.mRoot); break;
1709 mRoot.template merge<MERGE_ACTIVE_STATES_AND_NODES>(other.mRoot); break;
1710 }
1711}
1712
1713
1714template<typename RootNodeType>
1715template<typename OtherRootNodeType>
1716inline void
1717Tree<RootNodeType>::topologyUnion(const Tree<OtherRootNodeType>& other, const bool preserveTiles)
1718{
1719 this->clearAllAccessors();
1720 mRoot.topologyUnion(other.root(), preserveTiles);
1721}
1722
1723template<typename RootNodeType>
1724template<typename OtherRootNodeType>
1725inline void
1727{
1728 this->clearAllAccessors();
1729 mRoot.topologyIntersection(other.root());
1730}
1731
1732template<typename RootNodeType>
1733template<typename OtherRootNodeType>
1734inline void
1736{
1737 this->clearAllAccessors();
1738 mRoot.topologyDifference(other.root());
1739}
1740
1741////////////////////////////////////////
1742
1743
1744/// @brief Helper class to adapt a three-argument (a, b, result) CombineOp functor
1745/// into a single-argument functor that accepts a CombineArgs struct
1746template<typename AValueT, typename CombineOp, typename BValueT = AValueT>
1748{
1749 CombineOpAdapter(CombineOp& _op): op(_op) {}
1750
1752 op(args.a(), args.b(), args.result());
1753 }
1754
1755 CombineOp& op;
1756};
1757
1758
1759template<typename RootNodeType>
1760template<typename CombineOp>
1761inline void
1762Tree<RootNodeType>::combine(Tree& other, CombineOp& op, bool prune)
1763{
1765 this->combineExtended(other, extendedOp, prune);
1766}
1767
1768
1769/// @internal This overload is needed (for ICC and GCC, but not for VC) to disambiguate
1770/// code like this: <tt>aTree.combine(bTree, MyCombineOp(...))</tt>.
1771template<typename RootNodeType>
1772template<typename CombineOp>
1773inline void
1774Tree<RootNodeType>::combine(Tree& other, const CombineOp& op, bool prune)
1775{
1777 this->combineExtended(other, extendedOp, prune);
1778}
1779
1780
1781template<typename RootNodeType>
1782template<typename ExtendedCombineOp>
1783inline void
1784Tree<RootNodeType>::combineExtended(Tree& other, ExtendedCombineOp& op, bool prune)
1785{
1786 this->clearAllAccessors();
1787 mRoot.combine(other.root(), op, prune);
1788}
1789
1790
1791/// @internal This overload is needed (for ICC and GCC, but not for VC) to disambiguate
1792/// code like this: <tt>aTree.combineExtended(bTree, MyCombineOp(...))</tt>.
1793template<typename RootNodeType>
1794template<typename ExtendedCombineOp>
1795inline void
1796Tree<RootNodeType>::combineExtended(Tree& other, const ExtendedCombineOp& op, bool prune)
1797{
1798 this->clearAllAccessors();
1800}
1801
1802
1803template<typename RootNodeType>
1804template<typename CombineOp, typename OtherTreeType>
1805inline void
1806Tree<RootNodeType>::combine2(const Tree& a, const OtherTreeType& b, CombineOp& op, bool prune)
1807{
1809 this->combine2Extended(a, b, extendedOp, prune);
1810}
1811
1812
1813/// @internal This overload is needed (for ICC and GCC, but not for VC) to disambiguate
1814/// code like this: <tt>tree.combine2(aTree, bTree, MyCombineOp(...))</tt>.
1815template<typename RootNodeType>
1816template<typename CombineOp, typename OtherTreeType>
1817inline void
1818Tree<RootNodeType>::combine2(const Tree& a, const OtherTreeType& b, const CombineOp& op, bool prune)
1819{
1821 this->combine2Extended(a, b, extendedOp, prune);
1822}
1823
1824
1825template<typename RootNodeType>
1826template<typename ExtendedCombineOp, typename OtherTreeType>
1827inline void
1828Tree<RootNodeType>::combine2Extended(const Tree& a, const OtherTreeType& b,
1829 ExtendedCombineOp& op, bool prune)
1830{
1831 this->clearAllAccessors();
1832 mRoot.combine2(a.root(), b.root(), op, prune);
1833}
1834
1835
1836/// @internal This overload is needed (for ICC and GCC, but not for VC) to disambiguate
1837/// code like the following, where the functor argument is a temporary:
1838/// <tt>tree.combine2Extended(aTree, bTree, MyCombineOp(...))</tt>.
1839template<typename RootNodeType>
1840template<typename ExtendedCombineOp, typename OtherTreeType>
1841inline void
1842Tree<RootNodeType>::combine2Extended(const Tree& a, const OtherTreeType& b,
1843 const ExtendedCombineOp& op, bool prune)
1844{
1845 this->clearAllAccessors();
1846 mRoot.template combine2<const ExtendedCombineOp>(a.root(), b.root(), op, prune);
1847}
1848
1849
1850////////////////////////////////////////
1851
1852
1853template<typename RootNodeType>
1854inline const Name&
1856{
1857 static std::string sTreeTypeName = []()
1858 {
1859 // @todo use RootNode::NodeChain::foreach() instead
1860 std::vector<Index> dims;
1862 std::ostringstream ostr;
1863 ostr << "Tree_" << typeNameAsString<BuildType>();
1864 for (size_t i = 1, N = dims.size(); i < N; ++i) { // start from 1 to skip the RootNode
1865 ostr << "_" << dims[i];
1866 }
1867 return ostr.str();
1868 }();
1869 return sTreeTypeName;
1870}
1871
1872
1873template<typename RootNodeType>
1874template<typename OtherRootNodeType>
1875inline bool
1877{
1878 return mRoot.hasSameTopology(other.root());
1879}
1880
1881
1882template<typename RootNodeType>
1883inline bool
1885{
1886 bbox.reset(); // default invalid bbox
1887
1888 if (this->empty()) return false; // empty
1889
1890 mRoot.evalActiveBoundingBox(bbox, false);
1891
1892 return !bbox.empty();
1893}
1894
1895template<typename RootNodeType>
1896inline bool
1898{
1899 bbox.reset(); // default invalid bbox
1900
1901 if (this->empty()) return false; // empty
1902
1903 mRoot.evalActiveBoundingBox(bbox, true);
1904
1905 return !bbox.empty();
1906}
1907
1908
1909template<typename RootNodeType>
1910inline bool
1912{
1913 CoordBBox bbox;
1914 bool notEmpty = this->evalActiveVoxelBoundingBox(bbox);
1915 dim = bbox.extents();
1916 return notEmpty;
1917}
1918
1919
1920template<typename RootNodeType>
1921inline bool
1923{
1924 CoordBBox bbox;
1925 bool notEmpty = this->evalLeafBoundingBox(bbox);
1926 dim = bbox.extents();
1927 return notEmpty;
1928}
1929
1930
1931template<typename RootNodeType>
1932inline void
1934{
1935 dims.clear();
1936 RootNodeType::getNodeLog2Dims(dims);
1937}
1938
1939
1940template<typename RootNodeType>
1941inline void
1942Tree<RootNodeType>::print(std::ostream& os, int verboseLevel) const
1943{
1944 if (verboseLevel <= 0) return;
1945
1946 struct OnExit {
1947 std::ostream& os;
1948 std::streamsize savedPrecision;
1949 OnExit(std::ostream& _os): os(_os), savedPrecision(os.precision()) {}
1950 ~OnExit() { os.precision(savedPrecision); }
1951 };
1952 OnExit restorePrecision(os);
1953
1954 std::vector<Index> dims;
1955 Tree::getNodeLog2Dims(dims);// leaf is the last element
1956
1957 os << "Information about Tree:\n"
1958 << " Type: " << this->type() << "\n";
1959
1960 os << " Configuration:\n";
1961
1962 if (verboseLevel <= 1) {
1963 // Print node types and sizes.
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)";
1968 }
1969 os << ", Leaf(" << (1 << dims.back()) << "^3)\n";
1970 }
1971 os << " Background value: " << mRoot.background() << "\n";
1972 return;
1973 }
1974
1975 // The following is tree information that is expensive to extract.
1976
1977 ValueType minVal = zeroVal<ValueType>(), maxVal = zeroVal<ValueType>();
1978 if (verboseLevel > 3) {
1979 // This forces loading of all non-resident nodes.
1980 const math::MinMax<ValueType> extrema = tools::minMax(*this);
1981 minVal = extrema.min();
1982 maxVal = extrema.max();
1983 }
1984
1985 const auto nodeCount = this->nodeCount();//fast
1986 const Index64 leafCount = nodeCount.front();// leaf is the first element
1987 OPENVDB_ASSERT(dims.size() == nodeCount.size());
1988
1989 Index64 totalNodeCount = 0;
1990 for (size_t i = 0; i < nodeCount.size(); ++i) totalNodeCount += nodeCount[i];
1991
1992 // Print node types, counts and sizes.
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) {
1996 os << ", Internal(" << util::formattedInt(nodeCount[N - i]);
1997 os << " x " << (1 << dims[i]) << "^3)";
1998 }
1999 os << ", Leaf(" << util::formattedInt(leafCount);
2000 os << " x " << (1 << dims.back()) << "^3)\n";
2001 }
2002 os << " Background value: " << mRoot.background() << "\n";
2003
2004 // Statistics of topology and values
2005
2006 if (verboseLevel > 3) {
2007 os << " Min value: " << minVal << "\n";
2008 os << " Max value: " << maxVal << "\n";
2009 }
2010
2011 const Index64
2012 numActiveVoxels = this->activeVoxelCount(),
2013 numActiveLeafVoxels = this->activeLeafVoxelCount(),
2014 numActiveTiles = this->activeTileCount();
2015
2016 os << " Number of active voxels: " << util::formattedInt(numActiveVoxels) << "\n";
2017 os << " Number of active tiles: " << util::formattedInt(numActiveTiles) << "\n";
2018
2019 Coord dim(0, 0, 0);
2020 Index64 totalVoxels = 0;
2021 if (numActiveVoxels) { // nonempty
2022 CoordBBox bbox;
2023 this->evalActiveVoxelBoundingBox(bbox);
2024 dim = bbox.extents();
2025 totalVoxels = dim.x() * uint64_t(dim.y()) * dim.z();
2026
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";
2030
2031 const double activeRatio = (100.0 * double(numActiveVoxels)) / double(totalVoxels);
2032 os << " Percentage of active voxels: " << std::setprecision(3) << activeRatio << "%\n";
2033
2034 if (leafCount > 0) {
2035 const double fillRatio = (100.0 * double(numActiveLeafVoxels))
2036 / (double(leafCount) * double(LeafNodeType::NUM_VOXELS));
2037 os << " Average leaf node fill ratio: " << fillRatio << "%\n";
2038 }
2039
2040 if (verboseLevel > 2) {
2041 Index64 sum = 0;// count the number of unallocated leaf nodes
2042 for (auto it = this->cbeginLeaf(); it; ++it) if (!it->isAllocated()) ++sum;
2043 os << " Number of unallocated nodes: "
2044 << util::formattedInt(sum) << " ("
2045 << (100.0 * double(sum) / double(totalNodeCount)) << "%)\n";
2046 }
2047 } else {
2048 os << " Tree is empty!\n";
2049 }
2050 os << std::flush;
2051
2052 if (verboseLevel == 2) return;
2053
2054 // Memory footprint in bytes
2055 const Index64
2056 actualMem = this->memUsage(),
2057 denseMem = sizeof(ValueType) * totalVoxels,
2058 voxelsMem = sizeof(ValueType) * numActiveLeafVoxels;
2059 ///< @todo not accurate for BoolTree (and probably should count tile values)
2060
2061 os << "Memory footprint:\n";
2062 util::printBytes(os, actualMem, " Actual: ");
2063 util::printBytes(os, voxelsMem, " Active leaf voxels: ");
2064
2065 if (numActiveVoxels) {
2066 util::printBytes(os, denseMem, " Dense equivalent: ");
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";
2071 }
2072}
2073
2074} // namespace tree
2075} // namespace OPENVDB_VERSION_NAME
2076} // namespace openvdb
2077
2078#endif // OPENVDB_TREE_TREE_HAS_BEEN_INCLUDED
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Functions to count tiles, nodes or voxels in a grid.
Utility routines to output nicely-formatted numeric values.
Internal table nodes for OpenVDB trees.
#define OPENVDB_API
Definition Platform.h:286
#define OPENVDB_DEPRECATED_MESSAGE(msg)
Definition Platform.h:158
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
static Metadata::Ptr createMetadata(const Name &typeName)
Create new metadata of the given type.
static bool isRegisteredType(const Name &typeName)
Return true if the given type is known by the metadata type registry.
SharedPtr< Metadata > Ptr
Definition Metadata.h:27
Definition Exceptions.h:61
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:754
Templated metadata class to hold specific types.
Definition Metadata.h:123
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 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
Definition Tree.h:172
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
bool isValueOn(const Coord &xyz) const
Return true if the value at the given coordinates is active.
Definition Tree.h:444
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
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
LeafCIter cbeginLeaf() const
Definition Tree.h:993
const Name & type() const override
Return the name of this type of tree.
Definition Tree.h:273
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
void clip(const CoordBBox &)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition Tree.h:1619
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
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
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
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 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
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
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
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
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
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
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
Index64 countActiveLeafVoxels(const TreeT &tree, bool threaded=true)
Return the total number of active voxels stored in leaf nodes.
Definition Count.h:424
math::MinMax< typename TreeT::ValueType > minMax(const TreeT &tree, bool threaded=true)
Return the minimum and maximum active values in this tree.
Definition Count.h:491
Index64 countInactiveVoxels(const TreeT &tree, bool threaded=true)
Return the total number of inactive voxels in the tree.
Definition Count.h:449
Index64 countActiveVoxels(const TreeT &tree, bool threaded=true)
Return the total number of active voxels in the tree.
Definition Count.h:401
Index64 memUsage(const TreeT &tree, bool threaded=true)
Return the total amount of memory in bytes occupied by this tree.
Definition Count.h:481
Index64 countInactiveLeafVoxels(const TreeT &tree, bool threaded=true)
Return the total number of inactive voxels stored in leaf nodes.
Definition Count.h:459
Index64 countActiveTiles(const TreeT &tree, bool threaded=true)
Return the total number of active tiles in the tree.
Definition Count.h:470
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
Definition Coord.h:590
#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