OpenVDB  3.2.0
LeafNodeMask.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 
31 #ifndef OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
33 
34 #include <iostream>
35 #include <boost/shared_ptr.hpp>
36 #include <boost/shared_array.hpp>
37 #include <boost/static_assert.hpp>
38 #include <openvdb/Types.h>
39 #include <openvdb/io/Compression.h> // for io::readData(), etc.
40 #include <openvdb/math/Math.h> // for math::isZero()
41 #include <openvdb/util/NodeMasks.h>
42 #include "LeafNode.h"
43 #include "Iterator.h"
44 
45 
46 namespace openvdb {
48 namespace OPENVDB_VERSION_NAME {
49 namespace tree {
50 
54 template<Index Log2Dim>
55 class LeafNode<ValueMask, Log2Dim>
56 {
57 public:
59  typedef boost::shared_ptr<LeafNodeType> Ptr;
60  typedef ValueMask BuildType;// this is a rare case where
61  typedef bool ValueType;// value type != build type
63 
64  // These static declarations must be on separate lines to avoid VC9 compiler errors.
65  static const Index LOG2DIM = Log2Dim; // needed by parent nodes
66  static const Index TOTAL = Log2Dim; // needed by parent nodes
67  static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
68  static const Index NUM_VALUES = 1 << 3 * Log2Dim;
69  static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
70  static const Index SIZE = NUM_VALUES;
71  static const Index LEVEL = 0; // level 0 = leaf
72 
75  template<typename OtherValueType>
76  struct ValueConverter {
78  };
79 
82  template<typename OtherNodeType>
83  struct SameConfiguration {
85  };
86 
87  class Buffer
88  {
89  public:
90  typedef typename NodeMaskType::Word WordType;
91  static const Index WORD_COUNT = NodeMaskType::WORD_COUNT;
92  Buffer() {}
93  explicit Buffer(bool on) : mData(on) {}
94  Buffer(const NodeMaskType& other): mData(other) {}
95  Buffer(const Buffer& other): mData(other.mData) {}
96  ~Buffer() {}
97  void fill(bool val) { mData.set(val); }
98  Buffer& operator=(const Buffer& b)
99  {
100  if (&b != this) mData = b.mData;
101  return *this;
102  }
103 
104  const bool& getValue(Index i) const
105  {
106  assert(i < SIZE);
107  // We can't use the ternary operator here, otherwise Visual C++ returns
108  // a reference to a temporary.
109  if (mData.isOn(i)) return LeafNode::sOn;
110  return LeafNode::sOff;
111  }
112  const bool& operator[](Index i) const { return this->getValue(i); }
113 
114  bool operator==(const Buffer& other) const { return mData == other.mData; }
115  bool operator!=(const Buffer& other) const { return mData != other.mData; }
116 
117  void setValue(Index i, bool val) { assert(i < SIZE); mData.set(i, val); }
118 
119  void swap(Buffer& other) { if (&other != this) std::swap(mData, other.mData); }
120 
121  Index memUsage() const { return mData.memUsage(); }
122  static Index size() { return SIZE; }
123 
127  WordType* data()
128  {
129  return &(mData.template getWord<WordType>(0));
130  }
135  const WordType* data() const
136  {
137  return const_cast<Buffer*>(this)->data();
138  }
139 
140  private:
141  friend class ::TestLeaf;
142  // Allow the parent LeafNode to access this Buffer's bit mask.
143  friend class LeafNode;
144 
145  NodeMaskType mData;
146  }; // class Buffer
147 
148 
150  LeafNode();
151 
156  explicit LeafNode(const Coord& xyz, bool value = false, bool dummy = false);
157 
158 #ifndef OPENVDB_2_ABI_COMPATIBLE
159  LeafNode(PartialCreate, const Coord& xyz, bool value = false, bool dummy = false);
161 #endif
162 
164  LeafNode(const LeafNode&);
165 
167  template<typename OtherValueType>
168  explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
169 
171  template<typename ValueType>
173 
175  template<typename ValueType>
178  LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool offValue, bool onValue, TopologyCopy);
179  template<typename ValueType>
180  LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool background, TopologyCopy);
182 
184  ~LeafNode();
185 
186  //
187  // Statistics
188  //
190  static Index log2dim() { return Log2Dim; }
192  static Index dim() { return DIM; }
194  static Index size() { return SIZE; }
196  static Index numValues() { return SIZE; }
198  static Index getLevel() { return LEVEL; }
200  static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
202  static Index getChildDim() { return 1; }
204  static Index32 leafCount() { return 1; }
206  static Index32 nonLeafCount() { return 0; }
207 
209  Index64 onVoxelCount() const { return mBuffer.mData.countOn(); }
211  Index64 offVoxelCount() const { return mBuffer.mData.countOff(); }
212  Index64 onLeafVoxelCount() const { return this->onVoxelCount(); }
213  Index64 offLeafVoxelCount() const { return this->offVoxelCount(); }
214  static Index64 onTileCount() { return 0; }
215  static Index64 offTileCount() { return 0; }
216 
218  bool isEmpty() const { return mBuffer.mData.isOff(); }
220  bool isDense() const { return mBuffer.mData.isOn(); }
221 
222 #ifndef OPENVDB_2_ABI_COMPATIBLE
223  bool isAllocated() const { return true; }
230  bool allocate() { return true; }
231 #endif
232 
234  Index64 memUsage() const;
235 
239  void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
240 
243  CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
244 
246  void setOrigin(const Coord& origin) { mOrigin = origin; }
248  const Coord& origin() const { return mOrigin; }
250  void getOrigin(Coord& origin) const { origin = mOrigin; }
251  void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
253 
255  static Index coordToOffset(const Coord& xyz);
258  static Coord offsetToLocalCoord(Index n);
260  Coord offsetToGlobalCoord(Index n) const;
261 
263  std::string str() const;
264 
267  template<typename OtherType, Index OtherLog2Dim>
268  bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
269 
271  bool operator==(const LeafNode&) const;
272  bool operator!=(const LeafNode&) const;
273 
274  //
275  // Buffer management
276  //
279  void swap(Buffer& other) { mBuffer.swap(other); }
280  const Buffer& buffer() const { return mBuffer; }
281  Buffer& buffer() { return mBuffer; }
282 
283  //
284  // I/O methods
285  //
287  void readTopology(std::istream&, bool fromHalf = false);
289  void writeTopology(std::ostream&, bool toHalf = false) const;
290 
292  void readBuffers(std::istream&, bool fromHalf = false);
293  void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
295  void writeBuffers(std::ostream&, bool toHalf = false) const;
296 
297  //
298  // Accessor methods
299  //
301  const bool& getValue(const Coord& xyz) const;
303  const bool& getValue(Index offset) const;
304 
308  bool probeValue(const Coord& xyz, bool& val) const;
309 
311  static Index getValueLevel(const Coord&) { return LEVEL; }
312 
314  void setActiveState(const Coord& xyz, bool on);
316  void setActiveState(Index offset, bool on) { assert(offset<SIZE); mBuffer.mData.set(offset, on); }
317 
319  void setValueOnly(const Coord& xyz, bool val);
321  void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
322 
324  void setValueOff(const Coord& xyz) { mBuffer.mData.setOff(this->coordToOffset(xyz)); }
326  void setValueOff(Index offset) { assert(offset < SIZE); mBuffer.mData.setOff(offset); }
327 
329  void setValueOff(const Coord& xyz, bool val);
331  void setValueOff(Index offset, bool val);
332 
334  void setValueOn(const Coord& xyz) { mBuffer.mData.setOn(this->coordToOffset(xyz)); }
336  void setValueOn(Index offset) { assert(offset < SIZE); mBuffer.mData.setOn(offset); }
337 
339  void setValueOn(const Coord& xyz, bool val);
341  void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); }
343  void setValueOn(Index offset, bool val);
344 
347  template<typename ModifyOp>
348  void modifyValue(Index offset, const ModifyOp& op);
351  template<typename ModifyOp>
352  void modifyValue(const Coord& xyz, const ModifyOp& op);
353 
355  template<typename ModifyOp>
356  void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
357 
359  void setValuesOn() { mBuffer.mData.setOn(); }
361  void setValuesOff() { mBuffer.mData.setOff(); }
362 
364  bool isValueOn(const Coord& xyz) const { return mBuffer.mData.isOn(this->coordToOffset(xyz)); }
366  bool isValueOn(Index offset) const { assert(offset < SIZE); return mBuffer.mData.isOn(offset); }
367 
369  static bool hasActiveTiles() { return false; }
370 
372  void clip(const CoordBBox&, bool background);
373 
375  void fill(const CoordBBox& bbox, bool value, bool dummy = false);
376 
378  void fill(const bool& value, bool dummy = false);
379 
391  template<typename DenseT>
392  void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
393 
410  template<typename DenseT>
411  void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
412 
415  template<typename AccessorT>
416  const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
417 
420  template<typename AccessorT>
421  bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
422 
425  template<typename AccessorT>
426  void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
427 
431  template<typename AccessorT>
432  void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
433 
436  template<typename AccessorT>
437  void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
438  {
439  this->setValueOff(xyz, value);
440  }
441 
445  template<typename ModifyOp, typename AccessorT>
446  void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
447  {
448  this->modifyValue(xyz, op);
449  }
450 
453  template<typename ModifyOp, typename AccessorT>
454  void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
455  {
456  this->modifyValueAndActiveState(xyz, op);
457  }
458 
462  template<typename AccessorT>
463  void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
464  {
465  this->setActiveState(xyz, on);
466  }
467 
471  template<typename AccessorT>
472  bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
473  {
474  return this->probeValue(xyz, val);
475  }
476 
479  template<typename AccessorT>
480  static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
481 
485  const bool& getFirstValue() const { if (mBuffer.mData.isOn(0)) return sOn; else return sOff; }
489  const bool& getLastValue() const { if (mBuffer.mData.isOn(SIZE-1)) return sOn; else return sOff; }
490 
494  bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
496  bool isInactive() const { return mBuffer.mData.isOff(); }
497 
500  void resetBackground(bool, bool) {}
501 
503  void negate() { mBuffer.mData.toggle(); }
504 
505  template<MergePolicy Policy>
506  void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
507  template<MergePolicy Policy> void merge(bool tileValue, bool tileActive=false);
508 
511  void voxelizeActiveTiles(bool = true) {}
512 
519  template<typename OtherType>
520  void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
521 
533  template<typename OtherType>
534  void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
535 
547  template<typename OtherType>
548  void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
549 
550  template<typename CombineOp>
551  void combine(const LeafNode& other, CombineOp& op);
552  template<typename CombineOp>
553  void combine(bool, bool valueIsActive, CombineOp& op);
554 
555  template<typename CombineOp, typename OtherType /*= bool*/>
556  void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
557  template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
558  void combine2(bool, const OtherNodeT& other, bool valueIsActive, CombineOp&);
559  template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
560  void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
561 
566  template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
567 
568  template<typename VisitorOp> void visit(VisitorOp&);
569  template<typename VisitorOp> void visit(VisitorOp&) const;
570 
571  template<typename OtherLeafNodeType, typename VisitorOp>
572  void visit2Node(OtherLeafNodeType& other, VisitorOp&);
573  template<typename OtherLeafNodeType, typename VisitorOp>
574  void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
575  template<typename IterT, typename VisitorOp>
576  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
577  template<typename IterT, typename VisitorOp>
578  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
579 
581  void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
583  void addLeaf(LeafNode*) {}
584  template<typename AccessorT>
585  void addLeafAndCache(LeafNode*, AccessorT&) {}
586  template<typename NodeT>
587  NodeT* stealNode(const Coord&, const ValueType&, bool) { return NULL; }
588  template<typename NodeT>
589  NodeT* probeNode(const Coord&) { return NULL; }
590  template<typename NodeT>
591  const NodeT* probeConstNode(const Coord&) const { return NULL; }
592  template<typename ArrayT> void getNodes(ArrayT&) const {}
593  template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
595 
596  void addTile(Index level, const Coord&, bool val, bool active);
597  void addTile(Index offset, bool val, bool active);
598  template<typename AccessorT>
599  void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
600 
602  LeafNode* touchLeaf(const Coord&) { return this; }
604  template<typename AccessorT>
605  LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
606  LeafNode* probeLeaf(const Coord&) { return this; }
607  template<typename AccessorT>
608  LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
609  template<typename NodeT, typename AccessorT>
610  NodeT* probeNodeAndCache(const Coord&, AccessorT&)
611  {
613  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
614  return reinterpret_cast<NodeT*>(this);
616  }
618 
619  const LeafNode* probeLeaf(const Coord&) const { return this; }
621  template<typename AccessorT>
622  const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
623  const LeafNode* probeConstLeaf(const Coord&) const { return this; }
624  template<typename AccessorT>
625  const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
626  template<typename NodeT, typename AccessorT>
627  const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
628  {
630  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
631  return reinterpret_cast<const NodeT*>(this);
633  }
635 
636  //
637  // Iterators
638  //
639 protected:
643 
644  template<typename MaskIterT, typename NodeT, typename ValueT>
645  struct ValueIter:
646  // Derives from SparseIteratorBase, but can also be used as a dense iterator,
647  // if MaskIterT is a dense mask iterator type.
648  public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
649  {
651 
653  ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
654 
655  const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
656  const bool& getValue() const { return this->getItem(this->pos()); }
657 
658  // Note: setItem() can't be called on const iterators.
659  void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
660  // Note: setValue() can't be called on const iterators.
661  void setValue(bool value) const { this->setItem(this->pos(), value); }
662 
663  // Note: modifyItem() can't be called on const iterators.
664  template<typename ModifyOp>
665  void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
666  // Note: modifyValue() can't be called on const iterators.
667  template<typename ModifyOp>
668  void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
669  };
670 
672  template<typename MaskIterT, typename NodeT>
673  struct ChildIter:
674  public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
675  {
677  ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
678  MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
679  };
680 
681  template<typename NodeT, typename ValueT>
682  struct DenseIter: public DenseIteratorBase<
683  MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
684  {
687 
689  DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
690 
691  bool getItem(Index pos, void*& child, NonConstValueT& value) const
692  {
693  value = this->parent().getValue(pos);
694  child = NULL;
695  return false; // no child
696  }
697 
698  // Note: setItem() can't be called on const iterators.
699  //void setItem(Index pos, void* child) const {}
700 
701  // Note: unsetItem() can't be called on const iterators.
702  void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
703  };
704 
705 public:
706  typedef ValueIter<MaskOnIter, LeafNode, const bool> ValueOnIter;
707  typedef ValueIter<MaskOnIter, const LeafNode, const bool> ValueOnCIter;
708  typedef ValueIter<MaskOffIter, LeafNode, const bool> ValueOffIter;
709  typedef ValueIter<MaskOffIter, const LeafNode, const bool> ValueOffCIter;
710  typedef ValueIter<MaskDenseIter, LeafNode, const bool> ValueAllIter;
711  typedef ValueIter<MaskDenseIter, const LeafNode, const bool> ValueAllCIter;
712  typedef ChildIter<MaskOnIter, LeafNode> ChildOnIter;
713  typedef ChildIter<MaskOnIter, const LeafNode> ChildOnCIter;
714  typedef ChildIter<MaskOffIter, LeafNode> ChildOffIter;
715  typedef ChildIter<MaskOffIter, const LeafNode> ChildOffCIter;
716  typedef DenseIter<LeafNode, bool> ChildAllIter;
717  typedef DenseIter<const LeafNode, const bool> ChildAllCIter;
718 
719  ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mBuffer.mData.beginOn(), this); }
720  ValueOnCIter beginValueOn() const { return ValueOnCIter(mBuffer.mData.beginOn(), this); }
721  ValueOnIter beginValueOn() { return ValueOnIter(mBuffer.mData.beginOn(), this); }
722  ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mBuffer.mData.beginOff(), this); }
723  ValueOffCIter beginValueOff() const { return ValueOffCIter(mBuffer.mData.beginOff(), this); }
724  ValueOffIter beginValueOff() { return ValueOffIter(mBuffer.mData.beginOff(), this); }
725  ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mBuffer.mData.beginDense(), this); }
726  ValueAllCIter beginValueAll() const { return ValueAllCIter(mBuffer.mData.beginDense(), this); }
727  ValueAllIter beginValueAll() { return ValueAllIter(mBuffer.mData.beginDense(), this); }
728 
729  ValueOnCIter cendValueOn() const { return ValueOnCIter(mBuffer.mData.endOn(), this); }
730  ValueOnCIter endValueOn() const { return ValueOnCIter(mBuffer.mData.endOn(), this); }
731  ValueOnIter endValueOn() { return ValueOnIter(mBuffer.mData.endOn(), this); }
732  ValueOffCIter cendValueOff() const { return ValueOffCIter(mBuffer.mData.endOff(), this); }
733  ValueOffCIter endValueOff() const { return ValueOffCIter(mBuffer.mData.endOff(), this); }
734  ValueOffIter endValueOff() { return ValueOffIter(mBuffer.mData.endOff(), this); }
735  ValueAllCIter cendValueAll() const { return ValueAllCIter(mBuffer.mData.endDense(), this); }
736  ValueAllCIter endValueAll() const { return ValueAllCIter(mBuffer.mData.endDense(), this); }
737  ValueAllIter endValueAll() { return ValueAllIter(mBuffer.mData.endDense(), this); }
738 
739  // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
740  // because leaf nodes have no children.
741  ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mBuffer.mData.endOn(), this); }
742  ChildOnCIter beginChildOn() const { return ChildOnCIter(mBuffer.mData.endOn(), this); }
743  ChildOnIter beginChildOn() { return ChildOnIter(mBuffer.mData.endOn(), this); }
744  ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mBuffer.mData.endOff(), this); }
745  ChildOffCIter beginChildOff() const { return ChildOffCIter(mBuffer.mData.endOff(), this); }
746  ChildOffIter beginChildOff() { return ChildOffIter(mBuffer.mData.endOff(), this); }
747  ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mBuffer.mData.beginDense(), this); }
748  ChildAllCIter beginChildAll() const { return ChildAllCIter(mBuffer.mData.beginDense(), this); }
749  ChildAllIter beginChildAll() { return ChildAllIter(mBuffer.mData.beginDense(), this); }
750 
751  ChildOnCIter cendChildOn() const { return ChildOnCIter(mBuffer.mData.endOn(), this); }
752  ChildOnCIter endChildOn() const { return ChildOnCIter(mBuffer.mData.endOn(), this); }
753  ChildOnIter endChildOn() { return ChildOnIter(mBuffer.mData.endOn(), this); }
754  ChildOffCIter cendChildOff() const { return ChildOffCIter(mBuffer.mData.endOff(), this); }
755  ChildOffCIter endChildOff() const { return ChildOffCIter(mBuffer.mData.endOff(), this); }
756  ChildOffIter endChildOff() { return ChildOffIter(mBuffer.mData.endOff(), this); }
757  ChildAllCIter cendChildAll() const { return ChildAllCIter(mBuffer.mData.endDense(), this); }
758  ChildAllCIter endChildAll() const { return ChildAllCIter(mBuffer.mData.endDense(), this); }
759  ChildAllIter endChildAll() { return ChildAllIter(mBuffer.mData.endDense(), this); }
760 
761  //
762  // Mask accessors
763  //
764  bool isValueMaskOn(Index n) const { return mBuffer.mData.isOn(n); }
765  bool isValueMaskOn() const { return mBuffer.mData.isOn(); }
766  bool isValueMaskOff(Index n) const { return mBuffer.mData.isOff(n); }
767  bool isValueMaskOff() const { return mBuffer.mData.isOff(); }
768  const NodeMaskType& getValueMask() const { return mBuffer.mData; }
769  const NodeMaskType& valueMask() const { return mBuffer.mData; }
770  NodeMaskType& getValueMask() { return mBuffer.mData; }
771  void setValueMask(const NodeMaskType& mask) { mBuffer.mData = mask; }
772  bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
773  bool isChildMaskOff(Index) const { return true; }
774  bool isChildMaskOff() const { return true; }
775 protected:
776  void setValueMask(Index n, bool on) { mBuffer.mData.set(n, on); }
777  void setValueMaskOn(Index n) { mBuffer.mData.setOn(n); }
778  void setValueMaskOff(Index n) { mBuffer.mData.setOff(n); }
779 
781  static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
782 
783  template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
784  static inline void doVisit(NodeT&, VisitorOp&);
785 
786  template<typename NodeT, typename OtherNodeT, typename VisitorOp,
787  typename ChildAllIterT, typename OtherChildAllIterT>
788  static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
789 
790  template<typename NodeT, typename VisitorOp,
791  typename ChildAllIterT, typename OtherChildAllIterT>
792  static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
793 
795  Buffer mBuffer;
796 
799 
800  // These static declarations must be on separate lines to avoid VC9 compiler errors.
801  static const bool sOn;
802  static const bool sOff;
803 
804 private:
807  template<typename, Index> friend class LeafNode;
808 
809  friend struct ValueIter<MaskOnIter, LeafNode, bool>;
810  friend struct ValueIter<MaskOffIter, LeafNode, bool>;
811  friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
812  friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
813  friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
814  friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
815 
817  friend class IteratorBase<MaskOnIter, LeafNode>;
820  friend class IteratorBase<MaskOffIter, LeafNode>;
821  friend class IteratorBase<MaskDenseIter, LeafNode>;
823 
824 }; // class LeafNode<ValueMask>
825 
826 
831 template<Index Log2Dim> const bool LeafNode<ValueMask, Log2Dim>::sOn = true;
832 template<Index Log2Dim> const bool LeafNode<ValueMask, Log2Dim>::sOff = false;
833 
834 
836 
837 
838 template<Index Log2Dim>
839 inline
841  : mOrigin(0, 0, 0)
842 {
843 }
844 
845 template<Index Log2Dim>
846 inline
847 LeafNode<ValueMask, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool)
848  : mBuffer(value)
849  , mOrigin(xyz & (~(DIM - 1)))
850 {
851 }
852 
853 
854 #ifndef OPENVDB_2_ABI_COMPATIBLE
855 template<Index Log2Dim>
856 inline
858  : mBuffer(value)
859  , mOrigin(xyz & (~(DIM - 1)))
860 {
861 }
862 #endif
863 
864 
865 template<Index Log2Dim>
866 inline
868  : mBuffer(other.mBuffer)
869  , mOrigin(other.mOrigin)
870 {
871 }
872 
873 
874 // Copy-construct from a leaf node with the same configuration but a different ValueType.
875 template<Index Log2Dim>
876 template<typename ValueT>
877 inline
879  : mBuffer(other.valueMask())
880  , mOrigin(other.origin())
881 {
882 }
883 
884 
885 template<Index Log2Dim>
886 template<typename ValueT>
887 inline
889  bool, TopologyCopy)
890  : mBuffer(other.valueMask())// value = active state
891  , mOrigin(other.origin())
892 {
893 }
894 
895 
896 template<Index Log2Dim>
897 template<typename ValueT>
898 inline
900  : mBuffer(other.valueMask())// value = active state
901  , mOrigin(other.origin())
902 {
903 }
904 
905 
906 template<Index Log2Dim>
907 template<typename ValueT>
908 inline
910  bool offValue, bool onValue, TopologyCopy)
911  : mBuffer(other.valueMask())
912  , mOrigin(other.origin())
913 {
914  if (offValue==true) {
915  if (onValue==false) {
916  mBuffer.mData.toggle();
917  } else {
918  mBuffer.mData.setOn();
919  }
920  }
921 }
922 
923 
924 template<Index Log2Dim>
925 inline
927 {
928 }
929 
930 
932 
933 
934 template<Index Log2Dim>
935 inline Index64
937 {
938  // Use sizeof(*this) to capture alignment-related padding
939  return sizeof(*this);
940 }
941 
942 
943 template<Index Log2Dim>
944 inline void
946 {
947  CoordBBox this_bbox = this->getNodeBoundingBox();
948  if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
949  if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
950  if (visitVoxels) {//use voxel granularity?
951  this_bbox.reset();
952  for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
953  this_bbox.translate(this->origin());
954  }
955  bbox.expand(this_bbox);
956  }
957 }
958 
959 
960 template<Index Log2Dim>
961 template<typename OtherType, Index OtherLog2Dim>
962 inline bool
964 {
965  assert(other);
966  return (Log2Dim == OtherLog2Dim && mBuffer.mData == other->getValueMask());
967 }
968 
969 
970 template<Index Log2Dim>
971 inline std::string
973 {
974  std::ostringstream ostr;
975  ostr << "LeafNode @" << mOrigin << ": ";
976  for (Index32 n = 0; n < SIZE; ++n) ostr << (mBuffer.mData.isOn(n) ? '#' : '.');
977  return ostr.str();
978 }
979 
980 
982 
983 
984 template<Index Log2Dim>
985 inline Index
987 {
988  assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
989  return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
990  + ((xyz[1] & (DIM-1u)) << Log2Dim)
991  + (xyz[2] & (DIM-1u));
992 }
993 
994 
995 template<Index Log2Dim>
996 inline Coord
998 {
999  assert(n < (1 << 3*Log2Dim));
1000  Coord xyz;
1001  xyz.setX(n >> 2*Log2Dim);
1002  n &= ((1 << 2*Log2Dim) - 1);
1003  xyz.setY(n >> Log2Dim);
1004  xyz.setZ(n & ((1 << Log2Dim) - 1));
1005  return xyz;
1006 }
1007 
1008 
1009 template<Index Log2Dim>
1010 inline Coord
1012 {
1013  return (this->offsetToLocalCoord(n) + this->origin());
1014 }
1015 
1016 
1018 
1019 
1020 template<Index Log2Dim>
1021 inline void
1022 LeafNode<ValueMask, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
1023 {
1024  mBuffer.mData.load(is);
1025 }
1026 
1027 
1028 template<Index Log2Dim>
1029 inline void
1030 LeafNode<ValueMask, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
1031 {
1032  mBuffer.mData.save(os);
1033 }
1034 
1035 
1036 template<Index Log2Dim>
1037 inline void
1038 LeafNode<ValueMask, Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
1039 {
1040  // Boolean LeafNodes don't currently implement lazy loading.
1041  // Instead, load the full buffer, then clip it.
1042 
1043  this->readBuffers(is, fromHalf);
1044 
1045  // Get this tree's background value.
1046  bool background = false;
1047  if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1048  background = *static_cast<const bool*>(bgPtr);
1049  }
1050  this->clip(clipBBox, background);
1051 }
1052 
1053 
1054 template<Index Log2Dim>
1055 inline void
1056 LeafNode<ValueMask, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
1057 {
1058  // Read in the value mask = buffer.
1059  mBuffer.mData.load(is);
1060  // Read in the origin.
1061  is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1062 }
1063 
1064 
1065 template<Index Log2Dim>
1066 inline void
1067 LeafNode<ValueMask, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1068 {
1069  // Write out the value mask = buffer.
1070  mBuffer.mData.save(os);
1071  // Write out the origin.
1072  os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1073 }
1074 
1075 
1077 
1078 
1079 template<Index Log2Dim>
1080 inline bool
1081 LeafNode<ValueMask, Log2Dim>::operator==(const LeafNode& other) const
1082 {
1083  return mOrigin == other.mOrigin && mBuffer == other.mBuffer;
1084 }
1085 
1086 
1087 template<Index Log2Dim>
1088 inline bool
1089 LeafNode<ValueMask, Log2Dim>::operator!=(const LeafNode& other) const
1090 {
1091  return !(this->operator==(other));
1092 }
1093 
1094 
1096 
1097 
1098 template<Index Log2Dim>
1099 inline bool
1100 LeafNode<ValueMask, Log2Dim>::isConstant(bool& constValue, bool& state, bool) const
1101 {
1102  if (!mBuffer.mData.isConstant(state)) return false;
1103 
1104  constValue = state;
1105  return true;
1106 }
1107 
1108 
1110 
1111 
1112 template<Index Log2Dim>
1113 inline void
1114 LeafNode<ValueMask, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, bool val, bool active)
1115 {
1116  this->addTile(this->coordToOffset(xyz), val, active);
1117 }
1118 
1119 template<Index Log2Dim>
1120 inline void
1121 LeafNode<ValueMask, Log2Dim>::addTile(Index offset, bool val, bool active)
1122 {
1123  assert(offset < SIZE);
1124  this->setValueOnly(offset, val);
1125  this->setActiveState(offset, active);
1126 }
1127 
1128 template<Index Log2Dim>
1129 template<typename AccessorT>
1130 inline void
1132  bool val, bool active, AccessorT&)
1133 {
1134  this->addTile(level, xyz, val, active);
1135 }
1136 
1137 
1139 
1140 
1141 template<Index Log2Dim>
1142 inline const bool&
1144 {
1145  // This *CANNOT* use operator ? because Visual C++
1146  if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return sOn; else return sOff;
1147 }
1148 
1149 
1150 template<Index Log2Dim>
1151 inline const bool&
1153 {
1154  assert(offset < SIZE);
1155  // This *CANNOT* use operator ? for Windows
1156  if (mBuffer.mData.isOn(offset)) return sOn; else return sOff;
1157 }
1158 
1159 
1160 template<Index Log2Dim>
1161 inline bool
1163 {
1164  const Index offset = this->coordToOffset(xyz);
1165  val = mBuffer.mData.isOn(offset);
1166  return val;
1167 }
1168 
1169 
1170 template<Index Log2Dim>
1171 inline void
1173 {
1174  this->setValueOn(this->coordToOffset(xyz), val);
1175 }
1176 
1177 
1178 template<Index Log2Dim>
1179 inline void
1181 {
1182  assert(offset < SIZE);
1183  mBuffer.mData.set(offset, val);
1184 }
1185 
1186 
1187 template<Index Log2Dim>
1188 inline void
1190 {
1191  this->setValueOnly(this->coordToOffset(xyz), val);
1192 }
1193 
1194 
1195 template<Index Log2Dim>
1196 inline void
1198 {
1199  mBuffer.mData.set(this->coordToOffset(xyz), on);
1200 }
1201 
1202 
1203 template<Index Log2Dim>
1204 inline void
1206 {
1207  this->setValueOff(this->coordToOffset(xyz), val);
1208 }
1209 
1210 
1211 template<Index Log2Dim>
1212 inline void
1214 {
1215  assert(offset < SIZE);
1216  mBuffer.mData.set(offset, val);
1217 }
1218 
1219 
1220 template<Index Log2Dim>
1221 template<typename ModifyOp>
1222 inline void
1224 {
1225  bool val = mBuffer.mData.isOn(offset);
1226  op(val);
1227  mBuffer.mData.set(offset, val);
1228 }
1229 
1230 
1231 template<Index Log2Dim>
1232 template<typename ModifyOp>
1233 inline void
1234 LeafNode<ValueMask, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1235 {
1236  this->modifyValue(this->coordToOffset(xyz), op);
1237 }
1238 
1239 
1240 template<Index Log2Dim>
1241 template<typename ModifyOp>
1242 inline void
1244 {
1245  const Index offset = this->coordToOffset(xyz);
1246  bool val = mBuffer.mData.isOn(offset), state = val;
1247  op(val, state);
1248  mBuffer.mData.set(offset, val);
1249 }
1250 
1251 
1253 
1254 
1255 template<Index Log2Dim>
1256 template<MergePolicy Policy>
1257 inline void
1258 LeafNode<ValueMask, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1259 {
1261  if (Policy == MERGE_NODES) return;
1262  mBuffer.mData |= other.mBuffer.mData;
1264 }
1265 
1266 template<Index Log2Dim>
1267 template<MergePolicy Policy>
1268 inline void
1270 {
1272  if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1273  if (tileValue) mBuffer.mData.setOn();
1275 }
1276 
1277 
1279 
1280 
1281 template<Index Log2Dim>
1282 template<typename OtherType>
1283 inline void
1285 {
1286  mBuffer.mData |= other.valueMask();
1287 }
1288 
1289 
1290 template<Index Log2Dim>
1291 template<typename OtherType>
1292 inline void
1294  const bool&)
1295 {
1296  mBuffer.mData &= other.valueMask();
1297 }
1298 
1299 
1300 template<Index Log2Dim>
1301 template<typename OtherType>
1302 inline void
1304  const bool&)
1305 {
1306  mBuffer.mData &= !other.valueMask();
1307 }
1308 
1309 
1311 
1312 
1313 template<Index Log2Dim>
1314 inline void
1315 LeafNode<ValueMask, Log2Dim>::clip(const CoordBBox& clipBBox, bool background)
1316 {
1317  CoordBBox nodeBBox = this->getNodeBoundingBox();
1318  if (!clipBBox.hasOverlap(nodeBBox)) {
1319  // This node lies completely outside the clipping region. Fill it with background tiles.
1320  this->fill(nodeBBox, background, /*active=*/false);
1321  } else if (clipBBox.isInside(nodeBBox)) {
1322  // This node lies completely inside the clipping region. Leave it intact.
1323  return;
1324  }
1325 
1326  // This node isn't completely contained inside the clipping region.
1327  // Set any voxels that lie outside the region to the background value.
1328 
1329  // Construct a boolean mask that is on inside the clipping region and off outside it.
1330  NodeMaskType mask;
1331  nodeBBox.intersect(clipBBox);
1332  Coord xyz;
1333  int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1334  for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1335  for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1336  for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1337  mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1338  }
1339  }
1340  }
1341 
1342  // Set voxels that lie in the inactive region of the mask (i.e., outside
1343  // the clipping region) to the background value.
1344  for (MaskOffIter maskIter = mask.beginOff(); maskIter; ++maskIter) {
1345  this->setValueOff(maskIter.pos(), background);
1346  }
1347 }
1348 
1349 
1351 
1352 
1353 template<Index Log2Dim>
1354 inline void
1355 LeafNode<ValueMask, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool)
1356 {
1357  for (Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1358  const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1359  for (Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1360  const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1361  for (Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1362  const Index offset = offsetXY + (z & (DIM-1u));
1363  mBuffer.mData.set(offset, value);
1364  }
1365  }
1366  }
1367 }
1368 
1369 template<Index Log2Dim>
1370 inline void
1371 LeafNode<ValueMask, Log2Dim>::fill(const bool& value, bool)
1372 {
1373  mBuffer.fill(value);
1374 }
1375 
1376 
1378 
1379 
1380 template<Index Log2Dim>
1381 template<typename DenseT>
1382 inline void
1383 LeafNode<ValueMask, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1384 {
1385  typedef typename DenseT::ValueType DenseValueType;
1386 
1387  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1388  const Coord& min = dense.bbox().min();
1389  DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1390  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1391  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1392  DenseValueType* t1 = t0 + xStride * (x - min[0]);
1393  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1394  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1395  DenseValueType* t2 = t1 + yStride * (y - min[1]);
1396  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1397  for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1398  *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1399  }
1400  }
1401  }
1402 }
1403 
1404 
1405 template<Index Log2Dim>
1406 template<typename DenseT>
1407 inline void
1409  bool background, bool tolerance)
1410 {
1411  typedef typename DenseT::ValueType DenseValueType;
1412  struct Local {
1413  inline static bool toBool(const DenseValueType& v) { return !math::isZero(v); }
1414  };
1415 
1416  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1417  const Coord& min = dense.bbox().min();
1418  const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1419  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1420  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1421  const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1422  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1423  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1424  const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1425  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1426  for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1427  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1428  if (tolerance || (background == Local::toBool(*s2))) {
1429  mBuffer.mData.set(n2, background);
1430  } else {
1431  mBuffer.mData.set(n2, Local::toBool(*s2));
1432  }
1433  }
1434  }
1435  }
1436 }
1437 
1438 
1440 
1441 
1442 template<Index Log2Dim>
1443 template<typename CombineOp>
1444 inline void
1445 LeafNode<ValueMask, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1446 {
1447  CombineArgs<bool> args;
1448  for (Index i = 0; i < SIZE; ++i) {
1449  bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1450  op(args.setARef(aVal)
1451  .setAIsActive(aVal)
1452  .setBRef(bVal)
1453  .setBIsActive(bVal)
1454  .setResultRef(result));
1455  mBuffer.mData.set(i, result);
1456  }
1457 }
1458 
1459 
1460 template<Index Log2Dim>
1461 template<typename CombineOp>
1462 inline void
1463 LeafNode<ValueMask, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1464 {
1465  CombineArgs<bool> args;
1466  args.setBRef(value).setBIsActive(valueIsActive);
1467  for (Index i = 0; i < SIZE; ++i) {
1468  bool result = false, aVal = mBuffer.mData.isOn(i);
1469  op(args.setARef(aVal)
1470  .setAIsActive(aVal)
1471  .setResultRef(result));
1472  mBuffer.mData.set(i, result);
1473  }
1474 }
1475 
1476 
1478 
1479 
1480 template<Index Log2Dim>
1481 template<typename CombineOp, typename OtherType>
1482 inline void
1483 LeafNode<ValueMask, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1484  bool valueIsActive, CombineOp& op)
1485 {
1487  args.setBRef(value).setBIsActive(valueIsActive);
1488  for (Index i = 0; i < SIZE; ++i) {
1489  bool result = false, aVal = other.mBuffer.mData.isOn(i);
1490  op(args.setARef(aVal)
1491  .setAIsActive(aVal)
1492  .setResultRef(result));
1493  mBuffer.mData.set(i, result);
1494  }
1495 }
1496 
1497 
1498 template<Index Log2Dim>
1499 template<typename CombineOp, typename OtherNodeT>
1500 inline void
1501 LeafNode<ValueMask, Log2Dim>::combine2(bool value, const OtherNodeT& other,
1502  bool valueIsActive, CombineOp& op)
1503 {
1505  args.setARef(value).setAIsActive(valueIsActive);
1506  for (Index i = 0; i < SIZE; ++i) {
1507  bool result = false, bVal = other.mBuffer.mData.isOn(i);
1508  op(args.setBRef(bVal)
1509  .setBIsActive(bVal)
1510  .setResultRef(result));
1511  mBuffer.mData.set(i, result);
1512  }
1513 }
1514 
1515 
1516 template<Index Log2Dim>
1517 template<typename CombineOp, typename OtherNodeT>
1518 inline void
1519 LeafNode<ValueMask, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1520 {
1522  for (Index i = 0; i < SIZE; ++i) {
1523  bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1524  op(args.setARef(b0Val)
1525  .setAIsActive(b0Val)
1526  .setBRef(b1Val)
1527  .setBIsActive(b1Val)
1528  .setResultRef(result));
1529  mBuffer.mData.set(i, result);
1530  }
1531 }
1532 
1533 
1535 
1536 template<Index Log2Dim>
1537 template<typename BBoxOp>
1538 inline void
1540 {
1541  if (op.template descent<LEVEL>()) {
1542  for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1543 #ifdef _MSC_VER
1544  op.operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1545 #else
1546  op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1547 #endif
1548  }
1549  } else {
1550 #ifdef _MSC_VER
1551  op.operator()<LEVEL>(this->getNodeBoundingBox());
1552 #else
1553  op.template operator()<LEVEL>(this->getNodeBoundingBox());
1554 #endif
1555  }
1556 }
1557 
1558 
1559 template<Index Log2Dim>
1560 template<typename VisitorOp>
1561 inline void
1563 {
1564  doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1565 }
1566 
1567 
1568 template<Index Log2Dim>
1569 template<typename VisitorOp>
1570 inline void
1572 {
1573  doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1574 }
1575 
1576 
1577 template<Index Log2Dim>
1578 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1579 inline void
1580 LeafNode<ValueMask, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1581 {
1582  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1583  op(iter);
1584  }
1585 }
1586 
1587 
1589 
1590 
1591 template<Index Log2Dim>
1592 template<typename OtherLeafNodeType, typename VisitorOp>
1593 inline void
1594 LeafNode<ValueMask, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1595 {
1596  doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1597  typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1598 }
1599 
1600 
1601 template<Index Log2Dim>
1602 template<typename OtherLeafNodeType, typename VisitorOp>
1603 inline void
1604 LeafNode<ValueMask, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1605 {
1606  doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1607  typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1608 }
1609 
1610 
1611 template<Index Log2Dim>
1612 template<
1613  typename NodeT,
1614  typename OtherNodeT,
1615  typename VisitorOp,
1616  typename ChildAllIterT,
1617  typename OtherChildAllIterT>
1618 inline void
1619 LeafNode<ValueMask, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1620 {
1621  // Allow the two nodes to have different ValueTypes, but not different dimensions.
1622  BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
1623  BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
1624 
1625  ChildAllIterT iter = self.beginChildAll();
1626  OtherChildAllIterT otherIter = other.beginChildAll();
1627 
1628  for ( ; iter && otherIter; ++iter, ++otherIter) {
1629  op(iter, otherIter);
1630  }
1631 }
1632 
1633 
1635 
1636 
1637 template<Index Log2Dim>
1638 template<typename IterT, typename VisitorOp>
1639 inline void
1640 LeafNode<ValueMask, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1641 {
1642  doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1643 }
1644 
1645 
1646 template<Index Log2Dim>
1647 template<typename IterT, typename VisitorOp>
1648 inline void
1649 LeafNode<ValueMask, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1650 {
1651  doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1652 }
1653 
1654 
1655 template<Index Log2Dim>
1656 template<
1657  typename NodeT,
1658  typename VisitorOp,
1659  typename ChildAllIterT,
1660  typename OtherChildAllIterT>
1661 inline void
1662 LeafNode<ValueMask, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1663  VisitorOp& op, bool otherIsLHS)
1664 {
1665  if (!otherIter) return;
1666 
1667  if (otherIsLHS) {
1668  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1669  op(otherIter, iter);
1670  }
1671  } else {
1672  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1673  op(iter, otherIter);
1674  }
1675  }
1676 }
1677 
1678 } // namespace tree
1679 } // namespace OPENVDB_VERSION_NAME
1680 } // namespace openvdb
1681 
1682 #endif // OPENVDB_TREE_LEAF_NODE_MASK_HAS_BEEN_INCLUDED
1683 
1684 // Copyright (c) 2012-2016 DreamWorks Animation LLC
1685 // All rights reserved. This software is distributed under the
1686 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeMask.h:220
OffIterator beginOff() const
Definition: NodeMasks.h:351
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeMask.h:246
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:622
ChildAllCIter beginChildAll() const
Definition: LeafNodeMask.h:748
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1727
LeafNode specialization for values of type ValueMask that encodes both the active states and the bool...
Definition: LeafNodeMask.h:55
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeMask.h:366
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeMask.h:416
NodeMaskType & getValueMask()
Definition: LeafNodeMask.h:770
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:469
ValueOffCIter cendValueOff() const
Definition: LeafNodeMask.h:732
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeMask.h:713
Index64 offLeafVoxelCount() const
Definition: LeafNodeMask.h:213
static const Index LEVEL
Definition: LeafNode.h:81
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:591
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1276
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeMask.h:707
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNodeMask.h:204
NodeMaskType::Word WordType
Definition: LeafNodeMask.h:90
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeMask.h:747
WordType * data()
Definition: LeafNodeMask.h:127
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeMask.h:311
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: LeafNode.h:1745
Coord & setX(Int32 x)
Definition: Coord.h:101
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1717
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNodeMask.h:200
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1792
static const bool sOn
Definition: LeafNodeMask.h:801
void copyToDense(const GridOrTreeT &sparse, DenseT &dense, bool serial=false)
Populate a dense grid with the values of voxels from a sparse grid, where the sparse grid intersects ...
Definition: Dense.h:443
void setValue(bool value) const
Definition: LeafNodeMask.h:661
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1544
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeMask.h:485
Definition: Types.h:442
void reset()
Definition: Coord.h:338
void setValuesOff()
Mark all voxels as inactive but don&#39;t change their values.
Definition: LeafNodeMask.h:361
ValueAllIter endValueAll()
Definition: LeafNodeMask.h:737
bool isValueMaskOff() const
Definition: LeafNodeMask.h:767
void resetBackground(bool, bool)
no-op since for this temaplte specialization voxel values and states are indistinguishable.
Definition: LeafNodeMask.h:500
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNodeMask.h:202
void setItem(Index pos, bool value) const
Definition: LeafNodeMask.h:659
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:627
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNode.h:714
void visit(VisitorOp &)
Definition: LeafNode.h:2068
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1286
ChildOffCIter endChildOff() const
Definition: LeafNodeMask.h:755
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:498
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don&#39;t change its value. ...
Definition: LeafNodeMask.h:316
Int32 ValueType
Definition: Coord.h:55
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:365
Buffer(const Buffer &other)
Definition: LeafNodeMask.h:95
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeMask.h:243
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don&#39;t change its value.
Definition: LeafNodeMask.h:326
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node&#39;s set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this LeafNode and inactive in the other LeafNode.
Definition: LeafNode.h:1914
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeMask.h:668
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition: LeafNode.h:1468
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeMask.h:218
ValueOnCIter endValueOn() const
Definition: LeafNodeMask.h:730
ValueAllCIter beginValueAll() const
Definition: LeafNodeMask.h:726
const NodeMaskType & getValueMask() const
Definition: LeafNodeMask.h:768
ValueOffIter endValueOff()
Definition: LeafNodeMask.h:734
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:324
const bool & getItem(Index pos) const
Definition: LeafNodeMask.h:655
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeMask.h:192
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active...
Definition: LeafNode.h:732
bool isChildMaskOn(Index) const
Definition: LeafNodeMask.h:772
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1598
Definition: PointIndexGrid.h:69
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeMask.h:665
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:592
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:583
ValueOffCIter beginValueOff() const
Definition: LeafNodeMask.h:723
ValueOnCIter beginValueOn() const
Definition: LeafNodeMask.h:720
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don&#39;t change its value.
Definition: LeafNodeMask.h:336
boost::shared_ptr< LeafNodeType > Ptr
Definition: LeafNodeMask.h:59
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:625
bool isValueMaskOff(Index n) const
Definition: LeafNodeMask.h:766
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNodeMask.h:685
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeMask.h:480
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:593
Index memUsage() const
Definition: LeafNodeMask.h:121
ValueOnIter endValueOn()
Definition: LeafNodeMask.h:731
Int32 x() const
Definition: Coord.h:146
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeMask.h:454
NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeMask.h:642
OPENVDB_API const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNodeMask.h:62
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeMask.h:716
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNodeMask.h:334
bool probeValueAndCache(const Coord &xyz, bool &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val...
Definition: LeafNodeMask.h:472
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1263
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeMask.h:744
void copyFromDense(const DenseT &dense, GridOrTreeT &sparse, const typename GridOrTreeT::ValueType &tolerance, bool serial=false)
Populate a sparse grid with the values of all of the voxels of a dense grid.
Definition: Dense.h:590
ValueType * mData
Definition: LeafNode.h:361
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeMask.h:725
Coord & setY(Int32 y)
Definition: Coord.h:102
const Buffer & buffer() const
Definition: LeafNodeMask.h:280
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:592
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeMask.h:489
Index32 Index
Definition: Types.h:58
bool allocate()
Allocate memory for this node&#39;s buffer if it has not already been allocated.
Definition: LeafNodeMask.h:230
ChildOnCIter beginChildOn() const
Definition: LeafNodeMask.h:742
ValueMask BuildType
Definition: LeafNodeMask.h:60
Buffer(const NodeMaskType &other)
Definition: LeafNodeMask.h:94
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeMask.h:691
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeMask.h:702
bool isChildMaskOff(Index) const
Definition: LeafNodeMask.h:773
bool operator==(const Buffer &other) const
Definition: LeafNodeMask.h:114
int32_t Int32
Definition: Types.h:60
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeMask.h:722
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1981
uint64_t Index64
Definition: Types.h:57
void fill(const ValueType &val)
Populate this buffer with a constant value.
Definition: LeafNode.h:171
void fill(bool val)
Definition: LeafNodeMask.h:97
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:589
ValueOffIter beginValueOff()
Definition: LeafNodeMask.h:724
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:653
#define OPENVDB_VERSION_NAME
Definition: version.h:43
NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeMask.h:640
OPENVDB_STATIC_SPECIALIZATION GridType::Ptr clip(const GridType &grid, const BBoxd &)
Clip the given grid against a world-space bounding box and return a new grid containing the result...
Definition: Clip.h:356
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeMask.h:719
const Coord & origin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:475
ChildAllCIter endChildAll() const
Definition: LeafNodeMask.h:758
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1387
Coord & setZ(Int32 z)
Definition: Coord.h:103
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:401
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeMask.h:712
LeafNode< ValueMask, Log2Dim > LeafNodeType
Definition: LeafNodeMask.h:58
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeMask.h:689
ChildOnIter endChildOn()
Definition: LeafNodeMask.h:753
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeMask.h:798
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1707
static Index64 offTileCount()
Definition: LeafNodeMask.h:215
ValueOnCIter cendValueOn() const
Definition: LeafNodeMask.h:729
const NodeMaskType & valueMask() const
Definition: LeafNodeMask.h:769
void negate()
Invert the bits of the voxels, i.e. states and values.
Definition: LeafNodeMask.h:503
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:2100
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:610
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don&#39;t change its value.
Definition: LeafNode.h:1361
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:623
void setValueMaskOn(Index n)
Definition: LeafNodeMask.h:777
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNodeMask.h:426
Index64 onLeafVoxelCount() const
Definition: LeafNodeMask.h:212
const bool & operator[](Index i) const
Definition: LeafNodeMask.h:112
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1809
void translate(const Coord &t)
Translate this bounding box by .
Definition: Coord.h:440
~LeafNode()
Destructor.
Definition: LeafNode.h:1256
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeMask.h:623
BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeMask.h:686
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeMask.h:741
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1536
ChildOnCIter cendChildOn() const
Definition: LeafNodeMask.h:751
ValueOffCIter endValueOff() const
Definition: LeafNodeMask.h:733
Definition: Exceptions.h:39
LeafNode< OtherValueType, Log2Dim > Type
Definition: LeafNodeMask.h:77
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeMask.h:211
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeMask.h:190
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node&#39;s set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1897
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNodeMask.h:206
ChildAllCIter cendChildAll() const
Definition: LeafNodeMask.h:757
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNodeMask.h:198
NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeMask.h:641
uint32_t Index32
Definition: Types.h:56
const bool & getValue() const
Definition: LeafNodeMask.h:656
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
bool isValueMaskOn() const
Definition: LeafNodeMask.h:765
ValueAllIter beginValueAll()
Definition: LeafNodeMask.h:727
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeMask.h:714
void setValueMaskOff(Index n)
Definition: LeafNodeMask.h:778
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:421
void setValuesOn()
Mark all voxels as active but don&#39;t change their values.
Definition: LeafNodeMask.h:359
Index64 Word
Definition: NodeMasks.h:313
const NodeMaskType & valueMask() const
Definition: LeafNode.h:1111
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:608
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeMask.h:710
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNodeMask.h:650
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeMask.h:364
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1311
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:2170
Int32 z() const
Definition: Coord.h:148
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:2045
static Index64 onTileCount()
Definition: LeafNodeMask.h:214
Definition: NodeMasks.h:267
ChildAllIter beginChildAll()
Definition: LeafNodeMask.h:749
static const Index SIZE
Definition: LeafNode.h:80
void setValueMask(Index n, bool on)
Definition: LeafNodeMask.h:776
bool operator!=(const Buffer &other) const
Definition: LeafNodeMask.h:115
static const bool sOff
Definition: LeafNodeMask.h:802
ChildOffIter beginChildOff()
Definition: LeafNodeMask.h:746
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:449
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1939
const WordType * data() const
Definition: LeafNodeMask.h:135
const Coord & min() const
Definition: Coord.h:332
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeMask.h:709
bool ValueType
Definition: LeafNodeMask.h:61
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:2125
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
ChildOnCIter endChildOn() const
Definition: LeafNodeMask.h:752
LeafNode()
Default constructor.
Definition: LeafNode.h:1170
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNodeMask.h:463
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:395
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeMask.h:677
const Coord & max() const
Definition: Coord.h:333
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNodeMask.h:324
Buffer & buffer()
Definition: LeafNodeMask.h:281
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:367
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeMask.h:781
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:1109
static Index size()
Definition: LeafNodeMask.h:122
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:594
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNodeMask.h:446
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don&#39;t change its active state.
Definition: LeafNode.h:1369
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNodeMask.h:437
static const Index LOG2DIM
Definition: LeafNode.h:75
void swap(Buffer &other)
Exchange this node&#39;s data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeMask.h:279
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeMask.h:209
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1690
Int32 y() const
Definition: Coord.h:147
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeMask.h:250
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:591
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNodeMask.h:341
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeMask.h:715
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:374
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:427
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box...
Definition: LeafNode.h:1497
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeMask.h:708
ValueAllCIter endValueAll() const
Definition: LeafNodeMask.h:736
ChildAllIter endChildAll()
Definition: LeafNodeMask.h:759
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeMask.h:771
ChildOffCIter beginChildOff() const
Definition: LeafNodeMask.h:745
Definition: NodeMasks.h:205
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNodeMask.h:511
ChildOffIter endChildOff()
Definition: LeafNodeMask.h:756
Definition: NodeMasks.h:236
bool isInactive() const
Return true if all of this node&#39;s values are inactive.
Definition: LeafNodeMask.h:496
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeMask.h:706
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:383
Definition: Types.h:444
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:2086
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
void swap(Buffer &other)
Definition: LeafNodeMask.h:119
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeMask.h:369
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don&#39;t change its active state. ...
Definition: LeafNodeMask.h:321
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNodeMask.h:432
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node&#39;s set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if both of the original voxels were active.
Definition: LeafNode.h:1905
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeMask.h:711
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:196
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNodeMask.h:194
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1753
void merge(const LeafNode &)
Definition: LeafNode.h:1844
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:749
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1327
Definition: Types.h:109
Buffer mBuffer
Bitmask representing the values AND state of voxels.
Definition: LeafNodeMask.h:795
Definition: Types.h:266
Buffer & operator=(const Buffer &b)
Definition: LeafNodeMask.h:98
bool isValueMaskOn(Index n) const
Definition: LeafNodeMask.h:764
ValueAllCIter cendValueAll() const
Definition: LeafNodeMask.h:735
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeMask.h:606
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:2146
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeMask.h:717
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:1427
ValueOnIter beginValueOn()
Definition: LeafNodeMask.h:721
void setValue(Index i, bool val)
Definition: LeafNodeMask.h:117
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNode.h:704
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:585
bool isChildMaskOff() const
Definition: LeafNodeMask.h:774
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:312
const bool & getValue(Index i) const
Definition: LeafNodeMask.h:104
ChildOnIter beginChildOn()
Definition: LeafNodeMask.h:743
ChildOffCIter cendChildOff() const
Definition: LeafNodeMask.h:754
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeMask.h:587
static const Index DIM
Definition: LeafNode.h:77
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1300
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:324
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeMask.h:251
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeMask.h:605
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128