OpenVDB  3.0.0
NodeMasks.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 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  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
369  const NodeMask& operator&=(const NodeMask& other)
370  {
371  Index32 n = WORD_COUNT;
372  const Word* w2 = other.mWords;
373  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 &= *w2;
374  return *this;
375  }
376  const NodeMask& operator|=(const NodeMask& other)
377  {
378  Index32 n = WORD_COUNT;
379  const Word* w2 = other.mWords;
380  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 |= *w2;
381  return *this;
382  }
383  const NodeMask& operator^=(const NodeMask& other)
384  {
385  Index32 n = WORD_COUNT;
386  const Word* w2 = other.mWords;
387  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 ^= *w2;
388  return *this;
389  }
390  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
391  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
392  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
394  static Index32 memUsage() { return static_cast<Index32>(WORD_COUNT*sizeof(Word)); }
396  Index32 countOn() const
397  {
398  Index32 sum = 0, n = WORD_COUNT;
399  for (const Word* w = mWords; n--; ++w) sum += CountOn(*w);
400  return sum;
401  }
403  Index32 countOff() const { return SIZE-this->countOn(); }
405  void setOn(Index32 n) {
406  assert( (n >> 6) < WORD_COUNT );
407  mWords[n >> 6] |= Word(1) << (n & 63);
408  }
410  void setOff(Index32 n) {
411  assert( (n >> 6) < WORD_COUNT );
412  mWords[n >> 6] &= ~(Word(1) << (n & 63));
413  }
415  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
417  void set(bool on)
418  {
419  const Word state = on ? ~Word(0) : Word(0);
420  Index32 n = WORD_COUNT;
421  for (Word* w = mWords; n--; ++w) *w = state;
422  }
424  void setOn()
425  {
426  Index32 n = WORD_COUNT;
427  for (Word* w = mWords; n--; ++w) *w = ~Word(0);
428  }
430  void setOff()
431  {
432  Index32 n = WORD_COUNT;
433  for (Word* w = mWords; n--; ++w) *w = Word(0);
434  }
436  void toggle(Index32 n) {
437  assert( (n >> 6) < WORD_COUNT );
438  mWords[n >> 6] ^= Word(1) << (n & 63);
439  }
441  void toggle()
442  {
443  Index32 n = WORD_COUNT;
444  for (Word* w = mWords; n--; ++w) *w = ~*w;
445  }
447  void setFirstOn() { this->setOn(0); }
449  void setLastOn() { this->setOn(SIZE-1); }
451  void setFirstOff() { this->setOff(0); }
453  void setLastOff() { this->setOff(SIZE-1); }
455  bool isOn(Index32 n) const
456  {
457  assert( (n >> 6) < WORD_COUNT );
458  return 0 != (mWords[n >> 6] & (Word(1) << (n & 63)));
459  }
461  bool isOff(Index32 n) const {return !this->isOn(n); }
463  bool isOn() const
464  {
465  int n = WORD_COUNT;
466  for (const Word *w = mWords; n-- && *w++ == ~Word(0);) ;
467  return n == -1;
468  }
470  bool isOff() const
471  {
472  int n = WORD_COUNT;
473  for (const Word *w = mWords; n-- && *w++ == Word(0);) ;
474  return n == -1;
475  }
477  {
478  Index32 n = 0;
479  const Word* w = mWords;
480  for (; n<WORD_COUNT && !*w; ++w, ++n) ;
481  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(*w);
482  }
484  {
485  Index32 n = 0;
486  const Word* w = mWords;
487  for (; n<WORD_COUNT && !~*w; ++w, ++n) ;
488  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(~*w);
489  }
490 
492  template<typename WordT>
494  WordT getWord(Index n) const
495  {
496  assert(n*8*sizeof(WordT) < SIZE);
497  return reinterpret_cast<const WordT*>(mWords)[n];
498  }
499  template<typename WordT>
500  WordT& getWord(Index n)
501  {
502  assert(n*8*sizeof(WordT) < SIZE);
503  return reinterpret_cast<WordT*>(mWords)[n];
504  }
506 
507  void save(std::ostream& os) const
508  {
509  os.write(reinterpret_cast<const char*>(mWords), this->memUsage());
510  }
511  void load(std::istream& is) {
512  is.read(reinterpret_cast<char*>(mWords), this->memUsage());
513  }
515  void printInfo(std::ostream& os=std::cout) const
516  {
517  os << "NodeMask: Dim=" << DIM << " Log2Dim=" << Log2Dim
518  << " Bit count=" << SIZE << " word count=" << WORD_COUNT << std::endl;
519  }
520  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const
521  {
522  const Index32 n=(SIZE>max_out ? max_out : SIZE);
523  for (Index32 i=0; i < n; ++i) {
524  if ( !(i & 63) )
525  os << "||";
526  else if ( !(i%8) )
527  os << "|";
528  os << this->isOn(i);
529  }
530  os << "|" << std::endl;
531  }
532  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const
533  {
534  this->printInfo(os);
535  this->printBits(os, max_out);
536  }
537 
539  {
540  Index32 n = start >> 6;//initiate
541  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
542  Index32 m = start & 63;
543  Word b = mWords[n];
544  if (b & (Word(1) << m)) return start;//simpel case: start is on
545  b &= ~Word(0) << m;// mask out lower bits
546  while(!b && ++n<WORD_COUNT) b = mWords[n];// find next none-zero word
547  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
548  }
549 
551  {
552  Index32 n = start >> 6;//initiate
553  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
554  Index32 m = start & 63;
555  Word b = ~mWords[n];
556  if (b & (Word(1) << m)) return start;//simpel case: start is on
557  b &= ~Word(0) << m;// mask out lower bits
558  while(!b && ++n<WORD_COUNT) b = ~mWords[n];// find next none-zero word
559  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
560  }
561 };// NodeMask
562 
563 
565 template<>
566 class NodeMask<1>
567 {
568 public:
569 
570  static const Index32 LOG2DIM = 1;
571  static const Index32 DIM = 2;
572  static const Index32 SIZE = 8;
573  static const Index32 WORD_COUNT = 1;
574  typedef Byte Word;
575 
576 private:
577 
578  Byte mByte;//only member data!
579 
580 public:
582  NodeMask() : mByte(0x00U) {}
584  NodeMask(bool on) : mByte(on ? 0xFFU : 0x00U) {}
586  NodeMask(const NodeMask &other) : mByte(other.mByte) {}
590  void operator = (const NodeMask &other) { mByte = other.mByte; }
591 
595 
596  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
597  OnIterator endOn() const { return OnIterator(SIZE,this); }
598  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
599  OffIterator endOff() const { return OffIterator(SIZE,this); }
600  DenseIterator beginDense() const { return DenseIterator(0,this); }
601  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
602 
603  bool operator == (const NodeMask &other) const { return mByte == other.mByte; }
604 
605  bool operator != (const NodeMask &other) const {return mByte != other.mByte; }
606 
607  //
608  // Bitwise logical operations
609  //
610  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
611  const NodeMask& operator&=(const NodeMask& other)
612  {
613  mByte &= other.mByte;
614  return *this;
615  }
616  const NodeMask& operator|=(const NodeMask& other)
617  {
618  mByte |= other.mByte;
619  return *this;
620  }
621  const NodeMask& operator^=(const NodeMask& other)
622  {
623  mByte ^= other.mByte;
624  return *this;
625  }
626  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
627  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
628  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
630  static Index32 memUsage() { return 1; }
632  Index32 countOn() const { return CountOn(mByte); }
634  Index32 countOff() const { return CountOff(mByte); }
636  void setOn(Index32 n) {
637  assert( n < 8 );
638  mByte = mByte | static_cast<Byte>(0x01U << (n & 7));
639  }
641  void setOff(Index32 n) {
642  assert( n < 8 );
643  mByte = mByte & static_cast<Byte>(~(0x01U << (n & 7)));
644  }
646  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
648  void set(bool on) { mByte = on ? 0xFFU : 0x00U; }
650  void setOn() { mByte = 0xFFU; }
652  void setOff() { mByte = 0x00U; }
654  void toggle(Index32 n) {
655  assert( n < 8 );
656  mByte = mByte ^ static_cast<Byte>(0x01U << (n & 7));
657  }
659  void toggle() { mByte = static_cast<Byte>(~mByte); }
661  void setFirstOn() { this->setOn(0); }
663  void setLastOn() { this->setOn(7); }
665  void setFirstOff() { this->setOff(0); }
667  void setLastOff() { this->setOff(7); }
669  bool isOn(Index32 n) const
670  {
671  assert( n < 8 );
672  return mByte & (0x01U << (n & 7));
673  }
675  bool isOff(Index32 n) const {return !this->isOn(n); }
677  bool isOn() const { return mByte == 0xFFU; }
679  bool isOff() const { return mByte == 0; }
680  Index32 findFirstOn() const { return mByte ? FindLowestOn(mByte) : 8; }
682  {
683  const Byte b = static_cast<Byte>(~mByte);
684  return b ? FindLowestOn(b) : 8;
685  }
686  /*
688  template<typename WordT>
691  WordT getWord(Index n) const
692  {
693  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
694  assert(n == 0);
695  return reinterpret_cast<WordT>(mByte);
696  }
697  template<typename WordT>
698  WordT& getWord(Index n)
699  {
700  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
701  assert(n == 0);
702  return reinterpret_cast<WordT&>(mByte);
703  }
705  */
706  void save(std::ostream& os) const
707  {
708  os.write(reinterpret_cast<const char*>(&mByte), 1);
709  }
710  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mByte), 1); }
712  void printInfo(std::ostream& os=std::cout) const
713  {
714  os << "NodeMask: Dim=2, Log2Dim=1, Bit count=8, Word count=1"<<std::endl;
715  }
716  void printBits(std::ostream& os=std::cout) const
717  {
718  os << "||";
719  for (Index32 i=0; i < 8; ++i) os << this->isOn(i);
720  os << "||" << std::endl;
721  }
722  void printAll(std::ostream& os=std::cout) const
723  {
724  this->printInfo(os);
725  this->printBits(os);
726  }
727 
729  {
730  if (start>=8) return 8;
731  const Byte b = static_cast<Byte>(mByte & (0xFFU << start));
732  return b ? FindLowestOn(b) : 8;
733  }
734 
736  {
737  if (start>=8) return 8;
738  const Byte b = static_cast<Byte>(~mByte & (0xFFU << start));
739  return b ? FindLowestOn(b) : 8;
740  }
741 
742 };// NodeMask<1>
743 
744 
746 template<>
747 class NodeMask<2>
748 {
749 public:
750 
751  static const Index32 LOG2DIM = 2;
752  static const Index32 DIM = 4;
753  static const Index32 SIZE = 64;
754  static const Index32 WORD_COUNT = 1;
755  typedef Index64 Word;
756 
757 private:
758 
759  Word mWord;//only member data!
760 
761 public:
763  NodeMask() : mWord(UINT64_C(0x00)) {}
765  NodeMask(bool on) : mWord(on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00)) {}
767  NodeMask(const NodeMask &other) : mWord(other.mWord) {}
771  void operator = (const NodeMask &other) { mWord = other.mWord; }
772 
776 
777  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
778  OnIterator endOn() const { return OnIterator(SIZE,this); }
779  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
780  OffIterator endOff() const { return OffIterator(SIZE,this); }
781  DenseIterator beginDense() const { return DenseIterator(0,this); }
782  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
783 
784  bool operator == (const NodeMask &other) const { return mWord == other.mWord; }
785 
786  bool operator != (const NodeMask &other) const {return mWord != other.mWord; }
787 
788  //
789  // Bitwise logical operations
790  //
791  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
792  const NodeMask& operator&=(const NodeMask& other)
793  {
794  mWord &= other.mWord;
795  return *this;
796  }
797  const NodeMask& operator|=(const NodeMask& other)
798  {
799  mWord |= other.mWord;
800  return *this;
801  }
802  const NodeMask& operator^=(const NodeMask& other)
803  {
804  mWord ^= other.mWord;
805  return *this;
806  }
807  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
808  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
809  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
811  static Index32 memUsage() { return 8; }
813  Index32 countOn() const { return CountOn(mWord); }
815  Index32 countOff() const { return CountOff(mWord); }
817  void setOn(Index32 n) {
818  assert( n < 64 );
819  mWord |= UINT64_C(0x01) << (n & 63);
820  }
822  void setOff(Index32 n) {
823  assert( n < 64 );
824  mWord &= ~(UINT64_C(0x01) << (n & 63));
825  }
827  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
829  void set(bool on) { mWord = on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00); }
831  void setOn() { mWord = UINT64_C(0xFFFFFFFFFFFFFFFF); }
833  void setOff() { mWord = UINT64_C(0x00); }
835  void toggle(Index32 n) {
836  assert( n < 64 );
837  mWord ^= UINT64_C(0x01) << (n & 63);
838  }
840  void toggle() { mWord = ~mWord; }
842  void setFirstOn() { this->setOn(0); }
844  void setLastOn() { this->setOn(63); }
846  void setFirstOff() { this->setOff(0); }
848  void setLastOff() { this->setOff(63); }
850  bool isOn(Index32 n) const
851  {
852  assert( n < 64 );
853  return 0 != (mWord & (UINT64_C(0x01) << (n & 63)));
854  }
856  bool isOff(Index32 n) const {return !this->isOn(n); }
858  bool isOn() const { return mWord == UINT64_C(0xFFFFFFFFFFFFFFFF); }
860  bool isOff() const { return mWord == 0; }
861  Index32 findFirstOn() const { return mWord ? FindLowestOn(mWord) : 64; }
863  {
864  const Word w = ~mWord;
865  return w ? FindLowestOn(w) : 64;
866  }
868  template<typename WordT>
870  WordT getWord(Index n) const
871  {
872  assert(n*8*sizeof(WordT) < SIZE);
873  return reinterpret_cast<const WordT*>(&mWord)[n];
874  }
875  template<typename WordT>
876  WordT& getWord(Index n)
877  {
878  assert(n*8*sizeof(WordT) < SIZE);
879  return reinterpret_cast<WordT*>(mWord)[n];
880  }
882  void save(std::ostream& os) const
883  {
884  os.write(reinterpret_cast<const char*>(&mWord), 8);
885  }
886  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mWord), 8); }
888  void printInfo(std::ostream& os=std::cout) const
889  {
890  os << "NodeMask: Dim=4, Log2Dim=2, Bit count=64, Word count=1"<<std::endl;
891  }
892  void printBits(std::ostream& os=std::cout) const
893  {
894  os << "|";
895  for (Index32 i=0; i < 64; ++i) {
896  if ( !(i%8) ) os << "|";
897  os << this->isOn(i);
898  }
899  os << "||" << std::endl;
900  }
901  void printAll(std::ostream& os=std::cout) const
902  {
903  this->printInfo(os);
904  this->printBits(os);
905  }
906 
908  {
909  if (start>=64) return 64;
910  const Word w = mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
911  return w ? FindLowestOn(w) : 64;
912  }
913 
915  {
916  if (start>=64) return 64;
917  const Word w = ~mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
918  return w ? FindLowestOn(w) : 64;
919  }
920 
921 };// NodeMask<2>
922 
923 
924 // Unlike NodeMask above this RootNodeMask has a run-time defined size.
925 // It is only included for backward compatibility and will likely be
926 // deprecated in the future!
927 // This class is 32-bit specefic, hence the use if Index32 vs Index!
929 {
930 protected:
931  Index32 mBitSize, mIntSize;
933 
934 public:
935  RootNodeMask(): mBitSize(0), mIntSize(0), mBits(NULL) {}
937  mBitSize(bit_size), mIntSize(((bit_size-1)>>5)+1), mBits(new Index32[mIntSize])
938  {
939  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
940  }
942  mBitSize(B.mBitSize), mIntSize(B.mIntSize), mBits(new Index32[mIntSize])
943  {
944  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
945  }
946  ~RootNodeMask() {delete [] mBits;}
947 
948  void init(Index32 bit_size) {
949  mBitSize = bit_size;
950  mIntSize =((bit_size-1)>>5)+1;
951  delete [] mBits;
952  mBits = new Index32[mIntSize];
953  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
954  }
955 
956  Index getBitSize() const {return mBitSize;}
957 
958  Index getIntSize() const {return mIntSize;}
959 
961  if (mBitSize!=B.mBitSize) {
962  mBitSize=B.mBitSize;
963  mIntSize=B.mIntSize;
964  delete [] mBits;
965  mBits = new Index32[mIntSize];
966  }
967  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
968  return *this;
969  }
970 
972  {
973  protected:
974  Index32 mPos;//bit position
976  const RootNodeMask* mParent;//this iterator can't change the parent_mask!
977  public:
978  BaseIterator() : mPos(0), mBitSize(0), mParent(NULL) {}
979  BaseIterator(Index32 pos,const RootNodeMask *parent)
980  : mPos(pos), mBitSize(parent->getBitSize()), mParent(parent) {
981  assert( pos<=mBitSize );
982  }
983  bool operator==(const BaseIterator &iter) const {return mPos == iter.mPos;}
984  bool operator!=(const BaseIterator &iter) const {return mPos != iter.mPos;}
985  bool operator< (const BaseIterator &iter) const {return mPos < iter.mPos;}
987  mPos = iter.mPos;
988  mBitSize = iter.mBitSize;
989  mParent = iter.mParent;
990  return *this;
991  }
992 
993  Index32 offset() const {return mPos;}
994 
995  Index32 pos() const {return mPos;}
996 
997  bool test() const {
998  assert(mPos <= mBitSize);
999  return (mPos != mBitSize);
1000  }
1001 
1002  operator bool() const {return this->test();}
1003  }; // class BaseIterator
1004 
1006  class OnIterator: public BaseIterator
1007  {
1008  protected:
1009  using BaseIterator::mPos;//bit position;
1010  using BaseIterator::mBitSize;//bit size;
1011  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1012  public:
1014  OnIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1015  void increment() {
1016  assert(mParent!=NULL);
1017  mPos=mParent->findNextOn(mPos+1);
1018  assert(mPos <= mBitSize);
1019  }
1020  void increment(Index n) {
1021  for (Index i=0; i<n && this->next(); ++i) {}
1022  }
1023  bool next() {
1024  this->increment();
1025  return this->test();
1026  }
1027  bool operator*() const {return true;}
1029  this->increment();
1030  return *this;
1031  }
1032  }; // class OnIterator
1033 
1035  {
1036  protected:
1037  using BaseIterator::mPos;//bit position;
1038  using BaseIterator::mBitSize;//bit size;
1039  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1040  public:
1042  OffIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1043  void increment() {
1044  assert(mParent!=NULL);
1045  mPos=mParent->findNextOff(mPos+1);
1046  assert(mPos <= mBitSize);
1047  }
1048  void increment(Index n) {
1049  for (Index i=0; i<n && this->next(); ++i) {}
1050  }
1051  bool next() {
1052  this->increment();
1053  return this->test();
1054  }
1055  bool operator*() const {return true;}
1057  this->increment();
1058  return *this;
1059  }
1060  }; // class OffIterator
1061 
1063  {
1064  protected:
1065  using BaseIterator::mPos;//bit position;
1066  using BaseIterator::mBitSize;//bit size;
1067  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1068  public:
1070  DenseIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1071  void increment() {
1072  assert(mParent!=NULL);
1073  mPos += 1;//carefull - the increament might go beyond the end
1074  assert(mPos<= mBitSize);
1075  }
1076  void increment(Index n) {
1077  for (Index i=0; i<n && this->next(); ++i) {}
1078  }
1079  bool next() {
1080  this->increment();
1081  return this->test();
1082  }
1083  bool operator*() const {return mParent->isOn(mPos);}
1085  this->increment();
1086  return *this;
1087  }
1088  }; // class DenseIterator
1089 
1090  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
1091  OnIterator endOn() const { return OnIterator(mBitSize,this); }
1092  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
1093  OffIterator endOff() const { return OffIterator(mBitSize,this); }
1094  DenseIterator beginDense() const { return DenseIterator(0,this); }
1095  DenseIterator endDense() const { return DenseIterator(mBitSize,this); }
1096 
1097  bool operator == (const RootNodeMask &B) const {
1098  if (mBitSize != B.mBitSize) return false;
1099  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return false;
1100  return true;
1101  }
1102 
1103  bool operator != (const RootNodeMask &B) const {
1104  if (mBitSize != B.mBitSize) return true;
1105  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return true;
1106  return false;
1107  }
1108 
1109  //
1110  // Bitwise logical operations
1111  //
1112  RootNodeMask operator!() const { RootNodeMask m = *this; m.toggle(); return m; }
1113  const RootNodeMask& operator&=(const RootNodeMask& other) {
1114  assert(mIntSize == other.mIntSize);
1115  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1116  mBits[i] &= other.mBits[i];
1117  }
1118  for (Index32 i = other.mIntSize; i < mIntSize; ++i) mBits[i] = 0x00000000;
1119  return *this;
1120  }
1121  const RootNodeMask& operator|=(const RootNodeMask& other) {
1122  assert(mIntSize == other.mIntSize);
1123  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1124  mBits[i] |= other.mBits[i];
1125  }
1126  return *this;
1127  }
1128  const RootNodeMask& operator^=(const RootNodeMask& other) {
1129  assert(mIntSize == other.mIntSize);
1130  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1131  mBits[i] ^= other.mBits[i];
1132  }
1133  return *this;
1134  }
1135  RootNodeMask operator&(const RootNodeMask& other) const {
1136  RootNodeMask m(*this); m &= other; return m;
1137  }
1138  RootNodeMask operator|(const RootNodeMask& other) const {
1139  RootNodeMask m(*this); m |= other; return m;
1140  }
1141  RootNodeMask operator^(const RootNodeMask& other) const {
1142  RootNodeMask m(*this); m ^= other; return m;
1143  }
1144 
1145 
1147  return static_cast<Index32>(mIntSize*sizeof(Index32) + sizeof(*this));
1148  }
1149 
1150  Index32 countOn() const {
1151  assert(mBits);
1152  Index32 n=0;
1153  for (Index32 i=0; i< mIntSize; ++i) n += CountOn(mBits[i]);
1154  return n;
1155  }
1156 
1157  Index32 countOff() const { return mBitSize-this->countOn(); }
1158 
1159  void setOn(Index32 i) {
1160  assert(mBits);
1161  assert( (i>>5) < mIntSize);
1162  mBits[i>>5] |= 1<<(i&31);
1163  }
1164 
1165  void setOff(Index32 i) {
1166  assert(mBits);
1167  assert( (i>>5) < mIntSize);
1168  mBits[i>>5] &= ~(1<<(i&31));
1169  }
1170 
1171  void set(Index32 i, bool On) { On ? this->setOn(i) : this->setOff(i); }
1172 
1173  void setOn() {
1174  assert(mBits);
1175  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0xFFFFFFFF;
1176  }
1177  void setOff() {
1178  assert(mBits);
1179  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1180  }
1181  void toggle(Index32 i) {
1182  assert(mBits);
1183  assert( (i>>5) < mIntSize);
1184  mBits[i>>5] ^= 1<<(i&31);
1185  }
1186  void toggle() {
1187  assert(mBits);
1188  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=~mBits[i];
1189  }
1190  void setFirstOn() { this->setOn(0); }
1191  void setLastOn() { this->setOn(mBitSize-1); }
1192  void setFirstOff() { this->setOff(0); }
1193  void setLastOff() { this->setOff(mBitSize-1); }
1194  bool isOn(Index32 i) const {
1195  assert(mBits);
1196  assert( (i>>5) < mIntSize);
1197  return ( mBits[i >> 5] & (1<<(i&31)) );
1198  }
1199  bool isOff(Index32 i) const {
1200  assert(mBits);
1201  assert( (i>>5) < mIntSize);
1202  return ( ~mBits[i >> 5] & (1<<(i&31)) );
1203  }
1204 
1205  bool isOn() const {
1206  if (!mBits) return false;//undefined is off
1207  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0xFFFFFFFF) return false;
1208  return true;
1209  }
1210 
1211  bool isOff() const {
1212  if (!mBits) return true;//undefined is off
1213  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0) return false;
1214  return true;
1215  }
1216 
1218  assert(mBits);
1219  Index32 i=0;
1220  while(!mBits[i]) if (++i == mIntSize) return mBitSize;//reached end
1221  return 32*i + FindLowestOn(mBits[i]);
1222  }
1223 
1225  assert(mBits);
1226  Index32 i=0;
1227  while(!(~mBits[i])) if (++i == mIntSize) return mBitSize;//reached end
1228  return 32*i + FindLowestOn(~mBits[i]);
1229  }
1230 
1231  void save(std::ostream& os) const {
1232  assert(mBits);
1233  os.write((const char *)mBits,mIntSize*sizeof(Index32));
1234  }
1235  void load(std::istream& is) {
1236  assert(mBits);
1237  is.read((char *)mBits,mIntSize*sizeof(Index32));
1238  }
1240  void printInfo(std::ostream& os=std::cout) const {
1241  os << "RootNodeMask: Bit-size="<<mBitSize<<" Int-size="<<mIntSize<<std::endl;
1242  }
1243 
1244  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const {
1245  const Index32 n=(mBitSize>max_out?max_out:mBitSize);
1246  for (Index32 i=0; i < n; ++i) {
1247  if ( !(i&31) )
1248  os << "||";
1249  else if ( !(i%8) )
1250  os << "|";
1251  os << this->isOn(i);
1252  }
1253  os << "|" << std::endl;
1254  }
1255 
1256  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const {
1257  this->printInfo(os);
1258  this->printBits(os,max_out);
1259  }
1260 
1261  Index32 findNextOn(Index32 start) const {
1262  assert(mBits);
1263  Index32 n = start >> 5, m = start & 31;//initiate
1264  if (n>=mIntSize) return mBitSize; // check for out of bounds
1265  Index32 b = mBits[n];
1266  if (b & (1<<m)) return start;//simple case
1267  b &= 0xFFFFFFFF << m;// mask lower bits
1268  while(!b && ++n<mIntSize) b = mBits[n];// find next nonzero int
1269  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1270  }
1271 
1272  Index32 findNextOff(Index32 start) const {
1273  assert(mBits);
1274  Index32 n = start >> 5, m = start & 31;//initiate
1275  if (n>=mIntSize) return mBitSize; // check for out of bounds
1276  Index32 b = ~mBits[n];
1277  if (b & (1<<m)) return start;//simple case
1278  b &= 0xFFFFFFFF<<m;// mask lower bits
1279  while(!b && ++n<mIntSize) b = ~mBits[n];// find next nonzero int
1280  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1281  }
1282 
1283  Index32 memUsage() const {
1284  assert(mBits);
1285  return static_cast<Index32>(sizeof(Index32*)+(2+mIntSize)*sizeof(Index32));//in bytes
1286  }
1287 }; // class RootNodeMask
1288 
1289 } // namespace util
1290 } // namespace OPENVDB_VERSION_NAME
1291 } // namespace openvdb
1292 
1293 #endif // OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
1294 
1295 // Copyright (c) 2012-2014 DreamWorks Animation LLC
1296 // All rights reserved. This software is distributed under the
1297 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1272
OnIterator & operator++()
Definition: NodeMasks.h:1028
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:677
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:646
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:802
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:582
DenseIterator endDense() const
Definition: NodeMasks.h:601
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:449
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:809
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:827
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:621
DenseIterator endDense() const
Definition: NodeMasks.h:782
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:593
void save(std::ostream &os) const
Definition: NodeMasks.h:507
bool test() const
Definition: NodeMasks.h:194
Index getBitSize() const
Definition: NodeMasks.h:956
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:628
void increment()
Definition: NodeMasks.h:214
void increment()
Definition: NodeMasks.h:1043
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:774
OnMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:213
void setOff()
Definition: NodeMasks.h:1177
void setOff()
Set all bits off.
Definition: NodeMasks.h:430
~RootNodeMask()
Definition: NodeMasks.h:946
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:463
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:858
bool operator*() const
Definition: NodeMasks.h:1027
OffIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1042
void increment()
Definition: NodeMasks.h:1015
void load(std::istream &is)
Definition: NodeMasks.h:511
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:767
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:538
Index32 findFirstOff() const
Definition: NodeMasks.h:483
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:447
void increment()
Definition: NodeMasks.h:277
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:586
Base class for the bit mask iterators.
Definition: NodeMasks.h:174
uint64_t Index64
Definition: Types.h:58
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:842
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:630
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:383
Index32 memUsage() const
Definition: NodeMasks.h:1283
bool operator==(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:185
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:817
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:661
void increment(Index n)
Definition: NodeMasks.h:251
bool operator==(const BaseIterator &iter) const
Definition: NodeMasks.h:983
DenseMaskIterator()
Definition: NodeMasks.h:275
OffIterator endOff() const
Definition: NodeMasks.h:352
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:636
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:815
bool next()
Definition: NodeMasks.h:221
void toggle()
Definition: NodeMasks.h:1186
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:648
void setOn(Index32 i)
Definition: NodeMasks.h:1159
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1240
void save(std::ostream &os) const
Definition: NodeMasks.h:706
void load(std::istream &is)
Definition: NodeMasks.h:710
Index32 * mBits
Definition: NodeMasks.h:932
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:611
Index64 Word
Definition: NodeMasks.h:755
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:840
bool test() const
Definition: NodeMasks.h:997
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:811
Index32 mBitSize
Definition: NodeMasks.h:931
const RootNodeMask * mParent
Definition: NodeMasks.h:976
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:391
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:369
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:792
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:436
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:659
DenseIterator & operator++()
Definition: NodeMasks.h:1084
DenseIterator beginDense() const
Definition: NodeMasks.h:353
void increment(Index n)
Definition: NodeMasks.h:220
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:345
Index32 mBitSize
Definition: NodeMasks.h:975
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:634
OffMaskIterator()
Definition: NodeMasks.h:243
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:829
OffIterator beginOff() const
Definition: NodeMasks.h:1092
bool next()
Definition: NodeMasks.h:252
void save(std::ostream &os) const
Definition: NodeMasks.h:882
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:641
void load(std::istream &is)
Definition: NodeMasks.h:886
void setFirstOn()
Definition: NodeMasks.h:1190
Index32 mPos
Definition: NodeMasks.h:974
OffMaskIterator & operator++()
Definition: NodeMasks.h:258
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:550
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:626
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:151
Index32 findFirstOff() const
Definition: NodeMasks.h:1224
Index32 findFirstOn() const
Definition: NodeMasks.h:476
Index getIntSize() const
Definition: NodeMasks.h:958
OnIterator endOn() const
Definition: NodeMasks.h:350
const RootNodeMask & operator|=(const RootNodeMask &other)
Definition: NodeMasks.h:1121
DenseIterator beginDense() const
Definition: NodeMasks.h:1094
const RootNodeMask & operator^=(const RootNodeMask &other)
Definition: NodeMasks.h:1128
NodeMask operator!() const
Definition: NodeMasks.h:791
NodeMask operator!() const
Definition: NodeMasks.h:368
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:417
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:822
#define B6(n)
OnIterator endOn() const
Definition: NodeMasks.h:778
RootNodeMask operator|(const RootNodeMask &other) const
Definition: NodeMasks.h:1138
bool operator*() const
Definition: NodeMasks.h:226
OnIterator beginOn() const
Definition: NodeMasks.h:777
NodeMask operator!() const
Definition: NodeMasks.h:610
Index32 mPos
Definition: NodeMasks.h:177
NodeMask & operator=(const NodeMask &other)
Assignment operator.
Definition: NodeMasks.h:337
RootNodeMask(const RootNodeMask &B)
Definition: NodeMasks.h:941
OnIterator endOn() const
Definition: NodeMasks.h:597
BaseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:181
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:844
Index32 findFirstOn() const
Definition: NodeMasks.h:861
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:807
void increment(Index n)
Definition: NodeMasks.h:1076
OnIterator beginOn() const
Definition: NodeMasks.h:596
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:455
DenseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:276
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:494
Index32 findFirstOn() const
Definition: NodeMasks.h:680
bool operator!=(const BaseIterator &iter) const
Definition: NodeMasks.h:984
Index32 mIntSize
Definition: NodeMasks.h:931
#define OPENVDB_VERSION_NAME
Definition: version.h:43
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:592
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:888
bool next()
Definition: NodeMasks.h:1023
bool isOff(Index32 i) const
Definition: NodeMasks.h:1199
DenseMaskIterator & operator++()
Definition: NodeMasks.h:290
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:663
bool next()
Definition: NodeMasks.h:1051
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:346
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:773
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:584
void increment(Index n)
Definition: NodeMasks.h:1020
Index32 Index
Definition: Types.h:59
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:712
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:860
RootNodeMask operator^(const RootNodeMask &other) const
Definition: NodeMasks.h:1141
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:461
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:453
const RootNodeMask & operator&=(const RootNodeMask &other)
Definition: NodeMasks.h:1113
bool operator*() const
Definition: NodeMasks.h:289
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:470
bool operator!=(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:186
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:765
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:679
BaseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:979
OffIterator beginOff() const
Definition: NodeMasks.h:351
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:376
bool isOn() const
Definition: NodeMasks.h:1205
Index64 Word
Definition: NodeMasks.h:313
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:667
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:396
OnMaskIterator()
Definition: NodeMasks.h:212
Definition: NodeMasks.h:236
Definition: Exceptions.h:39
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:532
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:848
void increment()
Definition: NodeMasks.h:1071
void increment(Index n)
Definition: NodeMasks.h:1048
RootNodeMask operator!() const
Definition: NodeMasks.h:1112
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:415
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:520
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:813
void init(Index32 bit_size)
Definition: NodeMasks.h:948
void setOn()
Set all bits on.
Definition: NodeMasks.h:831
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:394
Index32 getMemUsage() const
Definition: NodeMasks.h:1146
BaseMaskIterator & operator=(const BaseMaskIterator &iter)
Definition: NodeMasks.h:188
void load(std::istream &is)
Definition: NodeMasks.h:1235
Byte Word
Definition: NodeMasks.h:574
RootNodeMask operator&(const RootNodeMask &other) const
Definition: NodeMasks.h:1135
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:632
void setOn()
Set all bits on.
Definition: NodeMasks.h:650
void setOff()
Set all bits off.
Definition: NodeMasks.h:652
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:808
OnIterator endOn() const
Definition: NodeMasks.h:1091
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:876
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:347
Index32 findFirstOn() const
Definition: NodeMasks.h:1217
Index32 pos() const
Definition: NodeMasks.h:193
Index32 findFirstOff() const
Definition: NodeMasks.h:681
Definition: NodeMasks.h:267
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:451
~NodeMask()
Destructor.
Definition: NodeMasks.h:588
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:716
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:722
OffIterator endOff() const
Definition: NodeMasks.h:599
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:500
Index32 CountOn(Index64 v)
Return the number of on bits in the given 64-bit value.
Definition: NodeMasks.h:92
bool operator*() const
Definition: NodeMasks.h:1055
Index32 findFirstOff() const
Definition: NodeMasks.h:862
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:333
void increment(Index n)
Definition: NodeMasks.h:283
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:901
RootNodeMask & operator=(const RootNodeMask &B)
Definition: NodeMasks.h:960
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:331
void setOff()
Set all bits off.
Definition: NodeMasks.h:833
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:870
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:627
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:616
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:329
void setOff(Index32 i)
Definition: NodeMasks.h:1165
Index32 countOff() const
Definition: NodeMasks.h:1157
Index32 countOn() const
Definition: NodeMasks.h:1150
unsigned char Byte
Definition: Types.h:64
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:410
OffIterator & operator++()
Definition: NodeMasks.h:1056
BaseMaskIterator()
Definition: NodeMasks.h:180
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:665
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:405
~NodeMask()
Destructor.
Definition: NodeMasks.h:769
void setOn()
Set all bits on.
Definition: NodeMasks.h:424
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:892
Definition: NodeMasks.h:205
void increment()
Definition: NodeMasks.h:245
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:914
DenseIterator endDense() const
Definition: NodeMasks.h:354
OffIterator endOff() const
Definition: NodeMasks.h:780
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:515
void toggle(Index32 i)
Definition: NodeMasks.h:1181
OffIterator()
Definition: NodeMasks.h:1041
bool operator*() const
Definition: NodeMasks.h:1083
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:835
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:441
void setLastOff()
Definition: NodeMasks.h:1193
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:735
bool operator*() const
Definition: NodeMasks.h:257
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:669
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:797
OnIterator()
Definition: NodeMasks.h:1013
OnIterator beginOn() const
Definition: NodeMasks.h:349
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:654
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:846
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:850
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1256
bool next()
Definition: NodeMasks.h:284
DenseIterator beginDense() const
Definition: NodeMasks.h:781
OffMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:244
RootNodeMask()
Definition: NodeMasks.h:935
Index32 FindLowestOn(Index64 v)
Return the least significant on bit of the given 64-bit value.
Definition: NodeMasks.h:133
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
OffIterator beginOff() const
Definition: NodeMasks.h:598
void save(std::ostream &os) const
Definition: NodeMasks.h:1231
const NodeMask * mParent
Definition: NodeMasks.h:178
OffIterator endOff() const
Definition: NodeMasks.h:1093
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:594
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:392
DenseIterator beginDense() const
Definition: NodeMasks.h:600
BaseIterator & operator=(const BaseIterator &iter)
Definition: NodeMasks.h:986
void setFirstOff()
Definition: NodeMasks.h:1192
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:856
OnMaskIterator & operator++()
Definition: NodeMasks.h:227
uint32_t Index32
Definition: Types.h:57
DenseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1070
Index32 offset() const
Definition: NodeMasks.h:192
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:775
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:390
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1244
~NodeMask()
Destructor.
Definition: NodeMasks.h:335
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:728
OffIterator beginOff() const
Definition: NodeMasks.h:779
void set(Index32 i, bool On)
Definition: NodeMasks.h:1171
void setLastOn()
Definition: NodeMasks.h:1191
Index32 offset() const
Definition: NodeMasks.h:993
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:907
bool next()
Definition: NodeMasks.h:1079
void setOn()
Definition: NodeMasks.h:1173
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:675
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:403
bool isOff() const
Definition: NodeMasks.h:1211
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:763
RootNodeMask(Index32 bit_size)
Definition: NodeMasks.h:936
OnIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1014
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1261
Index32 CountOff(Index64 v)
Return the number of off bits in the given 64-bit value.
Definition: NodeMasks.h:101
Index32 pos() const
Definition: NodeMasks.h:995
bool isOn(Index32 i) const
Definition: NodeMasks.h:1194
OnIterator beginOn() const
Definition: NodeMasks.h:1090
Definition: NodeMasks.h:928
DenseIterator endDense() const
Definition: NodeMasks.h:1095