OpenVDB: NodeMasks.h Source File

OpenVDB 3.1.0

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

- File List
- File Members

NodeMasks.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 //
34
35 #ifndef OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
36 #define OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
37
38 #include <cassert>
39 #include <cstring>
40 #include <iostream>// for cout
41 #include <openvdb/Platform.h>
42 #include <openvdb/Types.h>
43 //#include <boost/mpl/if.hpp>
44 //#include <strings.h> // for ffs
45
46 namespace openvdb {
47 OPENVDB_USE_VERSION_NAMESPACE
48 namespace OPENVDB_VERSION_NAME {
49 namespace util {
50
52 inline Index32
53 CountOn(Byte v)
54 {
55 // Simple LUT:
56 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
57 static
58 #endif
59 const Byte numBits[256] = {
60 # define B2(n) n, n+1, n+1, n+2
61 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
62 # define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
63 B6(0), B6(1), B6(1), B6(2)
64 };
65 return numBits[v];
66
67 // Sequentially clear least significant bits
68 //Index32 c;
69 //for (c = 0; v; c++) v &= v - 0x01U;
70 //return c;
71
72 // This version is only fast on CPUs with fast "%" and "*" operations
73 //return (v * UINT64_C(0x200040008001) & UINT64_C(0x111111111111111)) % 0xF;
74 }
76 inline Index32 CountOff(Byte v) { return CountOn(static_cast<Byte>(~v)); }
77
79 inline Index32
80 CountOn(Index32 v)
81 {
82 v = v - ((v >> 1) & 0x55555555U);
83 v = (v & 0x33333333U) + ((v >> 2) & 0x33333333U);
84 return (((v + (v >> 4)) & 0xF0F0F0FU) * 0x1010101U) >> 24;
85 }
86
88 inline Index32 CountOff(Index32 v) { return CountOn(~v); }
89
91 inline Index32
92 CountOn(Index64 v)
93 {
94 v = v - ((v >> 1) & UINT64_C(0x5555555555555555));
95 v = (v & UINT64_C(0x3333333333333333)) + ((v >> 2) & UINT64_C(0x3333333333333333));
96 return static_cast<Index32>(
97 (((v + (v >> 4)) & UINT64_C(0xF0F0F0F0F0F0F0F)) * UINT64_C(0x101010101010101)) >> 56);
98 }
99
101 inline Index32 CountOff(Index64 v) { return CountOn(~v); }
102
104 inline Index32
105 FindLowestOn(Byte v)
106 {
107 assert(v);
108 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
109 static
110 #endif
111 const Byte DeBruijn[8] = {0, 1, 6, 2, 7, 5, 4, 3};
112 return DeBruijn[Byte((v & -v) * 0x1DU) >> 5];
113 }
114
116 inline Index32
117 FindLowestOn(Index32 v)
118 {
119 assert(v);
120 //return ffs(v);
121 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
122 static
123 #endif
124 const Byte DeBruijn[32] = {
125 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
126 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
127 };
128 return DeBruijn[Index32((v & -v) * 0x077CB531U) >> 27];
129 }
130
132 inline Index32
133 FindLowestOn(Index64 v)
134 {
135 assert(v);
136 //return ffsll(v);
137 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
138 static
139 #endif
140 const Byte DeBruijn[64] = {
141 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
142 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
143 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
144 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12,
145 };
146 return DeBruijn[Index64((v & -v) * UINT64_C(0x022FDD63CC95386D)) >> 58];
147 }
148
150 inline Index32
151 FindHighestOn(Index32 v)
152 {
153 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
154 static
155 #endif
156 const Byte DeBruijn[32] = {
157 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
158 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
159 };
160 v |= v >> 1; // first round down to one less than a power of 2
161 v |= v >> 2;
162 v |= v >> 4;
163 v |= v >> 8;
164 v |= v >> 16;
165 return DeBruijn[Index32(v * 0x07C4ACDDU) >> 27];
166 }
167
168
170
171
173 template <typename NodeMask>
174 class BaseMaskIterator
175 {
176 protected:
177 Index32 mPos;//bit position
178 const NodeMask* mParent;//this iterator can't change the parent_mask!
179 public:
180 BaseMaskIterator() : mPos(NodeMask::SIZE), mParent(NULL) {}
181 BaseMaskIterator(Index32 pos,const NodeMask *parent) : mPos(pos), mParent(parent)
182 {
183 assert( (parent==NULL && pos==0 ) || (parent!=NULL && pos<=NodeMask::SIZE) );
184 }
185 bool operator==(const BaseMaskIterator &iter) const {return mPos == iter.mPos;}
186 bool operator!=(const BaseMaskIterator &iter) const {return mPos != iter.mPos;}
187 bool operator< (const BaseMaskIterator &iter) const {return mPos < iter.mPos;}
188 BaseMaskIterator& operator=(const BaseMaskIterator& iter)
189 {
190 mPos = iter.mPos; mParent = iter.mParent; return *this;
191 }
192 Index32 offset() const {return mPos;}
193 Index32 pos() const {return mPos;}
194 bool test() const
195 {
196 assert(mPos <= NodeMask::SIZE);
197 return (mPos != NodeMask::SIZE);
198 }
199 operator bool() const {return this->test();}
200 }; // class BaseMaskIterator
201
202
204 template <typename NodeMask>
205 class OnMaskIterator: public BaseMaskIterator<NodeMask>
206 {
207 private:
208 typedef BaseMaskIterator<NodeMask> BaseType;
209 using BaseType::mPos;//bit position;
210 using BaseType::mParent;//this iterator can't change the parent_mask!
211 public:
212 OnMaskIterator() : BaseType() {}
213 OnMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
214 void increment()
215 {
216 assert(mParent != NULL);
217 mPos = mParent->findNextOn(mPos+1);
218 assert(mPos <= NodeMask::SIZE);
219 }
220 void increment(Index n) { while(n-- && this->next()) ; }
221 bool next()
222 {
223 this->increment();
224 return this->test();
225 }
226 bool operator*() const {return true;}
227 OnMaskIterator& operator++()
228 {
229 this->increment();
230 return *this;
231 }
232 }; // class OnMaskIterator
233
234
235 template <typename NodeMask>
236 class OffMaskIterator: public BaseMaskIterator<NodeMask>
237 {
238 private:
239 typedef BaseMaskIterator<NodeMask> BaseType;
240 using BaseType::mPos;//bit position;
241 using BaseType::mParent;//this iterator can't change the parent_mask!
242 public:
243 OffMaskIterator() : BaseType() {}
244 OffMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
245 void increment()
246 {
247 assert(mParent != NULL);
248 mPos=mParent->findNextOff(mPos+1);
249 assert(mPos <= NodeMask::SIZE);
250 }
251 void increment(Index n) { while(n-- && this->next()) ; }
252 bool next()
253 {
254 this->increment();
255 return this->test();
256 }
257 bool operator*() const {return false;}
258 OffMaskIterator& operator++()
259 {
260 this->increment();
261 return *this;
262 }
263 }; // class OffMaskIterator
264
265
266 template <typename NodeMask>
267 class DenseMaskIterator: public BaseMaskIterator<NodeMask>
268 {
269 private:
270 typedef BaseMaskIterator<NodeMask> BaseType;
271 using BaseType::mPos;//bit position;
272 using BaseType::mParent;//this iterator can't change the parent_mask!
273
274 public:
275 DenseMaskIterator() : BaseType() {}
276 DenseMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
277 void increment()
278 {
279 assert(mParent != NULL);
280 mPos += 1;//careful - the increment might go beyond the end
281 assert(mPos<= NodeMask::SIZE);
282 }
283 void increment(Index n) { while(n-- && this->next()) ; }
284 bool next()
285 {
286 this->increment();
287 return this->test();
288 }
289 bool operator*() const {return mParent->isOn(mPos);}
290 DenseMaskIterator& operator++()
291 {
292 this->increment();
293 return *this;
294 }
295 }; // class DenseMaskIterator
296
297
303 template<Index Log2Dim>
304 class NodeMask
305 {
306 public:
307 BOOST_STATIC_ASSERT( Log2Dim>2 );
308
309 static const Index32 LOG2DIM = Log2Dim;
310 static const Index32 DIM = 1<<Log2Dim;
311 static const Index32 SIZE = 1<<3*Log2Dim;
312 static const Index32 WORD_COUNT = SIZE >> 6;// 2^6=64
313 typedef Index64 Word;
314
315 private:
316
317 // The bits are represented as a linear array of Words, and the
318 // size of a Word is 32 or 64 bits depending on the platform.
319 // The BIT_MASK is defined as the number of bits in a Word - 1
320 //static const Index32 BIT_MASK = sizeof(void*) == 8 ? 63 : 31;
321 //static const Index32 LOG2WORD = BIT_MASK == 63 ? 6 : 5;
322 //static const Index32 WORD_COUNT = SIZE >> LOG2WORD;
323 //typedef boost::mpl::if_c<BIT_MASK == 63, Index64, Index32>::type Word;
324
325 Word mWords[WORD_COUNT];//only member data!
326
327 public:
329 NodeMask() { this->setOff(); }
331 NodeMask(bool on) { this->set(on); }
333 NodeMask(const NodeMask &other) { *this = other; }
335 ~NodeMask() {}
337 NodeMask& operator=(const NodeMask& other)
338 {
339 Index32 n = WORD_COUNT;
340 const Word* w2 = other.mWords;
341 for (Word* w1 = mWords; n--; ++w1, ++w2) *w1 = *w2;
342 return *this;
343 }
344
345 typedef OnMaskIterator<NodeMask> OnIterator;
346 typedef OffMaskIterator<NodeMask> OffIterator;
347 typedef DenseMaskIterator<NodeMask> DenseIterator;
348
349 OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
350 OnIterator endOn() const { return OnIterator(SIZE,this); }
351 OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
352 OffIterator endOff() const { return OffIterator(SIZE,this); }
353 DenseIterator beginDense() const { return DenseIterator(0,this); }
354 DenseIterator endDense() const { return DenseIterator(SIZE,this); }
355
356 bool operator == (const NodeMask &other) const
357 {
358 int n = WORD_COUNT;
359 for (const Word *w1=mWords, *w2=other.mWords; n-- && *w1++ == *w2++;) ;
360 return n == -1;
361 }
362
363 bool operator != (const NodeMask &other) const { return !(*this == other); }
364
365 //
366 // Bitwise logical operations
367 //
368
375 template<typename WordOp>
376 const NodeMask& foreach(const NodeMask& other, const WordOp& op)
377 {
378 Word *w1 = mWords;
379 const Word *w2 = other.mWords;
380 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2) op( *w1, *w2);
381 return *this;
382 }
383 template<typename WordOp>
384 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const WordOp& op)
385 {
386 Word *w1 = mWords;
387 const Word *w2 = other1.mWords, *w3 = other2.mWords;
388 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2, ++w3) op( *w1, *w2, *w3);
389 return *this;
390 }
391 template<typename WordOp>
392 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const NodeMask& other3,
393 const WordOp& op)
394 {
395 Word *w1 = mWords;
396 const Word *w2 = other1.mWords, *w3 = other2.mWords, *w4 = other3.mWords;
397 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2, ++w3, ++w4) op( *w1, *w2, *w3, *w4);
398 return *this;
399 }
401 const NodeMask& operator&=(const NodeMask& other)
402 {
403 Word *w1 = mWords;
404 const Word *w2 = other.mWords;
405 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2) *w1 &= *w2;
406 return *this;
407 }
409 const NodeMask& operator|=(const NodeMask& other)
410 {
411 Word *w1 = mWords;
412 const Word *w2 = other.mWords;
413 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2) *w1 |= *w2;
414 return *this;
415 }
417 const NodeMask& operator-=(const NodeMask& other)
418 {
419 Word *w1 = mWords;
420 const Word *w2 = other.mWords;
421 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2) *w1 &= ~*w2;
422 return *this;
423 }
425 const NodeMask& operator^=(const NodeMask& other)
426 {
427 Word *w1 = mWords;
428 const Word *w2 = other.mWords;
429 for (Index32 n = WORD_COUNT; n--; ++w1, ++w2) *w1 ^= *w2;
430 return *this;
431 }
432 NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
433 NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
434 NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
435 NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
436
438 static Index32 memUsage() { return static_cast<Index32>(WORD_COUNT*sizeof(Word)); }
440 Index32 countOn() const
441 {
442 Index32 sum = 0, n = WORD_COUNT;
443 for (const Word* w = mWords; n--; ++w) sum += CountOn(*w);
444 return sum;
445 }
447 Index32 countOff() const { return SIZE-this->countOn(); }
449 void setOn(Index32 n) {
450 assert( (n >> 6) < WORD_COUNT );
451 mWords[n >> 6] |= Word(1) << (n & 63);
452 }
454 void setOff(Index32 n) {
455 assert( (n >> 6) < WORD_COUNT );
456 mWords[n >> 6] &= ~(Word(1) << (n & 63));
457 }
459 void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
461 void set(bool on)
462 {
463 const Word state = on ? ~Word(0) : Word(0);
464 Index32 n = WORD_COUNT;
465 for (Word* w = mWords; n--; ++w) *w = state;
466 }
468 void setOn()
469 {
470 Index32 n = WORD_COUNT;
471 for (Word* w = mWords; n--; ++w) *w = ~Word(0);
472 }
474 void setOff()
475 {
476 Index32 n = WORD_COUNT;
477 for (Word* w = mWords; n--; ++w) *w = Word(0);
478 }
480 void toggle(Index32 n) {
481 assert( (n >> 6) < WORD_COUNT );
482 mWords[n >> 6] ^= Word(1) << (n & 63);
483 }
485 void toggle()
486 {
487 Index32 n = WORD_COUNT;
488 for (Word* w = mWords; n--; ++w) *w = ~*w;
489 }
491 void setFirstOn() { this->setOn(0); }
493 void setLastOn() { this->setOn(SIZE-1); }
495 void setFirstOff() { this->setOff(0); }
497 void setLastOff() { this->setOff(SIZE-1); }
499 bool isOn(Index32 n) const
500 {
501 assert( (n >> 6) < WORD_COUNT );
502 return 0 != (mWords[n >> 6] & (Word(1) << (n & 63)));
503 }
505 bool isOff(Index32 n) const {return !this->isOn(n); }
507 bool isOn() const
508 {
509 int n = WORD_COUNT;
510 for (const Word *w = mWords; n-- && *w++ == ~Word(0);) ;
511 return n == -1;
512 }
514 bool isOff() const
515 {
516 int n = WORD_COUNT;
517 for (const Word *w = mWords; n-- && *w++ == Word(0);) ;
518 return n == -1;
519 }
520 Index32 findFirstOn() const
521 {
522 Index32 n = 0;
523 const Word* w = mWords;
524 for (; n<WORD_COUNT && !*w; ++w, ++n) ;
525 return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(*w);
526 }
527 Index32 findFirstOff() const
528 {
529 Index32 n = 0;
530 const Word* w = mWords;
531 for (; n<WORD_COUNT && !~*w; ++w, ++n) ;
532 return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(~*w);
533 }
534
536 template<typename WordT>
538 WordT getWord(Index n) const
539 {
540 assert(n*8*sizeof(WordT) < SIZE);
541 return reinterpret_cast<const WordT*>(mWords)[n];
542 }
543 template<typename WordT>
544 WordT& getWord(Index n)
545 {
546 assert(n*8*sizeof(WordT) < SIZE);
547 return reinterpret_cast<WordT*>(mWords)[n];
548 }
550
551 void save(std::ostream& os) const
552 {
553 os.write(reinterpret_cast<const char*>(mWords), this->memUsage());
554 }
555 void load(std::istream& is) {
556 is.read(reinterpret_cast<char*>(mWords), this->memUsage());
557 }
559 void printInfo(std::ostream& os=std::cout) const
560 {
561 os << "NodeMask: Dim=" << DIM << " Log2Dim=" << Log2Dim
562 << " Bit count=" << SIZE << " word count=" << WORD_COUNT << std::endl;
563 }
564 void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const
565 {
566 const Index32 n=(SIZE>max_out ? max_out : SIZE);
567 for (Index32 i=0; i < n; ++i) {
568 if ( !(i & 63) )
569 os << "||";
570 else if ( !(i%8) )
571 os << "|";
572 os << this->isOn(i);
573 }
574 os << "|" << std::endl;
575 }
576 void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const
577 {
578 this->printInfo(os);
579 this->printBits(os, max_out);
580 }
581
582 Index32 findNextOn(Index32 start) const
583 {
584 Index32 n = start >> 6;//initiate
585 if (n >= WORD_COUNT) return SIZE; // check for out of bounds
586 Index32 m = start & 63;
587 Word b = mWords[n];
588 if (b & (Word(1) << m)) return start;//simpel case: start is on
589 b &= ~Word(0) << m;// mask out lower bits
590 while(!b && ++n<WORD_COUNT) b = mWords[n];// find next none-zero word
591 return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
592 }
593
594 Index32 findNextOff(Index32 start) const
595 {
596 Index32 n = start >> 6;//initiate
597 if (n >= WORD_COUNT) return SIZE; // check for out of bounds
598 Index32 m = start & 63;
599 Word b = ~mWords[n];
600 if (b & (Word(1) << m)) return start;//simpel case: start is on
601 b &= ~Word(0) << m;// mask out lower bits
602 while(!b && ++n<WORD_COUNT) b = ~mWords[n];// find next none-zero word
603 return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
604 }
605 };// NodeMask
606
607
609 template<>
610 class NodeMask<1>
611 {
612 public:
613
614 static const Index32 LOG2DIM = 1;
615 static const Index32 DIM = 2;
616 static const Index32 SIZE = 8;
617 static const Index32 WORD_COUNT = 1;
618 typedef Byte Word;
619
620 private:
621
622 Byte mByte;//only member data!
623
624 public:
626 NodeMask() : mByte(0x00U) {}
628 NodeMask(bool on) : mByte(on ? 0xFFU : 0x00U) {}
630 NodeMask(const NodeMask &other) : mByte(other.mByte) {}
632 ~NodeMask() {}
634 void operator = (const NodeMask &other) { mByte = other.mByte; }
635
636 typedef OnMaskIterator<NodeMask> OnIterator;
637 typedef OffMaskIterator<NodeMask> OffIterator;
638 typedef DenseMaskIterator<NodeMask> DenseIterator;
639
640 OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
641 OnIterator endOn() const { return OnIterator(SIZE,this); }
642 OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
643 OffIterator endOff() const { return OffIterator(SIZE,this); }
644 DenseIterator beginDense() const { return DenseIterator(0,this); }
645 DenseIterator endDense() const { return DenseIterator(SIZE,this); }
646
647 bool operator == (const NodeMask &other) const { return mByte == other.mByte; }
648
649 bool operator != (const NodeMask &other) const {return mByte != other.mByte; }
650
651 //
652 // Bitwise logical operations
653 //
654
661 template<typename WordOp>
662 const NodeMask& foreach(const NodeMask& other, const WordOp& op)
663 {
664 op(mByte, other.mByte);
665 return *this;
666 }
667 template<typename WordOp>
668 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const WordOp& op)
669 {
670 op(mByte, other1.mByte, other2.mByte);
671 return *this;
672 }
673 template<typename WordOp>
674 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const NodeMask& other3,
675 const WordOp& op)
676 {
677 op(mByte, other1.mByte, other2.mByte, other3.mByte);
678 return *this;
679 }
681 const NodeMask& operator&=(const NodeMask& other)
682 {
683 mByte &= other.mByte;
684 return *this;
685 }
687 const NodeMask& operator|=(const NodeMask& other)
688 {
689 mByte |= other.mByte;
690 return *this;
691 }
693 const NodeMask& operator-=(const NodeMask& other)
694 {
695 mByte &= static_cast<Byte>(~other.mByte);
696 return *this;
697 }
699 const NodeMask& operator^=(const NodeMask& other)
700 {
701 mByte ^= other.mByte;
702 return *this;
703 }
704 NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
705 NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
706 NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
707 NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
709 static Index32 memUsage() { return 1; }
711 Index32 countOn() const { return CountOn(mByte); }
713 Index32 countOff() const { return CountOff(mByte); }
715 void setOn(Index32 n) {
716 assert( n < 8 );
717 mByte = mByte | static_cast<Byte>(0x01U << (n & 7));
718 }
720 void setOff(Index32 n) {
721 assert( n < 8 );
722 mByte = mByte & static_cast<Byte>(~(0x01U << (n & 7)));
723 }
725 void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
727 void set(bool on) { mByte = on ? 0xFFU : 0x00U; }
729 void setOn() { mByte = 0xFFU; }
731 void setOff() { mByte = 0x00U; }
733 void toggle(Index32 n) {
734 assert( n < 8 );
735 mByte = mByte ^ static_cast<Byte>(0x01U << (n & 7));
736 }
738 void toggle() { mByte = static_cast<Byte>(~mByte); }
740 void setFirstOn() { this->setOn(0); }
742 void setLastOn() { this->setOn(7); }
744 void setFirstOff() { this->setOff(0); }
746 void setLastOff() { this->setOff(7); }
748 bool isOn(Index32 n) const
749 {
750 assert( n < 8 );
751 return mByte & (0x01U << (n & 7));
752 }
754 bool isOff(Index32 n) const {return !this->isOn(n); }
756 bool isOn() const { return mByte == 0xFFU; }
758 bool isOff() const { return mByte == 0; }
759 Index32 findFirstOn() const { return mByte ? FindLowestOn(mByte) : 8; }
760 Index32 findFirstOff() const
761 {
762 const Byte b = static_cast<Byte>(~mByte);
763 return b ? FindLowestOn(b) : 8;
764 }
765 /*
767 template<typename WordT>
770 WordT getWord(Index n) const
771 {
772 BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
773 assert(n == 0);
774 return reinterpret_cast<WordT>(mByte);
775 }
776 template<typename WordT>
777 WordT& getWord(Index n)
778 {
779 BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
780 assert(n == 0);
781 return reinterpret_cast<WordT&>(mByte);
782 }
784 */
785 void save(std::ostream& os) const
786 {
787 os.write(reinterpret_cast<const char*>(&mByte), 1);
788 }
789 void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mByte), 1); }
791 void printInfo(std::ostream& os=std::cout) const
792 {
793 os << "NodeMask: Dim=2, Log2Dim=1, Bit count=8, Word count=1"<<std::endl;
794 }
795 void printBits(std::ostream& os=std::cout) const
796 {
797 os << "||";
798 for (Index32 i=0; i < 8; ++i) os << this->isOn(i);
799 os << "||" << std::endl;
800 }
801 void printAll(std::ostream& os=std::cout) const
802 {
803 this->printInfo(os);
804 this->printBits(os);
805 }
806
807 Index32 findNextOn(Index32 start) const
808 {
809 if (start>=8) return 8;
810 const Byte b = static_cast<Byte>(mByte & (0xFFU << start));
811 return b ? FindLowestOn(b) : 8;
812 }
813
814 Index32 findNextOff(Index32 start) const
815 {
816 if (start>=8) return 8;
817 const Byte b = static_cast<Byte>(~mByte & (0xFFU << start));
818 return b ? FindLowestOn(b) : 8;
819 }
820
821 };// NodeMask<1>
822
823
825 template<>
826 class NodeMask<2>
827 {
828 public:
829
830 static const Index32 LOG2DIM = 2;
831 static const Index32 DIM = 4;
832 static const Index32 SIZE = 64;
833 static const Index32 WORD_COUNT = 1;
834 typedef Index64 Word;
835
836 private:
837
838 Word mWord;//only member data!
839
840 public:
842 NodeMask() : mWord(UINT64_C(0x00)) {}
844 NodeMask(bool on) : mWord(on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00)) {}
846 NodeMask(const NodeMask &other) : mWord(other.mWord) {}
848 ~NodeMask() {}
850 void operator = (const NodeMask &other) { mWord = other.mWord; }
851
852 typedef OnMaskIterator<NodeMask> OnIterator;
853 typedef OffMaskIterator<NodeMask> OffIterator;
854 typedef DenseMaskIterator<NodeMask> DenseIterator;
855
856 OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
857 OnIterator endOn() const { return OnIterator(SIZE,this); }
858 OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
859 OffIterator endOff() const { return OffIterator(SIZE,this); }
860 DenseIterator beginDense() const { return DenseIterator(0,this); }
861 DenseIterator endDense() const { return DenseIterator(SIZE,this); }
862
863 bool operator == (const NodeMask &other) const { return mWord == other.mWord; }
864
865 bool operator != (const NodeMask &other) const {return mWord != other.mWord; }
866
867 //
868 // Bitwise logical operations
869 //
870
877 template<typename WordOp>
878 const NodeMask& foreach(const NodeMask& other, const WordOp& op)
879 {
880 op(mWord, other.mWord);
881 return *this;
882 }
883 template<typename WordOp>
884 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const WordOp& op)
885 {
886 op(mWord, other1.mWord, other2.mWord);
887 return *this;
888 }
889 template<typename WordOp>
890 const NodeMask& foreach(const NodeMask& other1, const NodeMask& other2, const NodeMask& other3,
891 const WordOp& op)
892 {
893 op(mWord, other1.mWord, other2.mWord, other3.mWord);
894 return *this;
895 }
897 const NodeMask& operator&=(const NodeMask& other)
898 {
899 mWord &= other.mWord;
900 return *this;
901 }
903 const NodeMask& operator|=(const NodeMask& other)
904 {
905 mWord |= other.mWord;
906 return *this;
907 }
909 const NodeMask& operator-=(const NodeMask& other)
910 {
911 mWord &= ~other.mWord;
912 return *this;
913 }
915 const NodeMask& operator^=(const NodeMask& other)
916 {
917 mWord ^= other.mWord;
918 return *this;
919 }
920 NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
921 NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
922 NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
923 NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
925 static Index32 memUsage() { return 8; }
927 Index32 countOn() const { return CountOn(mWord); }
929 Index32 countOff() const { return CountOff(mWord); }
931 void setOn(Index32 n) {
932 assert( n < 64 );
933 mWord |= UINT64_C(0x01) << (n & 63);
934 }
936 void setOff(Index32 n) {
937 assert( n < 64 );
938 mWord &= ~(UINT64_C(0x01) << (n & 63));
939 }
941 void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
943 void set(bool on) { mWord = on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00); }
945 void setOn() { mWord = UINT64_C(0xFFFFFFFFFFFFFFFF); }
947 void setOff() { mWord = UINT64_C(0x00); }
949 void toggle(Index32 n) {
950 assert( n < 64 );
951 mWord ^= UINT64_C(0x01) << (n & 63);
952 }
954 void toggle() { mWord = ~mWord; }
956 void setFirstOn() { this->setOn(0); }
958 void setLastOn() { this->setOn(63); }
960 void setFirstOff() { this->setOff(0); }
962 void setLastOff() { this->setOff(63); }
964 bool isOn(Index32 n) const
965 {
966 assert( n < 64 );
967 return 0 != (mWord & (UINT64_C(0x01) << (n & 63)));
968 }
970 bool isOff(Index32 n) const {return !this->isOn(n); }
972 bool isOn() const { return mWord == UINT64_C(0xFFFFFFFFFFFFFFFF); }
974 bool isOff() const { return mWord == 0; }
975 Index32 findFirstOn() const { return mWord ? FindLowestOn(mWord) : 64; }
976 Index32 findFirstOff() const
977 {
978 const Word w = ~mWord;
979 return w ? FindLowestOn(w) : 64;
980 }
982 template<typename WordT>
984 WordT getWord(Index n) const
985 {
986 assert(n*8*sizeof(WordT) < SIZE);
987 return reinterpret_cast<const WordT*>(&mWord)[n];
988 }
989 template<typename WordT>
990 WordT& getWord(Index n)
991 {
992 assert(n*8*sizeof(WordT) < SIZE);
993 return reinterpret_cast<WordT*>(mWord)[n];
994 }
996 void save(std::ostream& os) const
997 {
998 os.write(reinterpret_cast<const char*>(&mWord), 8);
999 }
1000 void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mWord), 8); }
1002 void printInfo(std::ostream& os=std::cout) const
1003 {
1004 os << "NodeMask: Dim=4, Log2Dim=2, Bit count=64, Word count=1"<<std::endl;
1005 }
1006 void printBits(std::ostream& os=std::cout) const
1007 {
1008 os << "|";
1009 for (Index32 i=0; i < 64; ++i) {
1010 if ( !(i%8) ) os << "|";
1011 os << this->isOn(i);
1012 }
1013 os << "||" << std::endl;
1014 }
1015 void printAll(std::ostream& os=std::cout) const
1016 {
1017 this->printInfo(os);
1018 this->printBits(os);
1019 }
1020
1021 Index32 findNextOn(Index32 start) const
1022 {
1023 if (start>=64) return 64;
1024 const Word w = mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
1025 return w ? FindLowestOn(w) : 64;
1026 }
1027
1028 Index32 findNextOff(Index32 start) const
1029 {
1030 if (start>=64) return 64;
1031 const Word w = ~mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
1032 return w ? FindLowestOn(w) : 64;
1033 }
1034
1035 };// NodeMask<2>
1036
1037
1038 // Unlike NodeMask above this RootNodeMask has a run-time defined size.
1039 // It is only included for backward compatibility and will likely be
1040 // deprecated in the future!
1041 // This class is 32-bit specefic, hence the use if Index32 vs Index!
1042 class RootNodeMask
1043 {
1044 protected:
1045 Index32 mBitSize, mIntSize;
1046 Index32 *mBits;
1047
1048 public:
1049 RootNodeMask(): mBitSize(0), mIntSize(0), mBits(NULL) {}
1050 RootNodeMask(Index32 bit_size):
1051 mBitSize(bit_size), mIntSize(((bit_size-1)>>5)+1), mBits(new Index32[mIntSize])
1052 {
1053 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1054 }
1055 RootNodeMask(const RootNodeMask& B):
1056 mBitSize(B.mBitSize), mIntSize(B.mIntSize), mBits(new Index32[mIntSize])
1057 {
1058 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
1059 }
1060 ~RootNodeMask() {delete [] mBits;}
1061
1062 void init(Index32 bit_size) {
1063 mBitSize = bit_size;
1064 mIntSize =((bit_size-1)>>5)+1;
1065 delete [] mBits;
1066 mBits = new Index32[mIntSize];
1067 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1068 }
1069
1070 Index getBitSize() const {return mBitSize;}
1071
1072 Index getIntSize() const {return mIntSize;}
1073
1074 RootNodeMask& operator=(const RootNodeMask& B) {
1075 if (mBitSize!=B.mBitSize) {
1076 mBitSize=B.mBitSize;
1077 mIntSize=B.mIntSize;
1078 delete [] mBits;
1079 mBits = new Index32[mIntSize];
1080 }
1081 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
1082 return *this;
1083 }
1084
1085 class BaseIterator
1086 {
1087 protected:
1088 Index32 mPos;//bit position
1089 Index32 mBitSize;
1090 const RootNodeMask* mParent;//this iterator can't change the parent_mask!
1091 public:
1092 BaseIterator() : mPos(0), mBitSize(0), mParent(NULL) {}
1093 BaseIterator(Index32 pos,const RootNodeMask *parent)
1094 : mPos(pos), mBitSize(parent->getBitSize()), mParent(parent) {
1095 assert( pos<=mBitSize );
1096 }
1097 bool operator==(const BaseIterator &iter) const {return mPos == iter.mPos;}
1098 bool operator!=(const BaseIterator &iter) const {return mPos != iter.mPos;}
1099 bool operator< (const BaseIterator &iter) const {return mPos < iter.mPos;}
1100 BaseIterator& operator=(const BaseIterator& iter) {
1101 mPos = iter.mPos;
1102 mBitSize = iter.mBitSize;
1103 mParent = iter.mParent;
1104 return *this;
1105 }
1106
1107 Index32 offset() const {return mPos;}
1108
1109 Index32 pos() const {return mPos;}
1110
1111 bool test() const {
1112 assert(mPos <= mBitSize);
1113 return (mPos != mBitSize);
1114 }
1115
1116 operator bool() const {return this->test();}
1117 }; // class BaseIterator
1118
1120 class OnIterator: public BaseIterator
1121 {
1122 protected:
1123 using BaseIterator::mPos;//bit position;
1124 using BaseIterator::mBitSize;//bit size;
1125 using BaseIterator::mParent;//this iterator can't change the parent_mask!
1126 public:
1127 OnIterator() : BaseIterator() {}
1128 OnIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1129 void increment() {
1130 assert(mParent!=NULL);
1131 mPos=mParent->findNextOn(mPos+1);
1132 assert(mPos <= mBitSize);
1133 }
1134 void increment(Index n) {
1135 for (Index i=0; i<n && this->next(); ++i) {}
1136 }
1137 bool next() {
1138 this->increment();
1139 return this->test();
1140 }
1141 bool operator*() const {return true;}
1142 OnIterator& operator++() {
1143 this->increment();
1144 return *this;
1145 }
1146 }; // class OnIterator
1147
1148 class OffIterator: public BaseIterator
1149 {
1150 protected:
1151 using BaseIterator::mPos;//bit position;
1152 using BaseIterator::mBitSize;//bit size;
1153 using BaseIterator::mParent;//this iterator can't change the parent_mask!
1154 public:
1155 OffIterator() : BaseIterator() {}
1156 OffIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1157 void increment() {
1158 assert(mParent!=NULL);
1159 mPos=mParent->findNextOff(mPos+1);
1160 assert(mPos <= mBitSize);
1161 }
1162 void increment(Index n) {
1163 for (Index i=0; i<n && this->next(); ++i) {}
1164 }
1165 bool next() {
1166 this->increment();
1167 return this->test();
1168 }
1169 bool operator*() const {return true;}
1170 OffIterator& operator++() {
1171 this->increment();
1172 return *this;
1173 }
1174 }; // class OffIterator
1175
1176 class DenseIterator: public BaseIterator
1177 {
1178 protected:
1179 using BaseIterator::mPos;//bit position;
1180 using BaseIterator::mBitSize;//bit size;
1181 using BaseIterator::mParent;//this iterator can't change the parent_mask!
1182 public:
1183 DenseIterator() : BaseIterator() {}
1184 DenseIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1185 void increment() {
1186 assert(mParent!=NULL);
1187 mPos += 1;//carefull - the increament might go beyond the end
1188 assert(mPos<= mBitSize);
1189 }
1190 void increment(Index n) {
1191 for (Index i=0; i<n && this->next(); ++i) {}
1192 }
1193 bool next() {
1194 this->increment();
1195 return this->test();
1196 }
1197 bool operator*() const {return mParent->isOn(mPos);}
1198 DenseIterator& operator++() {
1199 this->increment();
1200 return *this;
1201 }
1202 }; // class DenseIterator
1203
1204 OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
1205 OnIterator endOn() const { return OnIterator(mBitSize,this); }
1206 OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
1207 OffIterator endOff() const { return OffIterator(mBitSize,this); }
1208 DenseIterator beginDense() const { return DenseIterator(0,this); }
1209 DenseIterator endDense() const { return DenseIterator(mBitSize,this); }
1210
1211 bool operator == (const RootNodeMask &B) const {
1212 if (mBitSize != B.mBitSize) return false;
1213 for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return false;
1214 return true;
1215 }
1216
1217 bool operator != (const RootNodeMask &B) const {
1218 if (mBitSize != B.mBitSize) return true;
1219 for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return true;
1220 return false;
1221 }
1222
1223 //
1224 // Bitwise logical operations
1225 //
1226 RootNodeMask operator!() const { RootNodeMask m = *this; m.toggle(); return m; }
1227 const RootNodeMask& operator&=(const RootNodeMask& other) {
1228 assert(mIntSize == other.mIntSize);
1229 for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1230 mBits[i] &= other.mBits[i];
1231 }
1232 for (Index32 i = other.mIntSize; i < mIntSize; ++i) mBits[i] = 0x00000000;
1233 return *this;
1234 }
1235 const RootNodeMask& operator|=(const RootNodeMask& other) {
1236 assert(mIntSize == other.mIntSize);
1237 for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1238 mBits[i] |= other.mBits[i];
1239 }
1240 return *this;
1241 }
1242 const RootNodeMask& operator^=(const RootNodeMask& other) {
1243 assert(mIntSize == other.mIntSize);
1244 for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1245 mBits[i] ^= other.mBits[i];
1246 }
1247 return *this;
1248 }
1249 RootNodeMask operator&(const RootNodeMask& other) const {
1250 RootNodeMask m(*this); m &= other; return m;
1251 }
1252 RootNodeMask operator|(const RootNodeMask& other) const {
1253 RootNodeMask m(*this); m |= other; return m;
1254 }
1255 RootNodeMask operator^(const RootNodeMask& other) const {
1256 RootNodeMask m(*this); m ^= other; return m;
1257 }
1258
1259
1260 Index32 getMemUsage() const {
1261 return static_cast<Index32>(mIntSize*sizeof(Index32) + sizeof(*this));
1262 }
1263
1264 Index32 countOn() const {
1265 assert(mBits);
1266 Index32 n=0;
1267 for (Index32 i=0; i< mIntSize; ++i) n += CountOn(mBits[i]);
1268 return n;
1269 }
1270
1271 Index32 countOff() const { return mBitSize-this->countOn(); }
1272
1273 void setOn(Index32 i) {
1274 assert(mBits);
1275 assert( (i>>5) < mIntSize);
1276 mBits[i>>5] |= 1<<(i&31);
1277 }
1278
1279 void setOff(Index32 i) {
1280 assert(mBits);
1281 assert( (i>>5) < mIntSize);
1282 mBits[i>>5] &= ~(1<<(i&31));
1283 }
1284
1285 void set(Index32 i, bool On) { On ? this->setOn(i) : this->setOff(i); }
1286
1287 void setOn() {
1288 assert(mBits);
1289 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0xFFFFFFFF;
1290 }
1291 void setOff() {
1292 assert(mBits);
1293 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1294 }
1295 void toggle(Index32 i) {
1296 assert(mBits);
1297 assert( (i>>5) < mIntSize);
1298 mBits[i>>5] ^= 1<<(i&31);
1299 }
1300 void toggle() {
1301 assert(mBits);
1302 for (Index32 i=0; i<mIntSize; ++i) mBits[i]=~mBits[i];
1303 }
1304 void setFirstOn() { this->setOn(0); }
1305 void setLastOn() { this->setOn(mBitSize-1); }
1306 void setFirstOff() { this->setOff(0); }
1307 void setLastOff() { this->setOff(mBitSize-1); }
1308 bool isOn(Index32 i) const {
1309 assert(mBits);
1310 assert( (i>>5) < mIntSize);
1311 return ( mBits[i >> 5] & (1<<(i&31)) );
1312 }
1313 bool isOff(Index32 i) const {
1314 assert(mBits);
1315 assert( (i>>5) < mIntSize);
1316 return ( ~mBits[i >> 5] & (1<<(i&31)) );
1317 }
1318
1319 bool isOn() const {
1320 if (!mBits) return false;//undefined is off
1321 for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0xFFFFFFFF) return false;
1322 return true;
1323 }
1324
1325 bool isOff() const {
1326 if (!mBits) return true;//undefined is off
1327 for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0) return false;
1328 return true;
1329 }
1330
1331 Index32 findFirstOn() const {
1332 assert(mBits);
1333 Index32 i=0;
1334 while(!mBits[i]) if (++i == mIntSize) return mBitSize;//reached end
1335 return 32*i + FindLowestOn(mBits[i]);
1336 }
1337
1338 Index32 findFirstOff() const {
1339 assert(mBits);
1340 Index32 i=0;
1341 while(!(~mBits[i])) if (++i == mIntSize) return mBitSize;//reached end
1342 return 32*i + FindLowestOn(~mBits[i]);
1343 }
1344
1345 void save(std::ostream& os) const {
1346 assert(mBits);
1347 os.write((const char *)mBits,mIntSize*sizeof(Index32));
1348 }
1349 void load(std::istream& is) {
1350 assert(mBits);
1351 is.read((char *)mBits,mIntSize*sizeof(Index32));
1352 }
1354 void printInfo(std::ostream& os=std::cout) const {
1355 os << "RootNodeMask: Bit-size="<<mBitSize<<" Int-size="<<mIntSize<<std::endl;
1356 }
1357
1358 void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const {
1359 const Index32 n=(mBitSize>max_out?max_out:mBitSize);
1360 for (Index32 i=0; i < n; ++i) {
1361 if ( !(i&31) )
1362 os << "||";
1363 else if ( !(i%8) )
1364 os << "|";
1365 os << this->isOn(i);
1366 }
1367 os << "|" << std::endl;
1368 }
1369
1370 void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const {
1371 this->printInfo(os);
1372 this->printBits(os,max_out);
1373 }
1374
1375 Index32 findNextOn(Index32 start) const {
1376 assert(mBits);
1377 Index32 n = start >> 5, m = start & 31;//initiate
1378 if (n>=mIntSize) return mBitSize; // check for out of bounds
1379 Index32 b = mBits[n];
1380 if (b & (1<<m)) return start;//simple case
1381 b &= 0xFFFFFFFF << m;// mask lower bits
1382 while(!b && ++n<mIntSize) b = mBits[n];// find next nonzero int
1383 return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1384 }
1385
1386 Index32 findNextOff(Index32 start) const {
1387 assert(mBits);
1388 Index32 n = start >> 5, m = start & 31;//initiate
1389 if (n>=mIntSize) return mBitSize; // check for out of bounds
1390 Index32 b = ~mBits[n];
1391 if (b & (1<<m)) return start;//simple case
1392 b &= 0xFFFFFFFF<<m;// mask lower bits
1393 while(!b && ++n<mIntSize) b = ~mBits[n];// find next nonzero int
1394 return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1395 }
1396
1397 Index32 memUsage() const {
1398 assert(mBits);
1399 return static_cast<Index32>(sizeof(Index32*)+(2+mIntSize)*sizeof(Index32));//in bytes
1400 }
1401 }; // class RootNodeMask
1402
1403 } // namespace util
1404 } // namespace OPENVDB_VERSION_NAME
1405 } // namespace openvdb
1406
1407 #endif // OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
1408
1409 // Copyright (c) 2012-2015 DreamWorks Animation LLC
1410 // All rights reserved. This software is distributed under the
1411 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v3_1_0::util::NodeMask::isOn
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:507
openvdb::v3_1_0::util::NodeMask< 2 >::operator^=
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:915
openvdb::v3_1_0::util::NodeMask< 1 >::NodeMask
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:626
openvdb::v3_1_0::util::NodeMask< 1 >::isOn
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:756
openvdb::v3_1_0::util::NodeMask::countOff
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:447
openvdb::v3_1_0::util::NodeMask< 1 >::endDense
DenseIterator endDense() const
Definition: NodeMasks.h:645
openvdb::v3_1_0::util::NodeMask::operator-=
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:417
openvdb::v3_1_0::util::RootNodeMask
Definition: NodeMasks.h:1042
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::util::RootNodeMask::OnIterator::operator++
OnIterator & operator++()
Definition: NodeMasks.h:1142
openvdb::v3_1_0::util::NodeMask< 2 >::operator^
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:923
openvdb::v3_1_0::util::NodeMask< 1 >::operator^=
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:699
openvdb::v3_1_0::util::NodeMask< 2 >::endDense
DenseIterator endDense() const
Definition: NodeMasks.h:861
openvdb::v3_1_0::util::NodeMask< 1 >::OffIterator
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:637
openvdb::v3_1_0::util::BaseMaskIterator::operator!=
bool operator!=(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:186
openvdb::v3_1_0::util::NodeMask< 1 >::operator^
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:707
Types.h
openvdb::v3_1_0::util::RootNodeMask::load
void load(std::istream &is)
Definition: NodeMasks.h:1349
openvdb::v3_1_0::util::NodeMask< 2 >::OffIterator
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:853
openvdb::v3_1_0::util::RootNodeMask::countOn
Index32 countOn() const
Definition: NodeMasks.h:1264
openvdb::v3_1_0::Byte
unsigned char Byte
Definition: Types.h:63
openvdb::v3_1_0::util::CountOff
Index32 CountOff(Index64 v)
Return the number of off bits in the given 64-bit value.
Definition: NodeMasks.h:101
openvdb::v3_1_0::util::RootNodeMask::endOn
OnIterator endOn() const
Definition: NodeMasks.h:1205
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::increment
void increment()
Definition: NodeMasks.h:1185
openvdb::v3_1_0::util::NodeMask::findNextOn
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:582
openvdb::v3_1_0::util::NodeMask< 2 >::isOn
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:972
openvdb::v3_1_0::util::OffMaskIterator::next
bool next()
Definition: NodeMasks.h:252
openvdb::v3_1_0::util::NodeMask::findFirstOff
Index32 findFirstOff() const
Definition: NodeMasks.h:527
openvdb::v3_1_0::util::OnMaskIterator::increment
void increment()
Definition: NodeMasks.h:214
openvdb::v3_1_0::util::NodeMask::setLastOn
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:493
openvdb::v3_1_0::util::RootNodeMask::findFirstOn
Index32 findFirstOn() const
Definition: NodeMasks.h:1331
openvdb::v3_1_0::util::OnMaskIterator::OnMaskIterator
OnMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:213
openvdb::v3_1_0::util::BaseMaskIterator::pos
Index32 pos() const
Definition: NodeMasks.h:193
openvdb::v3_1_0::util::FindHighestOn
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:151
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::increment
void increment(Index n)
Definition: NodeMasks.h:1190
openvdb::v3_1_0::util::NodeMask< 2 >::NodeMask
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:846
openvdb::v3_1_0::util::NodeMask::endOff
OffIterator endOff() const
Definition: NodeMasks.h:352
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
openvdb::v3_1_0::util::RootNodeMask::OnIterator::operator*
bool operator*() const
Definition: NodeMasks.h:1141
openvdb::v3_1_0::util::RootNodeMask::OnIterator::increment
void increment()
Definition: NodeMasks.h:1129
openvdb::v3_1_0::util::RootNodeMask::operator^
RootNodeMask operator^(const RootNodeMask &other) const
Definition: NodeMasks.h:1255
openvdb::v3_1_0::util::RootNodeMask::OffIterator::operator++
OffIterator & operator++()
Definition: NodeMasks.h:1170
openvdb::v3_1_0::util::NodeMask< 1 >::NodeMask
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:630
openvdb::v3_1_0::util::NodeMask< 1 >::memUsage
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:709
openvdb::v3_1_0::util::RootNodeMask::init
void init(Index32 bit_size)
Definition: NodeMasks.h:1062
openvdb::v3_1_0::util::RootNodeMask::operator&=
const RootNodeMask & operator&=(const RootNodeMask &other)
Definition: NodeMasks.h:1227
openvdb::v3_1_0::util::NodeMask< 2 >::setFirstOn
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:956
openvdb::v3_1_0::util::NodeMask::setFirstOn
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:491
openvdb::v3_1_0::util::BaseMaskIterator::operator=
BaseMaskIterator & operator=(const BaseMaskIterator &iter)
Definition: NodeMasks.h:188
openvdb::v3_1_0::util::NodeMask< 2 >::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:931
openvdb::v3_1_0::util::RootNodeMask::OffIterator::OffIterator
OffIterator()
Definition: NodeMasks.h:1155
openvdb::v3_1_0::util::NodeMask< 1 >::setFirstOn
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:740
openvdb::v3_1_0::util::RootNodeMask::printAll
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1370
openvdb::v3_1_0::util::NodeMask::operator^=
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:425
openvdb::v3_1_0::util::NodeMask< 1 >::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:715
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::util::NodeMask< 2 >::countOff
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:929
openvdb::v3_1_0::util::OnMaskIterator
Definition: NodeMasks.h:205
openvdb::v3_1_0::util::NodeMask< 1 >::save
void save(std::ostream &os) const
Definition: NodeMasks.h:785
openvdb::v3_1_0::util::DenseMaskIterator::increment
void increment(Index n)
Definition: NodeMasks.h:283
openvdb::v3_1_0::util::OffMaskIterator
Definition: NodeMasks.h:236
openvdb::v3_1_0::util::NodeMask< 2 >::Word
Index64 Word
Definition: NodeMasks.h:834
openvdb::v3_1_0::util::NodeMask::operator&=
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:401
openvdb::v3_1_0::util::NodeMask< 1 >::load
void load(std::istream &is)
Definition: NodeMasks.h:789
openvdb::v3_1_0::util::NodeMask< 2 >::toggle
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:954
openvdb::v3_1_0::util::NodeMask< 1 >::operator&=
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:681
openvdb::v3_1_0::Index32
uint32_t Index32
Definition: Types.h:56
openvdb::v3_1_0::util::OnMaskIterator::next
bool next()
Definition: NodeMasks.h:221
openvdb::v3_1_0::util::NodeMask< 2 >::memUsage
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:925
openvdb::v3_1_0::util::NodeMask::OnIterator
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:345
openvdb::v3_1_0::util::RootNodeMask::operator!
RootNodeMask operator!() const
Definition: NodeMasks.h:1226
openvdb::v3_1_0::util::NodeMask< 1 >::toggle
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:738
openvdb::v3_1_0::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
openvdb::v3_1_0::util::NodeMask< 2 >::operator&=
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:897
openvdb::v3_1_0::util::RootNodeMask::OffIterator::next
bool next()
Definition: NodeMasks.h:1165
openvdb::v3_1_0::util::NodeMask::toggle
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:480
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::DenseIterator
DenseIterator()
Definition: NodeMasks.h:1183
openvdb::v3_1_0::util::RootNodeMask::setOff
void setOff(Index32 i)
Definition: NodeMasks.h:1279
openvdb::v3_1_0::util::RootNodeMask::countOff
Index32 countOff() const
Definition: NodeMasks.h:1271
openvdb::v3_1_0::util::NodeMask< 1 >::countOff
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:713
openvdb::v3_1_0::util::NodeMask::beginDense
DenseIterator beginDense() const
Definition: NodeMasks.h:353
openvdb::v3_1_0::util::NodeMask< 2 >::save
void save(std::ostream &os) const
Definition: NodeMasks.h:996
openvdb::v3_1_0::util::OnMaskIterator::increment
void increment(Index n)
Definition: NodeMasks.h:220
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::offset
Index32 offset() const
Definition: NodeMasks.h:1107
openvdb::v3_1_0::util::BaseMaskIterator::BaseMaskIterator
BaseMaskIterator()
Definition: NodeMasks.h:180
openvdb::v3_1_0::util::NodeMask< 1 >::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:720
openvdb::v3_1_0::util::NodeMask< 2 >::load
void load(std::istream &is)
Definition: NodeMasks.h:1000
openvdb::v3_1_0::util::RootNodeMask::save
void save(std::ostream &os) const
Definition: NodeMasks.h:1345
openvdb::v3_1_0::math::operator<
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
openvdb::v3_1_0::util::RootNodeMask::isOff
bool isOff() const
Definition: NodeMasks.h:1325
openvdb::v3_1_0::util::NodeMask::operator|
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:434
openvdb::v3_1_0::util::RootNodeMask::setFirstOff
void setFirstOff()
Definition: NodeMasks.h:1306
openvdb::v3_1_0::util::NodeMask::operator=
NodeMask & operator=(const NodeMask &other)
Assignment operator.
Definition: NodeMasks.h:337
openvdb::v3_1_0::util::RootNodeMask::setLastOff
void setLastOff()
Definition: NodeMasks.h:1307
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::util::RootNodeMask::RootNodeMask
RootNodeMask(Index32 bit_size)
Definition: NodeMasks.h:1050
openvdb::v3_1_0::util::NodeMask< 1 >::operator&
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:705
openvdb::v3_1_0::util::NodeMask::findNextOff
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:594
openvdb::v3_1_0::util::RootNodeMask::operator=
RootNodeMask & operator=(const RootNodeMask &B)
Definition: NodeMasks.h:1074
openvdb::v3_1_0::util::RootNodeMask::isOn
bool isOn(Index32 i) const
Definition: NodeMasks.h:1308
openvdb::v3_1_0::util::NodeMask< 2 >::operator!
NodeMask operator!() const
Definition: NodeMasks.h:920
openvdb::v3_1_0::util::NodeMask::findFirstOn
Index32 findFirstOn() const
Definition: NodeMasks.h:520
openvdb::v3_1_0::util::NodeMask< 2 >::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:936
openvdb::v3_1_0::util::NodeMask::endOn
OnIterator endOn() const
Definition: NodeMasks.h:350
B6
#define B6(n)
openvdb::v3_1_0::util::NodeMask< 2 >::endOn
OnIterator endOn() const
Definition: NodeMasks.h:857
openvdb::v3_1_0::util::RootNodeMask::setLastOn
void setLastOn()
Definition: NodeMasks.h:1305
openvdb::v3_1_0::util::NodeMask< 1 >::operator!
NodeMask operator!() const
Definition: NodeMasks.h:704
openvdb::v3_1_0::util::NodeMask< 2 >::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:856
openvdb::v3_1_0::util::NodeMask::operator!
NodeMask operator!() const
Definition: NodeMasks.h:432
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::util::BaseMaskIterator::mParent
const NodeMask * mParent
Definition: NodeMasks.h:178
openvdb::v3_1_0::util::NodeMask< 1 >::endOn
OnIterator endOn() const
Definition: NodeMasks.h:641
openvdb::v3_1_0::util::NodeMask< 2 >::setLastOn
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:958
openvdb::v3_1_0::util::DenseMaskIterator::operator++
DenseMaskIterator & operator++()
Definition: NodeMasks.h:290
openvdb::v3_1_0::util::NodeMask< 2 >::findFirstOn
Index32 findFirstOn() const
Definition: NodeMasks.h:975
openvdb::v3_1_0::util::RootNodeMask::toggle
void toggle(Index32 i)
Definition: NodeMasks.h:1295
openvdb::v3_1_0::util::NodeMask< 1 >::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:640
openvdb::v3_1_0::util::OnMaskIterator::operator*
bool operator*() const
Definition: NodeMasks.h:226
openvdb::v3_1_0::util::NodeMask< 2 >::operator&
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:921
openvdb::v3_1_0::util::BaseMaskIterator::offset
Index32 offset() const
Definition: NodeMasks.h:192
openvdb::v3_1_0::util::RootNodeMask::BaseIterator
Definition: NodeMasks.h:1085
openvdb::v3_1_0::util::CountOn
Index32 CountOn(Index64 v)
Return the number of on bits in the given 64-bit value.
Definition: NodeMasks.h:92
openvdb::v3_1_0::util::NodeMask< 1 >::findFirstOn
Index32 findFirstOn() const
Definition: NodeMasks.h:759
openvdb::v3_1_0::util::RootNodeMask::printBits
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1358
openvdb::v3_1_0::util::RootNodeMask::setOff
void setOff()
Definition: NodeMasks.h:1291
openvdb::v3_1_0::util::RootNodeMask::~RootNodeMask
~RootNodeMask()
Definition: NodeMasks.h:1060
openvdb::v3_1_0::util::RootNodeMask::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:1204
openvdb::v3_1_0::util::NodeMask::OffIterator
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:346
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_1_0::util::RootNodeMask::OffIterator::operator*
bool operator*() const
Definition: NodeMasks.h:1169
openvdb::v3_1_0::util::NodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:351
openvdb::v3_1_0::util::NodeMask< 1 >::OnIterator
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:636
openvdb::v3_1_0::util::RootNodeMask::findNextOff
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1386
openvdb::v3_1_0::util::NodeMask< 2 >::printInfo
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1002
openvdb::v3_1_0::util::NodeMask< 1 >::operator-=
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:693
openvdb::v3_1_0::util::NodeMask::operator|=
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:409
openvdb::v3_1_0::util::NodeMask< 1 >::setLastOn
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:742
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::test
bool test() const
Definition: NodeMasks.h:1111
openvdb::v3_1_0::util::RootNodeMask::RootNodeMask
RootNodeMask()
Definition: NodeMasks.h:1049
openvdb::v3_1_0::util::NodeMask::setLastOff
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:497
openvdb::v3_1_0::util::NodeMask< 1 >::NodeMask
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:628
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::mParent
const RootNodeMask * mParent
Definition: NodeMasks.h:1090
openvdb::v3_1_0::util::NodeMask< 2 >::OnIterator
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:852
openvdb::v3_1_0::util::RootNodeMask::endOff
OffIterator endOff() const
Definition: NodeMasks.h:1207
openvdb::v3_1_0::util::NodeMask< 2 >::isOff
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:974
openvdb::v3_1_0::util::NodeMask< 1 >::printInfo
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:791
openvdb::v3_1_0::util::NodeMask< 2 >::operator-=
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:909
openvdb::v3_1_0::util::RootNodeMask::OnIterator::next
bool next()
Definition: NodeMasks.h:1137
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::operator=
BaseIterator & operator=(const BaseIterator &iter)
Definition: NodeMasks.h:1100
openvdb::v3_1_0::util::BaseMaskIterator
Base class for the bit mask iterators.
Definition: NodeMasks.h:174
openvdb::v3_1_0::util::NodeMask::getWord
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:538
openvdb::v3_1_0::util::NodeMask< 2 >::NodeMask
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:844
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::operator++
DenseIterator & operator++()
Definition: NodeMasks.h:1198
openvdb::v3_1_0::util::RootNodeMask::OnIterator::increment
void increment(Index n)
Definition: NodeMasks.h:1134
openvdb::v3_1_0::util::BaseMaskIterator::test
bool test() const
Definition: NodeMasks.h:194
openvdb::v3_1_0::util::NodeMask< 1 >::isOff
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:758
openvdb::v3_1_0::util::NodeMask::Word
Index64 Word
Definition: NodeMasks.h:313
openvdb::v3_1_0::util::RootNodeMask::findNextOn
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1375
openvdb::v3_1_0::util::NodeMask::memUsage
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:438
openvdb::v3_1_0::util::NodeMask::isOff
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:514
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::operator==
bool operator==(const BaseIterator &iter) const
Definition: NodeMasks.h:1097
openvdb::v3_1_0::util::NodeMask< 1 >::setLastOff
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:746
openvdb::v3_1_0::util::RootNodeMask::endDense
DenseIterator endDense() const
Definition: NodeMasks.h:1209
openvdb::v3_1_0::util::RootNodeMask::setOn
void setOn(Index32 i)
Definition: NodeMasks.h:1273
openvdb
Definition: Exceptions.h:39
openvdb::v3_1_0::util::NodeMask::printBits
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:564
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::util::NodeMask< 2 >::setLastOff
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:962
openvdb::v3_1_0::util::RootNodeMask::setOn
void setOn()
Definition: NodeMasks.h:1287
openvdb::v3_1_0::util::RootNodeMask::mBitSize
Index32 mBitSize
Definition: NodeMasks.h:1045
openvdb::v3_1_0::util::NodeMask::countOn
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:440
openvdb::v3_1_0::util::NodeMask::setFirstOff
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:495
openvdb::v3_1_0::util::OnMaskIterator::OnMaskIterator
OnMaskIterator()
Definition: NodeMasks.h:212
openvdb::v3_1_0::util::NodeMask< 2 >::countOn
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:927
openvdb::v3_1_0::util::NodeMask< 2 >::setOn
void setOn()
Set all bits on.
Definition: NodeMasks.h:945
openvdb::v3_1_0::util::OffMaskIterator::OffMaskIterator
OffMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:244
openvdb::v3_1_0::util::BaseMaskIterator::operator==
bool operator==(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:185
openvdb::v3_1_0::util::NodeMask::DenseIterator
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:347
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::mBitSize
Index32 mBitSize
Definition: NodeMasks.h:1089
openvdb::v3_1_0::util::NodeMask< 1 >::Word
Byte Word
Definition: NodeMasks.h:618
openvdb::v3_1_0::util::NodeMask< 1 >::countOn
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:711
openvdb::v3_1_0::util::NodeMask< 1 >::setOn
void setOn()
Set all bits on.
Definition: NodeMasks.h:729
openvdb::v3_1_0::util::OffMaskIterator::OffMaskIterator
OffMaskIterator()
Definition: NodeMasks.h:243
openvdb::v3_1_0::util::NodeMask< 2 >::operator|
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:922
openvdb::v3_1_0::util::NodeMask< 1 >::setOff
void setOff()
Set all bits off.
Definition: NodeMasks.h:731
openvdb::v3_1_0::util::NodeMask< 2 >::getWord
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:990
openvdb::v3_1_0::util::DenseMaskIterator::increment
void increment()
Definition: NodeMasks.h:277
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::pos
Index32 pos() const
Definition: NodeMasks.h:1109
openvdb::v3_1_0::util::RootNodeMask::toggle
void toggle()
Definition: NodeMasks.h:1300
openvdb::v3_1_0::util::NodeMask::printAll
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:576
openvdb::v3_1_0::util::NodeMask::setOff
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:454
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::mPos
Index32 mPos
Definition: NodeMasks.h:1088
openvdb::v3_1_0::util::RootNodeMask::printInfo
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1354
openvdb::v3_1_0::util::NodeMask< 1 >::~NodeMask
~NodeMask()
Destructor.
Definition: NodeMasks.h:632
openvdb::v3_1_0::util::NodeMask< 1 >::findFirstOff
Index32 findFirstOff() const
Definition: NodeMasks.h:760
openvdb::v3_1_0::util::NodeMask< 1 >::printBits
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:795
openvdb::v3_1_0::util::RootNodeMask::OffIterator::increment
void increment()
Definition: NodeMasks.h:1157
openvdb::v3_1_0::util::NodeMask< 1 >::printAll
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:801
openvdb::v3_1_0::util::DenseMaskIterator
Definition: NodeMasks.h:267
openvdb::v3_1_0::util::NodeMask::NodeMask
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:331
openvdb::v3_1_0::util::DenseMaskIterator::operator*
bool operator*() const
Definition: NodeMasks.h:289
openvdb::v3_1_0::util::NodeMask< 1 >::endOff
OffIterator endOff() const
Definition: NodeMasks.h:643
openvdb::v3_1_0::util::NodeMask< 2 >::findFirstOff
Index32 findFirstOff() const
Definition: NodeMasks.h:976
openvdb::v3_1_0::util::RootNodeMask::OffIterator::OffIterator
OffIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1156
openvdb::v3_1_0::util::NodeMask< 2 >::printAll
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:1015
openvdb::v3_1_0::util::RootNodeMask::operator|=
const RootNodeMask & operator|=(const RootNodeMask &other)
Definition: NodeMasks.h:1235
openvdb::v3_1_0::util::NodeMask< 2 >::getWord
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:984
openvdb::v3_1_0::util::NodeMask::getWord
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:544
openvdb::v3_1_0::util::RootNodeMask::getBitSize
Index getBitSize() const
Definition: NodeMasks.h:1070
openvdb::v3_1_0::util::NodeMask< 1 >::operator|
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:706
openvdb::v3_1_0::util::NodeMask< 2 >::setOff
void setOff()
Set all bits off.
Definition: NodeMasks.h:947
openvdb::v3_1_0::util::NodeMask::NodeMask
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:333
openvdb::v3_1_0::util::NodeMask< 1 >::operator|=
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:687
openvdb::v3_1_0::util::DenseMaskIterator::DenseMaskIterator
DenseMaskIterator()
Definition: NodeMasks.h:275
openvdb::v3_1_0::util::NodeMask::endDense
DenseIterator endDense() const
Definition: NodeMasks.h:354
openvdb::v3_1_0::util::NodeMask< 1 >::setFirstOff
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:744
openvdb::v3_1_0::util::NodeMask< 2 >::~NodeMask
~NodeMask()
Destructor.
Definition: NodeMasks.h:848
openvdb::v3_1_0::util::NodeMask< 2 >::printBits
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:1006
openvdb::v3_1_0::util::NodeMask< 2 >::findNextOff
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1028
openvdb::v3_1_0::util::RootNodeMask::setFirstOn
void setFirstOn()
Definition: NodeMasks.h:1304
openvdb::v3_1_0::util::RootNodeMask::mBits
Index32 * mBits
Definition: NodeMasks.h:1046
openvdb::v3_1_0::util::NodeMask< 2 >::endOff
OffIterator endOff() const
Definition: NodeMasks.h:859
openvdb::v3_1_0::util::NodeMask::setOn
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:449
openvdb::v3_1_0::util::NodeMask::setOn
void setOn()
Set all bits on.
Definition: NodeMasks.h:468
openvdb::v3_1_0::util::NodeMask< 2 >::toggle
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:949
openvdb::v3_1_0::util::NodeMask< 1 >::findNextOff
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:814
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::BaseIterator
BaseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1093
openvdb::v3_1_0::util::NodeMask::printInfo
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:559
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::operator!=
bool operator!=(const BaseIterator &iter) const
Definition: NodeMasks.h:1098
openvdb::v3_1_0::util::DenseMaskIterator::next
bool next()
Definition: NodeMasks.h:284
openvdb::v3_1_0::Index64
uint64_t Index64
Definition: Types.h:57
openvdb::v3_1_0::util::OffMaskIterator::increment
void increment(Index n)
Definition: NodeMasks.h:251
openvdb::v3_1_0::util::NodeMask::operator&
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:433
openvdb::v3_1_0::util::NodeMask< 2 >::operator|=
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:903
openvdb::v3_1_0::util::NodeMask< 1 >::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:748
openvdb::v3_1_0::util::NodeMask::NodeMask
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:329
openvdb::v3_1_0::util::NodeMask< 1 >::toggle
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:733
openvdb::v3_1_0::util::NodeMask::toggle
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:485
openvdb::v3_1_0::util::RootNodeMask::memUsage
Index32 memUsage() const
Definition: NodeMasks.h:1397
openvdb::v3_1_0::util::NodeMask::~NodeMask
~NodeMask()
Destructor.
Definition: NodeMasks.h:335
openvdb::v3_1_0::util::NodeMask< 2 >::setFirstOff
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:960
openvdb::v3_1_0::util::RootNodeMask::BaseIterator::BaseIterator
BaseIterator()
Definition: NodeMasks.h:1092
openvdb::v3_1_0::util::RootNodeMask::OnIterator::OnIterator
OnIterator()
Definition: NodeMasks.h:1127
openvdb::v3_1_0::util::NodeMask::beginOn
OnIterator beginOn() const
Definition: NodeMasks.h:349
openvdb::v3_1_0::util::NodeMask< 2 >::isOn
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:964
openvdb::v3_1_0::util::NodeMask< 2 >::beginDense
DenseIterator beginDense() const
Definition: NodeMasks.h:860
openvdb::v3_1_0::util::FindLowestOn
Index32 FindLowestOn(Index64 v)
Return the least significant on bit of the given 64-bit value.
Definition: NodeMasks.h:133
openvdb::v3_1_0::util::OnMaskIterator::operator++
OnMaskIterator & operator++()
Definition: NodeMasks.h:227
openvdb::v3_1_0::util::NodeMask< 1 >::DenseIterator
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:638
openvdb::v3_1_0::util::RootNodeMask::RootNodeMask
RootNodeMask(const RootNodeMask &B)
Definition: NodeMasks.h:1055
openvdb::v3_1_0::util::NodeMask< 1 >::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:642
openvdb::v3_1_0::util::NodeMask< 1 >::beginDense
DenseIterator beginDense() const
Definition: NodeMasks.h:644
openvdb::v3_1_0::util::NodeMask< 2 >::isOff
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:970
openvdb::v3_1_0::util::NodeMask< 2 >::DenseIterator
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:854
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_1_0::util::NodeMask::operator^
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:435
openvdb::v3_1_0::util::RootNodeMask::getIntSize
Index getIntSize() const
Definition: NodeMasks.h:1072
openvdb::v3_1_0::util::RootNodeMask::mIntSize
Index32 mIntSize
Definition: NodeMasks.h:1045
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::next
bool next()
Definition: NodeMasks.h:1193
openvdb::v3_1_0::util::NodeMask< 1 >::findNextOn
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:807
openvdb::v3_1_0::util::NodeMask< 2 >::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:858
openvdb::v3_1_0::util::RootNodeMask::beginOff
OffIterator beginOff() const
Definition: NodeMasks.h:1206
openvdb::v3_1_0::util::RootNodeMask::isOff
bool isOff(Index32 i) const
Definition: NodeMasks.h:1313
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::DenseIterator
DenseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1184
openvdb::v3_1_0::util::RootNodeMask::operator|
RootNodeMask operator|(const RootNodeMask &other) const
Definition: NodeMasks.h:1252
openvdb::v3_1_0::util::NodeMask< 2 >::findNextOn
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1021
openvdb::v3_1_0::util::OffMaskIterator::increment
void increment()
Definition: NodeMasks.h:245
openvdb::v3_1_0::util::NodeMask< 1 >::isOff
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:754
openvdb::v3_1_0::util::BaseMaskIterator::mPos
Index32 mPos
Definition: NodeMasks.h:177
openvdb::v3_1_0::util::DenseMaskIterator::DenseMaskIterator
DenseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:276
openvdb::v3_1_0::util::RootNodeMask::DenseIterator::operator*
bool operator*() const
Definition: NodeMasks.h:1197
openvdb::v3_1_0::util::NodeMask< 2 >::NodeMask
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:842
openvdb::v3_1_0::util::RootNodeMask::OnIterator::OnIterator
OnIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1128
openvdb::v3_1_0::util::BaseMaskIterator::BaseMaskIterator
BaseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:181
openvdb::v3_1_0::util::OffMaskIterator::operator++
OffMaskIterator & operator++()
Definition: NodeMasks.h:258
openvdb::v3_1_0::util::RootNodeMask::getMemUsage
Index32 getMemUsage() const
Definition: NodeMasks.h:1260
openvdb::v3_1_0::util::RootNodeMask::findFirstOff
Index32 findFirstOff() const
Definition: NodeMasks.h:1338
openvdb::v3_1_0::util::OffMaskIterator::operator*
bool operator*() const
Definition: NodeMasks.h:257
openvdb::v3_1_0::util::NodeMask::save
void save(std::ostream &os) const
Definition: NodeMasks.h:551
openvdb::v3_1_0::util::RootNodeMask::operator&
RootNodeMask operator&(const RootNodeMask &other) const
Definition: NodeMasks.h:1249
Platform.h
openvdb::v3_1_0::util::RootNodeMask::OffIterator::increment
void increment(Index n)
Definition: NodeMasks.h:1162
openvdb::v3_1_0::util::RootNodeMask::beginDense
DenseIterator beginDense() const
Definition: NodeMasks.h:1208
openvdb::v3_1_0::util::RootNodeMask::operator^=
const RootNodeMask & operator^=(const RootNodeMask &other)
Definition: NodeMasks.h:1242
openvdb::v3_1_0::util::RootNodeMask::isOn
bool isOn() const
Definition: NodeMasks.h:1319
openvdb::v3_1_0::util::NodeMask::setOff
void setOff()
Set all bits off.
Definition: NodeMasks.h:474