OpenVDB: LeafManager.h Source File

OpenVDB 7.0.0

LeafManager.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
14
15 #ifndef OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
16 #define OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
17
18 #include <openvdb/Types.h>
19 #include <tbb/blocked_range.h>
20 #include <tbb/parallel_for.h>
21 #include <tbb/parallel_reduce.h>
22 #include <functional>
23 #include <type_traits>
24
25
26 namespace openvdb {
27 OPENVDB_USE_VERSION_NAMESPACE
28 namespace OPENVDB_VERSION_NAME {
29 namespace tree {
30
31 namespace leafmgr {
32
34 template<typename TreeT> struct TreeTraits {
36 static const bool IsConstTree = false;
37 using LeafIterType = typename TreeT::LeafIter;
38 };
39 template<typename TreeT> struct TreeTraits<const TreeT> {
40 static const bool IsConstTree = true;
41 using LeafIterType = typename TreeT::LeafCIter;
42 };
44
45 } // namespace leafmgr
46
47
50 template<typename ManagerT>
51 struct LeafManagerImpl
52 {
53 using RangeT = typename ManagerT::RangeType;
54 using LeafT = typename ManagerT::LeafType;
55 using BufT = typename ManagerT::BufferType;
56
57 static inline void doSwapLeafBuffer(const RangeT& r, size_t auxBufferIdx,
58 LeafT** leafs, BufT* bufs, size_t bufsPerLeaf)
59 {
60 for (size_t n = r.begin(), m = r.end(), N = bufsPerLeaf; n != m; ++n) {
61 leafs[n]->swap(bufs[n * N + auxBufferIdx]);
62 }
63 }
64 };
65
66
68
69
81 template<typename TreeT>
82 class LeafManager
83 {
84 public:
85 using TreeType = TreeT;
86 using ValueType = typename TreeT::ValueType;
87 using RootNodeType = typename TreeT::RootNodeType;
88 using NonConstLeafType = typename TreeType::LeafNodeType;
89 using LeafType = typename CopyConstness<TreeType, NonConstLeafType>::Type;
90 using LeafNodeType = LeafType;
91 using LeafIterType = typename leafmgr::TreeTraits<TreeT>::LeafIterType;
92 using NonConstBufferType = typename LeafType::Buffer;
93 using BufferType = typename CopyConstness<TreeType, NonConstBufferType>::Type;
94 using RangeType = tbb::blocked_range<size_t>; // leaf index range
95 static const Index DEPTH = 2; // root + leaf nodes
96
97 static const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree;
98
99 class LeafRange
100 {
101 public:
102 class Iterator
103 {
104 public:
105 Iterator(const LeafRange& range, size_t pos): mRange(range), mPos(pos)
106 {
107 assert(this->isValid());
108 }
109 Iterator(const Iterator&) = default;
110 Iterator& operator=(const Iterator&) = default;
112 Iterator& operator++() { ++mPos; return *this; }
114 LeafType& operator*() const { return mRange.mLeafManager.leaf(mPos); }
116 LeafType* operator->() const { return &(this->operator*()); }
119 BufferType& buffer(size_t bufferIdx)
120 {
121 return mRange.mLeafManager.getBuffer(mPos, bufferIdx);
122 }
124 size_t pos() const { return mPos; }
126 bool isValid() const { return mPos>=mRange.mBegin && mPos<=mRange.mEnd; }
128 bool test() const { return mPos < mRange.mEnd; }
130 operator bool() const { return this->test(); }
132 bool empty() const { return !this->test(); }
133 bool operator!=(const Iterator& other) const
134 {
135 return (mPos != other.mPos) || (&mRange != &other.mRange);
136 }
137 bool operator==(const Iterator& other) const { return !(*this != other); }
138 const LeafRange& leafRange() const { return mRange; }
139
140 private:
141 const LeafRange& mRange;
142 size_t mPos;
143 };// end Iterator
144
145 LeafRange(size_t begin, size_t end, const LeafManager& leafManager, size_t grainSize=1)
146 : mEnd(end)
147 , mBegin(begin)
148 , mGrainSize(grainSize)
149 , mLeafManager(leafManager)
150 {
151 }
152
153 Iterator begin() const {return Iterator(*this, mBegin);}
154
155 Iterator end() const {return Iterator(*this, mEnd);}
156
157 size_t size() const { return mEnd - mBegin; }
158
159 size_t grainsize() const { return mGrainSize; }
160
161 const LeafManager& leafManager() const { return mLeafManager; }
162
163 bool empty() const {return !(mBegin < mEnd);}
164
165 bool is_divisible() const {return mGrainSize < this->size();}
166
167 LeafRange(LeafRange& r, tbb::split)
168 : mEnd(r.mEnd)
169 , mBegin(doSplit(r))
170 , mGrainSize(r.mGrainSize)
171 , mLeafManager(r.mLeafManager)
172 {
173 }
174
175 private:
176 size_t mEnd, mBegin, mGrainSize;
177 const LeafManager& mLeafManager;
178
179 static size_t doSplit(LeafRange& r)
180 {
181 assert(r.is_divisible());
182 size_t middle = r.mBegin + (r.mEnd - r.mBegin) / 2u;
183 r.mEnd = middle;
184 return middle;
185 }
186 };// end of LeafRange
187
190 LeafManager(TreeType& tree, size_t auxBuffersPerLeaf=0, bool serial=false)
191 : mTree(&tree)
192 , mLeafCount(0)
193 , mAuxBufferCount(0)
194 , mAuxBuffersPerLeaf(auxBuffersPerLeaf)
195 , mLeafs(nullptr)
196 , mAuxBuffers(nullptr)
197 , mTask(nullptr)
198 , mIsMaster(true)
199 {
200 this->rebuild(serial);
201 }
202
206 LeafManager(TreeType& tree, LeafType** begin, LeafType** end,
207 size_t auxBuffersPerLeaf=0, bool serial=false)
208 : mTree(&tree)
209 , mLeafCount(end-begin)
210 , mAuxBufferCount(0)
211 , mAuxBuffersPerLeaf(auxBuffersPerLeaf)
212 , mLeafs(new LeafType*[mLeafCount])
213 , mAuxBuffers(nullptr)
214 , mTask(nullptr)
215 , mIsMaster(true)
216 {
217 size_t n = mLeafCount;
218 LeafType **target = mLeafs, **source = begin;
219 while (n--) *target++ = *source++;
220 if (auxBuffersPerLeaf) this->initAuxBuffers(serial);
221 }
222
226 LeafManager(const LeafManager& other)
227 : mTree(other.mTree)
228 , mLeafCount(other.mLeafCount)
229 , mAuxBufferCount(other.mAuxBufferCount)
230 , mAuxBuffersPerLeaf(other.mAuxBuffersPerLeaf)
231 , mLeafs(other.mLeafs)
232 , mAuxBuffers(other.mAuxBuffers)
233 , mTask(other.mTask)
234 , mIsMaster(false)
235 {
236 }
237
238 virtual ~LeafManager()
239 {
240 if (mIsMaster) {
241 delete [] mLeafs;
242 delete [] mAuxBuffers;
243 }
244 }
245
251 void rebuild(bool serial=false)
252 {
253 this->initLeafArray();
254 this->initAuxBuffers(serial);
255 }
257 void rebuild(size_t auxBuffersPerLeaf, bool serial=false)
259 {
260 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
261 this->rebuild(serial);
262 }
263 void rebuild(TreeType& tree, bool serial=false)
264 {
265 mTree = &tree;
266 this->rebuild(serial);
267 }
268 void rebuild(TreeType& tree, size_t auxBuffersPerLeaf, bool serial=false)
269 {
270 mTree = &tree;
271 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
272 this->rebuild(serial);
273 }
275 void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
280 {
281 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
282 this->initAuxBuffers(serial);
283 }
285 void removeAuxBuffers() { this->rebuildAuxBuffers(0); }
286
288 void rebuildLeafArray()
289 {
290 this->removeAuxBuffers();
291 this->initLeafArray();
292 }
293
295 size_t auxBufferCount() const { return mAuxBufferCount; }
297 size_t auxBuffersPerLeaf() const { return mAuxBuffersPerLeaf; }
298
300 size_t leafCount() const { return mLeafCount; }
301
304 Index64 activeLeafVoxelCount() const
305 {
306 return tbb::parallel_reduce(this->leafRange(), Index64(0),
307 [] (const LeafRange& range, Index64 sum) -> Index64 {
308 for (const auto& leaf: range) { sum += leaf.onVoxelCount(); }
309 return sum;
310 },
311 [] (Index64 n, Index64 m) -> Index64 { return n + m; });
312 }
313
315 const TreeType& tree() const { return *mTree; }
316
318 TreeType& tree() { return *mTree; }
319
321 const RootNodeType& root() const { return mTree->root(); }
322
324 RootNodeType& root() { return mTree->root(); }
325
327 bool isConstTree() const { return this->IsConstTree; }
328
331 LeafType& leaf(size_t leafIdx) const { assert(leafIdx<mLeafCount); return *mLeafs[leafIdx]; }
332
343 BufferType& getBuffer(size_t leafIdx, size_t bufferIdx) const
344 {
345 assert(leafIdx < mLeafCount);
346 assert(bufferIdx == 0 || bufferIdx - 1 < mAuxBuffersPerLeaf);
347 return bufferIdx == 0 ? mLeafs[leafIdx]->buffer()
348 : mAuxBuffers[leafIdx * mAuxBuffersPerLeaf + bufferIdx - 1];
349 }
350
355 RangeType getRange(size_t grainsize = 1) const { return RangeType(0, mLeafCount, grainsize); }
356
358 LeafRange leafRange(size_t grainsize = 1) const
359 {
360 return LeafRange(0, mLeafCount, *this, grainsize);
361 }
362
372 bool swapLeafBuffer(size_t bufferIdx, bool serial = false)
373 {
374 namespace ph = std::placeholders;
375 if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf || this->isConstTree()) return false;
376 mTask = std::bind(&LeafManager::doSwapLeafBuffer, ph::_1, ph::_2, bufferIdx - 1);
377 this->cook(serial ? 0 : 512);
378 return true;//success
379 }
384 bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial = false)
385 {
386 namespace ph = std::placeholders;
387 const size_t b1 = std::min(bufferIdx1, bufferIdx2);
388 const size_t b2 = std::max(bufferIdx1, bufferIdx2);
389 if (b1 == b2 || b2 > mAuxBuffersPerLeaf) return false;
390 if (b1 == 0) {
391 if (this->isConstTree()) return false;
392 mTask = std::bind(&LeafManager::doSwapLeafBuffer, ph::_1, ph::_2, b2-1);
393 } else {
394 mTask = std::bind(&LeafManager::doSwapAuxBuffer, ph::_1, ph::_2, b1-1, b2-1);
395 }
396 this->cook(serial ? 0 : 512);
397 return true;//success
398 }
399
408 bool syncAuxBuffer(size_t bufferIdx, bool serial = false)
409 {
410 namespace ph = std::placeholders;
411 if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf) return false;
412 mTask = std::bind(&LeafManager::doSyncAuxBuffer, ph::_1, ph::_2, bufferIdx - 1);
413 this->cook(serial ? 0 : 64);
414 return true;//success
415 }
416
420 bool syncAllBuffers(bool serial = false)
421 {
422 namespace ph = std::placeholders;
423 switch (mAuxBuffersPerLeaf) {
424 case 0: return false;//nothing to do
425 case 1: mTask = std::bind(&LeafManager::doSyncAllBuffers1, ph::_1, ph::_2); break;
426 case 2: mTask = std::bind(&LeafManager::doSyncAllBuffers2, ph::_1, ph::_2); break;
427 default: mTask = std::bind(&LeafManager::doSyncAllBuffersN, ph::_1, ph::_2); break;
428 }
429 this->cook(serial ? 0 : 64);
430 return true;//success
431 }
432
495 template<typename LeafOp>
496 void foreach(const LeafOp& op, bool threaded = true, size_t grainSize=1)
497 {
498 LeafTransformer<LeafOp> transform(op);
499 transform.run(this->leafRange(grainSize), threaded);
500 }
501
544 template<typename LeafOp>
545 void reduce(LeafOp& op, bool threaded = true, size_t grainSize=1)
546 {
547 LeafReducer<LeafOp> transform(op);
548 transform.run(this->leafRange(grainSize), threaded);
549 }
550
551
556 template<typename ArrayT>
557 void getNodes(ArrayT& array)
558 {
559 using T = typename ArrayT::value_type;
560 static_assert(std::is_pointer<T>::value, "argument to getNodes() must be a pointer array");
561 using LeafT = typename std::conditional<std::is_const<
562 typename std::remove_pointer<T>::type>::value, const LeafType, LeafType>::type;
563
564 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
565 if (std::is_same<T, LeafT*>::value) {
566 array.resize(mLeafCount);
567 for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
568 } else {
569 mTree->getNodes(array);
570 }
571 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
572 }
573
578 template<typename ArrayT>
579 void getNodes(ArrayT& array) const
580 {
581 using T = typename ArrayT::value_type;
582 static_assert(std::is_pointer<T>::value, "argument to getNodes() must be a pointer array");
583 static_assert(std::is_const<typename std::remove_pointer<T>::type>::value,
584 "argument to getNodes() must be an array of const node pointers");
585
586 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
587 if (std::is_same<T, const LeafType*>::value) {
588 array.resize(mLeafCount);
589 for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
590 } else {
591 mTree->getNodes(array);
592 }
593 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
594 }
595
607 size_t getPrefixSum(size_t*& offsets, size_t& size, size_t grainSize=1) const
608 {
609 if (offsets == nullptr || size < mLeafCount) {
610 delete [] offsets;
611 offsets = new size_t[mLeafCount];
612 size = mLeafCount;
613 }
614 size_t prefix = 0;
615 if ( grainSize > 0 ) {
616 PrefixSum tmp(this->leafRange( grainSize ), offsets, prefix);
617 } else {// serial
618 for (size_t i=0; i<mLeafCount; ++i) {
619 offsets[i] = prefix;
620 prefix += mLeafs[i]->onVoxelCount();
621 }
622 }
623 return prefix;
624 }
625
627 // All methods below are for internal use only and should never be called directly
628
630 void operator()(const RangeType& r) const
631 {
632 if (mTask) mTask(const_cast<LeafManager*>(this), r);
633 else OPENVDB_THROW(ValueError, "task is undefined");
634 }
635
636 private:
637
638 // This a simple wrapper for a c-style array so it mimics the api
639 // of a std container, e.g. std::vector or std::deque, and can be
640 // passed to Tree::getNodes().
641 struct MyArray {
642 using value_type = LeafType*;//required by Tree::getNodes
643 value_type* ptr;
644 MyArray(value_type* array) : ptr(array) {}
645 void push_back(value_type leaf) { *ptr++ = leaf; }//required by Tree::getNodes
646 };
647
648 void initLeafArray()
649 {
650 const size_t leafCount = mTree->leafCount();
651 if (leafCount != mLeafCount) {
652 delete [] mLeafs;
653 mLeafs = (leafCount == 0) ? nullptr : new LeafType*[leafCount];
654 mLeafCount = leafCount;
655 }
656 MyArray a(mLeafs);
657 mTree->getNodes(a);
658 }
659
660 void initAuxBuffers(bool serial)
661 {
662 const size_t auxBufferCount = mLeafCount * mAuxBuffersPerLeaf;
663 if (auxBufferCount != mAuxBufferCount) {
664 delete [] mAuxBuffers;
665 mAuxBuffers = (auxBufferCount == 0) ? nullptr : new NonConstBufferType[auxBufferCount];
666 mAuxBufferCount = auxBufferCount;
667 }
668 this->syncAllBuffers(serial);
669 }
670
671 void cook(size_t grainsize)
672 {
673 if (grainsize>0) {
674 tbb::parallel_for(this->getRange(grainsize), *this);
675 } else {
676 (*this)(this->getRange());
677 }
678 }
679
680 void doSwapLeafBuffer(const RangeType& r, size_t auxBufferIdx)
681 {
682 LeafManagerImpl<LeafManager>::doSwapLeafBuffer(
683 r, auxBufferIdx, mLeafs, mAuxBuffers, mAuxBuffersPerLeaf);
684 }
685
686 void doSwapAuxBuffer(const RangeType& r, size_t auxBufferIdx1, size_t auxBufferIdx2)
687 {
688 for (size_t N = mAuxBuffersPerLeaf, n = N*r.begin(), m = N*r.end(); n != m; n+=N) {
689 mAuxBuffers[n + auxBufferIdx1].swap(mAuxBuffers[n + auxBufferIdx2]);
690 }
691 }
692
693 void doSyncAuxBuffer(const RangeType& r, size_t auxBufferIdx)
694 {
695 for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
696 mAuxBuffers[n*N + auxBufferIdx] = mLeafs[n]->buffer();
697 }
698 }
699
700 void doSyncAllBuffers1(const RangeType& r)
701 {
702 for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
703 mAuxBuffers[n] = mLeafs[n]->buffer();
704 }
705 }
706
707 void doSyncAllBuffers2(const RangeType& r)
708 {
709 for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
710 const BufferType& leafBuffer = mLeafs[n]->buffer();
711 mAuxBuffers[2*n ] = leafBuffer;
712 mAuxBuffers[2*n+1] = leafBuffer;
713 }
714 }
715
716 void doSyncAllBuffersN(const RangeType& r)
717 {
718 for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
719 const BufferType& leafBuffer = mLeafs[n]->buffer();
720 for (size_t i=n*N, j=i+N; i!=j; ++i) mAuxBuffers[i] = leafBuffer;
721 }
722 }
723
726 template<typename LeafOp>
727 struct LeafTransformer
728 {
729 LeafTransformer(const LeafOp &leafOp) : mLeafOp(leafOp)
730 {
731 }
732 void run(const LeafRange &range, bool threaded) const
733 {
734 threaded ? tbb::parallel_for(range, *this) : (*this)(range);
735 }
736 void operator()(const LeafRange &range) const
737 {
738 for (typename LeafRange::Iterator it = range.begin(); it; ++it) mLeafOp(*it, it.pos());
739 }
740 const LeafOp mLeafOp;
741 };// LeafTransformer
742
745 template<typename LeafOp>
746 struct LeafReducer
747 {
748 LeafReducer(LeafOp &leafOp) : mLeafOp(&leafOp), mOwnsOp(false)
749 {
750 }
751 LeafReducer(const LeafReducer &other, tbb::split)
752 : mLeafOp(new LeafOp(*(other.mLeafOp), tbb::split())), mOwnsOp(true)
753 {
754 }
755 ~LeafReducer() { if (mOwnsOp) delete mLeafOp; }
756 void run(const LeafRange& range, bool threaded)
757 {
758 threaded ? tbb::parallel_reduce(range, *this) : (*this)(range);
759 }
760 void operator()(const LeafRange& range)
761 {
762 LeafOp &op = *mLeafOp;//local registry
763 for (typename LeafRange::Iterator it = range.begin(); it; ++it) op(*it, it.pos());
764 }
765 void join(const LeafReducer& other) { mLeafOp->join(*(other.mLeafOp)); }
766 LeafOp *mLeafOp;
767 const bool mOwnsOp;
768 };// LeafReducer
769
770 // Helper class to compute a prefix sum of offsets to active voxels
771 struct PrefixSum
772 {
773 PrefixSum(const LeafRange& r, size_t* offsets, size_t& prefix)
774 : mOffsets(offsets)
775 {
776 tbb::parallel_for( r, *this);
777 for (size_t i=0, leafCount = r.size(); i<leafCount; ++i) {
778 size_t tmp = offsets[i];
779 offsets[i] = prefix;
780 prefix += tmp;
781 }
782 }
783 inline void operator()(const LeafRange& r) const {
784 for (typename LeafRange::Iterator i = r.begin(); i; ++i) {
785 mOffsets[i.pos()] = i->onVoxelCount();
786 }
787 }
788 size_t* mOffsets;
789 };// PrefixSum
790
791 using FuncType = typename std::function<void (LeafManager*, const RangeType&)>;
792
793 TreeType* mTree;
794 size_t mLeafCount, mAuxBufferCount, mAuxBuffersPerLeaf;
795 LeafType** mLeafs;//array of LeafNode pointers
796 NonConstBufferType* mAuxBuffers;//array of auxiliary buffers
797 FuncType mTask;
798 const bool mIsMaster;
799 };//end of LeafManager class
800
801
802 // Partial specializations of LeafManager methods for const trees
803 template<typename TreeT>
804 struct LeafManagerImpl<LeafManager<const TreeT> >
805 {
806 using ManagerT = LeafManager<const TreeT>;
807 using RangeT = typename ManagerT::RangeType;
808 using LeafT = typename ManagerT::LeafType;
809 using BufT = typename ManagerT::BufferType;
810
811 static inline void doSwapLeafBuffer(const RangeT&, size_t /*auxBufferIdx*/,
812 LeafT**, BufT*, size_t /*bufsPerLeaf*/)
813 {
814 // Buffers can't be swapped into const trees.
815 }
816 };
817
818 } // namespace tree
819 } // namespace OPENVDB_VERSION_NAME
820 } // namespace openvdb
821
822 #endif // OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
openvdb::v7_0::tree::LeafManager::swapBuffer
bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial=false)
Swap any two buffers for each leaf node.
Definition: LeafManager.h:384
openvdb::v7_0::tree::LeafManager::LeafManager
LeafManager(TreeType &tree, LeafType **begin, LeafType **end, size_t auxBuffersPerLeaf=0, bool serial=false)
Construct directly from an existing array of leafnodes.
Definition: LeafManager.h:206
openvdb::v7_0::tree::LeafManager::LeafRange::begin
Iterator begin() const
Definition: LeafManager.h:153
openvdb::v7_0::tree::LeafManager::root
const RootNodeType & root() const
Return a const reference to root node associated with this manager.
Definition: LeafManager.h:321
openvdb::v7_0::tree::LeafManager::reduce
void reduce(LeafOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager....
Definition: LeafManager.h:545
openvdb::v7_0::tree::LeafManager::getNodes
void getNodes(ArrayT &array)
Insert pointers to nodes of the specified type into the array.
Definition: LeafManager.h:557
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::empty
bool empty() const
Return true if this iterator is exhausted.
Definition: LeafManager.h:132
openvdb::v7_0::math::operator*
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:618
openvdb::v7_0::tree::LeafManager::LeafRange::LeafRange
LeafRange(LeafRange &r, tbb::split)
Definition: LeafManager.h:167
openvdb::v7_0::tree::LeafManagerImpl::LeafT
typename ManagerT::LeafType LeafT
Definition: LeafManager.h:54
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::isValid
bool isValid() const
Return true if the position of this iterator is in a valid range.
Definition: LeafManager.h:126
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::operator*
LeafType & operator*() const
Return a reference to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:114
openvdb::v7_0::tree::LeafManager::activeLeafVoxelCount
Index64 activeLeafVoxelCount() const
Return the number of active voxels in the leaf nodes.
Definition: LeafManager.h:304
openvdb::v7_0::tree::LeafManager::swapLeafBuffer
bool swapLeafBuffer(size_t bufferIdx, bool serial=false)
Swap each leaf node's buffer with the nth corresponding auxiliary buffer, where n = bufferIdx.
Definition: LeafManager.h:372
Types.h
openvdb::v7_0::tree::LeafManager::TreeType
TreeT TreeType
Definition: LeafManager.h:85
openvdb::v7_0::tree::LeafManager::NonConstLeafType
typename TreeType::LeafNodeType NonConstLeafType
Definition: LeafManager.h:88
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::buffer
BufferType & buffer(size_t bufferIdx)
Return the nth buffer for the leaf node to which this iterator is pointing, where n = bufferIdx and n...
Definition: LeafManager.h:119
openvdb::v7_0::tree::LeafManager::leafRange
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:358
openvdb::v7_0::tree::LeafManager::BufferType
typename CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:93
openvdb::v7_0::tree::LeafManager::tree
TreeType & tree()
Return a reference to the tree associated with this manager.
Definition: LeafManager.h:318
openvdb::v7_0::tree::LeafManager::rebuildLeafArray
void rebuildLeafArray()
Remove the auxiliary buffers and rebuild the leaf array.
Definition: LeafManager.h:288
openvdb::v7_0::tree::LeafManager::LeafRange::leafManager
const LeafManager & leafManager() const
Definition: LeafManager.h:161
tbb
Definition: Coord.h:16
openvdb::v7_0::tree::LeafManager::NonConstBufferType
typename LeafType::Buffer NonConstBufferType
Definition: LeafManager.h:92
openvdb::v7_0::tree::LeafManager::LeafRange::grainsize
size_t grainsize() const
Definition: LeafManager.h:159
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition: LeafManager.h:133
openvdb::v7_0::tree::LeafManager::rebuild
void rebuild(TreeType &tree, size_t auxBuffersPerLeaf, bool serial=false)
Definition: LeafManager.h:268
openvdb::v7_0::tree::LeafManager::LeafRange::LeafRange
LeafRange(size_t begin, size_t end, const LeafManager &leafManager, size_t grainSize=1)
Definition: LeafManager.h:145
openvdb::v7_0::tree::LeafManager::syncAllBuffers
bool syncAllBuffers(bool serial=false)
Sync up all auxiliary buffers with their corresponding leaf node buffers.
Definition: LeafManager.h:420
openvdb::v7_0::tree::LeafManagerImpl
Definition: LeafManager.h:51
openvdb::v7_0::tree::LeafManager::LeafManager
LeafManager(TreeType &tree, size_t auxBuffersPerLeaf=0, bool serial=false)
Constructor from a tree reference and an auxiliary buffer count.
Definition: LeafManager.h:190
openvdb::v7_0::tree::LeafManager::LeafIterType
typename leafmgr::TreeTraits< TreeT >::LeafIterType LeafIterType
Definition: LeafManager.h:91
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::operator++
Iterator & operator++()
Advance to the next leaf node.
Definition: LeafManager.h:112
openvdb::v7_0::tree::LeafManager::auxBufferCount
size_t auxBufferCount() const
Return the total number of allocated auxiliary buffers.
Definition: LeafManager.h:295
openvdb::v7_0::tree::LeafManagerImpl::RangeT
typename ManagerT::RangeType RangeT
Definition: LeafManager.h:53
openvdb::v7_0::tree::LeafManagerImpl::doSwapLeafBuffer
static void doSwapLeafBuffer(const RangeT &r, size_t auxBufferIdx, LeafT **leafs, BufT *bufs, size_t bufsPerLeaf)
Definition: LeafManager.h:57
openvdb::v7_0::tree::LeafManager::LeafRange::size
size_t size() const
Definition: LeafManager.h:157
openvdb::v7_0::tree::LeafManager::leaf
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:331
openvdb::v7_0::tree::LeafManager::LeafRange
Definition: LeafManager.h:99
openvdb::v7_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::BufT
typename ManagerT::BufferType BufT
Definition: LeafManager.h:809
openvdb::v7_0::tree::LeafManagerImpl::BufT
typename ManagerT::BufferType BufT
Definition: LeafManager.h:55
openvdb::v7_0::tree::LeafManager::rebuild
void rebuild(TreeType &tree, bool serial=false)
Definition: LeafManager.h:263
openvdb::v7_0::tree::LeafManager::RangeType
tbb::blocked_range< size_t > RangeType
Definition: LeafManager.h:94
openvdb::v7_0::tree::LeafManager::syncAuxBuffer
bool syncAuxBuffer(size_t bufferIdx, bool serial=false)
Sync up the specified auxiliary buffer with the corresponding leaf node buffer.
Definition: LeafManager.h:408
openvdb::v7_0::tree::LeafManager::rebuild
void rebuild(bool serial=false)
(Re)initialize by resizing (if necessary) and repopulating the leaf array and by deleting existing au...
Definition: LeafManager.h:251
openvdb::v7_0::tree::LeafManager::RootNodeType
typename TreeT::RootNodeType RootNodeType
Definition: LeafManager.h:87
openvdb::v7_0::tree::LeafManager::tree
const TreeType & tree() const
Return a const reference to tree associated with this manager.
Definition: LeafManager.h:315
openvdb::v7_0::tree::LeafManager::getBuffer
BufferType & getBuffer(size_t leafIdx, size_t bufferIdx) const
Return the leaf or auxiliary buffer for the leaf node at index leafIdx. If bufferIdx is zero,...
Definition: LeafManager.h:343
openvdb::v7_0::tree::LeafManager
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
openvdb::v7_0::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:106
openvdb::v7_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::LeafT
typename ManagerT::LeafType LeafT
Definition: LeafManager.h:808
openvdb::v7_0::tree::LeafManager::ValueType
typename TreeT::ValueType ValueType
Definition: LeafManager.h:86
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
SIMD Intrinsic Headers.
Definition: Platform.h:114
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::operator->
LeafType * operator->() const
Return a pointer to the leaf node to which this iterator is pointing.
Definition: LeafManager.h:116
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator
Definition: LeafManager.h:102
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::test
bool test() const
Return true if this iterator is not yet exhausted.
Definition: LeafManager.h:128
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::pos
size_t pos() const
Return the index into the leaf array of the current leaf node.
Definition: LeafManager.h:124
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::operator==
bool operator==(const Iterator &other) const
Definition: LeafManager.h:137
openvdb::v7_0::tree::LeafManager::~LeafManager
virtual ~LeafManager()
Definition: LeafManager.h:238
openvdb::v7_0::tree::LeafManager::LeafNodeType
LeafType LeafNodeType
Definition: LeafManager.h:90
openvdb::v7_0::tree::LeafManager::operator()
void operator()(const RangeType &r) const
Used internally by tbb::parallel_for() - never call it directly!
Definition: LeafManager.h:630
openvdb::v7_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:102
openvdb::v7_0::tree::LeafManager::isConstTree
bool isConstTree() const
Return true if the tree associated with this manager is immutable.
Definition: LeafManager.h:327
openvdb::v7_0::Index
Index32 Index
Definition: Types.h:31
openvdb::v7_0::tree::leafmgr::TreeTraits
Useful traits for Tree types.
Definition: LeafManager.h:35
openvdb::v7_0::tree::LeafManager::LeafRange::is_divisible
bool is_divisible() const
Definition: LeafManager.h:165
openvdb::v7_0::CopyConstness::Type
typename std::remove_const< ToType >::type Type
Definition: Types.h:298
openvdb::v7_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::RangeT
typename ManagerT::RangeType RangeT
Definition: LeafManager.h:807
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:115
openvdb::v7_0::tree::LeafManager::getPrefixSum
size_t getPrefixSum(size_t *&offsets, size_t &size, size_t grainSize=1) const
Generate a linear array of prefix sums of offsets into the active voxels in the leafs....
Definition: LeafManager.h:607
openvdb::v7_0::tree::LeafManager::LeafManager
LeafManager(const LeafManager &other)
Definition: LeafManager.h:226
openvdb::v7_0::ValueError
Definition: Exceptions.h:65
openvdb::v7_0::tree::LeafManager::LeafType
typename CopyConstness< TreeType, NonConstLeafType >::Type LeafType
Definition: LeafManager.h:89
openvdb::v7_0::tree::LeafManager::root
RootNodeType & root()
Return a reference to the root node associated with this manager.
Definition: LeafManager.h:324
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::leafRange
const LeafRange & leafRange() const
Definition: LeafManager.h:138
openvdb::v7_0::tree::LeafManager::leafCount
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:300
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::Index64
uint64_t Index64
Definition: Types.h:30
openvdb::v7_0::tree::LeafManager::auxBuffersPerLeaf
size_t auxBuffersPerLeaf() const
Return the number of auxiliary buffers per leaf node.
Definition: LeafManager.h:297
openvdb::v7_0::tree::leafmgr::TreeTraits< const TreeT >::LeafIterType
typename TreeT::LeafCIter LeafIterType
Definition: LeafManager.h:41
openvdb::v7_0::tree::LeafManager::getRange
RangeType getRange(size_t grainsize=1) const
Return a tbb::blocked_range of leaf array indices.
Definition: LeafManager.h:355
openvdb::v7_0::tree::LeafManager::LeafRange::end
Iterator end() const
Definition: LeafManager.h:155
openvdb::v7_0::tree::LeafManager::LeafRange::empty
bool empty() const
Definition: LeafManager.h:163
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
openvdb::v7_0::tree::LeafManager::removeAuxBuffers
void removeAuxBuffers()
Remove the auxiliary buffers, but don't rebuild the leaf array.
Definition: LeafManager.h:285
openvdb::v7_0::tree::LeafManager::LeafRange::Iterator::Iterator
Iterator(const LeafRange &range, size_t pos)
Definition: LeafManager.h:105
openvdb::v7_0::tree::LeafManager::getNodes
void getNodes(ArrayT &array) const
Insert node pointers of the specified type into the array.
Definition: LeafManager.h:579
openvdb::v7_0::tree::leafmgr::TreeTraits::LeafIterType
typename TreeT::LeafIter LeafIterType
Definition: LeafManager.h:37
openvdb::v7_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::doSwapLeafBuffer
static void doSwapLeafBuffer(const RangeT &, size_t, LeafT **, BufT *, size_t)
Definition: LeafManager.h:811