8 #ifndef OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED 9 #define OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED 15 #include <openvdb/version.h> 19 #include <tbb/parallel_for.h> 21 #include <type_traits> 32 template<
typename _ChildNodeType, Index Log2Dim>
38 using ValueType =
typename ChildNodeType::ValueType;
39 using BuildType =
typename ChildNodeType::BuildType;
45 TOTAL = Log2Dim + ChildNodeType::TOTAL,
47 NUM_VALUES = 1 << (3 * Log2Dim),
48 LEVEL = 1 + ChildNodeType::LEVEL;
50 NUM_VOXELS = uint64_t(1) << (3 * TOTAL);
54 template<
typename OtherValueType>
63 template<
typename OtherNodeType>
94 template<
typename OtherChildNodeType>
100 template<
typename OtherChildNodeType>
107 template<
typename OtherChildNodeType>
126 template<
typename NodeT,
typename ChildT,
typename MaskIterT,
typename TagT>
128 MaskIterT, ChildIter<NodeT, ChildT, MaskIterT, TagT>, NodeT, ChildT>
132 MaskIterT,
ChildIter<NodeT, ChildT, MaskIterT, TagT>, NodeT, ChildT>(iter, parent) {}
136 assert(this->parent().isChildMaskOn(pos));
137 return *(this->parent().getChildNode(pos));
141 void setItem(
Index pos,
const ChildT& c)
const { this->parent().resetChildNode(pos, &c); }
147 template<
typename NodeT,
typename ValueT,
typename MaskIterT,
typename TagT>
149 MaskIterT, ValueIter<NodeT, ValueT, MaskIterT, TagT>, NodeT, ValueT>
153 MaskIterT,
ValueIter<NodeT, ValueT, MaskIterT, TagT>, NodeT, ValueT>(iter, parent) {}
155 const ValueT&
getItem(
Index pos)
const {
return this->parent().mNodes[pos].getValue(); }
158 void setItem(
Index pos,
const ValueT& v)
const { this->parent().mNodes[pos].setValue(v); }
161 template<
typename ModifyOp>
164 op(this->parent().mNodes[pos].getValue());
169 template<
typename NodeT,
typename ChildT,
typename ValueT,
typename TagT>
171 MaskDenseIterator, DenseIter<NodeT, ChildT, ValueT, TagT>, NodeT, ChildT, ValueT>
182 if (this->parent().isChildMaskOn(pos)) {
183 child = this->parent().getChildNode(pos);
187 value = this->parent().mNodes[pos].getValue();
194 this->parent().resetChildNode(pos, child);
200 this->parent().unsetChildNode(pos, value);
252 static void getNodeLog2Dims(std::vector<Index>& dims);
259 static Index coordToOffset(
const Coord& xyz);
262 static void offsetToLocalCoord(
Index n, Coord& xyz);
264 Coord offsetToGlobalCoord(
Index n)
const;
267 const Coord&
origin()
const {
return mOrigin; }
269 void setOrigin(
const Coord& origin) { mOrigin = origin; }
271 #if OPENVDB_ABI_VERSION_NUMBER >= 9 279 void nodeCount(std::vector<Index32> &vec)
const;
284 Index64 onLeafVoxelCount()
const;
285 Index64 offLeafVoxelCount()
const;
295 void evalActiveBoundingBox(
CoordBBox& bbox,
bool visitVoxels =
true)
const;
302 bool isEmpty()
const {
return mChildMask.isOff(); }
309 bool isConstant(
ValueType& firstValue,
bool& state,
310 const ValueType& tolerance = zeroVal<ValueType>())
const;
327 bool& state,
const ValueType& tolerance = zeroVal<ValueType>())
const;
330 bool isInactive()
const {
return this->isChildMaskOff() && this->isValueMaskOff(); }
333 bool isValueOn(
const Coord& xyz)
const;
338 bool hasActiveTiles()
const;
340 const ValueType& getValue(
const Coord& xyz)
const;
345 Index getValueLevel(
const Coord& xyz)
const;
355 void setActiveState(
const Coord& xyz,
bool on);
357 void setValueOnly(
const Coord& xyz,
const ValueType& value);
359 void setValueOn(
const Coord& xyz);
361 void setValueOn(
const Coord& xyz,
const ValueType& value);
363 void setValueOff(
const Coord& xyz);
365 void setValueOff(
const Coord& xyz,
const ValueType& value);
369 template<
typename ModifyOp>
370 void modifyValue(
const Coord& xyz,
const ModifyOp& op);
372 template<
typename ModifyOp>
373 void modifyValueAndActiveState(
const Coord& xyz,
const ModifyOp& op);
379 template<
typename AccessorT>
380 const ValueType& getValueAndCache(
const Coord& xyz, AccessorT&)
const;
386 template<
typename AccessorT>
387 bool isValueOnAndCache(
const Coord& xyz, AccessorT&)
const;
393 template<
typename AccessorT>
394 void setValueAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
400 template<
typename AccessorT>
401 void setValueOnlyAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
408 template<
typename ModifyOp,
typename AccessorT>
409 void modifyValueAndCache(
const Coord& xyz,
const ModifyOp& op, AccessorT&);
415 template<
typename ModifyOp,
typename AccessorT>
416 void modifyValueAndActiveStateAndCache(
const Coord& xyz,
const ModifyOp& op, AccessorT&);
422 template<
typename AccessorT>
423 void setValueOffAndCache(
const Coord& xyz,
const ValueType& value, AccessorT&);
429 template<
typename AccessorT>
430 void setActiveStateAndCache(
const Coord& xyz,
bool on, AccessorT&);
437 template<
typename AccessorT>
438 bool probeValueAndCache(
const Coord& xyz,
ValueType& value, AccessorT&)
const;
446 template<
typename AccessorT>
447 Index getValueLevelAndCache(
const Coord& xyz, AccessorT&)
const;
455 void writeTopology(std::ostream&,
bool toHalf =
false)
const;
456 void readTopology(std::istream&,
bool fromHalf =
false);
457 void writeBuffers(std::ostream&,
bool toHalf =
false)
const;
458 void readBuffers(std::istream&,
bool fromHalf =
false);
459 void readBuffers(std::istream&,
const CoordBBox&,
bool fromHalf =
false);
491 void voxelizeActiveTiles(
bool threaded =
true);
500 template<
typename DenseT>
505 template<MergePolicy Policy>
510 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
524 template<
typename OtherChildNodeType>
540 template<
typename OtherChildNodeType>
555 template<
typename OtherChildNodeType>
559 template<
typename CombineOp>
561 template<
typename CombineOp>
564 template<
typename CombineOp,
typename OtherNodeType >
565 void combine2(
const InternalNode& other0,
const OtherNodeType& other1, CombineOp&);
566 template<
typename CombineOp,
typename OtherNodeType >
567 void combine2(
const ValueType& value,
const OtherNodeType& other,
bool valIsActive, CombineOp&);
568 template<
typename CombineOp,
typename OtherValueType>
569 void combine2(
const InternalNode& other,
const OtherValueType&,
bool valIsActive, CombineOp&);
576 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
578 template<
typename VisitorOp>
void visit(VisitorOp&);
579 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
581 template<
typename OtherNodeType,
typename VisitorOp>
582 void visit2Node(OtherNodeType& other, VisitorOp&);
583 template<
typename OtherNodeType,
typename VisitorOp>
584 void visit2Node(OtherNodeType& other, VisitorOp&)
const;
585 template<
typename IterT,
typename VisitorOp>
586 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false);
587 template<
typename IterT,
typename VisitorOp>
588 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false)
const;
604 template<
typename AccessorT>
615 template<
typename NodeT>
616 NodeT* stealNode(
const Coord& xyz,
const ValueType& value,
bool state);
628 void addTile(
Index level,
const Coord& xyz,
const ValueType& value,
bool state);
635 template<
typename AccessorT>
636 void addTileAndCache(
Index level,
const Coord& xyz,
const ValueType&,
bool state, AccessorT&);
641 template<
typename NodeType> NodeType* probeNode(
const Coord& xyz);
642 template<
typename NodeType>
const NodeType* probeConstNode(
const Coord& xyz)
const;
648 template<
typename NodeType,
typename AccessorT>
649 NodeType* probeNodeAndCache(
const Coord& xyz, AccessorT&);
650 template<
typename NodeType,
typename AccessorT>
651 const NodeType* probeConstNodeAndCache(
const Coord& xyz, AccessorT&)
const;
658 const LeafNodeType* probeConstLeaf(
const Coord& xyz)
const;
665 template<
typename AccessorT>
666 LeafNodeType* probeLeafAndCache(
const Coord& xyz, AccessorT& acc);
667 template<
typename AccessorT>
668 const LeafNodeType* probeConstLeafAndCache(
const Coord& xyz, AccessorT& acc)
const;
669 template<
typename AccessorT>
670 const LeafNodeType* probeLeafAndCache(
const Coord& xyz, AccessorT& acc)
const;
683 template<
typename AccessorT>
684 LeafNodeType* touchLeafAndCache(
const Coord& xyz, AccessorT&);
709 template<
typename ArrayT>
710 void getNodes(ArrayT& array);
711 template<
typename ArrayT>
712 void getNodes(ArrayT& array)
const;
738 template<
typename ArrayT>
739 void stealNodes(ArrayT& array,
const ValueType& value,
bool state);
747 template<
typename OtherChildNodeType, Index OtherLog2Dim>
794 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
795 static inline void doVisit(NodeT&, VisitorOp&);
797 template<
typename NodeT,
typename OtherNodeT,
typename VisitorOp,
798 typename ChildAllIterT,
typename OtherChildAllIterT>
799 static inline void doVisit2Node(NodeT&, OtherNodeT&, VisitorOp&);
801 template<
typename NodeT,
typename VisitorOp,
802 typename ChildAllIterT,
typename OtherChildAllIterT>
803 static inline void doVisit2(NodeT&, OtherChildAllIterT&, VisitorOp&,
bool otherIsLHS);
816 template<
typename OtherInternalNode>
struct DeepCopy;
828 #if OPENVDB_ABI_VERSION_NUMBER >= 9 841 template<
typename ChildT1, Index Dim1,
typename NodeT2>
846 template<
typename ChildT1, Index Dim1,
typename ChildT2>
856 template<
typename ChildT, Index Log2Dim>
860 for (
Index i = 0; i < NUM_VALUES; ++i) mNodes[i].setValue(background);
864 template<
typename ChildT, Index Log2Dim>
867 mOrigin(origin[0] & ~(DIM - 1),
868 origin[1] & ~(DIM - 1),
869 origin[2] & ~(DIM - 1))
878 template<
typename ChildT, Index Log2Dim>
888 template<
typename ChildT, Index Log2Dim>
889 template<
typename OtherInternalNode>
893 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
897 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
898 if (s->mChildMask.isOff(i)) {
899 t->mNodes[i].setValue(
ValueType(s->mNodes[i].getValue()));
901 t->mNodes[i].setChild(
new ChildNodeType(*(s->mNodes[i].getChild())));
905 const OtherInternalNode*
s;
909 template<
typename ChildT, Index Log2Dim>
915 #if OPENVDB_ABI_VERSION_NUMBER >= 9
924 template<
typename ChildT, Index Log2Dim>
925 template<
typename OtherChildNodeType>
931 #if OPENVDB_ABI_VERSION_NUMBER >= 9
938 template<
typename ChildT, Index Log2Dim>
939 template<
typename OtherInternalNode>
943 const ValueType& background) : s(source), t(target), b(background) {
944 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
948 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
949 if (s->isChildMaskOn(i)) {
950 t->mNodes[i].setChild(
new ChildNodeType(*(s->mNodes[i].getChild()),
953 t->mNodes[i].setValue(b);
957 const OtherInternalNode*
s;
962 template<
typename ChildT, Index Log2Dim>
963 template<
typename OtherChildNodeType>
970 #if OPENVDB_ABI_VERSION_NUMBER >= 9
977 template<
typename ChildT, Index Log2Dim>
978 template<
typename OtherInternalNode>
983 : s(source), t(target), offV(offValue), onV(onValue) {
984 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
987 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
988 if (s->isChildMaskOn(i)) {
989 t->mNodes[i].setChild(
new ChildNodeType(*(s->mNodes[i].getChild()),
992 t->mNodes[i].setValue(s->isValueMaskOn(i) ? onV : offV);
996 const OtherInternalNode*
s;
1001 template<
typename ChildT, Index Log2Dim>
1002 template<
typename OtherChildNodeType>
1010 #if OPENVDB_ABI_VERSION_NUMBER >= 9
1018 template<
typename ChildT, Index Log2Dim>
1031 template<
typename ChildT, Index Log2Dim>
1038 sum += iter->leafCount();
1043 template<
typename ChildT, Index Log2Dim>
1047 assert(vec.size() > ChildNodeType::LEVEL);
1049 if (ChildNodeType::LEVEL > 0 && count > 0) {
1050 for (
auto iter = this->
cbeginChildOn(); iter; ++iter) iter->nodeCount(vec);
1052 vec[ChildNodeType::LEVEL] += count;
1056 template<
typename ChildT, Index Log2Dim>
1063 sum += iter->nonLeafCount();
1069 template<
typename ChildT, Index Log2Dim>
1077 template<
typename ChildT, Index Log2Dim>
1083 sum += iter->onVoxelCount();
1089 template<
typename ChildT, Index Log2Dim>
1095 sum += iter->offVoxelCount();
1101 template<
typename ChildT, Index Log2Dim>
1113 template<
typename ChildT, Index Log2Dim>
1124 template<
typename ChildT, Index Log2Dim>
1130 sum += iter->onTileCount();
1135 template<
typename ChildT, Index Log2Dim>
1142 sum += iter->memUsage();
1148 template<
typename ChildT, Index Log2Dim>
1152 if (bbox.isInside(this->getNodeBoundingBox()))
return;
1155 bbox.expand(i.getCoord(), ChildT::DIM);
1158 i->evalActiveBoundingBox(bbox, visitVoxels);
1166 template<
typename ChildT, Index Log2Dim>
1173 const Index i = iter.pos();
1175 child->prune(tolerance);
1176 if (child->isConstant(value, state, tolerance)) {
1189 template<
typename ChildT, Index Log2Dim>
1190 template<
typename NodeT>
1195 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1206 ?
reinterpret_cast<NodeT*
>(
child)
1207 : child->template stealNode<NodeT>(xyz, value, state);
1215 template<
typename ChildT, Index Log2Dim>
1216 template<
typename NodeT>
1221 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1227 ?
reinterpret_cast<NodeT*
>(
child)
1228 : child->template probeNode<NodeT>(xyz);
1233 template<
typename ChildT, Index Log2Dim>
1234 template<
typename NodeT,
typename AccessorT>
1239 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1244 acc.insert(xyz, child);
1246 ?
reinterpret_cast<NodeT*
>(
child)
1247 : child->template probeNodeAndCache<NodeT>(xyz, acc);
1252 template<
typename ChildT, Index Log2Dim>
1253 template<
typename NodeT>
1258 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1264 ?
reinterpret_cast<const NodeT*
>(
child)
1265 : child->template probeConstNode<NodeT>(xyz);
1270 template<
typename ChildT, Index Log2Dim>
1271 template<
typename NodeT,
typename AccessorT>
1276 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1281 acc.insert(xyz, child);
1283 ?
reinterpret_cast<const NodeT*
>(
child)
1284 : child->template probeConstNodeAndCache<NodeT>(xyz, acc);
1292 template<
typename ChildT, Index Log2Dim>
1293 inline typename ChildT::LeafNodeType*
1296 return this->
template probeNode<LeafNodeType>(xyz);
1300 template<
typename ChildT, Index Log2Dim>
1301 template<
typename AccessorT>
1302 inline typename ChildT::LeafNodeType*
1305 return this->
template probeNodeAndCache<LeafNodeType>(xyz, acc);
1309 template<
typename ChildT, Index Log2Dim>
1310 template<
typename AccessorT>
1311 inline const typename ChildT::LeafNodeType*
1318 template<
typename ChildT, Index Log2Dim>
1319 inline const typename ChildT::LeafNodeType*
1322 return this->
template probeConstNode<LeafNodeType>(xyz);
1326 template<
typename ChildT, Index Log2Dim>
1327 template<
typename AccessorT>
1328 inline const typename ChildT::LeafNodeType*
1331 return this->
template probeConstNodeAndCache<LeafNodeType>(xyz, acc);
1338 template<
typename ChildT, Index Log2Dim>
1342 assert(leaf !=
nullptr);
1343 const Coord& xyz = leaf->origin();
1345 ChildT*
child =
nullptr;
1347 if (ChildT::LEVEL>0) {
1350 child =
reinterpret_cast<ChildT*
>(leaf);
1354 if (ChildT::LEVEL>0) {
1358 child =
reinterpret_cast<ChildT*
>(leaf);
1362 child->addLeaf(leaf);
1366 template<
typename ChildT, Index Log2Dim>
1367 template<
typename AccessorT>
1371 assert(leaf !=
nullptr);
1372 const Coord& xyz = leaf->origin();
1374 ChildT*
child =
nullptr;
1376 if (ChildT::LEVEL>0) {
1378 acc.insert(xyz, child);
1380 child =
reinterpret_cast<ChildT*
>(leaf);
1384 if (ChildT::LEVEL>0) {
1386 acc.insert(xyz, child);
1389 child =
reinterpret_cast<ChildT*
>(leaf);
1393 child->addLeafAndCache(leaf, acc);
1400 template<
typename ChildT, Index Log2Dim>
1405 const Coord& xyz = child->origin();
1407 if (Coord((xyz & ~(
DIM-1))) != this->
origin())
return false;
1416 template<
typename ChildT, Index Log2Dim>
1426 template<
typename ChildT, Index Log2Dim>
1431 if (
LEVEL >= level) {
1434 if (
LEVEL > level) {
1437 child->addTile(level, xyz, value, state);
1444 if (
LEVEL > level) {
1445 child->addTile(level, xyz, value, state);
1457 template<
typename ChildT, Index Log2Dim>
1458 template<
typename AccessorT>
1463 if (
LEVEL >= level) {
1466 if (
LEVEL > level) {
1469 acc.insert(xyz, child);
1470 child->addTileAndCache(level, xyz, value, state, acc);
1477 if (
LEVEL > level) {
1478 acc.insert(xyz, child);
1479 child->addTileAndCache(level, xyz, value, state, acc);
1494 template<
typename ChildT, Index Log2Dim>
1495 inline typename ChildT::LeafNodeType*
1499 ChildT*
child =
nullptr;
1506 return child->touchLeaf(xyz);
1510 template<
typename ChildT, Index Log2Dim>
1511 template<
typename AccessorT>
1512 inline typename ChildT::LeafNodeType*
1519 acc.insert(xyz,
mNodes[n].getChild());
1527 template<
typename ChildT, Index Log2Dim>
1547 template<
typename ChildT, Index Log2Dim>
1560 if ((maxValue - v) > tolerance)
return false;
1562 }
else if (v > maxValue) {
1563 if ((v - minValue) > tolerance)
return false;
1574 template<
typename ChildT, Index Log2Dim>
1582 if (iter->hasActiveTiles())
return true;
1589 template<
typename ChildT, Index Log2Dim>
1598 template<
typename ChildT, Index Log2Dim>
1599 template<
typename AccessorT>
1605 acc.insert(xyz,
mNodes[n].getChild());
1610 template<
typename ChildT, Index Log2Dim>
1611 inline const typename ChildT::ValueType&
1619 template<
typename ChildT, Index Log2Dim>
1620 template<
typename AccessorT>
1621 inline const typename ChildT::ValueType&
1626 acc.insert(xyz,
mNodes[n].getChild());
1633 template<
typename ChildT, Index Log2Dim>
1641 template<
typename ChildT, Index Log2Dim>
1642 template<
typename AccessorT>
1648 acc.insert(xyz,
mNodes[n].getChild());
1655 template<
typename ChildT, Index Log2Dim>
1667 template<
typename ChildT, Index Log2Dim>
1668 template<
typename AccessorT>
1675 acc.insert(xyz,
mNodes[n].getChild());
1676 return mNodes[n].
getChild()->probeValueAndCache(xyz, value, acc);
1683 template<
typename ChildT, Index Log2Dim>
1699 template<
typename ChildT, Index Log2Dim>
1715 template<
typename ChildT, Index Log2Dim>
1734 template<
typename ChildT, Index Log2Dim>
1735 template<
typename AccessorT>
1754 acc.insert(xyz, child);
1755 child->setValueOffAndCache(xyz, value, acc);
1760 template<
typename ChildT, Index Log2Dim>
1779 template<
typename ChildT, Index Log2Dim>
1780 template<
typename AccessorT>
1798 acc.insert(xyz,
mNodes[n].getChild());
1804 template<
typename ChildT, Index Log2Dim>
1820 template<
typename ChildT, Index Log2Dim>
1821 template<
typename AccessorT>
1836 acc.insert(xyz,
mNodes[n].getChild());
1842 template<
typename ChildT, Index Log2Dim>
1860 template<
typename ChildT, Index Log2Dim>
1861 template<
typename AccessorT>
1878 acc.insert(xyz, child);
1879 child->setActiveStateAndCache(xyz, on, acc);
1884 template<
typename ChildT, Index Log2Dim>
1895 template<
typename ChildT, Index Log2Dim>
1896 template<
typename ModifyOp>
1906 bool createChild = !active;
1923 template<
typename ChildT, Index Log2Dim>
1924 template<
typename ModifyOp,
typename AccessorT>
1935 bool createChild = !active;
1951 acc.insert(xyz, child);
1952 child->modifyValueAndCache(xyz, op, acc);
1957 template<
typename ChildT, Index Log2Dim>
1958 template<
typename ModifyOp>
1967 bool modifiedState = !tileState;
1969 op(modifiedVal, modifiedState);
1977 if (hasChild)
mNodes[n].
getChild()->modifyValueAndActiveState(xyz, op);
1980 template<
typename ChildT, Index Log2Dim>
1981 template<
typename ModifyOp,
typename AccessorT>
1984 const Coord& xyz,
const ModifyOp& op, AccessorT& acc)
1991 bool modifiedState = !tileState;
1993 op(modifiedVal, modifiedState);
2003 acc.insert(xyz, child);
2004 child->modifyValueAndActiveStateAndCache(xyz, op, acc);
2012 template<
typename ChildT, Index Log2Dim>
2017 if (!clipBBox.hasOverlap(nodeBBox)) {
2019 this->
fill(nodeBBox, background,
false);
2020 }
else if (clipBBox.isInside(nodeBBox)) {
2031 CoordBBox tileBBox(xyz, xyz.offsetBy(ChildT::DIM - 1));
2032 if (!clipBBox.hasOverlap(tileBBox)) {
2037 }
else if (!clipBBox.isInside(tileBBox)) {
2045 tileBBox.intersect(clipBBox);
2050 this->
fill(tileBBox, val, on);
2062 template<
typename ChildT, Index Log2Dim>
2067 clippedBBox.intersect(bbox);
2068 if (!clippedBBox)
return;
2072 Coord xyz, tileMin, tileMax;
2073 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.x() + 1) {
2075 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.y() + 1) {
2077 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.z() + 1) {
2083 tileMax = tileMin.offsetBy(ChildT::DIM - 1);
2085 if (xyz != tileMin || Coord::lessThan(clippedBBox.max(), tileMax)) {
2089 ChildT*
child =
nullptr;
2102 child->fill(
CoordBBox(xyz, tmp), value, active);
2118 template<
typename ChildT, Index Log2Dim>
2123 clippedBBox.intersect(bbox);
2124 if (!clippedBBox)
return;
2128 Coord xyz, tileMin, tileMax;
2129 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.x() + 1) {
2131 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.y() + 1) {
2133 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.z() + 1) {
2140 ChildT*
child =
nullptr;
2152 tileMax = tileMin.offsetBy(ChildT::DIM - 1);
2155 child->denseFill(
CoordBBox{xyz, clippedBBox.max()},
value, active);
2165 template<
typename ChildT, Index Log2Dim>
2166 template<
typename DenseT>
2170 using DenseValueType =
typename DenseT::ValueType;
2172 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
2173 const Coord&
min = dense.bbox().min();
2174 for (Coord xyz = bbox.min(),
max; xyz[0] <= bbox.max()[0]; xyz[0] =
max[0] + 1) {
2175 for (xyz[1] = bbox.min()[1]; xyz[1] <= bbox.max()[1]; xyz[1] =
max[1] + 1) {
2176 for (xyz[2] = bbox.min()[2]; xyz[2] <= bbox.max()[2]; xyz[2] =
max[2] + 1) {
2188 sub.translate(-min);
2189 DenseValueType* a0 = dense.data() + zStride*sub.min()[2];
2190 for (
Int32 x=sub.min()[0], ex=sub.max()[0]+1; x<ex; ++x) {
2191 DenseValueType* a1 = a0 + x*xStride;
2192 for (
Int32 y=sub.min()[1], ey=sub.max()[1]+1; y<ey; ++y) {
2193 DenseValueType* a2 = a1 + y*yStride;
2194 for (
Int32 z = sub.min()[2], ez = sub.max()[2]+1;
2195 z < ez; ++z, a2 += zStride)
2197 *a2 = DenseValueType(value);
2211 template<
typename ChildT, Index Log2Dim>
2222 const ValueType zero = zeroVal<ValueType>();
2231 iter->writeTopology(os, toHalf);
2236 template<
typename ChildT, Index Log2Dim>
2252 child->readTopology(is);
2255 is.read(reinterpret_cast<char*>(&value),
sizeof(
ValueType));
2260 const bool oldVersion =
2266 std::unique_ptr<ValueType[]> valuePtr(
new ValueType[numValues]);
2276 assert(n == numValues);
2287 child->readTopology(is, fromHalf);
2296 template<
typename ChildT, Index Log2Dim>
2297 inline const typename ChildT::ValueType&
2304 template<
typename ChildT, Index Log2Dim>
2305 inline const typename ChildT::ValueType&
2316 template<
typename ChildT, Index Log2Dim>
2334 template<
typename ChildT, Index Log2Dim>
2339 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2346 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2347 if (mNode->mChildMask.isOn(i)) {
2348 mNode->mNodes[i].getChild()->voxelizeActiveTiles(
true);
2349 }
else if (mNode->mValueMask.isOn(i)) {
2350 const Coord &ijk = mNode->offsetToGlobalCoord(i);
2352 child->voxelizeActiveTiles(
true);
2353 mNode->mNodes[i].setChild(child);
2360 template<
typename ChildT, Index Log2Dim>
2372 iter->voxelizeActiveTiles(
false);
2380 template<
typename ChildT, Index Log2Dim>
2381 template<MergePolicy Policy>
2394 const Index n = iter.pos();
2398 background, otherBackground);
2406 child->resetBackground(otherBackground, background);
2413 const Index n = iter.pos();
2426 const Index n = iter.pos();
2429 mNodes[n].
getChild()->template merge<Policy>(*iter, background, otherBackground);
2437 child->resetBackground(otherBackground, background);
2448 const Index n = iter.pos();
2451 mNodes[n].
getChild()->template merge<Policy>(*iter, background, otherBackground);
2458 child->resetBackground(otherBackground, background);
2471 const Index n = iter.pos();
2474 mNodes[n].
getChild()->template merge<Policy>(iter.getValue(),
true);
2489 template<
typename ChildT, Index Log2Dim>
2490 template<MergePolicy Policy>
2499 if (!tileActive)
return;
2503 const Index n = iter.pos();
2509 iter.setValue(tileValue);
2520 template<
typename ChildT, Index Log2Dim>
2521 template<
typename OtherInternalNode>
2526 { tV = (tV | sV) & ~tC; }
2529 : s(source), t(target), mPreserveTiles(preserveTiles) {
2531 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2534 if (!mPreserveTiles) t->mChildMask |= s->mChildMask;
2535 else t->mChildMask |= (s->mChildMask & !t->mValueMask);
2538 t->mValueMask.foreach(s->mValueMask, t->mChildMask, op);
2539 assert((t->mValueMask & t->mChildMask).isOff());
2542 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2543 if (s->mChildMask.isOn(i)) {
2544 const typename OtherInternalNode::ChildNodeType& other = *(s->mNodes[i].getChild());
2545 if (t->mChildMask.isOn(i)) {
2546 t->mNodes[i].getChild()->topologyUnion(other, mPreserveTiles);
2548 if (!mPreserveTiles || t->mValueMask.isOff(i)) {
2551 t->mNodes[i].setChild(child);
2554 }
else if (s->mValueMask.isOn(i) && t->mChildMask.isOn(i)) {
2555 t->mNodes[i].getChild()->setValuesOn();
2559 const OtherInternalNode*
s;
2564 template<
typename ChildT, Index Log2Dim>
2565 template<
typename OtherChildT>
2572 template<
typename ChildT, Index Log2Dim>
2573 template<
typename OtherInternalNode>
2578 { tC = (tC & (sC | sV)) | (tV & sC); }
2581 const ValueType& background) : s(source), t(target), b(background) {
2583 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2587 t->mChildMask.foreach(s->mChildMask, s->mValueMask, t->mValueMask, op);
2589 t->mValueMask &= s->mValueMask;
2590 assert((t->mValueMask & t->mChildMask).isOff());
2593 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2594 if (t->mChildMask.isOn(i)) {
2595 ChildT*
child = t->mNodes[i].getChild();
2596 if (s->mChildMask.isOn(i)) {
2597 child->topologyIntersection(*(s->mNodes[i].getChild()), b);
2598 }
else if (s->mValueMask.isOff(i)) {
2600 t->mNodes[i].setValue(b);
2602 }
else if (t->mValueMask.isOn(i) && s->mChildMask.isOn(i)) {
2603 t->mNodes[i].setChild(
new ChildT(*(s->mNodes[i].getChild()),
2608 const OtherInternalNode*
s;
2613 template<
typename ChildT, Index Log2Dim>
2614 template<
typename OtherChildT>
2622 template<
typename ChildT, Index Log2Dim>
2623 template<
typename OtherInternalNode>
2628 { tC = (tC & (sC | ~sV)) | (tV & sC); }
2631 { tV &= ~((tC & sV) | (sC | sV)); }
2634 const ValueType& background) : s(source), t(target), b(background) {
2636 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2641 t->mChildMask.foreach(s->mChildMask, s->mValueMask, t->mValueMask, op1);
2644 t->mValueMask.foreach(t->mChildMask, s->mValueMask, oldChildMask, op2);
2645 assert((t->mValueMask & t->mChildMask).isOff());
2648 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2649 if (t->mChildMask.isOn(i)) {
2650 ChildT*
child = t->mNodes[i].getChild();
2651 if (s->mChildMask.isOn(i)) {
2652 child->topologyDifference(*(s->mNodes[i].getChild()), b);
2653 }
else if (s->mValueMask.isOn(i)) {
2655 t->mNodes[i].setValue(b);
2657 }
else if (t->mValueMask.isOn(i)) {
2658 if (s->mChildMask.isOn(i)) {
2659 const typename OtherInternalNode::ChildNodeType& other =
2660 *(s->mNodes[i].getChild());
2661 ChildT*
child =
new ChildT(other.origin(), t->mNodes[i].getValue(),
true);
2663 t->mNodes[i].setChild(child);
2668 const OtherInternalNode*
s;
2673 template<
typename ChildT, Index Log2Dim>
2674 template<
typename OtherChildT>
2686 template<
typename ChildT, Index Log2Dim>
2687 template<
typename CombineOp>
2691 const ValueType zero = zeroVal<ValueType>();
2736 if (child && otherChild) {
2737 child->combine(*otherChild, op);
2744 template<
typename ChildT, Index Log2Dim>
2745 template<
typename CombineOp>
2757 .setBIsActive(valueIsActive));
2764 if (child) child->combine(value, valueIsActive, op);
2773 template<
typename ChildT, Index Log2Dim>
2774 template<
typename CombineOp,
typename OtherNodeType>
2785 .setBRef(other1.mNodes[i].getValue())
2786 .setBIsActive(other1.isValueMaskOn(i)));
2795 : other1.mNodes[i].getChild()->origin();
2804 }
else if (other1.isChildMaskOff(i)) {
2808 other1.mNodes[i].getValue(), other1.isValueMaskOn(i), op);
2813 *other1.mNodes[i].getChild(), op);
2820 template<
typename ChildT, Index Log2Dim>
2821 template<
typename CombineOp,
typename OtherNodeType>
2824 bool valueIsActive, CombineOp& op)
2829 if (other.isChildMaskOff(i)) {
2831 .setAIsActive(valueIsActive)
2832 .setBRef(other.mNodes[i].getValue())
2833 .setBIsActive(other.isValueMaskOn(i)));
2838 typename OtherNodeType::ChildNodeType* otherChild = other.mNodes[i].getChild();
2847 mNodes[i].
getChild()->combine2(value, *otherChild, valueIsActive, op);
2853 template<
typename ChildT, Index Log2Dim>
2854 template<
typename CombineOp,
typename OtherValueType>
2857 bool valueIsActive, CombineOp& op)
2866 .setBIsActive(valueIsActive));
2880 mNodes[i].
getChild()->combine2(*otherChild, value, valueIsActive, op);
2889 template<
typename ChildT, Index Log2Dim>
2890 template<
typename BBoxOp>
2895 op.template operator()<
LEVEL>(CoordBBox::createCube(i.getCoord(), ChildNodeType::DIM));
2897 if (op.template descent<LEVEL>()) {
2901 op.template operator()<
LEVEL>(i->getNodeBoundingBox());
2907 template<
typename ChildT, Index Log2Dim>
2908 template<
typename VisitorOp>
2912 doVisit<InternalNode, VisitorOp, ChildAllIter>(*
this, op);
2916 template<
typename ChildT, Index Log2Dim>
2917 template<
typename VisitorOp>
2921 doVisit<const InternalNode, VisitorOp, ChildAllCIter>(*
this, op);
2925 template<
typename ChildT, Index Log2Dim>
2926 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
2930 typename NodeT::ValueType val;
2931 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
2932 if (op(iter))
continue;
2933 if (
typename ChildAllIterT::ChildNodeType*
child = iter.probeChild(val)) {
2943 template<
typename ChildT, Index Log2Dim>
2944 template<
typename OtherNodeType,
typename VisitorOp>
2949 typename OtherNodeType::ChildAllIter>(*
this, other, op);
2953 template<
typename ChildT, Index Log2Dim>
2954 template<
typename OtherNodeType,
typename VisitorOp>
2959 typename OtherNodeType::ChildAllCIter>(*
this, other, op);
2963 template<
typename ChildT, Index Log2Dim>
2966 typename OtherNodeT,
2968 typename ChildAllIterT,
2969 typename OtherChildAllIterT>
2974 static_assert(OtherNodeT::NUM_VALUES == NodeT::NUM_VALUES,
2975 "visit2() requires nodes to have the same dimensions");
2976 static_assert(OtherNodeT::LEVEL == NodeT::LEVEL,
2977 "visit2() requires nodes to be at the same tree level");
2979 typename NodeT::ValueType val;
2980 typename OtherNodeT::ValueType otherVal;
2982 ChildAllIterT iter =
self.beginChildAll();
2983 OtherChildAllIterT otherIter = other.beginChildAll();
2985 for ( ; iter && otherIter; ++iter, ++otherIter)
2987 const size_t skipBranch =
static_cast<size_t>(op(iter, otherIter));
2989 typename ChildAllIterT::ChildNodeType*
child =
2990 (skipBranch & 1U) ?
nullptr : iter.probeChild(val);
2991 typename OtherChildAllIterT::ChildNodeType* otherChild =
2992 (skipBranch & 2U) ?
nullptr : otherIter.probeChild(otherVal);
2994 if (child !=
nullptr && otherChild !=
nullptr) {
2995 child->visit2Node(*otherChild, op);
2996 }
else if (child !=
nullptr) {
2997 child->visit2(otherIter, op);
2998 }
else if (otherChild !=
nullptr) {
2999 otherChild->visit2(iter, op,
true);
3008 template<
typename ChildT, Index Log2Dim>
3009 template<
typename OtherChildAllIterType,
typename VisitorOp>
3012 VisitorOp& op,
bool otherIsLHS)
3014 doVisit2<InternalNode, VisitorOp, ChildAllIter, OtherChildAllIterType>(
3015 *
this, otherIter, op, otherIsLHS);
3019 template<
typename ChildT, Index Log2Dim>
3020 template<
typename OtherChildAllIterType,
typename VisitorOp>
3023 VisitorOp& op,
bool otherIsLHS)
const 3025 doVisit2<const InternalNode, VisitorOp, ChildAllCIter, OtherChildAllIterType>(
3026 *
this, otherIter, op, otherIsLHS);
3030 template<
typename ChildT, Index Log2Dim>
3031 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT,
typename OtherChildAllIterT>
3034 VisitorOp& op,
bool otherIsLHS)
3036 if (!otherIter)
return;
3038 const size_t skipBitMask = (otherIsLHS ? 2U : 1U);
3040 typename NodeT::ValueType val;
3041 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
3042 const size_t skipBranch =
static_cast<size_t>(
3043 otherIsLHS ? op(otherIter, iter) : op(iter, otherIter));
3045 typename ChildAllIterT::ChildNodeType*
child =
3046 (skipBranch & skipBitMask) ?
nullptr : iter.probeChild(val);
3048 if (child !=
nullptr) child->visit2(otherIter, op, otherIsLHS);
3056 template<
typename ChildT, Index Log2Dim>
3061 iter->writeBuffers(os, toHalf);
3066 template<
typename ChildT, Index Log2Dim>
3071 iter->readBuffers(is, fromHalf);
3076 template<
typename ChildT, Index Log2Dim>
3079 const CoordBBox& clipBBox,
bool fromHalf)
3086 iter->readBuffers(is, clipBBox, fromHalf);
3090 ValueType background = zeroVal<ValueType>();
3092 background = *
static_cast<const ValueType*
>(bgPtr);
3094 this->
clip(clipBBox, background);
3101 template<
typename ChildT, Index Log2Dim>
3105 dims.push_back(Log2Dim);
3106 ChildNodeType::getNodeLog2Dims(dims);
3110 template<
typename ChildT, Index Log2Dim>
3114 assert(n<(1<<3*Log2Dim));
3115 xyz.setX(n >> 2*Log2Dim);
3116 n &= ((1<<2*Log2Dim)-1);
3117 xyz.setY(n >> Log2Dim);
3118 xyz.setZ(n & ((1<<Log2Dim)-1));
3122 template<
typename ChildT, Index Log2Dim>
3126 return (((xyz[0] & (
DIM-1u)) >> ChildNodeType::TOTAL) << 2*Log2Dim)
3127 + (((xyz[1] & (
DIM-1u)) >> ChildNodeType::TOTAL) << Log2Dim)
3128 + ((xyz[2] & (
DIM-1u)) >> ChildNodeType::TOTAL);
3132 template<
typename ChildT, Index Log2Dim>
3138 local <<= ChildT::TOTAL;
3139 return local + this->
origin();
3146 template<
typename ChildT, Index Log2Dim>
3147 template<
typename ArrayT>
3151 using T =
typename ArrayT::value_type;
3153 using ArrayChildT =
typename std::conditional<
3154 std::is_const<typename std::remove_pointer<T>::type>
::value,
const ChildT, ChildT>::type;
3158 array.push_back(reinterpret_cast<T>(
mNodes[iter.pos()].
getChild()));
3160 iter->getNodes(array);
3166 template<
typename ChildT, Index Log2Dim>
3167 template<
typename ArrayT>
3171 using T =
typename ArrayT::value_type;
3173 static_assert(std::is_const<
typename std::remove_pointer<T>::type>::
value,
3174 "argument to getNodes() must be an array of const node pointers");
3178 array.push_back(reinterpret_cast<T>(
mNodes[iter.pos()].
getChild()));
3180 iter->getNodes(array);
3190 template<
typename ChildT, Index Log2Dim>
3191 template<
typename ArrayT>
3195 using T =
typename ArrayT::value_type;
3197 using ArrayChildT =
typename std::conditional<
3198 std::is_const<typename std::remove_pointer<T>::type>
::value,
const ChildT, ChildT>::type;
3201 const Index n = iter.pos();
3203 array.push_back(reinterpret_cast<T>(
mNodes[n].getChild()));
3207 iter->stealNodes(array, value, state);
3218 template<
typename ChildT, Index Log2Dim>
3226 mNodes[i].
getChild()->resetBackground(oldBackground, newBackground);
3237 template<
typename ChildT, Index Log2Dim>
3238 template<
typename OtherChildNodeType, Index OtherLog2Dim>
3246 if (!iter->hasSameTopology(other->
mNodes[iter.pos()].getChild()))
return false;
3252 template<
typename ChildT, Index Log2Dim>
3266 template<
typename ChildT, Index Log2Dim>
3278 template<
typename ChildT, Index Log2Dim>
3293 template<
typename ChildT, Index Log2Dim>
3300 template<
typename ChildT, Index Log2Dim>
3309 template<
typename ChildT, Index Log2Dim>
3310 inline const ChildT*
3321 #endif // OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: InternalNode.h:1591
void merge(InternalNode &other, const ValueType &background, const ValueType &otherBackground)
Efficiently merge another tree into this tree using one of several schemes.
Definition: InternalNode.h:2383
bool isInactive() const
Return true if this node has no children and only contains inactive values.
Definition: InternalNode.h:330
NodeT * stealNode(const Coord &xyz, const ValueType &value, bool state)
Return a pointer to the node of type NodeT that contains voxel (x, y, z) and replace it with a tile o...
Definition: InternalNode.h:1192
const OtherInternalNode * s
Definition: InternalNode.h:2559
NodeType * probeNode(const Coord &xyz)
Return a pointer to the node that contains voxel (x, y, z). If no such node exists, return nullptr.
ChildT * child
Definition: GridBuilder.h:1286
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition: InternalNode.h:2577
const AValueType & result() const
Get the output value.
Definition: Types.h:574
const NodeMaskType & getValueMask() const
Definition: InternalNode.h:772
Index32 mTransientData
Transient data (not serialized)
Definition: InternalNode.h:830
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:29
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: InternalNode.h:1960
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
Definition: InternalNode.h:2120
ChildOnIter beginChildOn()
Definition: InternalNode.h:226
Index64 offVoxelCount() const
Definition: InternalNode.h:1091
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:444
DeepCopy(const OtherInternalNode *source, InternalNode *target)
Definition: InternalNode.h:892
bool isChildMaskOn(Index n) const
Definition: InternalNode.h:769
ChildOffIter beginChildOff()
Definition: InternalNode.h:227
Definition: NodeMasks.h:270
void topologyDifference(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background)
Difference this node's set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this node and inactive in the other node.
void resetChildNode(Index i, ChildNodeType *child)
Definition: InternalNode.h:3254
Index32 leafCount() const
Definition: InternalNode.h:1033
void setItem(Index pos, ChildT *child) const
Definition: InternalNode.h:192
void visit(VisitorOp &)
Definition: InternalNode.h:2910
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:2647
void setValueOnlyAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: InternalNode.h:1823
bool probeValue(const Coord &xyz, ValueType &value) const
Definition: InternalNode.h:1657
bool probeValueAndCache(const Coord &xyz, ValueType &value, AccessorT &) const
Definition: InternalNode.h:1670
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Definition: InternalNode.h:127
ValueOnCIter cbeginValueOn() const
Definition: InternalNode.h:230
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:502
ValueOnCIter beginValueOn() const
Definition: InternalNode.h:234
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:178
ChildOnCIter beginChildOn() const
Definition: InternalNode.h:223
void setValuesOn()
Mark all values (both tiles and voxels) as active.
Definition: InternalNode.h:1886
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information for all active tiles and leaf nodes ...
Definition: InternalNode.h:2892
Definition: InternalNode.h:29
ValueIter()
Definition: InternalNode.h:151
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: InternalNode.h:1529
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: InternalNode.h:1898
bool isChildMaskOff() const
Definition: InternalNode.h:771
static Index32 memUsage()
Return the byte size of this NodeMask.
Definition: NodeMasks.h:441
const OtherInternalNode * s
Definition: InternalNode.h:2668
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: InternalNode.h:131
static Index getLevel()
Definition: InternalNode.h:249
const NodeType * probeConstNode(const Coord &xyz) const
Return a pointer to the node that contains voxel (x, y, z). If no such node exists, return nullptr.
Definition: InternalNode.h:148
typename ChildNodeType::ValueType ValueType
Definition: InternalNode.h:38
void topologyIntersection(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background)
Intersects this tree's set of active values with the active values of the other tree, whose ValueType may be different.
Definition: NodeMasks.h:239
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 readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:465
void readTopology(std::istream &, bool fromHalf=false)
Definition: InternalNode.h:2238
Index64 onVoxelCount() const
Definition: InternalNode.h:1079
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: InternalNode.h:152
Index getValueLevel(const Coord &xyz) const
Return the level of the tree (0 = leaf) at which the value at the given coordinates resides...
Definition: InternalNode.h:1635
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:508
ChildT & getItem(Index pos) const
Definition: InternalNode.h:134
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: InternalNode.h:1737
Definition: InternalNode.h:119
bool getItem(Index pos, ChildT *&child, NonConstValueT &value) const
Definition: InternalNode.h:180
Index getValueLevelAndCache(const Coord &xyz, AccessorT &) const
Return the level of the tree (0 = leaf) at which the value at the given coordinates resides...
Definition: InternalNode.h:1644
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: InternalNode.h:269
Definition: InternalNode.h:120
void modifyItem(Index pos, const ModifyOp &op) const
Definition: InternalNode.h:162
void visit2Node(OtherNodeType &other, VisitorOp &)
Definition: InternalNode.h:2946
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: InternalNode.h:2168
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:457
void addLeaf(LeafNodeType *leaf)
Add the specified leaf to this node, possibly creating a child branch in the process. If the leaf node already exists, replace it.
Definition: InternalNode.h:1340
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:2344
const ValueType & b
Definition: InternalNode.h:2610
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
Index32 countOn() const
Return the total number of on bits.
Definition: NodeMasks.h:443
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:644
Definition: version.h.in:246
Definition: InternalNode.h:2335
Coord mOrigin
Global grid index coordinates (x,y,z) of the local origin of this node.
Definition: InternalNode.h:827
InternalNode * t
Definition: InternalNode.h:997
typename NodeMaskType::Word W
Definition: InternalNode.h:2576
void writeBuffers(std::ostream &, bool toHalf=false) const
Definition: InternalNode.h:3058
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: InternalNode.h:3134
Index32 transientData() const
Return the transient data value.
Definition: InternalNode.h:273
Definition: InternalNode.h:2577
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Expand the specified bounding box so that it includes the active tiles of this internal node as well ...
Definition: InternalNode.h:1150
bool isChildMaskOff(Index n) const
Definition: InternalNode.h:770
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:2541
Definition: InternalNode.h:120
Definition: InternalNode.h:2627
const NodeMaskType & getChildMask() const
Definition: InternalNode.h:773
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1658
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:896
const OtherInternalNode * s
Definition: InternalNode.h:957
const OtherInternalNode * s
Definition: InternalNode.h:905
bool addChild(ChildNodeType *child)
Add the given child node at this level deducing the offset from it's origin. If a child node with thi...
Definition: InternalNode.h:1402
void stealNodes(ArrayT &array, const ValueType &value, bool state)
Steals all nodes of a certain type from the tree and adds them to a container with the following API:...
Definition: InternalNode.h:3193
const ValueType & getValue(const Coord &xyz) const
Definition: InternalNode.h:1612
ChildOnCIter cbeginChildOn() const
Definition: InternalNode.h:220
void topologyUnion(const InternalNode< OtherChildNodeType, Log2Dim > &other, const bool preserveTiles=false)
Union this branch's set of active values with the other branch's active values. The value type of the...
typename NodeMaskType::Word W
Definition: InternalNode.h:2524
void prune(const ValueType &tolerance=zeroVal< ValueType >())
Reduce the memory footprint of this tree by replacing with tiles any nodes whose values are all the s...
Definition: InternalNode.h:1168
static Index getChildDim()
Definition: InternalNode.h:256
Definition: InternalNode.h:817
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition: InternalNode.h:2627
const ValueT & getItem(Index pos) const
Definition: InternalNode.h:155
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:582
TopologyCopy1(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition: InternalNode.h:942
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:529
ChildNodeType * unsetChildNode(Index i, const ValueType &value)
Definition: InternalNode.h:3280
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:462
const ValueType & getFirstValue() const
If the first entry in this node's table is a tile, return the tile's value. Otherwise, return the result of calling getFirstValue() on the child.
Definition: InternalNode.h:2298
void setValueOnly(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: InternalNode.h:1806
ChildAllIter beginChildAll()
Definition: InternalNode.h:228
ValueConverter<T>::Type is the type of an InternalNode having the same child hierarchy and dimensions...
Definition: InternalNode.h:55
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:645
ChildT * getChild() const
Definition: NodeUnion.h:42
NodeMaskType mValueMask
Definition: InternalNode.h:825
void load(std::istream &is)
Definition: NodeMasks.h:569
typename ChildNodeType::LeafNodeType LeafNodeType
Definition: InternalNode.h:37
Index64 onLeafVoxelCount() const
Definition: InternalNode.h:1103
void writeTopology(std::ostream &, bool toHalf=false) const
Definition: InternalNode.h:2213
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return nullptr.
Definition: InternalNode.h:1320
ValueOffCIter beginValueOff() const
Definition: InternalNode.h:236
bool isValueMaskOff(Index n) const
Definition: InternalNode.h:767
typename ChildNodeType::BuildType BuildType
Definition: InternalNode.h:39
Definition: InternalNode.h:119
static const Index DIM
Definition: InternalNode.h:46
typename BaseT::NonConstValueType NonConstValueT
Definition: InternalNode.h:174
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by the node regardless of it...
Definition: InternalNode.h:299
void setChild(ChildT *child)
Definition: NodeUnion.h:43
Definition: InternalNode.h:119
UnionType mNodes[NUM_VALUES]
Definition: InternalNode.h:821
Index64 offLeafVoxelCount() const
Definition: InternalNode.h:1115
void save(std::ostream &os) const
Definition: NodeMasks.h:565
ValueAllCIter cbeginValueAll() const
Definition: InternalNode.h:233
LeafNodeType * touchLeafAndCache(const Coord &xyz, AccessorT &)
Same as touchLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
Index32 nonLeafCount() const
Definition: InternalNode.h:1058
const UnionType * getTable() const
Definition: InternalNode.h:781
TopologyIntersection(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition: InternalNode.h:2580
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: InternalNode.h:1844
ValueAllIter beginValueAll()
Definition: InternalNode.h:241
void unsetItem(Index pos, const ValueT &value) const
Definition: InternalNode.h:198
uint64_t Index64
Definition: Types.h:53
void setItem(Index pos, const ChildT &c) const
Definition: InternalNode.h:141
Definition: Exceptions.h:13
const OtherInternalNode * s
Definition: InternalNode.h:996
DenseIter< const InternalNode, const ChildNodeType, ValueType, ChildAll > ChildAllCIter
Definition: InternalNode.h:211
ChildOffCIter cbeginChildOff() const
Definition: InternalNode.h:221
InternalNode * mNode
Definition: InternalNode.h:2357
Definition: InternalNode.h:170
static void doVisit2Node(NodeT &, OtherNodeT &, VisitorOp &)
Definition: InternalNode.h:2971
void setChildNode(Index i, ChildNodeType *child)
Definition: InternalNode.h:3268
ValueOffCIter cbeginValueOff() const
Definition: InternalNode.h:232
ValueT value
Definition: GridBuilder.h:1287
Definition: InternalNode.h:2525
void setValueAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition: InternalNode.h:1782
Level getLevel()
Return the current logging level.
Definition: logging.h:141
InternalNode()
Default constructor.
Definition: InternalNode.h:72
Definition: InternalNode.h:2630
bool isValueMaskOn() const
Definition: InternalNode.h:766
bool isConstant(bool &isOn) const
Definition: NodeMasks.h:526
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:2592
Index64 Word
Definition: NodeMasks.h:316
bool isValueMaskOff() const
Definition: InternalNode.h:768
void addTile(Index level, const Coord &xyz, const ValueType &value, bool state)
Add a tile at the specified tree level that contains voxel (x, y, z), possibly creating a parent bran...
Definition: InternalNode.h:1428
void readBuffers(std::istream &, bool fromHalf=false)
Definition: InternalNode.h:3068
bool hasSameTopology(const InternalNode< OtherChildNodeType, OtherLog2Dim > *other) const
Return true if the given tree branch has the same node and active value topology as this tree branch ...
Definition: InternalNode.h:3240
NodeType * probeNodeAndCache(const Coord &xyz, AccessorT &)
Same as probeNode() except, if necessary, update the accessor with pointers to the nodes along the pa...
Index64 onTileCount() const
Definition: InternalNode.h:1126
NodeUnion< ValueType, ChildNodeType > UnionType
Definition: InternalNode.h:40
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: InternalNode.h:1701
Index32 Index
Definition: Types.h:54
VoxelizeActiveTiles(InternalNode &node)
Definition: InternalNode.h:2337
Definition: InternalNode.h:820
Definition: InternalNode.h:818
Index32 countOff() const
Return the total number of on bits.
Definition: NodeMasks.h:450
const ValueType & onV
Definition: InternalNode.h:998
ValueAllCIter beginValueAll() const
Definition: InternalNode.h:237
void combine2(const InternalNode &other0, const OtherNodeType &other1, CombineOp &)
Definition: InternalNode.h:2776
bool hasActiveTiles() const
Return true if this node or any of its child nodes have any active tiles.
Definition: InternalNode.h:1576
const OtherInternalNode * s
Definition: InternalNode.h:2608
TopologyUnion(const OtherInternalNode *source, InternalNode *target, const bool preserveTiles)
Definition: InternalNode.h:2528
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: InternalNode.h:1983
LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc)
Same as probeLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
const ValueT & getValue() const
Definition: NodeUnion.h:45
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:127
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: InternalNode.h:3124
void setItem(Index pos, const ValueT &v) const
Definition: InternalNode.h:158
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: InternalNode.h:1926
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:407
Definition: InternalNode.h:120
Index64 memUsage() const
Return the total amount of memory in bytes occupied by this node and its children.
Definition: InternalNode.h:1137
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition: InternalNode.h:2362
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition: InternalNode.h:3149
const NodeType * probeConstNodeAndCache(const Coord &xyz, AccessorT &) const
Same as probeNode() except, if necessary, update the accessor with pointers to the nodes along the pa...
DenseIter()
Definition: InternalNode.h:176
Index32 childCount() const
Definition: InternalNode.h:1071
void negate()
Change the sign of all the values represented in this node and its child nodes.
Definition: InternalNode.h:2318
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:986
_ChildNodeType ChildNodeType
Definition: InternalNode.h:36
InternalNode * t
Definition: InternalNode.h:2609
void addLeafAndCache(LeafNodeType *leaf, AccessorT &)
Same as addLeaf() except, if necessary, update the accessor with pointers to the nodes along the path...
Definition: InternalNode.h:1369
const ValueType & getLastValue() const
If the last entry in this node's table is a tile, return the tile's value. Otherwise, return the result of calling getLastValue() on the child.
Definition: InternalNode.h:2306
typename NodeMaskType::Word W
Definition: InternalNode.h:2626
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Change inactive tiles or voxels with value oldBackground to newBackground or -oldBackground to -newBa...
Definition: InternalNode.h:3220
ChildOffCIter beginChildOff() const
Definition: InternalNode.h:224
Definition: InternalNode.h:819
NodeMaskType getValueOffMask() const
Definition: InternalNode.h:774
const ValueType & b
Definition: InternalNode.h:2670
int32_t Int32
Definition: Types.h:56
InternalNode * t
Definition: InternalNode.h:906
ChildNodeType * getChildNode(Index n)
Returns a pointer to the child node at the linear offset n.
Definition: InternalNode.h:3302
void setTransientData(Index32 transientData)
Set the transient data value.
Definition: InternalNode.h:275
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition: InternalNode.h:116
InternalNode * t
Definition: InternalNode.h:2560
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:307
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, return nullptr.
Definition: InternalNode.h:1294
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition: NodeMasks.h:483
static const Index NUM_VALUES
Definition: InternalNode.h:47
Tag dispatch class that distinguishes constructors during file input.
Definition: Types.h:650
void operator()(const tbb::blocked_range< Index > &r) const
Definition: InternalNode.h:947
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: InternalNode.h:335
const LeafNodeType * probeConstLeafAndCache(const Coord &xyz, AccessorT &acc) const
Same as probeLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
static void getNodeLog2Dims(std::vector< Index > &dims)
Populated an std::vector with the dimension of all the nodes in the branch starting with this node...
Definition: InternalNode.h:3103
InternalNode * t
Definition: InternalNode.h:2669
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
const ValueType & b
Definition: InternalNode.h:959
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:508
static void doVisit2(NodeT &, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: InternalNode.h:3033
~InternalNode()
Definition: InternalNode.h:1020
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
void nodeCount(std::vector< Index32 > &vec) const
Definition: InternalNode.h:1045
LeafNodeType * touchLeaf(const Coord &xyz)
Return the leaf node that contains voxel (x, y, z). If no such node exists, create one...
Definition: InternalNode.h:1496
void addTileAndCache(Index level, const Coord &xyz, const ValueType &, bool state, AccessorT &)
Same as addTile() except, if necessary, update the accessor with pointers to the nodes along the path...
Definition: InternalNode.h:1460
bool isEmpty() const
Definition: InternalNode.h:302
Definition: NodeMasks.h:208
uint32_t Index32
Definition: Types.h:52
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: InternalNode.h:1685
const bool mPreserveTiles
Definition: InternalNode.h:2561
void combine(InternalNode &other, CombineOp &)
Definition: InternalNode.h:2689
typename NodeMaskType::OffIterator MaskOffIterator
Definition: InternalNode.h:115
Definition: InternalNode.h:33
Definition: version.h.in:237
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: InternalNode.h:2064
TopologyDifference(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition: InternalNode.h:2633
InternalNode * t
Definition: InternalNode.h:958
ValueOffIter beginValueOff()
Definition: InternalNode.h:240
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: InternalNode.h:2014
typename NodeMaskType::OnIterator MaskOnIterator
Definition: InternalNode.h:114
static void doVisit(NodeT &, VisitorOp &)
Definition: InternalNode.h:2928
ValueOnIter beginValueOn()
Definition: InternalNode.h:238
ChildAllCIter cbeginChildAll() const
Definition: InternalNode.h:222
DenseIter< InternalNode, ChildNodeType, ValueType, ChildAll > ChildAllIter
Definition: InternalNode.h:210
ChildAllCIter beginChildAll() const
Definition: InternalNode.h:225
ValueType combine(const ValueType &v0, const ValueType &v1, const ValueType &v2, const openvdb::Vec3d &w)
Combine different value types.
Definition: AttributeTransferUtil.h:141
void makeChildNodeEmpty(Index n, const ValueType &value)
Definition: InternalNode.h:3295
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Definition: InternalNode.h:1863
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Definition: InternalNode.h:1601
static Index dim()
Definition: InternalNode.h:246
ChildIter()
Definition: InternalNode.h:130
void operator()(W &tV, const W &sV, const W &tC) const
Definition: InternalNode.h:2525
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:114
bool resultIsActive() const
Definition: Types.h:593
Definition: InternalNode.h:816
static const Index LEVEL
Definition: InternalNode.h:48
void setValue(const ValueT &val)
Definition: NodeUnion.h:47
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of an Intern...
Definition: InternalNode.h:64
typename std::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:184
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:452
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: InternalNode.h:177
NodeMaskType mChildMask
Definition: InternalNode.h:825
TopologyCopy2(const OtherInternalNode *source, InternalNode *target, const ValueType &offValue, const ValueType &onValue)
Definition: InternalNode.h:981
void operator()(W &tV, const W &sC, const W &sV, const W &tC) const
Definition: InternalNode.h:2630
bool isValueMaskOn(Index n) const
Definition: InternalNode.h:765
static void offsetToLocalCoord(Index n, Coord &xyz)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: InternalNode.h:3112
Definition: InternalNode.h:821
void setValueMask(Index n, bool on)
Definition: InternalNode.h:786
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: InternalNode.h:267