8#ifndef OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED
9#define OPENVDB_TREE_INTERNALNODE_HAS_BEEN_INCLUDED
16#include <openvdb/version.h>
20#include <tbb/parallel_for.h>
30template<
typename, Index,
typename>
struct SameInternalConfig;
33template<
typename _ChildNodeType, Index Log2Dim>
39 using ValueType =
typename ChildNodeType::ValueType;
40 using BuildType =
typename ChildNodeType::BuildType;
46 TOTAL = Log2Dim + ChildNodeType::TOTAL,
49 LEVEL = 1 + ChildNodeType::LEVEL;
55 template<
typename OtherValueType>
58 OtherValueType>
::Type, Log2Dim>;
64 template<
typename OtherNodeType>
95 template<
typename OtherChildNodeType>
101 template<
typename OtherChildNodeType>
108 template<
typename OtherChildNodeType>
127 template<
typename NodeT,
typename ChildT,
typename MaskIterT,
typename TagT>
129 MaskIterT, ChildIter<NodeT, ChildT, MaskIterT, TagT>, NodeT, ChildT>
138 return *(this->
parent().getChildNode(
pos));
148 template<
typename NodeT,
typename ValueT,
typename MaskIterT,
typename TagT>
150 MaskIterT, ValueIter<NodeT, ValueT, MaskIterT, TagT>, NodeT, ValueT>
162 template<
typename ModifyOp>
170 template<
typename NodeT,
typename ChildT,
typename ValueT,
typename TagT>
172 MaskDenseIterator, DenseIter<NodeT, ChildT, ValueT, TagT>, NodeT, ChildT, ValueT>
184 child = this->
parent().getChildNode(
pos);
188 value = this->
parent().mNodes[
pos].getValue();
195 this->
parent().resetChildNode(
pos, child);
201 this->
parent().unsetChildNode(
pos, value);
207 using ChildOnIter = ChildIter<InternalNode, ChildNodeType, MaskOnIterator, ChildOn>;
208 using ChildOnCIter = ChildIter<const InternalNode,const ChildNodeType,MaskOnIterator,ChildOn>;
209 using ChildOffIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ChildOff>;
210 using ChildOffCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ChildOff>;
211 using ChildAllIter = DenseIter<InternalNode, ChildNodeType, ValueType, ChildAll>;
212 using ChildAllCIter = DenseIter<const InternalNode,const ChildNodeType, ValueType, ChildAll>;
214 using ValueOnIter = ValueIter<InternalNode, const ValueType, MaskOnIterator, ValueOn>;
215 using ValueOnCIter = ValueIter<const InternalNode, const ValueType, MaskOnIterator, ValueOn>;
216 using ValueOffIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ValueOff>;
217 using ValueOffCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ValueOff>;
218 using ValueAllIter = ValueIter<InternalNode, const ValueType, MaskOffIterator, ValueAll>;
219 using ValueAllCIter = ValueIter<const InternalNode,const ValueType,MaskOffIterator,ValueAll>;
374 template<
typename ModifyOp>
377 template<
typename ModifyOp>
384 template<
typename AccessorT>
391 template<
typename AccessorT>
398 template<
typename AccessorT>
405 template<
typename AccessorT>
413 template<
typename ModifyOp,
typename AccessorT>
420 template<
typename ModifyOp,
typename AccessorT>
427 template<
typename AccessorT>
434 template<
typename AccessorT>
442 template<
typename AccessorT>
451 template<
typename AccessorT>
578 template<
typename DenseT>
583 template<MergePolicy Policy>
588 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
602 template<
typename OtherChildNodeType>
618 template<
typename OtherChildNodeType>
633 template<
typename OtherChildNodeType>
637 template<
typename CombineOp>
639 template<
typename CombineOp>
642 template<
typename CombineOp,
typename OtherNodeType >
644 template<
typename CombineOp,
typename OtherNodeType >
645 void combine2(
const ValueType& value,
const OtherNodeType& other,
bool valIsActive, CombineOp&);
646 template<
typename CombineOp,
typename OtherValueType>
663 template<
typename AccessorT>
674 template<
typename NodeT>
694 template<
typename AccessorT>
744 template<
typename NodeType,
typename AccessorT>
746 template<
typename NodeType,
typename AccessorT>
761 template<
typename AccessorT>
763 template<
typename AccessorT>
765 template<
typename AccessorT>
779 template<
typename AccessorT>
805 template<
typename ArrayT>
807 template<
typename ArrayT>
834 template<
typename ArrayT>
843 template<
typename OtherChildNodeType, Index OtherLog2Dim>
900 struct VoxelizeActiveTiles;
901 template<
typename OtherInternalNode>
struct DeepCopy;
902 template<
typename OtherInternalNode>
struct TopologyCopy1;
903 template<
typename OtherInternalNode>
struct TopologyCopy2;
904 template<
typename OtherInternalNode>
struct TopologyUnion;
905 template<
typename OtherInternalNode>
struct TopologyDifference;
906 template<
typename OtherInternalNode>
struct TopologyIntersection;
924template<
typename ChildT1, Index Dim1,
typename NodeT2>
929template<
typename ChildT1, Index Dim1,
typename ChildT2>
931 static const bool value = ChildT1::template SameConfiguration<ChildT2>::value;
939template<
typename ChildT, Index Log2Dim>
947template<
typename ChildT, Index Log2Dim>
961template<
typename ChildT, Index Log2Dim>
971template<
typename ChildT, Index Log2Dim>
972template<
typename OtherInternalNode>
976 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
980 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
981 if (
s->mChildMask.isOff(i)) {
982 t->mNodes[i].setValue(
ValueType(
s->mNodes[i].getValue()));
988 const OtherInternalNode*
s;
992template<
typename ChildT, Index Log2Dim>
1005template<
typename ChildT, Index Log2Dim>
1006template<
typename OtherChildNodeType>
1017template<
typename ChildT, Index Log2Dim>
1018template<
typename OtherInternalNode>
1022 const ValueType& background) :
s(source),
t(target),
b(background) {
1023 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
1027 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
1028 if (
s->isChildMaskOn(i)) {
1032 t->mNodes[i].setValue(
b);
1036 const OtherInternalNode*
s;
1041template<
typename ChildT, Index Log2Dim>
1042template<
typename OtherChildNodeType>
1054template<
typename ChildT, Index Log2Dim>
1055template<
typename OtherInternalNode>
1060 :
s(source),
t(target),
offV(offValue),
onV(onValue) {
1061 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
1064 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
1065 if (
s->isChildMaskOn(i)) {
1069 t->mNodes[i].setValue(
s->isValueMaskOn(i) ?
onV :
offV);
1073 const OtherInternalNode*
s;
1078template<
typename ChildT, Index Log2Dim>
1079template<
typename OtherChildNodeType>
1093template<
typename ChildT, Index Log2Dim>
1106template<
typename ChildT, Index Log2Dim>
1110 if (ChildNodeType::getLevel() == 0)
return mChildMask.countOn();
1113 sum +=
iter->leafCount();
1118template<
typename ChildT, Index Log2Dim>
1124 if (ChildNodeType::LEVEL > 0 && count > 0) {
1127 vec[ChildNodeType::LEVEL] += count;
1130template<
typename ChildT, Index Log2Dim>
1136 if (ChildNodeType::LEVEL > 0 && count > 0) {
1139 iter->nodeCount(vec);
1143 vec[ChildNodeType::LEVEL] += count;
1147template<
typename ChildT, Index Log2Dim>
1152 if (ChildNodeType::getLevel() == 0)
return sum;
1154 sum +=
iter->nonLeafCount();
1160template<
typename ChildT, Index Log2Dim>
1168template<
typename ChildT, Index Log2Dim>
1174 sum +=
iter->onVoxelCount();
1180template<
typename ChildT, Index Log2Dim>
1186 sum +=
iter->offVoxelCount();
1192template<
typename ChildT, Index Log2Dim>
1198 sum +=
mNodes[
iter.pos()].getChild()->onLeafVoxelCount();
1204template<
typename ChildT, Index Log2Dim>
1210 sum +=
mNodes[
iter.pos()].getChild()->offLeafVoxelCount();
1215template<
typename ChildT, Index Log2Dim>
1221 sum +=
iter->onTileCount();
1226template<
typename ChildT, Index Log2Dim>
1233 sum +=
iter->memUsage();
1239template<
typename ChildT, Index Log2Dim>
1243 if (bbox.
isInside(this->getNodeBoundingBox()))
return;
1246 bbox.
expand(i.getCoord(), ChildT::DIM);
1249 i->evalActiveBoundingBox(bbox, visitVoxels);
1257template<
typename ChildT, Index Log2Dim>
1265 ChildT* child =
mNodes[i].getChild();
1266 child->prune(tolerance);
1267 if (child->isConstant(value, state, tolerance)) {
1271 mNodes[i].setValue(value);
1280template<
typename ChildT, Index Log2Dim>
1281template<
typename NodeT>
1285 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1286 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1290 ChildT* child =
mNodes[n].getChild();
1291 if (std::is_same<NodeT, ChildT>::value) {
1294 mNodes[n].setValue(value);
1296 return (std::is_same<NodeT, ChildT>::value)
1297 ?
reinterpret_cast<NodeT*
>(child)
1306template<
typename ChildT, Index Log2Dim>
1307template<
typename NodeT>
1311 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1312 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1316 ChildT* child =
mNodes[n].getChild();
1317 return (std::is_same<NodeT, ChildT>::value)
1318 ?
reinterpret_cast<NodeT*
>(child)
1324template<
typename ChildT, Index Log2Dim>
1325template<
typename NodeT,
typename AccessorT>
1329 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1330 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1334 ChildT* child =
mNodes[n].getChild();
1335 acc.insert(xyz, child);
1336 return (std::is_same<NodeT, ChildT>::value)
1337 ?
reinterpret_cast<NodeT*
>(child)
1343template<
typename ChildT, Index Log2Dim>
1344template<
typename NodeT>
1348 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1349 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1353 const ChildT* child =
mNodes[n].getChild();
1354 return (std::is_same<NodeT, ChildT>::value)
1355 ?
reinterpret_cast<const NodeT*
>(child)
1361template<
typename ChildT, Index Log2Dim>
1362template<
typename NodeT,
typename AccessorT>
1366 if ((NodeT::LEVEL == ChildT::LEVEL && !(std::is_same<NodeT, ChildT>::value)) ||
1367 NodeT::LEVEL > ChildT::LEVEL)
return nullptr;
1371 const ChildT* child =
mNodes[n].getChild();
1372 acc.insert(xyz, child);
1373 return (std::is_same<NodeT, ChildT>::value)
1374 ?
reinterpret_cast<const NodeT*
>(child)
1383template<
typename ChildT, Index Log2Dim>
1391template<
typename ChildT, Index Log2Dim>
1399template<
typename ChildT, Index Log2Dim>
1407template<
typename ChildT, Index Log2Dim>
1415template<
typename ChildT, Index Log2Dim>
1424template<
typename ChildT, Index Log2Dim>
1433template<
typename ChildT, Index Log2Dim>
1439 value =
mNodes[offset].getValue();
1444template<
typename ChildT, Index Log2Dim>
1450 value =
mNodes[offset].getValue();
1459template<
typename ChildT, Index Log2Dim>
1460inline typename ChildT::LeafNodeType*
1467template<
typename ChildT, Index Log2Dim>
1468template<
typename AccessorT>
1469inline typename ChildT::LeafNodeType*
1476template<
typename ChildT, Index Log2Dim>
1477template<
typename AccessorT>
1478inline const typename ChildT::LeafNodeType*
1485template<
typename ChildT, Index Log2Dim>
1486inline const typename ChildT::LeafNodeType*
1493template<
typename ChildT, Index Log2Dim>
1494template<
typename AccessorT>
1495inline const typename ChildT::LeafNodeType*
1505template<
typename ChildT, Index Log2Dim>
1510 const Coord& xyz = leaf->origin();
1512 ChildT* child =
nullptr;
1514 if (ChildT::LEVEL>0) {
1517 child =
reinterpret_cast<ChildT*
>(leaf);
1521 if (ChildT::LEVEL>0) {
1522 child =
mNodes[n].getChild();
1524 delete mNodes[n].getChild();
1525 child =
reinterpret_cast<ChildT*
>(leaf);
1526 mNodes[n].setChild(child);
1529 child->addLeaf(leaf);
1533template<
typename ChildT, Index Log2Dim>
1534template<
typename AccessorT>
1539 const Coord& xyz = leaf->origin();
1541 ChildT* child =
nullptr;
1543 if (ChildT::LEVEL>0) {
1545 acc.insert(xyz, child);
1547 child =
reinterpret_cast<ChildT*
>(leaf);
1551 if (ChildT::LEVEL>0) {
1552 child =
mNodes[n].getChild();
1553 acc.insert(xyz, child);
1555 delete mNodes[n].getChild();
1556 child =
reinterpret_cast<ChildT*
>(leaf);
1557 mNodes[n].setChild(child);
1560 child->addLeafAndCache(leaf, acc);
1567template<
typename ChildT, Index Log2Dim>
1572 const Coord& xyz = child->origin();
1583template<
typename ChildT, Index Log2Dim>
1593template<
typename ChildT, Index Log2Dim>
1598 if (
LEVEL >= level) {
1601 if (
LEVEL > level) {
1604 child->addTile(level, xyz, value, state);
1607 mNodes[n].setValue(value);
1610 ChildT* child =
mNodes[n].getChild();
1611 if (
LEVEL > level) {
1612 child->addTile(level, xyz, value, state);
1617 mNodes[n].setValue(value);
1624template<
typename ChildT, Index Log2Dim>
1625template<
typename AccessorT>
1628 const ValueType& value,
bool state, AccessorT& acc)
1630 if (
LEVEL >= level) {
1633 if (
LEVEL > level) {
1636 acc.insert(xyz, child);
1637 child->addTileAndCache(level, xyz, value, state, acc);
1640 mNodes[n].setValue(value);
1643 ChildT* child =
mNodes[n].getChild();
1644 if (
LEVEL > level) {
1645 acc.insert(xyz, child);
1646 child->addTileAndCache(level, xyz, value, state, acc);
1651 mNodes[n].setValue(value);
1661template<
typename ChildT, Index Log2Dim>
1662inline typename ChildT::LeafNodeType*
1666 ChildT* child =
nullptr;
1671 child =
mNodes[n].getChild();
1673 return child->touchLeaf(xyz);
1677template<
typename ChildT, Index Log2Dim>
1678template<
typename AccessorT>
1679inline typename ChildT::LeafNodeType*
1686 acc.insert(xyz,
mNodes[n].getChild());
1687 return mNodes[n].getChild()->touchLeafAndCache(xyz, acc);
1694template<
typename ChildT, Index Log2Dim>
1701 firstValue =
mNodes[0].getValue();
1714template<
typename ChildT, Index Log2Dim>
1723 minValue = maxValue =
mNodes[0].getValue();
1727 if ((maxValue - v) > tolerance)
return false;
1729 }
else if (v > maxValue) {
1730 if ((v - minValue) > tolerance)
return false;
1741template<
typename ChildT, Index Log2Dim>
1746 const bool anyActiveTiles = !
mValueMask.isOff();
1747 if (
LEVEL==1 || anyActiveTiles)
return anyActiveTiles;
1749 if (
iter->hasActiveTiles())
return true;
1756template<
typename ChildT, Index Log2Dim>
1762 :
mNodes[n].getChild()->isValueOn(xyz);
1765template<
typename ChildT, Index Log2Dim>
1771 :
mNodes[n].getChild()->isValueOff(xyz);
1774template<
typename ChildT, Index Log2Dim>
1775template<
typename AccessorT>
1781 acc.insert(xyz,
mNodes[n].getChild());
1782 return mNodes[n].getChild()->isValueOnAndCache(xyz, acc);
1786template<
typename ChildT, Index Log2Dim>
1787inline const typename ChildT::ValueType&
1792 :
mNodes[n].getChild()->getValue(xyz);
1795template<
typename ChildT, Index Log2Dim>
1796template<
typename AccessorT>
1797inline const typename ChildT::ValueType&
1802 acc.insert(xyz,
mNodes[n].getChild());
1803 return mNodes[n].getChild()->getValueAndCache(xyz, acc);
1805 return mNodes[n].getValue();
1809template<
typename ChildT, Index Log2Dim>
1817template<
typename ChildT, Index Log2Dim>
1818template<
typename AccessorT>
1824 acc.insert(xyz,
mNodes[n].getChild());
1825 return mNodes[n].getChild()->getValueLevelAndCache(xyz, acc);
1831template<
typename ChildT, Index Log2Dim>
1837 value =
mNodes[n].getValue();
1840 return mNodes[n].getChild()->probeValue(xyz, value);
1843template<
typename ChildT, Index Log2Dim>
1844template<
typename AccessorT>
1851 acc.insert(xyz,
mNodes[n].getChild());
1852 return mNodes[n].getChild()->probeValueAndCache(xyz, value, acc);
1854 value =
mNodes[n].getValue();
1859template<
typename ChildT, Index Log2Dim>
1871 if (hasChild)
mNodes[n].getChild()->setValueOff(xyz);
1875template<
typename ChildT, Index Log2Dim>
1887 if (hasChild)
mNodes[n].getChild()->setValueOn(xyz);
1891template<
typename ChildT, Index Log2Dim>
1907 if (hasChild)
mNodes[n].getChild()->setValueOff(xyz, value);
1910template<
typename ChildT, Index Log2Dim>
1911template<
typename AccessorT>
1929 ChildT* child =
mNodes[n].getChild();
1930 acc.insert(xyz, child);
1931 child->setValueOffAndCache(xyz, value, acc);
1936template<
typename ChildT, Index Log2Dim>
1952 if (hasChild)
mNodes[n].getChild()->setValueOn(xyz, value);
1955template<
typename ChildT, Index Log2Dim>
1956template<
typename AccessorT>
1974 acc.insert(xyz,
mNodes[n].getChild());
1975 mNodes[n].getChild()->setValueAndCache(xyz, value, acc);
1980template<
typename ChildT, Index Log2Dim>
1993 if (hasChild)
mNodes[n].getChild()->setValueOnly(xyz, value);
1996template<
typename ChildT, Index Log2Dim>
1997template<
typename AccessorT>
2012 acc.insert(xyz,
mNodes[n].getChild());
2013 mNodes[n].getChild()->setValueOnlyAndCache(xyz, value, acc);
2018template<
typename ChildT, Index Log2Dim>
2033 if (hasChild)
mNodes[n].getChild()->setActiveState(xyz, on);
2036template<
typename ChildT, Index Log2Dim>
2037template<
typename AccessorT>
2053 ChildT* child =
mNodes[n].getChild();
2054 acc.insert(xyz, child);
2055 child->setActiveStateAndCache(xyz, on, acc);
2060template<
typename ChildT, Index Log2Dim>
2066 mNodes[
iter.pos()].getChild()->setValuesOn();
2071template<
typename ChildT, Index Log2Dim>
2072template<
typename ModifyOp>
2082 bool createChild = !active;
2096 if (hasChild)
mNodes[n].getChild()->modifyValue(xyz, op);
2099template<
typename ChildT, Index Log2Dim>
2100template<
typename ModifyOp,
typename AccessorT>
2111 bool createChild = !active;
2127 acc.insert(xyz, child);
2128 child->modifyValueAndCache(xyz, op, acc);
2133template<
typename ChildT, Index Log2Dim>
2134template<
typename ModifyOp>
2143 bool modifiedState = !tileState;
2145 op(modifiedVal, modifiedState);
2153 if (hasChild)
mNodes[n].getChild()->modifyValueAndActiveState(xyz, op);
2156template<
typename ChildT, Index Log2Dim>
2157template<
typename ModifyOp,
typename AccessorT>
2160 const Coord& xyz,
const ModifyOp& op, AccessorT& acc)
2167 bool modifiedState = !tileState;
2169 op(modifiedVal, modifiedState);
2179 acc.insert(xyz, child);
2180 child->modifyValueAndActiveStateAndCache(xyz, op, acc);
2188template<
typename ChildT, Index Log2Dim>
2195 this->
fill(nodeBBox, background,
false);
2196 }
else if (clipBBox.
isInside(nodeBBox)) {
2213 }
else if (!clipBBox.
isInside(tileBBox)) {
2217 mNodes[pos].getChild()->clip(clipBBox, background);
2224 mNodes[pos].setValue(background);
2226 this->
fill(tileBBox, val, on);
2238template<
typename ChildT, Index Log2Dim>
2243 clippedBBox.intersect(bbox);
2244 if (!clippedBBox)
return;
2248 Coord xyz, tileMin, tileMax;
2249 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.
x() + 1) {
2251 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.
y() + 1) {
2253 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.
z() + 1) {
2259 tileMax = tileMin.
offsetBy(ChildT::DIM - 1);
2265 ChildT* child =
nullptr;
2272 child =
mNodes[n].getChild();
2278 child->fill(
CoordBBox(xyz, tmp), value, active);
2294template<
typename ChildT, Index Log2Dim>
2299 clippedBBox.intersect(bbox);
2300 if (!clippedBBox)
return;
2304 Coord xyz, tileMin, tileMax;
2305 for (
int x = clippedBBox.min().x(); x <= clippedBBox.max().x(); x = tileMax.
x() + 1) {
2307 for (
int y = clippedBBox.min().y(); y <= clippedBBox.max().y(); y = tileMax.
y() + 1) {
2309 for (
int z = clippedBBox.min().z(); z <= clippedBBox.max().z(); z = tileMax.
z() + 1) {
2316 ChildT* child =
nullptr;
2318 child =
mNodes[n].getChild();
2328 tileMax = tileMin.
offsetBy(ChildT::DIM - 1);
2331 child->denseFill(
CoordBBox{xyz, clippedBBox.
max()}, value, active);
2341template<
typename ChildT, Index Log2Dim>
2342template<
typename DenseT>
2346 using DenseValueType =
typename DenseT::ValueType;
2348 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
2349 const Coord& min = dense.bbox().min();
2350 for (
Coord xyz = bbox.
min(), max; xyz[0] <= bbox.
max()[0]; xyz[0] = max[0] + 1) {
2351 for (xyz[1] = bbox.
min()[1]; xyz[1] <= bbox.
max()[1]; xyz[1] = max[1] + 1) {
2352 for (xyz[2] = bbox.
min()[2]; xyz[2] <= bbox.
max()[2]; xyz[2] = max[2] + 1) {
2361 mNodes[n].getChild()->copyToDense(sub, dense);
2365 DenseValueType* a0 = dense.data() + zStride*sub.
min()[2];
2366 for (
Int32 x=sub.
min()[0], ex=sub.
max()[0]+1; x<ex; ++x) {
2367 DenseValueType* a1 = a0 + x*xStride;
2368 for (
Int32 y=sub.
min()[1], ey=sub.
max()[1]+1; y<ey; ++y) {
2369 DenseValueType* a2 = a1 + y*yStride;
2371 z < ez; ++z, a2 += zStride)
2373 *a2 = DenseValueType(value);
2387template<
typename ChildT, Index Log2Dim>
2407 iter->writeTopology(os, toHalf);
2412template<
typename ChildT, Index Log2Dim>
2427 mNodes[i].setChild(child);
2428 child->readTopology(is);
2431 is.read(
reinterpret_cast<char*
>(&value),
sizeof(
ValueType));
2432 mNodes[i].setValue(value);
2436 const bool oldVersion =
2442 std::unique_ptr<ValueType[]> valuePtr(
new ValueType[numValues]);
2463 child->readTopology(is, fromHalf);
2472template<
typename ChildT, Index Log2Dim>
2473inline const typename ChildT::ValueType&
2480template<
typename ChildT, Index Log2Dim>
2481inline const typename ChildT::ValueType&
2492template<
typename ChildT, Index Log2Dim>
2493inline const typename ChildT::ValueType&
2498 return mNodes[n].getValue();
2501template<
typename ChildT, Index Log2Dim>
2507 value =
mNodes[n].getValue();
2511template<
typename ChildT, Index Log2Dim>
2517 return mNodes[n].getChild();
2520template<
typename ChildT, Index Log2Dim>
2526 return mNodes[n].getChild();
2529template<
typename ChildT, Index Log2Dim>
2536template<
typename ChildT, Index Log2Dim>
2545template<
typename ChildT, Index Log2Dim>
2551 mNodes[n].setValue(value);
2554template<
typename ChildT, Index Log2Dim>
2563template<
typename ChildT, Index Log2Dim>
2569 mNodes[n].setValue(value);
2573template<
typename ChildT, Index Log2Dim>
2582template<
typename ChildT, Index Log2Dim>
2588 mNodes[n].setValue(value);
2592template<
typename ChildT, Index Log2Dim>
2599 mNodes[n].setChild(child);
2604template<
typename ChildT, Index Log2Dim>
2612 delete mNodes[n].getChild();
2613 mNodes[n].setChild(child);
2616template<
typename ChildT, Index Log2Dim>
2623 auto* child =
mNodes[n].getChild();
2626 mNodes[n].setValue(value);
2630template<
typename ChildT, Index Log2Dim>
2642template<
typename ChildT, Index Log2Dim>
2648 mNodes[i].getChild()->negate();
2660template<
typename ChildT, Index Log2Dim>
2665 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2672 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2673 if (
mNode->mChildMask.isOn(i)) {
2674 mNode->mNodes[i].getChild()->voxelizeActiveTiles(
true);
2675 }
else if (
mNode->mValueMask.isOn(i)) {
2676 const Coord &ijk =
mNode->offsetToGlobalCoord(i);
2678 child->voxelizeActiveTiles(
true);
2679 mNode->mNodes[i].setChild(child);
2686template<
typename ChildT, Index Log2Dim>
2698 iter->voxelizeActiveTiles(
false);
2706template<
typename ChildT, Index Log2Dim>
2707template<MergePolicy Policy>
2724 background, otherBackground);
2732 child->resetBackground(otherBackground, background);
2763 child->resetBackground(otherBackground, background);
2784 child->resetBackground(otherBackground, background);
2791 mNodes[n].setChild(child);
2815template<
typename ChildT, Index Log2Dim>
2816template<MergePolicy Policy>
2825 if (!tileActive)
return;
2835 iter.setValue(tileValue);
2846template<
typename ChildT, Index Log2Dim>
2847template<
typename OtherInternalNode>
2852 { tV = (tV | sV) & ~tC; }
2857 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2861 else t->mChildMask |= (
s->mChildMask & !
t->mValueMask);
2864 t->mValueMask.foreach(
s->mValueMask,
t->mChildMask, op);
2868 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2869 if (
s->mChildMask.isOn(i)) {
2870 const typename OtherInternalNode::ChildNodeType& other = *(
s->mNodes[i].getChild());
2871 if (
t->mChildMask.isOn(i)) {
2875 ChildT* child =
new ChildT(other,
t->mNodes[i].getValue(),
TopologyCopy());
2876 if (
t->mValueMask.isOn(i)) child->setValuesOn();
2877 t->mNodes[i].setChild(child);
2880 }
else if (
s->mValueMask.isOn(i) &&
t->mChildMask.isOn(i)) {
2881 t->mNodes[i].getChild()->setValuesOn();
2885 const OtherInternalNode*
s;
2890template<
typename ChildT, Index Log2Dim>
2891template<
typename OtherChildT>
2895 TopologyUnion<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, preserveTiles);
2898template<
typename ChildT, Index Log2Dim>
2899template<
typename OtherInternalNode>
2904 { tC = (tC & (sC | sV)) | (tV & sC); }
2907 const ValueType& background) :
s(source),
t(target),
b(background) {
2909 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2913 t->mChildMask.foreach(
s->mChildMask,
s->mValueMask,
t->mValueMask, op);
2915 t->mValueMask &=
s->mValueMask;
2919 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2920 if (
t->mChildMask.isOn(i)) {
2921 ChildT* child =
t->mNodes[i].getChild();
2922 if (
s->mChildMask.isOn(i)) {
2923 child->topologyIntersection(*(
s->mNodes[i].getChild()),
b);
2924 }
else if (
s->mValueMask.isOff(i)) {
2926 t->mNodes[i].setValue(
b);
2928 }
else if (
t->mValueMask.isOn(i) &&
s->mChildMask.isOn(i)) {
2929 t->mNodes[i].setChild(
new ChildT(*(
s->mNodes[i].getChild()),
2934 const OtherInternalNode*
s;
2939template<
typename ChildT, Index Log2Dim>
2940template<
typename OtherChildT>
2945 TopologyIntersection<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, background);
2948template<
typename ChildT, Index Log2Dim>
2949template<
typename OtherInternalNode>
2954 { tC = (tC & (sC | ~sV)) | (tV & sC); }
2957 { tV &= ~((tC & sV) | (sC | sV)); }
2960 const ValueType& background) :
s(source),
t(target),
b(background) {
2962 tbb::parallel_for(tbb::blocked_range<Index>(0,
NUM_VALUES), *
this);
2967 t->mChildMask.foreach(
s->mChildMask,
s->mValueMask,
t->mValueMask, op1);
2970 t->mValueMask.foreach(
t->mChildMask,
s->mValueMask, oldChildMask, op2);
2974 for (
Index i = r.begin(), end=r.end(); i!=end; ++i) {
2975 if (
t->mChildMask.isOn(i)) {
2976 ChildT* child =
t->mNodes[i].getChild();
2977 if (
s->mChildMask.isOn(i)) {
2978 child->topologyDifference(*(
s->mNodes[i].getChild()),
b);
2979 }
else if (
s->mValueMask.isOn(i)) {
2981 t->mNodes[i].setValue(
b);
2983 }
else if (
t->mValueMask.isOn(i)) {
2984 if (
s->mChildMask.isOn(i)) {
2985 const typename OtherInternalNode::ChildNodeType& other =
2986 *(
s->mNodes[i].getChild());
2987 ChildT* child =
new ChildT(other.origin(),
t->mNodes[i].getValue(),
true);
2988 child->topologyDifference(other,
b);
2989 t->mNodes[i].setChild(child);
2994 const OtherInternalNode*
s;
2999template<
typename ChildT, Index Log2Dim>
3000template<
typename OtherChildT>
3005 TopologyDifference<InternalNode<OtherChildT, Log2Dim> > tmp(&other,
this, background);
3012template<
typename ChildT, Index Log2Dim>
3013template<
typename CombineOp>
3058 *child =
mNodes[i].getChild(),
3062 if (child && otherChild) {
3063 child->combine(*otherChild, op);
3070template<
typename ChildT, Index Log2Dim>
3071template<
typename CombineOp>
3083 .setBIsActive(valueIsActive));
3090 if (child) child->combine(value, valueIsActive, op);
3099template<
typename ChildT, Index Log2Dim>
3100template<
typename CombineOp,
typename OtherNodeType>
3111 .
setBRef(other1.mNodes[i].getValue())
3121 : other1.mNodes[i].getChild()->origin();
3130 }
else if (other1.isChildMaskOff(i)) {
3134 other1.mNodes[i].getValue(), other1.isValueMaskOn(i), op);
3139 *other1.mNodes[i].getChild(), op);
3146template<
typename ChildT, Index Log2Dim>
3147template<
typename CombineOp,
typename OtherNodeType>
3150 bool valueIsActive, CombineOp& op)
3155 if (other.isChildMaskOff(i)) {
3158 .
setBRef(other.mNodes[i].getValue())
3164 typename OtherNodeType::ChildNodeType* otherChild = other.mNodes[i].getChild();
3173 mNodes[i].getChild()->combine2(value, *otherChild, valueIsActive, op);
3179template<
typename ChildT, Index Log2Dim>
3180template<
typename CombineOp,
typename OtherValueType>
3183 bool valueIsActive, CombineOp& op)
3206 mNodes[i].getChild()->combine2(*otherChild, value, valueIsActive, op);
3215template<
typename ChildT, Index Log2Dim>
3220 iter->writeBuffers(os, toHalf);
3225template<
typename ChildT, Index Log2Dim>
3230 iter->readBuffers(is, fromHalf);
3235template<
typename ChildT, Index Log2Dim>
3238 const CoordBBox& clipBBox,
bool fromHalf)
3245 iter->readBuffers(is, clipBBox, fromHalf);
3251 background = *
static_cast<const ValueType*
>(bgPtr);
3253 this->
clip(clipBBox, background);
3260template<
typename ChildT, Index Log2Dim>
3264 dims.push_back(Log2Dim);
3265 ChildNodeType::getNodeLog2Dims(dims);
3269template<
typename ChildT, Index Log2Dim>
3274 xyz.
setX(n >> 2*Log2Dim);
3275 n &= ((1<<2*Log2Dim)-1);
3276 xyz.
setY(n >> Log2Dim);
3277 xyz.
setZ(n & ((1<<Log2Dim)-1));
3281template<
typename ChildT, Index Log2Dim>
3285 return (((xyz[0] & (
DIM-1u)) >> ChildNodeType::TOTAL) << 2*Log2Dim)
3286 + (((xyz[1] & (
DIM-1u)) >> ChildNodeType::TOTAL) << Log2Dim)
3287 + ((xyz[2] & (
DIM-1u)) >> ChildNodeType::TOTAL);
3291template<
typename ChildT, Index Log2Dim>
3297 local <<= ChildT::TOTAL;
3298 return local + this->
origin();
3305template<
typename ChildT, Index Log2Dim>
3306template<
typename ArrayT>
3310 using T =
typename ArrayT::value_type;
3311 static_assert(std::is_pointer<T>::value,
"argument to getNodes() must be a pointer array");
3312 using ArrayChildT =
typename std::conditional<
3313 std::is_const<typename std::remove_pointer<T>::type>::value,
const ChildT, ChildT>::type;
3316 if (std::is_same<T, ArrayChildT*>::value) {
3317 array.push_back(
reinterpret_cast<T
>(
mNodes[
iter.pos()].getChild()));
3319 iter->getNodes(array);
3325template<
typename ChildT, Index Log2Dim>
3326template<
typename ArrayT>
3330 using T =
typename ArrayT::value_type;
3331 static_assert(std::is_pointer<T>::value,
"argument to getNodes() must be a pointer array");
3332 static_assert(std::is_const<typename std::remove_pointer<T>::type>::value,
3333 "argument to getNodes() must be an array of const node pointers");
3336 if (std::is_same<T, const ChildT*>::value) {
3337 array.push_back(
reinterpret_cast<T
>(
mNodes[
iter.pos()].getChild()));
3339 iter->getNodes(array);
3349template<
typename ChildT, Index Log2Dim>
3350template<
typename ArrayT>
3354 using T =
typename ArrayT::value_type;
3355 static_assert(std::is_pointer<T>::value,
"argument to stealNodes() must be a pointer array");
3356 using ArrayChildT =
typename std::conditional<
3357 std::is_const<typename std::remove_pointer<T>::type>::value,
const ChildT, ChildT>::type;
3361 if (std::is_same<T, ArrayChildT*>::value) {
3362 array.push_back(
reinterpret_cast<T
>(
mNodes[n].getChild()));
3364 mNodes[n].setValue(value);
3366 iter->stealNodes(array, value, state);
3369 if (std::is_same<T, ArrayChildT*>::value)
mChildMask.setOff();
3377template<
typename ChildT, Index Log2Dim>
3385 mNodes[i].getChild()->resetBackground(oldBackground, newBackground);
3388 mNodes[i].setValue(newBackground);
3396template<
typename ChildT, Index Log2Dim>
3397template<
typename OtherChildNodeType, Index OtherLog2Dim>
3411template<
typename ChildT, Index Log2Dim>
3417 delete mNodes[i].getChild();
3422 mNodes[i].setChild(child);
3425template<
typename ChildT, Index Log2Dim>
3433 mNodes[i].setChild(child);
3437template<
typename ChildT, Index Log2Dim>
3442 mNodes[i].setValue(value);
3447 mNodes[i].setValue(value);
3452template<
typename ChildT, Index Log2Dim>
3459template<
typename ChildT, Index Log2Dim>
3464 return mNodes[n].getChild();
3468template<
typename ChildT, Index Log2Dim>
3473 return mNodes[n].getChild();
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition Types.h:569
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition Types.h:621
const AValueType & result() const
Get the output value.
Definition Types.h:613
CombineArgs & setBIsActive(bool b)
Set the active state of the B value.
Definition Types.h:637
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition Types.h:623
bool resultIsActive() const
Definition Types.h:632
CombineArgs & setAIsActive(bool b)
Set the active state of the A value.
Definition Types.h:635
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:316
void minComponent(const Coord &other)
Perform a component-wise minimum with the other Coord.
Definition Coord.h:176
static bool lessThan(const Coord &a, const Coord &b)
Definition Coord.h:209
Tag dispatch class that distinguishes constructors during file input.
Definition Types.h:689
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition Types.h:683
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
void translate(const Coord &t)
Translate this bounding box by (tx, ty, tz).
Definition Coord.h:461
void expand(ValueType padding)
Pad this bounding box with the specified padding.
Definition Coord.h:421
const Coord & min() const
Definition Coord.h:324
bool hasOverlap(const CoordBBox &b) const
Return true if the given bounding box overlaps with this bounding box.
Definition Coord.h:415
const Coord & max() const
Definition Coord.h:325
bool isInside(const Coord &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition Coord.h:403
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:447
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Int32 y() const
Definition Coord.h:132
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition Coord.h:92
Int32 x() const
Definition Coord.h:131
Coord & setZ(Int32 z)
Definition Coord.h:82
Coord & setY(Int32 y)
Definition Coord.h:81
static Coord max()
Return the largest possible coordinate.
Definition Coord.h:47
Int32 z() const
Definition Coord.h:133
Coord & setX(Int32 x)
Definition Coord.h:80
Definition InternalNode.h:35
void setValueAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1958
ChildNodeType * getChildUnsafe(Index offset)
Return the child node at offset.
Definition InternalNode.h:2513
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition InternalNode.h:336
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:2709
ChildOnCIter cbeginChildOn() const
Definition InternalNode.h:221
const ValueType & getFirstValue() const
If the first entry in this node's table is a tile, return the tile's value. Otherwise,...
Definition InternalNode.h:2474
CoordBBox getNodeBoundingBox() const
Definition InternalNode.h:300
bool isConstant(ValueType &minValue, ValueType &maxValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition InternalNode.h:1716
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ValueOff > ValueOffCIter
Definition InternalNode.h:217
ChildNodeType * probeChildUnsafe(Index offset, ValueType &value, bool &active)
Return a pointer to the child node for a specific offset. If no such node exists, return nullptr.
Definition InternalNode.h:1435
ChildOnCIter beginChildOn() const
Definition InternalNode.h:224
ValueIter< InternalNode, const ValueType, MaskOffIterator, ValueAll > ValueAllIter
Definition InternalNode.h:218
const ChildNodeType * probeConstChildUnsafe(Index offset) const
Definition InternalNode.h:1426
ChildOnIter beginChildOn()
Definition InternalNode.h:227
NodeType * probeNode(const Coord &xyz)
Return a pointer to the node that contains voxel (x, y, z). If no such node exists,...
const NodeType * probeNode(const Coord &xyz) const
Definition InternalNode.h:702
bool isChildMaskOff(Index n) const
Definition InternalNode.h:866
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition InternalNode.h:1758
const ValueType & getValueUnsafe(Index offset) const
Return the tile value at offset.
Definition InternalNode.h:2494
const ChildNodeType * probeChildUnsafe(Index offset, ValueType &value, bool &active) const
Definition InternalNode.h:738
void writeTopology(std::ostream &, bool toHalf=false) const
Definition InternalNode.h:2389
util::NodeMask< Log2Dim > NodeMaskType
Definition InternalNode.h:42
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:2344
void setChildNode(Index i, ChildNodeType *child)
Definition InternalNode.h:3427
bool isChildMaskOff() const
Definition InternalNode.h:867
ValueOffCIter cbeginValueOff() const
Definition InternalNode.h:233
LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc)
Same as probeLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
Index32 transientData() const
Return the transient data value.
Definition InternalNode.h:273
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other)
Value conversion copy constructor.
Definition InternalNode.h:1008
InternalNode(const Coord &origin, const ValueType &fillValue, bool active=false)
Constructs an InternalNode with dense tiles.
Definition InternalNode.h:949
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:1536
static Index getChildDim()
Definition InternalNode.h:257
const NodeMaskType & getChildMask() const
Definition InternalNode.h:869
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,...
NodeUnion< ValueType, ChildNodeType > UnionType
Definition InternalNode.h:41
NodeMaskType mChildMask
Definition InternalNode.h:910
bool isValueMaskOff() const
Definition InternalNode.h:864
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &offValue, const ValueType &onValue, TopologyCopy)
Topology copy constructor.
Definition InternalNode.h:1081
void getNodes(ArrayT &array)
Adds all nodes of a certain type to a container with the following API:
Definition InternalNode.h:3308
bool isValueMaskOn() const
Definition InternalNode.h:862
Index64 nonLeafCount() const
Definition InternalNode.h:1149
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:1283
void voxelizeActiveTiles(bool threaded=true)
Densify active tiles, i.e., replace them with leaf-level active voxels.
Definition InternalNode.h:2688
NodeMaskType mValueMask
Definition InternalNode.h:910
InternalNode()
Default constructor.
Definition InternalNode.h:73
bool isChildMaskOn(Index n) const
Definition InternalNode.h:865
~InternalNode()
Definition InternalNode.h:1095
Index64 onLeafVoxelCount() const
const LeafNodeType * probeConstLeafAndCache(const Coord &xyz, AccessorT &acc) const
NodeMaskType getValueOffMask() const
Definition InternalNode.h:870
void merge(const ValueType &tileValue, bool tileActive)
Merge, using one of several schemes, this node (and its descendants) with a tile of the same dimensio...
Definition InternalNode.h:2818
LeafNodeType * probeLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists,...
Definition InternalNode.h:1461
bool getValueUnsafe(Index offset, ValueType &value) const
Return the tile value and active state at offset.
Definition InternalNode.h:2503
ValueAllCIter cbeginValueAll() const
Definition InternalNode.h:234
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:1259
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ValueAll > ValueAllCIter
Definition InternalNode.h:219
ValueOnCIter beginValueOn() const
Definition InternalNode.h:235
void setValueOnlyUnsafe(Index offset, const ValueType &value)
Set the tile value at offset but don't change its value.
Definition InternalNode.h:2547
Index64 offLeafVoxelCount() const
const ChildNodeType * probeConstChild(const Coord &xyz, ValueType &value, bool &active) const
Definition InternalNode.h:1409
void combine2(const InternalNode &other, const OtherValueType &, bool valIsActive, CombineOp &)
Definition InternalNode.h:3182
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:3379
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:1595
void combine2(const ValueType &value, const OtherNodeType &other, bool valIsActive, CombineOp &)
Definition InternalNode.h:3149
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition InternalNode.h:270
const Coord & origin() const
Definition InternalNode.h:268
const ChildNodeType * probeConstChildUnsafe(Index offset, ValueType &value, bool &active) const
Definition InternalNode.h:1446
bool isInactive() const
Return true if this node has no children and only contains inactive values.
Definition InternalNode.h:331
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition InternalNode.h:2136
void setValueOnlyAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1999
void combine2(const InternalNode &other0, const OtherNodeType &other1, CombineOp &)
Definition InternalNode.h:3102
friend class InternalNode
During topology-only construction, access is needed to protected/private members of other template in...
Definition InternalNode.h:857
bool isValueMaskOff(Index n) const
Definition InternalNode.h:863
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:1982
const LeafNodeType * probeConstLeaf(const Coord &xyz) const
Definition InternalNode.h:1487
void deleteChildUnsafe(Index offset, const ValueType &value, bool active)
Delete a child node at offset and replace with the given value and active state.
Definition InternalNode.h:2632
ChildNodeType * probeChild(const Coord &xyz)
Return a pointer to the child node that contains voxel (x, y, z). If no such node exists,...
Definition InternalNode.h:1385
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:1820
const NodeType * probeConstNodeAndCache(const Coord &xyz, AccessorT &) const
void setActiveStateUnsafe(Index offset, bool on)
Set the tile active state at offset but don't change its value.
Definition InternalNode.h:2538
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:2240
ValueOffCIter beginValueOff() const
Definition InternalNode.h:237
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Definition InternalNode.h:1913
void addLeaf(LeafNodeType *leaf)
Add the specified leaf to this node, possibly creating a child branch in the process....
Definition InternalNode.h:1507
InternalNode(const InternalNode< OtherChildNodeType, Log2Dim > &other, const ValueType &background, TopologyCopy)
Topology copy constructor.
Definition InternalNode.h:1044
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
ChildAllCIter cbeginChildAll() const
Definition InternalNode.h:223
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition InternalNode.h:2190
Index64 leafCount() const
Definition InternalNode.h:1108
ChildAllIter beginChildAll()
Definition InternalNode.h:229
ValueIter< InternalNode, const ValueType, MaskOnIterator, ValueOn > ValueOnIter
Definition InternalNode.h:214
static Index getLevel()
Definition InternalNode.h:250
void setValueOff(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as inactive.
Definition InternalNode.h:1893
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Definition InternalNode.h:1777
const ChildNodeType * probeChildUnsafe(Index offset) const
Definition InternalNode.h:728
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,...
static const Index DIM
Definition InternalNode.h:47
ChildNodeType * stealChildUnsafe(Index offset, const ValueType &value, bool active)
Replace a child node at offset with the given value and active state.
Definition InternalNode.h:2618
bool probeValue(const Coord &xyz, ValueType &value) const
Definition InternalNode.h:1833
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:2020
ValueOnIter beginValueOn()
Definition InternalNode.h:239
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:2102
static const Index LEVEL
Definition InternalNode.h:49
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...
void resetChildUnsafe(Index offset, ChildNodeType *child)
Replace a child node at offset with the given child node.
Definition InternalNode.h:2606
ChildOffCIter cbeginChildOff() const
Definition InternalNode.h:222
ChildOffIter beginChildOff()
Definition InternalNode.h:228
ChildIter< InternalNode, ChildNodeType, MaskOnIterator, ChildOn > ChildOnIter
Definition InternalNode.h:207
Index64 onVoxelCount() const
ChildOffCIter beginChildOff() const
Definition InternalNode.h:225
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition InternalNode.h:3283
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:1627
typename ChildNodeType::LeafNodeType LeafNodeType
Definition InternalNode.h:38
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition InternalNode.h:1861
NodeType * probeNodeAndCache(const Coord &xyz, AccessorT &)
Same as probeNode() except, if necessary, update the accessor with pointers to the nodes along the pa...
void writeBuffers(std::ostream &, bool toHalf=false) const
Definition InternalNode.h:3217
void nodeCount(std::vector< Index64 > &vec) const
Definition InternalNode.h:1120
ValueOnCIter cbeginValueOn() const
Definition InternalNode.h:231
typename ChildNodeType::ValueType ValueType
Definition InternalNode.h:39
const LeafNodeType * probeLeaf(const Coord &xyz) const
void setValueOnUnsafe(Index offset)
Mark the tile active at offset but don't change its value.
Definition InternalNode.h:2556
void setValueOnUnsafe(Index offset, const ValueType &value)
Set the tile value at offset and mark the voxel as active.
Definition InternalNode.h:2565
void resetChildNode(Index i, ChildNodeType *child)
Definition InternalNode.h:3413
void readBuffers(std::istream &, const CoordBBox &, bool fromHalf=false)
Definition InternalNode.h:3237
Index32 childCount() const
DenseIter< const InternalNode, const ChildNodeType, ValueType, ChildAll > ChildAllCIter
Definition InternalNode.h:212
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:1811
Index64 onTileCount() const
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:2074
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:3399
void setValueMask(Index n, bool on)
Definition InternalNode.h:882
const ChildNodeType * getChildUnsafe(Index offset) const
Return the child node at offset.
Definition InternalNode.h:2531
Index64 offVoxelCount() const
typename NodeMaskType::OffIterator MaskOffIterator
Definition InternalNode.h:116
ChildIter< const InternalNode, const ChildNodeType, MaskOnIterator, ChildOn > ChildOnCIter
Definition InternalNode.h:208
bool isConstant(ValueType &firstValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition InternalNode.h:1696
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:1663
void getNodes(ArrayT &array) const
Definition InternalNode.h:3328
const ChildNodeType * getConstChildUnsafe(Index offset) const
Return the child node at offset.
Definition InternalNode.h:2522
Index32 mTransientData
Definition InternalNode.h:914
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:2296
static const Index NUM_VALUES
Definition InternalNode.h:48
ValueIter< InternalNode, const ValueType, MaskOffIterator, ChildOff > ChildOffIter
Definition InternalNode.h:209
UnionType mNodes[NUM_VALUES]
Definition InternalNode.h:909
void negate()
Change the sign of all the values represented in this node and its child nodes.
Definition InternalNode.h:2644
void readTopology(std::istream &, bool fromHalf=false)
Definition InternalNode.h:2414
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition InternalNode.h:3293
ValueIter< const InternalNode, const ValueType, MaskOffIterator, ChildOff > ChildOffCIter
Definition InternalNode.h:210
ChildAllCIter beginChildAll() const
Definition InternalNode.h:226
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Definition InternalNode.h:2039
void setValuesOn()
Mark all values (both tiles and voxels) as active.
Definition InternalNode.h:2062
void makeChildNodeEmpty(Index n, const ValueType &value)
Definition InternalNode.h:3454
void setTransientData(Index32 transientData)
Set the transient data value.
Definition InternalNode.h:275
typename ChildNodeType::BuildType BuildType
Definition InternalNode.h:40
LeafNodeType * touchLeafAndCache(const Coord &xyz, AccessorT &)
Same as touchLeaf() except, if necessary, update the accessor with pointers to the nodes along the pa...
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:3352
ChildNodeType * getChildNode(Index n)
Returns a pointer to the child node at the linear offset n.
Definition InternalNode.h:3461
typename NodeMaskType::OnIterator MaskOnIterator
Definition InternalNode.h:115
const LeafNodeType * probeLeafAndCache(const Coord &xyz, AccessorT &acc) const
bool probeValueAndCache(const Coord &xyz, ValueType &value, AccessorT &) const
Definition InternalNode.h:1846
static const Index LOG2DIM
Definition InternalNode.h:45
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:1569
ChildNodeType * probeChildUnsafe(Index offset)
Return a pointer to the child node for a specific offset. If no such node exists, return nullptr.
Definition InternalNode.h:1417
DenseIter< InternalNode, ChildNodeType, ValueType, ChildAll > ChildAllIter
Definition InternalNode.h:211
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
ValueIter< const InternalNode, const ValueType, MaskOnIterator, ValueOn > ValueOnCIter
Definition InternalNode.h:215
const ChildNodeType * probeChild(const Coord &xyz) const
Definition InternalNode.h:710
bool isEmpty() const
Definition InternalNode.h:303
InternalNode(const ValueType &offValue)
Constructor of an InternalNode with dense inactive tiles of the specified value.
Definition InternalNode.h:941
const UnionType * getTable() const
Definition InternalNode.h:877
ChildNodeType * probeChild(const Coord &xyz, ValueType &value, bool &active)
Return a pointer to the child node that contains voxel (x, y, z). If no such node exists,...
Definition InternalNode.h:1401
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:3262
ValueOffIter beginValueOff()
Definition InternalNode.h:241
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition InternalNode.h:1877
ValueIter< InternalNode, const ValueType, MaskOffIterator, ValueOff > ValueOffIter
Definition InternalNode.h:216
const ChildNodeType * probeConstChild(const Coord &xyz) const
Definition InternalNode.h:1393
typename SubtreeT::Back ChildNodeType
Definition InternalNode.h:37
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:3271
const NodeMaskType & getValueMask() const
Definition InternalNode.h:868
static const Index TOTAL
Definition InternalNode.h:46
const ChildNodeType * getChildNode(Index n) const
Returns a pointer to the child node at the linear offset n.
Definition InternalNode.h:3470
const NodeType * probeConstNode(const Coord &xyz) const
bool hasActiveTiles() const
Return true if this node or any of its child nodes have any active tiles.
Definition InternalNode.h:1743
void combine(InternalNode &other, CombineOp &)
Definition InternalNode.h:3015
InternalNode(const InternalNode &)
Deep copy constructor.
Definition InternalNode.h:994
void setChildUnsafe(Index offset, ChildNodeType *child)
Replace a tile at offset with the given child node.
Definition InternalNode.h:2594
const ValueType & getValue(const Coord &xyz) const
Definition InternalNode.h:1788
void setValueOn(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active.
Definition InternalNode.h:1938
bool isValueOff(const Coord &xyz) const
Return true if the voxel at the given coordinates is inactive.
Definition InternalNode.h:1767
static const Index64 NUM_VOXELS
Definition InternalNode.h:51
void setValueOffUnsafe(Index offset)
Mark the tile inactive at offset but don't change its value.
Definition InternalNode.h:2575
ChildNodeType * unsetChildNode(Index i, const ValueType &value)
Definition InternalNode.h:3439
const ChildNodeType * probeChild(const Coord &xyz, ValueType &value, bool &active) const
Definition InternalNode.h:718
void readBuffers(std::istream &, bool fromHalf=false)
Definition InternalNode.h:3227
typename NodeMaskType::DenseIterator MaskDenseIterator
Definition InternalNode.h:117
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition InternalNode.h:2159
bool isValueOff(Index offset) const
Return true if the voxel at the given offset is inactive.
Definition InternalNode.h:340
ValueAllCIter beginValueAll() const
Definition InternalNode.h:238
Coord mOrigin
Definition InternalNode.h:912
static Index dim()
Definition InternalNode.h:247
void setValueOffUnsafe(Index offset, const ValueType &value)
Set the tile value at offset and mark the voxel as inactive.
Definition InternalNode.h:2584
InternalNode(PartialCreate, const Coord &, const ValueType &fillValue, bool active=false)
Definition InternalNode.h:963
void addTile(Index offset, const ValueType &value, bool state)
Delete any existing child branch at the specified offset and add a tile.
Definition InternalNode.h:1585
bool isValueMaskOn(Index n) const
Definition InternalNode.h:861
ValueAllIter beginValueAll()
Definition InternalNode.h:242
void combine(const ValueType &value, bool valueIsActive, CombineOp &)
Definition InternalNode.h:3073
const ValueType & getLastValue() const
If the last entry in this node's table is a tile, return the tile's value. Otherwise,...
Definition InternalNode.h:2482
Base class for iterators over internal and leaf nodes.
Definition Iterator.h:30
Index pos() const
Definition Iterator.h:60
InternalNode & parent() const
Definition Iterator.h:50
Default implementation of a NodeUnion that stores the child pointer and the value separately (i....
Definition NodeUnion.h:32
const ValueT & getValue() const
Definition NodeUnion.h:43
ChildT * getChild() const
Definition NodeUnion.h:40
void setValue(const ValueT &val)
Definition NodeUnion.h:45
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation.
Definition NodeMasks.h:308
Index64 Word
Definition NodeMasks.h:316
DenseMaskIterator< NodeMask > DenseIterator
Definition NodeMasks.h:350
void toggle(Index32 n)
Toggle the state of the nth bit.
Definition NodeMasks.h:483
OnMaskIterator< NodeMask > OnIterator
Definition NodeMasks.h:348
void setOff(Index32 n)
Set the nth bit off.
Definition NodeMasks.h:457
OffMaskIterator< NodeMask > OffIterator
Definition NodeMasks.h:349
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition Compression.h:646
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition Compression.h:466
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...
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:406
T negative(const T &val)
Return the unary negation of the given value.
Definition Math.h:128
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
Definition TreeIterator.h:30
Index32 Index
Definition Types.h:54
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
@ OPENVDB_FILE_VERSION_NODE_MASK_COMPRESSION
Definition version.h.in:262
@ OPENVDB_FILE_VERSION_INTERNALNODE_COMPRESSION
Definition version.h.in:253
uint32_t Index32
Definition Types.h:52
int32_t Int32
Definition Types.h:56
uint64_t Index64
Definition Types.h:53
@ MERGE_ACTIVE_STATES
Definition Types.h:507
@ MERGE_NODES
Definition Types.h:508
@ MERGE_ACTIVE_STATES_AND_NODES
Definition Types.h:509
Definition Exceptions.h:13
typename std::remove_const< ValueT >::type NonConstValueType
Definition Iterator.h:184
DenseIteratorBase()
Definition Iterator.h:188
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition InternalNode.h:132
ChildIter()
Definition InternalNode.h:131
ChildT & getItem(Index pos) const
Definition InternalNode.h:135
void setItem(Index pos, const ChildT &c) const
Definition InternalNode.h:142
Definition InternalNode.h:121
Definition InternalNode.h:121
Definition InternalNode.h:974
DeepCopy(const OtherInternalNode *source, InternalNode *target)
Definition InternalNode.h:975
InternalNode * t
Definition InternalNode.h:989
const OtherInternalNode * s
Definition InternalNode.h:988
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:979
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, ChildT, ValueT > BaseT
Definition InternalNode.h:174
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition InternalNode.h:178
void unsetItem(Index pos, const ValueT &value) const
Definition InternalNode.h:199
void setItem(Index pos, ChildT *child) const
Definition InternalNode.h:193
DenseIter()
Definition InternalNode.h:177
bool getItem(Index pos, ChildT *&child, NonConstValueT &value) const
Definition InternalNode.h:181
typename BaseT::NonConstValueType NonConstValueT
Definition InternalNode.h:175
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of an Intern...
Definition InternalNode.h:65
static const bool value
Definition InternalNode.h:66
Definition InternalNode.h:1020
TopologyCopy1(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:1021
InternalNode * t
Definition InternalNode.h:1037
const OtherInternalNode * s
Definition InternalNode.h:1036
const ValueType & b
Definition InternalNode.h:1038
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:1026
Definition InternalNode.h:1057
const ValueType & offV
Definition InternalNode.h:1075
TopologyCopy2(const OtherInternalNode *source, InternalNode *target, const ValueType &offValue, const ValueType &onValue)
Definition InternalNode.h:1058
InternalNode * t
Definition InternalNode.h:1074
const OtherInternalNode * s
Definition InternalNode.h:1073
const ValueType & onV
Definition InternalNode.h:1075
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:1063
Definition InternalNode.h:2953
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition InternalNode.h:2953
Definition InternalNode.h:2956
void operator()(W &tV, const W &sC, const W &sV, const W &tC) const
Definition InternalNode.h:2956
TopologyDifference(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:2959
typename NodeMaskType::Word W
Definition InternalNode.h:2952
InternalNode * t
Definition InternalNode.h:2995
const OtherInternalNode * s
Definition InternalNode.h:2994
const ValueType & b
Definition InternalNode.h:2996
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2973
Definition InternalNode.h:2903
void operator()(W &tC, const W &sC, const W &sV, const W &tV) const
Definition InternalNode.h:2903
TopologyIntersection(const OtherInternalNode *source, InternalNode *target, const ValueType &background)
Definition InternalNode.h:2906
typename NodeMaskType::Word W
Definition InternalNode.h:2902
InternalNode * t
Definition InternalNode.h:2935
const OtherInternalNode * s
Definition InternalNode.h:2934
const ValueType & b
Definition InternalNode.h:2936
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2918
Definition InternalNode.h:2851
void operator()(W &tV, const W &sV, const W &tC) const
Definition InternalNode.h:2851
Definition InternalNode.h:2849
typename NodeMaskType::Word W
Definition InternalNode.h:2850
InternalNode * t
Definition InternalNode.h:2886
const bool mPreserveTiles
Definition InternalNode.h:2887
const OtherInternalNode * s
Definition InternalNode.h:2885
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2867
TopologyUnion(const OtherInternalNode *source, InternalNode *target, const bool preserveTiles)
Definition InternalNode.h:2854
ValueConverter<T>::Type is the type of an InternalNode having the same child hierarchy and dimensions...
Definition InternalNode.h:56
InternalNode< typename ChildNodeType::template ValueConverter< OtherValueType >::Type, Log2Dim > Type
Definition InternalNode.h:57
void modifyItem(Index pos, const ModifyOp &op) const
Definition InternalNode.h:163
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition InternalNode.h:153
const ValueT & getItem(Index pos) const
Definition InternalNode.h:156
ValueIter()
Definition InternalNode.h:152
void setItem(Index pos, const ValueT &v) const
Definition InternalNode.h:159
Definition InternalNode.h:120
Definition InternalNode.h:120
Definition InternalNode.h:2662
InternalNode * mNode
Definition InternalNode.h:2683
void operator()(const tbb::blocked_range< Index > &r) const
Definition InternalNode.h:2670
VoxelizeActiveTiles(InternalNode &node)
Definition InternalNode.h:2663
static const bool value
Definition InternalNode.h:931
Definition InternalNode.h:925
static const bool value
Definition InternalNode.h:926
SparseIteratorBase()
Definition Iterator.h:122
const ValueType & getValue() const
Definition Iterator.h:139
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218