OpenVDB: LeafNode.h Source File

OpenVDB 3.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

LeafNode.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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_LEAFNODE_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
33
34 #include <iostream>
35 #include <algorithm> // for std::swap
36 #include <cstring> // for std::memcpy()
37 #include <boost/shared_ptr.hpp>
38 #include <boost/static_assert.hpp>
39 #include <boost/bind.hpp>
40 #include <tbb/blocked_range.h>
41 #include <tbb/spin_mutex.h>
42 #include <tbb/parallel_for.h>
43 #include <openvdb/Types.h>
44 #include <openvdb/util/NodeMasks.h>
45 #include <openvdb/io/Compression.h> // for io::readData(), etc.
46 #include "Iterator.h"
47
48
49 class TestLeaf;
50 template<typename> class TestLeafIO;
51
52 namespace openvdb {
53 OPENVDB_USE_VERSION_NAMESPACE
54 namespace OPENVDB_VERSION_NAME {
55 namespace tree {
56
57 template<Index, typename> struct SameLeafConfig; // forward declaration
58
59
64 template<typename T, Index Log2Dim>
65 class LeafNode
66 {
67 public:
68 typedef T ValueType;
69 typedef LeafNode<ValueType, Log2Dim> LeafNodeType;
70 typedef boost::shared_ptr<LeafNode> Ptr;
71 typedef util::NodeMask<Log2Dim> NodeMaskType;
72
73 static const Index
74 LOG2DIM = Log2Dim, // needed by parent nodes
75 TOTAL = Log2Dim, // needed by parent nodes
76 DIM = 1 << TOTAL, // dimension along one coordinate direction
77 NUM_VALUES = 1 << 3 * Log2Dim,
78 NUM_VOXELS = NUM_VALUES, // total number of voxels represented by this node
79 SIZE = NUM_VALUES,
80 LEVEL = 0; // level 0 = leaf
81
84 template<typename OtherValueType>
85 struct ValueConverter {
86 typedef LeafNode<OtherValueType, Log2Dim> Type;
87 };
88
91 template<typename OtherNodeType>
92 struct SameConfiguration {
93 static const bool value = SameLeafConfig<LOG2DIM, OtherNodeType>::value;
94 };
95
96 #ifndef OPENVDB_2_ABI_COMPATIBLE
97 struct FileInfo
98 {
99 FileInfo(): bufpos(0) , maskpos(0) {}
100 std::streamoff bufpos;
101 std::streamoff maskpos;
102 io::MappedFile::Ptr mapping;
103 boost::shared_ptr<io::StreamMetadata> meta;
104 };
105 #endif
106
109 class Buffer
110 {
111 public:
112 #ifdef OPENVDB_2_ABI_COMPATIBLE
113 Buffer(): mData(new ValueType[SIZE]) {}
116 explicit Buffer(const ValueType& val): mData(new ValueType[SIZE]) { this->fill(val); }
118 Buffer(const Buffer& other): mData(new ValueType[SIZE]) { *this = other; }
120 ~Buffer() { delete[] mData; }
121
123 bool isOutOfCore() const { return false; }
125 bool empty() const { return (mData == NULL); }
126 #else
127 typedef ValueType WordType;
128 static const Index WORD_COUNT = SIZE;
130 Buffer(): mData(new ValueType[SIZE]), mOutOfCore(0) {}
132 explicit Buffer(const ValueType& val): mData(new ValueType[SIZE]), mOutOfCore(0)
133 {
134 this->fill(val);
135 }
137 Buffer(const Buffer& other): mData(NULL), mOutOfCore(other.mOutOfCore)
138 {
139 if (other.isOutOfCore()) {
140 mFileInfo = new FileInfo(*other.mFileInfo);
141 } else {
142 this->allocate();
143 ValueType* target = mData;
144 const ValueType* source = other.mData;
145 Index n = SIZE;
146 while (n--) *target++ = *source++;
147 }
148 }
150 Buffer(PartialCreate, const ValueType&): mData(NULL), mOutOfCore(0) {}
152 ~Buffer()
153 {
154 if (this->isOutOfCore()) {
155 this->detachFromFile();
156 } else {
157 this->deallocate();
158 }
159 }
160
162 bool isOutOfCore() const { return bool(mOutOfCore); }
164 bool empty() const { return !mData || this->isOutOfCore(); }
165 #endif
166 bool allocate() { if (mData == NULL) mData = new ValueType[SIZE]; return !this->empty(); }
168
170 void fill(const ValueType& val)
171 {
172 this->detachFromFile();
173 if (mData != NULL) {
174 ValueType* target = mData;
175 Index n = SIZE;
176 while (n--) *target++ = val;
177 }
178 }
179
181 const ValueType& getValue(Index i) const { return this->at(i); }
183 const ValueType& operator[](Index i) const { return this->at(i); }
185 void setValue(Index i, const ValueType& val)
186 {
187 assert(i < SIZE);
188 #ifdef OPENVDB_2_ABI_COMPATIBLE
189 mData[i] = val;
190 #else
191 this->loadValues();
192 if (mData) mData[i] = val;
193 #endif
194 }
195
197 Buffer& operator=(const Buffer& other)
198 {
199 if (&other != this) {
200 #ifndef OPENVDB_2_ABI_COMPATIBLE
201 if (this->isOutOfCore()) {
202 this->detachFromFile();
203 } else {
204 if (other.isOutOfCore()) this->deallocate();
205 }
206 if (other.isOutOfCore()) {
207 mOutOfCore = other.mOutOfCore;
208 mFileInfo = new FileInfo(*other.mFileInfo);
209 } else {
210 #endif
211 this->allocate();
212 ValueType* target = mData;
213 const ValueType* source = other.mData;
214 Index n = SIZE;
215 while (n--) *target++ = *source++;
216 #ifndef OPENVDB_2_ABI_COMPATIBLE
217 }
218 #endif
219 }
220 return *this;
221 }
222
225 bool operator==(const Buffer& other) const
226 {
227 this->loadValues();
228 other.loadValues();
229 const ValueType *target = mData, *source = other.mData;
230 if (!target && !source) return true;
231 if (!target || !source) return false;
232 Index n = SIZE;
233 while (n && math::isExactlyEqual(*target++, *source++)) --n;
234 return n == 0;
235 }
238 bool operator!=(const Buffer& other) const { return !(other == *this); }
239
241 void swap(Buffer& other)
242 {
243 std::swap(mData, other.mData);
244 #ifndef OPENVDB_2_ABI_COMPATIBLE
245 std::swap(mOutOfCore, other.mOutOfCore);
246 #endif
247 }
248
250 Index memUsage() const
251 {
252 size_t n = sizeof(*this);
253 #ifdef OPENVDB_2_ABI_COMPATIBLE
254 if (mData) n += SIZE * sizeof(ValueType);
255 #else
256 if (this->isOutOfCore()) n += sizeof(FileInfo);
257 else if (mData) n += SIZE * sizeof(ValueType);
258 #endif
259 return static_cast<Index>(n);
260 }
262 static Index size() { return SIZE; }
263
267 const ValueType* data() const
268 {
269 #ifndef OPENVDB_2_ABI_COMPATIBLE
270 this->loadValues();
271 if (mData == NULL) {
272
273 Buffer* self = const_cast<Buffer*>(this);
274
275 // Since this method is const we need a lock (which
276 // will be contended at most once) to make it thread-safe.
277 tbb::spin_mutex::scoped_lock lock(self->mMutex);
278 if (mData == NULL) self->mData = new ValueType[SIZE];
279 }
280 #endif
281 return mData;
282 }
283
287 ValueType* data()
288 {
289 #ifndef OPENVDB_2_ABI_COMPATIBLE
290 this->loadValues();
291 if (mData == NULL) mData = new ValueType[SIZE];
292 #endif
293 return mData;
294 }
295
296 private:
298 const ValueType& at(Index i) const
299 {
300 assert(i < SIZE);
301 #ifdef OPENVDB_2_ABI_COMPATIBLE
302 return mData[i];
303 #else
304 this->loadValues();
305 // We can't use the ternary operator here, otherwise Visual C++ returns
306 // a reference to a temporary.
307 if (mData) return mData[i]; else return sZero;
308 #endif
309 }
310
316 ValueType& operator[](Index i) { return const_cast<ValueType&>(this->at(i)); }
317
318 bool deallocate()
319 {
320 if (mData != NULL && !this->isOutOfCore()) {
321 delete[] mData;
322 mData = NULL;
323 return true;
324 }
325 return false;
326 }
327
328 #ifdef OPENVDB_2_ABI_COMPATIBLE
329 void setOutOfCore(bool) {}
330 void loadValues() const {}
331 void doLoad() const {}
332 bool detachFromFile() { return false; }
333 #else
334 inline void setOutOfCore(bool b) { mOutOfCore = b; }
335 // To facilitate inlining in the common case in which the buffer is in-core,
336 // the loading logic is split into a separate function, doLoad().
337 inline void loadValues() const { if (this->isOutOfCore()) this->doLoad(); }
338 inline void doLoad() const;
339 inline bool detachFromFile()
340 {
341 if (this->isOutOfCore()) {
342 delete mFileInfo;
343 mFileInfo = NULL;
344 this->setOutOfCore(false);
345 return true;
346 }
347 return false;
348 }
349 #endif
350
351 friend class ::TestLeaf;
352 // Allow the parent LeafNode to access this buffer's data pointer.
353 friend class LeafNode;
354
355 #ifdef OPENVDB_2_ABI_COMPATIBLE
356 ValueType* mData;
357 #else
358 union {
359 ValueType* mData;
360 FileInfo* mFileInfo;
361 };
362 Index32 mOutOfCore; // currently interpreted as bool; extra bits reserved for future use
363 tbb::spin_mutex mMutex; // 1 byte
364 //int8_t mReserved[3]; // padding for alignment
365
366 static const ValueType sZero;
367 #endif
368 }; // class Buffer
369
370
372 LeafNode();
373
378 explicit LeafNode(const Coord& coords,
379 const ValueType& value = zeroVal<ValueType>(),
380 bool active = false);
381
382
383 #ifndef OPENVDB_2_ABI_COMPATIBLE
384 LeafNode(PartialCreate,
390 const Coord& coords,
391 const ValueType& value = zeroVal<ValueType>(),
392 bool active = false);
393 #endif
394
396 LeafNode(const LeafNode&);
397
399 template<typename OtherValueType>
400 explicit LeafNode(const LeafNode<OtherValueType, Log2Dim>& other);
401
403 template<typename OtherValueType>
404 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
405 const ValueType& offValue, const ValueType& onValue, TopologyCopy);
406
408 template<typename OtherValueType>
409 LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
410 const ValueType& background, TopologyCopy);
411
413 ~LeafNode();
414
415 //
416 // Statistics
417 //
419 static Index log2dim() { return Log2Dim; }
421 static Index dim() { return DIM; }
423 static Index size() { return SIZE; }
425 static Index numValues() { return SIZE; }
427 static Index getLevel() { return LEVEL; }
429 static void getNodeLog2Dims(std::vector<Index>& dims) { dims.push_back(Log2Dim); }
431 static Index getChildDim() { return 1; }
433 static Index32 leafCount() { return 1; }
435 static Index32 nonLeafCount() { return 0; }
436
438 Index64 onVoxelCount() const { return mValueMask.countOn(); }
440 Index64 offVoxelCount() const { return mValueMask.countOff(); }
441 Index64 onLeafVoxelCount() const { return onVoxelCount(); }
442 Index64 offLeafVoxelCount() const { return offVoxelCount(); }
443 static Index64 onTileCount() { return 0; }
444 static Index64 offTileCount() { return 0; }
446 bool isEmpty() const { return mValueMask.isOff(); }
448 bool isDense() const { return mValueMask.isOn(); }
449
450 #ifndef OPENVDB_2_ABI_COMPATIBLE
451 bool isAllocated() const { return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
454 bool allocate() { return mBuffer.allocate(); }
455 #endif
456
458 Index64 memUsage() const;
459
463 void evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels = true) const;
464
467 CoordBBox getNodeBoundingBox() const { return CoordBBox::createCube(mOrigin, DIM); }
468
470 void setOrigin(const Coord& origin) { mOrigin = origin; }
472 const Coord& origin() const { return mOrigin; }
474 void getOrigin(Coord& origin) const { origin = mOrigin; }
475 void getOrigin(Int32& x, Int32& y, Int32& z) const { mOrigin.asXYZ(x, y, z); }
477
479 static Index coordToOffset(const Coord& xyz);
482 static Coord offsetToLocalCoord(Index n);
484 Coord offsetToGlobalCoord(Index n) const;
485
487 std::string str() const;
488
491 template<typename OtherType, Index OtherLog2Dim>
492 bool hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const;
493
495 bool operator==(const LeafNode& other) const;
496 bool operator!=(const LeafNode& other) const { return !(other == *this); }
497
498 protected:
499 typedef typename NodeMaskType::OnIterator MaskOnIterator;
500 typedef typename NodeMaskType::OffIterator MaskOffIterator;
501 typedef typename NodeMaskType::DenseIterator MaskDenseIterator;
502
503 // Type tags to disambiguate template instantiations
504 struct ValueOn {}; struct ValueOff {}; struct ValueAll {};
505 struct ChildOn {}; struct ChildOff {}; struct ChildAll {};
506
507 template<typename MaskIterT, typename NodeT, typename ValueT, typename TagT>
508 struct ValueIter:
509 // Derives from SparseIteratorBase, but can also be used as a dense iterator,
510 // if MaskIterT is a dense mask iterator type.
511 public SparseIteratorBase<
512 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
513 {
514 typedef SparseIteratorBase<MaskIterT, ValueIter, NodeT, ValueT> BaseT;
515
516 ValueIter() {}
517 ValueIter(const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
518
519 ValueT& getItem(Index pos) const { return this->parent().getValue(pos); }
520 ValueT& getValue() const { return this->parent().getValue(this->pos()); }
521
522 // Note: setItem() can't be called on const iterators.
523 void setItem(Index pos, const ValueT& value) const
524 {
525 this->parent().setValueOnly(pos, value);
526 }
527 // Note: setValue() can't be called on const iterators.
528 void setValue(const ValueT& value) const
529 {
530 this->parent().setValueOnly(this->pos(), value);
531 }
532
533 // Note: modifyItem() can't be called on const iterators.
534 template<typename ModifyOp>
535 void modifyItem(Index n, const ModifyOp& op) const { this->parent().modifyValue(n, op); }
536 // Note: modifyValue() can't be called on const iterators.
537 template<typename ModifyOp>
538 void modifyValue(const ModifyOp& op) const { this->parent().modifyValue(this->pos(), op); }
539 };
540
542 template<typename MaskIterT, typename NodeT, typename TagT>
543 struct ChildIter:
544 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
545 {
546 ChildIter() {}
547 ChildIter(const MaskIterT& iter, NodeT* parent): SparseIteratorBase<
548 MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>(iter, parent) {}
549 };
550
551 template<typename NodeT, typename ValueT, typename TagT>
552 struct DenseIter: public DenseIteratorBase<
553 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, /*ChildT=*/void, ValueT>
554 {
555 typedef DenseIteratorBase<MaskDenseIterator, DenseIter, NodeT, void, ValueT> BaseT;
556 typedef typename BaseT::NonConstValueType NonConstValueT;
557
558 DenseIter() {}
559 DenseIter(const MaskDenseIterator& iter, NodeT* parent): BaseT(iter, parent) {}
560
561 bool getItem(Index pos, void*& child, NonConstValueT& value) const
562 {
563 value = this->parent().getValue(pos);
564 child = NULL;
565 return false; // no child
566 }
567
568 // Note: setItem() can't be called on const iterators.
569 //void setItem(Index pos, void* child) const {}
570
571 // Note: unsetItem() can't be called on const iterators.
572 void unsetItem(Index pos, const ValueT& value) const
573 {
574 this->parent().setValueOnly(pos, value);
575 }
576 };
577
578 public:
579 typedef ValueIter<MaskOnIterator, LeafNode, const ValueType, ValueOn> ValueOnIter;
580 typedef ValueIter<MaskOnIterator, const LeafNode, const ValueType, ValueOn> ValueOnCIter;
581 typedef ValueIter<MaskOffIterator, LeafNode, const ValueType, ValueOff> ValueOffIter;
582 typedef ValueIter<MaskOffIterator,const LeafNode,const ValueType,ValueOff> ValueOffCIter;
583 typedef ValueIter<MaskDenseIterator, LeafNode, const ValueType, ValueAll> ValueAllIter;
584 typedef ValueIter<MaskDenseIterator,const LeafNode,const ValueType,ValueAll> ValueAllCIter;
585 typedef ChildIter<MaskOnIterator, LeafNode, ChildOn> ChildOnIter;
586 typedef ChildIter<MaskOnIterator, const LeafNode, ChildOn> ChildOnCIter;
587 typedef ChildIter<MaskOffIterator, LeafNode, ChildOff> ChildOffIter;
588 typedef ChildIter<MaskOffIterator, const LeafNode, ChildOff> ChildOffCIter;
589 typedef DenseIter<LeafNode, ValueType, ChildAll> ChildAllIter;
590 typedef DenseIter<const LeafNode, const ValueType, ChildAll> ChildAllCIter;
591
592 ValueOnCIter cbeginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
593 ValueOnCIter beginValueOn() const { return ValueOnCIter(mValueMask.beginOn(), this); }
594 ValueOnIter beginValueOn() { return ValueOnIter(mValueMask.beginOn(), this); }
595 ValueOffCIter cbeginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
596 ValueOffCIter beginValueOff() const { return ValueOffCIter(mValueMask.beginOff(), this); }
597 ValueOffIter beginValueOff() { return ValueOffIter(mValueMask.beginOff(), this); }
598 ValueAllCIter cbeginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
599 ValueAllCIter beginValueAll() const { return ValueAllCIter(mValueMask.beginDense(), this); }
600 ValueAllIter beginValueAll() { return ValueAllIter(mValueMask.beginDense(), this); }
601
602 ValueOnCIter cendValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
603 ValueOnCIter endValueOn() const { return ValueOnCIter(mValueMask.endOn(), this); }
604 ValueOnIter endValueOn() { return ValueOnIter(mValueMask.endOn(), this); }
605 ValueOffCIter cendValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
606 ValueOffCIter endValueOff() const { return ValueOffCIter(mValueMask.endOff(), this); }
607 ValueOffIter endValueOff() { return ValueOffIter(mValueMask.endOff(), this); }
608 ValueAllCIter cendValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
609 ValueAllCIter endValueAll() const { return ValueAllCIter(mValueMask.endDense(), this); }
610 ValueAllIter endValueAll() { return ValueAllIter(mValueMask.endDense(), this); }
611
612 // Note that [c]beginChildOn() and [c]beginChildOff() actually return end iterators,
613 // because leaf nodes have no children.
614 ChildOnCIter cbeginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
615 ChildOnCIter beginChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
616 ChildOnIter beginChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
617 ChildOffCIter cbeginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
618 ChildOffCIter beginChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
619 ChildOffIter beginChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
620 ChildAllCIter cbeginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
621 ChildAllCIter beginChildAll() const { return ChildAllCIter(mValueMask.beginDense(), this); }
622 ChildAllIter beginChildAll() { return ChildAllIter(mValueMask.beginDense(), this); }
623
624 ChildOnCIter cendChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
625 ChildOnCIter endChildOn() const { return ChildOnCIter(mValueMask.endOn(), this); }
626 ChildOnIter endChildOn() { return ChildOnIter(mValueMask.endOn(), this); }
627 ChildOffCIter cendChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
628 ChildOffCIter endChildOff() const { return ChildOffCIter(mValueMask.endOff(), this); }
629 ChildOffIter endChildOff() { return ChildOffIter(mValueMask.endOff(), this); }
630 ChildAllCIter cendChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
631 ChildAllCIter endChildAll() const { return ChildAllCIter(mValueMask.endDense(), this); }
632 ChildAllIter endChildAll() { return ChildAllIter(mValueMask.endDense(), this); }
633
634 //
635 // Buffer management
636 //
639 void swap(Buffer& other) { mBuffer.swap(other); }
640 const Buffer& buffer() const { return mBuffer; }
641 Buffer& buffer() { return mBuffer; }
642
643 //
644 // I/O methods
645 //
649 void readTopology(std::istream& is, bool fromHalf = false);
653 void writeTopology(std::ostream& os, bool toHalf = false) const;
654
658 void readBuffers(std::istream& is, bool fromHalf = false);
663 void readBuffers(std::istream& is, const CoordBBox& bbox, bool fromHalf = false);
667 void writeBuffers(std::ostream& os, bool toHalf = false) const;
668
669 size_t streamingSize(bool toHalf = false) const;
670
671 //
672 // Accessor methods
673 //
675 const ValueType& getValue(const Coord& xyz) const;
677 const ValueType& getValue(Index offset) const;
678
682 bool probeValue(const Coord& xyz, ValueType& val) const;
686 bool probeValue(Index offset, ValueType& val) const;
687
689 static Index getValueLevel(const Coord&) { return LEVEL; }
690
692 void setActiveState(const Coord& xyz, bool on);
694 void setActiveState(Index offset, bool on) { assert(offset<SIZE); mValueMask.set(offset, on); }
695
697 void setValueOnly(const Coord& xyz, const ValueType& val);
699 void setValueOnly(Index offset, const ValueType& val);
700
702 void setValueOff(const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
704 void setValueOff(Index offset) { assert(offset < SIZE); mValueMask.setOff(offset); }
705
707 void setValueOff(const Coord& xyz, const ValueType& val);
709 void setValueOff(Index offset, const ValueType& val);
710
712 void setValueOn(const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
714 void setValueOn(Index offset) { assert(offset < SIZE); mValueMask.setOn(offset); }
716 void setValueOn(const Coord& xyz, const ValueType& val) {
717 this->setValueOn(LeafNode::coordToOffset(xyz), val);
718 }
720 void setValue(const Coord& xyz, const ValueType& val) { this->setValueOn(xyz, val); }
722 void setValueOn(Index offset, const ValueType& val) {
723 mBuffer.setValue(offset, val);
724 mValueMask.setOn(offset);
725 }
726
729 template<typename ModifyOp>
730 void modifyValue(Index offset, const ModifyOp& op)
731 {
732 ValueType val = mBuffer[offset];
733 op(val);
734 mBuffer.setValue(offset, val);
735 mValueMask.setOn(offset);
736 }
739 template<typename ModifyOp>
740 void modifyValue(const Coord& xyz, const ModifyOp& op)
741 {
742 this->modifyValue(this->coordToOffset(xyz), op);
743 }
744
746 template<typename ModifyOp>
747 void modifyValueAndActiveState(const Coord& xyz, const ModifyOp& op)
748 {
749 const Index offset = this->coordToOffset(xyz);
750 bool state = mValueMask.isOn(offset);
751 ValueType val = mBuffer[offset];
752 op(val, state);
753 mBuffer.setValue(offset, val);
754 mValueMask.set(offset, state);
755 }
756
758 void setValuesOn() { mValueMask.setOn(); }
760 void setValuesOff() { mValueMask.setOff(); }
761
763 bool isValueOn(const Coord& xyz) const {return this->isValueOn(LeafNode::coordToOffset(xyz));}
765 bool isValueOn(Index offset) const { return mValueMask.isOn(offset); }
766
768 static bool hasActiveTiles() { return false; }
769
771 void clip(const CoordBBox&, const ValueType& background);
772
774 void fill(const CoordBBox& bbox, const ValueType&, bool active = true);
775
777 void fill(const ValueType& value);
779 void fill(const ValueType& value, bool active);
780
792 template<typename DenseT>
793 void copyToDense(const CoordBBox& bbox, DenseT& dense) const;
794
811 template<typename DenseT>
812 void copyFromDense(const CoordBBox& bbox, const DenseT& dense,
813 const ValueType& background, const ValueType& tolerance);
814
817 template<typename AccessorT>
818 const ValueType& getValueAndCache(const Coord& xyz, AccessorT&) const
819 {
820 return this->getValue(xyz);
821 }
822
825 template<typename AccessorT>
826 bool isValueOnAndCache(const Coord& xyz, AccessorT&) const { return this->isValueOn(xyz); }
827
830 template<typename AccessorT>
831 void setValueAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
832 {
833 this->setValueOn(xyz, val);
834 }
835
839 template<typename AccessorT>
840 void setValueOnlyAndCache(const Coord& xyz, const ValueType& val, AccessorT&)
841 {
842 this->setValueOnly(xyz, val);
843 }
844
848 template<typename ModifyOp, typename AccessorT>
849 void modifyValueAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
850 {
851 this->modifyValue(xyz, op);
852 }
853
856 template<typename ModifyOp, typename AccessorT>
857 void modifyValueAndActiveStateAndCache(const Coord& xyz, const ModifyOp& op, AccessorT&)
858 {
859 this->modifyValueAndActiveState(xyz, op);
860 }
861
864 template<typename AccessorT>
865 void setValueOffAndCache(const Coord& xyz, const ValueType& value, AccessorT&)
866 {
867 this->setValueOff(xyz, value);
868 }
869
873 template<typename AccessorT>
874 void setActiveStateAndCache(const Coord& xyz, bool on, AccessorT&)
875 {
876 this->setActiveState(xyz, on);
877 }
878
882 template<typename AccessorT>
883 bool probeValueAndCache(const Coord& xyz, ValueType& val, AccessorT&) const
884 {
885 return this->probeValue(xyz, val);
886 }
887
891 template<typename AccessorT>
892 const ValueType& getValue(const Coord& xyz, bool& state, int& level, AccessorT&) const
893 {
894 const Index offset = this->coordToOffset(xyz);
895 state = mValueMask.isOn(offset);
896 level = LEVEL;
897 return mBuffer[offset];
898 }
899
902 template<typename AccessorT>
903 static Index getValueLevelAndCache(const Coord&, AccessorT&) { return LEVEL; }
904
908 const ValueType& getFirstValue() const { return mBuffer[0]; }
910 const ValueType& getLastValue() const { return mBuffer[SIZE - 1]; }
911
914 void resetBackground(const ValueType& oldBackground, const ValueType& newBackground);
915
916 void negate();
917
918 void voxelizeActiveTiles() {}
919
920 template<MergePolicy Policy> void merge(const LeafNode&);
921 template<MergePolicy Policy> void merge(const ValueType& tileValue, bool tileActive);
922 template<MergePolicy Policy>
923 void merge(const LeafNode& other, const ValueType& /*bg*/, const ValueType& /*otherBG*/);
924
931 template<typename OtherType>
932 void topologyUnion(const LeafNode<OtherType, Log2Dim>& other);
933
945 template<typename OtherType>
946 void topologyIntersection(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
947
959 template<typename OtherType>
960 void topologyDifference(const LeafNode<OtherType, Log2Dim>& other, const ValueType&);
961
962 template<typename CombineOp>
963 void combine(const LeafNode& other, CombineOp& op);
964 template<typename CombineOp>
965 void combine(const ValueType& value, bool valueIsActive, CombineOp& op);
966
967 template<typename CombineOp, typename OtherType /*= ValueType*/>
968 void combine2(const LeafNode& other, const OtherType&, bool valueIsActive, CombineOp&);
969 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
970 void combine2(const ValueType&, const OtherNodeT& other, bool valueIsActive, CombineOp&);
971 template<typename CombineOp, typename OtherNodeT /*= LeafNode*/>
972 void combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp&);
973
979 template<typename BBoxOp> void visitActiveBBox(BBoxOp&) const;
980
981 template<typename VisitorOp> void visit(VisitorOp&);
982 template<typename VisitorOp> void visit(VisitorOp&) const;
983
984 template<typename OtherLeafNodeType, typename VisitorOp>
985 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
986 template<typename OtherLeafNodeType, typename VisitorOp>
987 void visit2Node(OtherLeafNodeType& other, VisitorOp&) const;
988 template<typename IterT, typename VisitorOp>
989 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false);
990 template<typename IterT, typename VisitorOp>
991 void visit2(IterT& otherIter, VisitorOp&, bool otherIsLHS = false) const;
992
994 void prune(const ValueType& /*tolerance*/ = zeroVal<ValueType>()) {}
996 void addLeaf(LeafNode*) {}
997 template<typename AccessorT>
998 void addLeafAndCache(LeafNode*, AccessorT&) {}
999 template<typename NodeT>
1000 NodeT* stealNode(const Coord&, const ValueType&, bool) { return NULL; }
1001 template<typename NodeT>
1002 NodeT* probeNode(const Coord&) { return NULL; }
1003 template<typename NodeT>
1004 const NodeT* probeConstNode(const Coord&) const { return NULL; }
1005 template<typename ArrayT> void getNodes(ArrayT&) const {}
1006 template<typename ArrayT> void stealNodes(ArrayT&, const ValueType&, bool) {}
1008
1009 void addTile(Index level, const Coord&, const ValueType&, bool);
1010 void addTile(Index offset, const ValueType&, bool);
1011 template<typename AccessorT>
1012 void addTileAndCache(Index, const Coord&, const ValueType&, bool, AccessorT&);
1013
1015 LeafNode* touchLeaf(const Coord&) { return this; }
1017 template<typename AccessorT>
1018 LeafNode* touchLeafAndCache(const Coord&, AccessorT&) { return this; }
1019 template<typename NodeT, typename AccessorT>
1020 NodeT* probeNodeAndCache(const Coord&, AccessorT&)
1021 {
1022 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1023 if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
1024 return reinterpret_cast<NodeT*>(this);
1025 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1026 }
1027 LeafNode* probeLeaf(const Coord&) { return this; }
1028 template<typename AccessorT>
1029 LeafNode* probeLeafAndCache(const Coord&, AccessorT&) { return this; }
1031
1032 const LeafNode* probeConstLeaf(const Coord&) const { return this; }
1034 template<typename AccessorT>
1035 const LeafNode* probeConstLeafAndCache(const Coord&, AccessorT&) const { return this; }
1036 template<typename AccessorT>
1037 const LeafNode* probeLeafAndCache(const Coord&, AccessorT&) const { return this; }
1038 const LeafNode* probeLeaf(const Coord&) const { return this; }
1039 template<typename NodeT, typename AccessorT>
1040 const NodeT* probeConstNodeAndCache(const Coord&, AccessorT&) const
1041 {
1042 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1043 if (!(boost::is_same<NodeT,LeafNode>::value)) return NULL;
1044 return reinterpret_cast<const NodeT*>(this);
1045 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1046 }
1048
1058 bool isConstant(ValueType& constValue, bool& state,
1059 const ValueType& tolerance = zeroVal<ValueType>()) const;
1060
1072 bool isConstant(ValueType& minValue, ValueType& maxValue,
1073 bool& state, const ValueType& tolerance = zeroVal<ValueType>()) const;
1074
1076 bool isInactive() const { return mValueMask.isOff(); }
1077
1078 protected:
1079 friend class ::TestLeaf;
1080 template<typename> friend class ::TestLeafIO;
1081
1082 // During topology-only construction, access is needed
1083 // to protected/private members of other template instances.
1084 template<typename, Index> friend class LeafNode;
1085
1086 friend struct ValueIter<MaskOnIterator, LeafNode, ValueType, ValueOn>;
1087 friend struct ValueIter<MaskOffIterator, LeafNode, ValueType, ValueOff>;
1088 friend struct ValueIter<MaskDenseIterator, LeafNode, ValueType, ValueAll>;
1089 friend struct ValueIter<MaskOnIterator, const LeafNode, ValueType, ValueOn>;
1090 friend struct ValueIter<MaskOffIterator, const LeafNode, ValueType, ValueOff>;
1091 friend struct ValueIter<MaskDenseIterator, const LeafNode, ValueType, ValueAll>;
1092
1093 // Allow iterators to call mask accessor methods (see below).
1095 friend class IteratorBase<MaskOnIterator, LeafNode>;
1096 friend class IteratorBase<MaskOffIterator, LeafNode>;
1097 friend class IteratorBase<MaskDenseIterator, LeafNode>;
1098
1099 // Mask accessors
1100 public:
1101 bool isValueMaskOn(Index n) const { return mValueMask.isOn(n); }
1102 bool isValueMaskOn() const { return mValueMask.isOn(); }
1103 bool isValueMaskOff(Index n) const { return mValueMask.isOff(n); }
1104 bool isValueMaskOff() const { return mValueMask.isOff(); }
1105 const NodeMaskType& getValueMask() const { return mValueMask; }
1106 NodeMaskType& getValueMask() { return mValueMask; }
1107 void setValueMask(const NodeMaskType& mask) { mValueMask = mask; }
1108 bool isChildMaskOn(Index) const { return false; } // leaf nodes have no children
1109 bool isChildMaskOff(Index) const { return true; }
1110 bool isChildMaskOff() const { return true; }
1111 protected:
1112 void setValueMask(Index n, bool on) { mValueMask.set(n, on); }
1113 void setValueMaskOn(Index n) { mValueMask.setOn(n); }
1114 void setValueMaskOff(Index n) { mValueMask.setOff(n); }
1115
1117 static void evalNodeOrigin(Coord& xyz) { xyz &= ~(DIM - 1); }
1118
1119 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
1120 static inline void doVisit(NodeT&, VisitorOp&);
1121
1122 template<typename NodeT, typename OtherNodeT, typename VisitorOp,
1123 typename ChildAllIterT, typename OtherChildAllIterT>
1124 static inline void doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp&);
1125
1126 template<typename NodeT, typename VisitorOp,
1127 typename ChildAllIterT, typename OtherChildAllIterT>
1128 static inline void doVisit2(NodeT& self, OtherChildAllIterT&, VisitorOp&, bool otherIsLHS);
1129
1130 private:
1132 Buffer mBuffer;
1134 NodeMaskType mValueMask;
1136 Coord mOrigin;
1137 }; // end of LeafNode class
1138
1139
1140 #ifndef OPENVDB_2_ABI_COMPATIBLE
1141 template<typename T, Index Log2Dim>
1142 const T LeafNode<T, Log2Dim>::Buffer::sZero = zeroVal<T>();
1143 #endif
1144
1145
1147
1148
1150 template<Index Dim1, typename NodeT2>
1153 struct SameLeafConfig { static const bool value = false; };
1154
1155 template<Index Dim1, typename T2>
1156 struct SameLeafConfig<Dim1, LeafNode<T2, Dim1> > { static const bool value = true; };
1158
1159
1161
1162
1163 template<typename T, Index Log2Dim>
1164 inline
1165 LeafNode<T, Log2Dim>::LeafNode():
1166 mValueMask(),//default is off!
1167 mOrigin(0, 0, 0)
1168 {
1169 }
1170
1171
1172 template<typename T, Index Log2Dim>
1173 inline
1174 LeafNode<T, Log2Dim>::LeafNode(const Coord& xyz, const ValueType& val, bool active):
1175 mBuffer(val),
1176 mValueMask(active),
1177 mOrigin(xyz & (~(DIM - 1)))
1178 {
1179 }
1180
1181
1182 #ifndef OPENVDB_2_ABI_COMPATIBLE
1183 template<typename T, Index Log2Dim>
1184 inline
1185 LeafNode<T, Log2Dim>::LeafNode(PartialCreate, const Coord& xyz, const ValueType& val, bool active):
1186 mBuffer(PartialCreate(), val),
1187 mValueMask(active),
1188 mOrigin(xyz & (~(DIM - 1)))
1189 {
1190 }
1191 #endif
1192
1193
1194 template<typename T, Index Log2Dim>
1195 inline
1196 LeafNode<T, Log2Dim>::LeafNode(const LeafNode &other):
1197 mBuffer(other.mBuffer),
1198 mValueMask(other.mValueMask),
1199 mOrigin(other.mOrigin)
1200 {
1201 }
1202
1203
1204 // Copy-construct from a leaf node with the same configuration but a different ValueType.
1205 template<typename T, Index Log2Dim>
1206 template<typename OtherValueType>
1207 inline
1208 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other):
1209 mValueMask(other.mValueMask),
1210 mOrigin(other.mOrigin)
1211 {
1212 struct Local {
1214 static inline ValueType convertValue(const OtherValueType& val) { return ValueType(val); }
1215 };
1216
1217 for (Index i = 0; i < SIZE; ++i) {
1218 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
1219 }
1220 }
1221
1222
1223 template<typename T, Index Log2Dim>
1224 template<typename OtherValueType>
1225 inline
1226 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
1227 const ValueType& background, TopologyCopy):
1228 mBuffer(background),
1229 mValueMask(other.mValueMask),
1230 mOrigin(other.mOrigin)
1231 {
1232 }
1233
1234
1235 template<typename T, Index Log2Dim>
1236 template<typename OtherValueType>
1237 inline
1238 LeafNode<T, Log2Dim>::LeafNode(const LeafNode<OtherValueType, Log2Dim>& other,
1239 const ValueType& offValue, const ValueType& onValue, TopologyCopy):
1240 mValueMask(other.mValueMask),
1241 mOrigin(other.mOrigin)
1242 {
1243 for (Index i = 0; i < SIZE; ++i) {
1244 mBuffer[i] = (mValueMask.isOn(i) ? onValue : offValue);
1245 }
1246 }
1247
1248
1249 template<typename T, Index Log2Dim>
1250 inline
1251 LeafNode<T, Log2Dim>::~LeafNode()
1252 {
1253 }
1254
1255
1256 template<typename T, Index Log2Dim>
1257 inline std::string
1258 LeafNode<T, Log2Dim>::str() const
1259 {
1260 std::ostringstream ostr;
1261 ostr << "LeafNode @" << mOrigin << ": " << mBuffer;
1262 return ostr.str();
1263 }
1264
1265
1267
1268
1269 template<typename T, Index Log2Dim>
1270 inline Index
1271 LeafNode<T, Log2Dim>::coordToOffset(const Coord& xyz)
1272 {
1273 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1274 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1275 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1276 + (xyz[2] & (DIM-1u));
1277 }
1278
1279 template<typename T, Index Log2Dim>
1280 inline Coord
1281 LeafNode<T, Log2Dim>::offsetToLocalCoord(Index n)
1282 {
1283 assert(n<(1<< 3*Log2Dim));
1284 Coord xyz;
1285 xyz.setX(n >> 2*Log2Dim);
1286 n &= ((1<<2*Log2Dim)-1);
1287 xyz.setY(n >> Log2Dim);
1288 xyz.setZ(n & ((1<<Log2Dim)-1));
1289 return xyz;
1290 }
1291
1292
1293 template<typename T, Index Log2Dim>
1294 inline Coord
1295 LeafNode<T, Log2Dim>::offsetToGlobalCoord(Index n) const
1296 {
1297 return (this->offsetToLocalCoord(n) + this->origin());
1298 }
1299
1300
1302
1303
1304 template<typename ValueT, Index Log2Dim>
1305 inline const ValueT&
1306 LeafNode<ValueT, Log2Dim>::getValue(const Coord& xyz) const
1307 {
1308 return this->getValue(LeafNode::coordToOffset(xyz));
1309 }
1310
1311 template<typename ValueT, Index Log2Dim>
1312 inline const ValueT&
1313 LeafNode<ValueT, Log2Dim>::getValue(Index offset) const
1314 {
1315 assert(offset < SIZE);
1316 return mBuffer[offset];
1317 }
1318
1319
1320 template<typename T, Index Log2Dim>
1321 inline bool
1322 LeafNode<T, Log2Dim>::probeValue(const Coord& xyz, ValueType& val) const
1323 {
1324 return this->probeValue(LeafNode::coordToOffset(xyz), val);
1325 }
1326
1327 template<typename T, Index Log2Dim>
1328 inline bool
1329 LeafNode<T, Log2Dim>::probeValue(Index offset, ValueType& val) const
1330 {
1331 assert(offset < SIZE);
1332 val = mBuffer[offset];
1333 return mValueMask.isOn(offset);
1334 }
1335
1336
1337 template<typename T, Index Log2Dim>
1338 inline void
1339 LeafNode<T, Log2Dim>::setValueOff(const Coord& xyz, const ValueType& val)
1340 {
1341 this->setValueOff(LeafNode::coordToOffset(xyz), val);
1342 }
1343
1344 template<typename T, Index Log2Dim>
1345 inline void
1346 LeafNode<T, Log2Dim>::setValueOff(Index offset, const ValueType& val)
1347 {
1348 assert(offset < SIZE);
1349 mBuffer.setValue(offset, val);
1350 mValueMask.setOff(offset);
1351 }
1352
1353
1354 template<typename T, Index Log2Dim>
1355 inline void
1356 LeafNode<T, Log2Dim>::setActiveState(const Coord& xyz, bool on)
1357 {
1358 mValueMask.set(this->coordToOffset(xyz), on);
1359 }
1360
1361
1362 template<typename T, Index Log2Dim>
1363 inline void
1364 LeafNode<T, Log2Dim>::setValueOnly(const Coord& xyz, const ValueType& val)
1365 {
1366 this->setValueOnly(LeafNode::coordToOffset(xyz), val);
1367 }
1368
1369 template<typename T, Index Log2Dim>
1370 inline void
1371 LeafNode<T, Log2Dim>::setValueOnly(Index offset, const ValueType& val)
1372 {
1373 assert(offset<SIZE); mBuffer.setValue(offset, val);
1374 }
1375
1376
1378
1379
1380 template<typename T, Index Log2Dim>
1381 inline void
1382 LeafNode<T, Log2Dim>::clip(const CoordBBox& clipBBox, const T& background)
1383 {
1384 CoordBBox nodeBBox = this->getNodeBoundingBox();
1385 if (!clipBBox.hasOverlap(nodeBBox)) {
1386 // This node lies completely outside the clipping region. Fill it with the background.
1387 this->fill(background, /*active=*/false);
1388 } else if (clipBBox.isInside(nodeBBox)) {
1389 // This node lies completely inside the clipping region. Leave it intact.
1390 return;
1391 }
1392
1393 // This node isn't completely contained inside the clipping region.
1394 // Set any voxels that lie outside the region to the background value.
1395
1396 // Construct a boolean mask that is on inside the clipping region and off outside it.
1397 NodeMaskType mask;
1398 nodeBBox.intersect(clipBBox);
1399 Coord xyz;
1400 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1401 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1402 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1403 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1404 mask.setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1405 }
1406 }
1407 }
1408
1409 // Set voxels that lie in the inactive region of the mask (i.e., outside
1410 // the clipping region) to the background value.
1411 for (MaskOffIterator maskIter = mask.beginOff(); maskIter; ++maskIter) {
1412 this->setValueOff(maskIter.pos(), background);
1413 }
1414 }
1415
1416
1418
1419
1420 template<typename T, Index Log2Dim>
1421 inline void
1422 LeafNode<T, Log2Dim>::fill(const CoordBBox& bbox, const ValueType& value, bool active)
1423 {
1424 #ifndef OPENVDB_2_ABI_COMPATIBLE
1425 if (!this->allocate()) return;
1426 #endif
1427
1428 for (Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1429 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1430 for (Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1431 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1432 for (Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1433 const Index offset = offsetXY + (z & (DIM-1u));
1434 mBuffer[offset] = value;
1435 mValueMask.set(offset, active);
1436 }
1437 }
1438 }
1439 }
1440
1441 template<typename T, Index Log2Dim>
1442 inline void
1443 LeafNode<T, Log2Dim>::fill(const ValueType& value)
1444 {
1445 mBuffer.fill(value);
1446 }
1447
1448 template<typename T, Index Log2Dim>
1449 inline void
1450 LeafNode<T, Log2Dim>::fill(const ValueType& value, bool active)
1451 {
1452 mBuffer.fill(value);
1453 mValueMask.set(active);
1454 }
1455
1456
1458
1459
1460 template<typename T, Index Log2Dim>
1461 template<typename DenseT>
1462 inline void
1463 LeafNode<T, Log2Dim>::copyToDense(const CoordBBox& bbox, DenseT& dense) const
1464 {
1465 #ifndef OPENVDB_2_ABI_COMPATIBLE
1466 if (!this->isAllocated()) return;
1467 #endif
1468
1469 typedef typename DenseT::ValueType DenseValueType;
1470
1471 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1472 const Coord& min = dense.bbox().min();
1473 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // target array
1474 const T* s0 = &mBuffer[bbox.min()[2] & (DIM-1u)]; // source array
1475 for (Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1476 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1477 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1478 for (Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1479 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1480 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1481 for (Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1482 *t2 = DenseValueType(*s2++);
1483 }
1484 }
1485 }
1486 }
1487
1488
1489 template<typename T, Index Log2Dim>
1490 template<typename DenseT>
1491 inline void
1492 LeafNode<T, Log2Dim>::copyFromDense(const CoordBBox& bbox, const DenseT& dense,
1493 const ValueType& background, const ValueType& tolerance)
1494 {
1495 #ifndef OPENVDB_2_ABI_COMPATIBLE
1496 if (!this->allocate()) return;
1497 #endif
1498
1499 typedef typename DenseT::ValueType DenseValueType;
1500
1501 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1502 const Coord& min = dense.bbox().min();
1503
1504 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]); // source
1505 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1506 for (Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
1507 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1508 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1509 for (Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
1510 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1511 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1512 for (Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1513 if (math::isApproxEqual(background, ValueType(*s2), tolerance)) {
1514 mValueMask.setOff(n2);
1515 mBuffer[n2] = background;
1516 } else {
1517 mValueMask.setOn(n2);
1518 mBuffer[n2] = ValueType(*s2);
1519 }
1520 }
1521 }
1522 }
1523 }
1524
1525
1527
1528
1529 template<typename T, Index Log2Dim>
1530 inline void
1531 LeafNode<T, Log2Dim>::readTopology(std::istream& is, bool /*fromHalf*/)
1532 {
1533 mValueMask.load(is);
1534 }
1535
1536
1537 template<typename T, Index Log2Dim>
1538 inline void
1539 LeafNode<T, Log2Dim>::writeTopology(std::ostream& os, bool /*toHalf*/) const
1540 {
1541 mValueMask.save(os);
1542 }
1543
1544
1546
1547
1548 #ifndef OPENVDB_2_ABI_COMPATIBLE
1549 template<typename T, Index Log2Dim>
1550 inline void
1551 LeafNode<T, Log2Dim>::Buffer::doLoad() const
1552 {
1553 if (!this->isOutOfCore()) return;
1554
1555 Buffer* self = const_cast<Buffer*>(this);
1556
1557 // This lock will be contended at most once, after which this buffer
1558 // will no longer be out-of-core.
1559 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1560 if (!this->isOutOfCore()) return;
1561
1562 boost::scoped_ptr<FileInfo> info(self->mFileInfo);
1563 assert(info.get() != NULL);
1564 assert(info->mapping.get() != NULL);
1565 assert(info->meta.get() != NULL);
1566
1568 self->mData = NULL;
1569 self->allocate();
1570
1571 boost::shared_ptr<std::streambuf> buf = info->mapping->createBuffer();
1572 std::istream is(buf.get());
1573
1574 io::setStreamMetadataPtr(is, info->meta, /*transfer=*/true);
1575
1576 NodeMaskType mask;
1577 is.seekg(info->maskpos);
1578 mask.load(is);
1579
1580 is.seekg(info->bufpos);
1581 io::readCompressedValues(is, self->mData, SIZE, mask, io::getHalfFloat(is));
1582
1583 self->setOutOfCore(false);
1584 }
1585 #endif
1586
1587
1589
1590
1591 template<typename T, Index Log2Dim>
1592 inline void
1593 LeafNode<T,Log2Dim>::readBuffers(std::istream& is, bool fromHalf)
1594 {
1595 this->readBuffers(is, CoordBBox::inf(), fromHalf);
1596 }
1597
1598
1599 template<typename T, Index Log2Dim>
1600 inline void
1601 LeafNode<T,Log2Dim>::readBuffers(std::istream& is, const CoordBBox& clipBBox, bool fromHalf)
1602 {
1603 #ifndef OPENVDB_2_ABI_COMPATIBLE
1604 std::streamoff maskpos = is.tellg();
1605 #endif
1606
1607 // Read in the value mask.
1608 mValueMask.load(is);
1609
1610 int8_t numBuffers = 1;
1611 if (io::getFormatVersion(is) < OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION) {
1612 // Read in the origin.
1613 is.read(reinterpret_cast<char*>(&mOrigin), sizeof(Coord::ValueType) * 3);
1614
1615 // Read in the number of buffers, which should now always be one.
1616 is.read(reinterpret_cast<char*>(&numBuffers), sizeof(int8_t));
1617 }
1618
1619 CoordBBox nodeBBox = this->getNodeBoundingBox();
1620 if (!clipBBox.hasOverlap(nodeBBox)) {
1621 // This node lies completely outside the clipping region.
1622 // Read and discard its voxel values.
1623 Buffer temp;
1624 io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
1625 mValueMask.setOff();
1626 mBuffer.setOutOfCore(false);
1627 } else {
1628 #ifndef OPENVDB_2_ABI_COMPATIBLE
1629 // If this node lies completely inside the clipping region and it is being read
1630 // from a memory-mapped file, delay loading of its buffer until the buffer
1631 // is actually accessed. (If this node requires clipping, its buffer
1632 // must be accessed and therefore must be loaded.)
1633 io::MappedFile::Ptr mappedFile = io::getMappedFilePtr(is);
1634 const bool delayLoad = ((mappedFile.get() != NULL) && clipBBox.isInside(nodeBBox));
1635
1636 if (delayLoad) {
1637 mBuffer.setOutOfCore(true);
1638 mBuffer.mFileInfo = new FileInfo;
1639 mBuffer.mFileInfo->bufpos = is.tellg();
1640 mBuffer.mFileInfo->mapping = mappedFile;
1641 // Save the offset to the value mask, because the in-memory copy
1642 // might change before the value buffer gets read.
1643 mBuffer.mFileInfo->maskpos = maskpos;
1644
1645 mBuffer.mFileInfo->meta = io::getStreamMetadataPtr(is);
1646
1647 // Read and discard voxel values.
1648 Buffer temp;
1649 io::readCompressedValues(is, temp.mData, SIZE, mValueMask, fromHalf);
1650 } else {
1651 #endif
1652 mBuffer.allocate();
1653 io::readCompressedValues(is, mBuffer.mData, SIZE, mValueMask, fromHalf);
1654 mBuffer.setOutOfCore(false);
1655
1656 // Get this tree's background value.
1657 T background = zeroVal<T>();
1658 if (const void* bgPtr = io::getGridBackgroundValuePtr(is)) {
1659 background = *static_cast<const T*>(bgPtr);
1660 }
1661 this->clip(clipBBox, background);
1662 #ifndef OPENVDB_2_ABI_COMPATIBLE
1663 }
1664 #endif
1665 }
1666
1667 if (numBuffers > 1) {
1668 // Read in and discard auxiliary buffers that were created with earlier
1669 // versions of the library. (Auxiliary buffers are not mask compressed.)
1670 const bool zipped = io::getDataCompression(is) & io::COMPRESS_ZIP;
1671 Buffer temp;
1672 for (int i = 1; i < numBuffers; ++i) {
1673 if (fromHalf) {
1674 io::HalfReader<io::RealToHalf<T>::isReal, T>::read(is, temp.mData, SIZE, zipped);
1675 } else {
1676 io::readData<T>(is, temp.mData, SIZE, zipped);
1677 }
1678 }
1679 }
1680 }
1681
1682
1683 template<typename T, Index Log2Dim>
1684 inline void
1685 LeafNode<T, Log2Dim>::writeBuffers(std::ostream& os, bool toHalf) const
1686 {
1687 // Write out the value mask.
1688 mValueMask.save(os);
1689
1690 mBuffer.loadValues();
1691
1692 io::writeCompressedValues(os, mBuffer.mData, SIZE,
1693 mValueMask, /*childMask=*/NodeMaskType(), toHalf);
1694 }
1695
1696
1698
1699
1700 template<typename T, Index Log2Dim>
1701 inline bool
1702 LeafNode<T, Log2Dim>::operator==(const LeafNode& other) const
1703 {
1704 return mOrigin == other.mOrigin &&
1705 mValueMask == other.mValueMask &&
1706 mBuffer == other.mBuffer;
1707 }
1708
1709
1710 template<typename T, Index Log2Dim>
1711 inline Index64
1712 LeafNode<T, Log2Dim>::memUsage() const
1713 {
1714 // Use sizeof(*this) to capture alignment-related padding
1715 // (but note that sizeof(*this) includes sizeof(mBuffer)).
1716 return sizeof(*this) + mBuffer.memUsage() - sizeof(mBuffer);
1717 }
1718
1719
1720 template<typename T, Index Log2Dim>
1721 inline void
1722 LeafNode<T, Log2Dim>::evalActiveBoundingBox(CoordBBox& bbox, bool visitVoxels) const
1723 {
1724 CoordBBox this_bbox = this->getNodeBoundingBox();
1725 if (bbox.isInside(this_bbox)) return;//this LeafNode is already enclosed in the bbox
1726 if (ValueOnCIter iter = this->cbeginValueOn()) {//any active values?
1727 if (visitVoxels) {//use voxel granularity?
1728 this_bbox.reset();
1729 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
1730 this_bbox.translate(this->origin());
1731 }
1732 bbox.expand(this_bbox);
1733 }
1734 }
1735
1736
1737 template<typename T, Index Log2Dim>
1738 template<typename OtherType, Index OtherLog2Dim>
1739 inline bool
1740 LeafNode<T, Log2Dim>::hasSameTopology(const LeafNode<OtherType, OtherLog2Dim>* other) const
1741 {
1742 assert(other);
1743 return (Log2Dim == OtherLog2Dim && mValueMask == other->getValueMask());
1744 }
1745
1746
1747 template<typename T, Index Log2Dim>
1748 inline bool
1749 LeafNode<T, Log2Dim>::isConstant(ValueType& value, bool& state,
1750 const ValueType& tolerance) const
1751 {
1752 state = mValueMask.isOn();
1753 if (!(state || mValueMask.isOff())) return false;// Are values neither active nor inactive?
1754
1755 value = mBuffer[0];
1756 for (Index i = 1; i < SIZE; ++i) {
1757 if ( !math::isApproxEqual(mBuffer[i], value, tolerance) ) return false;
1758 }
1759 return true;
1760 }
1761
1762 template<typename T, Index Log2Dim>
1763 inline bool
1764 LeafNode<T, Log2Dim>::isConstant(ValueType& minValue, ValueType& maxValue,
1765 bool& state, const ValueType& tolerance) const
1766 {
1767 state = mValueMask.isOn();
1768 if (!(state || mValueMask.isOff())) return false;// Are values neither active nor inactive?
1769
1770 const T range = 2 * tolerance;
1771 minValue = maxValue = mBuffer[0];
1772 for (Index i = 1; i < SIZE; ++i) {// early termination
1773 const T& v = mBuffer[i];
1774 if (v < minValue) {
1775 if ((maxValue - v) > range) return false;
1776 minValue = v;
1777 } else if (v > maxValue) {
1778 if ((v - minValue) > range) return false;
1779 maxValue = v;
1780 }
1781 }
1782 return true;
1783 }
1784
1786
1787
1788 template<typename T, Index Log2Dim>
1789 inline void
1790 LeafNode<T, Log2Dim>::addTile(Index /*level*/, const Coord& xyz, const ValueType& val, bool active)
1791 {
1792 this->addTile(this->coordToOffset(xyz), val, active);
1793 }
1794
1795 template<typename T, Index Log2Dim>
1796 inline void
1797 LeafNode<T, Log2Dim>::addTile(Index offset, const ValueType& val, bool active)
1798 {
1799 assert(offset < SIZE);
1800 setValueOnly(offset, val);
1801 setActiveState(offset, active);
1802 }
1803
1804 template<typename T, Index Log2Dim>
1805 template<typename AccessorT>
1806 inline void
1807 LeafNode<T, Log2Dim>::addTileAndCache(Index level, const Coord& xyz,
1808 const ValueType& val, bool active, AccessorT&)
1809 {
1810 this->addTile(level, xyz, val, active);
1811 }
1812
1813
1815
1816
1817 template<typename T, Index Log2Dim>
1818 inline void
1819 LeafNode<T, Log2Dim>::resetBackground(const ValueType& oldBackground,
1820 const ValueType& newBackground)
1821 {
1822 #ifndef OPENVDB_2_ABI_COMPATIBLE
1823 if (!this->allocate()) return;
1824 #endif
1825
1826 typename NodeMaskType::OffIterator iter;
1827 // For all inactive values...
1828 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1829 ValueType &inactiveValue = mBuffer[iter.pos()];
1830 if (math::isApproxEqual(inactiveValue, oldBackground)) {
1831 inactiveValue = newBackground;
1832 } else if (math::isApproxEqual(inactiveValue, math::negative(oldBackground))) {
1833 inactiveValue = math::negative(newBackground);
1834 }
1835 }
1836 }
1837
1838
1839 template<typename T, Index Log2Dim>
1840 template<MergePolicy Policy>
1841 inline void
1842 LeafNode<T, Log2Dim>::merge(const LeafNode& other)
1843 {
1844 #ifndef OPENVDB_2_ABI_COMPATIBLE
1845 if (!this->allocate()) return;
1846 #endif
1847
1848 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1849 if (Policy == MERGE_NODES) return;
1850 typename NodeMaskType::OnIterator iter = other.mValueMask.beginOn();
1851 for (; iter; ++iter) {
1852 const Index n = iter.pos();
1853 if (mValueMask.isOff(n)) {
1854 mBuffer[n] = other.mBuffer[n];
1855 mValueMask.setOn(n);
1856 }
1857 }
1858 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1859 }
1860
1861 template<typename T, Index Log2Dim>
1862 template<MergePolicy Policy>
1863 inline void
1864 LeafNode<T, Log2Dim>::merge(const LeafNode& other,
1865 const ValueType& /*bg*/, const ValueType& /*otherBG*/)
1866 {
1867 this->template merge<Policy>(other);
1868 }
1869
1870 template<typename T, Index Log2Dim>
1871 template<MergePolicy Policy>
1872 inline void
1873 LeafNode<T, Log2Dim>::merge(const ValueType& tileValue, bool tileActive)
1874 {
1875 #ifndef OPENVDB_2_ABI_COMPATIBLE
1876 if (!this->allocate()) return;
1877 #endif
1878
1879 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
1880 if (Policy != MERGE_ACTIVE_STATES_AND_NODES) return;
1881 if (!tileActive) return;
1882 // Replace all inactive values with the active tile value.
1883 for (typename NodeMaskType::OffIterator iter = mValueMask.beginOff(); iter; ++iter) {
1884 const Index n = iter.pos();
1885 mBuffer[n] = tileValue;
1886 mValueMask.setOn(n);
1887 }
1888 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
1889 }
1890
1891
1892 template<typename T, Index Log2Dim>
1893 template<typename OtherType>
1894 inline void
1895 LeafNode<T, Log2Dim>::topologyUnion(const LeafNode<OtherType, Log2Dim>& other)
1896 {
1897 mValueMask |= other.getValueMask();
1898 }
1899
1900 template<typename T, Index Log2Dim>
1901 template<typename OtherType>
1902 inline void
1903 LeafNode<T, Log2Dim>::topologyIntersection(const LeafNode<OtherType, Log2Dim>& other,
1904 const ValueType&)
1905 {
1906 mValueMask &= other.getValueMask();
1907 }
1908
1909 template<typename T, Index Log2Dim>
1910 template<typename OtherType>
1911 inline void
1912 LeafNode<T, Log2Dim>::topologyDifference(const LeafNode<OtherType, Log2Dim>& other,
1913 const ValueType&)
1914 {
1915 mValueMask &= !other.getValueMask();
1916 }
1917
1918 template<typename T, Index Log2Dim>
1919 inline void
1920 LeafNode<T, Log2Dim>::negate()
1921 {
1922 #ifndef OPENVDB_2_ABI_COMPATIBLE
1923 if (!this->allocate()) return;
1924 #endif
1925 for (Index i = 0; i < SIZE; ++i) {
1926 mBuffer[i] = -mBuffer[i];
1927 }
1928 }
1929
1930
1932
1933
1934 template<typename T, Index Log2Dim>
1935 template<typename CombineOp>
1936 inline void
1937 LeafNode<T, Log2Dim>::combine(const LeafNode& other, CombineOp& op)
1938 {
1939 #ifndef OPENVDB_2_ABI_COMPATIBLE
1940 if (!this->allocate()) return;
1941 #endif
1942 CombineArgs<T> args;
1943 for (Index i = 0; i < SIZE; ++i) {
1944 op(args.setARef(mBuffer[i])
1945 .setAIsActive(mValueMask.isOn(i))
1946 .setBRef(other.mBuffer[i])
1947 .setBIsActive(other.mValueMask.isOn(i))
1948 .setResultRef(mBuffer[i]));
1949 mValueMask.set(i, args.resultIsActive());
1950 }
1951 }
1952
1953
1954 template<typename T, Index Log2Dim>
1955 template<typename CombineOp>
1956 inline void
1957 LeafNode<T, Log2Dim>::combine(const ValueType& value, bool valueIsActive, CombineOp& op)
1958 {
1959 #ifndef OPENVDB_2_ABI_COMPATIBLE
1960 if (!this->allocate()) return;
1961 #endif
1962 CombineArgs<T> args;
1963 args.setBRef(value).setBIsActive(valueIsActive);
1964 for (Index i = 0; i < SIZE; ++i) {
1965 op(args.setARef(mBuffer[i])
1966 .setAIsActive(mValueMask.isOn(i))
1967 .setResultRef(mBuffer[i]));
1968 mValueMask.set(i, args.resultIsActive());
1969 }
1970 }
1971
1972
1974
1975
1976 template<typename T, Index Log2Dim>
1977 template<typename CombineOp, typename OtherType>
1978 inline void
1979 LeafNode<T, Log2Dim>::combine2(const LeafNode& other, const OtherType& value,
1980 bool valueIsActive, CombineOp& op)
1981 {
1982 #ifndef OPENVDB_2_ABI_COMPATIBLE
1983 if (!this->allocate()) return;
1984 #endif
1985 CombineArgs<T, OtherType> args;
1986 args.setBRef(value).setBIsActive(valueIsActive);
1987 for (Index i = 0; i < SIZE; ++i) {
1988 op(args.setARef(other.mBuffer[i])
1989 .setAIsActive(other.mValueMask.isOn(i))
1990 .setResultRef(mBuffer[i]));
1991 mValueMask.set(i, args.resultIsActive());
1992 }
1993 }
1994
1995
1996 template<typename T, Index Log2Dim>
1997 template<typename CombineOp, typename OtherNodeT>
1998 inline void
1999 LeafNode<T, Log2Dim>::combine2(const ValueType& value, const OtherNodeT& other,
2000 bool valueIsActive, CombineOp& op)
2001 {
2002 #ifndef OPENVDB_2_ABI_COMPATIBLE
2003 if (!this->allocate()) return;
2004 #endif
2005 CombineArgs<T, typename OtherNodeT::ValueType> args;
2006 args.setARef(value).setAIsActive(valueIsActive);
2007 for (Index i = 0; i < SIZE; ++i) {
2008 op(args.setBRef(other.mBuffer[i])
2009 .setBIsActive(other.mValueMask.isOn(i))
2010 .setResultRef(mBuffer[i]));
2011 mValueMask.set(i, args.resultIsActive());
2012 }
2013 }
2014
2015
2016 template<typename T, Index Log2Dim>
2017 template<typename CombineOp, typename OtherNodeT>
2018 inline void
2019 LeafNode<T, Log2Dim>::combine2(const LeafNode& b0, const OtherNodeT& b1, CombineOp& op)
2020 {
2021 #ifndef OPENVDB_2_ABI_COMPATIBLE
2022 if (!this->allocate()) return;
2023 #endif
2024 CombineArgs<T, typename OtherNodeT::ValueType> args;
2025 for (Index i = 0; i < SIZE; ++i) {
2026 mValueMask.set(i, b0.mValueMask.isOn(i) || b1.mValueMask.isOn(i));
2027 op(args.setARef(b0.mBuffer[i])
2028 .setAIsActive(b0.mValueMask.isOn(i))
2029 .setBRef(b1.mBuffer[i])
2030 .setBIsActive(b1.mValueMask.isOn(i))
2031 .setResultRef(mBuffer[i]));
2032 mValueMask.set(i, args.resultIsActive());
2033 }
2034 }
2035
2036
2038
2039
2040 template<typename T, Index Log2Dim>
2041 template<typename BBoxOp>
2042 inline void
2043 LeafNode<T, Log2Dim>::visitActiveBBox(BBoxOp& op) const
2044 {
2045 if (op.template descent<LEVEL>()) {
2046 for (ValueOnCIter i=this->cbeginValueOn(); i; ++i) {
2047 #ifdef _MSC_VER
2048 op.operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
2049 #else
2050 op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
2051 #endif
2052 }
2053 } else {
2054 #ifdef _MSC_VER
2055 op.operator()<LEVEL>(this->getNodeBoundingBox());
2056 #else
2057 op.template operator()<LEVEL>(this->getNodeBoundingBox());
2058 #endif
2059 }
2060 }
2061
2062
2063 template<typename T, Index Log2Dim>
2064 template<typename VisitorOp>
2065 inline void
2066 LeafNode<T, Log2Dim>::visit(VisitorOp& op)
2067 {
2068 doVisit<LeafNode, VisitorOp, ChildAllIter>(*this, op);
2069 }
2070
2071
2072 template<typename T, Index Log2Dim>
2073 template<typename VisitorOp>
2074 inline void
2075 LeafNode<T, Log2Dim>::visit(VisitorOp& op) const
2076 {
2077 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*this, op);
2078 }
2079
2080
2081 template<typename T, Index Log2Dim>
2082 template<typename NodeT, typename VisitorOp, typename ChildAllIterT>
2083 inline void
2084 LeafNode<T, Log2Dim>::doVisit(NodeT& self, VisitorOp& op)
2085 {
2086 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
2087 op(iter);
2088 }
2089 }
2090
2091
2093
2094
2095 template<typename T, Index Log2Dim>
2096 template<typename OtherLeafNodeType, typename VisitorOp>
2097 inline void
2098 LeafNode<T, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op)
2099 {
2100 doVisit2Node<LeafNode, OtherLeafNodeType, VisitorOp, ChildAllIter,
2101 typename OtherLeafNodeType::ChildAllIter>(*this, other, op);
2102 }
2103
2104
2105 template<typename T, Index Log2Dim>
2106 template<typename OtherLeafNodeType, typename VisitorOp>
2107 inline void
2108 LeafNode<T, Log2Dim>::visit2Node(OtherLeafNodeType& other, VisitorOp& op) const
2109 {
2110 doVisit2Node<const LeafNode, OtherLeafNodeType, VisitorOp, ChildAllCIter,
2111 typename OtherLeafNodeType::ChildAllCIter>(*this, other, op);
2112 }
2113
2114
2115 template<typename T, Index Log2Dim>
2116 template<
2117 typename NodeT,
2118 typename OtherNodeT,
2119 typename VisitorOp,
2120 typename ChildAllIterT,
2121 typename OtherChildAllIterT>
2122 inline void
2123 LeafNode<T, Log2Dim>::doVisit2Node(NodeT& self, OtherNodeT& other, VisitorOp& op)
2124 {
2125 // Allow the two nodes to have different ValueTypes, but not different dimensions.
2126 BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
2127 BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
2128
2129 ChildAllIterT iter = self.beginChildAll();
2130 OtherChildAllIterT otherIter = other.beginChildAll();
2131
2132 for ( ; iter && otherIter; ++iter, ++otherIter) {
2133 op(iter, otherIter);
2134 }
2135 }
2136
2137
2139
2140
2141 template<typename T, Index Log2Dim>
2142 template<typename IterT, typename VisitorOp>
2143 inline void
2144 LeafNode<T, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS)
2145 {
2146 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(
2147 *this, otherIter, op, otherIsLHS);
2148 }
2149
2150
2151 template<typename T, Index Log2Dim>
2152 template<typename IterT, typename VisitorOp>
2153 inline void
2154 LeafNode<T, Log2Dim>::visit2(IterT& otherIter, VisitorOp& op, bool otherIsLHS) const
2155 {
2156 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(
2157 *this, otherIter, op, otherIsLHS);
2158 }
2159
2160
2161 template<typename T, Index Log2Dim>
2162 template<
2163 typename NodeT,
2164 typename VisitorOp,
2165 typename ChildAllIterT,
2166 typename OtherChildAllIterT>
2167 inline void
2168 LeafNode<T, Log2Dim>::doVisit2(NodeT& self, OtherChildAllIterT& otherIter,
2169 VisitorOp& op, bool otherIsLHS)
2170 {
2171 if (!otherIter) return;
2172
2173 if (otherIsLHS) {
2174 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
2175 op(otherIter, iter);
2176 }
2177 } else {
2178 for (ChildAllIterT iter = self.beginChildAll(); iter; ++iter) {
2179 op(iter, otherIter);
2180 }
2181 }
2182 }
2183
2184
2186
2187
2188 template<typename T, Index Log2Dim>
2189 inline std::ostream&
2190 operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
2191 {
2192 for (Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] << ", ";
2193 return os;
2194 }
2195
2196 } // namespace tree
2197 } // namespace OPENVDB_VERSION_NAME
2198 } // namespace openvdb
2199
2200
2202
2203
2204 // Specialization for LeafNodes of type bool
2205 #include "LeafNodeBool.h"
2206
2207 #endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
2208
2209 // Copyright (c) 2012-2015 DreamWorks Animation LLC
2210 // All rights reserved. This software is distributed under the
2211 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v3_1_0::tree::LeafNode::touchLeafAndCache
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1018
openvdb::v3_1_0::tree::LeafNode::FileInfo::maskpos
std::streamoff maskpos
Definition: LeafNode.h:101
openvdb::v3_1_0::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:1422
openvdb::v3_1_0::tree::LeafNode::setValueOn
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition: LeafNode.h:722
openvdb::v3_1_0::tree::LeafNode::ValueType
T ValueType
Definition: LeafNode.h:68
openvdb::v3_1_0::math::negative
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:116
openvdb::v3_1_0::tree::LeafNode::isAllocated
bool isAllocated() const
Return true if memory for this node&#39;s buffer has been allocated.
Definition: LeafNode.h:452
openvdb::v3_1_0::tree::LeafNode::cendValueAll
ValueAllCIter cendValueAll() const
Definition: LeafNode.h:608
openvdb::v3_1_0::tree::LeafNode::offVoxelCount
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition: LeafNode.h:440
openvdb::v3_1_0::tree::LeafNode::writeBuffers
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1685
openvdb::v3_1_0::util::NodeMask::load
void load(std::istream &is)
Definition: NodeMasks.h:555
openvdb::v3_1_0::Index
Index32 Index
Definition: Types.h:58
openvdb::v3_1_0::tree::LeafNode::cendValueOff
ValueOffCIter cendValueOff() const
Definition: LeafNode.h:605
openvdb::v3_1_0::tree::LeafNode::Buffer::data
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafNode.h:267
openvdb::v3_1_0::tree::LeafNode::coordToOffset
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1271
openvdb::v3_1_0::tree::LeafNode::ValueIter::setItem
void setItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:523
openvdb::v3_1_0::tree::LeafNode::cendChildOff
ChildOffCIter cendChildOff() const
Definition: LeafNode.h:627
openvdb::v3_1_0::tree::LeafNode::getValueMask
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:1105
openvdb::v3_1_0::CombineArgs::setBRef
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:344
Types.h
openvdb::v3_1_0::tree::LeafNode::offsetToGlobalCoord
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1295
openvdb::v3_1_0::tree::LeafNode::ValueOn
Definition: LeafNode.h:504
openvdb::v3_1_0::tree::LeafNode::setValueOffAndCache
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNode.h:865
openvdb::v3_1_0::tree::LeafNode::probeNode
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1002
openvdb::v3_1_0::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:408
openvdb::v3_1_0::tree::LeafNode::getFirstValue
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition: LeafNode.h:908
openvdb::v3_1_0::tree::LeafNode::DenseIter
Definition: LeafNode.h:552
Compression.h
openvdb::v3_1_0::tree::LeafNode::beginChildOn
ChildOnIter beginChildOn()
Definition: LeafNode.h:616
openvdb::v3_1_0::tree::LeafNode::addTile
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1790
openvdb::v3_1_0::tree::LeafNode::endValueAll
ValueAllCIter endValueAll() const
Definition: LeafNode.h:609
openvdb::v3_1_0::tree::LeafNode::negate
void negate()
Definition: LeafNode.h:1920
openvdb::v3_1_0::tree::LeafNode::ValueConverter::Type
LeafNode< OtherValueType, Log2Dim > Type
Definition: LeafNode.h:86
openvdb::v3_1_0::io::MappedFile::Ptr
boost::shared_ptr< MappedFile > Ptr
Definition: io.h:135
openvdb::v3_1_0::util::BaseMaskIterator::pos
Index32 pos() const
Definition: NodeMasks.h:193
openvdb::v3_1_0::tree::LeafNode::getLastValue
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition: LeafNode.h:910
openvdb::v3_1_0::tree::LeafNode::stealNode
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1000
openvdb::v3_1_0::tree::LeafNode::setValueMask
void setValueMask(const NodeMaskType &mask)
Definition: LeafNode.h:1107
openvdb::v3_1_0::tree::LeafNode::operator==
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1702
openvdb::v3_1_0::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
TestLeafIO
Definition: LeafNode.h:50
openvdb::v3_1_0::tree::LeafNode::getLevel
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNode.h:427
openvdb::v3_1_0::tree::LeafNode::isEmpty
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:446
openvdb::v3_1_0::tree::LeafNode::ValueIter::BaseT
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNode.h:514
openvdb::v3_1_0::tree::LeafNode::LEVEL
static const Index LEVEL
Definition: LeafNode.h:80
openvdb::v3_1_0::tree::LeafNode::Buffer::getValue
const ValueType & getValue(Index i) const
Return a const reference to the i&#39;th element of this buffer.
Definition: LeafNode.h:181
openvdb::v3_1_0::tree::LeafNode::beginValueOff
ValueOffIter beginValueOff()
Definition: LeafNode.h:597
openvdb::v3_1_0::tree::LeafNode::setValueMask
void setValueMask(Index n, bool on)
Definition: LeafNode.h:1112
openvdb::v3_1_0::tree::LeafNode::Buffer::swap
void swap(Buffer &other)
Exchange this buffer&#39;s values with the other buffer&#39;s values.
Definition: LeafNode.h:241
openvdb::v3_1_0::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:1281
openvdb::v3_1_0::tree::LeafNode::beginChildOff
ChildOffCIter beginChildOff() const
Definition: LeafNode.h:618
openvdb::v3_1_0::tree::LeafNode::cbeginChildAll
ChildAllCIter cbeginChildAll() const
Definition: LeafNode.h:620
openvdb::v3_1_0::tree::LeafNode::setValue
void setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNode.h:720
openvdb::v3_1_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
openvdb::v3_1_0::tree::LeafNode::dim
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition: LeafNode.h:421
openvdb::v3_1_0::tree::LeafNode::probeValueAndCache
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val...
Definition: LeafNode.h:883
openvdb::v3_1_0::tree::LeafNode::SameConfiguration
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition: LeafNode.h:92
openvdb::v3_1_0::tree::LeafNode::isValueOn
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:763
openvdb::v3_1_0::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:467
openvdb::v3_1_0::CombineArgs::resultIsActive
bool resultIsActive() const
Definition: Types.h:353
openvdb::v3_1_0::tree::LeafNode::ChildOffCIter
ChildIter< MaskOffIterator, const LeafNode, ChildOff > ChildOffCIter
Definition: LeafNode.h:588
openvdb::v3_1_0::tree::LeafNode::cendChildOn
ChildOnCIter cendChildOn() const
Definition: LeafNode.h:624
openvdb::v3_1_0::tree::LeafNode::ValueOff
Definition: LeafNode.h:504
openvdb::v3_1_0::util::NodeMask
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
openvdb::v3_1_0::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:712
openvdb::v3_1_0::tree::LeafNode::nonLeafCount
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNode.h:435
openvdb::v3_1_0::util::OnMaskIterator
Definition: NodeMasks.h:205
openvdb::v3_1_0::tree::LeafNode::FileInfo::mapping
io::MappedFile::Ptr mapping
Definition: LeafNode.h:102
openvdb::v3_1_0::io::writeCompressedValues
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:431
openvdb::v3_1_0::util::OffMaskIterator
Definition: NodeMasks.h:236
openvdb::v3_1_0::tree::LeafNode::buffer
Buffer & buffer()
Definition: LeafNode.h:641
openvdb::v3_1_0::Index32
uint32_t Index32
Definition: Types.h:56
openvdb::v3_1_0::tree::LeafNode::Buffer::WordType
ValueType WordType
Definition: LeafNode.h:127
openvdb::v3_1_0::tree::LeafNode::getOrigin
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:475
openvdb::v3_1_0::tree::LeafNode::Buffer::isOutOfCore
bool isOutOfCore() const
Return true if this buffer&#39;s values have not yet been read from disk.
Definition: LeafNode.h:162
openvdb::v3_1_0::tree::LeafNode::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: LeafNode.h:694
openvdb::v3_1_0::tools::clip
OPENVDB_STATIC_SPECIALIZATION GridType::Ptr clip(const GridType &grid, const BBoxd &)
Clip the given grid against a world-space bounding box and return a new grid containing the result...
Definition: Clip.h:355
openvdb::v3_1_0::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:730
openvdb::v3_1_0::tree::LeafNode::endValueOn
ValueOnCIter endValueOn() const
Definition: LeafNode.h:603
openvdb::v3_1_0::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:1912
openvdb::v3_1_0::tree::LeafNode::Buffer::Buffer
Buffer(PartialCreate, const ValueType &)
Construct a buffer but don&#39;t allocate memory for the full array of values.
Definition: LeafNode.h:150
openvdb::v3_1_0::tree::LeafNode::beginValueOn
ValueOnCIter beginValueOn() const
Definition: LeafNode.h:593
openvdb::v3_1_0::tree::LeafNode::DenseIter::DenseIter
DenseIter()
Definition: LeafNode.h:558
openvdb::v3_1_0::tree::LeafNode::visit
void visit(VisitorOp &)
Definition: LeafNode.h:2066
openvdb::v3_1_0::tree::LeafNode::buffer
const Buffer & buffer() const
Definition: LeafNode.h:640
openvdb::v3_1_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i...
Definition: LeafNode.h:892
openvdb::v3_1_0::tree::LeafNode::setValueOn
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNode.h:716
openvdb::v3_1_0::tree::LeafNode::beginValueOn
ValueOnIter beginValueOn()
Definition: LeafNode.h:594
openvdb::v3_1_0::tree::LeafNode::FileInfo::FileInfo
FileInfo()
Definition: LeafNode.h:99
openvdb::v3_1_0::tree::LeafNode::DenseIter::unsetItem
void unsetItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:572
openvdb::v3_1_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff(Index n) const
Definition: LeafNode.h:1103
openvdb::v3_1_0::tree::DenseIteratorBase::NonConstValueType
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
openvdb::v3_1_0::tree::LeafNode::ChildAllCIter
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:590
openvdb::v3_1_0::tree::LeafNode::cendValueOn
ValueOnCIter cendValueOn() const
Definition: LeafNode.h:602
openvdb::v3_1_0::math::isApproxEqual
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:370
openvdb::v3_1_0::tree::LeafNode::beginValueAll
ValueAllCIter beginValueAll() const
Definition: LeafNode.h:599
openvdb::v3_1_0::tree::LeafNode::ValueIter::setValue
void setValue(const ValueT &value) const
Definition: LeafNode.h:528
openvdb::v3_1_0::tree::LeafNode::endValueOn
ValueOnIter endValueOn()
Definition: LeafNode.h:604
openvdb::v3_1_0::tree::LeafNode::Buffer
Array of fixed size that stores the voxel values of a LeafNode.
Definition: LeafNode.h:109
openvdb::v3_1_0::tree::LeafNode::ValueAllIter
ValueIter< MaskDenseIterator, LeafNode, const ValueType, ValueAll > ValueAllIter
Definition: LeafNode.h:583
openvdb::v3_1_0::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:1819
openvdb::v3_1_0::io::setStreamMetadataPtr
OPENVDB_API void setStreamMetadataPtr(std::ios_base &, boost::shared_ptr< StreamMetadata > &, bool transfer=true)
Associate the given stream with (a shared pointer to) an object that stores metadata (file format...
openvdb::v3_1_0::tree::LeafNode::ValueIter::getValue
ValueT & getValue() const
Definition: LeafNode.h:520
openvdb::v3_1_0::tree::LeafNode::isChildMaskOn
bool isChildMaskOn(Index) const
Definition: LeafNode.h:1108
openvdb::v3_1_0::tree::LeafNode::ValueOnCIter
ValueIter< MaskOnIterator, const LeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: LeafNode.h:580
openvdb::v3_1_0::tools::composite::min
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:105
openvdb::v3_1_0::tree::LeafNode::ValueIter
Definition: LeafNode.h:508
openvdb::v3_1_0::tree::LeafNode::Buffer::Buffer
Buffer(const ValueType &val)
Construct a buffer populated with the specified value.
Definition: LeafNode.h:132
openvdb::v3_1_0::tree::LeafNode::readBuffers
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1593
openvdb::v3_1_0::tree::LeafNode::ChildAll
Definition: LeafNode.h:505
openvdb::v3_1_0::tree::LeafNode::endValueOff
ValueOffCIter endValueOff() const
Definition: LeafNode.h:606
openvdb::v3_1_0::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...
openvdb::v3_1_0::tree::LeafNode::operator!=
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:496
openvdb::v3_1_0::tree::LeafNode::onLeafVoxelCount
Index64 onLeafVoxelCount() const
Definition: LeafNode.h:441
openvdb::v3_1_0::tree::LeafNode::beginChildAll
ChildAllIter beginChildAll()
Definition: LeafNode.h:622
openvdb::v3_1_0::tree::LeafNode::getValueAndCache
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:818
openvdb::v3_1_0::tree::LeafNode::offLeafVoxelCount
Index64 offLeafVoxelCount() const
Definition: LeafNode.h:442
openvdb::v3_1_0::tree::LeafNode::beginChildAll
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:621
openvdb::v3_1_0::tree::LeafNode::probeConstNodeAndCache
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1040
openvdb::v3_1_0::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:2043
openvdb::v3_1_0::io::getStreamMetadataPtr
OPENVDB_API boost::shared_ptr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
openvdb::v3_1_0::tree::LeafNode::cbeginValueAll
ValueAllCIter cbeginValueAll() const
Definition: LeafNode.h:598
openvdb::v3_1_0::tree::LeafNode::probeLeaf
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNode.h:1038
openvdb::v3_1_0::tree::LeafNode::allocate
bool allocate()
Allocate memory for this node&#39;s buffer if it has not already been allocated.
Definition: LeafNode.h:454
openvdb::v3_1_0::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:1740
openvdb::v3_1_0::util::NodeMask::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:499
openvdb::v3_1_0::OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition: version.h:110
openvdb::v3_1_0::tree::LeafNode::combine2
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1979
openvdb::v3_1_0::tree::LeafNode::ChildOnCIter
ChildIter< MaskOnIterator, const LeafNode, ChildOn > ChildOnCIter
Definition: LeafNode.h:586
openvdb::v3_1_0::tree::LeafNode::Buffer::~Buffer
~Buffer()
Destructor.
Definition: LeafNode.h:152
openvdb::v3_1_0::tree::LeafNode::cendChildAll
ChildAllCIter cendChildAll() const
Definition: LeafNode.h:630
openvdb::v3_1_0::tree::LeafNode::endChildOff
ChildOffCIter endChildOff() const
Definition: LeafNode.h:628
openvdb::v3_1_0::tree::SameLeafConfig
Definition: PointIndexGrid.h:68
openvdb::v3_1_0::tree::LeafNode::probeNodeAndCache
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1020
openvdb::v3_1_0::io::HalfReader
Definition: Compression.h:211
openvdb::v3_1_0::tree::LeafNode::offTileCount
static Index64 offTileCount()
Definition: LeafNode.h:444
openvdb::v3_1_0::tree::LeafNode::ValueOffIter
ValueIter< MaskOffIterator, LeafNode, const ValueType, ValueOff > ValueOffIter
Definition: LeafNode.h:581
openvdb::v3_1_0::tree::LeafNode::ValueIter::modifyItem
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNode.h:535
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_1_0::tree::LeafNode::cbeginChildOff
ChildOffCIter cbeginChildOff() const
Definition: LeafNode.h:617
openvdb::v3_1_0::io::getFormatVersion
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
openvdb::v3_1_0::util::NodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:351
openvdb::v3_1_0::tree::LeafNode::Buffer::operator[]
const ValueType & operator[](Index i) const
Return a const reference to the i&#39;th element of this buffer.
Definition: LeafNode.h:183
openvdb::v3_1_0::tree::LeafNode::ValueIter::ValueIter
ValueIter()
Definition: LeafNode.h:516
openvdb::v3_1_0::tree::LeafNode::setValuesOn
void setValuesOn()
Mark all voxels as active but don&#39;t change their values.
Definition: LeafNode.h:758
openvdb::v3_1_0::tree::LeafNode::~LeafNode
~LeafNode()
Destructor.
Definition: LeafNode.h:1251
openvdb::v3_1_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff() const
Definition: LeafNode.h:1110
openvdb::v3_1_0::tree::LeafNode::isInactive
bool isInactive() const
Return true if all of this node&#39;s values are inactive.
Definition: LeafNode.h:1076
openvdb::v3_1_0::tree::LeafNode::MaskOnIterator
NodeMaskType::OnIterator MaskOnIterator
Definition: LeafNode.h:499
openvdb::v3_1_0::tree::LeafNode::endChildOn
ChildOnIter endChildOn()
Definition: LeafNode.h:626
openvdb::v3_1_0::tree::LeafNode::getValueLevelAndCache
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNode.h:903
openvdb::v3_1_0::tree::LeafNode::addLeafAndCache
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:998
openvdb::v3_1_0::tree::LeafNode::Buffer::empty
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafNode.h:164
openvdb::v3_1_0::tree::LeafNode::modifyValue
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNode.h:740
openvdb::v3_1_0::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:1356
openvdb::v3_1_0::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:1382
openvdb::v3_1_0::tree::LeafNode::FileInfo::meta
boost::shared_ptr< io::StreamMetadata > meta
Definition: LeafNode.h:103
openvdb::v3_1_0::tree::LeafNode::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: LeafNode.h:874
openvdb::v3_1_0::tree::LeafNode::ChildIter::ChildIter
ChildIter()
Definition: LeafNode.h:546
openvdb::v3_1_0::tree::LeafNode::beginChildOn
ChildOnCIter beginChildOn() const
Definition: LeafNode.h:615
openvdb::v3_1_0::tree::LeafNode::ChildOn
Definition: LeafNode.h:505
openvdb::v3_1_0::tree::LeafNode::Buffer::Buffer
Buffer(const Buffer &other)
Copy constructor.
Definition: LeafNode.h:137
openvdb::v3_1_0::io::readCompressedValues
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:329
openvdb::v3_1_0::CombineArgs::setARef
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:342
openvdb::v3_1_0::tree::LeafNode::ChildOff
Definition: LeafNode.h:505
openvdb::v3_1_0::tree::LeafNode::ChildIter::ChildIter
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:547
openvdb::v3_1_0::tree::LeafNode::Buffer::operator=
Buffer & operator=(const Buffer &other)
Copy the other buffer&#39;s values into this buffer.
Definition: LeafNode.h:197
openvdb::v3_1_0::tree::LeafNode::str
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1258
openvdb::v3_1_0::tree::LeafNode::ValueAllCIter
ValueIter< MaskDenseIterator, const LeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: LeafNode.h:584
openvdb::v3_1_0::tree::LeafNode::modifyValueAndActiveStateAndCache
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNode.h:857
openvdb::v3_1_0::tree::LeafNode::getNodeLog2Dims
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNode.h:429
openvdb::v3_1_0::util::NodeMask::set
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:459
openvdb
Definition: Exceptions.h:39
openvdb::v3_1_0::tree::LeafNode::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: LeafNode.h:639
openvdb::v3_1_0::tree::LeafNode::DenseIter::NonConstValueT
BaseT::NonConstValueType NonConstValueT
Definition: LeafNode.h:556
openvdb::v3_1_0::tree::LeafNode::FileInfo::bufpos
std::streamoff bufpos
Definition: LeafNode.h:100
openvdb::v3_1_0::tree::LeafNode::probeLeafAndCache
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1037
openvdb::v3_1_0::tree::LeafNode::Buffer::operator==
bool operator==(const Buffer &other) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafNode.h:225
openvdb::v3_1_0::util::NodeMask::isOff
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:505
openvdb::v3_1_0::tree::LeafNode::ValueOnIter
ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn > ValueOnIter
Definition: LeafNode.h:579
openvdb::v3_1_0::io::getDataCompression
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK, etc.) specifying whether and how input data is compressed or output data should be compressed.
LeafNodeBool.h
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
openvdb::v3_1_0::TopologyCopy
Definition: Types.h:419
openvdb::v3_1_0::tree::LeafNode::ChildOffIter
ChildIter< MaskOffIterator, LeafNode, ChildOff > ChildOffIter
Definition: LeafNode.h:587
openvdb::v3_1_0::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:347
openvdb::v3_1_0::tree::LeafNode::visit2Node
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:2098
openvdb::v3_1_0::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:1895
openvdb::v3_1_0::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:555
openvdb::v3_1_0::tree::LeafNode::beginValueOff
ValueOffCIter beginValueOff() const
Definition: LeafNode.h:596
openvdb::v3_1_0::tree::LeafNode::getValue
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1306
openvdb::v3_1_0::tree::LeafNode::setValueMaskOff
void setValueMaskOff(Index n)
Definition: LeafNode.h:1114
openvdb::v3_1_0::tree::LeafNode::combine
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1937
openvdb::v3_1_0::tree::LeafNode::NodeMaskType
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNode.h:71
openvdb::v3_1_0::tree::LeafNode::isValueOnAndCache
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:826
openvdb::v3_1_0::tree::LeafNode::addTileAndCache
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1807
openvdb::v3_1_0::tree::DenseIteratorBase
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
openvdb::v3_1_0::tree::LeafNode::Buffer::size
static Index size()
Return the number of values contained in this buffer.
Definition: LeafNode.h:262
openvdb::v3_1_0::tree::LeafNode::cbeginValueOn
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:592
openvdb::v3_1_0::tree::LeafNode::leafCount
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNode.h:433
openvdb::v3_1_0::tree::LeafNode::cbeginChildOn
ChildOnCIter cbeginChildOn() const
Definition: LeafNode.h:614
openvdb::v3_1_0::tree::LeafNode::readTopology
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1531
openvdb::v3_1_0::tree::LeafNode::evalNodeOrigin
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNode.h:1117
openvdb::v3_1_0::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:1463
openvdb::v3_1_0::tree::LeafNode::Buffer::data
ValueType * data()
Return a pointer to the array of voxel values.
Definition: LeafNode.h:287
openvdb::v3_1_0::util::NodeMask::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:454
openvdb::v3_1_0::tree::LeafNode::endChildOff
ChildOffIter endChildOff()
Definition: LeafNode.h:629
openvdb::v3_1_0::tree::LeafNode::FileInfo
Definition: LeafNode.h:97
openvdb::v3_1_0::util::DenseMaskIterator
Definition: NodeMasks.h:267
openvdb::v3_1_0::tree::LeafNode::onVoxelCount
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition: LeafNode.h:438
openvdb::v3_1_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn(Index n) const
Definition: LeafNode.h:1101
openvdb::v3_1_0::tree::LeafNode::DenseIter::BaseT
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNode.h:555
openvdb::v3_1_0::tree::LeafNode::isDense
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:448
openvdb::v3_1_0::tree::LeafNode::onTileCount
static Index64 onTileCount()
Definition: LeafNode.h:443
openvdb::v3_1_0::tree::LeafNode::size
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:423
openvdb::v3_1_0::tree::LeafNode::isValueOn
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNode.h:765
openvdb::v3_1_0::tree::LeafNode::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: LeafNode.h:849
openvdb::v3_1_0::tree::LeafNode::SIZE
static const Index SIZE
Definition: LeafNode.h:79
openvdb::v3_1_0::MERGE_NODES
Definition: Types.h:259
openvdb::v3_1_0::tree::LeafNode::setValueMaskOn
void setValueMaskOn(Index n)
Definition: LeafNode.h:1113
openvdb::v3_1_0::tree::LeafNode::ChildIter
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:543
openvdb::v3_1_0::tree::LeafNode::isChildMaskOff
bool isChildMaskOff(Index) const
Definition: LeafNode.h:1109
openvdb::v3_1_0::tree::LeafNode::endChildAll
ChildAllIter endChildAll()
Definition: LeafNode.h:632
openvdb::v3_1_0::tree::SparseIteratorBase
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
openvdb::v3_1_0::tree::LeafNode::getOrigin
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:474
openvdb::v3_1_0::tree::LeafNode::Buffer::operator!=
bool operator!=(const Buffer &other) const
Return true if the contents of the other buffer are not exactly equal to the contents of this buffer...
Definition: LeafNode.h:238
openvdb::v3_1_0::tree::LeafNode::getNodes
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:1005
openvdb::v3_1_0::tree::LeafNode::getValueMask
NodeMaskType & getValueMask()
Definition: LeafNode.h:1106
openvdb::v3_1_0::tree::LeafNode::doVisit2
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:2168
openvdb::v3_1_0::tree::LeafNode::getChildDim
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNode.h:431
openvdb::v3_1_0::tree::LeafNode::beginChildOff
ChildOffIter beginChildOff()
Definition: LeafNode.h:619
openvdb::v3_1_0::tree::LeafNode::memUsage
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1712
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
openvdb::v3_1_0::tree::LeafNode::ValueIter::getItem
ValueT & getItem(Index pos) const
Definition: LeafNode.h:519
openvdb::v3_1_0::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:1322
openvdb::v3_1_0::tree::LeafNode::probeConstNode
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:1004
openvdb::v3_1_0::tree::LeafNode::doVisit2Node
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:2123
openvdb::v3_1_0::tree::LeafNode::DenseIter::getItem
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNode.h:561
openvdb::v3_1_0::tree::LeafNode::getValueLevel
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition: LeafNode.h:689
openvdb::v3_1_0::tree::LeafNode::endChildAll
ChildAllCIter endChildAll() const
Definition: LeafNode.h:631
openvdb::v3_1_0::CombineArgs
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:304
openvdb::v3_1_0::tree::LeafNode::MaskOffIterator
NodeMaskType::OffIterator MaskOffIterator
Definition: LeafNode.h:500
openvdb::v3_1_0::tree::LeafNode::isValueMaskOn
bool isValueMaskOn() const
Definition: LeafNode.h:1102
openvdb::v3_1_0::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:449
openvdb::v3_1_0::tree::LeafNode::setValueOff
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don&#39;t change its value.
Definition: LeafNode.h:704
openvdb::v3_1_0::tree::LeafNode::Buffer::mFileInfo
FileInfo * mFileInfo
Definition: LeafNode.h:360
openvdb::v3_1_0::Int32
int32_t Int32
Definition: Types.h:60
openvdb::v3_1_0::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:1364
openvdb::v3_1_0::tree::LeafNode::endValueAll
ValueAllIter endValueAll()
Definition: LeafNode.h:610
openvdb::v3_1_0::Index64
uint64_t Index64
Definition: Types.h:57
openvdb::v3_1_0::tree::LeafNode::LOG2DIM
static const Index LOG2DIM
Definition: LeafNode.h:74
openvdb::v3_1_0::tree::LeafNode::Buffer::allocate
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafNode.h:167
Iterator.h
openvdb::v3_1_0::tree::LeafNode::probeLeafAndCache
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1029
openvdb::v3_1_0::io::COMPRESS_ZIP
Definition: Compression.h:79
openvdb::v3_1_0::tree::LeafNode::ValueOffCIter
ValueIter< MaskOffIterator, const LeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: LeafNode.h:582
openvdb::v3_1_0::tree::LeafNode::voxelizeActiveTiles
void voxelizeActiveTiles()
Definition: LeafNode.h:918
openvdb::v3_1_0::tree::LeafNode::LeafNode
LeafNode()
Default constructor.
Definition: LeafNode.h:1165
openvdb::v3_1_0::tree::LeafNode::ValueIter::modifyValue
void modifyValue(const ModifyOp &op) const
Definition: LeafNode.h:538
openvdb::v3_1_0::tree::LeafNode::MaskDenseIterator
NodeMaskType::DenseIterator MaskDenseIterator
Definition: LeafNode.h:501
openvdb::v3_1_0::tree::LeafNode::Buffer::setValue
void setValue(Index i, const ValueType &val)
Set the i&#39;th value of this buffer to the specified value.
Definition: LeafNode.h:185
openvdb::v3_1_0::tree::LeafNode::numValues
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:425
openvdb::v3_1_0::tree::LeafNode::log2dim
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition: LeafNode.h:419
openvdb::v3_1_0::util::NodeMask::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:349
openvdb::v3_1_0::tree::LeafNode::setValueAndCache
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNode.h:831
openvdb::v3_1_0::tree::LeafNode::cbeginValueOff
ValueOffCIter cbeginValueOff() const
Definition: LeafNode.h:595
openvdb::v3_1_0::tree::LeafNode::hasActiveTiles
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNode.h:768
openvdb::v3_1_0::tree::LeafNode::ValueConverter
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition: LeafNode.h:85
openvdb::v3_1_0::io::getMappedFilePtr
OPENVDB_API boost::shared_ptr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated, or a null pointer if the stream is not associated with a memory-mapped file.
openvdb::v3_1_0::tree::LeafNode::visit2
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:2144
NodeMasks.h
openvdb::v3_1_0::tree::LeafNode::evalActiveBoundingBox
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1722
openvdb::v3_1_0::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:702
openvdb::v3_1_0::PartialCreate
Definition: Types.h:421
openvdb::v3_1_0::tree::LeafNode
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
openvdb::v3_1_0::tree::LeafNode::ChildAllIter
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:589
openvdb::v3_1_0::tree::LeafNode::LeafNodeType
LeafNode< ValueType, Log2Dim > LeafNodeType
Definition: LeafNode.h:69
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_1_0::tree::LeafNode::Buffer::memUsage
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafNode.h:250
openvdb::v3_1_0::tree::LeafNode::beginValueAll
ValueAllIter beginValueAll()
Definition: LeafNode.h:600
openvdb::v3_1_0::tree::LeafNode::addLeaf
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNode.h:996
openvdb::v3_1_0::tree::LeafNode::endChildOn
ChildOnCIter endChildOn() const
Definition: LeafNode.h:625
openvdb::v3_1_0::tree::LeafNode::isValueMaskOff
bool isValueMaskOff() const
Definition: LeafNode.h:1104
openvdb::v3_1_0::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:1492
openvdb::v3_1_0::tree::LeafNode::ChildOnIter
ChildIter< MaskOnIterator, LeafNode, ChildOn > ChildOnIter
Definition: LeafNode.h:585
openvdb::v3_1_0::tree::LeafNode::DIM
static const Index DIM
Definition: LeafNode.h:76
openvdb::v3_1_0::tree::LeafNode::Buffer::fill
void fill(const ValueType &val)
Populate this buffer with a constant value.
Definition: LeafNode.h:170
openvdb::v3_1_0::tree::LeafNode::Buffer::Buffer
Buffer()
Default constructor.
Definition: LeafNode.h:130
openvdb::v3_1_0::tree::LeafNode::setValueOn
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don&#39;t change its value.
Definition: LeafNode.h:714
openvdb::v3_1_0::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:1903
openvdb::v3_1_0::tree::LeafNode::endValueOff
ValueOffIter endValueOff()
Definition: LeafNode.h:607
openvdb::v3_1_0::io::getHalfFloat
OPENVDB_API bool getHalfFloat(std::ios_base &)
Return true if floating-point values should be quantized to 16 bits when writing to the given stream ...
openvdb::v3_1_0::tree::IteratorBase
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
openvdb::v3_1_0::tree::LeafNode::Buffer::mData
ValueType * mData
Definition: LeafNode.h:359
openvdb::v3_1_0::tree::LeafNode::Ptr
boost::shared_ptr< LeafNode > Ptr
Definition: LeafNode.h:70
openvdb::v3_1_0::tree::LeafNode::merge
void merge(const LeafNode &)
Definition: LeafNode.h:1842
openvdb::v3_1_0::tree::LeafNode::ValueAll
Definition: LeafNode.h:504
openvdb::v3_1_0::tree::LeafNode::probeLeaf
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNode.h:1027
openvdb::v3_1_0::tree::LeafNode::ValueIter::ValueIter
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:517
openvdb::v3_1_0::tree::LeafNode::isConstant
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1749
openvdb::v3_1_0::tree::LeafNode::doVisit
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:2084
openvdb::v3_1_0::tree::LeafNode::stealNodes
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1006
openvdb::v3_1_0::tree::LeafNode::writeTopology
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1539
openvdb::v3_1_0::tree::LeafNode::setOrigin
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:470
openvdb::v3_1_0::util::NodeMask::save
void save(std::ostream &os) const
Definition: NodeMasks.h:551
openvdb::v3_1_0::tree::LeafNode::DenseIter::DenseIter
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: LeafNode.h:559
openvdb::v3_1_0::tree::LeafNode::setValueOnlyAndCache
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNode.h:840
openvdb::v3_1_0::tree::LeafNode::setValuesOff
void setValuesOff()
Mark all voxels as inactive but don&#39;t change their values.
Definition: LeafNode.h:760
openvdb::v3_1_0::tree::LeafNode::modifyValueAndActiveState
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:747
openvdb::v3_1_0::tree::LeafNode::probeConstLeafAndCache
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1035
openvdb::v3_1_0::MERGE_ACTIVE_STATES_AND_NODES
Definition: Types.h:260
openvdb::v3_1_0::tree::LeafNode::origin
const Coord & origin() const
Return the grid index coordinates of this node&#39;s local origin.
Definition: LeafNode.h:473