OpenVDB  2.1.0
NodeMasks.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2013 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/Types.h>
42 //#include <boost/mpl/if.hpp>
43 //#include <strings.h> // for ffs
44 
45 namespace openvdb {
47 namespace OPENVDB_VERSION_NAME {
48 namespace util {
49 
51 inline Index32
53 {
54  // Simple LUT:
55  static const Byte numBits[256] = {
56 # define B2(n) n, n+1, n+1, n+2
57 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
58 # define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2)
59  B6(0), B6(1), B6(1), B6(2)
60  };
61  return numBits[v];
62 
63  // Sequentially clear least significant bits
64  //Index32 c;
65  //for (c = 0; v; c++) v &= v - 0x01U;
66  //return c;
67 
68  // This version is only fast on CPUs with fast "%" and "*" operations
69  //return (v * UINT64_C(0x200040008001) & UINT64_C(0x111111111111111)) % 0xF;
70 }
72 inline Index32 CountOff(Byte v) { return CountOn(~v); }
73 
75 inline Index32
77 {
78  v = v - ((v >> 1) & 0x55555555U);
79  v = (v & 0x33333333U) + ((v >> 2) & 0x33333333U);
80  return (((v + (v >> 4)) & 0xF0F0F0FU) * 0x1010101U) >> 24;
81 }
82 
84 inline Index32 CountOff(Index32 v) { return CountOn(~v); }
85 
87 inline Index32
89 {
90  v = v - ((v >> 1) & UINT64_C(0x5555555555555555));
91  v = (v & UINT64_C(0x3333333333333333)) + ((v >> 2) & UINT64_C(0x3333333333333333));
92  return (((v + (v >> 4)) & UINT64_C(0xF0F0F0F0F0F0F0F)) * UINT64_C(0x101010101010101)) >> 56;
93 }
94 
96 inline Index32 CountOff(Index64 v) { return CountOn(~v); }
97 
99 inline Index32
101 {
102  assert(v);
103  static const Byte DeBruijn[8] = {0, 1, 6, 2, 7, 5, 4, 3};
104  return DeBruijn[Byte((v & -v) * 0x1DU) >> 5];
105 }
106 
108 inline Index32
110 {
111  assert(v);
112  //return ffs(v);
113  static const Byte DeBruijn[32] = {
114  0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
115  31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
116  };
117  return DeBruijn[Index32((v & -v) * 0x077CB531U) >> 27];
118 }
119 
121 inline Index32
123 {
124  assert(v);
125  //return ffsll(v);
126  static const Byte DeBruijn[64] = {
127  0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
128  62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
129  63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
130  51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12,
131  };
132  return DeBruijn[Index64((v & -v) * UINT64_C(0x022FDD63CC95386D)) >> 58];
133 }
134 
136 inline Index32
138 {
139  static const Byte DeBruijn[32] = {
140  0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
141  8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
142  };
143  v |= v >> 1; // first round down to one less than a power of 2
144  v |= v >> 2;
145  v |= v >> 4;
146  v |= v >> 8;
147  v |= v >> 16;
148  return DeBruijn[Index32(v * 0x07C4ACDDU) >> 27];
149 }
150 
151 
153 
154 
156 template <typename NodeMask>
158 {
159 protected:
160  Index32 mPos;//bit position
161  const NodeMask* mParent;//this iterator can't change the parent_mask!
162 public:
163  BaseMaskIterator() : mPos(NodeMask::SIZE), mParent(NULL) {}
164  BaseMaskIterator(Index32 pos,const NodeMask *parent) : mPos(pos), mParent(parent)
165  {
166  assert( (parent==NULL && pos==0 ) || (parent!=NULL && pos<=NodeMask::SIZE) );
167  }
168  bool operator==(const BaseMaskIterator &iter) const {return mPos == iter.mPos;}
169  bool operator!=(const BaseMaskIterator &iter) const {return mPos != iter.mPos;}
170  bool operator< (const BaseMaskIterator &iter) const {return mPos < iter.mPos;}
171  void operator= (const BaseMaskIterator &iter)
172  {
173  mPos = iter.mPos;
174  mParent = iter.mParent;
175  }
176  Index32 offset() const {return mPos;}
177  Index32 pos() const {return mPos;}
178  bool test() const
179  {
180  assert(mPos <= NodeMask::SIZE);
181  return (mPos != NodeMask::SIZE);
182  }
183  operator bool() const {return this->test();}
184 }; // class BaseMaskIterator
185 
186 
188 template <typename NodeMask>
189 class OnMaskIterator: public BaseMaskIterator<NodeMask>
190 {
191 private:
193  using BaseType::mPos;//bit position;
194  using BaseType::mParent;//this iterator can't change the parent_mask!
195 public:
197  OnMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
198  void increment()
199  {
200  assert(mParent != NULL);
201  mPos = mParent->findNextOn(mPos+1);
202  assert(mPos <= NodeMask::SIZE);
203  }
204  void increment(Index n) { while(n-- && this->next()) ; }
205  bool next()
206  {
207  this->increment();
208  return this->test();
209  }
210  bool operator*() const {return true;}
212  {
213  this->increment();
214  return *this;
215  }
216 }; // class OnMaskIterator
217 
218 
219 template <typename NodeMask>
220 class OffMaskIterator: public BaseMaskIterator<NodeMask>
221 {
222 private:
224  using BaseType::mPos;//bit position;
225  using BaseType::mParent;//this iterator can't change the parent_mask!
226 public:
228  OffMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
229  void increment()
230  {
231  assert(mParent != NULL);
232  mPos=mParent->findNextOff(mPos+1);
233  assert(mPos <= NodeMask::SIZE);
234  }
235  void increment(Index n) { while(n-- && this->next()) ; }
236  bool next()
237  {
238  this->increment();
239  return this->test();
240  }
241  bool operator*() const {return false;}
243  {
244  this->increment();
245  return *this;
246  }
247 }; // class OffMaskIterator
248 
249 
250 template <typename NodeMask>
251 class DenseMaskIterator: public BaseMaskIterator<NodeMask>
252 {
253 private:
255  using BaseType::mPos;//bit position;
256  using BaseType::mParent;//this iterator can't change the parent_mask!
257 
258 public:
260  DenseMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
261  void increment()
262  {
263  assert(mParent != NULL);
264  mPos += 1;//careful - the increment might go beyond the end
265  assert(mPos<= NodeMask::SIZE);
266  }
267  void increment(Index n) { while(n-- && this->next()) ; }
268  bool next()
269  {
270  this->increment();
271  return this->test();
272  }
273  bool operator*() const {return mParent->isOn(mPos);}
275  {
276  this->increment();
277  return *this;
278  }
279 }; // class DenseMaskIterator
280 
281 
287 template<Index Log2Dim>
288 class NodeMask
289 {
290 public:
291  BOOST_STATIC_ASSERT( Log2Dim>2 );
292 
293  static const Index32 LOG2DIM = Log2Dim;
294  static const Index32 DIM = 1<<Log2Dim;
295  static const Index32 SIZE = 1<<3*Log2Dim;
296  static const Index32 WORD_COUNT = SIZE >> 6;// 2^6=64
297  typedef Index64 Word;
298 
299 private:
300 
301  // The bits are represented as a linear array of Words, and the
302  // size of a Word is 32 or 64 bits depending on the platform.
303  // The BIT_MASK is defined as the number of bits in a Word - 1
304  //static const Index32 BIT_MASK = sizeof(void*) == 8 ? 63 : 31;
305  //static const Index32 LOG2WORD = BIT_MASK == 63 ? 6 : 5;
306  //static const Index32 WORD_COUNT = SIZE >> LOG2WORD;
307  //typedef boost::mpl::if_c<BIT_MASK == 63, Index64, Index32>::type Word;
308 
309  Word mWords[WORD_COUNT];//only member data!
310 
311 public:
313  NodeMask() { this->setOff(); }
315  NodeMask(bool on) { this->set(on); }
317  NodeMask(const NodeMask &other) { *this = other; }
321  void operator = (const NodeMask &other)
322  {
323  Index32 n = WORD_COUNT;
324  const Word* w2 = other.mWords;
325  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 = *w2;
326  }
327 
331 
332  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
333  OnIterator endOn() const { return OnIterator(SIZE,this); }
334  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
335  OffIterator endOff() const { return OffIterator(SIZE,this); }
336  DenseIterator beginDense() const { return DenseIterator(0,this); }
337  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
338 
339  bool operator == (const NodeMask &other) const
340  {
341  int n = WORD_COUNT;
342  for (const Word *w1=mWords, *w2=other.mWords; n-- && *w1++ == *w2++;) ;
343  return n == -1;
344  }
345 
346  bool operator != (const NodeMask &other) const { return !(*this == other); }
347 
348  //
349  // Bitwise logical operations
350  //
351  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
352  const NodeMask& operator&=(const NodeMask& other)
353  {
354  Index32 n = WORD_COUNT;
355  const Word* w2 = other.mWords;
356  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 &= *w2;
357  return *this;
358  }
359  const NodeMask& operator|=(const NodeMask& other)
360  {
361  Index32 n = WORD_COUNT;
362  const Word* w2 = other.mWords;
363  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 |= *w2;
364  return *this;
365  }
366  const NodeMask& operator^=(const NodeMask& other)
367  {
368  Index32 n = WORD_COUNT;
369  const Word* w2 = other.mWords;
370  for ( Word* w1 = mWords; n--; ++w1, ++w2) *w1 ^= *w2;
371  return *this;
372  }
373  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
374  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
375  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
377  static Index32 memUsage() { return WORD_COUNT*sizeof(Word); }
379  OPENVDB_DEPRECATED Index32 getMemUsage() const {return sizeof(*this);}
381  Index32 countOn() const
382  {
383  Index32 sum = 0, n = WORD_COUNT;
384  for (const Word* w = mWords; n--; ++w) sum += CountOn(*w);
385  return sum;
386  }
388  Index32 countOff() const { return SIZE-this->countOn(); }
390  void setOn(Index32 n) {
391  assert( (n >> 6) < WORD_COUNT );
392  mWords[n >> 6] |= Word(1) << (n & 63);
393  }
395  void setOff(Index32 n) {
396  assert( (n >> 6) < WORD_COUNT );
397  mWords[n >> 6] &= ~(Word(1) << (n & 63));
398  }
400  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
402  void set(bool on)
403  {
404  const Word state = on ? ~Word(0) : Word(0);
405  Index32 n = WORD_COUNT;
406  for (Word* w = mWords; n--; ++w) *w = state;
407  }
409  void setOn()
410  {
411  Index32 n = WORD_COUNT;
412  for (Word* w = mWords; n--; ++w) *w = ~Word(0);
413  }
415  void setOff()
416  {
417  Index32 n = WORD_COUNT;
418  for (Word* w = mWords; n--; ++w) *w = Word(0);
419  }
421  void toggle(Index32 n) {
422  assert( (n >> 6) < WORD_COUNT );
423  mWords[n >> 6] ^= 1 << (n & 63);
424  }
426  void toggle()
427  {
428  Index32 n = WORD_COUNT;
429  for (Word* w = mWords; n--; ++w) *w = ~*w;
430  }
432  void setFirstOn() { this->setOn(0); }
434  void setLastOn() { this->setOn(SIZE-1); }
436  void setFirstOff() { this->setOff(0); }
438  void setLastOff() { this->setOff(SIZE-1); }
440  bool isOn(Index32 n) const
441  {
442  assert( (n >> 6) < WORD_COUNT );
443  return 0 != (mWords[n >> 6] & (Word(1) << (n & 63)));
444  }
446  bool isOff(Index32 n) const {return !this->isOn(n); }
448  bool isOn() const
449  {
450  int n = WORD_COUNT;
451  for (const Word *w = mWords; n-- && *w++ == ~Word(0);) ;
452  return n == -1;
453  }
455  bool isOff() const
456  {
457  int n = WORD_COUNT;
458  for (const Word *w = mWords; n-- && *w++ == Word(0);) ;
459  return n == -1;
460  }
462  {
463  Index32 n = 0;
464  const Word* w = mWords;
465  for (; n<WORD_COUNT && !*w; ++w, ++n) ;
466  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(*w);
467  }
469  {
470  Index32 n = 0;
471  const Word* w = mWords;
472  for (; n<WORD_COUNT && !~*w; ++w, ++n) ;
473  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(~*w);
474  }
475 
477  template<typename WordT>
479  WordT getWord(Index n) const
480  {
481  assert(n*8*sizeof(WordT) < SIZE);
482  return reinterpret_cast<const WordT*>(mWords)[n];
483  }
484  template<typename WordT>
485  WordT& getWord(Index n)
486  {
487  assert(n*8*sizeof(WordT) < SIZE);
488  return reinterpret_cast<WordT*>(mWords)[n];
489  }
491 
492  void save(std::ostream& os) const
493  {
494  os.write(reinterpret_cast<const char*>(mWords), this->memUsage());
495  }
496  void load(std::istream& is) {
497  is.read(reinterpret_cast<char*>(mWords), this->memUsage());
498  }
500  void printInfo(std::ostream& os=std::cout) const
501  {
502  os << "NodeMask: Dim=" << DIM << " Log2Dim=" << Log2Dim
503  << " Bit count=" << SIZE << " word count=" << WORD_COUNT << std::endl;
504  }
505  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const
506  {
507  const Index32 n=(SIZE>max_out ? max_out : SIZE);
508  for (Index32 i=0; i < n; ++i) {
509  if ( !(i & 63) )
510  os << "||";
511  else if ( !(i%8) )
512  os << "|";
513  os << this->isOn(i);
514  }
515  os << "|" << std::endl;
516  }
517  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const
518  {
519  this->printInfo(os);
520  this->printBits(os, max_out);
521  }
522 
524  {
525  Index32 n = start >> 6;//initiate
526  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
527  Index32 m = start & 63;
528  Word b = mWords[n];
529  if (b & (Word(1) << m)) return start;//simpel case: start is on
530  b &= ~Word(0) << m;// mask out lower bits
531  while(!b && ++n<WORD_COUNT) b = mWords[n];// find next none-zero word
532  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
533  }
534 
536  {
537  Index32 n = start >> 6;//initiate
538  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
539  Index32 m = start & 63;
540  Word b = ~mWords[n];
541  if (b & (Word(1) << m)) return start;//simpel case: start is on
542  b &= ~Word(0) << m;// mask out lower bits
543  while(!b && ++n<WORD_COUNT) b = ~mWords[n];// find next none-zero word
544  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
545  }
546 };// NodeMask
547 
548 
550 template<>
551 class NodeMask<1>
552 {
553 public:
554 
555  static const Index32 LOG2DIM = 1;
556  static const Index32 DIM = 2;
557  static const Index32 SIZE = 8;
558  static const Index32 WORD_COUNT = 1;
559  typedef Byte Word;
560 
561 private:
562 
563  Byte mByte;//only member data!
564 
565 public:
567  NodeMask() : mByte(0x00U) {}
569  NodeMask(bool on) : mByte(on ? 0xFFU : 0x00U) {}
571  NodeMask(const NodeMask &other) : mByte(other.mByte) {}
575  void operator = (const NodeMask &other) { mByte = other.mByte; }
576 
580 
581  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
582  OnIterator endOn() const { return OnIterator(SIZE,this); }
583  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
584  OffIterator endOff() const { return OffIterator(SIZE,this); }
585  DenseIterator beginDense() const { return DenseIterator(0,this); }
586  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
587 
588  bool operator == (const NodeMask &other) const { return mByte == other.mByte; }
589 
590  bool operator != (const NodeMask &other) const {return mByte != other.mByte; }
591 
592  //
593  // Bitwise logical operations
594  //
595  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
596  const NodeMask& operator&=(const NodeMask& other)
597  {
598  mByte &= other.mByte;
599  return *this;
600  }
601  const NodeMask& operator|=(const NodeMask& other)
602  {
603  mByte |= other.mByte;
604  return *this;
605  }
606  const NodeMask& operator^=(const NodeMask& other)
607  {
608  mByte ^= other.mByte;
609  return *this;
610  }
611  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
612  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
613  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
615  static Index32 memUsage() { return 1; }
617  OPENVDB_DEPRECATED Index32 getMemUsage() const {return sizeof(*this);}
619  Index32 countOn() const { return CountOn(mByte); }
621  Index32 countOff() const { return CountOff(mByte); }
623  void setOn(Index32 n) {
624  assert( n < 8 );
625  mByte |= 0x01U << (n & 7);
626  }
628  void setOff(Index32 n) {
629  assert( n < 8 );
630  mByte &= ~(0x01U << (n & 7));
631  }
633  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
635  void set(bool on) { mByte = on ? 0xFFU : 0x00U; }
637  void setOn() { mByte = 0xFFU; }
639  void setOff() { mByte = 0x00U; }
641  void toggle(Index32 n) {
642  assert( n < 8 );
643  mByte ^= 0x01U << (n & 7);
644  }
646  void toggle() { mByte = ~mByte; }
648  void setFirstOn() { this->setOn(0); }
650  void setLastOn() { this->setOn(7); }
652  void setFirstOff() { this->setOff(0); }
654  void setLastOff() { this->setOff(7); }
656  bool isOn(Index32 n) const
657  {
658  assert( n < 8 );
659  return mByte & (0x01U << (n & 7));
660  }
662  bool isOff(Index32 n) const {return !this->isOn(n); }
664  bool isOn() const { return mByte == 0xFFU; }
666  bool isOff() const { return mByte == 0; }
667  Index32 findFirstOn() const { return mByte ? FindLowestOn(mByte) : 8; }
669  {
670  const Byte b = ~mByte;
671  return b ? FindLowestOn(b) : 8;
672  }
673  /*
675  template<typename WordT>
678  WordT getWord(Index n) const
679  {
680  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
681  assert(n == 0);
682  return reinterpret_cast<WordT>(mByte);
683  }
684  template<typename WordT>
685  WordT& getWord(Index n)
686  {
687  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
688  assert(n == 0);
689  return reinterpret_cast<WordT&>(mByte);
690  }
692  */
693  void save(std::ostream& os) const
694  {
695  os.write(reinterpret_cast<const char*>(&mByte), 1);
696  }
697  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mByte), 1); }
699  void printInfo(std::ostream& os=std::cout) const
700  {
701  os << "NodeMask: Dim=2, Log2Dim=1, Bit count=8, Word count=1"<<std::endl;
702  }
703  void printBits(std::ostream& os=std::cout) const
704  {
705  os << "||";
706  for (Index32 i=0; i < 8; ++i) os << this->isOn(i);
707  os << "||" << std::endl;
708  }
709  void printAll(std::ostream& os=std::cout) const
710  {
711  this->printInfo(os);
712  this->printBits(os);
713  }
714 
716  {
717  if (start>=8) return 8;
718  const Byte b = mByte & (0xFFU << start);
719  return b ? FindLowestOn(b) : 8;
720  }
721 
723  {
724  if (start>=8) return 8;
725  const Byte b = ~mByte & (0xFFU << start);
726  return b ? FindLowestOn(b) : 8;
727  }
728 
729 };// NodeMask<1>
730 
731 
733 template<>
734 class NodeMask<2>
735 {
736 public:
737 
738  static const Index32 LOG2DIM = 2;
739  static const Index32 DIM = 4;
740  static const Index32 SIZE = 64;
741  static const Index32 WORD_COUNT = 1;
742  typedef Index64 Word;
743 
744 private:
745 
746  Word mWord;//only member data!
747 
748 public:
750  NodeMask() : mWord(UINT64_C(0x00)) {}
752  NodeMask(bool on) : mWord(on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00)) {}
754  NodeMask(const NodeMask &other) : mWord(other.mWord) {}
758  void operator = (const NodeMask &other) { mWord = other.mWord; }
759 
763 
764  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
765  OnIterator endOn() const { return OnIterator(SIZE,this); }
766  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
767  OffIterator endOff() const { return OffIterator(SIZE,this); }
768  DenseIterator beginDense() const { return DenseIterator(0,this); }
769  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
770 
771  bool operator == (const NodeMask &other) const { return mWord == other.mWord; }
772 
773  bool operator != (const NodeMask &other) const {return mWord != other.mWord; }
774 
775  //
776  // Bitwise logical operations
777  //
778  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
779  const NodeMask& operator&=(const NodeMask& other)
780  {
781  mWord &= other.mWord;
782  return *this;
783  }
784  const NodeMask& operator|=(const NodeMask& other)
785  {
786  mWord |= other.mWord;
787  return *this;
788  }
789  const NodeMask& operator^=(const NodeMask& other)
790  {
791  mWord ^= other.mWord;
792  return *this;
793  }
794  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
795  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
796  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
798  static Index32 memUsage() { return 8; }
800  OPENVDB_DEPRECATED Index32 getMemUsage() const {return sizeof(*this);}
802  Index32 countOn() const { return CountOn(mWord); }
804  Index32 countOff() const { return CountOff(mWord); }
806  void setOn(Index32 n) {
807  assert( n < 64 );
808  mWord |= UINT64_C(0x01) << (n & 63);
809  }
811  void setOff(Index32 n) {
812  assert( n < 64 );
813  mWord &= ~(UINT64_C(0x01) << (n & 63));
814  }
816  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
818  void set(bool on) { mWord = on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00); }
820  void setOn() { mWord = UINT64_C(0xFFFFFFFFFFFFFFFF); }
822  void setOff() { mWord = UINT64_C(0x00); }
824  void toggle(Index32 n) {
825  assert( n < 64 );
826  mWord ^= UINT64_C(0x01) << (n & 63);
827  }
829  void toggle() { mWord = ~mWord; }
831  void setFirstOn() { this->setOn(0); }
833  void setLastOn() { this->setOn(63); }
835  void setFirstOff() { this->setOff(0); }
837  void setLastOff() { this->setOff(63); }
839  bool isOn(Index32 n) const
840  {
841  assert( n < 64 );
842  return 0 != (mWord & (UINT64_C(0x01) << (n & 63)));
843  }
845  bool isOff(Index32 n) const {return !this->isOn(n); }
847  bool isOn() const { return mWord == UINT64_C(0xFFFFFFFFFFFFFFFF); }
849  bool isOff() const { return mWord == 0; }
850  Index32 findFirstOn() const { return mWord ? FindLowestOn(mWord) : 64; }
852  {
853  const Word w = ~mWord;
854  return w ? FindLowestOn(w) : 64;
855  }
857  template<typename WordT>
859  WordT getWord(Index n) const
860  {
861  assert(n*8*sizeof(WordT) < SIZE);
862  return reinterpret_cast<const WordT*>(&mWord)[n];
863  }
864  template<typename WordT>
865  WordT& getWord(Index n)
866  {
867  assert(n*8*sizeof(WordT) < SIZE);
868  return reinterpret_cast<WordT*>(mWord)[n];
869  }
871  void save(std::ostream& os) const
872  {
873  os.write(reinterpret_cast<const char*>(&mWord), 8);
874  }
875  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mWord), 8); }
877  void printInfo(std::ostream& os=std::cout) const
878  {
879  os << "NodeMask: Dim=4, Log2Dim=2, Bit count=64, Word count=1"<<std::endl;
880  }
881  void printBits(std::ostream& os=std::cout) const
882  {
883  os << "|";
884  for (Index32 i=0; i < 64; ++i) {
885  if ( !(i%8) ) os << "|";
886  os << this->isOn(i);
887  }
888  os << "||" << std::endl;
889  }
890  void printAll(std::ostream& os=std::cout) const
891  {
892  this->printInfo(os);
893  this->printBits(os);
894  }
895 
897  {
898  if (start>=64) return 64;
899  const Word w = mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
900  return w ? FindLowestOn(w) : 64;
901  }
902 
904  {
905  if (start>=64) return 64;
906  const Word w = ~mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
907  return w ? FindLowestOn(w) : 64;
908  }
909 
910 };// NodeMask<2>
911 
912 
913 // Unlike NodeMask above this RootNodeMask has a run-time defined size.
914 // It is only included for backward compatibility and will likely be
915 // deprecated in the future!
916 // This class is 32-bit specefic, hence the use if Index32 vs Index!
918 {
919 protected:
920  Index32 mBitSize, mIntSize;
922 
923 public:
924  RootNodeMask(): mBitSize(0), mIntSize(0), mBits(NULL) {}
926  mBitSize(bit_size), mIntSize(((bit_size-1)>>5)+1), mBits(new Index32[mIntSize])
927  {
928  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
929  }
931  mBitSize(B.mBitSize), mIntSize(B.mIntSize), mBits(new Index32[mIntSize])
932  {
933  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
934  }
935  ~RootNodeMask() {delete [] mBits;}
936 
937  void init(Index32 bit_size) {
938  mBitSize = bit_size;
939  mIntSize =((bit_size-1)>>5)+1;
940  delete [] mBits;
941  mBits = new Index32[mIntSize];
942  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
943  }
944 
945  Index getBitSize() const {return mBitSize;}
946 
947  Index getIntSize() const {return mIntSize;}
948 
949  void operator = (const RootNodeMask &B) {
950  if (mBitSize!=B.mBitSize) {
951  mBitSize=B.mBitSize;
952  mIntSize=B.mIntSize;
953  delete [] mBits;
954  mBits = new Index32[mIntSize];
955  }
956  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
957  }
958 
960  {
961  protected:
962  Index32 mPos;//bit position
964  const RootNodeMask* mParent;//this iterator can't change the parent_mask!
965  public:
966  BaseIterator() : mPos(0), mBitSize(0), mParent(NULL) {}
967  BaseIterator(Index32 pos,const RootNodeMask *parent)
968  : mPos(pos), mBitSize(parent->getBitSize()), mParent(parent) {
969  assert( pos<=mBitSize );
970  }
971  bool operator==(const BaseIterator &iter) const {return mPos == iter.mPos;}
972  bool operator!=(const BaseIterator &iter) const {return mPos != iter.mPos;}
973  bool operator< (const BaseIterator &iter) const {return mPos < iter.mPos;}
974  void operator=(const BaseIterator &iter) {
975  mPos = iter.mPos;
976  mBitSize = iter.mBitSize;
977  mParent = iter.mParent;
978  }
979 
980  Index32 offset() const {return mPos;}
981 
982  Index32 pos() const {return mPos;}
983 
984  bool test() const {
985  assert(mPos <= mBitSize);
986  return (mPos != mBitSize);
987  }
988 
989  operator bool() const {return this->test();}
990  }; // class BaseIterator
991 
993  class OnIterator: public BaseIterator
994  {
995  protected:
996  using BaseIterator::mPos;//bit position;
997  using BaseIterator::mBitSize;//bit size;
998  using BaseIterator::mParent;//this iterator can't change the parent_mask!
999  public:
1001  OnIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1002  void increment() {
1003  assert(mParent!=NULL);
1004  mPos=mParent->findNextOn(mPos+1);
1005  assert(mPos <= mBitSize);
1006  }
1007  void increment(Index n) {
1008  for (Index i=0; i<n && this->next(); ++i) {}
1009  }
1010  bool next() {
1011  this->increment();
1012  return this->test();
1013  }
1014  bool operator*() const {return true;}
1016  this->increment();
1017  return *this;
1018  }
1019  }; // class OnIterator
1020 
1022  {
1023  protected:
1024  using BaseIterator::mPos;//bit position;
1025  using BaseIterator::mBitSize;//bit size;
1026  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1027  public:
1029  OffIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1030  void increment() {
1031  assert(mParent!=NULL);
1032  mPos=mParent->findNextOff(mPos+1);
1033  assert(mPos <= mBitSize);
1034  }
1035  void increment(Index n) {
1036  for (Index i=0; i<n && this->next(); ++i) {}
1037  }
1038  bool next() {
1039  this->increment();
1040  return this->test();
1041  }
1042  bool operator*() const {return true;}
1044  this->increment();
1045  return *this;
1046  }
1047  }; // class OffIterator
1048 
1050  {
1051  protected:
1052  using BaseIterator::mPos;//bit position;
1053  using BaseIterator::mBitSize;//bit size;
1054  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1055  public:
1057  DenseIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1058  void increment() {
1059  assert(mParent!=NULL);
1060  mPos += 1;//carefull - the increament might go beyond the end
1061  assert(mPos<= mBitSize);
1062  }
1063  void increment(Index n) {
1064  for (Index i=0; i<n && this->next(); ++i) {}
1065  }
1066  bool next() {
1067  this->increment();
1068  return this->test();
1069  }
1070  bool operator*() const {return mParent->isOn(mPos);}
1072  this->increment();
1073  return *this;
1074  }
1075  }; // class DenseIterator
1076 
1077  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
1078  OnIterator endOn() const { return OnIterator(mBitSize,this); }
1079  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
1080  OffIterator endOff() const { return OffIterator(mBitSize,this); }
1081  DenseIterator beginDense() const { return DenseIterator(0,this); }
1082  DenseIterator endDense() const { return DenseIterator(mBitSize,this); }
1083 
1084  bool operator == (const RootNodeMask &B) const {
1085  if (mBitSize != B.mBitSize) return false;
1086  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return false;
1087  return true;
1088  }
1089 
1090  bool operator != (const RootNodeMask &B) const {
1091  if (mBitSize != B.mBitSize) return true;
1092  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return true;
1093  return false;
1094  }
1095 
1096  //
1097  // Bitwise logical operations
1098  //
1099  RootNodeMask operator!() const { RootNodeMask m = *this; m.toggle(); return m; }
1100  const RootNodeMask& operator&=(const RootNodeMask& other) {
1101  assert(mIntSize == other.mIntSize);
1102  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1103  mBits[i] &= other.mBits[i];
1104  }
1105  for (Index32 i = other.mIntSize; i < mIntSize; ++i) mBits[i] = 0x00000000;
1106  return *this;
1107  }
1108  const RootNodeMask& operator|=(const RootNodeMask& other) {
1109  assert(mIntSize == other.mIntSize);
1110  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1111  mBits[i] |= other.mBits[i];
1112  }
1113  return *this;
1114  }
1115  const RootNodeMask& operator^=(const RootNodeMask& other) {
1116  assert(mIntSize == other.mIntSize);
1117  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1118  mBits[i] ^= other.mBits[i];
1119  }
1120  return *this;
1121  }
1122  RootNodeMask operator&(const RootNodeMask& other) const {
1123  RootNodeMask m(*this); m &= other; return m;
1124  }
1125  RootNodeMask operator|(const RootNodeMask& other) const {
1126  RootNodeMask m(*this); m |= other; return m;
1127  }
1128  RootNodeMask operator^(const RootNodeMask& other) const {
1129  RootNodeMask m(*this); m ^= other; return m;
1130  }
1131 
1132 
1133  Index32 getMemUsage() const {return mIntSize*sizeof(Index32) + sizeof(*this);}
1134 
1135  Index32 countOn() const {
1136  assert(mBits);
1137  Index32 n=0;
1138  for (Index32 i=0; i< mIntSize; ++i) n += CountOn(mBits[i]);
1139  return n;
1140  }
1141 
1142  Index32 countOff() const { return mBitSize-this->countOn(); }
1143 
1144  void setOn(Index32 i) {
1145  assert(mBits);
1146  assert( (i>>5) < mIntSize);
1147  mBits[i>>5] |= 1<<(i&31);
1148  }
1149 
1150  void setOff(Index32 i) {
1151  assert(mBits);
1152  assert( (i>>5) < mIntSize);
1153  mBits[i>>5] &= ~(1<<(i&31));
1154  }
1155 
1156  void set(Index32 i, bool On) { On ? this->setOn(i) : this->setOff(i); }
1157 
1158  void setOn() {
1159  assert(mBits);
1160  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0xFFFFFFFF;
1161  }
1162  void setOff() {
1163  assert(mBits);
1164  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1165  }
1166  void toggle(Index32 i) {
1167  assert(mBits);
1168  assert( (i>>5) < mIntSize);
1169  mBits[i>>5] ^= 1<<(i&31);
1170  }
1171  void toggle() {
1172  assert(mBits);
1173  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=~mBits[i];
1174  }
1175  void setFirstOn() { this->setOn(0); }
1176  void setLastOn() { this->setOn(mBitSize-1); }
1177  void setFirstOff() { this->setOff(0); }
1178  void setLastOff() { this->setOff(mBitSize-1); }
1179  bool isOn(Index32 i) const {
1180  assert(mBits);
1181  assert( (i>>5) < mIntSize);
1182  return ( mBits[i >> 5] & (1<<(i&31)) );
1183  }
1184  bool isOff(Index32 i) const {
1185  assert(mBits);
1186  assert( (i>>5) < mIntSize);
1187  return ( ~mBits[i >> 5] & (1<<(i&31)) );
1188  }
1189 
1190  bool isOn() const {
1191  if (!mBits) return false;//undefined is off
1192  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0xFFFFFFFF) return false;
1193  return true;
1194  }
1195 
1196  bool isOff() const {
1197  if (!mBits) return true;//undefined is off
1198  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0) return false;
1199  return true;
1200  }
1201 
1203  assert(mBits);
1204  Index32 i=0;
1205  while(!mBits[i]) if (++i == mIntSize) return mBitSize;//reached end
1206  return 32*i + FindLowestOn(mBits[i]);
1207  }
1208 
1210  assert(mBits);
1211  Index32 i=0;
1212  while(!(~mBits[i])) if (++i == mIntSize) return mBitSize;//reached end
1213  return 32*i + FindLowestOn(~mBits[i]);
1214  }
1215 
1216  void save(std::ostream& os) const {
1217  assert(mBits);
1218  os.write((const char *)mBits,mIntSize*sizeof(Index32));
1219  }
1220  void load(std::istream& is) {
1221  assert(mBits);
1222  is.read((char *)mBits,mIntSize*sizeof(Index32));
1223  }
1225  void printInfo(std::ostream& os=std::cout) const {
1226  os << "RootNodeMask: Bit-size="<<mBitSize<<" Int-size="<<mIntSize<<std::endl;
1227  }
1228 
1229  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const {
1230  const Index32 n=(mBitSize>max_out?max_out:mBitSize);
1231  for (Index32 i=0; i < n; ++i) {
1232  if ( !(i&31) )
1233  os << "||";
1234  else if ( !(i%8) )
1235  os << "|";
1236  os << this->isOn(i);
1237  }
1238  os << "|" << std::endl;
1239  }
1240 
1241  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const {
1242  this->printInfo(os);
1243  this->printBits(os,max_out);
1244  }
1245 
1246  Index32 findNextOn(Index32 start) const {
1247  assert(mBits);
1248  Index32 n = start >> 5, m = start & 31;//initiate
1249  if (n>=mIntSize) return mBitSize; // check for out of bounds
1250  Index32 b = mBits[n];
1251  if (b & (1<<m)) return start;//simple case
1252  b &= 0xFFFFFFFF << m;// mask lower bits
1253  while(!b && ++n<mIntSize) b = mBits[n];// find next nonzero int
1254  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1255  }
1256 
1257  Index32 findNextOff(Index32 start) const {
1258  assert(mBits);
1259  Index32 n = start >> 5, m = start & 31;//initiate
1260  if (n>=mIntSize) return mBitSize; // check for out of bounds
1261  Index32 b = ~mBits[n];
1262  if (b & (1<<m)) return start;//simple case
1263  b &= 0xFFFFFFFF<<m;// mask lower bits
1264  while(!b && ++n<mIntSize) b = ~mBits[n];// find next nonzero int
1265  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1266  }
1267 
1268  Index32 memUsage() const {
1269  assert(mBits);
1270  return sizeof(Index32*)+(2+mIntSize)*sizeof(Index32);//in bytes
1271  }
1272 }; // class RootNodeMask
1273 
1274 } // namespace util
1275 } // namespace OPENVDB_VERSION_NAME
1276 } // namespace openvdb
1277 
1278 #endif // OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
1279 
1280 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1281 // All rights reserved. This software is distributed under the
1282 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
DenseIterator beginDense() const
Definition: NodeMasks.h:1081
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:395
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:795
DenseMaskIterator & operator++()
Definition: NodeMasks.h:274
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:505
const RootNodeMask & operator&=(const RootNodeMask &other)
Definition: NodeMasks.h:1100
bool isOn() const
Definition: NodeMasks.h:1190
OffIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1029
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:845
OffIterator endOff() const
Definition: NodeMasks.h:335
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:388
bool operator*() const
Definition: NodeMasks.h:210
#define OPENVDB_DEPRECATED
Definition: Platform.h:47
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:881
OffIterator beginOff() const
Definition: NodeMasks.h:1079
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:621
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
DenseIterator endDense() const
Definition: NodeMasks.h:586
OffMaskIterator()
Definition: NodeMasks.h:227
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:656
RootNodeMask operator!() const
Definition: NodeMasks.h:1099
DenseIterator endDense() const
Definition: NodeMasks.h:769
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:612
void increment(Index n)
Definition: NodeMasks.h:1063
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:839
void increment()
Definition: NodeMasks.h:261
void setOn()
Set all bits on.
Definition: NodeMasks.h:820
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:654
Index32 findFirstOn() const
Definition: NodeMasks.h:461
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:479
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:806
void setOn(Index32 i)
Definition: NodeMasks.h:1144
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:662
Index32 pos() const
Definition: NodeMasks.h:177
Byte Word
Definition: NodeMasks.h:559
bool operator*() const
Definition: NodeMasks.h:273
bool operator!=(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:169
void setOn()
Set all bits on.
Definition: NodeMasks.h:637
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:837
bool isOff() const
Definition: NodeMasks.h:1196
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:569
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:623
OffMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:228
Index32 * mBits
Definition: NodeMasks.h:921
Definition: NodeMasks.h:189
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:752
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:796
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:313
DenseMaskIterator()
Definition: NodeMasks.h:259
bool next()
Definition: NodeMasks.h:268
bool next()
Definition: NodeMasks.h:1010
void load(std::istream &is)
Definition: NodeMasks.h:496
Index32 CountOff(Byte v)
Return the number of off bits in the given 8-bit value.
Definition: NodeMasks.h:72
~NodeMask()
Destructor.
Definition: NodeMasks.h:573
OnIterator beginOn() const
Definition: NodeMasks.h:332
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:613
BaseMaskIterator()
Definition: NodeMasks.h:163
void set(Index32 i, bool On)
Definition: NodeMasks.h:1156
OnIterator beginOn() const
Definition: NodeMasks.h:1077
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:328
Index32 FindLowestOn(Byte v)
Return the least significant on bit of the given 8-bit value.
Definition: NodeMasks.h:100
void save(std::ostream &os) const
Definition: NodeMasks.h:693
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:824
bool next()
Definition: NodeMasks.h:1066
Base class for the bit mask iterators.
Definition: NodeMasks.h:157
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:485
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:641
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:288
OnIterator()
Definition: NodeMasks.h:1000
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:877
~NodeMask()
Destructor.
Definition: NodeMasks.h:756
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:381
Index32 Index
Definition: Types.h:56
~NodeMask()
Destructor.
Definition: NodeMasks.h:319
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:317
OffIterator()
Definition: NodeMasks.h:1028
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:601
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:699
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:715
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:833
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:352
Index32 mIntSize
Definition: NodeMasks.h:920
Index64 Word
Definition: NodeMasks.h:742
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:366
void increment(Index n)
Definition: NodeMasks.h:267
void save(std::ostream &os) const
Definition: NodeMasks.h:871
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:903
void save(std::ostream &os) const
Definition: NodeMasks.h:1216
RootNodeMask operator&(const RootNodeMask &other) const
Definition: NodeMasks.h:1122
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:896
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1246
DenseIterator beginDense() const
Definition: NodeMasks.h:768
bool test() const
Definition: NodeMasks.h:984
void operator=(const BaseIterator &iter)
Definition: NodeMasks.h:974
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:722
DenseIterator endDense() const
Definition: NodeMasks.h:1082
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:831
Index32 offset() const
Definition: NodeMasks.h:980
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:359
DenseIterator beginDense() const
Definition: NodeMasks.h:585
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:784
Index32 getMemUsage() const
Definition: NodeMasks.h:1133
#define B6(n)
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:750
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:648
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:650
void increment()
Definition: NodeMasks.h:229
void setOn()
Set all bits on.
Definition: NodeMasks.h:409
OnIterator beginOn() const
Definition: NodeMasks.h:764
bool isOn(Index32 i) const
Definition: NodeMasks.h:1179
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:849
OnMaskIterator & operator++()
Definition: NodeMasks.h:211
void increment(Index n)
Definition: NodeMasks.h:1007
Index32 countOn() const
Definition: NodeMasks.h:1135
OnIterator beginOn() const
Definition: NodeMasks.h:581
OffIterator & operator++()
Definition: NodeMasks.h:1043
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:374
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:666
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:402
bool next()
Definition: NodeMasks.h:205
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:426
bool isOff(Index32 i) const
Definition: NodeMasks.h:1184
void increment(Index n)
Definition: NodeMasks.h:235
Index32 offset() const
Definition: NodeMasks.h:176
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:567
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:754
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:596
#define OPENVDB_VERSION_NAME
Definition: version.h:45
RootNodeMask(Index32 bit_size)
Definition: NodeMasks.h:925
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:421
const NodeMask * mParent
Definition: NodeMasks.h:161
OffIterator beginOff() const
Definition: NodeMasks.h:583
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:571
Index getBitSize() const
Definition: NodeMasks.h:945
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:779
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1229
OPENVDB_DEPRECATED Index32 getMemUsage() const
Return the byte size of this NodeMask.
Definition: NodeMasks.h:379
OnIterator & operator++()
Definition: NodeMasks.h:1015
unsigned char Byte
Definition: Types.h:61
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:446
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:377
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1257
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:440
DenseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1057
void increment()
Definition: NodeMasks.h:198
bool operator*() const
Definition: NodeMasks.h:241
OffIterator endOff() const
Definition: NodeMasks.h:1080
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:611
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:330
uint32_t Index32
Definition: Types.h:54
bool test() const
Definition: NodeMasks.h:178
void load(std::istream &is)
Definition: NodeMasks.h:697
bool next()
Definition: NodeMasks.h:236
Index32 findFirstOff() const
Definition: NodeMasks.h:1209
OffIterator beginOff() const
Definition: NodeMasks.h:766
NodeMask operator!() const
Definition: NodeMasks.h:778
uint64_t Index64
Definition: Types.h:55
OnMaskIterator()
Definition: NodeMasks.h:196
Index32 mBitSize
Definition: NodeMasks.h:963
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:577
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:137
bool operator==(const BaseIterator &iter) const
Definition: NodeMasks.h:971
bool operator*() const
Definition: NodeMasks.h:1014
NodeMask operator!() const
Definition: NodeMasks.h:595
bool operator*() const
Definition: NodeMasks.h:1070
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:865
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:760
DenseIterator endDense() const
Definition: NodeMasks.h:337
bool operator==(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:168
Index32 mPos
Definition: NodeMasks.h:962
void setOff()
Set all bits off.
Definition: NodeMasks.h:639
OnIterator endOn() const
Definition: NodeMasks.h:333
OffMaskIterator & operator++()
Definition: NodeMasks.h:242
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:794
RootNodeMask operator^(const RootNodeMask &other) const
Definition: NodeMasks.h:1128
OffIterator beginOff() const
Definition: NodeMasks.h:334
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:578
void load(std::istream &is)
Definition: NodeMasks.h:875
void increment()
Definition: NodeMasks.h:1030
OnIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1001
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:652
const RootNodeMask * mParent
Definition: NodeMasks.h:964
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:761
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:390
~RootNodeMask()
Definition: NodeMasks.h:935
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:375
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:635
Index getIntSize() const
Definition: NodeMasks.h:947
void setOff()
Set all bits off.
Definition: NodeMasks.h:822
Index32 pos() const
Definition: NodeMasks.h:982
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:664
Index32 CountOn(Byte v)
Return the number of on bits in the given 8-bit value.
Definition: NodeMasks.h:52
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:438
void setOn()
Definition: NodeMasks.h:1158
Definition: NodeMasks.h:917
RootNodeMask()
Definition: NodeMasks.h:924
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1225
void setOff(Index32 i)
Definition: NodeMasks.h:1150
Index32 findFirstOff() const
Definition: NodeMasks.h:668
OnMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:197
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:835
BaseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:967
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:829
void setFirstOn()
Definition: NodeMasks.h:1175
bool operator*() const
Definition: NodeMasks.h:1042
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:709
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:315
Index32 mBitSize
Definition: NodeMasks.h:920
Index64 Word
Definition: NodeMasks.h:297
Index32 findFirstOff() const
Definition: NodeMasks.h:851
void setLastOff()
Definition: NodeMasks.h:1178
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:373
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:432
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:818
DenseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:260
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:646
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:890
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:847
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:789
const RootNodeMask & operator^=(const RootNodeMask &other)
Definition: NodeMasks.h:1115
OffIterator endOff() const
Definition: NodeMasks.h:584
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:400
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:606
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:434
void increment()
Definition: NodeMasks.h:1002
bool operator!=(const BaseIterator &iter) const
Definition: NodeMasks.h:972
NodeMask operator!() const
Definition: NodeMasks.h:351
Definition: NodeMasks.h:220
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:633
OnIterator endOn() const
Definition: NodeMasks.h:765
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:579
void load(std::istream &is)
Definition: NodeMasks.h:1220
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:816
void setLastOn()
Definition: NodeMasks.h:1176
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:615
Definition: NodeMasks.h:251
Index32 mPos
Definition: NodeMasks.h:160
OffIterator endOff() const
Definition: NodeMasks.h:767
OnIterator endOn() const
Definition: NodeMasks.h:582
void increment()
Definition: NodeMasks.h:1058
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:762
void setOff()
Definition: NodeMasks.h:1162
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:517
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
DenseIterator & operator++()
Definition: NodeMasks.h:1071
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:523
RootNodeMask(const RootNodeMask &B)
Definition: NodeMasks.h:930
Index32 findFirstOn() const
Definition: NodeMasks.h:850
void increment(Index n)
Definition: NodeMasks.h:204
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:628
void setOff()
Set all bits off.
Definition: NodeMasks.h:415
DenseIterator beginDense() const
Definition: NodeMasks.h:336
Index32 findFirstOn() const
Definition: NodeMasks.h:1202
RootNodeMask operator|(const RootNodeMask &other) const
Definition: NodeMasks.h:1125
void setFirstOff()
Definition: NodeMasks.h:1177
void toggle(Index32 i)
Definition: NodeMasks.h:1166
Index32 findFirstOn() const
Definition: NodeMasks.h:667
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:329
void save(std::ostream &os) const
Definition: NodeMasks.h:492
OnIterator endOn() const
Definition: NodeMasks.h:1078
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:798
void init(Index32 bit_size)
Definition: NodeMasks.h:937
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:802
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:859
OPENVDB_DEPRECATED Index32 getMemUsage() const
Return the byte size of this NodeMask.
Definition: NodeMasks.h:617
Index32 countOff() const
Definition: NodeMasks.h:1142
void toggle()
Definition: NodeMasks.h:1171
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:438
const RootNodeMask & operator|=(const RootNodeMask &other)
Definition: NodeMasks.h:1108
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:436
void increment(Index n)
Definition: NodeMasks.h:1035
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1241
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:535
Index32 memUsage() const
Definition: NodeMasks.h:1268
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:619
OPENVDB_DEPRECATED Index32 getMemUsage() const
Return the byte size of this NodeMask.
Definition: NodeMasks.h:800
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:811
BaseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:164
bool next()
Definition: NodeMasks.h:1038
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:448
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:500
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:703
Index32 findFirstOff() const
Definition: NodeMasks.h:468
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:804
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:455