OpenVDB: LeafNodeBool.h Source File

OpenVDB 4.0.2

LeafNodeBool.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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_BOOL_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
33
34 #include <openvdb/Types.h>
35 #include <openvdb/io/Compression.h> // for io::readData(), etc.
36 #include <openvdb/math/Math.h> // for math::isZero()
37 #include <openvdb/util/NodeMasks.h>
38 #include "LeafNode.h"
39 #include "Iterator.h"
40 #include <boost/shared_array.hpp>
41 #include <iostream>
42 #include <type_traits>
43
44
45 namespace openvdb {
46 OPENVDB_USE_VERSION_NAMESPACE
47 namespace OPENVDB_VERSION_NAME {
48 namespace tree {
49
52 template<Index Log2Dim>
53 class LeafNode<bool, Log2Dim>
54 {
55 public:
56 using LeafNodeType = LeafNode<bool, Log2Dim>;
57 using BuildType = bool;
58 using ValueType = bool;
59 using Buffer = LeafBuffer<ValueType, Log2Dim>;
60 using NodeMaskType = util::NodeMask<Log2Dim>;
61 using Ptr = SharedPtr<LeafNodeType>;
62
63 // These static declarations must be on separate lines to avoid VC9 compiler errors.
64 static const Index LOG2DIM = Log2Dim; // needed by parent nodes
65 static const Index TOTAL = Log2Dim; // needed by parent nodes
66 static const Index DIM = 1 << TOTAL; // dimension along one coordinate direction
67 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
68 static const Index NUM_VOXELS = NUM_VALUES; // total number of voxels represented by this node
69 static const Index SIZE = NUM_VALUES;
70 static const Index LEVEL = 0; // level 0 = leaf
71
74 template<typename ValueType>
75 struct ValueConverter { using Type = LeafNode<ValueType, Log2Dim>; };
76
79 template<typename OtherNodeType>
80 struct SameConfiguration {
81 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
82 };
83
84
86 LeafNode();
87
92 explicit LeafNode(const Coord& xyz, bool value = false, bool active = false);
93
94 #ifndef OPENVDB_2_ABI_COMPATIBLE
95 LeafNode(PartialCreate, const Coord& xyz, bool value = false, bool active = false);
97 #endif
98
100 LeafNode(const LeafNode&);
101
103 LeafNode& operator=(const LeafNode&) = default;
104
106 template<typename OtherValueType>
107 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
108
110 template<typename ValueType>
111 LeafNode(const LeafNode<ValueType, Log2Dim>& other, TopologyCopy);
112
114 template<typename ValueType>
117 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool offValue, bool onValue, TopologyCopy);
118 template<typename ValueType>
119 LeafNode(const LeafNode<ValueType, Log2Dim>& other, bool background, TopologyCopy);
121
123 ~LeafNode();
124
125 //
126 // Statistics
127 //
129 static Index log2dim() { return Log2Dim; }
131 static Index dim() { return DIM; }
132 static Index size() { return SIZE; }
133 static Index numValues() { return SIZE; }
134 static Index getLevel() { return LEVEL; }
135 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
136 static Index getChildDim() { return 1; }
137
138 static Index32 leafCount() { return 1; }
139 static Index32 nonLeafCount() { return 0; }
140
142 Index64 onVoxelCount() const { return mValueMask.countOn(); }
144 Index64 offVoxelCount() const { return mValueMask.countOff(); }
145 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
146 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
147 static Index64 onTileCount() { return 0; }
148 static Index64 offTileCount() { return 0; }
149
151 bool isEmpty() const { return mValueMask.isOff(); }
153 bool isDense() const { return mValueMask.isOn(); }
154
155 #ifndef OPENVDB_2_ABI_COMPATIBLE
156 bool isAllocated() const { return true; }
163 bool allocate() { return true; }
164 #endif
165
167 Index64 memUsage() const;
168
172 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
173
176 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
177
179 void setOrigin(const Coord& origin) { mOrigin = origin; }
181 const Coord& origin() const { return mOrigin; }
183 void getOrigin(Coord& origin) const { origin = mOrigin; }
184 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
186
188 static Index coordToOffset(const Coord& xyz);
191 static Coord offsetToLocalCoord(Index n);
193 Coord offsetToGlobalCoord(Index n) const;
194
196 std::string str() const;
197
200 template<typename OtherType, Index OtherLog2Dim>
201 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
202
204 bool operator==(const LeafNode&) const;
205 bool operator!=(const LeafNode&) const;
206
207 //
208 // Buffer management
209 //
212 void swap(Buffer& other) { mBuffer.swap(other); }
213 const Buffer& buffer() const { return mBuffer; }
214 Buffer& buffer() { return mBuffer; }
215
216 //
217 // I/O methods
218 //
220 void readTopology(std::istream&, bool fromHalf = false);
222 void writeTopology(std::ostream&, bool toHalf = false) const;
223
225 void readBuffers(std::istream&, bool fromHalf = false);
226 void readBuffers(std::istream& is, const CoordBBox&, bool fromHalf = false);
228 void writeBuffers(std::ostream&, bool toHalf = false) const;
229
230 //
231 // Accessor methods
232 //
234 const bool& getValue(const Coord& xyz) const;
236 const bool& getValue(Index offset) const;
237
241 bool probeValue(const Coord& xyz, bool& val) const;
242
244 static Index getValueLevel(const Coord&) { return LEVEL; }
245
247 void setActiveState(const Coord& xyz, bool on);
249 void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
250
252 void setValueOnly(const Coord& xyz, bool val);
254 void setValueOnly(Index offset, bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
255
257 void setValueOff(const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
259 void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
260
262 void setValueOff(const Coord& xyz, bool val);
264 void setValueOff(Index offset, bool val);
265
267 void setValueOn(const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
269 void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
270
272 void setValueOn(const Coord& xyz, bool val);
274 void setValue(const Coord& xyz, bool val) { this->setValueOn(xyz, val); }
276 void setValueOn(Index offset, bool val);
277
280 template<typename ModifyOp>
281 void modifyValue(Index offset, const ModifyOp& op);
284 template<typename ModifyOp>
285 void modifyValue(const Coord& xyz, const ModifyOp& op);
286
288 template<typename ModifyOp>
289 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op);
290
292 void setValuesOn() { mValueMask.setOn(); }
294 void setValuesOff() { mValueMask.setOff(); }
295
297 bool isValueOn(const Coord& xyz) const { return mValueMask.isOn(this->coordToOffset(xyz)); }
299 bool isValueOn(Index offset) const { assert(offset < SIZE); return mValueMask.isOn(offset); }
300
302 static bool hasActiveTiles() { return false; }
303
305 void clip(const CoordBBox&, bool background);
306
308 void fill(const CoordBBox& bbox, bool value, bool active = true);
310 void denseFill(const CoordBBox& bbox, bool val, bool on = true) { this->fill(bbox, val, on); }
311
313 void fill(const bool& value);
315 void fill(const bool& value, bool active);
316
328 template<typename DenseT>
329 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
330
347 template<typename DenseT>
348 void copyFromDense(const CoordBBox& bbox, const DenseT& dense, bool background, bool tolerance);
349
352 template<typename AccessorT>
353 const bool& getValueAndCache(const Coord& xyz, AccessorT&) const {return this->getValue(xyz);}
354
357 template<typename AccessorT>
358 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
359
362 template<typename AccessorT>
363 void setValueAndCache(const Coord& xyz, bool val, AccessorT&) { this->setValueOn(xyz, val); }
364
368 template<typename AccessorT>
369 void setValueOnlyAndCache(const Coord& xyz, bool val, AccessorT&) {this->setValueOnly(xyz,val);}
370
373 template<typename AccessorT>
374 void setValueOffAndCache(const Coord& xyz, bool value, AccessorT&)
375 {
376 this->setValueOff(xyz, value);
377 }
378
382 template<typename ModifyOp, typename AccessorT>
383 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
384 {
385 this->modifyValue(xyz, op);
386 }
387
390 template<typename ModifyOp, typename AccessorT>
391 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
392 {
393 this->modifyValueAndActiveState(xyz, op);
394 }
395
399 template<typename AccessorT>
400 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
401 {
402 this->setActiveState(xyz, on);
403 }
404
408 template<typename AccessorT>
409 bool probeValueAndCache(const Coord& xyz, bool& val, AccessorT&) const
410 {
411 return this->probeValue(xyz, val);
412 }
413
416 template<typename AccessorT>
417 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
418
422 const bool& getFirstValue() const { if (mValueMask.isOn(0)) return Buffer::sOn; else return Buffer::sOff; }
426 const bool& getLastValue() const { if (mValueMask.isOn(SIZE-1)) return Buffer::sOn; else return Buffer::sOff; }
427
431 bool isConstant(bool& constValue, bool& state, bool tolerance = 0) const;
432
438 bool medianAll() const;
439
446 Index medianOn(ValueType &value) const;
447
454 Index medianOff(ValueType &value) const;
455
457 bool isInactive() const { return mValueMask.isOff(); }
458
459 void resetBackground(bool oldBackground, bool newBackground);
460
461 void negate() { mBuffer.mData.toggle(); }
462
463 template<MergePolicy Policy>
464 void merge(const LeafNode& other, bool bg = false, bool otherBG = false);
465 template<MergePolicy Policy> void merge(bool tileValue, bool tileActive);
466
469 void voxelizeActiveTiles(bool = true) {}
470
477 template<typename OtherType>
478 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
479
491 template<typename OtherType>
492 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const bool&);
493
505 template<typename OtherType>
506 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const bool&);
507
508 template<typename CombineOp>
509 void combine(const LeafNode& other, CombineOp& op);
510 template<typename CombineOp>
511 void combine(bool, bool valueIsActive, CombineOp& op);
512
513 template<typename CombineOp, typename OtherType /*= bool*/>
514 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
515 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
516 void combine2(bool, const OtherNodeT& other, bool valueIsActive, CombineOp&);
517 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
518 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
519
524 template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
525
526 template<typename VisitorOp> void visit(VisitorOp&);
527 template<typename VisitorOp> void visit(VisitorOp&) const;
528
529 template<typename OtherLeafNodeType, typename VisitorOp>
530 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
531 template<typename OtherLeafNodeType, typename VisitorOp>
532 void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
533 template<typename IterT, typename VisitorOp>
534 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
535 template<typename IterT, typename VisitorOp>
536 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
537
539 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
541 void addLeaf(LeafNode*) {}
542 template<typename AccessorT>
543 void addLeafAndCache(LeafNode*, AccessorT&) {}
544 template<typename NodeT>
545 NodeT* stealNode(const Coord&, const ValueType&, bool) { return nullptr; }
546 template<typename NodeT>
547 NodeT* probeNode(const Coord&) { return nullptr; }
548 template<typename NodeT>
549 const NodeT* probeConstNode(const Coord&) const { return nullptr; }
550 template<typename ArrayT> void getNodes(ArrayT&) const {}
551 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
553
554 void addTile(Index level, const Coord&, bool val, bool active);
555 void addTile(Index offset, bool val, bool active);
556 template<typename AccessorT>
557 void addTileAndCache(Index level, const Coord&, bool val, bool active, AccessorT&);
558
560 LeafNode* touchLeaf(const Coord&) { return this; }
562 template<typename AccessorT>
563 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
564 LeafNode* probeLeaf(const Coord&) { return this; }
565 template<typename AccessorT>
566 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
567 template<typename NodeT, typename AccessorT>
568 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
569 {
570 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
571 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
572 return reinterpret_cast<NodeT*>(this);
573 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
574 }
576
577 const LeafNode* probeLeaf(const Coord&) const { return this; }
579 template<typename AccessorT>
580 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
581 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
582 template<typename AccessorT>
583 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
584 template<typename NodeT, typename AccessorT>
585 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
586 {
587 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
588 if (!(std::is_same<NodeT, LeafNode>::value)) return nullptr;
589 return reinterpret_cast<const NodeT*>(this);
590 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
591 }
593
594 //
595 // Iterators
596 //
597 protected:
598 using MaskOnIter = typename NodeMaskType::OnIterator;
599 using MaskOffIter = typename NodeMaskType::OffIterator;
600 using MaskDenseIter = typename NodeMaskType::DenseIterator;
601
602 template<typename MaskIterT, typename NodeT, typename ValueT>
603 struct ValueIter:
604 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
605 // if MaskIterT is a dense mask iterator type.
606 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
607 {
608 using BaseT = SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT>;
609
610 ValueIter() {}
611 ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
612
613 const bool& getItem(Index pos) const { return this->parent().getValue(pos); }
614 const bool& getValue() const { return this->getItem(this->pos()); }
615
616 // Note: setItem() can't be called on const iterators.
617 void setItem(Index pos, bool value) const { this->parent().setValueOnly(pos, value); }
618 // Note: setValue() can't be called on const iterators.
619 void setValue(bool value) const { this->setItem(this->pos(), value); }
620
621 // Note: modifyItem() can't be called on const iterators.
622 template<typename ModifyOp>
623 void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
624 // Note: modifyValue() can't be called on const iterators.
625 template<typename ModifyOp>
626 void modifyValue(const ModifyOp& op) const { this->modifyItem(this->pos(), op); }
627 };
628
630 template<typename MaskIterT, typename NodeT>
631 struct ChildIter:
632 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>
633 {
634 ChildIter() {}
635 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
636 MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
637 };
638
639 template<typename NodeT, typename ValueT>
640 struct DenseIter: public DenseIteratorBase<
641 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, /*ChildT=*/void, ValueT>
642 {
643 using BaseT = DenseIteratorBase<MaskDenseIter, DenseIter, NodeT, void, ValueT>;
644 using NonConstValueT = typename BaseT::NonConstValueType;
645
646 DenseIter() {}
647 DenseIter(const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
648
649 bool getItem(Index pos, void*& child, NonConstValueT& value) const
650 {
651 value = this->parent().getValue(pos);
652 child = nullptr;
653 return false; // no child
654 }
655
656 // Note: setItem() can't be called on const iterators.
657 //void setItem(Index pos, void* child) const {}
658
659 // Note: unsetItem() can't be called on const iterators.
660 void unsetItem(Index pos, const ValueT& val) const {this->parent().setValueOnly(pos, val);}
661 };
662
663 public:
664 using ValueOnIter = ValueIter<MaskOnIter, LeafNode, const bool>;
665 using ValueOnCIter = ValueIter<MaskOnIter, const LeafNode, const bool>;
666 using ValueOffIter = ValueIter<MaskOffIter, LeafNode, const bool>;
667 using ValueOffCIter = ValueIter<MaskOffIter, const LeafNode, const bool>;
668 using ValueAllIter = ValueIter<MaskDenseIter, LeafNode, const bool>;
669 using ValueAllCIter = ValueIter<MaskDenseIter, const LeafNode, const bool>;
670 using ChildOnIter = ChildIter<MaskOnIter, LeafNode>;
671 using ChildOnCIter = ChildIter<MaskOnIter, const LeafNode>;
672 using ChildOffIter = ChildIter<MaskOffIter, LeafNode>;
673 using ChildOffCIter = ChildIter<MaskOffIter, const LeafNode>;
674 using ChildAllIter = DenseIter<LeafNode, bool>;
675 using ChildAllCIter = DenseIter<const LeafNode, const bool>;
676
677 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
678 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
679 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
680 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
681 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
682 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
683 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
684 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
685 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
686
687 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
688 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
689 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
690 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
691 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
692 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
693 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
694 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
695 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
696
697 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
698 // because leaf nodes have no children.
699 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
700 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
701 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
702 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
703 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
704 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
705 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
706 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
707 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
708
709 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
710 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
711 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
712 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
713 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
714 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
715 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
716 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
717 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
718
719 //
720 // Mask accessors
721 //
722 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
723 bool isValueMaskOn() const { return mValueMask.isOn(); }
724 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
725 bool isValueMaskOff() const { return mValueMask.isOff(); }
726 const NodeMaskType& getValueMask() const { return mValueMask; }
727 const NodeMaskType& valueMask() const { return mValueMask; }
728 NodeMaskType& getValueMask() { return mValueMask; }
729 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
730 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
731 bool isChildMaskOff(Index) const { return true; }
732 bool isChildMaskOff() const { return true; }
733 protected:
734 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
735 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
736 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
737
739 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
740
741 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
742 static inline void doVisit(NodeT&, VisitorOp&);
743
744 template<typename NodeT, typename OtherNodeT, typename VisitorOp,
745 typename ChildAllIterT, typename OtherChildAllIterT>
746 static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
747
748 template<typename NodeT, typename VisitorOp,
749 typename ChildAllIterT, typename OtherChildAllIterT>
750 static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
751
752
754 NodeMaskType mValueMask;
756 Buffer mBuffer;
758 Coord mOrigin;
759
760 private:
763 template<typename, Index> friend class LeafNode;
764
765 friend struct ValueIter<MaskOnIter, LeafNode, bool>;
766 friend struct ValueIter<MaskOffIter, LeafNode, bool>;
767 friend struct ValueIter<MaskDenseIter, LeafNode, bool>;
768 friend struct ValueIter<MaskOnIter, const LeafNode, bool>;
769 friend struct ValueIter<MaskOffIter, const LeafNode, bool>;
770 friend struct ValueIter<MaskDenseIter, const LeafNode, bool>;
771
773 friend class IteratorBase<MaskOnIter, LeafNode>;
776 friend class IteratorBase<MaskOffIter, LeafNode>;
777 friend class IteratorBase<MaskDenseIter, LeafNode>;
779
780 }; // class LeafNode<bool>
781
782
784
785
786 template<Index Log2Dim>
787 inline
788 LeafNode<bool, Log2Dim>::LeafNode()
789 : mOrigin(0, 0, 0)
790 {
791 }
792
793
794 template<Index Log2Dim>
795 inline
796 LeafNode<bool, Log2Dim>::LeafNode(const Coord& xyz, bool value, bool active)
797 : mValueMask(active)
798 , mBuffer(value)
799 , mOrigin(xyz & (~(DIM - 1)))
800 {
801 }
802
803
804 #ifndef OPENVDB_2_ABI_COMPATIBLE
805 template<Index Log2Dim>
806 inline
807 LeafNode<bool, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, bool value, bool active)
808 : mValueMask(active)
809 , mBuffer(value)
810 , mOrigin(xyz & (~(DIM - 1)))
811 {
815 }
816 #endif
817
818
819 template<Index Log2Dim>
820 inline
821 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode &other)
822 : mValueMask(other.valueMask())
823 , mBuffer(other.mBuffer)
824 , mOrigin(other.mOrigin)
825 {
826 }
827
828
829 // Copy-construct from a leaf node with the same configuration but a different ValueType.
830 template<Index Log2Dim>
831 template<typename ValueT>
832 inline
833 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other)
834 : mValueMask(other.valueMask())
835 , mOrigin(other.origin())
836 {
837 struct Local {
839 static inline bool convertValue(const ValueT& val) { return bool(val); }
840 };
841
842 for (Index i = 0; i < SIZE; ++i) {
843 mBuffer.setValue(i, Local::convertValue(other.mBuffer[i]));
844 }
845 }
846
847
848 template<Index Log2Dim>
849 template<typename ValueT>
850 inline
851 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
852 bool background, TopologyCopy)
853 : mValueMask(other.valueMask())
854 , mBuffer(background)
855 , mOrigin(other.origin())
856 {
857 }
858
859
860 template<Index Log2Dim>
861 template<typename ValueT>
862 inline
863 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other, TopologyCopy)
864 : mValueMask(other.valueMask())
865 , mBuffer(other.valueMask())// value = active state
866 , mOrigin(other.origin())
867 {
868 }
869
870
871 template<Index Log2Dim>
872 template<typename ValueT>
873 inline
874 LeafNode<bool, Log2Dim>::LeafNode(const LeafNode<ValueT, Log2Dim>& other,
875 bool offValue, bool onValue, TopologyCopy)
876 : mValueMask(other.valueMask())
877 , mBuffer(other.valueMask())
878 , mOrigin(other.origin())
879 {
880 if (offValue) { if (!onValue) mBuffer.mData.toggle(); else mBuffer.mData.setOn(); }
881 }
882
883
884 template<Index Log2Dim>
885 inline
886 LeafNode<bool, Log2Dim>::~LeafNode()
887 {
888 }
889
890
892
893
894 template<Index Log2Dim>
895 inline Index64
896 LeafNode<bool, Log2Dim>::memUsage() const
897 {
898 // Use sizeof(*this) to capture alignment-related padding
899 return sizeof(*this);
900 }
901
902
903 template<Index Log2Dim>
904 inline void
905 LeafNode<bool, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
906 {
907 CoordBBox this_bbox = this->getNodeBoundingBox();
908 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
909 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
910 if (visitVoxels) {//use voxel granularity?
911 this_bbox.reset();
912 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
913 this_bbox.translate(this->origin());
914 }
915 bbox.expand(this_bbox);
916 }
917 }
918
919
920 template<Index Log2Dim>
921 template<typename OtherType, Index OtherLog2Dim>
922 inline bool
923 LeafNode<bool, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
924 {
925 assert(other);
926 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
927 }
928
929
930 template<Index Log2Dim>
931 inline std::string
932 LeafNode<bool, Log2Dim>::str() const
933 {
934 std::ostringstream ostr;
935 ostr << "LeafNode @" << mOrigin << ": ";
936 for (Index32 n = 0; n < SIZE; ++n) ostr << (mValueMask.isOn(n) ? '#' : '.');
937 return ostr.str();
938 }
939
940
942
943
944 template<Index Log2Dim>
945 inline Index
946 LeafNode<bool, Log2Dim>::coordToOffset(const Coord& xyz)
947 {
948 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
949 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
950 + ((xyz[1] & (DIM-1u)) << Log2Dim)
951 + (xyz[2] & (DIM-1u));
952 }
953
954
955 template<Index Log2Dim>
956 inline Coord
957 LeafNode<bool, Log2Dim>::offsetToLocalCoord(Index n)
958 {
959 assert(n < (1 << 3*Log2Dim));
960 Coord xyz;
961 xyz.setX(n >> 2*Log2Dim);
962 n &= ((1 << 2*Log2Dim) - 1);
963 xyz.setY(n >> Log2Dim);
964 xyz.setZ(n & ((1 << Log2Dim) - 1));
965 return xyz;
966 }
967
968
969 template<Index Log2Dim>
970 inline Coord
971 LeafNode<bool, Log2Dim>::offsetToGlobalCoord(Index n) const
972 {
973 return (this->offsetToLocalCoord(n) + this->origin());
974 }
975
976
978
979
980 template<Index Log2Dim>
981 inline void
982 LeafNode<bool, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
983 {
984 mValueMask.load(is);
985 }
986
987
988 template<Index Log2Dim>
989 inline void
990 LeafNode<bool, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
991 {
992 mValueMask.save(os);
993 }
994
995
996 template<Index Log2Dim>
997 inline void
998 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
999 {
1000 // Boolean LeafNodes don't currently implement lazy loading.
1001 // Instead, load the full buffer, then clip it.
1002
1003 this->readBuffers(is, fromHalf);
1004
1005 // Get this tree's background value.
1006 bool background = false;
1007 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1008 background = *static_cast<const bool*>(bgPtr);
1009 }
1010 this->clip(clipBBox, background);
1011 }
1012
1013
1014 template<Index Log2Dim>
1015 inline void
1016 LeafNode<bool, Log2Dim>::readBuffers(std::istream& is, bool /*fromHalf*/)
1017 {
1018 // Read in the value mask.
1019 mValueMask.load(is);
1020 // Read in the origin.
1021 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1022
1023 if (io::getFormatVersion(is) >= OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION) {
1024 // Read in the mask for the voxel values.
1025 mBuffer.mData.load(is);
1026 } else {
1027 // Older files stored one or more bool arrays.
1028
1029 // Read in the number of buffers, which should now always be one.
1030 int8_t numBuffers = 0;
1031 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1032
1033 // Read in the buffer.
1034 // (Note: prior to the bool leaf optimization, buffers were always compressed.)
1035 boost::shared_array<bool> buf(new bool[SIZE]);
1036 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1037
1038 // Transfer values to mBuffer.
1039 mBuffer.mData.setOff();
1040 for (Index i = 0; i < SIZE; ++i) {
1041 if (buf[i]) mBuffer.mData.setOn(i);
1042 }
1043
1044 if (numBuffers > 1) {
1045 // Read in and discard auxiliary buffers that were created with
1046 // earlier versions of the library.
1047 for (int i = 1; i < numBuffers; ++i) {
1048 io::readData<bool>(is, buf.get(), SIZE, /*isCompressed=*/true);
1049 }
1050 }
1051 }
1052 }
1053
1054
1055 template<Index Log2Dim>
1056 inline void
1057 LeafNode<bool, Log2Dim>::writeBuffers(std::ostream& os, bool /*toHalf*/) const
1058 {
1059 // Write out the value mask.
1060 mValueMask.save(os);
1061 // Write out the origin.
1062 os.write(reinterpret_cast<const char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1063 // Write out the voxel values.
1064 mBuffer.mData.save(os);
1065 }
1066
1067
1069
1070
1071 template<Index Log2Dim>
1072 inline bool
1073 LeafNode<bool, Log2Dim>::operator==(const LeafNode& other) const
1074 {
1075 return mOrigin == other.mOrigin &&
1076 mValueMask == other.valueMask() &&
1077 mBuffer == other.mBuffer;
1078 }
1079
1080
1081 template<Index Log2Dim>
1082 inline bool
1083 LeafNode<bool, Log2Dim>::operator!=(const LeafNode& other) const
1084 {
1085 return !(this->operator==(other));
1086 }
1087
1088
1090
1091
1092 template<Index Log2Dim>
1093 inline bool
1094 LeafNode<bool, Log2Dim>::isConstant(bool& constValue, bool& state, bool tolerance) const
1095 {
1096 if (!mValueMask.isConstant(state)) return false;
1097
1098 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1099 if (!tolerance && !(mBuffer.mData.isOn() || mBuffer.mData.isOff())) return false;
1100
1101 constValue = mBuffer.mData.isOn();
1102 return true;
1103 }
1104
1106
1107 template<Index Log2Dim>
1108 inline bool
1109 LeafNode<bool, Log2Dim>::medianAll() const
1110 {
1111 const Index countTrue = mBuffer.mData.countOn();
1112 return countTrue > (NUM_VALUES >> 1);
1113 }
1114
1115 template<Index Log2Dim>
1116 inline Index
1117 LeafNode<bool, Log2Dim>::medianOn(bool& state) const
1118 {
1119 const NodeMaskType tmp = mBuffer.mData & mValueMask;//both true and active
1120 const Index countTrueOn = tmp.countOn(), countOn = mValueMask.countOn();
1121 state = countTrueOn > (NUM_VALUES >> 1);
1122 return countOn;
1123 }
1124
1125 template<Index Log2Dim>
1126 inline Index
1127 LeafNode<bool, Log2Dim>::medianOff(bool& state) const
1128 {
1129 const NodeMaskType tmp = mBuffer.mData & (!mValueMask);//both true and inactive
1130 const Index countTrueOff = tmp.countOn(), countOff = mValueMask.countOff();
1131 state = countTrueOff > (NUM_VALUES >> 1);
1132 return countOff;
1133 }
1134
1136
1137
1138 template<Index Log2Dim>
1139 inline void
1140 LeafNode<bool, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, bool val, bool active)
1141 {
1142 this->addTile(this->coordToOffset(xyz), val, active);
1143 }
1144
1145 template<Index Log2Dim>
1146 inline void
1147 LeafNode<bool, Log2Dim>::addTile(Index offset, bool val, bool active)
1148 {
1149 assert(offset < SIZE);
1150 this->setValueOnly(offset, val);
1151 this->setActiveState(offset, active);
1152 }
1153
1154 template<Index Log2Dim>
1155 template<typename AccessorT>
1156 inline void
1157 LeafNode<bool, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1158 bool val, bool active, AccessorT&)
1159 {
1160 this->addTile(level, xyz, val, active);
1161 }
1162
1163
1165
1166
1167 template<Index Log2Dim>
1168 inline const bool&
1169 LeafNode<bool, Log2Dim>::getValue(const Coord& xyz) const
1170 {
1171 // This *CANNOT* use operator ? because Visual C++
1172 if (mBuffer.mData.isOn(this->coordToOffset(xyz))) return Buffer::sOn; else return Buffer::sOff;
1173 }
1174
1175
1176 template<Index Log2Dim>
1177 inline const bool&
1178 LeafNode<bool, Log2Dim>::getValue(Index offset) const
1179 {
1180 assert(offset < SIZE);
1181 // This *CANNOT* use operator ? for Windows
1182 if (mBuffer.mData.isOn(offset)) return Buffer::sOn; else return Buffer::sOff;
1183 }
1184
1185
1186 template<Index Log2Dim>
1187 inline bool
1188 LeafNode<bool, Log2Dim>::probeValue(const Coord& xyz, bool& val) const
1189 {
1190 const Index offset = this->coordToOffset(xyz);
1191 val = mBuffer.mData.isOn(offset);
1192 return mValueMask.isOn(offset);
1193 }
1194
1195
1196 template<Index Log2Dim>
1197 inline void
1198 LeafNode<bool, Log2Dim>::setValueOn(const Coord& xyz, bool val)
1199 {
1200 this->setValueOn(this->coordToOffset(xyz), val);
1201 }
1202
1203
1204 template<Index Log2Dim>
1205 inline void
1206 LeafNode<bool, Log2Dim>::setValueOn(Index offset, bool val)
1207 {
1208 assert(offset < SIZE);
1209 mValueMask.setOn(offset);
1210 mBuffer.mData.set(offset, val);
1211 }
1212
1213
1214 template<Index Log2Dim>
1215 inline void
1216 LeafNode<bool, Log2Dim>::setValueOnly(const Coord& xyz, bool val)
1217 {
1218 this->setValueOnly(this->coordToOffset(xyz), val);
1219 }
1220
1221
1222 template<Index Log2Dim>
1223 inline void
1224 LeafNode<bool, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1225 {
1226 mValueMask.set(this->coordToOffset(xyz), on);
1227 }
1228
1229
1230 template<Index Log2Dim>
1231 inline void
1232 LeafNode<bool, Log2Dim>::setValueOff(const Coord& xyz, bool val)
1233 {
1234 this->setValueOff(this->coordToOffset(xyz), val);
1235 }
1236
1237
1238 template<Index Log2Dim>
1239 inline void
1240 LeafNode<bool, Log2Dim>::setValueOff(Index offset, bool val)
1241 {
1242 assert(offset < SIZE);
1243 mValueMask.setOff(offset);
1244 mBuffer.mData.set(offset, val);
1245 }
1246
1247
1248 template<Index Log2Dim>
1249 template<typename ModifyOp>
1250 inline void
1251 LeafNode<bool, Log2Dim>::modifyValue(Index offset, const ModifyOp& op)
1252 {
1253 bool val = mBuffer.mData.isOn(offset);
1254 op(val);
1255 mBuffer.mData.set(offset, val);
1256 mValueMask.setOn(offset);
1257 }
1258
1259
1260 template<Index Log2Dim>
1261 template<typename ModifyOp>
1262 inline void
1263 LeafNode<bool, Log2Dim>::modifyValue(const Coord& xyz, const ModifyOp& op)
1264 {
1265 this->modifyValue(this->coordToOffset(xyz), op);
1266 }
1267
1268
1269 template<Index Log2Dim>
1270 template<typename ModifyOp>
1271 inline void
1272 LeafNode<bool, Log2Dim>::modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
1273 {
1274 const Index offset = this->coordToOffset(xyz);
1275 bool val = mBuffer.mData.isOn(offset), state = mValueMask.isOn(offset);
1276 op(val, state);
1277 mBuffer.mData.set(offset, val);
1278 mValueMask.set(offset, state);
1279 }
1280
1281
1283
1284
1285 template<Index Log2Dim>
1286 inline void
1287 LeafNode<bool, Log2Dim>::resetBackground(bool oldBackground, bool newBackground)
1288 {
1289 if (newBackground != oldBackground) {
1290 // Flip mBuffer's background bits and zero its foreground bits.
1291 NodeMaskType bgMask = !(mBuffer.mData | mValueMask);
1292 // Overwrite mBuffer's background bits, leaving its foreground bits intact.
1293 mBuffer.mData = (mBuffer.mData & mValueMask) | bgMask;
1294 }
1295 }
1296
1297
1299
1300
1301 template<Index Log2Dim>
1302 template<MergePolicy Policy>
1303 inline void
1304 LeafNode<bool, Log2Dim>::merge(const LeafNode& other, bool /*bg*/, bool /*otherBG*/)
1305 {
1306 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1307 if (Policy == MERGE_NODES) return;
1308 for (typename NodeMaskType::OnIterator iter = other.valueMask().beginOn(); iter; ++iter) {
1309 const Index n = iter.pos();
1310 if (mValueMask.isOff(n)) {
1311 mBuffer.mData.set(n, other.mBuffer.mData.isOn(n));
1312 mValueMask.setOn(n);
1313 }
1314 }
1315 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1316 }
1317
1318 template<Index Log2Dim>
1319 template<MergePolicy Policy>
1320 inline void
1321 LeafNode<bool, Log2Dim>::merge(bool tileValue, bool tileActive)
1322 {
1323 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1324 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1325 if (!tileActive) return;
1326 // Replace all inactive values with the active tile value.
1327 if (tileValue) mBuffer.mData |= !mValueMask; // -0=>1, +0=>0, -1=>1, +1=>1 (-,+ = off,on)
1328 else mBuffer.mData &= mValueMask; // -0=>0, +0=>0, -1=>0, +1=>1
1329 mValueMask.setOn();
1330 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1331 }
1332
1333
1335
1336
1337 template<Index Log2Dim>
1338 template<typename OtherType>
1339 inline void
1340 LeafNode<bool, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other)
1341 {
1342 mValueMask |= other.valueMask();
1343 }
1344
1345
1346 template<Index Log2Dim>
1347 template<typename OtherType>
1348 inline void
1349 LeafNode<bool, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1350 const bool&)
1351 {
1352 mValueMask &= other.valueMask();
1353 }
1354
1355
1356 template<Index Log2Dim>
1357 template<typename OtherType>
1358 inline void
1359 LeafNode<bool, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1360 const bool&)
1361 {
1362 mValueMask &= !other.valueMask();
1363 }
1364
1365
1367
1368
1369 template<Index Log2Dim>
1370 inline void
1371 LeafNode<bool, Log2Dim>::clip(const CoordBBox& clipBBox, bool background)
1372 {
1373 CoordBBox nodeBBox = this->getNodeBoundingBox();
1374 if (!clipBBox.hasOverlap(nodeBBox)) {
1375 // This node lies completely outside the clipping region. Fill it with background tiles.
1376 this->fill(nodeBBox, background, /*active=*/false);
1377 } else if (clipBBox.isInside(nodeBBox)) {
1378 // This node lies completely inside the clipping region. Leave it intact.
1379 return;
1380 }
1381
1382 // This node isn't completely contained inside the clipping region.
1383 // Set any voxels that lie outside the region to the background value.
1384
1385 // Construct a boolean mask that is on inside the clipping region and off outside it.
1386 NodeMaskType mask;
1387 nodeBBox.intersect(clipBBox);
1388 Coord xyz;
1389 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1390 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1391 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1392 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1393 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1394 }
1395 }
1396 }
1397
1398 // Set voxels that lie in the inactive region of the mask (i.e., outside
1399 // the clipping region) to the background value.
1400 for (MaskOffIter maskIter = mask.beginOff(); maskIter; ++maskIter) {
1401 this->setValueOff(maskIter.pos(), background);
1402 }
1403 }
1404
1405
1407
1408
1409 template<Index Log2Dim>
1410 inline void
1411 LeafNode<bool, Log2Dim>::fill(const CoordBBox& bbox, bool value, bool active)
1412 {
1413 auto clippedBBox = this->getNodeBoundingBox();
1414 clippedBBox.intersect(bbox);
1415 if (!clippedBBox) return;
1416
1417 for (Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1418 const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1419 for (Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1420 const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1421 for (Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1422 const Index offset = offsetXY + (z & (DIM-1u));
1423 mValueMask.set(offset, active);
1424 mBuffer.mData.set(offset, value);
1425 }
1426 }
1427 }
1428 }
1429
1430 template<Index Log2Dim>
1431 inline void
1432 LeafNode<bool, Log2Dim>::fill(const bool& value)
1433 {
1434 mBuffer.fill(value);
1435 }
1436
1437 template<Index Log2Dim>
1438 inline void
1439 LeafNode<bool, Log2Dim>::fill(const bool& value, bool active)
1440 {
1441 mBuffer.fill(value);
1442 mValueMask.set(active);
1443 }
1444
1445
1447
1448
1449 template<Index Log2Dim>
1450 template<typename DenseT>
1451 inline void
1452 LeafNode<bool, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1453 {
1454 using DenseValueType = typename DenseT::ValueType;
1455
1456 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1457 const Coord& min = dense.bbox().min();
1458 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1459 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1460 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1461 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1462 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1463 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1464 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1465 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1466 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1467 *t2 = DenseValueType(mBuffer.mData.isOn(n2++));
1468 }
1469 }
1470 }
1471 }
1472
1473
1474 template<Index Log2Dim>
1475 template<typename DenseT>
1476 inline void
1477 LeafNode<bool, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1478 bool background, bool tolerance)
1479 {
1480 using DenseValueType = typename DenseT::ValueType;
1481 struct Local {
1482 inline static bool toBool(const DenseValueType& v) { return !math::isZero(v); }
1483 };
1484
1485 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1486 const Coord& min = dense.bbox().min();
1487 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1488 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1489 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1490 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1491 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1492 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1493 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1494 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1495 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1496 // Note: if tolerance is true (i.e., 1), then all boolean values compare equal.
1497 if (tolerance || (background == Local::toBool(*s2))) {
1498 mValueMask.setOff(n2);
1499 mBuffer.mData.set(n2, background);
1500 } else {
1501 mValueMask.setOn(n2);
1502 mBuffer.mData.set(n2, Local::toBool(*s2));
1503 }
1504 }
1505 }
1506 }
1507 }
1508
1509
1511
1512
1513 template<Index Log2Dim>
1514 template<typename CombineOp>
1515 inline void
1516 LeafNode<bool, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1517 {
1518 CombineArgs<bool> args;
1519 for (Index i = 0; i < SIZE; ++i) {
1520 bool result = false, aVal = mBuffer.mData.isOn(i), bVal = other.mBuffer.mData.isOn(i);
1521 op(args.setARef(aVal)
1522 .setAIsActive(mValueMask.isOn(i))
1523 .setBRef(bVal)
1524 .setBIsActive(other.valueMask().isOn(i))
1525 .setResultRef(result));
1526 mValueMask.set(i, args.resultIsActive());
1527 mBuffer.mData.set(i, result);
1528 }
1529 }
1530
1531
1532 template<Index Log2Dim>
1533 template<typename CombineOp>
1534 inline void
1535 LeafNode<bool, Log2Dim>::combine(bool value, bool valueIsActive, CombineOp& op)
1536 {
1537 CombineArgs<bool> args;
1538 args.setBRef(value).setBIsActive(valueIsActive);
1539 for (Index i = 0; i < SIZE; ++i) {
1540 bool result = false, aVal = mBuffer.mData.isOn(i);
1541 op(args.setARef(aVal)
1542 .setAIsActive(mValueMask.isOn(i))
1543 .setResultRef(result));
1544 mValueMask.set(i, args.resultIsActive());
1545 mBuffer.mData.set(i, result);
1546 }
1547 }
1548
1549
1551
1552
1553 template<Index Log2Dim>
1554 template<typename CombineOp, typename OtherType>
1555 inline void
1556 LeafNode<bool, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1557 bool valueIsActive, CombineOp& op)
1558 {
1559 CombineArgs<bool, OtherType> args;
1560 args.setBRef(value).setBIsActive(valueIsActive);
1561 for (Index i = 0; i < SIZE; ++i) {
1562 bool result = false, aVal = other.mBuffer.mData.isOn(i);
1563 op(args.setARef(aVal)
1564 .setAIsActive(other.valueMask().isOn(i))
1565 .setResultRef(result));
1566 mValueMask.set(i, args.resultIsActive());
1567 mBuffer.mData.set(i, result);
1568 }
1569 }
1570
1571
1572 template<Index Log2Dim>
1573 template<typename CombineOp, typename OtherNodeT>
1574 inline void
1575 LeafNode<bool, Log2Dim>::combine2(bool value, const OtherNodeT& other,
1576 bool valueIsActive, CombineOp& op)
1577 {
1578 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1579 args.setARef(value).setAIsActive(valueIsActive);
1580 for (Index i = 0; i < SIZE; ++i) {
1581 bool result = false, bVal = other.mBuffer.mData.isOn(i);
1582 op(args.setBRef(bVal)
1583 .setBIsActive(other.valueMask().isOn(i))
1584 .setResultRef(result));
1585 mValueMask.set(i, args.resultIsActive());
1586 mBuffer.mData.set(i, result);
1587 }
1588 }
1589
1590
1591 template<Index Log2Dim>
1592 template<typename CombineOp, typename OtherNodeT>
1593 inline void
1594 LeafNode<bool, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
1595 {
1596 CombineArgs<bool, typename OtherNodeT::ValueType> args;
1597 for (Index i = 0; i < SIZE; ++i) {
1598 // Default behavior: output voxel is active if either input voxel is active.
1599 mValueMask.set(i, b0.valueMask().isOn(i) || b1.valueMask().isOn(i));
1600
1601 bool result = false, b0Val = b0.mBuffer.mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1602 op(args.setARef(b0Val)
1603 .setAIsActive(b0.valueMask().isOn(i))
1604 .setBRef(b1Val)
1605 .setBIsActive(b1.valueMask().isOn(i))
1606 .setResultRef(result));
1607 mValueMask.set(i, args.resultIsActive());
1608 mBuffer.mData.set(i, result);
1609 }
1610 }
1611
1612
1614
1615 template<Index Log2Dim>
1616 template<typename BBoxOp>
1617 inline void
1618 LeafNode<bool, Log2Dim>::visitActiveBBox(BBoxOp& op) const
1619 {
1620 if (op.template descent<LEVEL>()) {
1621 for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
1622 #ifdef _MSC_VER
1623 op.operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1624 #else
1625 op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1626 #endif
1627 }
1628 } else {
1629 #ifdef _MSC_VER
1630 op.operator()<LEVEL>(this->getNodeBoundingBox());
1631 #else
1632 op.template operator()<LEVEL>(this->getNodeBoundingBox());
1633 #endif
1634 }
1635 }
1636
1637
1638 template<Index Log2Dim>
1639 template<typename VisitorOp>
1640 inline void
1641 LeafNode<bool, Log2Dim>::visit(VisitorOp& op)
1642 {
1643 doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
1644 }
1645
1646
1647 template<Index Log2Dim>
1648 template<typename VisitorOp>
1649 inline void
1650 LeafNode<bool, Log2Dim>::visit(VisitorOp& op) const
1651 {
1652 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
1653 }
1654
1655
1656 template<Index Log2Dim>
1657 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1658 inline void
1659 LeafNode<bool, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
1660 {
1661 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1662 op(iter);
1663 }
1664 }
1665
1666
1668
1669
1670 template<Index Log2Dim>
1671 template<typename OtherLeafNodeType, typename VisitorOp>
1672 inline void
1673 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
1674 {
1675 doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
1676 typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
1677 }
1678
1679
1680 template<Index Log2Dim>
1681 template<typename OtherLeafNodeType, typename VisitorOp>
1682 inline void
1683 LeafNode<bool, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
1684 {
1685 doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
1686 typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
1687 }
1688
1689
1690 template<Index Log2Dim>
1691 template<
1692 typename NodeT,
1693 typename OtherNodeT,
1694 typename VisitorOp,
1695 typename ChildAllIterT,
1696 typename OtherChildAllIterT>
1697 inline void
1698 LeafNode<bool, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
1699 {
1700 // Allow the two nodes to have different ValueTypes, but not different dimensions.
1701 static_assert(OtherNodeT::SIZE == NodeT::SIZE,
1702 "can't visit nodes of different sizes simultaneously");
1703 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
1704 "can't visit nodes at different tree levels simultaneously");
1705
1706 ChildAllIterT iter = self.beginChildAll();
1707 OtherChildAllIterT otherIter = other.beginChildAll();
1708
1709 for ( ; iter && otherIter; ++iter, ++otherIter) {
1710 op(iter, otherIter);
1711 }
1712 }
1713
1714
1716
1717
1718 template<Index Log2Dim>
1719 template<typename IterT, typename VisitorOp>
1720 inline void
1721 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
1722 {
1723 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*this, otherIter, op, otherIsLHS);
1724 }
1725
1726
1727 template<Index Log2Dim>
1728 template<typename IterT, typename VisitorOp>
1729 inline void
1730 LeafNode<bool, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
1731 {
1732 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*this, otherIter, op, otherIsLHS);
1733 }
1734
1735
1736 template<Index Log2Dim>
1737 template<
1738 typename NodeT,
1739 typename VisitorOp,
1740 typename ChildAllIterT,
1741 typename OtherChildAllIterT>
1742 inline void
1743 LeafNode<bool, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
1744 VisitorOp& op, bool otherIsLHS)
1745 {
1746 if (!otherIter) return;
1747
1748 if (otherIsLHS) {
1749 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1750 op(otherIter, iter);
1751 }
1752 } else {
1753 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
1754 op(iter, otherIter);
1755 }
1756 }
1757 }
1758
1759 } // namespace tree
1760 } // namespace OPENVDB_VERSION_NAME
1761 } // namespace openvdb
1762
1763 #endif // OPENVDB_TREE_LEAF_NODE_BOOL_HAS_BEEN_INCLUDED
1764
1765 // Copyright (c) 2012-2017 DreamWorks Animation LLC
1766 // All rights reserved. This software is distributed under the
1767 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v4_0_2::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1444
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:551
openvdb::v4_0_2::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:143
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::size
static Index size()
Definition: LeafNodeBool.h:132
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:731
openvdb::v4_0_2::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:221
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::offTileCount
static Index64 offTileCount()
Definition: LeafNodeBool.h:148
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValue
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:274
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:611
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:583
openvdb::v4_0_2::tools::clip
GridType::Ptr clip(const GridType &grid, const BBoxd &bbox, bool keepInterior=true)
Clip the given grid against a world-space bounding box and return a new grid containing the result...
Definition: Clip.h:375
openvdb::v4_0_2::io::getGridBackgroundValuePtr
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...
Types.h
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNodeBool.h:267
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::dim
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:131
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendValueAll
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:693
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:145
openvdb::v4_0_2::tree::LeafNode::setActiveState
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:1134
Compression.h
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:179
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValuesOn
void setValuesOn()
Mark all voxels as active but don&#39;t change their values.
Definition: LeafNodeBool.h:292
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getLastValue
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:426
openvdb::v4_0_2::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:495
openvdb::v4_0_2::tree::LeafNode::hasSameTopology
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:1499
openvdb::v4_0_2::SharedPtr
std::shared_ptr< T > SharedPtr
Definition: Types.h:130
openvdb::v4_0_2::MERGE_NODES
Definition: Types.h:317
openvdb::v4_0_2::math::Coord::z
Int32 z() const
Definition: Coord.h:156
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildOffCIter
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:673
openvdb::v4_0_2::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1073
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v4_0_2::math::Coord::setZ
Coord & setZ(Int32 z)
Definition: Coord.h:105
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:707
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:244
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeConstNode
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:549
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::mOrigin
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:758
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don&#39;t change its value.
Definition: LeafNodeBool.h:259
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:700
openvdb::v4_0_2::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1471
openvdb::v4_0_2::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1036
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueMaskOff
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:736
openvdb::v4_0_2::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:502
openvdb::v4_0_2::tree::LeafNode::visit
void visit(VisitorOp &)
Definition: LeafNode.h:1888
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:545
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueOnCIter
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:665
openvdb::v4_0_2::tree::LeafNode::clip
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1160
openvdb::v4_0_2::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1461
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendChildOff
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:712
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendValueOff
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:690
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildOnIter
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:670
openvdb::v4_0_2::tree::LeafNode::fill
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:1200
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::voxelizeActiveTiles
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNodeBool.h:469
openvdb::v4_0_2::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:358
openvdb::v4_0_2::tree::LeafNode::LeafNode
LeafNode()
Default constructor.
Definition: LeafNode.h:943
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOnlyAndCache
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:369
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::buffer
const Buffer & buffer() const
Definition: LeafNodeBool.h:213
openvdb::v4_0_2::math::Coord::y
Int32 y() const
Definition: Coord.h:155
openvdb::v4_0_2::tree::LeafNode::visitActiveBBox
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1865
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:680
openvdb::v4_0_2::Index32
uint32_t Index32
Definition: Types.h:55
openvdb::v4_0_2::tree::LeafNode::LEVEL
static const Index LEVEL
Definition: LeafNode.h:78
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::Ptr
SharedPtr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:61
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::offVoxelCount
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:144
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:417
openvdb::v4_0_2::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1629
openvdb::v4_0_2::tree::LeafNode::topologyDifference
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:1734
i
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueAllCIter
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:669
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:692
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildAllCIter
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:675
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:711
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::MaskOnIter
typename NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:598
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:563
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::MaskOffIter
typename NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:599
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendValueOn
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:687
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:543
openvdb::v4_0_2::tree::LeafNode::copyFromDense
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:1274
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildOffIter
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:672
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::addLeaf
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:541
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::numValues
static Index numValues()
Definition: LeafNodeBool.h:133
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeConstLeaf
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:581
openvdb::v4_0_2::math::CoordBBox
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:261
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:183
openvdb::v4_0_2::tree::LeafNode::visit2
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1968
openvdb::v4_0_2::math::CoordBBox::expand
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:419
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:585
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOffAndCache
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:374
openvdb::v4_0_2::util::NodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:354
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:717
openvdb::v4_0_2::tree::LeafNode::doVisit2
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1992
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:705
openvdb::v4_0_2::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:886
openvdb::v4_0_2::Index
Index32 Index
Definition: Types.h:57
openvdb::v4_0_2::util::DenseMaskIterator
Definition: NodeMasks.h:270
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:734
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:635
openvdb::v4_0_2::tree::LeafNode::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:317
openvdb::v4_0_2::tree::LeafNode::ChildAllIter
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:314
openvdb::v4_0_2::PartialCreate
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:505
openvdb::v4_0_2::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1084
openvdb::v4_0_2::tree::LeafNode::setValueOnly
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:1142
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isInactive
bool isInactive() const
Return true if all of this node&#39;s values are inactive.
Definition: LeafNodeBool.h:457
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::swap
void swap(Buffer &other)
Exchange this node&#39;s data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeBool.h:212
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:647
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:660
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnCIter endValueOn() const
Definition: LeafNodeBool.h:688
openvdb::v4_0_2::tree::LeafBuffer::mData
ValueType * mData
Definition: LeafBuffer.h:220
openvdb::v4_0_2::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1801
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::allocate
bool allocate()
Allocate memory for this node&#39;s buffer if it has not already been allocated.
Definition: LeafNodeBool.h:163
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getLevel
static Index getLevel()
Definition: LeafNodeBool.h:134
openvdb::v4_0_2::tree::LeafNode::isConstant
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1507
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:626
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setActiveStateAndCache
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:400
openvdb::v4_0_2::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1321
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildOn
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:710
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:704
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeBool.h:176
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:694
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::leafCount
static Index32 leafCount()
Definition: LeafNodeBool.h:138
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendChildAll
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:715
openvdb::v4_0_2::tree::LeafNode::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNode.h:427
openvdb::v4_0_2::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::modifyValueAndCache
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:383
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:151
openvdb::v4_0_2::tree::LeafNode::resetBackground
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1641
openvdb::v4_0_2::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:61
openvdb::v4_0_2::Index64
uint64_t Index64
Definition: Types.h:56
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn() const
Definition: LeafNodeBool.h:723
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:580
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:649
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::getItem
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:613
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:297
openvdb::v4_0_2::tree::LeafNode::merge
void merge(const LeafNode &)
Definition: LeafNode.h:1664
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::BuildType
bool BuildType
Definition: LeafNodeBool.h:57
openvdb::v4_0_2::tree::LeafNode::medianOn
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1561
openvdb::v4_0_2::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition: LeafNode.h:1029
openvdb::v4_0_2::tools::prune
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:361
openvdb::v4_0_2::tree::LeafNode::modifyValueAndActiveState
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:472
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v4_0_2::tree::LeafNode::origin
const Coord & origin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:198
openvdb::v4_0_2::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:426
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:568
openvdb::v4_0_2::math::CoordBBox::translate
void translate(const Coord &t)
Translate this bounding box by .
Definition: Coord.h:458
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildOff
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:703
openvdb::v4_0_2::tree::LeafNode::getNodeBoundingBox
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:192
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueOffCIter
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:667
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:682
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getChildDim
static Index getChildDim()
Definition: LeafNodeBool.h:136
openvdb::v4_0_2::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:308
openvdb::v4_0_2::tree::LeafNode::NUM_VALUES
static const Index NUM_VALUES
Definition: LeafNode.h:75
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::setValue
void setValue(bool value) const
Definition: LeafNodeBool.h:619
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::nonLeafCount
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:139
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueAll
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:695
openvdb::v4_0_2::tree::LeafNode::beginChildAll
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:346
openvdb::v4_0_2::tree::LeafNode::offsetToLocalCoord
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1059
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildOn
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:701
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getValueAndCache
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:353
openvdb::v4_0_2::tools::copyFromDense
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:592
openvdb::v4_0_2::tree::LeafNode::coordToOffset
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1049
openvdb::v4_0_2::util::NodeMask::save
void save(std::ostream &os) const
Definition: NodeMasks.h:565
openvdb::v4_0_2::math::CoordBBox::isInside
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:401
openvdb
Definition: Exceptions.h:39
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueAllIter
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeBool.h:668
openvdb::v4_0_2::math::Coord::setX
Coord & setX(Int32 x)
Definition: Coord.h:103
openvdb::v4_0_2::tree::LeafBuffer< ValueType, Log2Dim >
openvdb::v4_0_2::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:487
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeLeaf
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeBool.h:564
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
openvdb::v4_0_2::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1759
openvdb::v4_0_2::util::NodeMask::countOn
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:443
openvdb::v4_0_2::tree::LeafNode::topologyUnion
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:1717
openvdb::v4_0_2::math::CoordBBox::max
const Coord & max() const
Definition: Coord.h:335
openvdb::v4_0_2::util::OffMaskIterator
Definition: NodeMasks.h:239
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueOn
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:689
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::negate
void negate()
Definition: LeafNodeBool.h:461
openvdb::v4_0_2::CombineArgs::resultIsActive
bool resultIsActive() const
Definition: Types.h:435
openvdb::v4_0_2::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:371
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::ValueIter
ValueIter()
Definition: LeafNodeBool.h:610
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:713
openvdb::v4_0_2::math::CoordBBox::intersect
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:445
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNodeBool.h:184
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:684
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeBool.h:739
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:302
openvdb::v4_0_2::tree::LeafNode::visit2Node
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1920
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:678
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::onVoxelCount
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:142
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::onTileCount
static Index64 onTileCount()
Definition: LeafNodeBool.h:147
openvdb::v4_0_2::tree::LeafNode::LOG2DIM
static const Index LOG2DIM
Definition: LeafNode.h:72
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:677
openvdb::v4_0_2::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOff
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don&#39;t change its value.
Definition: LeafNodeBool.h:257
openvdb::v4_0_2::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:424
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginChildAll
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:706
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don&#39;t change their values.
Definition: LeafNodeBool.h:294
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:699
LeafNode.h
openvdb::v4_0_2::tree::LeafNode::SIZE
static const Index SIZE
Definition: LeafNode.h:77
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setActiveState
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: LeafNodeBool.h:249
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getValueMask
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:728
openvdb::v4_0_2::MERGE_ACTIVE_STATES_AND_NODES
Definition: Types.h:318
openvdb::v4_0_2::tree::LeafNode::modifyValue
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:455
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueOnIter
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeBool.h:664
openvdb::v4_0_2::math::CoordBBox::createCube
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:326
openvdb::v4_0_2::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1349
openvdb::v4_0_2::tree::LeafNode::probeValue
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1100
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeValueAndCache
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:409
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:722
openvdb::v4_0_2::tree::LeafNode::valueMask
const NodeMaskType & valueMask() const
Definition: LeafNode.h:888
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:729
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildAll
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:716
openvdb::v4_0_2::tree::LeafBuffer::fill
void fill(const ValueType &)
Populate this buffer with a constant value.
Definition: LeafBuffer.h:338
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildAllIter
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:674
openvdb::v4_0_2::util::NodeMask::countOff
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:450
openvdb::v4_0_2::math::Coord::x
Int32 x() const
Definition: Coord.h:154
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:391
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::mBuffer
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:756
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
openvdb::v4_0_2::util::OnMaskIterator
Definition: NodeMasks.h:208
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueOffIter
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeBool.h:666
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::setItem
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:617
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:146
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildOnCIter
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:671
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::getValue
const bool & getValue() const
Definition: LeafNodeBool.h:614
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::DenseIter::DenseIter
DenseIter()
Definition: LeafNodeBool.h:646
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueAll
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:685
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isDense
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:153
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOn
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:730
openvdb::v4_0_2::util::NodeMask::isConstant
bool isConstant(bool &isOn) const
Definition: NodeMasks.h:526
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::MaskDenseIter
typename NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:600
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueAndCache
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:363
openvdb::v4_0_2::tree::SameLeafConfig
Definition: PointDataGrid.h:192
Iterator.h
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getValueMask
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:726
openvdb::v4_0_2::util::NodeMask::set
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:462
openvdb::v4_0_2::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:503
openvdb::v4_0_2::tree::LeafNode::medianOff
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1585
openvdb::v4_0_2::tree::LeafNode::medianAll
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1543
openvdb::v4_0_2::math::Coord
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueMaskOn
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:735
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getNodes
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:550
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endChildOff
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:714
openvdb::v4_0_2::Int32
int32_t Int32
Definition: Types.h:59
openvdb::v4_0_2::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
openvdb::v4_0_2::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don&#39;t change its value.
Definition: LeafNode.h:437
NodeMasks.h
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::valueMask
const NodeMaskType & valueMask() const
Definition: LeafNodeBool.h:727
openvdb::v4_0_2::tree::LeafNode::topologyIntersection
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:1725
openvdb::v4_0_2::tools::copyToDense
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:445
openvdb::v4_0_2::tree::LeafNode::doVisit
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1906
openvdb::v4_0_2::tree::LeafNode::ChildAllCIter
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:315
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::buffer
Buffer & buffer()
Definition: LeafNodeBool.h:214
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v4_0_2::math::Coord::ValueType
Int32 ValueType
Definition: Coord.h:56
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:623
openvdb::v4_0_2::tree::LeafNode::copyToDense
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:1245
openvdb::v4_0_2::math::Coord::setY
Coord & setY(Int32 y)
Definition: Coord.h:104
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ChildIter::ChildIter
ChildIter()
Definition: LeafNodeBool.h:634
openvdb::v4_0_2::util::NodeMask::load
void load(std::istream &is)
Definition: NodeMasks.h:569
openvdb::v4_0_2::math::CoordBBox::min
const Coord & min() const
Definition: Coord.h:334
openvdb::v4_0_2::util::NodeMask::isOff
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:508
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isChildMaskOff
bool isChildMaskOff() const
Definition: LeafNodeBool.h:732
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::mValueMask
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:754
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOnly
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: LeafNodeBool.h:254
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::log2dim
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:129
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeNode
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:547
openvdb::v4_0_2::math::CoordBBox::reset
void reset()
Definition: Coord.h:340
openvdb::v4_0_2::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1481
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:702
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:53
openvdb::v4_0_2::util::NodeMask::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:457
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don&#39;t change its value.
Definition: LeafNodeBool.h:269
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::endValueOff
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:691
openvdb::v4_0_2::math::CoordBBox::hasOverlap
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:413
openvdb::v4_0_2::tree::LeafNode::doVisit2Node
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1945
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:683
openvdb::v4_0_2::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::denseFill
void denseFill(const CoordBBox &bbox, bool val, bool on=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNodeBool.h:310
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:135
openvdb::v4_0_2::tree::LeafNode::DIM
static const Index DIM
Definition: LeafNode.h:74
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::ValueType
bool ValueType
Definition: LeafNodeBool.h:58
openvdb::v4_0_2::tree::DenseIteratorBase::NonConstValueType
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:212
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::getFirstValue
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:422
openvdb::v4_0_2::tree::LeafBuffer::setValue
void setValue(Index i, const ValueType &)
Set the i&#39;th value of this buffer to the specified value.
Definition: LeafBuffer.h:289
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::cendChildOn
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:709
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueOff
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:681
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:299
openvdb::v4_0_2::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1612
openvdb::v4_0_2::OPENVDB_FILE_VERSION_BOOL_LEAF_OPTIMIZATION
Definition: version.h:104
openvdb::v4_0_2::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:206
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::beginValueOn
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:679
openvdb::v4_0_2::util::NodeMask::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:352
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff() const
Definition: LeafNodeBool.h:725
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:724
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:566
openvdb::v4_0_2::tree::LeafNode< bool, Log2Dim >::DenseIter::NonConstValueT
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:644
openvdb::v4_0_2::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1313