OpenVDB: LeafManager.h Source File

OpenVDB 3.2.0

LeafManager.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
41
42 #ifndef OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
43 #define OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
44
45 #include <boost/shared_ptr.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/function.hpp>
48 #include <boost/mpl/if.hpp>
49 #include <boost/type_traits/is_const.hpp>
50 #include <boost/type_traits/is_pointer.hpp>
51 #include <boost/type_traits/is_same.hpp>
52 #include <boost/type_traits/remove_pointer.hpp>
53 #include <tbb/blocked_range.h>
54 #include <tbb/parallel_for.h>
55 #include <tbb/parallel_reduce.h>
56 #include <openvdb/Types.h>
57 #include "TreeIterator.h" // for CopyConstness
58
59 namespace openvdb {
60 OPENVDB_USE_VERSION_NAMESPACE
61 namespace OPENVDB_VERSION_NAME {
62 namespace tree {
63
64 namespace leafmgr {
65
67 template<typename TreeT> struct TreeTraits {
69 static const bool IsConstTree = false;
70 typedef typename TreeT::LeafIter LeafIterType;
71 };
72 template<typename TreeT> struct TreeTraits<const TreeT> {
73 static const bool IsConstTree = true;
74 typedef typename TreeT::LeafCIter LeafIterType;
75 };
77
78 } // namespace leafmgr
79
80
83 template<typename ManagerT>
84 struct LeafManagerImpl
85 {
86 typedef typename ManagerT::RangeType RangeT;
87 typedef typename ManagerT::LeafType LeafT;
88 typedef typename ManagerT::BufferType BufT;
89
90 static inline void doSwapLeafBuffer(const RangeT& r, size_t auxBufferIdx,
91 LeafT** leafs, BufT* bufs, size_t bufsPerLeaf)
92 {
93 for (size_t n = r.begin(), m = r.end(), N = bufsPerLeaf; n != m; ++n) {
94 leafs[n]->swap(bufs[n * N + auxBufferIdx]);
95 }
96 }
97 };
98
99
101
102
114 template<typename TreeT>
115 class LeafManager
116 {
117 public:
118 typedef TreeT TreeType;
119 typedef typename TreeT::ValueType ValueType;
120 typedef typename TreeT::RootNodeType RootNodeType;
121 typedef typename TreeType::LeafNodeType NonConstLeafType;
122 typedef typename CopyConstness<TreeType, NonConstLeafType>::Type LeafType;
123 typedef LeafType LeafNodeType;
124 typedef typename leafmgr::TreeTraits<TreeT>::LeafIterType LeafIterType;
125 typedef typename LeafType::Buffer NonConstBufferType;
126 typedef typename CopyConstness<TreeType, NonConstBufferType>::Type BufferType;
127 typedef tbb::blocked_range<size_t> RangeType;//leaf index range
128 static const Index DEPTH = 2;//root + leafs
129
130 static const bool IsConstTree = leafmgr::TreeTraits<TreeT>::IsConstTree;
131
132 class LeafRange
133 {
134 public:
135 class Iterator
136 {
137 public:
138 Iterator(const LeafRange& range, size_t pos): mRange(range), mPos(pos)
139 {
140 assert(this->isValid());
141 }
142 Iterator& operator=(const Iterator& other)
143 {
144 mRange = other.mRange; mPos = other.mPos; return *this;
145 }
147 Iterator& operator++() { ++mPos; return *this; }
149 LeafType& operator*() const { return mRange.mLeafManager.leaf(mPos); }
151 LeafType* operator->() const { return &(this->operator*()); }
154 BufferType& buffer(size_t bufferIdx)
155 {
156 return mRange.mLeafManager.getBuffer(mPos, bufferIdx);
157 }
159 size_t pos() const { return mPos; }
161 bool isValid() const { return mPos>=mRange.mBegin && mPos<=mRange.mEnd; }
163 bool test() const { return mPos < mRange.mEnd; }
165 operator bool() const { return this->test(); }
167 bool empty() const { return !this->test(); }
168 bool operator!=(const Iterator& other) const
169 {
170 return (mPos != other.mPos) || (&mRange != &other.mRange);
171 }
172 bool operator==(const Iterator& other) const { return !(*this != other); }
173 const LeafRange& leafRange() const { return mRange; }
174
175 private:
176 const LeafRange& mRange;
177 size_t mPos;
178 };// end Iterator
179
180 LeafRange(size_t begin, size_t end, const LeafManager& leafManager, size_t grainSize=1)
181 : mEnd(end)
182 , mBegin(begin)
183 , mGrainSize(grainSize)
184 , mLeafManager(leafManager)
185 {
186 }
187
188 Iterator begin() const {return Iterator(*this, mBegin);}
189
190 Iterator end() const {return Iterator(*this, mEnd);}
191
192 size_t size() const { return mEnd - mBegin; }
193
194 size_t grainsize() const { return mGrainSize; }
195
196 const LeafManager& leafManager() const { return mLeafManager; }
197
198 bool empty() const {return !(mBegin < mEnd);}
199
200 bool is_divisible() const {return mGrainSize < this->size();}
201
202 LeafRange(LeafRange& r, tbb::split)
203 : mEnd(r.mEnd)
204 , mBegin(doSplit(r))
205 , mGrainSize(r.mGrainSize)
206 , mLeafManager(r.mLeafManager)
207 {
208 }
209
210 private:
211 size_t mEnd, mBegin, mGrainSize;
212 const LeafManager& mLeafManager;
213
214 static size_t doSplit(LeafRange& r)
215 {
216 assert(r.is_divisible());
217 size_t middle = r.mBegin + (r.mEnd - r.mBegin) / 2u;
218 r.mEnd = middle;
219 return middle;
220 }
221 };// end of LeafRange
222
225 LeafManager(TreeType& tree, size_t auxBuffersPerLeaf=0, bool serial=false)
226 : mTree(&tree)
227 , mLeafCount(0)
228 , mAuxBufferCount(0)
229 , mAuxBuffersPerLeaf(auxBuffersPerLeaf)
230 , mLeafs(NULL)
231 , mAuxBuffers(NULL)
232 , mTask(0)
233 , mIsMaster(true)
234 {
235 this->rebuild(serial);
236 }
237
241 LeafManager(TreeType& tree, LeafType** begin, LeafType** end,
242 size_t auxBuffersPerLeaf=0, bool serial=false)
243 : mTree(&tree)
244 , mLeafCount(end-begin)
245 , mAuxBufferCount(0)
246 , mAuxBuffersPerLeaf(auxBuffersPerLeaf)
247 , mLeafs(new LeafType*[mLeafCount])
248 , mAuxBuffers(NULL)
249 , mTask(0)
250 , mIsMaster(true)
251 {
252 size_t n = mLeafCount;
253 LeafType **target = mLeafs, **source = begin;
254 while (n--) *target++ = *source++;
255 if (auxBuffersPerLeaf) this->initAuxBuffers(serial);
256 }
257
261 LeafManager(const LeafManager& other)
262 : mTree(other.mTree)
263 , mLeafCount(other.mLeafCount)
264 , mAuxBufferCount(other.mAuxBufferCount)
265 , mAuxBuffersPerLeaf(other.mAuxBuffersPerLeaf)
266 , mLeafs(other.mLeafs)
267 , mAuxBuffers(other.mAuxBuffers)
268 , mTask(other.mTask)
269 , mIsMaster(false)
270 {
271 }
272
273 virtual ~LeafManager()
274 {
275 if (mIsMaster) {
276 delete [] mLeafs;
277 delete [] mAuxBuffers;
278 }
279 }
280
286 void rebuild(bool serial=false)
287 {
288 this->initLeafArray();
289 this->initAuxBuffers(serial);
290 }
292 void rebuild(size_t auxBuffersPerLeaf, bool serial=false)
294 {
295 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
296 this->rebuild(serial);
297 }
298 void rebuild(TreeType& tree, bool serial=false)
299 {
300 mTree = &tree;
301 this->rebuild(serial);
302 }
303 void rebuild(TreeType& tree, size_t auxBuffersPerLeaf, bool serial=false)
304 {
305 mTree = &tree;
306 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
307 this->rebuild(serial);
308 }
310 void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
315 {
316 mAuxBuffersPerLeaf = auxBuffersPerLeaf;
317 this->initAuxBuffers(serial);
318 }
320 void removeAuxBuffers() { this->rebuildAuxBuffers(0); }
321
323 void rebuildLeafArray()
324 {
325 this->removeAuxBuffers();
326 this->initLeafArray();
327 }
328
330 size_t auxBufferCount() const { return mAuxBufferCount; }
332 size_t auxBuffersPerLeaf() const { return mAuxBuffersPerLeaf; }
333
335 size_t leafCount() const { return mLeafCount; }
336
338 const TreeType& tree() const { return *mTree; }
339
341 TreeType& tree() { return *mTree; }
342
344 const RootNodeType& root() const { return mTree->root(); }
345
347 RootNodeType& root() { return mTree->root(); }
348
350 bool isConstTree() const { return this->IsConstTree; }
351
354 LeafType& leaf(size_t leafIdx) const { assert(leafIdx<mLeafCount); return *mLeafs[leafIdx]; }
355
366 BufferType& getBuffer(size_t leafIdx, size_t bufferIdx) const
367 {
368 assert(leafIdx < mLeafCount);
369 assert(bufferIdx == 0 || bufferIdx - 1 < mAuxBuffersPerLeaf);
370 return bufferIdx == 0 ? mLeafs[leafIdx]->buffer()
371 : mAuxBuffers[leafIdx * mAuxBuffersPerLeaf + bufferIdx - 1];
372 }
373
378 RangeType getRange(size_t grainsize = 1) const { return RangeType(0, mLeafCount, grainsize); }
379
381 LeafRange leafRange(size_t grainsize = 1) const
382 {
383 return LeafRange(0, mLeafCount, *this, grainsize);
384 }
385
395 bool swapLeafBuffer(size_t bufferIdx, bool serial = false)
396 {
397 if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf || this->isConstTree()) return false;
398 mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, bufferIdx - 1);
399 this->cook(serial ? 0 : 512);
400 return true;//success
401 }
406 bool swapBuffer(size_t bufferIdx1, size_t bufferIdx2, bool serial = false)
407 {
408 const size_t b1 = std::min(bufferIdx1, bufferIdx2);
409 const size_t b2 = std::max(bufferIdx1, bufferIdx2);
410 if (b1 == b2 || b2 > mAuxBuffersPerLeaf) return false;
411 if (b1 == 0) {
412 if (this->isConstTree()) return false;
413 mTask = boost::bind(&LeafManager::doSwapLeafBuffer, _1, _2, b2-1);
414 } else {
415 mTask = boost::bind(&LeafManager::doSwapAuxBuffer, _1, _2, b1-1, b2-1);
416 }
417 this->cook(serial ? 0 : 512);
418 return true;//success
419 }
420
429 bool syncAuxBuffer(size_t bufferIdx, bool serial = false)
430 {
431 if (bufferIdx == 0 || bufferIdx > mAuxBuffersPerLeaf) return false;
432 mTask = boost::bind(&LeafManager::doSyncAuxBuffer, _1, _2, bufferIdx - 1);
433 this->cook(serial ? 0 : 64);
434 return true;//success
435 }
436
440 bool syncAllBuffers(bool serial = false)
441 {
442 switch (mAuxBuffersPerLeaf) {
443 case 0: return false;//nothing to do
444 case 1: mTask = boost::bind(&LeafManager::doSyncAllBuffers1, _1, _2); break;
445 case 2: mTask = boost::bind(&LeafManager::doSyncAllBuffers2, _1, _2); break;
446 default: mTask = boost::bind(&LeafManager::doSyncAllBuffersN, _1, _2); break;
447 }
448 this->cook(serial ? 0 : 64);
449 return true;//success
450 }
451
514 template<typename LeafOp>
515 void foreach(const LeafOp& op, bool threaded = true, size_t grainSize=1)
516 {
517 LeafTransformer<LeafOp> transform(op);
518 transform.run(this->leafRange(grainSize), threaded);
519 }
520
563 template<typename LeafOp>
564 void reduce(LeafOp& op, bool threaded = true, size_t grainSize=1)
565 {
566 LeafReducer<LeafOp> transform(op);
567 transform.run(this->leafRange(grainSize), threaded);
568 }
569
570
575 template<typename ArrayT>
576 void getNodes(ArrayT& array)
577 {
578 typedef typename ArrayT::value_type T;
579 BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
580 typedef typename boost::mpl::if_<boost::is_const<typename boost::remove_pointer<T>::type>,
581 const LeafType, LeafType>::type LeafT;
582
583 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
584 if (boost::is_same<T, LeafT*>::value) {
585 array.resize(mLeafCount);
586 for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
587 } else {
588 mTree->getNodes(array);
589 }
590 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
591 }
592
597 template<typename ArrayT>
598 void getNodes(ArrayT& array) const
599 {
600 typedef typename ArrayT::value_type T;
601 BOOST_STATIC_ASSERT(boost::is_pointer<T>::value);
602 BOOST_STATIC_ASSERT(boost::is_const<typename boost::remove_pointer<T>::type>::value);
603
604 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
605 if (boost::is_same<T, const LeafType*>::value) {
606 array.resize(mLeafCount);
607 for (size_t i=0; i<mLeafCount; ++i) array[i] = reinterpret_cast<T>(mLeafs[i]);
608 } else {
609 mTree->getNodes(array);
610 }
611 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
612 }
613
627 size_t getPreFixSum(size_t*& offsets, size_t& size, size_t grainSize=1) const
628 {
629 if (offsets == NULL || size < mLeafCount) {
630 delete [] offsets;
631 offsets = new size_t[mLeafCount];
632 size = mLeafCount;
633 }
634 size_t prefix = 0;
635 if ( grainSize > 0 ) {
636 PreFixSum tmp(this->leafRange( grainSize ), offsets, prefix);
637 } else {// serial
638 for (size_t i=0; i<mLeafCount; ++i) {
639 offsets[i] = prefix;
640 prefix += mLeafs[i]->onVoxelCount();
641 }
642 }
643 return prefix;
644 }
645
647 // All methods below are for internal use only and should never be called directly
648
650 void operator()(const RangeType& r) const
651 {
652 if (mTask) mTask(const_cast<LeafManager*>(this), r);
653 else OPENVDB_THROW(ValueError, "task is undefined");
654 }
655
656 private:
657
658 // This a simple wrapper for a c-style array so it mimics the api
659 // of a std container, e.g. std::vector or std::deque, and can be
660 // passed to Tree::getNodes().
661 struct MyArray {
662 typedef LeafType* value_type;//required by Tree::getNodes
663 value_type* ptr;
664 MyArray(value_type* array) : ptr(array) {}
665 void push_back(value_type leaf) { *ptr++ = leaf; }//required by Tree::getNodes
666 };
667
668 void initLeafArray()
669 {
670 const size_t leafCount = mTree->leafCount();
671 if (leafCount != mLeafCount) {
672 delete [] mLeafs;
673 mLeafs = (leafCount == 0) ? NULL : new LeafType*[leafCount];
674 mLeafCount = leafCount;
675 }
676 MyArray a(mLeafs);
677 mTree->getNodes(a);
678 }
679
680 void initAuxBuffers(bool serial)
681 {
682 const size_t auxBufferCount = mLeafCount * mAuxBuffersPerLeaf;
683 if (auxBufferCount != mAuxBufferCount) {
684 delete [] mAuxBuffers;
685 mAuxBuffers = (auxBufferCount == 0) ? NULL : new NonConstBufferType[auxBufferCount];
686 mAuxBufferCount = auxBufferCount;
687 }
688 this->syncAllBuffers(serial);
689 }
690
691 void cook(size_t grainsize)
692 {
693 if (grainsize>0) {
694 tbb::parallel_for(this->getRange(grainsize), *this);
695 } else {
696 (*this)(this->getRange());
697 }
698 }
699
700 void doSwapLeafBuffer(const RangeType& r, size_t auxBufferIdx)
701 {
702 LeafManagerImpl<LeafManager>::doSwapLeafBuffer(
703 r, auxBufferIdx, mLeafs, mAuxBuffers, mAuxBuffersPerLeaf);
704 }
705
706 void doSwapAuxBuffer(const RangeType& r, size_t auxBufferIdx1, size_t auxBufferIdx2)
707 {
708 for (size_t N = mAuxBuffersPerLeaf, n = N*r.begin(), m = N*r.end(); n != m; n+=N) {
709 mAuxBuffers[n + auxBufferIdx1].swap(mAuxBuffers[n + auxBufferIdx2]);
710 }
711 }
712
713 void doSyncAuxBuffer(const RangeType& r, size_t auxBufferIdx)
714 {
715 for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
716 mAuxBuffers[n*N + auxBufferIdx] = mLeafs[n]->buffer();
717 }
718 }
719
720 void doSyncAllBuffers1(const RangeType& r)
721 {
722 for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
723 mAuxBuffers[n] = mLeafs[n]->buffer();
724 }
725 }
726
727 void doSyncAllBuffers2(const RangeType& r)
728 {
729 for (size_t n = r.begin(), m = r.end(); n != m; ++n) {
730 const BufferType& leafBuffer = mLeafs[n]->buffer();
731 mAuxBuffers[2*n ] = leafBuffer;
732 mAuxBuffers[2*n+1] = leafBuffer;
733 }
734 }
735
736 void doSyncAllBuffersN(const RangeType& r)
737 {
738 for (size_t n = r.begin(), m = r.end(), N = mAuxBuffersPerLeaf; n != m; ++n) {
739 const BufferType& leafBuffer = mLeafs[n]->buffer();
740 for (size_t i=n*N, j=i+N; i!=j; ++i) mAuxBuffers[i] = leafBuffer;
741 }
742 }
743
746 template<typename LeafOp>
747 struct LeafTransformer
748 {
749 LeafTransformer(const LeafOp &leafOp) : mLeafOp(leafOp)
750 {
751 }
752 void run(const LeafRange &range, bool threaded) const
753 {
754 threaded ? tbb::parallel_for(range, *this) : (*this)(range);
755 }
756 void operator()(const LeafRange &range) const
757 {
758 for (typename LeafRange::Iterator it = range.begin(); it; ++it) mLeafOp(*it, it.pos());
759 }
760 const LeafOp mLeafOp;
761 };// LeafTransformer
762
765 template<typename LeafOp>
766 struct LeafReducer
767 {
768 LeafReducer(LeafOp &leafOp) : mLeafOp(&leafOp), mOwnsOp(false)
769 {
770 }
771 LeafReducer(const LeafReducer &other, tbb::split)
772 : mLeafOp(new LeafOp(*(other.mLeafOp), tbb::split())), mOwnsOp(true)
773 {
774 }
775 ~LeafReducer() { if (mOwnsOp) delete mLeafOp; }
776 void run(const LeafRange& range, bool threaded)
777 {
778 threaded ? tbb::parallel_reduce(range, *this) : (*this)(range);
779 }
780 void operator()(const LeafRange& range)
781 {
782 LeafOp &op = *mLeafOp;//local registry
783 for (typename LeafRange::Iterator it = range.begin(); it; ++it) op(*it, it.pos());
784 }
785 void join(const LeafReducer& other) { mLeafOp->join(*(other.mLeafOp)); }
786 LeafOp *mLeafOp;
787 const bool mOwnsOp;
788 };// LeafReducer
789
790 // Helper class to compute a pre-fix sum of offsets to active voxels
791 struct PreFixSum
792 {
793 PreFixSum(const LeafRange& r, size_t* offsets, size_t& prefix)
794 : mOffsets(offsets)
795 {
796 tbb::parallel_for( r, *this);
797 for (size_t i=0, leafCount = r.size(); i<leafCount; ++i) {
798 size_t tmp = offsets[i];
799 offsets[i] = prefix;
800 prefix += tmp;
801 }
802 }
803 inline void operator()(const LeafRange& r) const {
804 for (typename LeafRange::Iterator i = r.begin(); i; ++i) {
805 mOffsets[i.pos()] = i->onVoxelCount();
806 }
807 }
808 size_t* mOffsets;
809 };// PreFixSum
810
811 typedef typename boost::function<void (LeafManager*, const RangeType&)> FuncType;
812
813 TreeType* mTree;
814 size_t mLeafCount, mAuxBufferCount, mAuxBuffersPerLeaf;
815 LeafType** mLeafs;//array of LeafNode pointers
816 NonConstBufferType* mAuxBuffers;//array of auxiliary buffers
817 FuncType mTask;
818 const bool mIsMaster;
819 };//end of LeafManager class
820
821
822 // Partial specializations of LeafManager methods for const trees
823 template<typename TreeT>
824 struct LeafManagerImpl<LeafManager<const TreeT> >
825 {
826 typedef LeafManager<const TreeT> ManagerT;
827 typedef typename ManagerT::RangeType RangeT;
828 typedef typename ManagerT::LeafType LeafT;
829 typedef typename ManagerT::BufferType BufT;
830
831 static inline void doSwapLeafBuffer(const RangeT&, size_t /*auxBufferIdx*/,
832 LeafT**, BufT*, size_t /*bufsPerLeaf*/)
833 {
834 // Buffers can't be swapped into const trees.
835 }
836 };
837
838 } // namespace tree
839 } // namespace OPENVDB_VERSION_NAME
840 } // namespace openvdb
841
842 #endif // OPENVDB_TREE_LEAFMANAGER_HAS_BEEN_INCLUDED
843
844 // Copyright (c) 2012-2016 DreamWorks Animation LLC
845 // All rights reserved. This software is distributed under the
846 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v3_2_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:406
openvdb::v3_2_0::tree::LeafManagerImpl::LeafT
ManagerT::LeafType LeafT
Definition: LeafManager.h:87
openvdb::v3_2_0::tree::LeafManager::LeafRange::grainsize
size_t grainsize() const
Definition: LeafManager.h:194
openvdb::v3_2_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:159
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::leafRange
const LeafRange & leafRange() const
Definition: LeafManager.h:173
openvdb::v3_2_0::tree::LeafManager::LeafRange::LeafRange
LeafRange(LeafRange &r, tbb::split)
Definition: LeafManager.h:202
openvdb::v3_2_0::tree::LeafManager::LeafRange
Definition: LeafManager.h:132
Types.h
openvdb::v3_2_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::RangeT
ManagerT::RangeType RangeT
Definition: LeafManager.h:827
openvdb::v3_2_0::tree::LeafManager::~LeafManager
virtual ~LeafManager()
Definition: LeafManager.h:273
openvdb::v3_2_0::tree::LeafManagerImpl::RangeT
ManagerT::RangeType RangeT
Definition: LeafManager.h:86
openvdb::v3_2_0::tree::LeafManager::getRange
RangeType getRange(size_t grainsize=1) const
Return a tbb::blocked_range of leaf array indices.
Definition: LeafManager.h:378
openvdb::v3_2_0::tree::LeafManager::rebuildLeafArray
void rebuildLeafArray()
Remove the auxiliary buffers and rebuild the leaf array.
Definition: LeafManager.h:323
openvdb::v3_2_0::tree::LeafManager::getNodes
void getNodes(ArrayT &array) const
Insert node pointers of the specified type into the array.
Definition: LeafManager.h:598
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
openvdb::v3_2_0::tree::LeafManager::auxBufferCount
size_t auxBufferCount() const
Return the total number of allocated auxiliary buffers.
Definition: LeafManager.h:330
openvdb::v3_2_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:429
openvdb::v3_2_0::tree::LeafManager::rebuild
void rebuild(TreeType &tree, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:298
openvdb::v3_2_0::tree::LeafManager
This class manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
openvdb::v3_2_0::math::operator*
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:658
openvdb::v3_2_0::tree::LeafManager::swapLeafBuffer
bool swapLeafBuffer(size_t bufferIdx, bool serial=false)
Swap each leaf node&#39;s buffer with the nth corresponding auxiliary buffer, where n = bufferIdx...
Definition: LeafManager.h:395
openvdb::v3_2_0::tree::LeafManagerImpl::BufT
ManagerT::BufferType BufT
Definition: LeafManager.h:88
openvdb::v3_2_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:151
openvdb::v3_2_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::ManagerT
LeafManager< const TreeT > ManagerT
Definition: LeafManager.h:826
openvdb::v3_2_0::tree::CopyConstness::Type
boost::remove_const< ToType >::type Type
Definition: TreeIterator.h:66
openvdb::v3_2_0::tools::composite::max
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
openvdb::v3_2_0::tree::LeafManager::removeAuxBuffers
void removeAuxBuffers()
Remove the auxiliary buffers, but don&#39;t rebuild the leaf array.
Definition: LeafManager.h:320
openvdb::v3_2_0::tree::LeafManager::LeafIterType
leafmgr::TreeTraits< TreeT >::LeafIterType LeafIterType
Definition: LeafManager.h:124
openvdb::v3_2_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:286
openvdb::v3_2_0::tree::LeafManager::NonConstBufferType
LeafType::Buffer NonConstBufferType
Definition: LeafManager.h:125
openvdb::v3_2_0::tree::LeafManagerImpl
Definition: LeafManager.h:84
openvdb::v3_2_0::tree::LeafManager::auxBuffersPerLeaf
size_t auxBuffersPerLeaf() const
Return the number of auxiliary buffers per leaf node.
Definition: LeafManager.h:332
openvdb::v3_2_0::tree::LeafManager::rebuild
void rebuild(TreeType &tree, size_t auxBuffersPerLeaf, bool serial=false)
Repopulate the leaf array and delete and reallocate auxiliary buffers.
Definition: LeafManager.h:303
openvdb::v3_2_0::Index
Index32 Index
Definition: Types.h:58
TreeIterator.h
openvdb::v3_2_0::tree::LeafManager::getPreFixSum
size_t getPreFixSum(size_t *&offsets, size_t &size, size_t grainSize=1) const
Generate a linear array of pre-fix sums of offsets into the active voxels in the leafs. So offsets[n]+m is the offset to the mth active voxel in the nth leaf node (useful for user-managed value buffers, e.g. in tools/LevelSetAdvect.h).
Definition: LeafManager.h:627
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_2_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:149
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::Iterator
Iterator(const LeafRange &range, size_t pos)
Definition: LeafManager.h:138
openvdb::v3_2_0::tree::leafmgr::TreeTraits
Useful traits for Tree types.
Definition: LeafManager.h:68
openvdb::v3_2_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::LeafT
ManagerT::LeafType LeafT
Definition: LeafManager.h:828
openvdb::v3_2_0::tree::LeafManagerImpl::doSwapLeafBuffer
static void doSwapLeafBuffer(const RangeT &r, size_t auxBufferIdx, LeafT **leafs, BufT *bufs, size_t bufsPerLeaf)
Definition: LeafManager.h:90
openvdb::v3_2_0::tree::leafmgr::TreeTraits::LeafIterType
TreeT::LeafIter LeafIterType
Definition: LeafManager.h:70
openvdb::v3_2_0::tree::LeafManager::isConstTree
bool isConstTree() const
Return true if the tree associated with this manager is immutable.
Definition: LeafManager.h:350
openvdb::v3_2_0::tree::LeafManager::LeafRange::size
size_t size() const
Definition: LeafManager.h:192
openvdb::v3_2_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. Unlike foreach (defined above) this method performs a reduction on all the leaf nodes.
Definition: LeafManager.h:564
openvdb::v3_2_0::tree::LeafManager::BufferType
CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:126
openvdb::v3_2_0::tree::LeafManager::LeafManager
LeafManager(const LeafManager &other)
Definition: LeafManager.h:261
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::operator!=
bool operator!=(const Iterator &other) const
Definition: LeafManager.h:168
openvdb::v3_2_0::tree::LeafManager::LeafType
CopyConstness< TreeType, NonConstLeafType >::Type LeafType
Definition: LeafManager.h:122
openvdb::v3_2_0::tree::LeafManager::LeafNodeType
LeafType LeafNodeType
Definition: LeafManager.h:123
openvdb::v3_2_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:241
openvdb
Definition: Exceptions.h:39
openvdb::v3_2_0::tree::LeafManager::NonConstLeafType
TreeType::LeafNodeType NonConstLeafType
Definition: LeafManager.h:121
openvdb::v3_2_0::tree::LeafManager::RangeType
tbb::blocked_range< size_t > RangeType
Definition: LeafManager.h:127
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
openvdb::v3_2_0::tree::LeafManager::leafCount
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:335
openvdb::v3_2_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:154
openvdb::v3_2_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:366
openvdb::v3_2_0::tree::LeafManager::LeafRange::begin
Iterator begin() const
Definition: LeafManager.h:188
openvdb::v3_2_0::tree::leafmgr::TreeTraits< const TreeT >::LeafIterType
TreeT::LeafCIter LeafIterType
Definition: LeafManager.h:74
openvdb::v3_2_0::tree::LeafManager::LeafRange::empty
bool empty() const
Definition: LeafManager.h:198
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
openvdb::v3_2_0::tree::LeafManager::LeafRange::LeafRange
LeafRange(size_t begin, size_t end, const LeafManager &leafManager, size_t grainSize=1)
Definition: LeafManager.h:180
openvdb::v3_2_0::tree::LeafManager::operator()
void operator()(const RangeType &r) const
Used internally by tbb::parallel_for() - never call it directly!
Definition: LeafManager.h:650
openvdb::v3_2_0::tree::LeafManager::getNodes
void getNodes(ArrayT &array)
Insert pointers to nodes of the specified type into the array.
Definition: LeafManager.h:576
openvdb::v3_2_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:354
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator
Definition: LeafManager.h:135
openvdb::v3_2_0::ValueError
Definition: Exceptions.h:88
openvdb::v3_2_0::tree::LeafManager::syncAllBuffers
bool syncAllBuffers(bool serial=false)
Sync up all auxiliary buffers with their corresponding leaf node buffers.
Definition: LeafManager.h:440
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::operator++
Iterator & operator++()
Advance to the next leaf node.
Definition: LeafManager.h:147
openvdb::v3_2_0::tree::LeafManager::LeafRange::is_divisible
bool is_divisible() const
Definition: LeafManager.h:200
openvdb::v3_2_0::tree::LeafManager::tree
TreeType & tree()
Return a reference to the tree associated with this manager.
Definition: LeafManager.h:341
openvdb::v3_2_0::tree::LeafManager::LeafRange::end
Iterator end() const
Definition: LeafManager.h:190
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::empty
bool empty() const
Return true if this iterator is exhausted.
Definition: LeafManager.h:167
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_2_0::tree::LeafManager::TreeType
TreeT TreeType
Definition: LeafManager.h:118
openvdb::v3_2_0::tree::LeafManager::LeafRange::leafManager
const LeafManager & leafManager() const
Definition: LeafManager.h:196
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::operator=
Iterator & operator=(const Iterator &other)
Definition: LeafManager.h:142
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::operator==
bool operator==(const Iterator &other) const
Definition: LeafManager.h:172
openvdb::v3_2_0::tree::LeafManager::root
RootNodeType & root()
Return a reference to the root node associated with this manager.
Definition: LeafManager.h:347
openvdb::v3_2_0::tree::LeafManager::root
const RootNodeType & root() const
Return a const reference to root node associated with this manager.
Definition: LeafManager.h:344
openvdb::v3_2_0::tree::LeafManager::RootNodeType
TreeT::RootNodeType RootNodeType
Definition: LeafManager.h:120
openvdb::v3_2_0::tree::LeafManager::LeafRange::Iterator::test
bool test() const
Return true if this iterator is not yet exhausted.
Definition: LeafManager.h:163
openvdb::v3_2_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:161
openvdb::v3_2_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::doSwapLeafBuffer
static void doSwapLeafBuffer(const RangeT &, size_t, LeafT **, BufT *, size_t)
Definition: LeafManager.h:831
openvdb::v3_2_0::tree::LeafManager::tree
const TreeType & tree() const
Return a const reference to tree associated with this manager.
Definition: LeafManager.h:338
openvdb::v3_2_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:225
openvdb::v3_2_0::tree::LeafManager::leafRange
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:381
openvdb::v3_2_0::tree::LeafManagerImpl< LeafManager< const TreeT > >::BufT
ManagerT::BufferType BufT
Definition: LeafManager.h:829
openvdb::v3_2_0::tree::LeafManager::ValueType
TreeT::ValueType ValueType
Definition: LeafManager.h:119
openvdb::v3_2_0::tools::composite::min
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128