31 #ifndef OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED 32 #define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED 44 #include <type_traits> 56 template<Index,
typename>
struct SameLeafConfig;
63 template<
typename T, Index Log2Dim>
78 NUM_VALUES = 1 << 3 * Log2Dim,
79 NUM_VOXELS = NUM_VALUES,
85 template<
typename OtherValueType>
90 template<
typename OtherNodeType>
104 const ValueType& value = zeroVal<ValueType>(),
105 bool active =
false);
108 #if OPENVDB_ABI_VERSION_NUMBER >= 3 116 const ValueType& value = zeroVal<ValueType>(),
117 bool active =
false);
127 template<
typename OtherValueType>
131 template<
typename OtherValueType>
136 template<
typename OtherValueType>
174 bool isEmpty()
const {
return mValueMask.isOff(); }
176 bool isDense()
const {
return mValueMask.isOn(); }
178 #if OPENVDB_ABI_VERSION_NUMBER >= 3 179 bool isAllocated()
const {
return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
191 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
200 const Coord& origin()
const {
return mOrigin; }
215 std::string str()
const;
219 template<
typename OtherType, Index OtherLog2Dim>
235 template<
typename MaskIterT,
typename NodeT,
typename ValueT,
typename TagT>
240 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
247 ValueT&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
248 ValueT&
getValue()
const {
return this->parent().getValue(this->pos()); }
253 this->parent().setValueOnly(pos, value);
258 this->parent().setValueOnly(this->pos(), value);
262 template<
typename ModifyOp>
263 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
265 template<
typename ModifyOp>
266 void modifyValue(
const ModifyOp& op)
const { this->parent().modifyValue(this->pos(), op); }
270 template<
typename MaskIterT,
typename NodeT,
typename TagT>
272 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
279 template<
typename NodeT,
typename ValueT,
typename TagT>
281 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, void, ValueT>
291 value = this->parent().getValue(pos);
302 this->parent().setValueOnly(pos, value);
377 void readTopology(std::istream& is,
bool fromHalf =
false);
381 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
386 void readBuffers(std::istream& is,
bool fromHalf =
false);
391 void readBuffers(std::istream& is,
const CoordBBox& bbox,
bool fromHalf =
false);
395 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
397 size_t streamingSize(
bool toHalf =
false)
const;
403 const ValueType& getValue(
const Coord& xyz)
const;
405 const ValueType& getValue(
Index offset)
const;
410 bool probeValue(
const Coord& xyz, ValueType& val)
const;
414 bool probeValue(
Index offset, ValueType& val)
const;
420 void setActiveState(
const Coord& xyz,
bool on);
425 void setValueOnly(
const Coord& xyz,
const ValueType& val);
427 void setValueOnly(
Index offset,
const ValueType& val);
435 void setValueOff(
const Coord& xyz,
const ValueType& val);
437 void setValueOff(
Index offset,
const ValueType& val);
445 this->setValueOn(LeafNode::coordToOffset(xyz), val);
451 mBuffer.setValue(offset, val);
452 mValueMask.setOn(offset);
457 template<
typename ModifyOp>
462 mBuffer.setValue(offset, val);
463 mValueMask.setOn(offset);
467 template<
typename ModifyOp>
470 this->modifyValue(this->coordToOffset(xyz), op);
474 template<
typename ModifyOp>
477 const Index offset = this->coordToOffset(xyz);
478 bool state = mValueMask.isOn(offset);
481 mBuffer.setValue(offset, val);
482 mValueMask.set(offset, state);
502 void fill(
const CoordBBox& bbox,
const ValueType&,
bool active =
true);
506 this->fill(bbox, value, active);
510 void fill(
const ValueType& value);
512 void fill(
const ValueType& value,
bool active);
525 template<
typename DenseT>
544 template<
typename DenseT>
546 const ValueType& background,
const ValueType& tolerance);
550 template<
typename AccessorT>
553 return this->getValue(xyz);
558 template<
typename AccessorT>
563 template<
typename AccessorT>
566 this->setValueOn(xyz, val);
572 template<
typename AccessorT>
575 this->setValueOnly(xyz, val);
581 template<
typename ModifyOp,
typename AccessorT>
584 this->modifyValue(xyz, op);
589 template<
typename ModifyOp,
typename AccessorT>
592 this->modifyValueAndActiveState(xyz, op);
597 template<
typename AccessorT>
600 this->setValueOff(xyz, value);
606 template<
typename AccessorT>
609 this->setActiveState(xyz, on);
615 template<
typename AccessorT>
618 return this->probeValue(xyz, val);
624 template<
typename AccessorT>
627 const Index offset = this->coordToOffset(xyz);
628 state = mValueMask.isOn(offset);
630 return mBuffer[offset];
635 template<
typename AccessorT>
647 void resetBackground(
const ValueType& oldBackground,
const ValueType& newBackground);
655 template<MergePolicy Policy>
void merge(
const LeafNode&);
656 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
657 template<MergePolicy Policy>
658 void merge(
const LeafNode& other,
const ValueType& ,
const ValueType& );
666 template<
typename OtherType>
680 template<
typename OtherType>
694 template<
typename OtherType>
697 template<
typename CombineOp>
698 void combine(
const LeafNode& other, CombineOp& op);
699 template<
typename CombineOp>
700 void combine(
const ValueType& value,
bool valueIsActive, CombineOp& op);
702 template<
typename CombineOp,
typename OtherType >
703 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
704 template<
typename CombineOp,
typename OtherNodeT >
705 void combine2(
const ValueType&,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
706 template<
typename CombineOp,
typename OtherNodeT >
707 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
714 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
716 template<
typename VisitorOp>
void visit(VisitorOp&);
717 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
719 template<
typename OtherLeafNodeType,
typename VisitorOp>
720 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
721 template<
typename OtherLeafNodeType,
typename VisitorOp>
722 void visit2Node(OtherLeafNodeType& other, VisitorOp&)
const;
723 template<
typename IterT,
typename VisitorOp>
724 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false);
725 template<
typename IterT,
typename VisitorOp>
726 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false)
const;
729 void prune(
const ValueType& = zeroVal<ValueType>()) {}
732 template<
typename AccessorT>
734 template<
typename NodeT>
736 template<
typename NodeT>
738 template<
typename NodeT>
740 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
744 void addTile(
Index level,
const Coord&,
const ValueType&,
bool);
745 void addTile(
Index offset,
const ValueType&,
bool);
746 template<
typename AccessorT>
747 void addTileAndCache(
Index,
const Coord&,
const ValueType&,
bool, AccessorT&);
752 template<
typename AccessorT>
754 template<
typename NodeT,
typename AccessorT>
758 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
759 return reinterpret_cast<NodeT*>(
this);
763 template<
typename AccessorT>
767 const LeafNode* probeConstLeaf(
const Coord&)
const {
return this; }
769 template<
typename AccessorT>
771 template<
typename AccessorT>
774 template<
typename NodeT,
typename AccessorT>
778 if (!(std::is_same<NodeT, LeafNode>::value))
return nullptr;
779 return reinterpret_cast<const NodeT*>(
this);
793 bool isConstant(ValueType& firstValue,
bool& state,
794 const ValueType& tolerance = zeroVal<ValueType>())
const;
807 bool isConstant(ValueType& minValue, ValueType& maxValue,
808 bool& state,
const ValueType& tolerance = zeroVal<ValueType>())
const;
825 ValueType medianAll(ValueType *tmp =
nullptr)
const;
841 Index medianOn(ValueType &value, ValueType *tmp =
nullptr)
const;
857 Index medianOff(ValueType &value, ValueType *tmp =
nullptr)
const;
863 friend class ::TestLeaf;
864 template<
typename>
friend class ::TestLeafIO;
901 inline void skipCompressedValues(
bool seekable, std::istream&,
bool fromHalf);
906 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
907 static inline void doVisit(NodeT&, VisitorOp&);
909 template<
typename NodeT,
typename OtherNodeT,
typename VisitorOp,
910 typename ChildAllIterT,
typename OtherChildAllIterT>
911 static inline void doVisit2Node(NodeT&
self, OtherNodeT& other, VisitorOp&);
913 template<
typename NodeT,
typename VisitorOp,
914 typename ChildAllIterT,
typename OtherChildAllIterT>
915 static inline void doVisit2(NodeT&
self, OtherChildAllIterT&, VisitorOp&,
bool otherIsLHS);
921 NodeMaskType mValueMask;
931 template<Index Dim1,
typename NodeT2>
936 template<Index Dim1,
typename T2>
944 template<
typename T, Index Log2Dim>
953 template<
typename T, Index Log2Dim>
958 mOrigin(xyz & (~(DIM - 1)))
963 #if OPENVDB_ABI_VERSION_NUMBER >= 3 964 template<
typename T, Index Log2Dim>
969 mOrigin(xyz & (~(DIM - 1)))
975 template<
typename T, Index Log2Dim>
978 mBuffer(other.mBuffer),
979 mValueMask(other.valueMask()),
980 mOrigin(other.mOrigin)
986 template<
typename T, Index Log2Dim>
987 template<
typename OtherValueType>
990 mValueMask(other.valueMask()),
991 mOrigin(other.mOrigin)
995 static inline ValueType convertValue(
const OtherValueType& val) {
return ValueType(val); }
999 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
1004 template<
typename T, Index Log2Dim>
1005 template<
typename OtherValueType>
1009 mBuffer(background),
1010 mValueMask(other.valueMask()),
1011 mOrigin(other.mOrigin)
1016 template<
typename T, Index Log2Dim>
1017 template<
typename OtherValueType>
1021 mValueMask(other.valueMask()),
1022 mOrigin(other.mOrigin)
1025 mBuffer[i] = (mValueMask.
isOn(i) ? onValue : offValue);
1030 template<
typename T, Index Log2Dim>
1037 template<
typename T, Index Log2Dim>
1041 std::ostringstream ostr;
1042 ostr <<
"LeafNode @" << mOrigin <<
": " << mBuffer;
1050 template<
typename T, Index Log2Dim>
1054 assert ((xyz[0] & (DIM-1u)) < DIM && (xyz[1] & (DIM-1u)) < DIM && (xyz[2] & (DIM-1u)) < DIM);
1055 return ((xyz[0] & (DIM-1u)) << 2*Log2Dim)
1056 + ((xyz[1] & (DIM-1u)) << Log2Dim)
1057 + (xyz[2] & (DIM-1u));
1060 template<
typename T, Index Log2Dim>
1064 assert(n<(1<< 3*Log2Dim));
1066 xyz.
setX(n >> 2*Log2Dim);
1067 n &= ((1<<2*Log2Dim)-1);
1068 xyz.
setY(n >> Log2Dim);
1069 xyz.
setZ(n & ((1<<Log2Dim)-1));
1074 template<
typename T, Index Log2Dim>
1078 return (this->offsetToLocalCoord(n) + this->origin());
1085 template<
typename ValueT, Index Log2Dim>
1086 inline const ValueT&
1092 template<
typename ValueT, Index Log2Dim>
1093 inline const ValueT&
1096 assert(offset < SIZE);
1097 return mBuffer[offset];
1101 template<
typename T, Index Log2Dim>
1108 template<
typename T, Index Log2Dim>
1112 assert(offset < SIZE);
1113 val = mBuffer[offset];
1114 return mValueMask.isOn(offset);
1118 template<
typename T, Index Log2Dim>
1125 template<
typename T, Index Log2Dim>
1129 assert(offset < SIZE);
1130 mBuffer.setValue(offset, val);
1131 mValueMask.setOff(offset);
1135 template<
typename T, Index Log2Dim>
1139 mValueMask.set(this->coordToOffset(xyz), on);
1143 template<
typename T, Index Log2Dim>
1150 template<
typename T, Index Log2Dim>
1154 assert(offset<SIZE); mBuffer.setValue(offset, val);
1161 template<
typename T, Index Log2Dim>
1165 CoordBBox nodeBBox = this->getNodeBoundingBox();
1168 this->fill(background,
false);
1169 }
else if (clipBBox.
isInside(nodeBBox)) {
1181 int &x = xyz.
x(), &y = xyz.
y(), &z = xyz.
z();
1182 for (x = nodeBBox.
min().
x(); x <= nodeBBox.
max().
x(); ++x) {
1183 for (y = nodeBBox.
min().
y(); y <= nodeBBox.
max().
y(); ++y) {
1184 for (z = nodeBBox.
min().
z(); z <= nodeBBox.
max().
z(); ++z) {
1185 mask.
setOn(static_cast<Index32>(this->coordToOffset(xyz)));
1193 this->setValueOff(maskIter.pos(), background);
1201 template<
typename T, Index Log2Dim>
1205 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1206 if (!this->allocate())
return;
1209 auto clippedBBox = this->getNodeBoundingBox();
1210 clippedBBox.intersect(bbox);
1211 if (!clippedBBox)
return;
1213 for (
Int32 x = clippedBBox.min().x(); x <= clippedBBox.max().x(); ++x) {
1214 const Index offsetX = (x & (DIM-1u)) << 2*Log2Dim;
1215 for (
Int32 y = clippedBBox.min().y(); y <= clippedBBox.max().y(); ++y) {
1216 const Index offsetXY = offsetX + ((y & (DIM-1u)) << Log2Dim);
1217 for (
Int32 z = clippedBBox.min().z(); z <= clippedBBox.max().z(); ++z) {
1218 const Index offset = offsetXY + (z & (DIM-1u));
1219 mBuffer[offset] = value;
1220 mValueMask.set(offset, active);
1226 template<
typename T, Index Log2Dim>
1230 mBuffer.fill(value);
1233 template<
typename T, Index Log2Dim>
1237 mBuffer.fill(value);
1238 mValueMask.set(active);
1245 template<
typename T, Index Log2Dim>
1246 template<
typename DenseT>
1250 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1251 mBuffer.loadValues();
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();
1258 DenseValueType* t0 = dense.data() + zStride * (bbox.
min()[2] -
min[2]);
1259 const T* s0 = &mBuffer[bbox.
min()[2] & (DIM-1u)];
1260 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0] + 1; x < ex; ++x) {
1261 DenseValueType* t1 = t0 + xStride * (x -
min[0]);
1262 const T* s1 = s0 + ((x & (DIM-1u)) << 2*Log2Dim);
1263 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1] + 1; y < ey; ++y) {
1264 DenseValueType* t2 = t1 + yStride * (y -
min[1]);
1265 const T* s2 = s1 + ((y & (DIM-1u)) << Log2Dim);
1266 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2] + 1; z < ez; ++z, t2 += zStride) {
1267 *t2 = DenseValueType(*s2++);
1274 template<
typename T, Index Log2Dim>
1275 template<
typename DenseT>
1280 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1281 if (!this->allocate())
return;
1284 using DenseValueType =
typename DenseT::ValueType;
1286 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1287 const Coord&
min = dense.bbox().min();
1289 const DenseValueType* s0 = dense.data() + zStride * (bbox.
min()[2] -
min[2]);
1290 const Int32 n0 = bbox.
min()[2] & (DIM-1u);
1291 for (
Int32 x = bbox.
min()[0], ex = bbox.
max()[0]+1; x < ex; ++x) {
1292 const DenseValueType* s1 = s0 + xStride * (x -
min[0]);
1293 const Int32 n1 = n0 + ((x & (DIM-1u)) << 2*LOG2DIM);
1294 for (
Int32 y = bbox.
min()[1], ey = bbox.
max()[1]+1; y < ey; ++y) {
1295 const DenseValueType* s2 = s1 + yStride * (y -
min[1]);
1296 Int32 n2 = n1 + ((y & (DIM-1u)) << LOG2DIM);
1297 for (
Int32 z = bbox.
min()[2], ez = bbox.
max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1299 mValueMask.setOff(n2);
1300 mBuffer[n2] = background;
1302 mValueMask.setOn(n2);
1314 template<
typename T, Index Log2Dim>
1318 mValueMask.load(is);
1322 template<
typename T, Index Log2Dim>
1326 mValueMask.save(os);
1334 template<
typename T, Index Log2Dim>
1340 io::readCompressedValues<ValueType, NodeMaskType>(
1341 is,
nullptr, SIZE, mValueMask, fromHalf);
1350 template<
typename T, Index Log2Dim>
1358 template<
typename T, Index Log2Dim>
1363 const bool seekable = meta && meta->seekable();
1365 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1366 std::streamoff maskpos = is.tellg();
1371 mValueMask.seek(is);
1374 mValueMask.load(is);
1377 int8_t numBuffers = 1;
1383 is.read(reinterpret_cast<char*>(&numBuffers),
sizeof(int8_t));
1386 CoordBBox nodeBBox = this->getNodeBoundingBox();
1389 skipCompressedValues(seekable, is, fromHalf);
1390 mValueMask.setOff();
1391 mBuffer.setOutOfCore(
false);
1393 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1399 const bool delayLoad = ((mappedFile.get() !=
nullptr) && clipBBox.
isInside(nodeBBox));
1402 mBuffer.setOutOfCore(
true);
1403 mBuffer.mFileInfo =
new typename Buffer::FileInfo;
1404 mBuffer.mFileInfo->meta = meta;
1405 mBuffer.mFileInfo->bufpos = is.tellg();
1406 mBuffer.mFileInfo->mapping = mappedFile;
1409 mBuffer.mFileInfo->maskpos = maskpos;
1411 skipCompressedValues(seekable, is, fromHalf);
1416 mBuffer.setOutOfCore(
false);
1419 T background = zeroVal<T>();
1421 background = *static_cast<const T*>(bgPtr);
1423 this->
clip(clipBBox, background);
1424 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1429 if (numBuffers > 1) {
1434 for (
int i = 1; i < numBuffers; ++i) {
1438 io::readData<T>(is, temp.
mData, SIZE, zipped);
1445 template<
typename T, Index Log2Dim>
1450 mValueMask.save(os);
1452 mBuffer.loadValues();
1462 template<
typename T, Index Log2Dim>
1466 return mOrigin == other.mOrigin &&
1468 mBuffer == other.mBuffer;
1472 template<
typename T, Index Log2Dim>
1478 return sizeof(*this) + mBuffer.memUsage() -
sizeof(mBuffer);
1482 template<
typename T, Index Log2Dim>
1486 CoordBBox this_bbox = this->getNodeBoundingBox();
1487 if (bbox.
isInside(this_bbox))
return;
1491 for(; iter; ++iter) this_bbox.
expand(this->offsetToLocalCoord(iter.pos()));
1499 template<
typename T, Index Log2Dim>
1500 template<
typename OtherType, Index OtherLog2Dim>
1505 return (Log2Dim == OtherLog2Dim && mValueMask == other->
getValueMask());
1508 template<
typename T, Index Log2Dim>
1514 if (!mValueMask.isConstant(state))
return false;
1515 firstValue = mBuffer[0];
1516 for (
Index i = 1; i < SIZE; ++i) {
1522 template<
typename T, Index Log2Dim>
1529 if (!mValueMask.isConstant(state))
return false;
1530 minValue = maxValue = mBuffer[0];
1531 for (
Index i = 1; i < SIZE; ++i) {
1532 const T& v = mBuffer[i];
1534 if ((maxValue - v) > tolerance)
return false;
1536 }
else if (v > maxValue) {
1537 if ((v - minValue) > tolerance)
return false;
1544 template<
typename T, Index Log2Dim>
1548 std::unique_ptr<T[]> data(
nullptr);
1549 if (tmp ==
nullptr) {
1550 data.reset(
new T[NUM_VALUES]);
1553 if (tmp != mBuffer.data()) {
1554 const T* src = mBuffer.data();
1555 for (T* dst = tmp; dst-tmp < NUM_VALUES;) *dst++ = *src++;
1557 static const size_t midpoint = (NUM_VALUES - 1) >> 1;
1558 std::nth_element(tmp, tmp + midpoint, tmp + NUM_VALUES);
1559 return tmp[midpoint];
1562 template<
typename T, Index Log2Dim>
1566 const Index count = mValueMask.countOn();
1567 if (count == NUM_VALUES) {
1568 value = this->medianAll(tmp);
1570 }
else if (count == 0) {
1573 std::unique_ptr<T[]> data(
nullptr);
1574 if (tmp ==
nullptr) {
1575 data.reset(
new T[count]);
1578 for (
auto iter=this->cbeginValueOn(); iter; ++iter) *tmp++ = *iter;
1579 T *begin = tmp - count;
1580 const size_t midpoint = (count - 1) >> 1;
1581 std::nth_element(begin, begin + midpoint, tmp);
1582 value = begin[midpoint];
1586 template<
typename T, Index Log2Dim>
1590 const Index count = mValueMask.countOff();
1591 if (count == NUM_VALUES) {
1592 value = this->medianAll(tmp);
1594 }
else if (count == 0) {
1597 std::unique_ptr<T[]> data(
nullptr);
1598 if (tmp ==
nullptr) {
1599 data.reset(
new T[count]);
1602 for (
auto iter=this->cbeginValueOff(); iter; ++iter) *tmp++ = *iter;
1603 T *begin = tmp - count;
1604 const size_t midpoint = (count - 1) >> 1;
1605 std::nth_element(begin, begin + midpoint, tmp);
1606 value = begin[midpoint];
1613 template<
typename T, Index Log2Dim>
1617 this->addTile(this->coordToOffset(xyz), val, active);
1620 template<
typename T, Index Log2Dim>
1624 assert(offset < SIZE);
1625 setValueOnly(offset, val);
1626 setActiveState(offset, active);
1629 template<
typename T, Index Log2Dim>
1630 template<
typename AccessorT>
1633 const ValueType& val,
bool active, AccessorT&)
1635 this->addTile(level, xyz, val, active);
1642 template<
typename T, Index Log2Dim>
1647 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1648 if (!this->allocate())
return;
1653 for (iter = this->mValueMask.beginOff(); iter; ++iter) {
1656 inactiveValue = newBackground;
1664 template<
typename T, Index Log2Dim>
1665 template<MergePolicy Policy>
1669 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1670 if (!this->allocate())
return;
1676 for (; iter; ++iter) {
1678 if (mValueMask.isOff(n)) {
1679 mBuffer[n] = other.mBuffer[n];
1680 mValueMask.setOn(n);
1686 template<
typename T, Index Log2Dim>
1687 template<MergePolicy Policy>
1692 this->
template merge<Policy>(other);
1695 template<
typename T, Index Log2Dim>
1696 template<MergePolicy Policy>
1700 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1701 if (!this->allocate())
return;
1706 if (!tileActive)
return;
1709 const Index n = iter.pos();
1710 mBuffer[n] = tileValue;
1711 mValueMask.setOn(n);
1717 template<
typename T, Index Log2Dim>
1718 template<
typename OtherType>
1725 template<
typename T, Index Log2Dim>
1726 template<
typename OtherType>
1734 template<
typename T, Index Log2Dim>
1735 template<
typename OtherType>
1743 template<
typename T, Index Log2Dim>
1747 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1748 if (!this->allocate())
return;
1750 for (
Index i = 0; i < SIZE; ++i) {
1751 mBuffer[i] = -mBuffer[i];
1759 template<
typename T, Index Log2Dim>
1760 template<
typename CombineOp>
1764 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1765 if (!this->allocate())
return;
1768 for (
Index i = 0; i < SIZE; ++i) {
1770 .setAIsActive(mValueMask.isOn(i))
1771 .setBRef(other.mBuffer[i])
1773 .setResultRef(mBuffer[i]));
1779 template<
typename T, Index Log2Dim>
1780 template<
typename CombineOp>
1784 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1785 if (!this->allocate())
return;
1788 args.
setBRef(value).setBIsActive(valueIsActive);
1789 for (
Index i = 0; i < SIZE; ++i) {
1791 .setAIsActive(mValueMask.isOn(i))
1792 .setResultRef(mBuffer[i]));
1801 template<
typename T, Index Log2Dim>
1802 template<
typename CombineOp,
typename OtherType>
1805 bool valueIsActive, CombineOp& op)
1807 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1808 if (!this->allocate())
return;
1811 args.
setBRef(value).setBIsActive(valueIsActive);
1812 for (
Index i = 0; i < SIZE; ++i) {
1813 op(args.
setARef(other.mBuffer[i])
1815 .setResultRef(mBuffer[i]));
1821 template<
typename T, Index Log2Dim>
1822 template<
typename CombineOp,
typename OtherNodeT>
1825 bool valueIsActive, CombineOp& op)
1827 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1828 if (!this->allocate())
return;
1831 args.
setARef(value).setAIsActive(valueIsActive);
1832 for (
Index i = 0; i < SIZE; ++i) {
1833 op(args.
setBRef(other.mBuffer[i])
1834 .setBIsActive(other.valueMask().isOn(i))
1835 .setResultRef(mBuffer[i]));
1841 template<
typename T, Index Log2Dim>
1842 template<
typename CombineOp,
typename OtherNodeT>
1846 #if OPENVDB_ABI_VERSION_NUMBER >= 3 1847 if (!this->allocate())
return;
1850 for (
Index i = 0; i < SIZE; ++i) {
1851 mValueMask.set(i, b0.
valueMask().
isOn(i) || b1.valueMask().isOn(i));
1852 op(args.
setARef(b0.mBuffer[i])
1854 .setBRef(b1.mBuffer[i])
1855 .setBIsActive(b1.valueMask().isOn(i))
1856 .setResultRef(mBuffer[i]));
1865 template<
typename T, Index Log2Dim>
1866 template<
typename BBoxOp>
1870 if (op.template descent<LEVEL>()) {
1880 op.operator()<LEVEL>(this->getNodeBoundingBox());
1882 op.template operator()<LEVEL>(this->getNodeBoundingBox());
1888 template<
typename T, Index Log2Dim>
1889 template<
typename VisitorOp>
1893 doVisit<LeafNode, VisitorOp, ChildAllIter>(*
this, op);
1897 template<
typename T, Index Log2Dim>
1898 template<
typename VisitorOp>
1902 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*
this, op);
1906 template<
typename T, Index Log2Dim>
1907 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
1911 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
1920 template<
typename T, Index Log2Dim>
1921 template<
typename OtherLeafNodeType,
typename VisitorOp>
1926 typename OtherLeafNodeType::ChildAllIter>(*
this, other, op);
1930 template<
typename T, Index Log2Dim>
1931 template<
typename OtherLeafNodeType,
typename VisitorOp>
1936 typename OtherLeafNodeType::ChildAllCIter>(*
this, other, op);
1940 template<
typename T, Index Log2Dim>
1943 typename OtherNodeT,
1945 typename ChildAllIterT,
1946 typename OtherChildAllIterT>
1951 static_assert(OtherNodeT::SIZE == NodeT::SIZE,
1952 "can't visit nodes of different sizes simultaneously");
1953 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
1954 "can't visit nodes at different tree levels simultaneously");
1956 ChildAllIterT iter =
self.beginChildAll();
1957 OtherChildAllIterT otherIter = other.beginChildAll();
1959 for ( ; iter && otherIter; ++iter, ++otherIter) {
1960 op(iter, otherIter);
1968 template<
typename T, Index Log2Dim>
1969 template<
typename IterT,
typename VisitorOp>
1973 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(
1974 *
this, otherIter, op, otherIsLHS);
1978 template<
typename T, Index Log2Dim>
1979 template<
typename IterT,
typename VisitorOp>
1983 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(
1984 *
this, otherIter, op, otherIsLHS);
1988 template<
typename T, Index Log2Dim>
1992 typename ChildAllIterT,
1993 typename OtherChildAllIterT>
1996 VisitorOp& op,
bool otherIsLHS)
1998 if (!otherIter)
return;
2001 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
2002 op(otherIter, iter);
2005 for (ChildAllIterT iter =
self.beginChildAll(); iter; ++iter) {
2006 op(iter, otherIter);
2015 template<
typename T, Index Log2Dim>
2016 inline std::ostream&
2019 for (
Index32 i = 0, N = buf.
size(); i < N; ++i) os << buf.
mData[i] <<
", ";
2037 #endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED Definition: LeafNode.h:236
ValueOffCIter cendValueOff() const
Definition: LeafNode.h:333
Coord & setY(Int32 y)
Definition: Coord.h:107
Coord & setZ(Int32 z)
Definition: Coord.h:108
~LeafNode()
Destructor.
Definition: LeafNode.h:1032
ValueOnCIter beginValueOn() const
Definition: LeafNode.h:321
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:733
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNode.h:432
Definition: LeafNode.h:233
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:211
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:739
ChildAllIter beginChildAll()
Definition: LeafNode.h:350
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition: LeafNode.h:417
Definition: NodeMasks.h:272
ValueT & getValue() const
Definition: LeafNode.h:248
Index64 offLeafVoxelCount() const
Definition: LeafNode.h:170
LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:753
Definition: LeafNode.h:280
ChildOnIter beginChildOn()
Definition: LeafNode.h:344
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:56
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:151
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition: LeafNode.h:149
OffIterator beginOff() const
Definition: NodeMasks.h:356
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:245
ChildOnCIter cbeginChildOn() const
Definition: LeafNode.h:342
Index32 Index
Definition: Types.h:61
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:320
void unsetItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:300
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:1137
uint64_t Index64
Definition: Types.h:60
OnIterator beginOn() const
Definition: NodeMasks.h:354
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:582
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNode.h:157
SharedPtr< MappedFile > Ptr
Definition: io.h:152
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:755
Definition: LeafNode.h:49
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNode.h:731
Coord & setX(Int32 x)
Definition: Coord.h:106
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:275
ChildOnCIter beginChildOn() const
Definition: LeafNode.h:343
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNode.h:762
ChildOffCIter beginChildOff() const
Definition: LeafNode.h:346
static const Index SIZE
Definition: LeafNode.h:80
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition: LeafNode.h:86
static Index size()
Return the number of values contained in this buffer.
Definition: LeafBuffer.h:180
ValueAllIter endValueAll()
Definition: LeafNode.h:338
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:1248
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:205
ValueOffCIter beginValueOff() const
Definition: LeafNode.h:324
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:1971
ChildOffIter endChildOff()
Definition: LeafNode.h:357
bool isChildMaskOn(Index) const
Definition: LeafNode.h:893
bool operator!=(const LeafNode &other) const
Definition: LeafNode.h:224
DenseIter()
Definition: LeafNode.h:286
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:141
T BuildType
Definition: LeafNode.h:67
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:349
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:430
Int32 z() const
Definition: Coord.h:159
ValueAllCIter cendValueAll() const
Definition: LeafNode.h:336
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:598
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:491
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:518
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:1995
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNode.h:493
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition: LeafNode.h:91
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition: LeafNode.h:641
const Coord & max() const
Definition: Coord.h:338
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNode.h:182
ValueType ValueType
Definition: Iterator.h:144
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1324
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNode.h:289
ValueOnCIter cendValueOn() const
Definition: LeafNode.h:330
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:607
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNode.h:163
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:1728
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition: NodeMasks.h:309
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNode.h:773
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:740
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:1737
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1316
ChildAllCIter cbeginChildAll() const
Definition: LeafNode.h:348
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:1277
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNode.h:442
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1464
void setValueMask(const NodeMaskType &mask)
Definition: LeafNode.h:892
ValueType * mData
Definition: LeafBuffer.h:225
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNode.h:904
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1484
void reset()
Definition: Coord.h:343
Index medianOn(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the active voxels in this node.
Definition: LeafNode.h:1564
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:770
bool isValueMaskOff(Index n) const
Definition: LeafNode.h:887
std::ostream & operator<<(std::ostream &os, const typename LeafNode< T, Log2Dim >::Buffer &buf)
Definition: LeafNode.h:2017
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:475
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:450
int32_t Int32
Definition: Types.h:63
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNode.h:860
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:458
ChildIter()
Definition: LeafNode.h:274
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:1909
ValueType medianAll(ValueType *tmp=nullptr) const
Computes the median value of all the active AND inactive voxels in this node.
Definition: LeafNode.h:1546
Int32 x() const
Definition: Coord.h:157
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNode.h:161
bool resultIsActive() const
Definition: Types.h:450
ChildOffIter beginChildOff()
Definition: LeafNode.h:347
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1474
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:1868
ValueOnIter beginValueOn()
Definition: LeafNode.h:322
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: Coord.h:404
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition: LeafNode.h:643
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:176
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:741
NodeMaskType & getValueMask()
Definition: LeafNode.h:890
Index32 pos() const
Definition: NodeMasks.h:202
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1087
void modifyValue(const ModifyOp &op) const
Definition: LeafNode.h:266
bool isValueMaskOn(Index n) const
Definition: LeafNode.h:885
Definition: NodeMasks.h:210
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition: LeafNode.h:168
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:153
uint32_t Index32
Definition: Types.h:59
LeafNode()
Default constructor.
Definition: LeafNode.h:946
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNode.h:263
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition: LeafNode.h:166
typename BaseT::NonConstValueType NonConstValueT
Definition: LeafNode.h:284
ValueOnIter endValueOn()
Definition: LeafNode.h:332
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNode.h:488
ChildOnCIter endChildOn() const
Definition: LeafNode.h:353
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
Definition: NodeMasks.h:241
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:1203
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:889
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: LeafNode.h:233
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1804
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition: Coord.h:416
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:367
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:1923
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:108
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:573
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1447
Buffer & buffer()
Definition: LeafNode.h:369
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:551
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1163
Definition: Compression.h:216
static Index64 offTileCount()
Definition: LeafNode.h:172
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node.
Definition: LeafNode.h:195
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNode.h:159
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1615
const Coord & min() const
Definition: Coord.h:337
ValueOffCIter endValueOff() const
Definition: LeafNode.h:334
bool isChildMaskOff() const
Definition: LeafNode.h:895
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition: LeafNode.h:147
void setValueMask(Index n, bool on)
Definition: LeafNode.h:897
Definition: Exceptions.h:40
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:264
void visit(VisitorOp &)
Definition: LeafNode.h:1891
void voxelizeActiveTiles(bool=true)
No-op.
Definition: LeafNode.h:653
void setValueMaskOff(Index n)
Definition: LeafNode.h:899
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:1948
ValueOnCIter endValueOn() const
Definition: LeafNode.h:331
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:1720
ValueOffIter endValueOff()
Definition: LeafNode.h:335
ChildOnCIter cendChildOn() const
Definition: LeafNode.h:352
ChildOnIter endChildOn()
Definition: LeafNode.h:354
Int32 ValueType
Definition: Coord.h:59
Index medianOff(ValueType &value, ValueType *tmp=nullptr) const
Computes the median value of all the inactive voxels in this node.
Definition: LeafNode.h:1588
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:468
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:358
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNode.h:636
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition: Coord.h:422
ValueAllIter beginValueAll()
Definition: LeafNode.h:328
const Buffer & buffer() const
Definition: LeafNode.h:368
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNode.h:155
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1644
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:203
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNode.h:496
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:625
ChildAllCIter endChildAll() const
Definition: LeafNode.h:359
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:386
Index64 onLeafVoxelCount() const
Definition: LeafNode.h:169
ValueT & getItem(Index pos) const
Definition: LeafNode.h:247
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: LeafNode.h:229
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1039
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim....
Definition: LeafNode.h:64
Definition: Compression.h:79
Int32 y() const
Definition: Coord.h:158
ChildAllCIter cendChildAll() const
Definition: LeafNode.h:358
ValueAllCIter beginValueAll() const
Definition: LeafNode.h:327
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1632
void negate()
Definition: LeafNode.h:1745
bool isChildMaskOff(Index) const
Definition: LeafNode.h:894
OPENVDB_API SharedPtr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated,...
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:504
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1052
ValueAllCIter endValueAll() const
Definition: LeafNode.h:337
static CoordBBox inf()
Return an "infinite" bounding box, as defined by the Coord value range.
Definition: Coord.h:335
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:775
void skipCompressedValues(bool seekable, std::istream &, bool fromHalf)
Definition: LeafNode.h:1336
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:1502
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:764
SharedPtr< LeafNode > Ptr
Definition: LeafNode.h:72
void merge(const LeafNode &)
Definition: LeafNode.h:1667
typename NodeMaskType::OnIterator MaskOnIterator
Definition: LeafNode.h:227
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0,...
Definition: LeafNode.h:1062
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1103
std::shared_ptr< T > SharedPtr
Definition: Types.h:139
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:422
ValueAllCIter cbeginValueAll() const
Definition: LeafNode.h:326
Definition: version.h:229
ChildOffCIter endChildOff() const
Definition: LeafNode.h:356
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:564
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:735
ValueOffCIter cbeginValueOff() const
Definition: LeafNode.h:323
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNode.h:486
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:174
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:559
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...
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:520
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:462
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1510
Definition: LeafNode.h:232
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1352
ChildOffCIter cbeginChildOff() const
Definition: LeafNode.h:345
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK,...
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:616
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:439
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:440
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition: Coord.h:329
ChildAllIter endChildAll()
Definition: LeafNode.h:360
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:737
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
bool isValueMaskOn() const
Definition: LeafNode.h:886
const NodeMaskType & valueMask() const
Definition: LeafNode.h:891
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:448
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1076
typename NodeMaskType::OffIterator MaskOffIterator
Definition: LeafNode.h:228
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: LeafNode.h:287
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:444
ValueIter()
Definition: LeafNode.h:244
ValueOffIter beginValueOff()
Definition: LeafNode.h:325
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:339
Definition: PointDataGrid.h:201
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNode.h:590
static Index64 onTileCount()
Definition: LeafNode.h:171
void setValueMaskOn(Index n)
Definition: LeafNode.h:898
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:202
Definition: LeafNode.h:232
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:772
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:1145
Definition: LeafNode.h:232
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1762
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:454
bool isValueMaskOff() const
Definition: LeafNode.h:888
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition: Coord.h:448
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:504
ChildOffCIter cendChildOff() const
Definition: LeafNode.h:355
T ValueType
Definition: LeafNode.h:68
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNode.h:198
void setItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:251
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:271
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:441
void translate(const Coord &t)
Definition: Coord.h:462
void setValue(const ValueT &value) const
Definition: LeafNode.h:256