OpenVDB  2.0.0
TreeIterator.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 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 //
32 
33 #ifndef OPENVDB_TREE_TREEITERATOR_HAS_BEEN_INCLUDED
34 #define OPENVDB_TREE_TREEITERATOR_HAS_BEEN_INCLUDED
35 
36 #include <boost/mpl/front.hpp>
37 #include <boost/mpl/pop_front.hpp>
38 #include <boost/mpl/push_back.hpp>
39 #include <boost/mpl/size.hpp>
40 #include <boost/mpl/vector.hpp>
41 #include <boost/static_assert.hpp>
42 #include <boost/type_traits/remove_const.hpp>
43 #include <tbb/blocked_range.h>
44 #include <tbb/parallel_for.h>
45 #include <openvdb/version.h>
46 #include <openvdb/Types.h>
47 
48 // Prior to 0.96.1, depth-bounded value iterators always descended to the leaf level
49 // and iterated past leaf nodes. Now, they never descend past the maximum depth.
50 // Comment out the following line to restore the older, less-efficient behavior:
51 #define ENABLE_TREE_VALUE_DEPTH_BOUND_OPTIMIZATION
52 
53 
54 namespace openvdb {
56 namespace OPENVDB_VERSION_NAME {
57 namespace tree {
58 
65 template<typename FromType, typename ToType> struct CopyConstness {
66  typedef typename boost::remove_const<ToType>::type Type;
67 };
68 template<typename FromType, typename ToType> struct CopyConstness<const FromType, ToType> {
69  typedef const ToType Type;
70 };
71 
72 
74 
75 
76 namespace iter {
77 
78 template<typename HeadT, int HeadLevel>
79 struct InvertedTree {
80  typedef typename InvertedTree<typename HeadT::ChildNodeType, HeadLevel-1>::Type SubtreeT;
81  typedef typename boost::mpl::push_back<SubtreeT, HeadT>::type Type;
82 };
83 template<typename HeadT>
84 struct InvertedTree<HeadT, /*HeadLevel=*/1> {
85  typedef typename boost::mpl::vector<typename HeadT::ChildNodeType, HeadT>::type Type;
86 };
87 
88 } // namespace iter
89 
90 
92 
93 
105 template<typename NodeT, typename IterT>
107 {
108  template<typename ChildT> static ChildT* getChild(const IterT&) { return NULL; }
109 };
110 
111 template<typename NodeT>
112 struct IterTraits<NodeT, typename NodeT::ChildOnIter>
113 {
114  typedef typename NodeT::ChildOnIter IterT;
115  static IterT begin(NodeT& node) { return node.beginChildOn(); }
116  template<typename ChildT> static ChildT* getChild(const IterT& iter) {
117  return &iter.getValue();
118  }
119  template<typename OtherNodeT> struct NodeConverter {
120  typedef typename OtherNodeT::ChildOnIter Type;
121  };
122 };
123 
124 template<typename NodeT>
125 struct IterTraits<NodeT, typename NodeT::ChildOnCIter>
126 {
127  typedef typename NodeT::ChildOnCIter IterT;
128  static IterT begin(const NodeT& node) { return node.cbeginChildOn(); }
129  template<typename ChildT> static const ChildT* getChild(const IterT& iter) {
130  return &iter.getValue();
131  }
132  template<typename OtherNodeT> struct NodeConverter {
133  typedef typename OtherNodeT::ChildOnCIter Type;
134  };
135 };
136 
137 template<typename NodeT>
138 struct IterTraits<NodeT, typename NodeT::ChildOffIter>
139 {
140  typedef typename NodeT::ChildOffIter IterT;
141  static IterT begin(NodeT& node) { return node.beginChildOff(); }
142  template<typename OtherNodeT> struct NodeConverter {
143  typedef typename OtherNodeT::ChildOffIter Type;
144  };
145 };
146 
147 template<typename NodeT>
148 struct IterTraits<NodeT, typename NodeT::ChildOffCIter>
149 {
150  typedef typename NodeT::ChildOffCIter IterT;
151  static IterT begin(const NodeT& node) { return node.cbeginChildOff(); }
152  template<typename OtherNodeT> struct NodeConverter {
153  typedef typename OtherNodeT::ChildOffCIter Type;
154  };
155 };
156 
157 template<typename NodeT>
158 struct IterTraits<NodeT, typename NodeT::ChildAllIter>
159 {
160  typedef typename NodeT::ChildAllIter IterT;
161  static IterT begin(NodeT& node) { return node.beginChildAll(); }
162  template<typename ChildT> static ChildT* getChild(const IterT& iter) {
163  typename IterT::NonConstValueType val;
164  return iter.probeChild(val);
165  }
166  template<typename OtherNodeT> struct NodeConverter {
167  typedef typename OtherNodeT::ChildAllIter Type;
168  };
169 };
170 
171 template<typename NodeT>
172 struct IterTraits<NodeT, typename NodeT::ChildAllCIter>
173 {
174  typedef typename NodeT::ChildAllCIter IterT;
175  static IterT begin(const NodeT& node) { return node.cbeginChildAll(); }
176  template<typename ChildT> static ChildT* getChild(const IterT& iter) {
177  typename IterT::NonConstValueType val;
178  return iter.probeChild(val);
179  }
180  template<typename OtherNodeT> struct NodeConverter {
181  typedef typename OtherNodeT::ChildAllCIter Type;
182  };
183 };
184 
185 template<typename NodeT>
186 struct IterTraits<NodeT, typename NodeT::ValueOnIter>
187 {
188  typedef typename NodeT::ValueOnIter IterT;
189  static IterT begin(NodeT& node) { return node.beginValueOn(); }
190  template<typename OtherNodeT> struct NodeConverter {
191  typedef typename OtherNodeT::ValueOnIter Type;
192  };
193 };
194 
195 template<typename NodeT>
196 struct IterTraits<NodeT, typename NodeT::ValueOnCIter>
197 {
198  typedef typename NodeT::ValueOnCIter IterT;
199  static IterT begin(const NodeT& node) { return node.cbeginValueOn(); }
200  template<typename OtherNodeT> struct NodeConverter {
201  typedef typename OtherNodeT::ValueOnCIter Type;
202  };
203 };
204 
205 template<typename NodeT>
206 struct IterTraits<NodeT, typename NodeT::ValueOffIter>
207 {
208  typedef typename NodeT::ValueOffIter IterT;
209  static IterT begin(NodeT& node) { return node.beginValueOff(); }
210  template<typename OtherNodeT> struct NodeConverter {
211  typedef typename OtherNodeT::ValueOffIter Type;
212  };
213 };
214 
215 template<typename NodeT>
216 struct IterTraits<NodeT, typename NodeT::ValueOffCIter>
217 {
218  typedef typename NodeT::ValueOffCIter IterT;
219  static IterT begin(const NodeT& node) { return node.cbeginValueOff(); }
220  template<typename OtherNodeT> struct NodeConverter {
221  typedef typename OtherNodeT::ValueOffCIter Type;
222  };
223 };
224 
225 template<typename NodeT>
226 struct IterTraits<NodeT, typename NodeT::ValueAllIter>
227 {
228  typedef typename NodeT::ValueAllIter IterT;
229  static IterT begin(NodeT& node) { return node.beginValueAll(); }
230  template<typename OtherNodeT> struct NodeConverter {
231  typedef typename OtherNodeT::ValueAllIter Type;
232  };
233 };
234 
235 template<typename NodeT>
236 struct IterTraits<NodeT, typename NodeT::ValueAllCIter>
237 {
238  typedef typename NodeT::ValueAllCIter IterT;
239  static IterT begin(const NodeT& node) { return node.cbeginValueAll(); }
240  template<typename OtherNodeT> struct NodeConverter {
241  typedef typename OtherNodeT::ValueAllCIter Type;
242  };
243 };
244 
245 
247 
248 
259 template<typename PrevItemT, typename NodeVecT, size_t VecSize, Index _Level>
261 {
262 public:
264  typedef typename PrevItemT::IterT PrevIterT;
266  typedef typename boost::mpl::front<NodeVecT>::type _NodeT;
269  NodeConverter<_NodeT>::Type IterT;
270 
272  typedef typename IterT::NodeType NodeT;
274  typedef typename IterT::NonConstNodeType NCNodeT;
276  typedef typename IterT::NonConstValueType NCValueT;
283  static const Index Level = _Level;
284 
285  IterListItem(PrevItemT* prev): mNext(this), mPrev(prev) {}
286 
287  IterListItem(const IterListItem& other): mIter(other.mIter), mNext(other.mNext), mPrev(NULL) {}
289  {
290  if (&other != this) {
291  mIter = other.mIter;
292  mNext = other.mNext;
293  mPrev = NULL;
294  }
295  return *this;
296  }
297 
298  void updateBackPointers(PrevItemT* prev) { mPrev = prev; mNext.updateBackPointers(this); }
299 
300  void setIter(const IterT& iter) { mIter = iter; }
301  template<typename OtherIterT>
302  void setIter(const OtherIterT& iter) { mNext.setIter(iter); }
303 
305  void getNode(Index lvl, NodeT*& node) const
306  {
307  node = (lvl <= Level) ? mIter.getParentNode() : NULL;
308  }
310  template<typename OtherNodeT>
311  void getNode(Index lvl, OtherNodeT*& node) const { mNext.getNode(lvl, node); }
312 
318  template<typename OtherIterListItemT>
319  void initLevel(Index lvl, OtherIterListItemT& otherListItem)
320  {
321  if (lvl == Level) {
322  const NodeT* node = NULL;
323  otherListItem.getNode(lvl, node);
324  mIter = (node == NULL) ? IterT() : ITraits::begin(*const_cast<NodeT*>(node));
325  } else {
326  // Forward to one of the following list elements.
327  mNext.initLevel(lvl, otherListItem);
328  }
329  }
330 
332  Index pos(Index lvl) const { return (lvl == Level) ? mIter.pos() : mNext.pos(lvl); }
333 
335  bool test(Index lvl) const { return (lvl == Level) ? mIter.test() : mNext.test(lvl); }
336 
338  bool next(Index lvl) { return (lvl == Level) ? mIter.next() : mNext.next(lvl); }
339 
342  bool down(Index lvl)
343  {
344  if (lvl == Level && mPrev != NULL && mIter) {
345  if (ChildT* child = ITraits::template getChild<ChildT>(mIter)) {
346  mPrev->setIter(PrevItemT::ITraits::begin(*child));
347  return true;
348  }
349  }
350  return (lvl > Level) ? mNext.down(lvl) : false;
351  }
352 
355  Coord getCoord(Index lvl) const
356  {
357  return (lvl == Level) ? mIter.getCoord() : mNext.getCoord(lvl);
358  }
360  {
361  return (lvl == Level) ? NodeT::getChildDim() : mNext.getChildDim(lvl);
362  }
365  {
366  return (lvl == Level) ? ChildT::NUM_VOXELS : mNext.getVoxelCount(lvl);
367  }
368 
370  bool isValueOn(Index lvl) const
371  {
372  return (lvl == Level) ? mIter.isValueOn() : mNext.isValueOn(lvl);
373  }
374 
376  const NCValueT& getValue(Index lvl) const
377  {
378  if (lvl == Level) return mIter.getValue();
379  return mNext.getValue(lvl);
380  }
381 
385  void setValue(Index lvl, const NCValueT& val) const
386  {
387  if (lvl == Level) mIter.setValue(val); else mNext.setValue(lvl, val);
388  }
392  void setValueOn(Index lvl, bool on = true) const
393  {
394  if (lvl == Level) mIter.setValueOn(on); else mNext.setValueOn(lvl, on);
395  }
399  void setValueOff(Index lvl) const
400  {
401  if (lvl == Level) mIter.setValueOff(); else mNext.setValueOff(lvl);
402  }
403 
406  template<typename ModifyOp>
407  void modifyValue(Index lvl, const ModifyOp& op) const
408  {
409  if (lvl == Level) mIter.modifyValue(op); else mNext.modifyValue(lvl, op);
410  }
411 
412 private:
413  typedef typename boost::mpl::pop_front<NodeVecT>::type RestT; // NodeVecT minus its first item
414  typedef IterListItem<IterListItem, RestT, VecSize - 1, Level + 1> NextItem;
415 
416  IterT mIter;
417  NextItem mNext;
418  PrevItemT* mPrev;
419 };
420 
421 
423 template<typename PrevItemT, typename NodeVecT, size_t VecSize>
424 class IterListItem<PrevItemT, NodeVecT, VecSize, /*Level=*/0U>
425 {
426 public:
428  typedef typename PrevItemT::IterT PrevIterT;
430  typedef typename boost::mpl::front<NodeVecT>::type _NodeT;
433  NodeConverter<_NodeT>::Type IterT;
434 
436  typedef typename IterT::NodeType NodeT;
438  typedef typename IterT::NonConstNodeType NCNodeT;
440  typedef typename IterT::NonConstValueType NCValueT;
443  static const Index Level = 0;
444 
445  IterListItem(PrevItemT*): mNext(this), mPrev(NULL) {}
446 
447  IterListItem(const IterListItem& other): mIter(other.mIter), mNext(other.mNext), mPrev(NULL) {}
449  {
450  if (&other != this) {
451  mIter = other.mIter;
452  mNext = other.mNext;
453  mPrev = NULL;
454  }
455  return *this;
456  }
457 
458  void updateBackPointers(PrevItemT* = NULL) { mPrev = NULL; mNext.updateBackPointers(this); }
459 
460  void setIter(const IterT& iter) { mIter = iter; }
461  template<typename OtherIterT>
462  void setIter(const OtherIterT& iter) { mNext.setIter(iter); }
463 
464  void getNode(Index lvl, NodeT*& node) const
465  {
466  node = (lvl == 0) ? mIter.getParentNode() : NULL;
467  }
468  template<typename OtherNodeT>
469  void getNode(Index lvl, OtherNodeT*& node) const { mNext.getNode(lvl, node); }
470 
471  template<typename OtherIterListItemT>
472  void initLevel(Index lvl, OtherIterListItemT& otherListItem)
473  {
474  if (lvl == 0) {
475  const NodeT* node = NULL;
476  otherListItem.getNode(lvl, node);
477  mIter = (node == NULL) ? IterT() : ITraits::begin(*const_cast<NodeT*>(node));
478  } else {
479  mNext.initLevel(lvl, otherListItem);
480  }
481  }
482 
483  Index pos(Index lvl) const { return (lvl == 0) ? mIter.pos() : mNext.pos(lvl); }
484 
485  bool test(Index lvl) const { return (lvl == 0) ? mIter.test() : mNext.test(lvl); }
486 
487  bool next(Index lvl) { return (lvl == 0) ? mIter.next() : mNext.next(lvl); }
488 
489  bool down(Index lvl) { return (lvl == 0) ? false : mNext.down(lvl); }
490 
491  Coord getCoord(Index lvl) const
492  {
493  return (lvl == 0) ? mIter.getCoord() : mNext.getCoord(lvl);
494  }
496  {
497  return (lvl == 0) ? NodeT::getChildDim() : mNext.getChildDim(lvl);
498  }
499 
501  {
502  return (lvl == 0) ? 1 : mNext.getVoxelCount(lvl);
503  }
504 
505  bool isValueOn(Index lvl) const
506  {
507  return (lvl == 0) ? mIter.isValueOn() : mNext.isValueOn(lvl);
508  }
509 
510  const NCValueT& getValue(Index lvl) const
511  {
512  if (lvl == 0) return mIter.getValue();
513  return mNext.getValue(lvl);
514  }
515 
516  void setValue(Index lvl, const NCValueT& val) const
517  {
518  if (lvl == 0) mIter.setValue(val); else mNext.setValue(lvl, val);
519  }
520  void setValueOn(Index lvl, bool on = true) const
521  {
522  if (lvl == 0) mIter.setValueOn(on); else mNext.setValueOn(lvl, on);
523  }
524  void setValueOff(Index lvl) const
525  {
526  if (lvl == 0) mIter.setValueOff(); else mNext.setValueOff(lvl);
527  }
528 
529  template<typename ModifyOp>
530  void modifyValue(Index lvl, const ModifyOp& op) const
531  {
532  if (lvl == 0) mIter.modifyValue(op); else mNext.modifyValue(lvl, op);
533  }
534 
535 private:
536  typedef typename boost::mpl::pop_front<NodeVecT>::type RestT; // NodeVecT minus its first item
537  typedef IterListItem<IterListItem, RestT, VecSize - 1, /*Level=*/1> NextItem;
538 
539  IterT mIter;
540  NextItem mNext;
541  PrevItemT* mPrev;
542 };
543 
544 
546 template<typename PrevItemT, typename NodeVecT, Index _Level>
547 class IterListItem<PrevItemT, NodeVecT, /*VecSize=*/1, _Level>
548 {
549 public:
550  typedef typename boost::mpl::front<NodeVecT>::type _NodeT;
552  typedef typename PrevItemT::IterT PrevIterT;
555  NodeConverter<_NodeT>::Type IterT;
556 
558  typedef typename IterT::NodeType NodeT;
560  typedef typename IterT::NonConstNodeType NCNodeT;
562  typedef typename IterT::NonConstValueType NCValueT;
569  static const Index Level = _Level;
570 
571  IterListItem(PrevItemT* prev): mPrev(prev) {}
572 
573  IterListItem(const IterListItem& other): mIter(other.mIter), mPrev(NULL) {}
575  {
576  if (&other != this) {
577  mIter = other.mIter;
578  mPrev = NULL;
579  }
580  return *this;
581  }
582 
583  void updateBackPointers(PrevItemT* prev) { mPrev = prev; }
584 
585  // The following method specializations differ from the default template
586  // implementations mainly in that they don't forward.
587 
588  void setIter(const IterT& iter) { mIter = iter; }
589 
590  void getNode(Index lvl, NodeT*& node) const
591  {
592  node = (lvl <= Level) ? mIter.getParentNode() : NULL;
593  }
594 
595  template<typename OtherIterListItemT>
596  void initLevel(Index lvl, OtherIterListItemT& otherListItem)
597  {
598  if (lvl == Level) {
599  const NodeT* node = NULL;
600  otherListItem.getNode(lvl, node);
601  mIter = (node == NULL) ? IterT() : ITraits::begin(*const_cast<NodeT*>(node));
602  }
603  }
604 
605  Index pos(Index lvl) const { return (lvl == Level) ? mIter.pos() : Index(-1); }
606 
607  bool test(Index lvl) const { return (lvl == Level) ? mIter.test() : false; }
608 
609  bool next(Index lvl) { return (lvl == Level) ? mIter.next() : false; }
610 
611  bool down(Index lvl)
612  {
613  if (lvl == Level && mPrev != NULL && mIter) {
614  if (ChildT* child = ITraits::template getChild<ChildT>(mIter)) {
615  mPrev->setIter(PrevItemT::ITraits::begin(*child));
616  return true;
617  }
618  }
619  return false;
620  }
621 
622  Coord getCoord(Index lvl) const { return (lvl == Level) ? mIter.getCoord() : Coord(); }
623  Index getChildDim(Index lvl) const { return (lvl == Level) ? NodeT::getChildDim() : 0; }
624  Index64 getVoxelCount(Index lvl) const { return (lvl == Level) ? ChildT::NUM_VOXELS : 0; }
625 
626  bool isValueOn(Index lvl) const { return (lvl == Level) ? mIter.isValueOn() : false; }
627 
628  const NCValueT& getValue(Index lvl) const
629  {
630  assert(lvl == Level);
631  (void)lvl; // avoid unused variable warning in optimized builds
632  return mIter.getValue();
633  }
634 
635  void setValue(Index lvl, const NCValueT& val) const { if (lvl == Level) mIter.setValue(val); }
636  void setValueOn(Index lvl, bool on = true) const { if (lvl == Level) mIter.setValueOn(on); }
637  void setValueOff(Index lvl) const { if (lvl == Level) mIter.setValueOff(); }
638 
639  template<typename ModifyOp>
640  void modifyValue(Index lvl, const ModifyOp& op) const
641  {
642  if (lvl == Level) mIter.modifyValue(op);
643  }
644 
645 private:
646  IterT mIter;
647  PrevItemT* mPrev;
648 };
649 
650 
652 
653 
654 //#define DEBUG_TREE_VALUE_ITERATOR
655 
657 template<typename _TreeT, typename ValueIterT>
659 {
660 public:
661  typedef _TreeT TreeT;
662  typedef typename ValueIterT::NodeType NodeT;
663  typedef typename ValueIterT::NonConstValueType ValueT;
664  typedef typename NodeT::ChildOnCIter ChildOnIterT;
665  static const Index ROOT_LEVEL = NodeT::LEVEL;
666  BOOST_STATIC_ASSERT(ValueIterT::NodeType::LEVEL == ROOT_LEVEL);
667  static const Index LEAF_LEVEL = 0, ROOT_DEPTH = 0, LEAF_DEPTH = ROOT_LEVEL;
668 
670 
672  TreeValueIteratorBase& operator=(const TreeValueIteratorBase& other);
673 
675  void setMinDepth(Index minDepth);
677  Index getMinDepth() const { return ROOT_LEVEL - Index(mMaxLevel); }
679  void setMaxDepth(Index maxDepth);
681  Index getMaxDepth() const { return ROOT_LEVEL - Index(mMinLevel); }
682 
684  bool test() const { return mValueIterList.test(mLevel); }
686  operator bool() const { return this->test(); }
688 
691  bool next();
693  TreeValueIteratorBase& operator++() { this->next(); return *this; }
694 
697  Index getLevel() const { return mLevel; }
700  Index getDepth() const { return ROOT_LEVEL - mLevel; }
701  static Index getLeafDepth() { return LEAF_DEPTH; }
702 
707  template<typename NodeType>
708  void getNode(NodeType*& node) const { mValueIterList.getNode(mLevel, node); }
709 
712  Coord getCoord() const { return mValueIterList.getCoord(mLevel); }
716  bool getBoundingBox(CoordBBox&) const;
719  CoordBBox getBoundingBox() const { CoordBBox b; this->getBoundingBox(b); return b; }
720 
722  Index64 getVoxelCount() const { return mValueIterList.getVoxelCount(mLevel);}
723 
725  bool isTileValue() const { return mLevel != 0 && this->test(); }
727  bool isVoxelValue() const { return mLevel == 0 && this->test(); }
729  bool isValueOn() const { return mValueIterList.isValueOn(mLevel); }
730 
732  const ValueT& getValue() const { return mValueIterList.getValue(mLevel); }
734  const ValueT& operator*() const { return this->getValue(); }
735  const ValueT* operator->() const { return &(this->operator*()); }
737 
740  void setValue(const ValueT& val) const { mValueIterList.setValue(mLevel, val); }
743  void setActiveState(bool on) const { mValueIterList.setValueOn(mLevel, on); }
745  void setValueOff() const { mValueIterList.setValueOff(mLevel); }
746 
752  template<typename ModifyOp>
753  void modifyValue(const ModifyOp& op) const { mValueIterList.modifyValue(mLevel, op); }
754 
756  TreeT* getTree() const { return mTree; }
757 
759  std::string summary() const;
760 
761 private:
762  bool advance(bool dontIncrement = false);
763 
764  typedef typename iter::InvertedTree<NodeT, NodeT::LEVEL>::Type InvTreeT;
765  struct PrevChildItem { typedef ChildOnIterT IterT; };
766  struct PrevValueItem { typedef ValueIterT IterT; };
767 
768  IterListItem<PrevChildItem, InvTreeT, /*VecSize=*/ROOT_LEVEL+1, /*Level=*/0> mChildIterList;
769  IterListItem<PrevValueItem, InvTreeT, /*VecSize=*/ROOT_LEVEL+1, /*Level=*/0> mValueIterList;
770  Index mLevel;
771  int mMinLevel, mMaxLevel;
772  TreeT* mTree;
773 }; // class TreeValueIteratorBase
774 
775 
776 template<typename TreeT, typename ValueIterT>
777 inline
779  mChildIterList(NULL),
780  mValueIterList(NULL),
781  mLevel(ROOT_LEVEL),
782  mMinLevel(int(LEAF_LEVEL)),
783  mMaxLevel(int(ROOT_LEVEL)),
784  mTree(&tree)
785 {
786  mChildIterList.setIter(IterTraits<NodeT, ChildOnIterT>::begin(tree.getRootNode()));
787  mValueIterList.setIter(IterTraits<NodeT, ValueIterT>::begin(tree.getRootNode()));
788  this->advance(/*dontIncrement=*/true);
789 }
790 
791 
792 template<typename TreeT, typename ValueIterT>
793 inline
795  mChildIterList(other.mChildIterList),
796  mValueIterList(other.mValueIterList),
797  mLevel(other.mLevel),
798  mMinLevel(other.mMinLevel),
799  mMaxLevel(other.mMaxLevel),
800  mTree(other.mTree)
801 {
802  mChildIterList.updateBackPointers();
803  mValueIterList.updateBackPointers();
804 }
805 
806 
807 template<typename TreeT, typename ValueIterT>
810 {
811  if (&other != this) {
812  mChildIterList = other.mChildIterList;
813  mValueIterList = other.mValueIterList;
814  mLevel = other.mLevel;
815  mMinLevel = other.mMinLevel;
816  mMaxLevel = other.mMaxLevel;
817  mTree = other.mTree;
818  mChildIterList.updateBackPointers();
819  mValueIterList.updateBackPointers();
820  }
821  return *this;
822 }
823 
824 
825 template<typename TreeT, typename ValueIterT>
826 inline void
828 {
829  mMaxLevel = int(ROOT_LEVEL - minDepth); // level = ROOT_LEVEL - depth
830  if (int(mLevel) > mMaxLevel) this->next();
831 }
832 
833 
834 template<typename TreeT, typename ValueIterT>
835 inline void
837 {
838  // level = ROOT_LEVEL - depth
839  mMinLevel = int(ROOT_LEVEL - std::min(maxDepth, this->getLeafDepth()));
840  if (int(mLevel) < mMinLevel) this->next();
841 }
842 
843 
844 template<typename TreeT, typename ValueIterT>
845 inline bool
847 {
848  do {
849  if (!this->advance()) return false;
850  } while (int(mLevel) < mMinLevel || int(mLevel) > mMaxLevel);
851  return true;
852 }
853 
854 
855 template<typename TreeT, typename ValueIterT>
856 inline bool
858 {
859  Index
860  vPos = mValueIterList.pos(mLevel),
861  cPos = mChildIterList.pos(mLevel);
862  if (vPos == cPos && mChildIterList.test(mLevel)) {
864  mValueIterList.next(mLevel);
865  vPos = mValueIterList.pos(mLevel);
866  }
867  if (vPos < cPos) {
868  if (dontIncrement) return true;
869  if (mValueIterList.next(mLevel)) {
870  if (mValueIterList.pos(mLevel) == cPos && mChildIterList.test(mLevel)) {
872  mValueIterList.next(mLevel);
873  }
874  // If there is a next value and it precedes the next child, return.
875  if (mValueIterList.pos(mLevel) < cPos) return true;
876  }
877  } else {
878  // Advance to the next child, which may or may not precede the next value.
879  if (!dontIncrement) mChildIterList.next(mLevel);
880  }
881 #ifdef DEBUG_TREE_VALUE_ITERATOR
882  std::cout << "\n" << this->summary() << std::flush;
883 #endif
884 
885  // Descend to the lowest level at which the next value precedes the next child.
886  while (mChildIterList.pos(mLevel) < mValueIterList.pos(mLevel)) {
887 #ifdef ENABLE_TREE_VALUE_DEPTH_BOUND_OPTIMIZATION
888  if (int(mLevel) == mMinLevel) {
889  // If the current node lies at the lowest allowed level, none of its
890  // children can be visited, so advance its child iterator to the end.
893  while (mChildIterList.test(mLevel)) mChildIterList.next(mLevel);
894  } else
895 #endif
896  if (mChildIterList.down(mLevel)) {
897  --mLevel; // descend one level
898  mValueIterList.initLevel(mLevel, mChildIterList);
899  if (mValueIterList.pos(mLevel) == mChildIterList.pos(mLevel)
900  && mChildIterList.test(mLevel))
901  {
903  mValueIterList.next(mLevel);
904  }
905  } else break;
906 #ifdef DEBUG_TREE_VALUE_ITERATOR
907  std::cout << "\n" << this->summary() << std::flush;
908 #endif
909  }
910  // Ascend to the nearest level at which one of the iterators is not yet exhausted.
911  while (!mChildIterList.test(mLevel) && !mValueIterList.test(mLevel)) {
912  if (mLevel == ROOT_LEVEL) return false;
913  ++mLevel;
914  mChildIterList.next(mLevel);
915  this->advance(/*dontIncrement=*/true);
916  }
917  return true;
918 }
919 
920 
921 template<typename TreeT, typename ValueIterT>
922 inline bool
924 {
925  if (!this->test()) {
926  bbox = CoordBBox();
927  return false;
928  }
929  bbox.min() = mValueIterList.getCoord(mLevel);
930  bbox.max() = bbox.min().offsetBy(mValueIterList.getChildDim(mLevel) - 1);
931  return true;
932 }
933 
934 
935 template<typename TreeT, typename ValueIterT>
936 inline std::string
938 {
939  std::ostringstream ostr;
940  for (int lvl = int(ROOT_LEVEL); lvl >= 0 && lvl >= int(mLevel); --lvl) {
941  if (lvl == 0) ostr << "leaf";
942  else if (lvl == int(ROOT_LEVEL)) ostr << "root";
943  else ostr << "int" << (ROOT_LEVEL - lvl);
944  ostr << " v" << mValueIterList.pos(lvl)
945  << " c" << mChildIterList.pos(lvl);
946  if (lvl > int(mLevel)) ostr << " / ";
947  }
948  if (this->test() && mValueIterList.pos(mLevel) < mChildIterList.pos(mLevel)) {
949  if (mLevel == 0) {
950  ostr << " " << this->getCoord();
951  } else {
952  ostr << " " << this->getBoundingBox();
953  }
954  }
955  return ostr.str();
956 }
957 
958 
960 
961 
963 template<typename _TreeT, typename RootChildOnIterT>
965 {
966 public:
967  typedef _TreeT TreeT;
968  typedef RootChildOnIterT RootIterT;
969  typedef typename RootIterT::NodeType RootNodeT;
970  typedef typename RootIterT::NonConstNodeType NCRootNodeT;
971  static const Index ROOT_LEVEL = RootNodeT::LEVEL;
973  static const Index LEAF_LEVEL = 0, ROOT_DEPTH = 0, LEAF_DEPTH = ROOT_LEVEL;
974 
976 
979 
980  NodeIteratorBase(const NodeIteratorBase& other);
982 
984  void setMinDepth(Index minDepth);
986  Index getMinDepth() const { return ROOT_LEVEL - Index(mMaxLevel); }
988  void setMaxDepth(Index maxDepth);
990  Index getMaxDepth() const { return ROOT_LEVEL - Index(mMinLevel); }
991 
993  bool test() const { return !mDone; }
995  operator bool() const { return this->test(); }
997 
1000  bool next();
1002  void increment() { this->next(); }
1003  NodeIteratorBase& operator++() { this->increment(); return *this; }
1005  void increment(Index n) { for (Index i = 0; i < n && this->next(); ++i) {} }
1006 
1009  Index getLevel() const { return mLevel; }
1012  Index getDepth() const { return ROOT_LEVEL - mLevel; }
1013  static Index getLeafDepth() { return LEAF_DEPTH; }
1014 
1017  Coord getCoord() const;
1021  bool getBoundingBox(CoordBBox& bbox) const;
1024  CoordBBox getBoundingBox() const { CoordBBox b; this->getBoundingBox(b); return b; }
1025 
1029  template<typename NodeT>
1030  void getNode(NodeT*& node) const { node = NULL; mIterList.getNode(mLevel, node); }
1031 
1032  TreeT* getTree() const { return mTree; }
1033 
1034  std::string summary() const;
1035 
1036 private:
1037  struct PrevItem { typedef RootIterT IterT; };
1038 
1039  IterListItem<PrevItem, InvTreeT, /*VecSize=*/ROOT_LEVEL+1, LEAF_LEVEL> mIterList;
1040  Index mLevel;
1041  int mMinLevel, mMaxLevel;
1042  bool mDone;
1043  TreeT* mTree;
1044 }; // class NodeIteratorBase
1045 
1046 
1047 template<typename TreeT, typename RootChildOnIterT>
1048 inline
1050  mIterList(NULL),
1051  mLevel(ROOT_LEVEL),
1052  mMinLevel(int(LEAF_LEVEL)),
1053  mMaxLevel(int(ROOT_LEVEL)),
1054  mDone(true),
1055  mTree(NULL)
1056 {
1057 }
1058 
1059 
1060 template<typename TreeT, typename RootChildOnIterT>
1061 inline
1063  mIterList(NULL),
1064  mLevel(ROOT_LEVEL),
1065  mMinLevel(int(LEAF_LEVEL)),
1066  mMaxLevel(int(ROOT_LEVEL)),
1067  mDone(false),
1068  mTree(&tree)
1069 {
1070  mIterList.setIter(RootIterTraits::begin(tree.getRootNode()));
1071 }
1072 
1073 
1074 template<typename TreeT, typename RootChildOnIterT>
1075 inline
1077  mIterList(other.mIterList),
1078  mLevel(other.mLevel),
1079  mMinLevel(other.mMinLevel),
1080  mMaxLevel(other.mMaxLevel),
1081  mDone(other.mDone),
1082  mTree(other.mTree)
1083 {
1084  mIterList.updateBackPointers();
1085 }
1086 
1087 
1088 template<typename TreeT, typename RootChildOnIterT>
1091 {
1092  if (&other != this) {
1093  mLevel = other.mLevel;
1094  mMinLevel = other.mMinLevel;
1095  mMaxLevel = other.mMaxLevel;
1096  mDone = other.mDone;
1097  mTree = other.mTree;
1098  mIterList = other.mIterList;
1099  mIterList.updateBackPointers();
1100  }
1101  return *this;
1102 }
1103 
1104 
1105 template<typename TreeT, typename RootChildOnIterT>
1106 inline void
1108 {
1109  mMaxLevel = int(ROOT_LEVEL - minDepth); // level = ROOT_LEVEL - depth
1110  if (int(mLevel) > mMaxLevel) this->next();
1111 }
1112 
1113 
1114 template<typename TreeT, typename RootChildOnIterT>
1115 inline void
1117 {
1118  // level = ROOT_LEVEL - depth
1119  mMinLevel = int(ROOT_LEVEL - std::min(maxDepth, this->getLeafDepth()));
1120  if (int(mLevel) < mMinLevel) this->next();
1121 }
1122 
1123 
1124 template<typename TreeT, typename RootChildOnIterT>
1125 inline bool
1127 {
1128  do {
1129  if (mDone) return false;
1130 
1131  // If the iterator over the current node points to a child,
1132  // descend to the child (depth-first traversal).
1133  if (int(mLevel) > mMinLevel && mIterList.test(mLevel)) {
1134  if (!mIterList.down(mLevel)) return false;
1135  --mLevel;
1136  } else {
1137  // Ascend to the nearest ancestor that has other children.
1138  while (!mIterList.test(mLevel)) {
1139  if (mLevel == ROOT_LEVEL) {
1140  // Can't ascend higher than the root.
1141  mDone = true;
1142  return false;
1143  }
1144  ++mLevel; // ascend one level
1145  mIterList.next(mLevel); // advance to the next child, if there is one
1146  }
1147  // Descend to the child.
1148  if (!mIterList.down(mLevel)) return false;
1149  --mLevel;
1150  }
1151  } while (int(mLevel) < mMinLevel || int(mLevel) > mMaxLevel);
1152  return true;
1153 }
1154 
1155 
1156 template<typename TreeT, typename RootChildOnIterT>
1157 inline Coord
1159 {
1160  if (mLevel != ROOT_LEVEL) return mIterList.getCoord(mLevel + 1);
1161  RootNodeT* root = NULL;
1162  this->getNode(root);
1163  return root ? root->getMinIndex() : Coord::min();
1164 }
1165 
1166 
1167 template<typename TreeT, typename RootChildOnIterT>
1168 inline bool
1170 {
1171  if (mLevel == ROOT_LEVEL) {
1172  RootNodeT* root = NULL;
1173  this->getNode(root);
1174  if (root == NULL) {
1175  bbox = CoordBBox();
1176  return false;
1177  }
1178  root->getIndexRange(bbox);
1179  return true;
1180  }
1181  bbox.min() = mIterList.getCoord(mLevel + 1);
1182  bbox.max() = bbox.min().offsetBy(mIterList.getChildDim(mLevel + 1) - 1);
1183  return true;
1184 }
1185 
1186 
1187 template<typename TreeT, typename RootChildOnIterT>
1188 inline std::string
1190 {
1191  std::ostringstream ostr;
1192  for (int lvl = int(ROOT_LEVEL); lvl >= 0 && lvl >= int(mLevel); --lvl) {
1193  if (lvl == 0) ostr << "leaf";
1194  else if (lvl == int(ROOT_LEVEL)) ostr << "root";
1195  else ostr << "int" << (ROOT_LEVEL - lvl);
1196  ostr << " c" << mIterList.pos(lvl);
1197  if (lvl > int(mLevel)) ostr << " / ";
1198  }
1199  CoordBBox bbox;
1200  this->getBoundingBox(bbox);
1201  ostr << " " << bbox;
1202  return ostr.str();
1203 }
1204 
1205 
1207 
1208 
1210 template<typename TreeT, typename RootChildOnIterT>
1212 {
1213 public:
1214  typedef RootChildOnIterT RootIterT;
1215  typedef typename RootIterT::NodeType RootNodeT;
1216  typedef typename RootIterT::NonConstNodeType NCRootNodeT;
1217  static const Index ROOT_LEVEL = RootNodeT::LEVEL;
1219  typedef typename boost::mpl::front<InvTreeT>::type NCLeafNodeT;
1222 
1224 
1225  LeafIteratorBase(): mIterList(NULL), mTree(NULL) {}
1226 
1227  LeafIteratorBase(TreeT& tree): mIterList(NULL), mTree(&tree)
1228  {
1229  // Initialize the iterator list with a root node iterator.
1230  mIterList.setIter(RootIterTraits::begin(tree.getRootNode()));
1231  // Descend along the first branch, initializing the node iterator at each level.
1232  Index lvl = ROOT_LEVEL;
1233  for ( ; lvl > 0 && mIterList.down(lvl); --lvl) {}
1234  // If the first branch terminated above the leaf level, backtrack to the next branch.
1235  if (lvl > 0) this->next();
1236  }
1237 
1238  LeafIteratorBase(const LeafIteratorBase& other): mIterList(other.mIterList), mTree(other.mTree)
1239  {
1240  mIterList.updateBackPointers();
1241  }
1243  {
1244  if (&other != this) {
1245  mTree = other.mTree;
1246  mIterList = other.mIterList;
1247  mIterList.updateBackPointers();
1248  }
1249  return *this;
1250  }
1251 
1253  LeafNodeT* getLeaf() const { LeafNodeT* n = NULL; mIterList.getNode(LEAF_LEVEL, n); return n; }
1255  LeafNodeT& operator*() const { return *this->getLeaf(); }
1256  LeafNodeT* operator->() const { return this->getLeaf(); }
1258 
1259  bool test() const { return mIterList.test(LEAF_PARENT_LEVEL); }
1260  operator bool() const { return this->test(); }
1261 
1263  bool next();
1265  void increment() { this->next(); }
1266  LeafIteratorBase& operator++() { this->increment(); return *this; }
1268  void increment(Index n) { for (Index i = 0; i < n && this->next(); ++i) {} }
1270 
1271  TreeT* getTree() const { return mTree; }
1272 
1273 private:
1274  struct PrevItem { typedef RootIterT IterT; };
1275 
1279  IterListItem<PrevItem, InvTreeT, /*VecSize=*/ROOT_LEVEL+1, LEAF_LEVEL> mIterList;
1280  TreeT* mTree;
1281 }; // class LeafIteratorBase
1282 
1283 
1284 template<typename TreeT, typename RootChildOnIterT>
1285 inline bool
1287 {
1288  // If the iterator is valid for the current node one level above the leaf level,
1289  // advance the iterator to the node's next child.
1290  if (mIterList.test(LEAF_PARENT_LEVEL) && mIterList.next(LEAF_PARENT_LEVEL)) {
1291  mIterList.down(LEAF_PARENT_LEVEL); // initialize the leaf iterator
1292  return true;
1293  }
1294 
1295  Index lvl = LEAF_PARENT_LEVEL;
1296  while (!mIterList.test(LEAF_PARENT_LEVEL)) {
1297  if (mIterList.test(lvl)) {
1298  mIterList.next(lvl);
1299  } else {
1300  do {
1301  // Ascend to the nearest level at which
1302  // one of the iterators is not yet exhausted.
1303  if (lvl == ROOT_LEVEL) return false;
1304  ++lvl;
1305  if (mIterList.test(lvl)) mIterList.next(lvl);
1306  } while (!mIterList.test(lvl));
1307  }
1308  // Descend to the lowest child, but not as far as the leaf iterator.
1309  while (lvl > LEAF_PARENT_LEVEL && mIterList.down(lvl)) --lvl;
1310  }
1311  mIterList.down(LEAF_PARENT_LEVEL); // initialize the leaf iterator
1312  return true;
1313 }
1314 
1315 
1317 
1318 
1321 template<typename IterT>
1323 {
1324 public:
1325  IteratorRange(const IterT& iter, size_t grainSize = 8):
1326  mIter(iter),
1327  mGrainSize(grainSize),
1328  mSize(0)
1329  {
1330  mSize = this->size();
1331  }
1332  IteratorRange(IteratorRange& other, tbb::split):
1333  mIter(other.mIter),
1334  mGrainSize(other.mGrainSize),
1335  mSize(other.mSize >> 1)
1336  {
1337  other.increment(mSize);
1338  }
1339 
1343  const IterT& iterator() const { return mIter; }
1344 
1345  bool empty() const { return mSize == 0 || !mIter.test(); }
1346  bool test() const { return !this->empty(); }
1347  operator bool() const { return !this->empty(); }
1348 
1351  bool is_divisible() const { return mSize > mGrainSize; }
1352 
1354  void increment(Index n = 1) { for ( ; n > 0 && mSize > 0; --n, --mSize, ++mIter) {} }
1356  IteratorRange& operator++() { this->increment(); return *this; }
1359  bool next() { this->increment(); return this->test(); }
1360 
1361 private:
1362  Index size() const { Index n = 0; for (IterT it(mIter); it.test(); ++n, ++it) {} return n; }
1363 
1364  IterT mIter;
1365  size_t mGrainSize;
1370  Index mSize;
1371 };
1372 
1373 
1375 
1376 
1379 
1380 } // namespace tree
1381 } // namespace OPENVDB_VERSION_NAME
1382 } // namespace openvdb
1383 
1384 #endif // OPENVDB_TREE_TREEITERATOR_HAS_BEEN_INCLUDED
1385 
1386 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1387 // All rights reserved. This software is distributed under the
1388 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
void setActiveState(bool on) const
Change the active/inactive state of the tile or voxel value to which this iterator is currently point...
Definition: TreeIterator.h:743
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:199
void increment(Index n)
Increment the iterator n times.
Definition: TreeIterator.h:1005
Index getChildDim(Index lvl) const
Definition: TreeIterator.h:495
_TreeT TreeT
Definition: TreeIterator.h:967
Base class for tree-traversal iterators over tile and voxel values.
Definition: TreeIterator.h:658
static const Index LEAF_DEPTH
Definition: TreeIterator.h:973
IterTraits< typename PrevIterT::NonConstNodeType, PrevIterT >::template NodeConverter< _NodeT >::Type IterT
The type of iterator stored in this list item (e.g., InternalNode::ValueOnCIter)
Definition: TreeIterator.h:269
void setValue(Index lvl, const NCValueT &val) const
Definition: TreeIterator.h:516
Coord getCoord() const
Return the global coordinates of the voxel or tile to which this iterator is currently pointing...
Definition: TreeIterator.h:712
IterTraits< typename PrevIterT::NonConstNodeType, PrevIterT >::template NodeConverter< _NodeT >::Type IterT
The type of iterator stored in this list item (e.g., InternalNode::ValueOnCIter)
Definition: TreeIterator.h:433
void setIter(const OtherIterT &iter)
Definition: TreeIterator.h:302
LeafNodeT & operator*() const
Return the leaf node to which the iterator is pointing.
Definition: TreeIterator.h:1255
void increment(Index n=1)
Advance the iterator n times.
Definition: TreeIterator.h:1354
CopyConstness< NCNodeT, typename NCNodeT::ChildNodeType >::Type NCChildT
NodeT&#39;s child node type with const qualifiers removed.
Definition: TreeIterator.h:566
NodeIteratorBase()
Definition: TreeIterator.h:1049
Index pos(Index lvl) const
Definition: TreeIterator.h:483
NodeT::ValueOffCIter IterT
Definition: TreeIterator.h:218
NodeT::ChildOffIter IterT
Definition: TreeIterator.h:140
bool next(Index lvl)
Definition: TreeIterator.h:609
IteratorRange(IteratorRange &other, tbb::split)
Definition: TreeIterator.h:1332
IterTraits< NCNodeT, IterT > ITraits
Definition: TreeIterator.h:281
CopyConstness< NodeT, typename NodeT::ChildNodeType >::Type ChildT
NodeT&#39;s child node type, with the same constness (e.g., const InternalNode&lt;...&gt;)
Definition: TreeIterator.h:278
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:175
IterTraits< typename PrevIterT::NonConstNodeType, PrevIterT >::template NodeConverter< _NodeT >::Type IterT
The type of iterator stored in this list item (e.g., RootNode::ValueOnCIter)
Definition: TreeIterator.h:555
ValueIterT::NodeType NodeT
Definition: TreeIterator.h:662
void setMaxDepth(Index maxDepth)
Specify the depth of the lowest level of the tree to which to descend (depth 0 = root).
Definition: TreeIterator.h:1116
Base class for tree-traversal iterators over all leaf nodes (but not leaf voxels) ...
Definition: TreeIterator.h:1211
void initLevel(Index lvl, OtherIterListItemT &otherListItem)
Initialize the iterator for level lvl of the tree with the node over which the corresponding iterator...
Definition: TreeIterator.h:319
Index64 getVoxelCount(Index lvl) const
Definition: TreeIterator.h:500
static const Index LEAF_LEVEL
Definition: TreeIterator.h:1221
static ChildT * getChild(const IterT &)
Definition: TreeIterator.h:108
Coord getCoord() const
Return the global coordinates of the voxel or tile to which this iterator is currently pointing...
Definition: TreeIterator.h:1158
ValueIterT::NonConstValueType ValueT
Definition: TreeIterator.h:663
void setMinDepth(Index minDepth)
Specify the depth of the highest level of the tree to which to ascend (depth 0 = root).
Definition: TreeIterator.h:1107
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:128
IterTraits< NCRootNodeT, RootIterT > RootIterTraits
Definition: TreeIterator.h:1223
TreeValueIteratorBase(TreeT &)
Definition: TreeIterator.h:778
void modifyValue(Index lvl, const ModifyOp &op) const
Definition: TreeIterator.h:640
boost::mpl::push_back< SubtreeT, HeadT >::type Type
Definition: TreeIterator.h:81
IterTraits< NCNodeT, IterT > ITraits
Definition: TreeIterator.h:567
void setValue(const ValueT &val) const
Change the tile or voxel value to which this iterator is currently pointing and mark it as active...
Definition: TreeIterator.h:740
void getNode(Index lvl, OtherNodeT *&node) const
Definition: TreeIterator.h:469
void modifyValue(Index lvl, const ModifyOp &op) const
Definition: TreeIterator.h:530
void getNode(Index lvl, NodeT *&node) const
Definition: TreeIterator.h:590
Index getMinDepth() const
Return the depth of the highest level of the tree to which this iterator ascends. ...
Definition: TreeIterator.h:986
void setValueOff(Index lvl) const
Definition: TreeIterator.h:524
bool isValueOn(Index lvl) const
Definition: TreeIterator.h:505
static IterT begin(NodeT &node)
Definition: TreeIterator.h:229
IterT::NonConstValueType NCValueT
The type of value (with const qualifiers removed) to which the iterator points.
Definition: TreeIterator.h:562
const ToType Type
Definition: TreeIterator.h:69
NodeT::ValueOnIter IterT
Definition: TreeIterator.h:188
IterTraits< NCRootNodeT, RootIterT > RootIterTraits
Definition: TreeIterator.h:975
CoordBBox getBoundingBox() const
Return the axis-aligned bounding box of the voxel or tile to which this iterator is currently pointin...
Definition: TreeIterator.h:719
Coord getCoord(Index lvl) const
Definition: TreeIterator.h:491
void setValueOff() const
Mark the tile or voxel value to which this iterator is currently pointing as inactive.
Definition: TreeIterator.h:745
static const Index LEAF_LEVEL
Definition: TreeIterator.h:973
void setValue(Index lvl, const NCValueT &val) const
Definition: TreeIterator.h:635
RootChildOnIterT RootIterT
Definition: TreeIterator.h:1214
Definition: TreeIterator.h:1322
std::string summary() const
Definition: TreeIterator.h:1189
IterT::NonConstNodeType NCNodeT
The type of the node with const qualifiers removed (&quot;Non-Const&quot;)
Definition: TreeIterator.h:274
Index getChildDim(Index lvl) const
Definition: TreeIterator.h:623
InvertedTree< typename HeadT::ChildNodeType, HeadLevel-1 >::Type SubtreeT
Definition: TreeIterator.h:80
static ChildT * getChild(const IterT &iter)
Definition: TreeIterator.h:176
static const Index ROOT_DEPTH
Definition: TreeIterator.h:973
boost::mpl::front< NodeVecT >::type _NodeT
The type of node (non-const) whose iterator is stored in this list item.
Definition: TreeIterator.h:430
void getNode(NodeType *&node) const
Return in node a pointer to the node over which this iterator is currently iterating or one of that n...
Definition: TreeIterator.h:708
LeafIteratorBase & operator=(const LeafIteratorBase &other)
Definition: TreeIterator.h:1242
static ChildT * getChild(const IterT &iter)
Definition: TreeIterator.h:116
static IterT begin(NodeT &node)
Definition: TreeIterator.h:189
IterListItem(const IterListItem &other)
Definition: TreeIterator.h:447
Index getLevel() const
Return the level in the tree (0 = leaf) of the node to which this iterator is currently pointing...
Definition: TreeIterator.h:697
IterListItem(PrevItemT *prev)
Definition: TreeIterator.h:571
bool test(Index lvl) const
Return true if the iterator at level lvl of the tree has not yet reached its end. ...
Definition: TreeIterator.h:335
const NCValueT & getValue(Index lvl) const
Definition: TreeIterator.h:628
Definition: TreeIterator.h:79
Coord getCoord(Index lvl) const
Definition: TreeIterator.h:622
Index getLevel() const
Return the level in the tree (0 = leaf) of the node to which this iterator is currently pointing...
Definition: TreeIterator.h:1009
boost::remove_const< ToType >::type Type
Definition: TreeIterator.h:66
Definition: TreeIterator.h:65
TreeT * getTree() const
Definition: TreeIterator.h:1271
TreeValueIteratorBase & operator=(const TreeValueIteratorBase &other)
Definition: TreeIterator.h:809
IterListItem & operator=(const IterListItem &other)
Definition: TreeIterator.h:448
void updateBackPointers(PrevItemT *prev)
Definition: TreeIterator.h:583
void setIter(const IterT &iter)
Definition: TreeIterator.h:300
bool down(Index lvl)
Definition: TreeIterator.h:611
Index getDepth() const
Return the depth in the tree (0 = root) of the node to which this iterator is currently pointing...
Definition: TreeIterator.h:700
void modifyValue(const ModifyOp &op) const
Apply a functor to the item to which this iterator is pointing. (Not valid for const iterators...
Definition: TreeIterator.h:753
CopyConstness< NCNodeT, typename NCNodeT::ChildNodeType >::Type NCChildT
NodeT&#39;s child node type with const qualifiers removed.
Definition: TreeIterator.h:280
NodeIteratorBase & operator=(const NodeIteratorBase &other)
Definition: TreeIterator.h:1090
LeafIteratorBase & operator++()
Advance the iterator to the next leaf node.
Definition: TreeIterator.h:1266
PrevItemT::IterT PrevIterT
The type of iterator stored in the previous list item.
Definition: TreeIterator.h:264
Coord getCoord(Index lvl) const
Return the global coordinates of the voxel or tile to which the iterator at level lvl of the tree is ...
Definition: TreeIterator.h:355
void updateBackPointers(PrevItemT *=NULL)
Definition: TreeIterator.h:458
Index64 getVoxelCount(Index lvl) const
Definition: TreeIterator.h:624
IterListItem & operator=(const IterListItem &other)
Definition: TreeIterator.h:288
bool next(Index lvl)
Increment the iterator at level lvl of the tree.
Definition: TreeIterator.h:338
NodeT::ValueAllCIter IterT
Definition: TreeIterator.h:238
static IterT begin(NodeT &node)
Definition: TreeIterator.h:161
NodeT::ChildOnCIter ChildOnIterT
Definition: TreeIterator.h:664
static const Index LEAF_PARENT_LEVEL
Definition: TreeIterator.h:1221
bool down(Index lvl)
If the iterator at level lvl of the tree points to a child node, initialize the next iterator in this...
Definition: TreeIterator.h:342
IterT::NodeType NodeT
The type of node over which IterT iterates (e.g., const RootNode&lt;...&gt;)
Definition: TreeIterator.h:558
NodeIteratorBase & operator++()
Definition: TreeIterator.h:1003
boost::mpl::front< NodeVecT >::type _NodeT
Definition: TreeIterator.h:550
static IterT begin(NodeT &node)
Definition: TreeIterator.h:209
void getNode(Index lvl, NodeT *&node) const
Return the node over which this list element&#39;s iterator iterates.
Definition: TreeIterator.h:305
IterT::NonConstValueType NCValueT
The type of value (with const qualifiers removed) to which the iterator points.
Definition: TreeIterator.h:440
void getNode(Index lvl, NodeT *&node) const
Definition: TreeIterator.h:464
Index pos(Index lvl) const
Return The table offset of the iterator at level lvl of the tree.
Definition: TreeIterator.h:332
NodeT::ValueOnCIter IterT
Definition: TreeIterator.h:198
Index getMaxDepth() const
Return the depth of the lowest level of the tree to which this iterator ascends.
Definition: TreeIterator.h:990
void getNode(Index lvl, OtherNodeT *&node) const
Return the node over which one of the following list elements&#39; iterator iterates. ...
Definition: TreeIterator.h:311
CoordBBox getBoundingBox() const
Return the axis-aligned bounding box of the voxel or tile to which this iterator is currently pointin...
Definition: TreeIterator.h:1024
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:239
#define OPENVDB_VERSION_NAME
Definition: version.h:45
void setValueOff(Index lvl) const
Mark the value to which the iterator at level lvl of the tree points as inactive. ...
Definition: TreeIterator.h:399
RootChildOnIterT RootIterT
Definition: TreeIterator.h:968
static const ChildT * getChild(const IterT &iter)
Definition: TreeIterator.h:129
TreeT * getTree() const
Definition: TreeIterator.h:1032
IterTraits< NCNodeT, IterT > ITraits
Definition: TreeIterator.h:441
bool test() const
Definition: TreeIterator.h:1346
_TreeT TreeT
Definition: TreeIterator.h:661
static const Index ROOT_LEVEL
Definition: TreeIterator.h:971
CopyConstness< RootNodeT, NCLeafNodeT >::Type LeafNodeT
Definition: TreeIterator.h:1220
Index getMinDepth() const
Return the depth of the highest level of the tree to which this iterator ascends. ...
Definition: TreeIterator.h:677
bool test(Index lvl) const
Definition: TreeIterator.h:607
void setValueOn(Index lvl, bool on=true) const
Set the value (to val) to which the iterator at level lvl of the tree points and mark the value as ac...
Definition: TreeIterator.h:392
bool isTileValue() const
Return true if this iterator is currently pointing to a (non-leaf) tile value.
Definition: TreeIterator.h:725
bool test() const
Definition: TreeIterator.h:1259
boost::mpl::vector< typename HeadT::ChildNodeType, HeadT >::type Type
Definition: TreeIterator.h:85
void setIter(const OtherIterT &iter)
Definition: TreeIterator.h:462
IterListItem(const IterListItem &other)
Definition: TreeIterator.h:573
RootIterT::NonConstNodeType NCRootNodeT
Definition: TreeIterator.h:970
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
CopyConstness< NodeT, typename NodeT::ChildNodeType >::Type ChildT
NodeT&#39;s child node type, with the same constness (e.g., const InternalNode&lt;...&gt;)
Definition: TreeIterator.h:564
const ValueT * operator->() const
Return the tile or voxel value to which this iterator is currently pointing.
Definition: TreeIterator.h:735
void setValueOn(Index lvl, bool on=true) const
Definition: TreeIterator.h:520
NodeT::ValueOffIter IterT
Definition: TreeIterator.h:208
boost::mpl::front< NodeVecT >::type _NodeT
The type of node (non-const) whose iterator is stored in this list item.
Definition: TreeIterator.h:266
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:151
NodeT::ChildOnCIter IterT
Definition: TreeIterator.h:127
void initLevel(Index lvl, OtherIterListItemT &otherListItem)
Definition: TreeIterator.h:596
Index pos(Index lvl) const
Definition: TreeIterator.h:605
RootIterT::NodeType RootNodeT
Definition: TreeIterator.h:969
const IterT & iterator() const
Return a reference to this range&#39;s iterator.
Definition: TreeIterator.h:1343
IterListItem(const IterListItem &other)
Definition: TreeIterator.h:287
IterT::NodeType NodeT
The type of node (const or non-const) over which IterT iterates (e.g., const RootNode&lt;...&gt;)
Definition: TreeIterator.h:436
void setMinDepth(Index minDepth)
Specify the depth of the highest level of the tree to which to ascend (depth 0 = root).
Definition: TreeIterator.h:827
LeafNodeT * operator->() const
Return the leaf node to which the iterator is pointing.
Definition: TreeIterator.h:1256
std::string summary() const
Return a string (for debugging, mainly) describing this iterator&#39;s current state. ...
Definition: TreeIterator.h:937
Index64 getVoxelCount() const
Return the number of (virtual) voxels corresponding to the value.
Definition: TreeIterator.h:722
static const Index ROOT_LEVEL
Definition: TreeIterator.h:1217
IterListItem & operator=(const IterListItem &other)
Definition: TreeIterator.h:574
RootIterT::NodeType RootNodeT
Definition: TreeIterator.h:1215
bool next()
Advance the iterator to the next leaf node.
Definition: TreeIterator.h:1286
LeafIteratorBase(TreeT &tree)
Definition: TreeIterator.h:1227
void increment()
Advance the iterator to the next leaf node.
Definition: TreeIterator.h:1265
void setMaxDepth(Index maxDepth)
Specify the depth of the lowest level of the tree to which to descend (depth 0 = root).
Definition: TreeIterator.h:836
bool isVoxelValue() const
Return true if this iterator is currently pointing to a (leaf) voxel value.
Definition: TreeIterator.h:727
static ChildT * getChild(const IterT &iter)
Definition: TreeIterator.h:162
IteratorRange & operator++()
Advance the iterator to the next item.
Definition: TreeIterator.h:1356
IterT::NonConstValueType NCValueT
The type of value (with const qualifiers removed) to which the iterator points.
Definition: TreeIterator.h:276
const NCValueT & getValue(Index lvl) const
Return the value to which the iterator at level lvl of the tree points.
Definition: TreeIterator.h:376
IterT::NonConstNodeType NCNodeT
The type of the node with const qualifiers removed (&quot;Non-Const&quot;)
Definition: TreeIterator.h:560
bool next()
Advance to the next tile or voxel value.
Definition: TreeIterator.h:1126
const NCValueT & getValue(Index lvl) const
Definition: TreeIterator.h:510
TreeT * getTree() const
Return a pointer to the tree over which this iterator is iterating.
Definition: TreeIterator.h:756
Base class for tree-traversal iterators over all nodes.
Definition: TreeIterator.h:964
Index32 Index
Definition: Types.h:56
void setIter(const IterT &iter)
Definition: TreeIterator.h:460
void setValueOn(Index lvl, bool on=true) const
Definition: TreeIterator.h:636
RootIterT::NonConstNodeType NCRootNodeT
Definition: TreeIterator.h:1216
NodeT::ChildOffCIter IterT
Definition: TreeIterator.h:150
Index getChildDim(Index lvl) const
Definition: TreeIterator.h:359
IterListItem(PrevItemT *prev)
Definition: TreeIterator.h:285
static Index getLeafDepth()
Definition: TreeIterator.h:1013
bool isValueOn() const
Return true if the value to which this iterator is currently pointing is active.
Definition: TreeIterator.h:729
bool isValueOn(Index lvl) const
Definition: TreeIterator.h:626
Definition: TreeIterator.h:106
LeafNodeT * getLeaf() const
Return the leaf node to which the iterator is pointing.
Definition: TreeIterator.h:1254
IteratorRange(const IterT &iter, size_t grainSize=8)
Definition: TreeIterator.h:1325
PrevItemT::IterT PrevIterT
The type of iterator stored in the previous list item.
Definition: TreeIterator.h:552
static IterT begin(NodeT &node)
Definition: TreeIterator.h:115
An IterListItem is an element of a compile-time linked list of iterators to nodes of different types...
Definition: TreeIterator.h:260
LeafIteratorBase(const LeafIteratorBase &other)
Definition: TreeIterator.h:1238
bool test(Index lvl) const
Definition: TreeIterator.h:485
TreeValueIteratorBase & operator++()
Advance to the next tile or voxel value.
Definition: TreeIterator.h:693
IterT::NodeType NodeT
The type of node (const or non-const) over which IterT iterates (e.g., const RootNode&lt;...&gt;)
Definition: TreeIterator.h:272
static Index getLeafDepth()
Definition: TreeIterator.h:701
static IterT begin(const NodeT &node)
Definition: TreeIterator.h:219
NodeT::ValueAllIter IterT
Definition: TreeIterator.h:228
bool test() const
Return true if this iterator is not yet exhausted.
Definition: TreeIterator.h:994
bool isValueOn(Index lvl) const
Return true if the iterator at level lvl of the tree points to an active value.
Definition: TreeIterator.h:370
Index getMaxDepth() const
Return the depth of the lowest level of the tree to which this iterator ascends.
Definition: TreeIterator.h:681
PrevItemT::IterT PrevIterT
The type of iterator stored in the previous list item.
Definition: TreeIterator.h:428
const ValueT & operator*() const
Return the tile or voxel value to which this iterator is currently pointing.
Definition: TreeIterator.h:734
Index64 getVoxelCount(Index lvl) const
Return the number of (virtual) voxels spanned by a tile value or child node.
Definition: TreeIterator.h:364
void modifyValue(Index lvl, const ModifyOp &op) const
Apply a functor to the item to which this iterator is pointing.
Definition: TreeIterator.h:407
IterT::NonConstNodeType NCNodeT
The type of the node with const qualifiers removed (&quot;Non-Const&quot;)
Definition: TreeIterator.h:438
LeafIteratorBase()
Definition: TreeIterator.h:1225
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
bool next()
Advance the iterator to the next item.
Definition: TreeIterator.h:1359
bool empty() const
Definition: TreeIterator.h:1345
NodeT::ChildAllCIter IterT
Definition: TreeIterator.h:174
void increment()
Advance the iterator to the next leaf node.
Definition: TreeIterator.h:1002
void setValueOff(Index lvl) const
Definition: TreeIterator.h:637
uint64_t Index64
Definition: Types.h:55
bool next()
Advance to the next tile or voxel value. Return true if this iterator is not yet exhausted.
Definition: TreeIterator.h:846
iter::InvertedTree< NCRootNodeT, ROOT_LEVEL >::Type InvTreeT
Definition: TreeIterator.h:972
boost::mpl::front< InvTreeT >::type NCLeafNodeT
Definition: TreeIterator.h:1219
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
void getNode(NodeT *&node) const
Return the node to which the iterator is pointing.
Definition: TreeIterator.h:1030
void updateBackPointers(PrevItemT *prev)
Definition: TreeIterator.h:298
void setValue(Index lvl, const NCValueT &val) const
Set the value (to val) to which the iterator at level lvl of the tree points and mark the value as ac...
Definition: TreeIterator.h:385
iter::InvertedTree< NCRootNodeT, ROOT_LEVEL >::Type InvTreeT
Definition: TreeIterator.h:1218
NodeT::ChildAllIter IterT
Definition: TreeIterator.h:160
static IterT begin(NodeT &node)
Definition: TreeIterator.h:141
void setIter(const IterT &iter)
Definition: TreeIterator.h:588
bool is_divisible() const
Return true if this range is splittable (i.e., if the iterator can be advanced more than mGrainSize t...
Definition: TreeIterator.h:1351
NodeT::ChildOnIter IterT
Definition: TreeIterator.h:114
Index getDepth() const
Return the depth in the tree (0 = root) of the node to which this iterator is currently pointing...
Definition: TreeIterator.h:1012
void initLevel(Index lvl, OtherIterListItemT &otherListItem)
Definition: TreeIterator.h:472