OpenVDB  2.3.0
LeafNodeBool.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 
31 #ifndef OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAFNODEBOOL_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/util/NodeMasks.h>
41 #include "LeafNode.h"
42 #include "Iterator.h"
43 #include "Util.h"
44 
45 
46 namespace openvdb {
48 namespace OPENVDB_VERSION_NAME {
49 namespace tree {
50 
53 template<Index Log2Dim>
54 class LeafNode<bool, Log2Dim>
55 {
56 public:
58  typedef boost::shared_ptr<LeafNodeType> Ptr;
59  typedef bool ValueType;
61 
62  // These static declarations must be on separate lines to avoid VC9 compiler errors.
63  static const Index LOG2DIM = Log2Dim; // needed by parent nodes
64  static const Index TOTAL = Log2Dim; // needed by parent nodes
65  static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
66  static const Index NUM_VALUES = 1 << 3 * Log2Dim;
67  static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
68  static const Index SIZE = NUM_VALUES;
69  static const Index LEVEL = 0; // level 0 = leaf
70 
73  template<typename ValueType>
74  struct ValueConverter { typedef LeafNode<ValueType, Log2Dim> Type; };
75 
78  template<typename OtherNodeType>
79  struct SameConfiguration {
81  };
82 
83 
84  class Buffer
85  {
86  public:
87  Buffer() {}
88  Buffer(bool on) : mData(on) {}
89  Buffer(const NodeMaskType& other): mData(other) {}
90  Buffer(const Buffer& other): mData(other.mData) {}
91  ~Buffer() {}
92  void fill(bool val) { mData.set(val); }
93  Buffer& operator=(const Buffer& b) { if (&b != this) { mData = b.mData; } return *this; }
94 
95  const bool& getValue(Index i) const
96  {
97  assert(i < SIZE);
98  return mData.isOn(i) ? LeafNode::sOn : LeafNode::sOff;
99  }
100  const bool& operator[](Index i) const { return this->getValue(i); }
101 
102  bool operator==(const Buffer& other) const { return mData == other.mData; }
103  bool operator!=(const Buffer& other) const { return mData != other.mData; }
104 
105  void setValue(Index i, bool val) { assert(i < SIZE); mData.set(i, val); }
106 
107  void swap(Buffer& other) { if (&other != this) std::swap(mData, other.mData); }
108 
109  Index memUsage() const { return mData.memUsage(); }
110  static Index size() { return SIZE; }
111 
112  private:
113  friend class ::TestLeaf;
114  // Allow the parent LeafNode to access this Buffer's bit mask.
115  friend class LeafNode;
116 
117  NodeMaskType mData;
118  }; // class Buffer
119 
120 
122  LeafNode();
123 
128  explicit LeafNode(const Coord& xyz, bool value = false, bool active = false);
129 
131  LeafNode(const LeafNode&);
132 
134  template<typename OtherValueType>
135  explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
136 
138  template<typename ValueType>
140 
142  template<typename ValueType>
145  LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool offValue, bool onValue, TopologyCopy);
146  template<typename ValueType>
147  LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool background, TopologyCopy);
149 
151  ~LeafNode();
152 
153  //
154  // Statistics
155  //
157  static Index log2dim() { return Log2Dim; }
159  static Index dim() { return DIM; }
160  static Index size() { return SIZE; }
161  static Index numValues() { return SIZE; }
162  static Index getLevel() { return LEVEL; }
163  static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
164  static Index getChildDim() { return 1; }
165 
166  static Index32 leafCount() { return 1; }
167  static Index32 nonLeafCount() { return 0; }
168 
170  Index64 onVoxelCount() const { return mValueMask.countOn(); }
172  Index64 offVoxelCount() const { return mValueMask.countOff(); }
173  Index64 onLeafVoxelCount() const { return onVoxelCount(); }
174  Index64 offLeafVoxelCount() const { return offVoxelCount(); }
175  static Index64 onTileCount() { return 0; }
176  static Index64 offTileCount() { return 0; }
177 
179  bool isEmpty() const { return mValueMask.isOff(); }
181  bool isDense() const { return mValueMask.isOn(); }
182 
184  Index64 memUsage() const;
185 
189  void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
190 
193  CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
194 
196  void setOrigin(const Coord& origin) { mOrigin = origin; }
198  const Coord& origin() const { return mOrigin; }
200  void getOrigin(Coord& origin) const { origin = mOrigin; }
201  void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
203 
205  static Index coordToOffset(const Coord& xyz);
208  static Coord offsetToLocalCoord(Index n);
210  Coord offsetToGlobalCoord(Index n) const;
211 
213  std::string str() const;
214 
217  template<typename OtherType, Index OtherLog2Dim>
218  bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
219 
221  bool operator==(const LeafNode&) const;
222  bool operator!=(const LeafNode&) const;
223 
224  //
225  // Buffer management
226  //
229  void swap(Buffer& other) { mBuffer.swap(other); }
230  const Buffer& buffer() const { return mBuffer; }
231  Buffer& buffer() { return mBuffer; }
232 
233  //
234  // I/O methods
235  //
237  void readTopology(std::istream&, bool fromHalf = false);
239  void writeTopology(std::ostream&, bool toHalf = false) const;
240 
242  void readBuffers(std::istream&, bool fromHalf = false);
244  void writeBuffers(std::ostream&, bool toHalf = false) const;
245 
246  //
247  // Accessor methods
248  //
250  const bool& getValue(const Coord& xyz) const;
252  const bool& getValue(Index offset) const;
253 
257  bool probeValue(const Coord& xyz, bool& val) const;
258 
260  static Index getValueLevel(const Coord&) { return LEVEL; }
261 
263  void setActiveState(const Coord& xyz, bool on);
265  void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
266 
268  void setValueOnly(const Coord& xyz, bool val);
270  void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
271 
273  void setValueOff(const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
275  void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
276 
278  void setValueOff(const Coord& xyz, bool val);
280  void setValueOff(Index offset, bool val);
281 
283  void setValueOn(const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
285  void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
286 
288  void setValueOn(const Coord& xyz, bool val);
290  void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); };
292  void setValueOn(Index offset, bool val);
293 
296  template<typename ModifyOp>
297  void modifyValue(Index offset, const ModifyOp& op);
300  template<typename ModifyOp>
301  void modifyValue(const Coord& xyz, const ModifyOp& op);
302 
304  template<typename ModifyOp>
305  void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
306 
308  void setValuesOn() { mValueMask.setOn(); }
310  void setValuesOff() { mValueMask.setOff(); }
311 
313  bool isValueOn(const Coord& xyz) const { return mValueMask.isOn(this->coordToOffset(xyz)); }
315  bool isValueOn(Index offset) const { assert(offset < SIZE); return mValueMask.isOn(offset); }
316 
318  static bool hasActiveTiles() { return false; }
319 
321  void fill(const CoordBBox& bbox, bool value, bool active = true);
322 
324  void fill(const bool& value);
326  void fill(const bool& value, bool active);
327 
339  template<typename DenseT>
340  void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
341 
358  template<typename DenseT>
359  void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
360 
363  template<typename AccessorT>
364  const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
365 
368  template<typename AccessorT>
369  bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
370 
373  template<typename AccessorT>
374  void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
375 
379  template<typename AccessorT>
380  void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
381 
384  template<typename AccessorT>
385  void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
386  {
387  this->setValueOff(xyz, value);
388  }
389 
393  template<typename ModifyOp, typename AccessorT>
394  void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
395  {
396  this->modifyValue(xyz, op);
397  }
398 
401  template<typename ModifyOp, typename AccessorT>
402  void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
403  {
404  this->modifyValueAndActiveState(xyz, op);
405  }
406 
410  template<typename AccessorT>
411  void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
412  {
413  this->setActiveState(xyz, on);
414  }
415 
419  template<typename AccessorT>
420  bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
421  {
422  return this->probeValue(xyz, val);
423  }
424 
427  template<typename AccessorT>
428  static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
429 
433  const bool& getFirstValue() const { if (mValueMask.isOn(0)) return sOn; else return sOff; }
437  const bool& getLastValue() const { if (mValueMask.isOn(SIZE-1)) return sOn; else return sOff; }
438 
442  bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
444  bool isInactive() const { return mValueMask.isOff(); }
445 
446  void resetBackground(bool oldBackground, bool newBackground);
447 
448  void negate() { mBuffer.mData.toggle(); }
449 
450  template<MergePolicy Policy>
451  void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
452  template<MergePolicy Policy> void merge(bool tileValue, bool tileActive);
453 
455 
462  template<typename OtherType>
463  void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
464 
476  template<typename OtherType>
477  void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
478 
490  template<typename OtherType>
491  void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
492 
493  template<typename CombineOp>
494  void combine(const LeafNode& other, CombineOp& op);
495  template<typename CombineOp>
496  void combine(bool, bool valueIsActive, CombineOp& op);
497 
498  template<typename CombineOp, typename OtherType /*= bool*/>
499  void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
500  template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
501  void combine2(bool, const OtherNodeT& other, bool valueIsActive, CombineOp&);
502  template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
503  void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
504 
509  template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
510 
511  template<typename VisitorOp> void visit(VisitorOp&);
512  template<typename VisitorOp> void visit(VisitorOp&) const;
513 
514  template<typename OtherLeafNodeType, typename VisitorOp>
515  void visit2Node(OtherLeafNodeType& other, VisitorOp&);
516  template<typename OtherLeafNodeType, typename VisitorOp>
517  void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
518  template<typename IterT, typename VisitorOp>
519  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
520  template<typename IterT, typename VisitorOp>
521  void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
522 
524  void signedFloodFill(bool) {}
527  void signedFloodFill(bool, bool) {}
528  template<typename PruneOp> void pruneOp(PruneOp&) {}
529  void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
530  void pruneInactive(const ValueType&) {}
531  void addLeaf(LeafNode*) {}
532  template<typename AccessorT>
533  void addLeafAndCache(LeafNode*, AccessorT&) {}
534  template<typename NodeT>
535  NodeT* stealNode(const Coord&, const ValueType&, bool) { return NULL; }
536  template<typename NodeT>
537  NodeT* probeNode(const Coord&) { return NULL; }
538  template<typename NodeT>
539  const NodeT* probeConstNode(const Coord&) const { return NULL; }
541 
542  void addTile(Index level, const Coord&, bool val, bool active);
543  void addTile(Index offset, bool val, bool active);
544  template<typename AccessorT>
545  void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
546 
548  LeafNode* touchLeaf(const Coord&) { return this; }
550  template<typename AccessorT>
551  LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
552  LeafNode* probeLeaf(const Coord&) { return this; }
553  template<typename AccessorT>
554  LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
555  template<typename NodeT, typename AccessorT>
556  NodeT* probeNodeAndCache(const Coord&, AccessorT&)
557  {
559  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
560  return reinterpret_cast<NodeT*>(this);
562  }
564 
565  const LeafNode* probeLeaf(const Coord&) const { return this; }
567  template<typename AccessorT>
568  const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
569  const LeafNode* probeConstLeaf(const Coord&) const { return this; }
570  template<typename AccessorT>
571  const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
572  template<typename NodeT, typename AccessorT>
573  const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
574  {
576  if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
577  return reinterpret_cast<const NodeT*>(this);
579  }
581 
582  //
583  // Iterators
584  //
585 protected:
589 
590  template<typename MaskIterT, typename NodeT, typename ValueT>
591  struct ValueIter:
592  // Derives from SparseIteratorBase, but can also be used as a dense iterator,
593  // if MaskIterT is a dense mask iterator type.
594  public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
595  {
597 
599  ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
600 
601  const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
602  const bool& getValue() const { return this->getItem(this->pos()); }
603 
604  // Note: setItem() can't be called on const iterators.
605  void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
606  // Note: setValue() can't be called on const iterators.
607  void setValue(bool value) const { this->setItem(this->pos(), value); }
608 
609  // Note: modifyItem() can't be called on const iterators.
610  template<typename ModifyOp>
611  void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
612  // Note: modifyValue() can't be called on const iterators.
613  template<typename ModifyOp>
614  void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
615  };
616 
618  template<typename MaskIterT, typename NodeT>
619  struct ChildIter:
620  public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
621  {
623  ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
624  MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
625  };
626 
627  template<typename NodeT, typename ValueT>
628  struct DenseIter: public DenseIteratorBase<
629  MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
630  {
633 
635  DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
636 
637  bool getItem(Index pos, void*& child, NonConstValueT& value) const
638  {
639  value = this->parent().getValue(pos);
640  child = NULL;
641  return false; // no child
642  }
643 
644  // Note: setItem() can't be called on const iterators.
645  //void setItem(Index pos, void* child) const {}
646 
647  // Note: unsetItem() can't be called on const iterators.
648  void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
649  };
650 
651 public:
652  typedef ValueIter<MaskOnIter, LeafNode, const bool> ValueOnIter;
653  typedef ValueIter<MaskOnIter, const LeafNode, const bool> ValueOnCIter;
654  typedef ValueIter<MaskOffIter, LeafNode, const bool> ValueOffIter;
655  typedef ValueIter<MaskOffIter, const LeafNode, const bool> ValueOffCIter;
656  typedef ValueIter<MaskDenseIter, LeafNode, const bool> ValueAllIter;
657  typedef ValueIter<MaskDenseIter, const LeafNode, const bool> ValueAllCIter;
658  typedef ChildIter<MaskOnIter, LeafNode> ChildOnIter;
659  typedef ChildIter<MaskOnIter, const LeafNode> ChildOnCIter;
660  typedef ChildIter<MaskOffIter, LeafNode> ChildOffIter;
661  typedef ChildIter<MaskOffIter, const LeafNode> ChildOffCIter;
662  typedef DenseIter<LeafNode, bool> ChildAllIter;
663  typedef DenseIter<const LeafNode, const bool> ChildAllCIter;
664 
665  ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
666  ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
667  ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
668  ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
669  ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
670  ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
671  ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
672  ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
673  ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
674 
675  ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
676  ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
677  ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
678  ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
679  ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
680  ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
681  ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
682  ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
683  ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
684 
685  // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
686  // because leaf nodes have no children.
687  ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
688  ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
689  ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
690  ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
691  ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
692  ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
693  ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
694  ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
695  ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
696 
697  ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
698  ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
699  ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
700  ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
701  ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
702  ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
703  ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
704  ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
705  ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
706 
707  //
708  // Mask accessors
709  //
710  bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
711  bool isValueMaskOn() const { return mValueMask.isOn(); }
712  bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
713  bool isValueMaskOff() const { return mValueMask.isOff(); }
714  const NodeMaskType& getValueMask() const { return mValueMask; }
715  NodeMaskType& getValueMask() { return mValueMask; }
716  void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
717  bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
718  bool isChildMaskOff(Index) const { return true; }
719  bool isChildMaskOff() const { return true; }
720 protected:
721  void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
722  void setValueMaskOn(Index n) { mValueMask.setOn(n); }
723  void setValueMaskOff(Index n) { mValueMask.setOff(n); }
724 
726  static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
727 
728  template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
729  static inline void doVisit(NodeT&, VisitorOp&);
730 
731  template<typename NodeT, typename OtherNodeT, typename VisitorOp,
732  typename ChildAllIterT, typename OtherChildAllIterT>
733  static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
734 
735  template<typename NodeT, typename VisitorOp,
736  typename ChildAllIterT, typename OtherChildAllIterT>
737  static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
738 
739 
743  Buffer mBuffer;
745  Coord mOrigin;
746 
747  // These static declarations must be on separate lines to avoid VC9 compiler errors.
748  static const bool sOn;
749  static const bool sOff;
750 
751 private:
754  template<typename, Index> friend class LeafNode;
755 
756  friend struct ValueIter<MaskOnIter, LeafNode, bool>;
757  friend struct ValueIter<MaskOffIter, LeafNode, bool>;
758  friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
759  friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
760  friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
761  friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
762 
764  friend class IteratorBase<MaskOnIter, LeafNode>;
770 
771 }; // class LeafNode<bool>
772 
773 
778 template<Index Log2Dim> const bool LeafNode<bool, Log2Dim>::sOn = true;
779 template<Index Log2Dim> const bool LeafNode<bool, Log2Dim>::sOff = false;
780 
781 
783 
784 
785 template<Index Log2Dim>
786 inline
788 {
789 }
790 
791 
792 template<Index Log2Dim>
793 inline
794 LeafNode<bool, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool active):
795  mValueMask(active),
796  mBuffer(value),
797  mOrigin(xyz & (~(DIM - 1)))
798 {
799 }
800 
801 
802 template<Index Log2Dim>
803 inline
805  mValueMask(other.mValueMask),
806  mBuffer(other.mBuffer),
807  mOrigin(other.mOrigin)
808 {
809 }
810 
811 
812 // Copy-construct from a leaf node with the same configuration but a different ValueType.
813 template<Index Log2Dim>
814 template<typename ValueT>
815 inline
817  mValueMask(other.getValueMask()),
818  mOrigin(other.origin())
819 {
820  struct Local {
822  static inline bool convertValue(const ValueT& val) { return bool(val); }
823  };
824 
825  for (Index i = 0; i < SIZE; ++i) {
826  mBuffer.setValue(i, Local::convertValue(other.mBuffer[i]));
827  }
828 }
829 
830 
831 template<Index Log2Dim>
832 template<typename ValueT>
833 inline
835  bool background, TopologyCopy):
836  mValueMask(other.getValueMask()),
837  mBuffer(background),
838  mOrigin(other.origin())
839 {
840 }
841 
842 
843 template<Index Log2Dim>
844 template<typename ValueT>
845 inline
847  mValueMask(other.getValueMask()),
848  mBuffer(other.getValueMask()), // value = active state
849  mOrigin(other.origin())
850 {
851 }
852 
853 
854 template<Index Log2Dim>
855 template<typename ValueT>
856 inline
858  bool offValue, bool onValue, TopologyCopy):
859  mValueMask(other.getValueMask()),
860  mBuffer(other.getValueMask()),
861  mOrigin(other.origin())
862 {
863  if (offValue) { if (!onValue) mBuffer.mData.toggle(); else mBuffer.mData.setOn(); }
864 }
865 
866 
867 template<Index Log2Dim>
868 inline
870 {
871 }
872 
873 
875 
876 
877 template<Index Log2Dim>
878 inline Index64
880 {
881  return sizeof(mOrigin) + mValueMask.memUsage() + mBuffer.memUsage();
882 }
883 
884 
885 template<Index Log2Dim>
886 inline void
887 LeafNode<bool, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
888 {
889  CoordBBox this_bbox = this->getNodeBoundingBox();
890  if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
891  if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
892  if (visitVoxels) {//use voxel granularity?
893  this_bbox.reset();
894  for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
895  this_bbox.translate(this->origin());
896  }
897  bbox.expand(this_bbox);
898  }
899 }
900 
901 
902 template<Index Log2Dim>
903 template<typename OtherType, Index OtherLog2Dim>
904 inline bool
906 {
907  assert(other);
908  return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
909 }
910 
911 
912 template<Index Log2Dim>
913 inline std::string
915 {
916  std::ostringstream ostr;
917  ostr << "LeafNode @" << mOrigin << ": ";
918  for (Index32 n = 0; n < SIZE; ++n) ostr << (mValueMask.isOn(n) ? '#' : '.');
919  return ostr.str();
920 }
921 
922 
924 
925 
926 template<Index Log2Dim>
927 inline Index
929 {
930  assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
931  return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
932  + ((xyz[1] & (DIM-1u)) << Log2Dim)
933  + (xyz[2] & (DIM-1u));
934 }
935 
936 
937 template<Index Log2Dim>
938 inline Coord
940 {
941  assert(n < (1 << 3*Log2Dim));
942  Coord xyz;
943  xyz.setX(n >> 2*Log2Dim);
944  n &= ((1 << 2*Log2Dim) - 1);
945  xyz.setY(n >> Log2Dim);
946  xyz.setZ(n & ((1 << Log2Dim) - 1));
947  return xyz;
948 }
949 
950 
951 template<Index Log2Dim>
952 inline Coord
954 {
955  return (this->offsetToLocalCoord(n) + this->origin());
956 }
957 
958 
960 
961 
962 template<Index Log2Dim>
963 inline void
964 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
965 {
966  mValueMask.load(is);
967 }
968 
969 
970 template<Index Log2Dim>
971 inline void
972 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
973 {
974  mValueMask.save(os);
975 }
976 
977 
978 template<Index Log2Dim>
979 inline void
980 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
981 {
982  // Read in the value mask.
983  mValueMask.load(is);
984  // Read in the origin.
985  is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
986 
988  // Read in the mask for the voxel values.
989  mBuffer.mData.load(is);
990  } else {
991  // Older files stored one or more bool arrays.
992 
993  // Read in the number of buffers, which should now always be one.
994  int8_t numBuffers = 0;
995  is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
996 
997  // Read in the buffer.
998  // (Note: prior to the bool leaf optimization, buffers were always compressed.)
999  boost::shared_array<bool> buf(new bool[SIZE]);
1000  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1001 
1002  // Transfer values to mBuffer.
1003  mBuffer.mData.setOff();
1004  for (Index i = 0; i < SIZE; ++i) {
1005  if (buf[i]) mBuffer.mData.setOn(i);
1006  }
1007 
1008  if (numBuffers > 1) {
1009  // Read in and discard auxiliary buffers that were created with
1010  // earlier versions of the library.
1011  for (int i = 1; i < numBuffers; ++i) {
1012  io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1013  }
1014  }
1015  }
1016 }
1017 
1018 
1019 template<Index Log2Dim>
1020 inline void
1021 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1022 {
1023  // Write out the value mask.
1024  mValueMask.save(os);
1025  // Write out the origin.
1026  os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1027  // Write out the voxel values.
1028  mBuffer.mData.save(os);
1029 }
1030 
1031 
1033 
1034 
1035 template<Index Log2Dim>
1036 inline bool
1038 {
1039  return (mValueMask == other.mValueMask && mBuffer.mData == other.mBuffer.mData);
1040 }
1041 
1042 
1043 template<Index Log2Dim>
1044 inline bool
1046 {
1047  return !(this->operator==(other));
1048 }
1049 
1050 
1052 
1053 
1054 template<Index Log2Dim>
1055 inline bool
1056 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1057 {
1058  state = mValueMask.isOn();
1059 
1060  if (!(state || mValueMask.isOff())) return false;
1061 
1062  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1063  if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1064 
1065  state = mValueMask.isOn();
1066  constValue = mBuffer.mData.isOn();
1067  return true;
1068 }
1069 
1070 
1072 
1073 
1074 template<Index Log2Dim>
1075 inline void
1076 LeafNode<bool, Log2Dim>::addTile(Index level, const Coord& xyz, bool val, bool active)
1077 {
1078  assert(level == 0);
1079  this->addTile(this->coordToOffset(xyz), val, active);
1080 }
1081 
1082 template<Index Log2Dim>
1083 inline void
1084 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1085 {
1086  assert(offset < SIZE);
1087  setValueOnly(offset, val);
1088  setActiveState(offset, active);
1089 }
1090 
1091 template<Index Log2Dim>
1092 template<typename AccessorT>
1093 inline void
1095  bool val, bool active, AccessorT&)
1096 {
1097  this->addTile(level, xyz, val, active);
1098 }
1099 
1100 
1102 
1103 
1104 template<Index Log2Dim>
1105 inline const bool&
1106 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1107 {
1108  // This *CANNOT* use operator ? because Visual C++
1109  if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return sOn; else return sOff;
1110 }
1111 
1112 
1113 template<Index Log2Dim>
1114 inline const bool&
1116 {
1117  assert(offset < SIZE);
1118  // This *CANNOT* use operator ? for Windows
1119  if (mBuffer.mData.isOn(offset)) return sOn; else return sOff;
1120 }
1121 
1122 
1123 template<Index Log2Dim>
1124 inline bool
1125 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1126 {
1127  const Index offset = this->coordToOffset(xyz);
1128  val = mBuffer.mData.isOn(offset);
1129  return mValueMask.isOn(offset);
1130 }
1131 
1132 
1133 template<Index Log2Dim>
1134 inline void
1135 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1136 {
1137  this->setValueOn(this->coordToOffset(xyz), val);
1138 }
1139 
1140 
1141 template<Index Log2Dim>
1142 inline void
1144 {
1145  assert(offset < SIZE);
1146  mValueMask.setOn(offset);
1147  mBuffer.mData.set(offset, val);
1148 }
1149 
1150 
1151 template<Index Log2Dim>
1152 inline void
1153 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1154 {
1155  this->setValueOnly(this->coordToOffset(xyz), val);
1156 }
1157 
1158 
1159 template<Index Log2Dim>
1160 inline void
1162 {
1163  mValueMask.set(this->coordToOffset(xyz), on);
1164 }
1165 
1166 
1167 template<Index Log2Dim>
1168 inline void
1169 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1170 {
1171  this->setValueOff(this->coordToOffset(xyz), val);
1172 }
1173 
1174 
1175 template<Index Log2Dim>
1176 inline void
1178 {
1179  assert(offset < SIZE);
1180  mValueMask.setOff(offset);
1181  mBuffer.mData.set(offset, val);
1182 }
1183 
1184 
1185 template<Index Log2Dim>
1186 template<typename ModifyOp>
1187 inline void
1188 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1189 {
1190  bool val = mBuffer.mData.isOn(offset);
1191  op(val);
1192  mBuffer.mData.set(offset, val);
1193  mValueMask.setOn(offset);
1194 }
1195 
1196 
1197 template<Index Log2Dim>
1198 template<typename ModifyOp>
1199 inline void
1200 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1201 {
1202  this->modifyValue(this->coordToOffset(xyz), op);
1203 }
1204 
1205 
1206 template<Index Log2Dim>
1207 template<typename ModifyOp>
1208 inline void
1209 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1210 {
1211  const Index offset = this->coordToOffset(xyz);
1212  bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1213  op(val, state);
1214  mBuffer.mData.set(offset, val);
1215  mValueMask.set(offset, state);
1216 }
1217 
1218 
1220 
1221 
1222 template<Index Log2Dim>
1223 inline void
1224 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1225 {
1226  if (newBackground != oldBackground) {
1227  // Flip mBuffer's background bits and zero its foreground bits.
1228  NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1229  // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1230  mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1231  }
1232 }
1233 
1234 
1236 
1237 
1238 template<Index Log2Dim>
1239 template<MergePolicy Policy>
1240 inline void
1241 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1242 {
1244  if (Policy == MERGE_NODES) return;
1245  for (typename NodeMaskType::OnIterator iter = other.mValueMask.beginOn(); iter; ++iter) {
1246  const Index n = iter.pos();
1247  if (mValueMask.isOff(n)) {
1248  mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1249  mValueMask.setOn(n);
1250  }
1251  }
1253 }
1254 
1255 template<Index Log2Dim>
1256 template<MergePolicy Policy>
1257 inline void
1258 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1259 {
1261  if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1262  if (!tileActive) return;
1263  // Replace all inactive values with the active tile value.
1264  if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1265  else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1266  mValueMask.setOn();
1268 }
1269 
1270 
1272 
1273 
1274 template<Index Log2Dim>
1275 template<typename OtherType>
1276 inline void
1278 {
1279  mValueMask |= other.getValueMask();
1280 }
1281 
1282 
1283 template<Index Log2Dim>
1284 template<typename OtherType>
1285 inline void
1287  const bool&)
1288 {
1289  mValueMask &= other.getValueMask();
1290 }
1291 
1292 
1293 template<Index Log2Dim>
1294 template<typename OtherType>
1295 inline void
1297  const bool&)
1298 {
1299  mValueMask &= !other.getValueMask();
1300 }
1301 
1302 
1304 
1305 
1306 template<Index Log2Dim>
1307 inline void
1308 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1309 {
1310  for (Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1311  const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1312  for (Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1313  const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1314  for (Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1315  const Index offset = offsetXY + (z & (DIM-1u));
1316  mValueMask.set(offset, active);
1317  mBuffer.mData.set(offset, value);
1318  }
1319  }
1320  }
1321 }
1322 
1323 template<Index Log2Dim>
1324 inline void
1326 {
1327  mBuffer.fill(value);
1328 }
1329 
1330 template<Index Log2Dim>
1331 inline void
1332 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1333 {
1334  mBuffer.fill(value);
1335  mValueMask.set(active);
1336 }
1337 
1338 
1340 
1341 
1342 template<Index Log2Dim>
1343 template<typename DenseT>
1344 inline void
1345 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1346 {
1347  typedef typename DenseT::ValueType DenseValueType;
1348 
1349  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1350  const Coord& min = dense.bbox().min();
1351  DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1352  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1353  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1354  DenseValueType* t1 = t0 + xStride * (x - min[0]);
1355  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1356  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1357  DenseValueType* t2 = t1 + yStride * (y - min[1]);
1358  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1359  for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1360  *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1361  }
1362  }
1363  }
1364 }
1365 
1366 
1367 template<Index Log2Dim>
1368 template<typename DenseT>
1369 inline void
1370 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1371  bool background, bool tolerance)
1372 {
1373  typedef typename DenseT::ValueType DenseValueType;
1374 
1375  const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1376  const Coord& min = dense.bbox().min();
1377  const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1378  const Int32 n0 = bbox.min()[2] & (DIM-1u);
1379  for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1380  const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1381  const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1382  for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1383  const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1384  Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1385  for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1386  // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1387  if (tolerance || background == bool(*s2)) {
1388  mValueMask.setOff(n2);
1389  mBuffer.mData.set(n2, background);
1390  } else {
1391  mValueMask.setOn(n2);
1392  mBuffer.mData.set(n2, bool(*s2));
1393  }
1394  }
1395  }
1396  }
1397 }
1398 
1399 
1401 
1402 
1403 template<Index Log2Dim>
1404 template<typename CombineOp>
1405 inline void
1406 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1407 {
1408  CombineArgs<bool> args;
1409  for (Index i = 0; i < SIZE; ++i) {
1410  bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1411  op(args.setARef(aVal)
1412  .setAIsActive(mValueMask.isOn(i))
1413  .setBRef(bVal)
1414  .setBIsActive(other.mValueMask.isOn(i))
1415  .setResultRef(result));
1416  mValueMask.set(i, args.resultIsActive());
1417  mBuffer.mData.set(i, result);
1418  }
1419 }
1420 
1421 
1422 template<Index Log2Dim>
1423 template<typename CombineOp>
1424 inline void
1425 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1426 {
1427  CombineArgs<bool> args;
1428  args.setBRef(value).setBIsActive(valueIsActive);
1429  for (Index i = 0; i < SIZE; ++i) {
1430  bool result = false, aVal = mBuffer.mData.isOn(i);
1431  op(args.setARef(aVal)
1432  .setAIsActive(mValueMask.isOn(i))
1433  .setResultRef(result));
1434  mValueMask.set(i, args.resultIsActive());
1435  mBuffer.mData.set(i, result);
1436  }
1437 }
1438 
1439 
1441 
1442 
1443 template<Index Log2Dim>
1444 template<typename CombineOp, typename OtherType>
1445 inline void
1446 LeafNode<bool, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1447  bool valueIsActive, CombineOp& op)
1448 {
1450  args.setBRef(value).setBIsActive(valueIsActive);
1451  for (Index i = 0; i < SIZE; ++i) {
1452  bool result = false, aVal = other.mBuffer.mData.isOn(i);
1453  op(args.setARef(aVal)
1454  .setAIsActive(other.mValueMask.isOn(i))
1455  .setResultRef(result));
1456  mValueMask.set(i, args.resultIsActive());
1457  mBuffer.mData.set(i, result);
1458  }
1459 }
1460 
1461 
1462 template<Index Log2Dim>
1463 template<typename CombineOp, typename OtherNodeT>
1464 inline void
1465 LeafNode<bool, Log2Dim>::combine2(bool value, const OtherNodeT& other,
1466  bool valueIsActive, CombineOp& op)
1467 {
1469  args.setARef(value).setAIsActive(valueIsActive);
1470  for (Index i = 0; i < SIZE; ++i) {
1471  bool result = false, bVal = other.mBuffer.mData.isOn(i);
1472  op(args.setBRef(bVal)
1473  .setBIsActive(other.mValueMask.isOn(i))
1474  .setResultRef(result));
1475  mValueMask.set(i, args.resultIsActive());
1476  mBuffer.mData.set(i, result);
1477  }
1478 }
1479 
1480 
1481 template<Index Log2Dim>
1482 template<typename CombineOp, typename OtherNodeT>
1483 inline void
1484 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1485 {
1487  for (Index i = 0; i < SIZE; ++i) {
1488  // Default behavior: output voxel is active if either input voxel is active.
1489  mValueMask.set(i, b0.mValueMask.isOn(i) || b1.mValueMask.isOn(i));
1490 
1491  bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1492  op(args.setARef(b0Val)
1493  .setAIsActive(b0.mValueMask.isOn(i))
1494  .setBRef(b1Val)
1495  .setBIsActive(b1.mValueMask.isOn(i))
1496  .setResultRef(result));
1497  mValueMask.set(i, args.resultIsActive());
1498  mBuffer.mData.set(i, result);
1499  }
1500 }
1501 
1502 
1504 
1505 template<Index Log2Dim>
1506 template<typename BBoxOp>
1507 inline void
1509 {
1510  if (op.template descent<LEVEL>()) {
1511  for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1512 #ifdef _MSC_VER
1513  op.operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1514 #else
1515  op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1516 #endif
1517  }
1518  } else {
1519 #ifdef _MSC_VER
1520  op.operator()<LEVEL>(this->getNodeBoundingBox());
1521 #else
1522  op.template operator()<LEVEL>(this->getNodeBoundingBox());
1523 #endif
1524  }
1525 }
1526 
1527 
1528 template<Index Log2Dim>
1529 template<typename VisitorOp>
1530 inline void
1532 {
1533  doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1534 }
1535 
1536 
1537 template<Index Log2Dim>
1538 template<typename VisitorOp>
1539 inline void
1541 {
1542  doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1543 }
1544 
1545 
1546 template<Index Log2Dim>
1547 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1548 inline void
1549 LeafNode<bool, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1550 {
1551  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1552  op(iter);
1553  }
1554 }
1555 
1556 
1558 
1559 
1560 template<Index Log2Dim>
1561 template<typename OtherLeafNodeType, typename VisitorOp>
1562 inline void
1563 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1564 {
1565  doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1566  typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1567 }
1568 
1569 
1570 template<Index Log2Dim>
1571 template<typename OtherLeafNodeType, typename VisitorOp>
1572 inline void
1573 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1574 {
1575  doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1576  typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1577 }
1578 
1579 
1580 template<Index Log2Dim>
1581 template<
1582  typename NodeT,
1583  typename OtherNodeT,
1584  typename VisitorOp,
1585  typename ChildAllIterT,
1586  typename OtherChildAllIterT>
1587 inline void
1588 LeafNode<bool, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1589 {
1590  // Allow the two nodes to have different ValueTypes, but not different dimensions.
1591  BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
1592  BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
1593 
1594  ChildAllIterT iter = self.beginChildAll();
1595  OtherChildAllIterT otherIter = other.beginChildAll();
1596 
1597  for ( ; iter && otherIter; ++iter, ++otherIter) {
1598  op(iter, otherIter);
1599  }
1600 }
1601 
1602 
1604 
1605 
1606 template<Index Log2Dim>
1607 template<typename IterT, typename VisitorOp>
1608 inline void
1609 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1610 {
1611  doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1612 }
1613 
1614 
1615 template<Index Log2Dim>
1616 template<typename IterT, typename VisitorOp>
1617 inline void
1618 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1619 {
1620  doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1621 }
1622 
1623 
1624 template<Index Log2Dim>
1625 template<
1626  typename NodeT,
1627  typename VisitorOp,
1628  typename ChildAllIterT,
1629  typename OtherChildAllIterT>
1630 inline void
1631 LeafNode<bool, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1632  VisitorOp& op, bool otherIsLHS)
1633 {
1634  if (!otherIter) return;
1635 
1636  if (otherIsLHS) {
1637  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1638  op(otherIter, iter);
1639  }
1640  } else {
1641  for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1642  op(iter, otherIter);
1643  }
1644  }
1645 }
1646 
1647 } // namespace tree
1648 } // namespace OPENVDB_VERSION_NAME
1649 } // namespace openvdb
1650 
1651 #endif // OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
1652 
1653 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1654 // All rights reserved. This software is distributed under the
1655 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
bool resultIsActive() const
Definition: Types.h:314
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:745
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:691
static const Index LOG2DIM
Definition: LeafNode.h:74
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeBool.h:652
void pruneOp(PruneOp &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:528
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:554
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:531
BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:632
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:678
static Index32 leafCount()
Definition: LeafNodeBool.h:166
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNodeBool.h:380
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1533
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:658
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1569
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeBool.h:193
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:476
void combine(FloatTreeT &lhsDist, IntTreeT &lhsIndex, FloatTreeT &rhsDist, IntTreeT &rhsIndex)
Definition: MeshToVolume.h:396
void swap(Buffer &other)
Definition: LeafNodeBool.h:107
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:662
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:393
static const bool sOn
Definition: LeafNodeBool.h:748
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:172
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:694
void setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:721
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:437
bool operator!=(const Buffer &other) const
Definition: LeafNodeBool.h:103
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:655
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:675
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeBool.h:229
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: LeafNodeBool.h:420
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:601
static Index getLevel()
Definition: LeafNodeBool.h:162
Buffer(const Buffer &other)
Definition: LeafNodeBool.h:90
void pruneInactive(const ValueType &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:530
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:712
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:515
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1037
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:201
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node'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:1502
const bool & getValue() const
Definition: LeafNodeBool.h:602
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1679
OnIterator beginOn() const
Definition: NodeMasks.h:332
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1494
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:714
static Index getChildDim()
Definition: LeafNodeBool.h:164
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:303
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNodeBool.h:273
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value. ...
Definition: LeafNodeBool.h:265
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:54
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:1325
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:1161
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:167
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:568
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:683
Index32 Index
Definition: Types.h:57
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:679
void fill(const ValueType &val)
Populates the buffer with a constant value.
Definition: LeafNode.h:111
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:677
void negate()
Definition: LeafNodeBool.h:448
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:693
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1289
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:371
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:688
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:689
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:159
static const Index SIZE
Definition: LeafNode.h:79
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:252
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1704
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:433
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:446
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:196
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:653
void load(std::istream &is)
Definition: NodeMasks.h:494
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1023
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:571
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:670
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:692
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:428
Definition: NodeMasks.h:188
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1048
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeBool.h:654
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:715
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:181
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1013
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeBool.h:285
static Index size()
Definition: LeafNodeBool.h:160
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:703
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:504
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1240
void setValue(Index i, const ValueType &val)
Set the i'th value of the Buffer to the specified value.
Definition: LeafNode.h:122
void setValue(bool value) const
Definition: LeafNodeBool.h:607
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:174
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:318
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:402
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:157
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeBool.h:656
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:486
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:667
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:659
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:702
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:275
static const Index DIM
Definition: LeafNode.h:76
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:637
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:671
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:533
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:287
LeafNode< ValueType, Log2Dim > Type
Definition: LeafNodeBool.h:74
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNodeBool.h:411
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNodeBool.h:290
Definition: NodeMasks.h:219
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:265
Index memUsage() const
Definition: LeafNodeBool.h:109
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNodeBool.h:444
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:364
static const bool sOff
Definition: LeafNodeBool.h:749
Buffer(bool on)
Definition: LeafNodeBool.h:88
NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:586
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:717
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNodeBool.h:310
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:705
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:444
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:313
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:368
uint64_t Index64
Definition: Types.h:56
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:695
#define OPENVDB_VERSION_NAME
Definition: version.h:45
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: LeafNodeBool.h:394
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:718
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:179
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:701
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:690
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1624
void visit(VisitorOp &)
Definition: LeafNode.h:1647
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:635
static Index memUsage()
Return the memory-footprint of this Buffer in units of bytes.
Definition: LeafNode.h:153
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1665
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:704
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:1124
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:687
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state. ...
Definition: LeafNodeBool.h:270
const bool & getValue(Index i) const
Definition: LeafNodeBool.h:95
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1299
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: LeafNode.h:1098
Definition: Types.h:223
void voxelizeActiveTiles()
Definition: LeafNodeBool.h:454
bool ValueType
Definition: LeafNodeBool.h:59
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:170
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeBool.h:275
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:660
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1375
void fill(bool val)
Definition: LeafNodeBool.h:92
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:681
static Index64 offTileCount()
Definition: LeafNodeBool.h:176
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:665
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:377
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNodeBool.h:283
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:438
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:723
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:573
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:400
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:121
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:697
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:741
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1334
bool isValueMaskOff() const
Definition: LeafNodeBool.h:713
void setValue(Index i, bool val)
Definition: LeafNodeBool.h:105
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNodeBool.h:308
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:722
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:388
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1357
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:305
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:648
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:260
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:673
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:599
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1221
bool isValueMaskOn() const
Definition: LeafNodeBool.h:711
static const Index LEVEL
Definition: LeafNode.h:80
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1749
const Buffer & buffer() const
Definition: LeafNodeBool.h:230
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeBool.h:552
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:666
uint32_t Index32
Definition: Types.h:55
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:872
NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:587
int32_t Int32
Definition: Types.h:59
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:668
LeafNode< bool, Log2Dim > LeafNodeType
Definition: LeafNodeBool.h:57
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:369
OPENVDB_IMPORT uint32_t getFormatVersion(std::istream &)
Return the file format version number associated with the given input stream.
const bool & operator[](Index i) const
Definition: LeafNodeBool.h:100
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:611
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:614
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1064
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:556
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:1186
Buffer(const NodeMaskType &other)
Definition: LeafNodeBool.h:89
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:539
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNodeBool.h:596
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNodeBool.h:631
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1274
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:369
Definition: LeafNode.h:57
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNodeBool.h:374
NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:588
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:122
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:173
boost::shared_ptr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:58
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:163
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1725
static Index64 onTileCount()
Definition: LeafNodeBool.h:175
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1000
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:716
void signedFloodFill(bool, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:527
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:698
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:315
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node'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:1511
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1430
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:519
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNodeBool.h:385
static Index size()
Definition: LeafNodeBool.h:110
LeafNode()
Default constructor.
Definition: LeafNode.h:919
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:454
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:661
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:537
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:605
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNode.h:864
Buffer & operator=(const Buffer &b)
Definition: LeafNodeBool.h:93
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1307
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:710
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:398
Definition: NodeMasks.h:250
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:623
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNode.h:862
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1229
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:663
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: LeafNode.h:1106
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:200
Definition: Types.h:380
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:699
void merge(const LeafNode &)
Definition: LeafNode.h:1449
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNodeBool.h:60
~LeafNode()
Destructor.
Definition: LeafNode.h:993
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:669
ValueOnCIter endValueOn() const
Definition: LeafNodeBool.h:676
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:680
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:682
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:535
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
static Index numValues()
Definition: LeafNodeBool.h:161
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:657
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeBool.h:726
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:246
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:569
void save(std::ostream &os) const
Definition: NodeMasks.h:490
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:743
void prune(const ValueType &=zeroVal< ValueType >())
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:529
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:700
Buffer & buffer()
Definition: LeafNodeBool.h:231
bool operator==(const Buffer &other) const
Definition: LeafNodeBool.h:102
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:368
bool isChildMaskOff() const
Definition: LeafNodeBool.h:719
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
Buffer mBuffer
Buffer containing the actual data values.
Definition: LeafNode.h:860
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:551
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:672