31 #ifndef OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
32 #define OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
35 #include <boost/shared_ptr.hpp>
36 #include <boost/shared_array.hpp>
37 #include <boost/static_assert.hpp>
38 #include <openvdb/Types.h>
39 #include <openvdb/io/Compression.h>
40 #include <openvdb/math/Math.h>
41 #include <openvdb/util/NodeMasks.h>
53 template<Index Log2Dim>
58 typedef boost::shared_ptr<LeafNodeType>
Ptr;
63 static const Index LOG2DIM = Log2Dim;
64 static const Index TOTAL = Log2Dim;
65 static const Index DIM = 1 << TOTAL;
66 static const Index NUM_VALUES = 1 << 3 * Log2Dim;
67 static const Index NUM_VOXELS = NUM_VALUES;
68 static const Index SIZE = NUM_VALUES;
73 template<
typename ValueType>
78 template<
typename OtherNodeType>
79 struct SameConfiguration {
89 Buffer(
const NodeMaskType& other): mData(other) {}
90 Buffer(
const Buffer& other): mData(other.mData) {}
92 void fill(
bool val) { mData.set(val); }
93 Buffer&
operator=(
const Buffer& b) {
if (&b !=
this) { mData = b.mData; }
return *
this; }
100 if (mData.isOn(i))
return LeafNode::sOn;
else return LeafNode::sOff;
104 bool operator==(
const Buffer& other)
const {
return mData == other.mData; }
105 bool operator!=(
const Buffer& other)
const {
return mData != other.mData; }
109 void swap(Buffer& other) {
if (&other !=
this) std::swap(mData, other.mData); }
115 friend class ::TestLeaf;
130 explicit LeafNode(
const Coord& xyz,
bool value =
false,
bool active =
false);
132 #ifndef OPENVDB_2_ABI_COMPATIBLE
141 template<
typename OtherValueType>
145 template<
typename ValueType>
149 template<
typename ValueType>
153 template<
typename ValueType>
186 bool isEmpty()
const {
return mValueMask.isOff(); }
188 bool isDense()
const {
return mValueMask.isOn(); }
190 #ifndef OPENVDB_2_ABI_COMPATIBLE
191 bool isAllocated()
const {
return true; }
207 void evalActiveBoundingBox(CoordBBox& bbox,
bool visitVoxels =
true)
const;
214 void setOrigin(
const Coord& origin) { mOrigin = origin; }
216 const Coord& origin()
const {
return mOrigin; }
218 void getOrigin(Coord& origin)
const { origin = mOrigin; }
223 static Index coordToOffset(
const Coord& xyz);
226 static Coord offsetToLocalCoord(
Index n);
228 Coord offsetToGlobalCoord(
Index n)
const;
231 std::string str()
const;
235 template<
typename OtherType, Index OtherLog2Dim>
247 void swap(Buffer& other) { mBuffer.swap(other); }
248 const Buffer&
buffer()
const {
return mBuffer; }
255 void readTopology(std::istream&,
bool fromHalf =
false);
257 void writeTopology(std::ostream&,
bool toHalf =
false)
const;
260 void readBuffers(std::istream&,
bool fromHalf =
false);
261 void readBuffers(std::istream& is,
const CoordBBox&,
bool fromHalf =
false);
263 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
269 const bool& getValue(
const Coord& xyz)
const;
271 const bool& getValue(
Index offset)
const;
276 bool probeValue(
const Coord& xyz,
bool& val)
const;
282 void setActiveState(
const Coord& xyz,
bool on);
287 void setValueOnly(
const Coord& xyz,
bool val);
289 void setValueOnly(
Index offset,
bool val) { assert(offset<SIZE); mBuffer.setValue(offset,val); }
292 void setValueOff(
const Coord& xyz) { mValueMask.setOff(this->coordToOffset(xyz)); }
297 void setValueOff(
const Coord& xyz,
bool val);
299 void setValueOff(
Index offset,
bool val);
302 void setValueOn(
const Coord& xyz) { mValueMask.setOn(this->coordToOffset(xyz)); }
307 void setValueOn(
const Coord& xyz,
bool val);
309 void setValue(
const Coord& xyz,
bool val) { this->setValueOn(xyz, val); };
311 void setValueOn(
Index offset,
bool val);
315 template<
typename ModifyOp>
316 void modifyValue(
Index offset,
const ModifyOp& op);
319 template<
typename ModifyOp>
320 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
323 template<
typename ModifyOp>
324 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
332 bool isValueOn(
const Coord& xyz)
const {
return mValueMask.isOn(this->coordToOffset(xyz)); }
334 bool isValueOn(
Index offset)
const { assert(offset < SIZE);
return mValueMask.isOn(offset); }
340 void clip(
const CoordBBox&,
bool background);
343 void fill(
const CoordBBox& bbox,
bool value,
bool active =
true);
346 void fill(
const bool& value);
348 void fill(
const bool& value,
bool active);
361 template<
typename DenseT>
362 void copyToDense(
const CoordBBox& bbox, DenseT& dense)
const;
380 template<
typename DenseT>
381 void copyFromDense(
const CoordBBox& bbox,
const DenseT& dense,
bool background,
bool tolerance);
385 template<
typename AccessorT>
386 const bool&
getValueAndCache(
const Coord& xyz, AccessorT&)
const {
return this->getValue(xyz);}
390 template<
typename AccessorT>
395 template<
typename AccessorT>
396 void setValueAndCache(
const Coord& xyz,
bool val, AccessorT&) { this->setValueOn(xyz, val); }
401 template<
typename AccessorT>
406 template<
typename AccessorT>
409 this->setValueOff(xyz, value);
415 template<
typename ModifyOp,
typename AccessorT>
418 this->modifyValue(xyz, op);
423 template<
typename ModifyOp,
typename AccessorT>
426 this->modifyValueAndActiveState(xyz, op);
432 template<
typename AccessorT>
435 this->setActiveState(xyz, on);
441 template<
typename AccessorT>
444 return this->probeValue(xyz, val);
449 template<
typename AccessorT>
455 const bool&
getFirstValue()
const {
if (mValueMask.isOn(0))
return sOn;
else return sOff; }
459 const bool&
getLastValue()
const {
if (mValueMask.isOn(SIZE-1))
return sOn;
else return sOff; }
464 bool isConstant(
bool& constValue,
bool& state,
bool tolerance = 0)
const;
468 void resetBackground(
bool oldBackground,
bool newBackground);
470 void negate() { mBuffer.mData.toggle(); }
472 template<MergePolicy Policy>
473 void merge(
const LeafNode& other,
bool bg =
false,
bool otherBG =
false);
474 template<MergePolicy Policy>
void merge(
bool tileValue,
bool tileActive);
484 template<
typename OtherType>
498 template<
typename OtherType>
512 template<
typename OtherType>
515 template<
typename CombineOp>
517 template<
typename CombineOp>
518 void combine(
bool,
bool valueIsActive, CombineOp& op);
520 template<
typename CombineOp,
typename OtherType >
521 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
522 template<
typename CombineOp,
typename OtherNodeT >
523 void combine2(
bool,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
524 template<
typename CombineOp,
typename OtherNodeT >
525 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
531 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
533 template<
typename VisitorOp>
void visit(VisitorOp&);
534 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
536 template<
typename OtherLeafNodeType,
typename VisitorOp>
537 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
538 template<
typename OtherLeafNodeType,
typename VisitorOp>
539 void visit2Node(OtherLeafNodeType& other, VisitorOp&)
const;
540 template<
typename IterT,
typename VisitorOp>
541 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false);
542 template<
typename IterT,
typename VisitorOp>
543 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false)
const;
546 void prune(
const ValueType& = zeroVal<ValueType>()) {}
549 template<
typename AccessorT>
551 template<
typename NodeT>
552 NodeT*
stealNode(
const Coord&,
const ValueType&,
bool) {
return NULL; }
553 template<
typename NodeT>
555 template<
typename NodeT>
557 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
560 void addTile(
Index level,
const Coord&,
bool val,
bool active);
561 void addTile(
Index offset,
bool val,
bool active);
562 template<
typename AccessorT>
563 void addTileAndCache(
Index level,
const Coord&,
bool val,
bool active, AccessorT&);
566 LeafNode* touchLeaf(
const Coord&) {
return this; }
568 template<
typename AccessorT>
571 template<
typename AccessorT>
573 template<
typename NodeT,
typename AccessorT>
577 if (!(boost::is_same<NodeT,LeafNode>::value))
return NULL;
578 return reinterpret_cast<NodeT*
>(
this);
583 const LeafNode* probeLeaf(
const Coord&)
const {
return this; }
585 template<
typename AccessorT>
588 template<
typename AccessorT>
590 template<
typename NodeT,
typename AccessorT>
594 if (!(boost::is_same<NodeT,LeafNode>::value))
return NULL;
595 return reinterpret_cast<const NodeT*
>(
this);
608 template<
typename MaskIterT,
typename NodeT,
typename ValueT>
612 public SparseIteratorBase<MaskIterT, ValueIter<MaskIterT, NodeT, ValueT>, NodeT, ValueT>
617 ValueIter(
const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
619 const bool&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
620 const bool&
getValue()
const {
return this->getItem(this->pos()); }
623 void setItem(
Index pos,
bool value)
const { this->parent().setValueOnly(pos, value); }
625 void setValue(
bool value)
const { this->setItem(this->pos(), value); }
628 template<
typename ModifyOp>
629 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
631 template<
typename ModifyOp>
632 void modifyValue(
const ModifyOp& op)
const { this->modifyItem(this->pos(), op); }
636 template<
typename MaskIterT,
typename NodeT>
642 MaskIterT, ChildIter<MaskIterT, NodeT>, NodeT, bool>(iter, parent) {}
645 template<
typename NodeT,
typename ValueT>
647 MaskDenseIter, DenseIter<NodeT, ValueT>, NodeT, void, ValueT>
653 DenseIter(
const MaskDenseIter& iter, NodeT* parent): BaseT(iter, parent) {}
657 value = this->parent().getValue(pos);
666 void unsetItem(
Index pos,
const ValueT& val)
const {this->parent().setValueOnly(pos, val);}
671 typedef ValueIter<MaskOnIter, const LeafNode, const bool>
ValueOnCIter;
683 ValueOnCIter
cbeginValueOn()
const {
return ValueOnCIter(mValueMask.beginOn(),
this); }
684 ValueOnCIter
beginValueOn()
const {
return ValueOnCIter(mValueMask.beginOn(),
this); }
685 ValueOnIter
beginValueOn() {
return ValueOnIter(mValueMask.beginOn(),
this); }
686 ValueOffCIter
cbeginValueOff()
const {
return ValueOffCIter(mValueMask.beginOff(),
this); }
687 ValueOffCIter
beginValueOff()
const {
return ValueOffCIter(mValueMask.beginOff(),
this); }
688 ValueOffIter
beginValueOff() {
return ValueOffIter(mValueMask.beginOff(),
this); }
689 ValueAllCIter
cbeginValueAll()
const {
return ValueAllCIter(mValueMask.beginDense(),
this); }
690 ValueAllCIter
beginValueAll()
const {
return ValueAllCIter(mValueMask.beginDense(),
this); }
691 ValueAllIter
beginValueAll() {
return ValueAllIter(mValueMask.beginDense(),
this); }
693 ValueOnCIter
cendValueOn()
const {
return ValueOnCIter(mValueMask.endOn(),
this); }
694 ValueOnCIter
endValueOn()
const {
return ValueOnCIter(mValueMask.endOn(),
this); }
695 ValueOnIter
endValueOn() {
return ValueOnIter(mValueMask.endOn(),
this); }
696 ValueOffCIter
cendValueOff()
const {
return ValueOffCIter(mValueMask.endOff(),
this); }
697 ValueOffCIter
endValueOff()
const {
return ValueOffCIter(mValueMask.endOff(),
this); }
698 ValueOffIter
endValueOff() {
return ValueOffIter(mValueMask.endOff(),
this); }
699 ValueAllCIter
cendValueAll()
const {
return ValueAllCIter(mValueMask.endDense(),
this); }
700 ValueAllCIter
endValueAll()
const {
return ValueAllCIter(mValueMask.endDense(),
this); }
701 ValueAllIter
endValueAll() {
return ValueAllIter(mValueMask.endDense(),
this); }
705 ChildOnCIter
cbeginChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
706 ChildOnCIter
beginChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
707 ChildOnIter
beginChildOn() {
return ChildOnIter(mValueMask.endOn(),
this); }
708 ChildOffCIter
cbeginChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
709 ChildOffCIter
beginChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
710 ChildOffIter
beginChildOff() {
return ChildOffIter(mValueMask.endOff(),
this); }
711 ChildAllCIter
cbeginChildAll()
const {
return ChildAllCIter(mValueMask.beginDense(),
this); }
712 ChildAllCIter
beginChildAll()
const {
return ChildAllCIter(mValueMask.beginDense(),
this); }
713 ChildAllIter
beginChildAll() {
return ChildAllIter(mValueMask.beginDense(),
this); }
715 ChildOnCIter
cendChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
716 ChildOnCIter
endChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
717 ChildOnIter
endChildOn() {
return ChildOnIter(mValueMask.endOn(),
this); }
718 ChildOffCIter
cendChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
719 ChildOffCIter
endChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
720 ChildOffIter
endChildOff() {
return ChildOffIter(mValueMask.endOff(),
this); }
721 ChildAllCIter
cendChildAll()
const {
return ChildAllCIter(mValueMask.endDense(),
this); }
722 ChildAllCIter
endChildAll()
const {
return ChildAllCIter(mValueMask.endDense(),
this); }
723 ChildAllIter
endChildAll() {
return ChildAllIter(mValueMask.endDense(),
this); }
746 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
747 static inline void doVisit(NodeT&, VisitorOp&);
749 template<
typename NodeT,
typename OtherNodeT,
typename VisitorOp,
750 typename ChildAllIterT,
typename OtherChildAllIterT>
751 static inline void doVisit2Node(NodeT&
self, OtherNodeT& other, VisitorOp&);
753 template<
typename NodeT,
typename VisitorOp,
754 typename ChildAllIterT,
typename OtherChildAllIterT>
755 static inline void doVisit2(NodeT&
self, OtherChildAllIterT&, VisitorOp&,
bool otherIsLHS);
774 friend struct ValueIter<MaskOnIter,
LeafNode, bool>;
775 friend struct ValueIter<MaskOffIter,
LeafNode, bool>;
776 friend struct ValueIter<MaskDenseIter,
LeafNode, bool>;
777 friend struct ValueIter<MaskOnIter, const
LeafNode, bool>;
778 friend struct ValueIter<MaskOffIter, const
LeafNode, bool>;
779 friend struct ValueIter<MaskDenseIter, const
LeafNode, bool>;
803 template<Index Log2Dim>
810 template<Index Log2Dim>
815 mOrigin(xyz & (~(DIM - 1)))
820 #ifndef OPENVDB_2_ABI_COMPATIBLE
821 template<Index Log2Dim>
826 mOrigin(xyz & (~(DIM - 1)))
835 template<Index Log2Dim>
838 mValueMask(other.mValueMask),
839 mBuffer(other.mBuffer),
840 mOrigin(other.mOrigin)
846 template<Index Log2Dim>
847 template<
typename ValueT>
850 mValueMask(other.getValueMask()),
851 mOrigin(other.origin())
855 static inline bool convertValue(
const ValueT& val) {
return bool(val); }
859 mBuffer.
setValue(i, Local::convertValue(other.mBuffer[i]));
864 template<Index Log2Dim>
865 template<
typename ValueT>
869 mValueMask(other.getValueMask()),
871 mOrigin(other.origin())
876 template<Index Log2Dim>
877 template<
typename ValueT>
880 mValueMask(other.getValueMask()),
881 mBuffer(other.getValueMask()),
882 mOrigin(other.origin())
887 template<Index Log2Dim>
888 template<
typename ValueT>
892 mValueMask(other.getValueMask()),
893 mBuffer(other.getValueMask()),
894 mOrigin(other.origin())
896 if (offValue) {
if (!onValue) mBuffer.
mData.toggle();
else mBuffer.
mData.setOn(); }
900 template<Index Log2Dim>
910 template<Index Log2Dim>
918 template<Index Log2Dim>
923 if (bbox.isInside(this_bbox))
return;
927 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
928 this_bbox.translate(this->
origin());
930 bbox.expand(this_bbox);
935 template<Index Log2Dim>
936 template<
typename OtherType, Index OtherLog2Dim>
941 return (Log2Dim == OtherLog2Dim && mValueMask == other->
getValueMask());
945 template<Index Log2Dim>
949 std::ostringstream ostr;
950 ostr <<
"LeafNode @" << mOrigin <<
": ";
951 for (
Index32 n = 0; n <
SIZE; ++n) ostr << (mValueMask.
isOn(n) ?
'#' :
'.');
959 template<Index Log2Dim>
963 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
964 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
965 + ((xyz[1] & (DIM-1u)) << Log2Dim)
966 + (xyz[2] & (DIM-1u));
970 template<Index Log2Dim>
974 assert(n < (1 << 3*Log2Dim));
976 xyz.setX(n >> 2*Log2Dim);
977 n &= ((1 << 2*Log2Dim) - 1);
978 xyz.setY(n >> Log2Dim);
979 xyz.setZ(n & ((1 << Log2Dim) - 1));
984 template<Index Log2Dim>
995 template<Index Log2Dim>
1003 template<Index Log2Dim>
1007 mValueMask.
save(os);
1011 template<Index Log2Dim>
1021 bool background =
false;
1023 background = *
static_cast<const bool*
>(bgPtr);
1025 this->
clip(clipBBox, background);
1029 template<Index Log2Dim>
1034 mValueMask.
load(is);
1036 is.read(reinterpret_cast<char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1040 mBuffer.
mData.load(is);
1045 int8_t numBuffers = 0;
1046 is.read(reinterpret_cast<char*>(&numBuffers),
sizeof(int8_t));
1050 boost::shared_array<bool> buf(
new bool[SIZE]);
1051 io::readData<bool>(is, buf.get(),
SIZE,
true);
1054 mBuffer.
mData.setOff();
1056 if (buf[i]) mBuffer.
mData.setOn(i);
1059 if (numBuffers > 1) {
1062 for (
int i = 1; i < numBuffers; ++i) {
1063 io::readData<bool>(is, buf.get(),
SIZE,
true);
1070 template<Index Log2Dim>
1075 mValueMask.
save(os);
1077 os.write(reinterpret_cast<const char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1079 mBuffer.
mData.save(os);
1086 template<Index Log2Dim>
1090 return (mValueMask == other.mValueMask && mBuffer.
mData == other.mBuffer.
mData);
1094 template<Index Log2Dim>
1105 template<Index Log2Dim>
1109 state = mValueMask.
isOn();
1111 if (!(state || mValueMask.
isOff()))
return false;
1114 if (!tolerance && !(mBuffer.
mData.isOn() || mBuffer.
mData.isOff()))
return false;
1116 state = mValueMask.
isOn();
1117 constValue = mBuffer.
mData.isOn();
1125 template<Index Log2Dim>
1132 template<Index Log2Dim>
1136 assert(offset < SIZE);
1141 template<Index Log2Dim>
1142 template<
typename AccessorT>
1145 bool val,
bool active, AccessorT&)
1147 this->
addTile(level, xyz, val, active);
1154 template<Index Log2Dim>
1159 if (mBuffer.
mData.isOn(this->coordToOffset(xyz)))
return sOn;
else return sOff;
1163 template<Index Log2Dim>
1167 assert(offset < SIZE);
1169 if (mBuffer.
mData.isOn(offset))
return sOn;
else return sOff;
1173 template<Index Log2Dim>
1178 val = mBuffer.
mData.isOn(offset);
1179 return mValueMask.
isOn(offset);
1183 template<Index Log2Dim>
1191 template<Index Log2Dim>
1195 assert(offset < SIZE);
1196 mValueMask.
setOn(offset);
1197 mBuffer.
mData.set(offset, val);
1201 template<Index Log2Dim>
1209 template<Index Log2Dim>
1217 template<Index Log2Dim>
1225 template<Index Log2Dim>
1229 assert(offset < SIZE);
1230 mValueMask.
setOff(offset);
1231 mBuffer.
mData.set(offset, val);
1235 template<Index Log2Dim>
1236 template<
typename ModifyOp>
1240 bool val = mBuffer.
mData.isOn(offset);
1242 mBuffer.
mData.set(offset, val);
1243 mValueMask.
setOn(offset);
1247 template<Index Log2Dim>
1248 template<
typename ModifyOp>
1256 template<Index Log2Dim>
1257 template<
typename ModifyOp>
1262 bool val = mBuffer.
mData.isOn(offset), state = mValueMask.
isOn(offset);
1264 mBuffer.
mData.set(offset, val);
1265 mValueMask.
set(offset, state);
1272 template<Index Log2Dim>
1276 if (newBackground != oldBackground) {
1278 NodeMaskType bgMask = !(mBuffer.
mData | mValueMask);
1280 mBuffer.
mData = (mBuffer.
mData & mValueMask) | bgMask;
1288 template<Index Log2Dim>
1289 template<MergePolicy Policy>
1296 const Index n = iter.pos();
1297 if (mValueMask.
isOff(n)) {
1298 mBuffer.
mData.set(n, other.mBuffer.
mData.isOn(n));
1299 mValueMask.
setOn(n);
1305 template<Index Log2Dim>
1306 template<MergePolicy Policy>
1312 if (!tileActive)
return;
1314 if (tileValue) mBuffer.
mData |= !mValueMask;
1315 else mBuffer.
mData &= mValueMask;
1324 template<Index Log2Dim>
1325 template<
typename OtherType>
1333 template<Index Log2Dim>
1334 template<
typename OtherType>
1343 template<Index Log2Dim>
1344 template<
typename OtherType>
1356 template<Index Log2Dim>
1361 if (!clipBBox.hasOverlap(nodeBBox)) {
1363 this->
fill(nodeBBox, background,
false);
1364 }
else if (clipBBox.isInside(nodeBBox)) {
1374 nodeBBox.intersect(clipBBox);
1376 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1377 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1378 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1379 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1396 template<Index Log2Dim>
1400 for (
Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1401 const Index offsetX = (x & (DIM-1u))<<2*Log2Dim;
1402 for (
Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1403 const Index offsetXY = offsetX + ((y & (DIM-1u))<< Log2Dim);
1404 for (
Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1405 const Index offset = offsetXY + (z & (DIM-1u));
1406 mValueMask.
set(offset, active);
1407 mBuffer.
mData.set(offset, value);
1413 template<Index Log2Dim>
1417 mBuffer.
fill(value);
1420 template<Index Log2Dim>
1424 mBuffer.
fill(value);
1425 mValueMask.
set(active);
1432 template<Index Log2Dim>
1433 template<
typename DenseT>
1437 typedef typename DenseT::ValueType DenseValueType;
1439 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1440 const Coord&
min = dense.bbox().min();
1441 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1442 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1443 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1444 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1446 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1447 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1449 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1450 *t2 = DenseValueType(mBuffer.
mData.isOn(n2++));
1457 template<Index Log2Dim>
1458 template<
typename DenseT>
1461 bool background,
bool tolerance)
1463 typedef typename DenseT::ValueType DenseValueType;
1465 inline static bool toBool(
const DenseValueType& v) {
return !
math::isZero(v); }
1468 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1469 const Coord&
min = dense.bbox().min();
1470 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1471 const Int32 n0 = bbox.min()[2] & (DIM-1u);
1472 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1473 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1475 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1476 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1478 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1480 if (tolerance || (background == Local::toBool(*s2))) {
1482 mBuffer.
mData.set(n2, background);
1484 mValueMask.
setOn(n2);
1485 mBuffer.
mData.set(n2, Local::toBool(*s2));
1496 template<Index Log2Dim>
1497 template<
typename CombineOp>
1503 bool result =
false, aVal = mBuffer.
mData.isOn(i), bVal = other.mBuffer.
mData.isOn(i);
1505 .setAIsActive(mValueMask.
isOn(i))
1507 .setBIsActive(other.mValueMask.
isOn(i))
1508 .setResultRef(result));
1510 mBuffer.
mData.set(i, result);
1515 template<Index Log2Dim>
1516 template<
typename CombineOp>
1521 args.
setBRef(value).setBIsActive(valueIsActive);
1523 bool result =
false, aVal = mBuffer.
mData.isOn(i);
1525 .setAIsActive(mValueMask.
isOn(i))
1526 .setResultRef(result));
1528 mBuffer.
mData.set(i, result);
1536 template<Index Log2Dim>
1537 template<
typename CombineOp,
typename OtherType>
1540 bool valueIsActive, CombineOp& op)
1543 args.
setBRef(value).setBIsActive(valueIsActive);
1545 bool result =
false, aVal = other.mBuffer.
mData.isOn(i);
1547 .setAIsActive(other.mValueMask.
isOn(i))
1548 .setResultRef(result));
1550 mBuffer.
mData.set(i, result);
1555 template<Index Log2Dim>
1556 template<
typename CombineOp,
typename OtherNodeT>
1559 bool valueIsActive, CombineOp& op)
1562 args.
setARef(value).setAIsActive(valueIsActive);
1564 bool result =
false, bVal = other.mBuffer.mData.isOn(i);
1566 .setBIsActive(other.mValueMask.isOn(i))
1567 .setResultRef(result));
1569 mBuffer.
mData.set(i, result);
1574 template<Index Log2Dim>
1575 template<
typename CombineOp,
typename OtherNodeT>
1582 mValueMask.
set(i, b0.mValueMask.
isOn(i) || b1.mValueMask.isOn(i));
1584 bool result =
false, b0Val = b0.mBuffer.
mData.isOn(i), b1Val = b1.mBuffer.mData.isOn(i);
1586 .setAIsActive(b0.mValueMask.
isOn(i))
1588 .setBIsActive(b1.mValueMask.isOn(i))
1589 .setResultRef(result));
1591 mBuffer.
mData.set(i, result);
1598 template<Index Log2Dim>
1599 template<
typename BBoxOp>
1603 if (op.template descent<LEVEL>()) {
1606 op.operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1608 op.template operator()<LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
1621 template<Index Log2Dim>
1622 template<
typename VisitorOp>
1626 doVisit<LeafNode, VisitorOp, ChildAllIter>(*
this, op);
1630 template<Index Log2Dim>
1631 template<
typename VisitorOp>
1635 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*
this, op);
1639 template<Index Log2Dim>
1640 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
1644 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
1653 template<Index Log2Dim>
1654 template<
typename OtherLeafNodeType,
typename VisitorOp>
1659 typename OtherLeafNodeType::ChildAllIter>(*
this, other, op);
1663 template<Index Log2Dim>
1664 template<
typename OtherLeafNodeType,
typename VisitorOp>
1669 typename OtherLeafNodeType::ChildAllCIter>(*
this, other, op);
1673 template<Index Log2Dim>
1676 typename OtherNodeT,
1678 typename ChildAllIterT,
1679 typename OtherChildAllIterT>
1684 BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
1685 BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
1687 ChildAllIterT iter =
self.beginChildAll();
1688 OtherChildAllIterT otherIter = other.beginChildAll();
1690 for ( ; iter && otherIter; ++iter, ++otherIter) {
1691 op(iter, otherIter);
1699 template<Index Log2Dim>
1700 template<
typename IterT,
typename VisitorOp>
1704 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(*
this, otherIter, op, otherIsLHS);
1708 template<Index Log2Dim>
1709 template<
typename IterT,
typename VisitorOp>
1713 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(*
this, otherIter, op, otherIsLHS);
1717 template<Index Log2Dim>
1721 typename ChildAllIterT,
1722 typename OtherChildAllIterT>
1725 VisitorOp& op,
bool otherIsLHS)
1727 if (!otherIter)
return;
1730 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
1731 op(otherIter, iter);
1734 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
1735 op(iter, otherIter);
1744 #endif // OPENVDB_TREE_LEAFNODEBOOL_HAS_BEEN_INCLUDED
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1631
ChildIter< MaskOffIter, const LeafNode > ChildOffCIter
Definition: LeafNodeBool.h:679
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:349
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNodeBool.h:60
void setValueAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNodeBool.h:396
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1217
ChildOffCIter cendChildOff() const
Definition: LeafNodeBool.h:718
~Buffer()
Definition: LeafNodeBool.h:91
ChildOnCIter cbeginChildOn() const
Definition: LeafNodeBool.h:705
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:441
static Index getChildDim()
Definition: LeafNodeBool.h:171
ChildAllCIter beginChildAll() const
Definition: LeafNodeBool.h:712
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:554
void save(std::ostream &os) const
Definition: NodeMasks.h:507
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1718
ValueAllCIter cendValueAll() const
Definition: LeafNodeBool.h:699
DenseIter(const MaskDenseIter &iter, NodeT *parent)
Definition: LeafNodeBool.h:653
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:1051
DenseIter< const LeafNode, const bool > ChildAllCIter
Definition: LeafNodeBool.h:681
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:572
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNodeBool.h:424
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1648
NodeMaskType::OffIterator MaskOffIter
Definition: LeafNodeBool.h:605
LeafNode< bool, Log2Dim > LeafNodeType
Definition: LeafNodeBool.h:57
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1241
ChildOffCIter cbeginChildOff() const
Definition: LeafNodeBool.h:708
ValueIter< MaskDenseIter, LeafNode, const bool > ValueAllIter
Definition: LeafNodeBool.h:674
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:550
void load(std::istream &is)
Definition: NodeMasks.h:511
LeafNode< ValueType, Log2Dim > Type
Definition: LeafNodeBool.h:74
ChildAllIter endChildAll()
Definition: LeafNodeBool.h:723
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:214
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1227
ChildAllCIter cbeginChildAll() const
Definition: LeafNodeBool.h:711
ChildOffIter endChildOff()
Definition: LeafNodeBool.h:720
uint64_t Index64
Definition: Types.h:58
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:435
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNodeBool.h:302
ValueIter< MaskOnIter, const LeafNode, const bool > ValueOnCIter
Definition: LeafNodeBool.h:671
ValueOffIter beginValueOff()
Definition: LeafNodeBool.h:688
const bool & getValue(Index i) const
Definition: LeafNodeBool.h:95
ValueOnCIter cendValueOn() const
Definition: LeafNodeBool.h:693
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:219
Buffer & buffer()
Definition: LeafNodeBool.h:249
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active...
Definition: LeafNode.h:698
bool isValueMaskOff(Index n) const
Definition: LeafNodeBool.h:730
ChildOnIter beginChildOn()
Definition: LeafNodeBool.h:707
ValueIter< MaskDenseIter, const LeafNode, const bool > ValueAllCIter
Definition: LeafNodeBool.h:675
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:680
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:548
bool resultIsActive() const
Definition: Types.h:358
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNodeBool.h:327
void visit(VisitorOp &)
Definition: LeafNode.h:1994
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNodeBool.h:211
ValueAllCIter beginValueAll() const
Definition: LeafNodeBool.h:690
const bool & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNodeBool.h:386
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:586
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNodeBool.h:466
void setValue(bool value) const
Definition: LeafNodeBool.h:625
ChildOffCIter endChildOff() const
Definition: LeafNodeBool.h:719
ValueOffCIter cbeginValueOff() const
Definition: LeafNodeBool.h:686
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNodeBool.h:304
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:617
void setValue(Index i, const ValueType &val)
Set the i'th value of this buffer to the specified value.
Definition: LeafNode.h:185
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this LeafNode and inactive in the other LeafNode.
Definition: LeafNode.h:1840
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNodeBool.h:186
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNodeBool.h:292
ValueOnCIter beginValueOn() const
Definition: LeafNodeBool.h:684
Buffer()
Definition: LeafNodeBool.h:87
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:347
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNodeBool.h:641
ChildIter< MaskOnIter, LeafNode > ChildOnIter
Definition: LeafNodeBool.h:676
ValueOnCIter cbeginValueOn() const
Definition: LeafNodeBool.h:683
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNodeBool.h:416
void swap(Buffer &other)
Definition: LeafNodeBool.h:109
ValueOffCIter endValueOff() const
Definition: LeafNodeBool.h:697
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1539
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:558
int32_t Int32
Definition: Types.h:61
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:464
ChildOnIter endChildOn()
Definition: LeafNodeBool.h:717
void setValue(const Coord &xyz, bool val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNodeBool.h:309
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1747
static Index getLevel()
Definition: LeafNodeBool.h:169
ValueIter< MaskOffIter, const LeafNode, const bool > ValueOffCIter
Definition: LeafNodeBool.h:673
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:589
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1971
bool isChildMaskOff() const
Definition: LeafNodeBool.h:737
ValueIter()
Definition: LeafNodeBool.h:616
void fill(const ValueType &val)
Populate this buffer with a constant value.
Definition: LeafNode.h:170
ChildAllCIter cendChildAll() const
Definition: LeafNodeBool.h:721
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: LeafNode.h:1686
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNodeBool.h:614
ValueOnIter endValueOn()
Definition: LeafNodeBool.h:695
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1907
void setValueMask(const NodeMaskType &mask)
Definition: LeafNodeBool.h:734
Definition: version.h:104
void setValueMask(Index n, bool on)
Definition: LeafNodeBool.h:739
ValueOnIter beginValueOn()
Definition: LeafNodeBool.h:685
const LeafNode * probeConstLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:587
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:589
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:455
void unsetItem(Index pos, const ValueT &val) const
Definition: LeafNodeBool.h:666
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:557
Index memUsage() const
Definition: LeafNodeBool.h:111
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafNode.h:250
ChildIter< MaskOffIter, LeafNode > ChildOffIter
Definition: LeafNodeBool.h:678
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNodeBool.h:570
static Index size()
Definition: LeafNodeBool.h:112
NodeMaskType & getValueMask()
Definition: LeafNodeBool.h:733
BaseT::NonConstValueType NonConstValueT
Definition: LeafNodeBool.h:650
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNodeBool.h:294
bool isChildMaskOff(Index) const
Definition: LeafNodeBool.h:736
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Index64 onLeafVoxelCount() const
Definition: LeafNodeBool.h:180
ValueType * mData
Definition: LeafNode.h:327
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: LeafNode.h:1302
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNodeBool.h:744
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:391
Index64 offLeafVoxelCount() const
Definition: LeafNodeBool.h:181
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNodeBool.h:337
Index32 Index
Definition: Types.h:59
void setValueMaskOn(Index n)
Definition: LeafNodeBool.h:740
~LeafNode()
Destructor.
Definition: LeafNode.h:1197
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:461
const Buffer & buffer() const
Definition: LeafNodeBool.h:248
const bool & operator[](Index i) const
Definition: LeafNodeBool.h:102
static Index log2dim()
Return log2 of the size of the buffer storage.
Definition: LeafNodeBool.h:164
ChildOffIter beginChildOff()
Definition: LeafNodeBool.h:710
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNodeBool.h:247
static void getNodeLog2Dims(std::vector< Index > &dims)
Definition: LeafNodeBool.h:170
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:309
ChildOnCIter cendChildOn() const
Definition: LeafNodeBool.h:715
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1328
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1204
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value. ...
Definition: LeafNodeBool.h:284
OffIterator beginOff() const
Definition: NodeMasks.h:351
bool isChildMaskOn(Index) const
Definition: LeafNodeBool.h:735
Buffer(const NodeMaskType &other)
Definition: LeafNodeBool.h:89
static const bool sOn
Definition: LeafNodeBool.h:766
Buffer(bool on)
Definition: LeafNodeBool.h:88
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNodeBool.h:655
Definition: NodeMasks.h:236
Definition: Exceptions.h:39
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:2026
static Index dim()
Return the number of voxels in each dimension.
Definition: LeafNodeBool.h:166
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNodeBool.h:450
const NodeMaskType & getValueMask() const
Definition: LeafNodeBool.h:732
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1252
static Index64 onTileCount()
Definition: LeafNodeBool.h:182
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:415
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
bool probeValueAndCache(const Coord &xyz, bool &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val...
Definition: LeafNodeBool.h:442
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1735
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:560
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1477
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:394
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1823
Index64 offVoxelCount() const
Return the number of inactive voxels.
Definition: LeafNodeBool.h:179
bool isValueMaskOn() const
Definition: LeafNodeBool.h:729
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: LeafNodeBool.h:763
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1865
static Index32 nonLeafCount()
Definition: LeafNodeBool.h:174
void setValueOnly(Index offset, bool val)
Set the value of the voxel at the given offset but don't change its active state. ...
Definition: LeafNodeBool.h:289
ValueOffCIter beginValueOff() const
Definition: LeafNodeBool.h:687
NodeMaskType mValueMask
Bitmask that determines which voxels are active.
Definition: LeafNodeBool.h:759
ValueAllCIter cbeginValueAll() const
Definition: LeafNodeBool.h:689
Definition: NodeMasks.h:267
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNodeBool.h:198
boost::shared_ptr< LeafNodeType > Ptr
Definition: LeafNodeBool.h:58
void fill(bool val)
Definition: LeafNodeBool.h:92
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition: LeafNode.h:1409
ValueAllIter beginValueAll()
Definition: LeafNodeBool.h:691
bool operator==(const Buffer &other) const
Definition: LeafNodeBool.h:104
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
const bool & getItem(Index pos) const
Definition: LeafNodeBool.h:619
bool isValueMaskOff() const
Definition: LeafNodeBool.h:731
ChildOffCIter beginChildOff() const
Definition: LeafNodeBool.h:709
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:2096
OPENVDB_API const void * getGridBackgroundValuePtr(std::ios_base &)
Return a pointer to the background value of the grid currently being read from or written to the give...
void setItem(Index pos, bool value) const
Definition: LeafNodeBool.h:623
ChildIter< MaskOnIter, const LeafNode > ChildOnCIter
Definition: LeafNodeBool.h:677
ValueAllCIter endValueAll() const
Definition: LeafNodeBool.h:700
static Index getValueLevel(const Coord &)
Return the level (0) at which leaf node values reside.
Definition: LeafNodeBool.h:279
ChildAllIter beginChildAll()
Definition: LeafNodeBool.h:713
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1268
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNodeBool.h:334
static const Index SIZE
Definition: LeafNode.h:79
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNodeBool.h:218
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:410
static Index size()
Definition: LeafNodeBool.h:167
void setValue(Index i, bool val)
Definition: LeafNodeBool.h:107
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNodeBool.h:332
void setValueMaskOff(Index n)
Definition: LeafNodeBool.h:741
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:405
Definition: NodeMasks.h:205
bool isValueMaskOn(Index n) const
Definition: LeafNodeBool.h:728
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNodeBool.h:433
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1658
const bool & getValue() const
Definition: LeafNodeBool.h:620
ChildOnCIter endChildOn() const
Definition: LeafNodeBool.h:716
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:2051
LeafNode()
Default constructor.
Definition: LeafNode.h:1111
void setValueOffAndCache(const Coord &xyz, bool value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNodeBool.h:407
ValueAllIter endValueAll()
Definition: LeafNodeBool.h:701
LeafNode specialization for values of type bool that stores both the active states and the values of ...
Definition: LeafNodeBool.h:54
DenseIter< LeafNode, bool > ChildAllIter
Definition: LeafNodeBool.h:680
Definition: PointIndexGrid.h:68
Index64 onVoxelCount() const
Return the number of active voxels.
Definition: LeafNodeBool.h:177
ValueOffCIter cendValueOff() const
Definition: LeafNodeBool.h:696
OnIterator beginOn() const
Definition: NodeMasks.h:349
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNodeBool.h:629
static Index32 leafCount()
Definition: LeafNodeBool.h:173
ChildOnCIter beginChildOn() const
Definition: LeafNodeBool.h:706
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNodeBool.h:591
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: LeafNode.h:1310
static Index numValues()
Definition: LeafNodeBool.h:168
static const Index LOG2DIM
Definition: LeafNode.h:74
ValueOffIter endValueOff()
Definition: LeafNodeBool.h:698
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:552
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1668
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
Buffer & operator=(const Buffer &b)
Definition: LeafNodeBool.h:93
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:557
const bool & getLastValue() const
Return a const reference to the last entry in the buffer.
Definition: LeafNodeBool.h:459
NodeMaskType::OnIterator MaskOnIter
Definition: LeafNodeBool.h:604
DenseIter()
Definition: LeafNodeBool.h:652
ChildAllCIter endChildAll() const
Definition: LeafNodeBool.h:722
DenseIteratorBase< MaskDenseIter, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNodeBool.h:649
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box...
Definition: LeafNode.h:1438
uint32_t Index32
Definition: Types.h:57
ChildIter()
Definition: LeafNodeBool.h:640
void voxelizeActiveTiles()
Definition: LeafNodeBool.h:476
ValueIter< MaskOnIter, LeafNode, const bool > ValueOnIter
Definition: LeafNodeBool.h:670
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:2072
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:670
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNodeBool.h:556
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
bool ValueType
Definition: LeafNodeBool.h:59
NodeMaskType::DenseIterator MaskDenseIter
Definition: LeafNodeBool.h:606
static Index64 offTileCount()
Definition: LeafNodeBool.h:183
Buffer mBuffer
Bitmask representing the values of voxels.
Definition: LeafNodeBool.h:761
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:314
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:569
bool isDense() const
Return true if this node only contains active voxels.
Definition: LeafNodeBool.h:188
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:2012
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNodeBool.h:329
const bool & getFirstValue() const
Return a const reference to the first entry in the buffer.
Definition: LeafNodeBool.h:455
static const bool sOff
Definition: LeafNodeBool.h:767
ValueIter< MaskOffIter, LeafNode, const bool > ValueOffIter
Definition: LeafNodeBool.h:672
bool operator!=(const Buffer &other) const
Definition: LeafNodeBool.h:105
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if both of the original voxels were active.
Definition: LeafNode.h:1831
void setValueOnlyAndCache(const Coord &xyz, bool val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNodeBool.h:402
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueOnCIter endValueOn() const
Definition: LeafNodeBool.h:694
void negate()
Definition: LeafNodeBool.h:470
void merge(const LeafNode &)
Definition: LeafNode.h:1770
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:715
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNodeBool.h:574
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1695
Buffer(const Buffer &other)
Definition: LeafNodeBool.h:90
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:1368
void modifyValue(const ModifyOp &op) const
Definition: LeafNodeBool.h:632
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1485