Go to the documentation of this file.
4 #ifndef OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
5 #define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
17 #include <type_traits>
29 template<Index,
typename>
struct SameLeafConfig;
36 template<
typename T, Index Log2Dim>
51 NUM_VALUES = 1 << 3 * Log2Dim,
52 NUM_VOXELS = NUM_VALUES,
58 template<
typename OtherValueType>
63 template<
typename OtherNodeType>
77 const ValueType& value = zeroVal<ValueType>(),
87 const ValueType& value = zeroVal<ValueType>(),
97 template<
typename OtherValueType>
101 template<
typename OtherValueType>
106 template<
typename OtherValueType>
148 bool isEmpty()
const {
return mValueMask.isOff(); }
150 bool isDense()
const {
return mValueMask.isOn(); }
152 bool isAllocated()
const {
return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
162 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
171 const Coord& origin()
const {
return mOrigin; }
186 std::string str()
const;
190 template<
typename OtherType, Index OtherLog2Dim>
206 template<
typename MaskIterT,
typename NodeT,
typename ValueT,
typename TagT>
211 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
218 ValueT&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
219 ValueT&
getValue()
const {
return this->parent().getValue(this->pos()); }
224 this->parent().setValueOnly(pos, value);
229 this->parent().setValueOnly(this->pos(), value);
233 template<
typename ModifyOp>
234 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
236 template<
typename ModifyOp>
237 void modifyValue(
const ModifyOp& op)
const { this->parent().modifyValue(this->pos(), op); }
241 template<
typename MaskIterT,
typename NodeT,
typename TagT>
243 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
250 template<
typename NodeT,
typename ValueT,
typename TagT>
252 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, void, ValueT>
262 value = this->parent().getValue(pos);
273 this->parent().setValueOnly(pos, value);
348 void readTopology(std::istream& is,
bool fromHalf =
false);
352 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
357 void readBuffers(std::istream& is,
bool fromHalf =
false);
362 void readBuffers(std::istream& is,
const CoordBBox& bbox,
bool fromHalf =
false);
366 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
391 void setActiveState(
const Coord& xyz,
bool on);
396 void setValueOnly(
const Coord& xyz,
const ValueType& val);
398 void setValueOnly(
Index offset,
const ValueType& val);
406 void setValueOff(
const Coord& xyz,
const ValueType& val);
408 void setValueOff(
Index offset,
const ValueType& val);
416 this->setValueOn(LeafNode::coordToOffset(xyz), val);
422 mBuffer.setValue(offset, val);
423 mValueMask.setOn(offset);
428 template<
typename ModifyOp>
431 mBuffer.loadValues();
432 if (!mBuffer.empty()) {
436 mValueMask.setOn(offset);
442 template<
typename ModifyOp>
445 this->modifyValue(this->coordToOffset(xyz), op);
449 template<
typename ModifyOp>
452 mBuffer.loadValues();
453 if (!mBuffer.empty()) {
454 const Index offset = this->coordToOffset(xyz);
455 bool state = mValueMask.isOn(offset);
459 mValueMask.set(offset, state);
480 void fill(
const CoordBBox& bbox,
const ValueType&,
bool active =
true);
484 this->fill(bbox, value, active);
488 void fill(
const ValueType& value);
490 void fill(
const ValueType& value,
bool active);
503 template<
typename DenseT>
522 template<
typename DenseT>
524 const ValueType& background,
const ValueType& tolerance);
528 template<
typename AccessorT>
531 return this->getValue(xyz);
536 template<
typename AccessorT>
541 template<
typename AccessorT>
544 this->setValueOn(xyz, val);
550 template<
typename AccessorT>
553 this->setValueOnly(xyz, val);
559 template<
typename ModifyOp,
typename AccessorT>
562 this->modifyValue(xyz, op);
567 template<
typename ModifyOp,
typename AccessorT>
570 this->modifyValueAndActiveState(xyz, op);
575 template<
typename AccessorT>
578 this->setValueOff(xyz, value);
584 template<
typename AccessorT>
587 this->setActiveState(xyz, on);
593 template<
typename AccessorT>
596 return this->probeValue(xyz, val);
602 template<
typename AccessorT>
605 const Index offset = this->coordToOffset(xyz);
606 state = mValueMask.isOn(offset);
608 return mBuffer[offset];
613 template<
typename AccessorT>
625 void resetBackground(
const ValueType& oldBackground,
const ValueType& newBackground);
633 template<MergePolicy Policy>
void merge(
const LeafNode&);
634 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
635 template<MergePolicy Policy>
636 void merge(
const LeafNode& other,
const ValueType& ,
const ValueType& );
644 template<
typename OtherType>
658 template<
typename OtherType>
672 template<
typename OtherType>
675 template<
typename CombineOp>
677 template<
typename CombineOp>
678 void combine(
const ValueType& value,
bool valueIsActive, CombineOp& op);
680 template<
typename CombineOp,
typename OtherType >
681 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
682 template<
typename CombineOp,
typename OtherNodeT >
683 void combine2(
const ValueType&,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
684 template<
typename CombineOp,
typename OtherNodeT >
685 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
692 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
694 template<
typename VisitorOp>
void visit(VisitorOp&);
695 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
697 template<
typename OtherLeafNodeType,
typename VisitorOp>
698 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
699 template<
typename OtherLeafNodeType,
typename VisitorOp>
700 void visit2Node(OtherLeafNodeType& other, VisitorOp&)
const;
701 template<
typename IterT,
typename VisitorOp>
702 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false);
703 template<
typename IterT,
typename VisitorOp>
704 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false)
const;
707 void prune(
const ValueType& = zeroVal<ValueType>()) {}
710 template<
typename AccessorT>
712 template<
typename NodeT>
714 template<
typename NodeT>
716 template<
typename NodeT>
718 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
722 void addTile(
Index level,
const Coord&,
const ValueType&,
bool);
723 void addTile(
Index offset,
const ValueType&,
bool);
724 template<
typename AccessorT>
725 void addTileAndCache(
Index,
const Coord&,
const ValueType&,
bool, AccessorT&);
730 template<
typename AccessorT>
732 template<
typename NodeT,
typename AccessorT>
736 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
737 return reinterpret_cast<NodeT*
>(
this);
741 template<
typename AccessorT>
745 const LeafNode* probeConstLeaf(
const Coord&)
const {
return this; }
747 template<
typename AccessorT>
749 template<
typename AccessorT>
752 template<
typename NodeT,
typename AccessorT>
756 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
757 return reinterpret_cast<const NodeT*
>(
this);
771 bool isConstant(ValueType& firstValue,
bool& state,
772 const ValueType& tolerance = zeroVal<ValueType>())
const;
785 bool isConstant(ValueType& minValue, ValueType& maxValue,
786 bool& state,
const ValueType& tolerance = zeroVal<ValueType>())
const;
803 ValueType medianAll(ValueType *tmp =
nullptr)
const;
819 Index medianOn(ValueType &value, ValueType *tmp =
nullptr)
const;
835 Index medianOff(ValueType &value, ValueType *tmp =
nullptr)
const;
841 friend class ::TestLeaf;
842 template<
typename>
friend class ::TestLeafIO;
879 inline void skipCompressedValues(
bool seekable, std::istream&,
bool fromHalf);
884 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
885 static inline void doVisit(NodeT&, VisitorOp&);
887 template<
typename NodeT,
typename OtherNodeT,
typename VisitorOp,
888 typename ChildAllIterT,
typename OtherChildAllIterT>
889 static inline void doVisit2Node(NodeT&
self, OtherNodeT& other, VisitorOp&);
891 template<
typename NodeT,
typename VisitorOp,
892 typename ChildAllIterT,
typename OtherChildAllIterT>
893 static inline void doVisit2(NodeT&
self, OtherChildAllIterT&, VisitorOp&,
bool otherIsLHS);
899 NodeMaskType mValueMask;
909 template<Index Dim1,
typename NodeT2>
914 template<Index Dim1,
typename T2>
922 template<
typename T, Index Log2Dim>
931 template<
typename T, Index Log2Dim>
936 mOrigin(xyz & (~(DIM - 1)))
941 template<
typename T, Index Log2Dim>
946 mOrigin(xyz & (~(DIM - 1)))
951 template<
typename T, Index Log2Dim>
954 mBuffer(other.mBuffer),
955 mValueMask(other.valueMask()),
956 mOrigin(other.mOrigin)
962 template<
typename T, Index Log2Dim>
963 template<
typename OtherValueType>
966 mValueMask(other.valueMask()),
967 mOrigin(other.mOrigin)
971 static inline ValueType convertValue(
const OtherValueType& val) {
return ValueType(val); }
975 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
980 template<
typename T, Index Log2Dim>
981 template<
typename OtherValueType>
986 mValueMask(other.valueMask()),
987 mOrigin(other.mOrigin)
992 template<
typename T, Index Log2Dim>
993 template<
typename OtherValueType>
997 mValueMask(other.valueMask()),
998 mOrigin(other.mOrigin)
1001 mBuffer[i] = (mValueMask.
isOn(i) ? onValue : offValue);
1006 template<
typename T, Index Log2Dim>
1013 template<
typename T, Index Log2Dim>
1017 std::ostringstream ostr;
1018 ostr <<
"LeafNode @" << mOrigin <<
": " << mBuffer;
1026 template<
typename T, Index Log2Dim>
1030 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1031 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1032 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1033 + (xyz[2] & (DIM-1u));
1036 template<
typename T, Index Log2Dim>
1040 assert(n<(1<< 3*Log2Dim));
1042 xyz.
setX(n >> 2*Log2Dim);
1043 n &= ((1<<2*Log2Dim)-1);
1044 xyz.
setY(n >> Log2Dim);
1045 xyz.
setZ(n & ((1<<Log2Dim)-1));
1050 template<
typename T, Index Log2Dim>
1054 return (this->offsetToLocalCoord(n) + this->origin());
1061 template<
typename ValueT, Index Log2Dim>
1062 inline const ValueT&
1068 template<
typename ValueT, Index Log2Dim>
1069 inline const ValueT&
1072 assert(offset < SIZE);
1073 return mBuffer[offset];
1077 template<
typename T, Index Log2Dim>
1084 template<
typename T, Index Log2Dim>
1088 assert(offset < SIZE);
1089 val = mBuffer[offset];
1090 return mValueMask.isOn(offset);
1094 template<
typename T, Index Log2Dim>
1101 template<
typename T, Index Log2Dim>
1105 assert(offset < SIZE);
1106 mBuffer.setValue(offset, val);
1107 mValueMask.setOff(offset);
1111 template<
typename T, Index Log2Dim>
1115 mValueMask.set(this->coordToOffset(xyz), on);
1119 template<
typename T, Index Log2Dim>
1126 template<
typename T, Index Log2Dim>
1130 assert(offset<SIZE); mBuffer.setValue(offset, val);
1137 template<
typename T, Index Log2Dim>
1141 CoordBBox nodeBBox = this->getNodeBoundingBox();
1144 this->fill(background,
false);
1145 }
else if (clipBBox.
isInside(nodeBBox)) {
1157 int &x = xyz.
x(), &y = xyz.
y(), &z = xyz.
z();
1158 for (x = nodeBBox.
min().
x(); x <= nodeBBox.
max().
x(); ++x) {
1159 for (y = nodeBBox.
min().
y(); y <= nodeBBox.
max().
y(); ++y) {
1160 for (z = nodeBBox.
min().
z(); z <= nodeBBox.
max().
z(); ++z) {
1161 mask.
setOn(
static_cast<Index32>(this->coordToOffset(xyz)));
1169 this->setValueOff(maskIter.pos(), background);
1177 template<
typename T, Index Log2Dim>
1181 if (!this->allocate())
return;
1183 auto clippedBBox = this->getNodeBoundingBox();
1184 clippedBBox.intersect(bbox);
1185 if (!clippedBBox)
return;
1187 for (
Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1188 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1189 for (
Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1190 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1191 for (
Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1192 const Index offset = offsetXY + (z & (DIM-1u));
1193 mBuffer[offset] = value;
1194 mValueMask.set(offset, active);
1200 template<
typename T, Index Log2Dim>
1204 mBuffer.fill(value);
1207 template<
typename T, Index Log2Dim>
1211 mBuffer.fill(value);
1212 mValueMask.set(active);
1219 template<
typename T, Index Log2Dim>
1220 template<
typename DenseT>
1224 mBuffer.loadValues();
1226 using DenseValueType =
typename DenseT::ValueType;
1228 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1229 const Coord&
min = dense.bbox().min();
1230 DenseValueType* t0 = dense.data() + zStride * (bbox.
min()[2] -
min[2]);
1231 const T* s0 = &mBuffer[bbox.
min()[2] & (DIM-1u)];
1232 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1233 DenseValueType* t1 = t0 + xStride * (x -
min[0]);
1234 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1235 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1236 DenseValueType* t2 = t1 + yStride * (y -
min[1]);
1237 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1238 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2] + 1; z < ez; ++z, t2 += zStride) {
1239 *t2 = DenseValueType(*s2++);
1246 template<
typename T, Index Log2Dim>
1247 template<
typename DenseT>
1252 if (!this->allocate())
return;
1254 using DenseValueType =
typename DenseT::ValueType;
1256 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1257 const Coord&
min = dense.bbox().min();
1259 const DenseValueType* s0 = dense.data() + zStride * (bbox.
min()[2] -
min[2]);
1260 const Int32 n0 = bbox.
min()[2] & (DIM-1u);
1261 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0]+1; x < ex; ++x) {
1262 const DenseValueType* s1 = s0 + xStride * (x -
min[0]);
1263 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1264 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1]+1; y < ey; ++y) {
1265 const DenseValueType* s2 = s1 + yStride * (y -
min[1]);
1266 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1267 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1269 mValueMask.setOff(n2);
1270 mBuffer[n2] = background;
1272 mValueMask.setOn(n2);
1284 template<
typename T, Index Log2Dim>
1288 mValueMask.load(is);
1292 template<
typename T, Index Log2Dim>
1296 mValueMask.save(os);
1304 template<
typename T, Index Log2Dim>
1310 io::readCompressedValues<ValueType, NodeMaskType>(
1311 is,
nullptr, SIZE, mValueMask, fromHalf);
1320 template<
typename T, Index Log2Dim>
1328 template<
typename T, Index Log2Dim>
1333 const bool seekable = meta && meta->seekable();
1335 std::streamoff maskpos = is.tellg();
1339 mValueMask.seek(is);
1342 mValueMask.load(is);
1345 int8_t numBuffers = 1;
1351 is.read(
reinterpret_cast<char*
>(&numBuffers),
sizeof(int8_t));
1354 CoordBBox nodeBBox = this->getNodeBoundingBox();
1357 skipCompressedValues(seekable, is, fromHalf);
1358 mValueMask.setOff();
1359 mBuffer.setOutOfCore(
false);
1366 const bool delayLoad = ((mappedFile.get() !=
nullptr) && clipBBox.
isInside(nodeBBox));
1369 mBuffer.setOutOfCore(
true);
1370 mBuffer.mFileInfo =
new typename Buffer::FileInfo;
1371 mBuffer.mFileInfo->meta = meta;
1372 mBuffer.mFileInfo->bufpos = is.tellg();
1373 mBuffer.mFileInfo->mapping = mappedFile;
1376 mBuffer.mFileInfo->maskpos = maskpos;
1378 skipCompressedValues(seekable, is, fromHalf);
1382 mBuffer.setOutOfCore(
false);
1385 T background = zeroVal<T>();
1387 background = *
static_cast<const T*
>(bgPtr);
1389 this->
clip(clipBBox, background);
1393 if (numBuffers > 1) {
1398 for (
int i = 1; i < numBuffers; ++i) {
1402 io::readData<T>(is, temp.
mData, SIZE, zipped);
1408 if (meta) meta->setLeaf(meta->leaf() + 1);
1412 template<
typename T, Index Log2Dim>
1417 mValueMask.save(os);
1419 mBuffer.loadValues();
1429 template<
typename T, Index Log2Dim>
1433 return mOrigin == other.mOrigin &&
1435 mBuffer == other.mBuffer;
1439 template<
typename T, Index Log2Dim>
1445 return sizeof(*this) + mBuffer.memUsage() -
sizeof(mBuffer);
1449 template<
typename T, Index Log2Dim>
1453 CoordBBox this_bbox = this->getNodeBoundingBox();
1454 if (bbox.
isInside(this_bbox))
return;
1458 for(; iter; ++iter) this_bbox.
expand(this->offsetToLocalCoord(iter.pos()));
1466 template<
typename T, Index Log2Dim>
1467 template<
typename OtherType, Index OtherLog2Dim>
1472 return (Log2Dim == OtherLog2Dim && mValueMask == other->
getValueMask());
1475 template<
typename T, Index Log2Dim>
1481 if (!mValueMask.isConstant(state))
return false;
1482 firstValue = mBuffer[0];
1483 for (
Index i = 1; i < SIZE; ++i) {
1489 template<
typename T, Index Log2Dim>
1496 if (!mValueMask.isConstant(state))
return false;
1497 minValue = maxValue = mBuffer[0];
1498 for (
Index i = 1; i < SIZE; ++i) {
1499 const T& v = mBuffer[i];
1501 if ((maxValue - v) > tolerance)
return false;
1503 }
else if (v > maxValue) {
1504 if ((v - minValue) > tolerance)
return false;
1511 template<
typename T, Index Log2Dim>
1515 std::unique_ptr<T[]> data(
nullptr);
1516 if (tmp ==
nullptr) {
1517 data.reset(
new T[NUM_VALUES]);
1520 if (tmp != mBuffer.data()) {
1521 const T* src = mBuffer.data();
1522 for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
1524 static const size_t midpoint = (NUM_VALUES - 1) >> 1;
1525 std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES);
1526 return tmp[midpoint];
1529 template<
typename T, Index Log2Dim>
1533 const Index count = mValueMask.countOn();
1534 if (count == NUM_VALUES) {
1535 value = this->medianAll(tmp);
1537 }
else if (count == 0) {
1540 std::unique_ptr<T[]> data(
nullptr);
1541 if (tmp ==
nullptr) {
1542 data.reset(
new T[count]);
1545 for (
auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
1546 T *begin = tmp - count;
1547 const size_t midpoint = (count - 1) >> 1;
1548 std::nth_element(begin, begin + midpoint, tmp);
1549 value = begin[midpoint];
1553 template<
typename T, Index Log2Dim>
1557 const Index count = mValueMask.countOff();
1558 if (count == NUM_VALUES) {
1559 value = this->medianAll(tmp);
1561 }
else if (count == 0) {
1564 std::unique_ptr<T[]> data(
nullptr);
1565 if (tmp ==
nullptr) {
1566 data.reset(
new T[count]);
1569 for (
auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
1570 T *begin = tmp - count;
1571 const size_t midpoint = (count - 1) >> 1;
1572 std::nth_element(begin, begin + midpoint, tmp);
1573 value = begin[midpoint];
1580 template<
typename T, Index Log2Dim>
1584 this->addTile(this->coordToOffset(xyz), val, active);
1587 template<
typename T, Index Log2Dim>
1591 assert(offset < SIZE);
1592 setValueOnly(offset, val);
1593 setActiveState(offset, active);
1596 template<
typename T, Index Log2Dim>
1597 template<
typename AccessorT>
1600 const ValueType& val,
bool active, AccessorT&)
1602 this->addTile(level, xyz, val, active);
1609 template<
typename T, Index Log2Dim>
1614 if (!this->allocate())
return;
1618 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1621 inactiveValue = newBackground;
1629 template<
typename T, Index Log2Dim>
1630 template<MergePolicy Policy>
1634 if (!this->allocate())
return;
1639 for (; iter; ++iter) {
1641 if (mValueMask.isOff(n)) {
1642 mBuffer[n] = other.mBuffer[n];
1643 mValueMask.setOn(n);
1649 template<
typename T, Index Log2Dim>
1650 template<MergePolicy Policy>
1655 this->
template merge<Policy>(other);
1658 template<
typename T, Index Log2Dim>
1659 template<MergePolicy Policy>
1663 if (!this->allocate())
return;
1667 if (!tileActive)
return;
1670 const Index n = iter.pos();
1671 mBuffer[n] = tileValue;
1672 mValueMask.setOn(n);
1678 template<
typename T, Index Log2Dim>
1679 template<
typename OtherType>
1686 template<
typename T, Index Log2Dim>
1687 template<
typename OtherType>
1695 template<
typename T, Index Log2Dim>
1696 template<
typename OtherType>
1704 template<
typename T, Index Log2Dim>
1708 if (!this->allocate())
return;
1710 for (
Index i = 0; i < SIZE; ++i) {
1711 mBuffer[i] = -mBuffer[i];
1719 template<
typename T, Index Log2Dim>
1720 template<
typename CombineOp>
1724 if (!this->allocate())
return;
1727 for (
Index i = 0; i < SIZE; ++i) {
1729 .setAIsActive(mValueMask.isOn(i))
1730 .setBRef(other.mBuffer[i])
1732 .setResultRef(mBuffer[i]));
1738 template<
typename T, Index Log2Dim>
1739 template<
typename CombineOp>
1743 if (!this->allocate())
return;
1746 args.
setBRef(value).setBIsActive(valueIsActive);
1747 for (
Index i = 0; i < SIZE; ++i) {
1749 .setAIsActive(mValueMask.isOn(i))
1750 .setResultRef(mBuffer[i]));
1759 template<
typename T, Index Log2Dim>
1760 template<
typename CombineOp,
typename OtherType>
1763 bool valueIsActive, CombineOp& op)
1765 if (!this->allocate())
return;
1768 args.
setBRef(value).setBIsActive(valueIsActive);
1769 for (
Index i = 0; i < SIZE; ++i) {
1770 op(args.
setARef(other.mBuffer[i])
1772 .setResultRef(mBuffer[i]));
1778 template<
typename T, Index Log2Dim>
1779 template<
typename CombineOp,
typename OtherNodeT>
1782 bool valueIsActive, CombineOp& op)
1784 if (!this->allocate())
return;
1787 args.
setARef(value).setAIsActive(valueIsActive);
1788 for (
Index i = 0; i < SIZE; ++i) {
1789 op(args.
setBRef(other.mBuffer[i])
1790 .setBIsActive(other.valueMask().isOn(i))
1791 .setResultRef(mBuffer[i]));
1797 template<
typename T, Index Log2Dim>
1798 template<
typename CombineOp,
typename OtherNodeT>
1802 if (!this->allocate())
return;
1805 for (
Index i = 0; i < SIZE; ++i) {
1806 mValueMask.set(i, b0.
valueMask().
isOn(i) || b1.valueMask().isOn(i));
1807 op(args.
setARef(b0.mBuffer[i])
1809 .setBRef(b1.mBuffer[i])
1810 .setBIsActive(b1.valueMask().isOn(i))
1811 .setResultRef(mBuffer[i]));
1820 template<
typename T, Index Log2Dim>
1821 template<
typename BBoxOp>
1825 if (op.template descent<LEVEL>()) {
1830 op.template operator()<LEVEL>(this->getNodeBoundingBox());
1835 template<
typename T, Index Log2Dim>
1836 template<
typename VisitorOp>
1840 doVisit<LeafNode, VisitorOp, ChildAllIter>(*
this, op);
1844 template<
typename T, Index Log2Dim>
1845 template<
typename VisitorOp>
1849 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*
this, op);
1853 template<
typename T, Index Log2Dim>
1854 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
1858 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
1867 template<
typename T, Index Log2Dim>
1868 template<
typename OtherLeafNodeType,
typename VisitorOp>
1873 typename OtherLeafNodeType::ChildAllIter>(*
this, other, op);
1877 template<
typename T, Index Log2Dim>
1878 template<
typename OtherLeafNodeType,
typename VisitorOp>
1883 typename OtherLeafNodeType::ChildAllCIter>(*
this, other, op);
1887 template<
typename T, Index Log2Dim>
1890 typename OtherNodeT,
1892 typename ChildAllIterT,
1893 typename OtherChildAllIterT>
1898 static_assert(OtherNodeT::SIZE == NodeT::SIZE,
1899 "can't visit nodes of different sizes simultaneously");
1900 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
1901 "can't visit nodes at different tree levels simultaneously");
1903 ChildAllIterT iter =
self.beginChildAll();
1904 OtherChildAllIterT otherIter = other.beginChildAll();
1906 for ( ; iter && otherIter; ++iter, ++otherIter) {
1907 op(iter, otherIter);
1915 template<
typename T, Index Log2Dim>
1916 template<
typename IterT,
typename VisitorOp>
1920 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(
1921 *
this, otherIter, op, otherIsLHS);
1925 template<
typename T, Index Log2Dim>
1926 template<
typename IterT,
typename VisitorOp>
1930 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(
1931 *
this, otherIter, op, otherIsLHS);
1935 template<
typename T, Index Log2Dim>
1939 typename ChildAllIterT,
1940 typename OtherChildAllIterT>
1943 VisitorOp& op,
bool otherIsLHS)
1945 if (!otherIter)
return;
1948 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
1949 op(otherIter, iter);
1952 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
1953 op(iter, otherIter);
1962 template<
typename T, Index Log2Dim>
1963 inline std::ostream&
1966 for (
Index32 i = 0, N = buf.
size(); i < N; ++i) os << buf.
mData[i] <<
", ";
1984 #endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition: LeafNode.h:388
ChildAllCIter endChildAll() const
Definition: LeafNode.h:330
Index64 onLeafVoxelCount() const
Definition: LeafNode.h:143
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:1113
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNode.h:129
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:371
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
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:1121
T ValueType
Definition: LeafNode.h:41
Coord & setY(Int32 y)
Definition: Coord.h:81
const Buffer & buffer() const
Definition: LeafNode.h:339
ChildOffCIter beginChildOff() const
Definition: LeafNode.h:317
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNode.h:631
ValueOnCIter endValueOn() const
Definition: LeafNode.h:302
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:121
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:482
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:986
ValueOnCIter cendValueOn() const
Definition: LeafNode.h:301
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition: LeafNode.h:119
void unsetItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:271
void nodeCount(std::vector< Index32 > &) const
no-op
Definition: LeafNode.h:133
~LeafNode()
Destructor.
Definition: LeafNode.h:1008
NodeT * probeNode(const Coord &)
Definition: LeafNode.h:715
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:244
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: LeafNode.h:200
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNode.h:474
Definition: Compression.h:292
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNode.h:169
void skipCompressedValues(bool seekable, std::istream &, bool fromHalf)
Definition: LeafNode.h:1306
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:429
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:465
SharedPtr< MappedFile > Ptr
Definition: io.h:136
Int32 ValueType
Definition: Coord.h:33
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val.
Definition: LeafNode.h:594
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:750
size_t streamingSize(bool toHalf=false) const
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
void addLeaf(LeafNode *)
Definition: LeafNode.h:709
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:1045
Index32 Index
Definition: Types.h:31
Definition: LeafNode.h:204
ChildOffCIter cbeginChildOff() const
Definition: LeafNode.h:316
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i....
Definition: LeafNode.h:603
bool isChildMaskOff() const
Definition: LeafNode.h:873
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNode.h:585
ChildOnCIter beginChildOn() const
Definition: LeafNode.h:314
Definition: LeafNode.h:912
void reset()
Definition: Coord.h:327
ChildAllIter beginChildAll()
Definition: LeafNode.h:321
void getNodes(ArrayT &) const
Definition: LeafNode.h:718
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1531
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:115
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:313
Coord & setZ(Int32 z)
Definition: Coord.h:82
ChildOnCIter endChildOn() const
Definition: LeafNode.h:324
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNode.h:260
LeafNode * probeLeaf(const Coord &)
Definition: LeafNode.h:740
static Index64 offTileCount()
Definition: LeafNode.h:146
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:30
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:733
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNode.h:576
NodeMaskType & getValueMask()
Definition: LeafNode.h:868
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1722
ValueOffIter beginValueOff()
Definition: LeafNode.h:296
void setValue(const ValueT &value) const
Definition: LeafNode.h:227
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition: LeafNode.h:117
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1431
@ MERGE_ACTIVE_STATES_AND_NODES
Definition: Types.h:872
Int32 y() const
Definition: Coord.h:132
bool isChildMaskOff(Index) const
Definition: LeafNode.h:872
Definition: LeafNode.h:22
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:450
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:90
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
ChildOffCIter endChildOff() const
Definition: LeafNode.h:327
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1079
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition: Coord.h:458
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:1179
bool isValueMaskOff(Index n) const
Definition: LeafNode.h:865
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1294
Definition: NodeMasks.h:209
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition: LeafNode.h:421
ValueIter()
Definition: LeafNode.h:215
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1856
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Definition: LeafNode.h:174
ValueOffCIter endValueOff() const
Definition: LeafNode.h:305
ValueAllCIter cendValueAll() const
Definition: LeafNode.h:307
ChildOnCIter cbeginChildOn() const
Definition: LeafNode.h:313
uint64_t Index64
Definition: Types.h:30
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition: LeafNode.h:142
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNode.h:471
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:1469
Int32 x() const
Definition: Coord.h:131
ChildAllCIter cbeginChildAll() const
Definition: LeafNode.h:319
LeafNode & operator=(const LeafNode &)=default
Deep assignment operator.
OnIterator beginOn() const
Definition: NodeMasks.h:352
ValueAllCIter endValueAll() const
Definition: LeafNode.h:308
Definition: LeafNode.h:212
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNode.h:255
ValueT & getItem(Index pos) const
Definition: LeafNode.h:218
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition: LeafNode.h:64
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1052
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:867
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:179
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:291
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:246
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
void visit(VisitorOp &)
Definition: LeafNode.h:1838
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1477
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition: LeafNode.h:1038
bool isValueMaskOn(Index n) const
Definition: LeafNode.h:863
bool isValueMaskOff() const
Definition: LeafNode.h:866
Definition: NodeMasks.h:240
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value.
Definition: LeafNode.h:393
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:731
void modifyValue(const ModifyOp &op) const
Definition: LeafNode.h:237
void setValueMask(const NodeMaskType &mask)
Definition: LeafNode.h:870
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:1047
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:150
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition: LeafNode.h:140
ChildOffIter beginChildOff()
Definition: LeafNode.h:318
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 setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:419
uint32_t Index32
Definition: Types.h:29
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1063
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:216
void addLeafAndCache(LeafNode *, AccessorT &)
Definition: LeafNode.h:711
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNode.h:125
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNode.h:403
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:140
OffIterator beginOff() const
Definition: NodeMasks.h:354
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNode.h:338
int32_t Int32
Definition: Types.h:33
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNode.h:568
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNode.h:234
static const Index SIZE
Definition: LeafNode.h:53
const NodeMaskType & valueMask() const
Definition: LeafNode.h:869
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition: LeafNode.h:619
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:502
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1028
@ MERGE_NODES
Definition: Types.h:871
ValueOnIter beginValueOn()
Definition: LeafNode.h:293
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1918
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:984
bool isValueMaskOn() const
Definition: LeafNode.h:864
const LeafNode * probeLeaf(const Coord &) const
Definition: LeafNode.h:751
Definition: LeafNode.h:203
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1611
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,...
Definition: LeafNode.h:1698
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:308
ValueType * mData
Definition: LeafBuffer.h:148
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1762
Index64 offLeafVoxelCount() const
Definition: LeafNode.h:144
const NodeT * probeConstNode(const Coord &) const
Definition: LeafNode.h:717
ValueOffCIter cendValueOff() const
Definition: LeafNode.h:304
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:645
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1015
friend class LeafNode
Definition: LeafNode.h:846
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:411
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1599
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
Int32 z() const
Definition: Coord.h:133
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition: LeafNode.h:621
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNode.h:542
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:123
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:469
bool resultIsActive() const
Definition: Types.h:995
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition: version.h:187
ValueAllIter beginValueAll()
Definition: LeafNode.h:299
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: LeafNode.h:560
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:415
ValueOffCIter beginValueOff() const
Definition: LeafNode.h:295
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1451
DenseIter()
Definition: LeafNode.h:257
Definition: LeafNode.h:203
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1139
typename NodeMaskType::OffIterator MaskOffIterator
Definition: LeafNode.h:199
ValueAllIter endValueAll()
Definition: LeafNode.h:309
static Index32 childCount()
Return the child count for this node, which is zero.
Definition: LeafNode.h:137
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNode.h:882
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:38
bool isChildMaskOn(Index) const
Definition: LeafNode.h:871
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1555
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition: LeafNode.h:166
typename NodeMaskType::OnIterator MaskOnIterator
Definition: LeafNode.h:198
void getOrigin(Coord &origin) const
Definition: LeafNode.h:173
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:932
Definition: LeafNode.h:203
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:529
void setValueMaskOn(Index n)
Definition: LeafNode.h:876
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,...
Definition: LeafNode.h:1689
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Definition: LeafNode.h:742
ChildOffIter endChildOff()
Definition: LeafNode.h:328
ValueT & getValue() const
Definition: LeafNode.h:219
Coord & setX(Int32 x)
Definition: Coord.h:80
ChildAllIter endChildAll()
Definition: LeafNode.h:331
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNode.h:614
Index32 pos() const
Definition: NodeMasks.h:200
Definition: LeafNode.h:253
ValueAllCIter beginValueAll() const
Definition: LeafNode.h:298
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:1681
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1322
const Coord & max() const
Definition: Coord.h:322
ValueAllCIter cbeginValueAll() const
Definition: LeafNode.h:297
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:412
ChildAllCIter cendChildAll() const
Definition: LeafNode.h:329
const Coord & min() const
Definition: Coord.h:321
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:320
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:148
ValueOnCIter beginValueOn() const
Definition: LeafNode.h:292
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNode.h:551
void stealNodes(ArrayT &, const ValueType &, bool)
Definition: LeafNode.h:719
SharedPtr< LeafNode > Ptr
Definition: LeafNode.h:45
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1513
T BuildType
Definition: LeafNode.h:40
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNode.h:413
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNode.h:838
ChildOnCIter cendChildOn() const
Definition: LeafNode.h:323
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition: LeafNode.h:59
void negate()
Definition: LeafNode.h:1706
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:1249
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:418
void setValueMask(Index n, bool on)
Definition: LeafNode.h:875
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1942
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:1222
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:537
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:753
Definition: LeafNode.h:204
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNode.h:127
void setValueMaskOff(Index n)
Definition: LeafNode.h:877
void merge(const LeafNode &)
Definition: LeafNode.h:1632
void setItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:222
ValueOffIter endValueOff()
Definition: LeafNode.h:306
ValueType ValueType
Definition: Iterator.h:117
ChildOnIter beginChildOn()
Definition: LeafNode.h:315
Definition: Exceptions.h:13
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1870
NodeT * stealNode(const Coord &, const ValueType &, bool)
Definition: LeafNode.h:713
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:319
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1441
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1286
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Definition: LeafNode.h:748
std::shared_ptr< T > SharedPtr
Definition: Types.h:91
ValueOnIter endValueOn()
Definition: LeafNode.h:303
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1895
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNode.h:464
@ COMPRESS_ZIP
Definition: Compression.h:54
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:114
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active.
Definition: LeafNode.h:443
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1414
Buffer & buffer()
Definition: LeafNode.h:340
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNode.h:131
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:195
ChildOnIter endChildOn()
Definition: LeafNode.h:325
ValueOffCIter cbeginValueOff() const
Definition: LeafNode.h:294
ChildOffCIter cendChildOff() const
Definition: LeafNode.h:326
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNode.h:152
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1823
ChildIter()
Definition: LeafNode.h:245
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition: LeafNode.h:1964
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:444
Definition: NodeMasks.h:271
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNode.h:154
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:401
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: LeafNode.h:258
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
static Index64 onTileCount()
Definition: LeafNode.h:145
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1582
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:400
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNode.h:135
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNode.h:466