OpenVDB  2.3.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;}
172  {
173  mPos = iter.mPos; mParent = iter.mParent; return *this;
174  }
175  Index32 offset() const {return mPos;}
176  Index32 pos() const {return mPos;}
177  bool test() const
178  {
179  assert(mPos <= NodeMask::SIZE);
180  return (mPos != NodeMask::SIZE);
181  }
182  operator bool() const {return this->test();}
183 }; // class BaseMaskIterator
184 
185 
187 template <typename NodeMask>
188 class OnMaskIterator: public BaseMaskIterator<NodeMask>
189 {
190 private:
192  using BaseType::mPos;//bit position;
193  using BaseType::mParent;//this iterator can't change the parent_mask!
194 public:
196  OnMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
197  void increment()
198  {
199  assert(mParent != NULL);
200  mPos = mParent->findNextOn(mPos+1);
201  assert(mPos <= NodeMask::SIZE);
202  }
203  void increment(Index n) { while(n-- && this->next()) ; }
204  bool next()
205  {
206  this->increment();
207  return this->test();
208  }
209  bool operator*() const {return true;}
211  {
212  this->increment();
213  return *this;
214  }
215 }; // class OnMaskIterator
216 
217 
218 template <typename NodeMask>
219 class OffMaskIterator: public BaseMaskIterator<NodeMask>
220 {
221 private:
223  using BaseType::mPos;//bit position;
224  using BaseType::mParent;//this iterator can't change the parent_mask!
225 public:
227  OffMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
228  void increment()
229  {
230  assert(mParent != NULL);
231  mPos=mParent->findNextOff(mPos+1);
232  assert(mPos <= NodeMask::SIZE);
233  }
234  void increment(Index n) { while(n-- && this->next()) ; }
235  bool next()
236  {
237  this->increment();
238  return this->test();
239  }
240  bool operator*() const {return false;}
242  {
243  this->increment();
244  return *this;
245  }
246 }; // class OffMaskIterator
247 
248 
249 template <typename NodeMask>
250 class DenseMaskIterator: public BaseMaskIterator<NodeMask>
251 {
252 private:
254  using BaseType::mPos;//bit position;
255  using BaseType::mParent;//this iterator can't change the parent_mask!
256 
257 public:
259  DenseMaskIterator(Index32 pos,const NodeMask *parent) : BaseType(pos,parent) {}
260  void increment()
261  {
262  assert(mParent != NULL);
263  mPos += 1;//careful - the increment might go beyond the end
264  assert(mPos<= NodeMask::SIZE);
265  }
266  void increment(Index n) { while(n-- && this->next()) ; }
267  bool next()
268  {
269  this->increment();
270  return this->test();
271  }
272  bool operator*() const {return mParent->isOn(mPos);}
274  {
275  this->increment();
276  return *this;
277  }
278 }; // class DenseMaskIterator
279 
280 
286 template<Index Log2Dim>
287 class NodeMask
288 {
289 public:
290  BOOST_STATIC_ASSERT( Log2Dim>2 );
291 
292  static const Index32 LOG2DIM = Log2Dim;
293  static const Index32 DIM = 1<<Log2Dim;
294  static const Index32 SIZE = 1<<3*Log2Dim;
295  static const Index32 WORD_COUNT = SIZE >> 6;// 2^6=64
296  typedef Index64 Word;
297 
298 private:
299 
300  // The bits are represented as a linear array of Words, and the
301  // size of a Word is 32 or 64 bits depending on the platform.
302  // The BIT_MASK is defined as the number of bits in a Word - 1
303  //static const Index32 BIT_MASK = sizeof(void*) == 8 ? 63 : 31;
304  //static const Index32 LOG2WORD = BIT_MASK == 63 ? 6 : 5;
305  //static const Index32 WORD_COUNT = SIZE >> LOG2WORD;
306  //typedef boost::mpl::if_c<BIT_MASK == 63, Index64, Index32>::type Word;
307 
308  Word mWords[WORD_COUNT];//only member data!
309 
310 public:
312  NodeMask() { this->setOff(); }
314  NodeMask(bool on) { this->set(on); }
316  NodeMask(const NodeMask &other) { *this = other; }
320  NodeMask& operator=(const NodeMask& other)
321  {
322  Index32 n = WORD_COUNT;
323  const Word* w2 = other.mWords;
324  for (Word* w1 = mWords; n--; ++w1, ++w2) *w1 = *w2;
325  return *this;
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  Index32 countOn() const
380  {
381  Index32 sum = 0, n = WORD_COUNT;
382  for (const Word* w = mWords; n--; ++w) sum += CountOn(*w);
383  return sum;
384  }
386  Index32 countOff() const { return SIZE-this->countOn(); }
388  void setOn(Index32 n) {
389  assert( (n >> 6) < WORD_COUNT );
390  mWords[n >> 6] |= Word(1) << (n & 63);
391  }
393  void setOff(Index32 n) {
394  assert( (n >> 6) < WORD_COUNT );
395  mWords[n >> 6] &= ~(Word(1) << (n & 63));
396  }
398  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
400  void set(bool on)
401  {
402  const Word state = on ? ~Word(0) : Word(0);
403  Index32 n = WORD_COUNT;
404  for (Word* w = mWords; n--; ++w) *w = state;
405  }
407  void setOn()
408  {
409  Index32 n = WORD_COUNT;
410  for (Word* w = mWords; n--; ++w) *w = ~Word(0);
411  }
413  void setOff()
414  {
415  Index32 n = WORD_COUNT;
416  for (Word* w = mWords; n--; ++w) *w = Word(0);
417  }
419  void toggle(Index32 n) {
420  assert( (n >> 6) < WORD_COUNT );
421  mWords[n >> 6] ^= 1 << (n & 63);
422  }
424  void toggle()
425  {
426  Index32 n = WORD_COUNT;
427  for (Word* w = mWords; n--; ++w) *w = ~*w;
428  }
430  void setFirstOn() { this->setOn(0); }
432  void setLastOn() { this->setOn(SIZE-1); }
434  void setFirstOff() { this->setOff(0); }
436  void setLastOff() { this->setOff(SIZE-1); }
438  bool isOn(Index32 n) const
439  {
440  assert( (n >> 6) < WORD_COUNT );
441  return 0 != (mWords[n >> 6] & (Word(1) << (n & 63)));
442  }
444  bool isOff(Index32 n) const {return !this->isOn(n); }
446  bool isOn() const
447  {
448  int n = WORD_COUNT;
449  for (const Word *w = mWords; n-- && *w++ == ~Word(0);) ;
450  return n == -1;
451  }
453  bool isOff() const
454  {
455  int n = WORD_COUNT;
456  for (const Word *w = mWords; n-- && *w++ == Word(0);) ;
457  return n == -1;
458  }
460  {
461  Index32 n = 0;
462  const Word* w = mWords;
463  for (; n<WORD_COUNT && !*w; ++w, ++n) ;
464  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(*w);
465  }
467  {
468  Index32 n = 0;
469  const Word* w = mWords;
470  for (; n<WORD_COUNT && !~*w; ++w, ++n) ;
471  return n==WORD_COUNT ? SIZE : (n << 6) + FindLowestOn(~*w);
472  }
473 
475  template<typename WordT>
477  WordT getWord(Index n) const
478  {
479  assert(n*8*sizeof(WordT) < SIZE);
480  return reinterpret_cast<const WordT*>(mWords)[n];
481  }
482  template<typename WordT>
483  WordT& getWord(Index n)
484  {
485  assert(n*8*sizeof(WordT) < SIZE);
486  return reinterpret_cast<WordT*>(mWords)[n];
487  }
489 
490  void save(std::ostream& os) const
491  {
492  os.write(reinterpret_cast<const char*>(mWords), this->memUsage());
493  }
494  void load(std::istream& is) {
495  is.read(reinterpret_cast<char*>(mWords), this->memUsage());
496  }
498  void printInfo(std::ostream& os=std::cout) const
499  {
500  os << "NodeMask: Dim=" << DIM << " Log2Dim=" << Log2Dim
501  << " Bit count=" << SIZE << " word count=" << WORD_COUNT << std::endl;
502  }
503  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const
504  {
505  const Index32 n=(SIZE>max_out ? max_out : SIZE);
506  for (Index32 i=0; i < n; ++i) {
507  if ( !(i & 63) )
508  os << "||";
509  else if ( !(i%8) )
510  os << "|";
511  os << this->isOn(i);
512  }
513  os << "|" << std::endl;
514  }
515  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const
516  {
517  this->printInfo(os);
518  this->printBits(os, max_out);
519  }
520 
522  {
523  Index32 n = start >> 6;//initiate
524  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
525  Index32 m = start & 63;
526  Word b = mWords[n];
527  if (b & (Word(1) << m)) return start;//simpel case: start is on
528  b &= ~Word(0) << m;// mask out lower bits
529  while(!b && ++n<WORD_COUNT) b = mWords[n];// find next none-zero word
530  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
531  }
532 
534  {
535  Index32 n = start >> 6;//initiate
536  if (n >= WORD_COUNT) return SIZE; // check for out of bounds
537  Index32 m = start & 63;
538  Word b = ~mWords[n];
539  if (b & (Word(1) << m)) return start;//simpel case: start is on
540  b &= ~Word(0) << m;// mask out lower bits
541  while(!b && ++n<WORD_COUNT) b = ~mWords[n];// find next none-zero word
542  return (!b ? SIZE : (n << 6) + FindLowestOn(b));//catch last word=0
543  }
544 };// NodeMask
545 
546 
548 template<>
549 class NodeMask<1>
550 {
551 public:
552 
553  static const Index32 LOG2DIM = 1;
554  static const Index32 DIM = 2;
555  static const Index32 SIZE = 8;
556  static const Index32 WORD_COUNT = 1;
557  typedef Byte Word;
558 
559 private:
560 
561  Byte mByte;//only member data!
562 
563 public:
565  NodeMask() : mByte(0x00U) {}
567  NodeMask(bool on) : mByte(on ? 0xFFU : 0x00U) {}
569  NodeMask(const NodeMask &other) : mByte(other.mByte) {}
573  void operator = (const NodeMask &other) { mByte = other.mByte; }
574 
578 
579  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
580  OnIterator endOn() const { return OnIterator(SIZE,this); }
581  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
582  OffIterator endOff() const { return OffIterator(SIZE,this); }
583  DenseIterator beginDense() const { return DenseIterator(0,this); }
584  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
585 
586  bool operator == (const NodeMask &other) const { return mByte == other.mByte; }
587 
588  bool operator != (const NodeMask &other) const {return mByte != other.mByte; }
589 
590  //
591  // Bitwise logical operations
592  //
593  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
594  const NodeMask& operator&=(const NodeMask& other)
595  {
596  mByte &= other.mByte;
597  return *this;
598  }
599  const NodeMask& operator|=(const NodeMask& other)
600  {
601  mByte |= other.mByte;
602  return *this;
603  }
604  const NodeMask& operator^=(const NodeMask& other)
605  {
606  mByte ^= other.mByte;
607  return *this;
608  }
609  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
610  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
611  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
613  static Index32 memUsage() { return 1; }
615  Index32 countOn() const { return CountOn(mByte); }
617  Index32 countOff() const { return CountOff(mByte); }
619  void setOn(Index32 n) {
620  assert( n < 8 );
621  mByte |= 0x01U << (n & 7);
622  }
624  void setOff(Index32 n) {
625  assert( n < 8 );
626  mByte &= ~(0x01U << (n & 7));
627  }
629  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
631  void set(bool on) { mByte = on ? 0xFFU : 0x00U; }
633  void setOn() { mByte = 0xFFU; }
635  void setOff() { mByte = 0x00U; }
637  void toggle(Index32 n) {
638  assert( n < 8 );
639  mByte ^= 0x01U << (n & 7);
640  }
642  void toggle() { mByte = ~mByte; }
644  void setFirstOn() { this->setOn(0); }
646  void setLastOn() { this->setOn(7); }
648  void setFirstOff() { this->setOff(0); }
650  void setLastOff() { this->setOff(7); }
652  bool isOn(Index32 n) const
653  {
654  assert( n < 8 );
655  return mByte & (0x01U << (n & 7));
656  }
658  bool isOff(Index32 n) const {return !this->isOn(n); }
660  bool isOn() const { return mByte == 0xFFU; }
662  bool isOff() const { return mByte == 0; }
663  Index32 findFirstOn() const { return mByte ? FindLowestOn(mByte) : 8; }
665  {
666  const Byte b = ~mByte;
667  return b ? FindLowestOn(b) : 8;
668  }
669  /*
671  template<typename WordT>
674  WordT getWord(Index n) const
675  {
676  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
677  assert(n == 0);
678  return reinterpret_cast<WordT>(mByte);
679  }
680  template<typename WordT>
681  WordT& getWord(Index n)
682  {
683  BOOST_STATIC_ASSERT(sizeof(WordT) == sizeof(Byte));
684  assert(n == 0);
685  return reinterpret_cast<WordT&>(mByte);
686  }
688  */
689  void save(std::ostream& os) const
690  {
691  os.write(reinterpret_cast<const char*>(&mByte), 1);
692  }
693  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mByte), 1); }
695  void printInfo(std::ostream& os=std::cout) const
696  {
697  os << "NodeMask: Dim=2, Log2Dim=1, Bit count=8, Word count=1"<<std::endl;
698  }
699  void printBits(std::ostream& os=std::cout) const
700  {
701  os << "||";
702  for (Index32 i=0; i < 8; ++i) os << this->isOn(i);
703  os << "||" << std::endl;
704  }
705  void printAll(std::ostream& os=std::cout) const
706  {
707  this->printInfo(os);
708  this->printBits(os);
709  }
710 
712  {
713  if (start>=8) return 8;
714  const Byte b = mByte & (0xFFU << start);
715  return b ? FindLowestOn(b) : 8;
716  }
717 
719  {
720  if (start>=8) return 8;
721  const Byte b = ~mByte & (0xFFU << start);
722  return b ? FindLowestOn(b) : 8;
723  }
724 
725 };// NodeMask<1>
726 
727 
729 template<>
730 class NodeMask<2>
731 {
732 public:
733 
734  static const Index32 LOG2DIM = 2;
735  static const Index32 DIM = 4;
736  static const Index32 SIZE = 64;
737  static const Index32 WORD_COUNT = 1;
738  typedef Index64 Word;
739 
740 private:
741 
742  Word mWord;//only member data!
743 
744 public:
746  NodeMask() : mWord(UINT64_C(0x00)) {}
748  NodeMask(bool on) : mWord(on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00)) {}
750  NodeMask(const NodeMask &other) : mWord(other.mWord) {}
754  void operator = (const NodeMask &other) { mWord = other.mWord; }
755 
759 
760  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
761  OnIterator endOn() const { return OnIterator(SIZE,this); }
762  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
763  OffIterator endOff() const { return OffIterator(SIZE,this); }
764  DenseIterator beginDense() const { return DenseIterator(0,this); }
765  DenseIterator endDense() const { return DenseIterator(SIZE,this); }
766 
767  bool operator == (const NodeMask &other) const { return mWord == other.mWord; }
768 
769  bool operator != (const NodeMask &other) const {return mWord != other.mWord; }
770 
771  //
772  // Bitwise logical operations
773  //
774  NodeMask operator!() const { NodeMask m(*this); m.toggle(); return m; }
775  const NodeMask& operator&=(const NodeMask& other)
776  {
777  mWord &= other.mWord;
778  return *this;
779  }
780  const NodeMask& operator|=(const NodeMask& other)
781  {
782  mWord |= other.mWord;
783  return *this;
784  }
785  const NodeMask& operator^=(const NodeMask& other)
786  {
787  mWord ^= other.mWord;
788  return *this;
789  }
790  NodeMask operator&(const NodeMask& other) const { NodeMask m(*this); m &= other; return m; }
791  NodeMask operator|(const NodeMask& other) const { NodeMask m(*this); m |= other; return m; }
792  NodeMask operator^(const NodeMask& other) const { NodeMask m(*this); m ^= other; return m; }
794  static Index32 memUsage() { return 8; }
796  Index32 countOn() const { return CountOn(mWord); }
798  Index32 countOff() const { return CountOff(mWord); }
800  void setOn(Index32 n) {
801  assert( n < 64 );
802  mWord |= UINT64_C(0x01) << (n & 63);
803  }
805  void setOff(Index32 n) {
806  assert( n < 64 );
807  mWord &= ~(UINT64_C(0x01) << (n & 63));
808  }
810  void set(Index32 n, bool On) { On ? this->setOn(n) : this->setOff(n); }
812  void set(bool on) { mWord = on ? UINT64_C(0xFFFFFFFFFFFFFFFF) : UINT64_C(0x00); }
814  void setOn() { mWord = UINT64_C(0xFFFFFFFFFFFFFFFF); }
816  void setOff() { mWord = UINT64_C(0x00); }
818  void toggle(Index32 n) {
819  assert( n < 64 );
820  mWord ^= UINT64_C(0x01) << (n & 63);
821  }
823  void toggle() { mWord = ~mWord; }
825  void setFirstOn() { this->setOn(0); }
827  void setLastOn() { this->setOn(63); }
829  void setFirstOff() { this->setOff(0); }
831  void setLastOff() { this->setOff(63); }
833  bool isOn(Index32 n) const
834  {
835  assert( n < 64 );
836  return 0 != (mWord & (UINT64_C(0x01) << (n & 63)));
837  }
839  bool isOff(Index32 n) const {return !this->isOn(n); }
841  bool isOn() const { return mWord == UINT64_C(0xFFFFFFFFFFFFFFFF); }
843  bool isOff() const { return mWord == 0; }
844  Index32 findFirstOn() const { return mWord ? FindLowestOn(mWord) : 64; }
846  {
847  const Word w = ~mWord;
848  return w ? FindLowestOn(w) : 64;
849  }
851  template<typename WordT>
853  WordT getWord(Index n) const
854  {
855  assert(n*8*sizeof(WordT) < SIZE);
856  return reinterpret_cast<const WordT*>(&mWord)[n];
857  }
858  template<typename WordT>
859  WordT& getWord(Index n)
860  {
861  assert(n*8*sizeof(WordT) < SIZE);
862  return reinterpret_cast<WordT*>(mWord)[n];
863  }
865  void save(std::ostream& os) const
866  {
867  os.write(reinterpret_cast<const char*>(&mWord), 8);
868  }
869  void load(std::istream& is) { is.read(reinterpret_cast<char*>(&mWord), 8); }
871  void printInfo(std::ostream& os=std::cout) const
872  {
873  os << "NodeMask: Dim=4, Log2Dim=2, Bit count=64, Word count=1"<<std::endl;
874  }
875  void printBits(std::ostream& os=std::cout) const
876  {
877  os << "|";
878  for (Index32 i=0; i < 64; ++i) {
879  if ( !(i%8) ) os << "|";
880  os << this->isOn(i);
881  }
882  os << "||" << std::endl;
883  }
884  void printAll(std::ostream& os=std::cout) const
885  {
886  this->printInfo(os);
887  this->printBits(os);
888  }
889 
891  {
892  if (start>=64) return 64;
893  const Word w = mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
894  return w ? FindLowestOn(w) : 64;
895  }
896 
898  {
899  if (start>=64) return 64;
900  const Word w = ~mWord & (UINT64_C(0xFFFFFFFFFFFFFFFF) << start);
901  return w ? FindLowestOn(w) : 64;
902  }
903 
904 };// NodeMask<2>
905 
906 
907 // Unlike NodeMask above this RootNodeMask has a run-time defined size.
908 // It is only included for backward compatibility and will likely be
909 // deprecated in the future!
910 // This class is 32-bit specefic, hence the use if Index32 vs Index!
912 {
913 protected:
914  Index32 mBitSize, mIntSize;
916 
917 public:
918  RootNodeMask(): mBitSize(0), mIntSize(0), mBits(NULL) {}
920  mBitSize(bit_size), mIntSize(((bit_size-1)>>5)+1), mBits(new Index32[mIntSize])
921  {
922  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
923  }
925  mBitSize(B.mBitSize), mIntSize(B.mIntSize), mBits(new Index32[mIntSize])
926  {
927  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
928  }
929  ~RootNodeMask() {delete [] mBits;}
930 
931  void init(Index32 bit_size) {
932  mBitSize = bit_size;
933  mIntSize =((bit_size-1)>>5)+1;
934  delete [] mBits;
935  mBits = new Index32[mIntSize];
936  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
937  }
938 
939  Index getBitSize() const {return mBitSize;}
940 
941  Index getIntSize() const {return mIntSize;}
942 
944  if (mBitSize!=B.mBitSize) {
945  mBitSize=B.mBitSize;
946  mIntSize=B.mIntSize;
947  delete [] mBits;
948  mBits = new Index32[mIntSize];
949  }
950  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=B.mBits[i];
951  return *this;
952  }
953 
955  {
956  protected:
957  Index32 mPos;//bit position
959  const RootNodeMask* mParent;//this iterator can't change the parent_mask!
960  public:
961  BaseIterator() : mPos(0), mBitSize(0), mParent(NULL) {}
962  BaseIterator(Index32 pos,const RootNodeMask *parent)
963  : mPos(pos), mBitSize(parent->getBitSize()), mParent(parent) {
964  assert( pos<=mBitSize );
965  }
966  bool operator==(const BaseIterator &iter) const {return mPos == iter.mPos;}
967  bool operator!=(const BaseIterator &iter) const {return mPos != iter.mPos;}
968  bool operator< (const BaseIterator &iter) const {return mPos < iter.mPos;}
970  mPos = iter.mPos;
971  mBitSize = iter.mBitSize;
972  mParent = iter.mParent;
973  return *this;
974  }
975 
976  Index32 offset() const {return mPos;}
977 
978  Index32 pos() const {return mPos;}
979 
980  bool test() const {
981  assert(mPos <= mBitSize);
982  return (mPos != mBitSize);
983  }
984 
985  operator bool() const {return this->test();}
986  }; // class BaseIterator
987 
989  class OnIterator: public BaseIterator
990  {
991  protected:
992  using BaseIterator::mPos;//bit position;
993  using BaseIterator::mBitSize;//bit size;
994  using BaseIterator::mParent;//this iterator can't change the parent_mask!
995  public:
997  OnIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
998  void increment() {
999  assert(mParent!=NULL);
1000  mPos=mParent->findNextOn(mPos+1);
1001  assert(mPos <= mBitSize);
1002  }
1003  void increment(Index n) {
1004  for (Index i=0; i<n && this->next(); ++i) {}
1005  }
1006  bool next() {
1007  this->increment();
1008  return this->test();
1009  }
1010  bool operator*() const {return true;}
1012  this->increment();
1013  return *this;
1014  }
1015  }; // class OnIterator
1016 
1018  {
1019  protected:
1020  using BaseIterator::mPos;//bit position;
1021  using BaseIterator::mBitSize;//bit size;
1022  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1023  public:
1025  OffIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1026  void increment() {
1027  assert(mParent!=NULL);
1028  mPos=mParent->findNextOff(mPos+1);
1029  assert(mPos <= mBitSize);
1030  }
1031  void increment(Index n) {
1032  for (Index i=0; i<n && this->next(); ++i) {}
1033  }
1034  bool next() {
1035  this->increment();
1036  return this->test();
1037  }
1038  bool operator*() const {return true;}
1040  this->increment();
1041  return *this;
1042  }
1043  }; // class OffIterator
1044 
1046  {
1047  protected:
1048  using BaseIterator::mPos;//bit position;
1049  using BaseIterator::mBitSize;//bit size;
1050  using BaseIterator::mParent;//this iterator can't change the parent_mask!
1051  public:
1053  DenseIterator(Index32 pos,const RootNodeMask *parent) : BaseIterator(pos,parent) {}
1054  void increment() {
1055  assert(mParent!=NULL);
1056  mPos += 1;//carefull - the increament might go beyond the end
1057  assert(mPos<= mBitSize);
1058  }
1059  void increment(Index n) {
1060  for (Index i=0; i<n && this->next(); ++i) {}
1061  }
1062  bool next() {
1063  this->increment();
1064  return this->test();
1065  }
1066  bool operator*() const {return mParent->isOn(mPos);}
1068  this->increment();
1069  return *this;
1070  }
1071  }; // class DenseIterator
1072 
1073  OnIterator beginOn() const { return OnIterator(this->findFirstOn(),this); }
1074  OnIterator endOn() const { return OnIterator(mBitSize,this); }
1075  OffIterator beginOff() const { return OffIterator(this->findFirstOff(),this); }
1076  OffIterator endOff() const { return OffIterator(mBitSize,this); }
1077  DenseIterator beginDense() const { return DenseIterator(0,this); }
1078  DenseIterator endDense() const { return DenseIterator(mBitSize,this); }
1079 
1080  bool operator == (const RootNodeMask &B) const {
1081  if (mBitSize != B.mBitSize) return false;
1082  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return false;
1083  return true;
1084  }
1085 
1086  bool operator != (const RootNodeMask &B) const {
1087  if (mBitSize != B.mBitSize) return true;
1088  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != B.mBits[i]) return true;
1089  return false;
1090  }
1091 
1092  //
1093  // Bitwise logical operations
1094  //
1095  RootNodeMask operator!() const { RootNodeMask m = *this; m.toggle(); return m; }
1096  const RootNodeMask& operator&=(const RootNodeMask& other) {
1097  assert(mIntSize == other.mIntSize);
1098  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1099  mBits[i] &= other.mBits[i];
1100  }
1101  for (Index32 i = other.mIntSize; i < mIntSize; ++i) mBits[i] = 0x00000000;
1102  return *this;
1103  }
1104  const RootNodeMask& operator|=(const RootNodeMask& other) {
1105  assert(mIntSize == other.mIntSize);
1106  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1107  mBits[i] |= other.mBits[i];
1108  }
1109  return *this;
1110  }
1111  const RootNodeMask& operator^=(const RootNodeMask& other) {
1112  assert(mIntSize == other.mIntSize);
1113  for (Index32 i = 0, N = std::min(mIntSize, other.mIntSize); i < N; ++i) {
1114  mBits[i] ^= other.mBits[i];
1115  }
1116  return *this;
1117  }
1118  RootNodeMask operator&(const RootNodeMask& other) const {
1119  RootNodeMask m(*this); m &= other; return m;
1120  }
1121  RootNodeMask operator|(const RootNodeMask& other) const {
1122  RootNodeMask m(*this); m |= other; return m;
1123  }
1124  RootNodeMask operator^(const RootNodeMask& other) const {
1125  RootNodeMask m(*this); m ^= other; return m;
1126  }
1127 
1128 
1129  Index32 getMemUsage() const {return mIntSize*sizeof(Index32) + sizeof(*this);}
1130 
1131  Index32 countOn() const {
1132  assert(mBits);
1133  Index32 n=0;
1134  for (Index32 i=0; i< mIntSize; ++i) n += CountOn(mBits[i]);
1135  return n;
1136  }
1137 
1138  Index32 countOff() const { return mBitSize-this->countOn(); }
1139 
1140  void setOn(Index32 i) {
1141  assert(mBits);
1142  assert( (i>>5) < mIntSize);
1143  mBits[i>>5] |= 1<<(i&31);
1144  }
1145 
1146  void setOff(Index32 i) {
1147  assert(mBits);
1148  assert( (i>>5) < mIntSize);
1149  mBits[i>>5] &= ~(1<<(i&31));
1150  }
1151 
1152  void set(Index32 i, bool On) { On ? this->setOn(i) : this->setOff(i); }
1153 
1154  void setOn() {
1155  assert(mBits);
1156  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0xFFFFFFFF;
1157  }
1158  void setOff() {
1159  assert(mBits);
1160  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=0x00000000;
1161  }
1162  void toggle(Index32 i) {
1163  assert(mBits);
1164  assert( (i>>5) < mIntSize);
1165  mBits[i>>5] ^= 1<<(i&31);
1166  }
1167  void toggle() {
1168  assert(mBits);
1169  for (Index32 i=0; i<mIntSize; ++i) mBits[i]=~mBits[i];
1170  }
1171  void setFirstOn() { this->setOn(0); }
1172  void setLastOn() { this->setOn(mBitSize-1); }
1173  void setFirstOff() { this->setOff(0); }
1174  void setLastOff() { this->setOff(mBitSize-1); }
1175  bool isOn(Index32 i) const {
1176  assert(mBits);
1177  assert( (i>>5) < mIntSize);
1178  return ( mBits[i >> 5] & (1<<(i&31)) );
1179  }
1180  bool isOff(Index32 i) const {
1181  assert(mBits);
1182  assert( (i>>5) < mIntSize);
1183  return ( ~mBits[i >> 5] & (1<<(i&31)) );
1184  }
1185 
1186  bool isOn() const {
1187  if (!mBits) return false;//undefined is off
1188  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0xFFFFFFFF) return false;
1189  return true;
1190  }
1191 
1192  bool isOff() const {
1193  if (!mBits) return true;//undefined is off
1194  for (Index32 i=0; i<mIntSize; ++i) if (mBits[i] != 0) return false;
1195  return true;
1196  }
1197 
1199  assert(mBits);
1200  Index32 i=0;
1201  while(!mBits[i]) if (++i == mIntSize) return mBitSize;//reached end
1202  return 32*i + FindLowestOn(mBits[i]);
1203  }
1204 
1206  assert(mBits);
1207  Index32 i=0;
1208  while(!(~mBits[i])) if (++i == mIntSize) return mBitSize;//reached end
1209  return 32*i + FindLowestOn(~mBits[i]);
1210  }
1211 
1212  void save(std::ostream& os) const {
1213  assert(mBits);
1214  os.write((const char *)mBits,mIntSize*sizeof(Index32));
1215  }
1216  void load(std::istream& is) {
1217  assert(mBits);
1218  is.read((char *)mBits,mIntSize*sizeof(Index32));
1219  }
1221  void printInfo(std::ostream& os=std::cout) const {
1222  os << "RootNodeMask: Bit-size="<<mBitSize<<" Int-size="<<mIntSize<<std::endl;
1223  }
1224 
1225  void printBits(std::ostream& os=std::cout, Index32 max_out=80u) const {
1226  const Index32 n=(mBitSize>max_out?max_out:mBitSize);
1227  for (Index32 i=0; i < n; ++i) {
1228  if ( !(i&31) )
1229  os << "||";
1230  else if ( !(i%8) )
1231  os << "|";
1232  os << this->isOn(i);
1233  }
1234  os << "|" << std::endl;
1235  }
1236 
1237  void printAll(std::ostream& os=std::cout, Index32 max_out=80u) const {
1238  this->printInfo(os);
1239  this->printBits(os,max_out);
1240  }
1241 
1242  Index32 findNextOn(Index32 start) const {
1243  assert(mBits);
1244  Index32 n = start >> 5, m = start & 31;//initiate
1245  if (n>=mIntSize) return mBitSize; // check for out of bounds
1246  Index32 b = mBits[n];
1247  if (b & (1<<m)) return start;//simple case
1248  b &= 0xFFFFFFFF << m;// mask lower bits
1249  while(!b && ++n<mIntSize) b = mBits[n];// find next nonzero int
1250  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1251  }
1252 
1253  Index32 findNextOff(Index32 start) const {
1254  assert(mBits);
1255  Index32 n = start >> 5, m = start & 31;//initiate
1256  if (n>=mIntSize) return mBitSize; // check for out of bounds
1257  Index32 b = ~mBits[n];
1258  if (b & (1<<m)) return start;//simple case
1259  b &= 0xFFFFFFFF<<m;// mask lower bits
1260  while(!b && ++n<mIntSize) b = ~mBits[n];// find next nonzero int
1261  return (!b ? mBitSize : 32*n + FindLowestOn(b));//catch last-int=0
1262  }
1263 
1264  Index32 memUsage() const {
1265  assert(mBits);
1266  return sizeof(Index32*)+(2+mIntSize)*sizeof(Index32);//in bytes
1267  }
1268 }; // class RootNodeMask
1269 
1270 } // namespace util
1271 } // namespace OPENVDB_VERSION_NAME
1272 } // namespace openvdb
1273 
1274 #endif // OPENVDB_UTIL_NODEMASKS_HAS_BEEN_INCLUDED
1275 
1276 // Copyright (c) 2012-2013 DreamWorks Animation LLC
1277 // All rights reserved. This software is distributed under the
1278 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:386
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
bool operator*() const
Definition: NodeMasks.h:209
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:791
void init(Index32 bit_size)
Definition: NodeMasks.h:931
void setOff(Index32 i)
Definition: NodeMasks.h:1146
Index32 countOff() const
Definition: NodeMasks.h:1138
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:1242
bool operator!=(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:169
Index32 CountOn(Index64 v)
Return the number of on bits in the given 64-bit value.
Definition: NodeMasks.h:88
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:446
Index32 findFirstOff() const
Definition: NodeMasks.h:466
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:839
Index32 memUsage() const
Definition: NodeMasks.h:1264
Index32 findFirstOn() const
Definition: NodeMasks.h:459
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:477
BaseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:164
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:617
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:393
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:875
DenseIterator endDense() const
Definition: NodeMasks.h:584
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:503
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:652
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:610
BaseMaskIterator()
Definition: NodeMasks.h:163
OffIterator endOff() const
Definition: NodeMasks.h:335
DenseIterator endDense() const
Definition: NodeMasks.h:765
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:833
void setOn()
Set all bits on.
Definition: NodeMasks.h:814
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:650
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:800
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:312
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:658
OnIterator beginOn() const
Definition: NodeMasks.h:1073
Byte Word
Definition: NodeMasks.h:557
void increment(Index n)
Definition: NodeMasks.h:1031
void setOn()
Set all bits on.
Definition: NodeMasks.h:633
void setLastOn()
Definition: NodeMasks.h:1172
OnIterator beginOn() const
Definition: NodeMasks.h:332
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:831
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:567
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:619
Index getIntSize() const
Definition: NodeMasks.h:941
void setOn()
Definition: NodeMasks.h:1154
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:1253
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:748
Index32 Index
Definition: Types.h:57
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:792
RootNodeMask()
Definition: NodeMasks.h:918
DenseMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:259
bool operator*() const
Definition: NodeMasks.h:1066
Index32 findFirstOn() const
Definition: NodeMasks.h:1198
~NodeMask()
Destructor.
Definition: NodeMasks.h:571
void increment()
Definition: NodeMasks.h:228
Index32 FindLowestOn(Index64 v)
Return the least significant on bit of the given 64-bit value.
Definition: NodeMasks.h:122
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:611
void setLastOff()
Definition: NodeMasks.h:1174
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:483
OnIterator endOn() const
Definition: NodeMasks.h:1074
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:379
void save(std::ostream &os) const
Definition: NodeMasks.h:1212
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:446
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:316
Index32 pos() const
Definition: NodeMasks.h:176
bool next()
Definition: NodeMasks.h:1006
void load(std::istream &is)
Definition: NodeMasks.h:494
void toggle(Index32 i)
Definition: NodeMasks.h:1162
OffIterator endOff() const
Definition: NodeMasks.h:1076
void save(std::ostream &os) const
Definition: NodeMasks.h:689
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:818
Index32 * mBits
Definition: NodeMasks.h:915
Index32 findFirstOff() const
Definition: NodeMasks.h:1205
const RootNodeMask & operator^=(const RootNodeMask &other)
Definition: NodeMasks.h:1111
Definition: NodeMasks.h:188
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:366
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:871
~NodeMask()
Destructor.
Definition: NodeMasks.h:752
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:637
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:599
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:328
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:695
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:711
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:827
Index64 Word
Definition: NodeMasks.h:738
void save(std::ostream &os) const
Definition: NodeMasks.h:865
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:897
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:890
~NodeMask()
Destructor.
Definition: NodeMasks.h:318
void setOn()
Set all bits on.
Definition: NodeMasks.h:407
BaseMaskIterator & operator=(const BaseMaskIterator &iter)
Definition: NodeMasks.h:171
~RootNodeMask()
Definition: NodeMasks.h:929
bool isOff(Index32 i) const
Definition: NodeMasks.h:1180
DenseIterator beginDense() const
Definition: NodeMasks.h:764
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:825
OnMaskIterator & operator++()
Definition: NodeMasks.h:210
void increment(Index n)
Definition: NodeMasks.h:1003
Index32 offset() const
Definition: NodeMasks.h:175
bool operator*() const
Definition: NodeMasks.h:240
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:718
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:352
Base class for the bit mask iterators.
Definition: NodeMasks.h:157
NodeMask operator|(const NodeMask &other) const
Definition: NodeMasks.h:374
DenseIterator beginDense() const
Definition: NodeMasks.h:583
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:780
bool next()
Definition: NodeMasks.h:235
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:287
#define B6(n)
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:644
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:424
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:746
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:646
OnIterator beginOn() const
Definition: NodeMasks.h:760
DenseIterator & operator++()
Definition: NodeMasks.h:1067
void setOff()
Definition: NodeMasks.h:1158
Definition: NodeMasks.h:219
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:843
void setFirstOn()
Definition: NodeMasks.h:1171
const NodeMask & operator|=(const NodeMask &other)
Definition: NodeMasks.h:359
OnIterator beginOn() const
Definition: NodeMasks.h:579
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:419
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:662
Index32 CountOff(Index64 v)
Return the number of off bits in the given 64-bit value.
Definition: NodeMasks.h:96
RootNodeMask operator!() const
Definition: NodeMasks.h:1095
OnIterator & operator++()
Definition: NodeMasks.h:1011
bool test() const
Definition: NodeMasks.h:980
Index32 offset() const
Definition: NodeMasks.h:976
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:750
bool test() const
Definition: NodeMasks.h:177
void increment()
Definition: NodeMasks.h:1026
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:594
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:444
NodeMask()
Default constructor sets all bits off.
Definition: NodeMasks.h:565
uint64_t Index64
Definition: Types.h:56
#define OPENVDB_VERSION_NAME
Definition: version.h:45
void increment()
Definition: NodeMasks.h:197
OffIterator()
Definition: NodeMasks.h:1024
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:400
OffIterator beginOff() const
Definition: NodeMasks.h:581
NodeMask(const NodeMask &other)
Copy constructor.
Definition: NodeMasks.h:569
bool next()
Definition: NodeMasks.h:204
const NodeMask & operator&=(const NodeMask &other)
Definition: NodeMasks.h:775
bool operator==(const BaseMaskIterator &iter) const
Definition: NodeMasks.h:168
Index32 mPos
Definition: NodeMasks.h:957
DenseIterator beginDense() const
Definition: NodeMasks.h:1077
RootNodeMask & operator=(const RootNodeMask &B)
Definition: NodeMasks.h:943
bool next()
Definition: NodeMasks.h:1062
void load(std::istream &is)
Definition: NodeMasks.h:1216
NodeMask & operator=(const NodeMask &other)
Assignment operator.
Definition: NodeMasks.h:320
bool operator*() const
Definition: NodeMasks.h:1010
Index32 FindHighestOn(Index32 v)
Return the most significant on bit of the given 32-bit value.
Definition: NodeMasks.h:137
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:609
void load(std::istream &is)
Definition: NodeMasks.h:693
bool operator*() const
Definition: NodeMasks.h:1038
OffIterator beginOff() const
Definition: NodeMasks.h:762
OnIterator endOn() const
Definition: NodeMasks.h:333
void increment()
Definition: NodeMasks.h:260
BaseIterator & operator=(const BaseIterator &iter)
Definition: NodeMasks.h:969
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:377
NodeMask operator!() const
Definition: NodeMasks.h:774
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:575
OffIterator beginOff() const
Definition: NodeMasks.h:1075
bool isOn() const
Definition: NodeMasks.h:1186
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:438
const NodeMask * mParent
Definition: NodeMasks.h:161
void increment()
Definition: NodeMasks.h:1054
bool operator*() const
Definition: NodeMasks.h:272
Index getBitSize() const
Definition: NodeMasks.h:939
NodeMask operator!() const
Definition: NodeMasks.h:593
OnMaskIterator< NodeMask > OnIterator
Definition: NodeMasks.h:756
WordT & getWord(Index n)
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:859
Index32 pos() const
Definition: NodeMasks.h:978
bool operator<(const Tuple< SIZE, T0 > &t0, const Tuple< SIZE, T1 > &t1)
Definition: Tuple.h:158
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:330
OffIterator & operator++()
Definition: NodeMasks.h:1039
void setOff()
Set all bits off.
Definition: NodeMasks.h:635
unsigned char Byte
Definition: Types.h:62
DenseMaskIterator & operator++()
Definition: NodeMasks.h:273
OnMaskIterator()
Definition: NodeMasks.h:195
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:790
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:388
DenseMaskIterator()
Definition: NodeMasks.h:258
void increment(Index n)
Definition: NodeMasks.h:234
bool next()
Definition: NodeMasks.h:267
RootNodeMask operator|(const RootNodeMask &other) const
Definition: NodeMasks.h:1121
NodeMask operator^(const NodeMask &other) const
Definition: NodeMasks.h:375
void load(std::istream &is)
Definition: NodeMasks.h:869
void toggle()
Definition: NodeMasks.h:1167
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:576
const RootNodeMask & operator|=(const RootNodeMask &other)
Definition: NodeMasks.h:1104
void increment(Index n)
Definition: NodeMasks.h:1059
Index32 mBitSize
Definition: NodeMasks.h:914
DenseIterator endDense() const
Definition: NodeMasks.h:337
uint32_t Index32
Definition: Types.h:55
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:648
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:757
Index32 getMemUsage() const
Definition: NodeMasks.h:1129
Index32 mBitSize
Definition: NodeMasks.h:958
OnMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:196
bool isOff() const
Definition: NodeMasks.h:1192
OffIterator beginOff() const
Definition: NodeMasks.h:334
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:631
bool operator==(const BaseIterator &iter) const
Definition: NodeMasks.h:966
DenseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1053
void setOff()
Set all bits off.
Definition: NodeMasks.h:816
DenseIterator endDense() const
Definition: NodeMasks.h:1078
bool isOn(Index32 i) const
Definition: NodeMasks.h:1175
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:660
OnIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:997
void setFirstOn()
Set the first bit on.
Definition: NodeMasks.h:430
Index32 countOn() const
Definition: NodeMasks.h:1131
Index32 findFirstOff() const
Definition: NodeMasks.h:664
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:829
bool operator!=(const BaseIterator &iter) const
Definition: NodeMasks.h:967
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:823
Index32 findFirstOff() const
Definition: NodeMasks.h:845
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:705
const RootNodeMask * mParent
Definition: NodeMasks.h:959
void set(bool on)
Set all bits to the specified state.
Definition: NodeMasks.h:812
const RootNodeMask & operator&=(const RootNodeMask &other)
Definition: NodeMasks.h:1096
Definition: NodeMasks.h:911
RootNodeMask(Index32 bit_size)
Definition: NodeMasks.h:919
void increment(Index n)
Definition: NodeMasks.h:266
void toggle()
Toggle the state of all bits in the mask.
Definition: NodeMasks.h:642
void printAll(std::ostream &os=std::cout) const
Definition: NodeMasks.h:884
bool isOn() const
Return true if all the bits are on.
Definition: NodeMasks.h:841
void setLastOn()
Set the last bit on.
Definition: NodeMasks.h:432
void increment()
Definition: NodeMasks.h:998
NodeMask operator!() const
Definition: NodeMasks.h:351
NodeMask(bool on)
All bits are set to the specified state.
Definition: NodeMasks.h:314
OffMaskIterator & operator++()
Definition: NodeMasks.h:241
OffIterator endOff() const
Definition: NodeMasks.h:582
Index64 Word
Definition: NodeMasks.h:296
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:785
RootNodeMask(const RootNodeMask &B)
Definition: NodeMasks.h:924
NodeMask operator&(const NodeMask &other) const
Definition: NodeMasks.h:373
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:454
void setOn(Index32 i)
Definition: NodeMasks.h:1140
const NodeMask & operator^=(const NodeMask &other)
Definition: NodeMasks.h:604
void setFirstOff()
Definition: NodeMasks.h:1173
bool next()
Definition: NodeMasks.h:1034
BaseIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:962
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:515
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:629
void increment(Index n)
Definition: NodeMasks.h:203
OnIterator endOn() const
Definition: NodeMasks.h:761
DenseIterator beginDense() const
Definition: NodeMasks.h:336
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:577
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:810
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:398
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:613
OffIterator endOff() const
Definition: NodeMasks.h:763
Definition: NodeMasks.h:250
void printAll(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1237
OffIterator(Index32 pos, const RootNodeMask *parent)
Definition: NodeMasks.h:1025
OnIterator endOn() const
Definition: NodeMasks.h:580
DenseMaskIterator< NodeMask > DenseIterator
Definition: NodeMasks.h:758
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
Index32 findFirstOn() const
Definition: NodeMasks.h:844
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:624
OffMaskIterator()
Definition: NodeMasks.h:226
Index32 findNextOff(Index32 start) const
Definition: NodeMasks.h:533
Index32 findFirstOn() const
Definition: NodeMasks.h:663
Index32 findNextOn(Index32 start) const
Definition: NodeMasks.h:521
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:794
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:796
void set(Index32 i, bool On)
Definition: NodeMasks.h:1152
RootNodeMask operator^(const RootNodeMask &other) const
Definition: NodeMasks.h:1124
WordT getWord(Index n) const
Return the nth word of the bit mask, for a word of arbitrary size.
Definition: NodeMasks.h:853
void setOff()
Set all bits off.
Definition: NodeMasks.h:413
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:498
bool isOff() const
Return true if all the bits are off.
Definition: NodeMasks.h:453
Index32 mPos
Definition: NodeMasks.h:160
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:615
void printBits(std::ostream &os=std::cout, Index32 max_out=80u) const
Definition: NodeMasks.h:1225
OffMaskIterator< NodeMask > OffIterator
Definition: NodeMasks.h:329
OffMaskIterator(Index32 pos, const NodeMask *parent)
Definition: NodeMasks.h:227
void save(std::ostream &os) const
Definition: NodeMasks.h:490
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:805
Index32 mIntSize
Definition: NodeMasks.h:914
void printInfo(std::ostream &os=std::cout) const
simple print method for debugging
Definition: NodeMasks.h:1221
RootNodeMask operator&(const RootNodeMask &other) const
Definition: NodeMasks.h:1118
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:798
void setLastOff()
Set the last bit off.
Definition: NodeMasks.h:436
void printBits(std::ostream &os=std::cout) const
Definition: NodeMasks.h:699
void setFirstOff()
Set the first bit off.
Definition: NodeMasks.h:434