OpenVDB  3.1.0
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 {
48 namespace OPENVDB_VERSION_NAME {
49 namespace util {
50 
52 inline Index32
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
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
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
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
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
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
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>
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;}
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:
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;}
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:
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;}
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:
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);}
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; }
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 
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  }
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  }
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 
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 
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) {}
634  void operator = (const NodeMask &other) { mByte = other.mByte; }
635 
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; }
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 
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 
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) {}
850  void operator = (const NodeMask &other) { mWord = other.mWord; }
851 
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; }
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 
1022  {
1023  if (start>=64) return 64;
1024  const Word w = mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
1025  return w ? FindLowestOn(w) : 64;
1026  }
1027 
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!
1043 {
1044 protected:
1045  Index32 mBitSize, mIntSize;
1047 
1048 public:
1049  RootNodeMask(): mBitSize(0), mIntSize(0), mBits(NULL) {}
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  }
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 
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 
1086  {
1087  protected:
1088  Index32 mPos;//bit position
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;}
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:
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:
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:
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 
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 
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 
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/ )
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:507
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:915
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:626
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:756
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:447
DenseIterator endDense() const
Definition: NodeMasks.h:645
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:725
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:417
Definition: NodeMasks.h:1042
void load(std::istream &is)
Definition: NodeMasks.h:555
Index32 Index
Definition: Types.h:58
OnIterator & operator++()
Definition: NodeMasks.h:1142
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:923
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:699
DenseIterator endDense() const
Definition: NodeMasks.h:861
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:941
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:637
bool operator!=(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:186
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:707
void load(std::istream &is)
Definition: NodeMasks.h:1349
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:853
Index32 countOn() const
Definition: NodeMasks.h:1264
unsigned char Byte
Definition: Types.h:63
Index32 CountOff(Index64 v)
Return the number of off bits in the given 64-bit value.
Definition: NodeMasks.h:101
OnIterator endOn() const
Definition: NodeMasks.h:1205
void increment()
Definition: NodeMasks.h:1185
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:582
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:972
bool next()
Definition: NodeMasks.h:252
Index32 findFirstOff() const
Definition: NodeMasks.h:527
void increment()
Definition: NodeMasks.h:214
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:493
Index32 findFirstOn() const
Definition: NodeMasks.h:1331
OnMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:213
Index32 pos() const
Definition: NodeMasks.h:193
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:151
void increment(Index n)
Definition: NodeMasks.h:1190
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:846
OffIterator endOff() const
Definition: NodeMasks.h:352
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
bool operator*() const
Definition: NodeMasks.h:1141
void increment()
Definition: NodeMasks.h:1129
RootNodeMask operator^(const RootNodeMask &other) const
Definition: NodeMasks.h:1255
OffIterator & operator++()
Definition: NodeMasks.h:1170
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:630
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:709
void init(Index32 bit_size)
Definition: NodeMasks.h:1062
const RootNodeMask & operator&=(const RootNodeMask &other)
Definition: NodeMasks.h:1227
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:956
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:491
BaseMaskIterator & operator=(const BaseMaskIterator &iter)
Definition: NodeMasks.h:188
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:931
OffIterator()
Definition: NodeMasks.h:1155
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:740
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1370
const NodeMask & operator^=(const NodeMask &other)
Bitwise XOR.
Definition: NodeMasks.h:425
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:715
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:929
Definition: NodeMasks.h:205
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:727
void save(std::ostream &os) const
Definition: NodeMasks.h:785
void increment(Index n)
Definition: NodeMasks.h:283
Definition: NodeMasks.h:236
Index64 Word
Definition: NodeMasks.h:834
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:401
void load(std::istream &is)
Definition: NodeMasks.h:789
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:954
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:681
uint32_t Index32
Definition: Types.h:56
bool next()
Definition: NodeMasks.h:221
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:925
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:345
RootNodeMask operator!() const
Definition: NodeMasks.h:1226
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:738
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
const NodeMask & operator&=(const NodeMask &other)
Bitwise intersection.
Definition: NodeMasks.h:897
bool next()
Definition: NodeMasks.h:1165
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:480
void setOff(Index32 i)
Definition: NodeMasks.h:1279
Index32 countOff() const
Definition: NodeMasks.h:1271
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:713
DenseIterator beginDense() const
Definition: NodeMasks.h:353
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:943
void save(std::ostream &os) const
Definition: NodeMasks.h:996
void increment(Index n)
Definition: NodeMasks.h:220
Index32 offset() const
Definition: NodeMasks.h:1107
BaseMaskIterator()
Definition: NodeMasks.h:180
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:720
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:461
void load(std::istream &is)
Definition: NodeMasks.h:1000
void save(std::ostream &os) const
Definition: NodeMasks.h:1345
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
bool isOff() const
Definition: NodeMasks.h:1325
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:434
void setFirstOff()
Definition: NodeMasks.h:1306
NodeMask & operator=(const NodeMask &other)
Assignment operator.
Definition: NodeMasks.h:337
void setLastOff()
Definition: NodeMasks.h:1307
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:105
RootNodeMask(Index32 bit_size)
Definition: NodeMasks.h:1050
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:705
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:594
RootNodeMask & operator=(const RootNodeMask &B)
Definition: NodeMasks.h:1074
bool isOn(Index32 i) const
Definition: NodeMasks.h:1308
NodeMask operator!() const
Definition: NodeMasks.h:920
Index32 findFirstOn() const
Definition: NodeMasks.h:520
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:936
OnIterator endOn() const
Definition: NodeMasks.h:350
#define B6(n)
OnIterator endOn() const
Definition: NodeMasks.h:857
void setLastOn()
Definition: NodeMasks.h:1305
NodeMask operator!() const
Definition: NodeMasks.h:704
OnIterator beginOn() const
Definition: NodeMasks.h:856
NodeMask operator!() const
Definition: NodeMasks.h:432
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:499
const NodeMask * mParent
Definition: NodeMasks.h:178
OnIterator endOn() const
Definition: NodeMasks.h:641
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:958
DenseMaskIterator & operator++()
Definition: NodeMasks.h:290
Index32 findFirstOn() const
Definition: NodeMasks.h:975
void toggle(Index32 i)
Definition: NodeMasks.h:1295
OnIterator beginOn() const
Definition: NodeMasks.h:640
bool operator*() const
Definition: NodeMasks.h:226
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:921
Index32 offset() const
Definition: NodeMasks.h:192
Index32 CountOn(Index64 v)
Return the number of on bits in the given 64-bit value.
Definition: NodeMasks.h:92
Index32 findFirstOn() const
Definition: NodeMasks.h:759
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1358
void setOff()
Definition: NodeMasks.h:1291
~RootNodeMask()
Definition: NodeMasks.h:1060
OnIterator beginOn() const
Definition: NodeMasks.h:1204
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:346
#define OPENVDB_VERSION_NAME
Definition: version.h:43
bool operator*() const
Definition: NodeMasks.h:1169
OffIterator beginOff() const
Definition: NodeMasks.h:351
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:636
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1386
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1002
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:693
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:409
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:742
bool test() const
Definition: NodeMasks.h:1111
RootNodeMask()
Definition: NodeMasks.h:1049
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:497
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:628
const RootNodeMask * mParent
Definition: NodeMasks.h:1090
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:852
OffIterator endOff() const
Definition: NodeMasks.h:1207
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:974
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:791
const NodeMask & operator-=(const NodeMask &other)
Bitwise difference.
Definition: NodeMasks.h:909
bool next()
Definition: NodeMasks.h:1137
BaseIterator & operator=(const BaseIterator &iter)
Definition: NodeMasks.h:1100
Base class for the bit mask iterators.
Definition: NodeMasks.h:174
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:538
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:844
DenseIterator & operator++()
Definition: NodeMasks.h:1198
void increment(Index n)
Definition: NodeMasks.h:1134
bool test() const
Definition: NodeMasks.h:194
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:758
Index64 Word
Definition: NodeMasks.h:313
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1375
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:438
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:514
bool operator==(const BaseIterator &iter) const
Definition: NodeMasks.h:1097
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:746
DenseIterator endDense() const
Definition: NodeMasks.h:1209
void setOn(Index32 i)
Definition: NodeMasks.h:1273
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:459
void set(Index32 i, bool On)
Definition: NodeMasks.h:1285
Definition: Exceptions.h:39
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:564
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:505
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:962
void setOn()
Definition: NodeMasks.h:1287
Index32 mBitSize
Definition: NodeMasks.h:1045
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:440
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:495
OnMaskIterator()
Definition: NodeMasks.h:212
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:927
void setOn()
Set all bits on.
Definition: NodeMasks.h:945
OffMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:244
bool operator==(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:185
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:347
Index32 mBitSize
Definition: NodeMasks.h:1089
Byte Word
Definition: NodeMasks.h:618
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:711
void setOn()
Set all bits on.
Definition: NodeMasks.h:729
OffMaskIterator()
Definition: NodeMasks.h:243
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:922
void setOff()
Set all bits off.
Definition: NodeMasks.h:731
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:990
void increment()
Definition: NodeMasks.h:277
Index32 pos() const
Definition: NodeMasks.h:1109
void toggle()
Definition: NodeMasks.h:1300
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:576
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:454
Index32 mPos
Definition: NodeMasks.h:1088
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1354
~NodeMask()
Destructor.
Definition: NodeMasks.h:632
Index32 findFirstOff() const
Definition: NodeMasks.h:760
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:795
void increment()
Definition: NodeMasks.h:1157
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:801
Definition: NodeMasks.h:267
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:331
bool operator*() const
Definition: NodeMasks.h:289
OffIterator endOff() const
Definition: NodeMasks.h:643
Index32 findFirstOff() const
Definition: NodeMasks.h:976
OffIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1156
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:1015
const RootNodeMask & operator|=(const RootNodeMask &other)
Definition: NodeMasks.h:1235
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:984
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:544
Index getBitSize() const
Definition: NodeMasks.h:1070
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:706
void setOff()
Set all bits off.
Definition: NodeMasks.h:947
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:333
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:687
DenseMaskIterator()
Definition: NodeMasks.h:275
DenseIterator endDense() const
Definition: NodeMasks.h:354
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:744
~NodeMask()
Destructor.
Definition: NodeMasks.h:848
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:1006
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1028
void setFirstOn()
Definition: NodeMasks.h:1304
Index32 * mBits
Definition: NodeMasks.h:1046
OffIterator endOff() const
Definition: NodeMasks.h:859
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:449
void setOn()
Set all bits on.
Definition: NodeMasks.h:468
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:949
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:814
BaseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1093
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:559
bool operator!=(const BaseIterator &iter) const
Definition: NodeMasks.h:1098
bool next()
Definition: NodeMasks.h:284
uint64_t Index64
Definition: Types.h:57
void increment(Index n)
Definition: NodeMasks.h:251
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:433
const NodeMask & operator|=(const NodeMask &other)
Bitwise union.
Definition: NodeMasks.h:903
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:748
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:329
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:733
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:485
Index32 memUsage() const
Definition: NodeMasks.h:1397
~NodeMask()
Destructor.
Definition: NodeMasks.h:335
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:960
BaseIterator()
Definition: NodeMasks.h:1092
OnIterator()
Definition: NodeMasks.h:1127
OnIterator beginOn() const
Definition: NodeMasks.h:349
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:964
DenseIterator beginDense() const
Definition: NodeMasks.h:860
Index32 FindLowestOn(Index64 v)
Return the least significant on bit of the given 64-bit value.
Definition: NodeMasks.h:133
OnMaskIterator & operator++()
Definition: NodeMasks.h:227
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:638
RootNodeMask(const RootNodeMask &B)
Definition: NodeMasks.h:1055
OffIterator beginOff() const
Definition: NodeMasks.h:642
DenseIterator beginDense() const
Definition: NodeMasks.h:644
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:970
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:854
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:435
Index getIntSize() const
Definition: NodeMasks.h:1072
Index32 mIntSize
Definition: NodeMasks.h:1045
bool next()
Definition: NodeMasks.h:1193
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:807
OffIterator beginOff() const
Definition: NodeMasks.h:858
OffIterator beginOff() const
Definition: NodeMasks.h:1206
bool isOff(Index32 i) const
Definition: NodeMasks.h:1313
DenseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1184
RootNodeMask operator|(const RootNodeMask &other) const
Definition: NodeMasks.h:1252
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1021
void increment()
Definition: NodeMasks.h:245
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:754
Index32 mPos
Definition: NodeMasks.h:177
DenseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:276
bool operator*() const
Definition: NodeMasks.h:1197
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:842
OnIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1128
BaseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:181
OffMaskIterator & operator++()
Definition: NodeMasks.h:258
Index32 getMemUsage() const
Definition: NodeMasks.h:1260
Index32 findFirstOff() const
Definition: NodeMasks.h:1338
bool operator*() const
Definition: NodeMasks.h:257
void save(std::ostream &os) const
Definition: NodeMasks.h:551
RootNodeMask operator&(const RootNodeMask &other) const
Definition: NodeMasks.h:1249
void increment(Index n)
Definition: NodeMasks.h:1162
DenseIterator beginDense() const
Definition: NodeMasks.h:1208
const RootNodeMask & operator^=(const RootNodeMask &other)
Definition: NodeMasks.h:1242
bool isOn() const
Definition: NodeMasks.h:1319
void setOff()
Set all bits off.
Definition: NodeMasks.h:474