31 #ifndef OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED 32 #define OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED 37 #include <boost/shared_ptr.hpp> 38 #include <boost/static_assert.hpp> 39 #include <boost/bind.hpp> 40 #include <tbb/blocked_range.h> 41 #include <tbb/spin_mutex.h> 42 #include <tbb/parallel_for.h> 43 #include <openvdb/Types.h> 44 #include <openvdb/util/NodeMasks.h> 45 #include <openvdb/io/Compression.h> 57 template<Index,
typename>
struct SameLeafConfig;
64 template<
typename T, Index Log2Dim>
70 typedef boost::shared_ptr<LeafNode>
Ptr;
77 NUM_VALUES = 1 << 3 * Log2Dim,
78 NUM_VOXELS = NUM_VALUES,
84 template<
typename OtherValueType>
91 template<
typename OtherNodeType>
96 #ifndef OPENVDB_2_ABI_COMPATIBLE 103 boost::shared_ptr<io::StreamMetadata>
meta;
112 #ifdef OPENVDB_2_ABI_COMPATIBLE 113 Buffer(): mData(
new ValueType[SIZE]) {}
116 explicit Buffer(
const ValueType& val): mData(
new ValueType[SIZE]) { this->fill(val); }
118 Buffer(
const Buffer& other): mData(
new ValueType[SIZE]) { *
this = other; }
120 ~
Buffer() {
delete[] mData; }
123 bool isOutOfCore()
const {
return false; }
125 bool empty()
const {
return (mData == NULL); }
128 static const Index WORD_COUNT = SIZE;
130 Buffer(): mData(new ValueType[SIZE]), mOutOfCore(0) {}
132 explicit Buffer(
const ValueType& val): mData(new ValueType[SIZE]), mOutOfCore(0)
143 ValueType* target = mData;
144 const ValueType* source = other.
mData;
146 while (n--) *target++ = *source++;
154 if (this->isOutOfCore()) {
155 this->detachFromFile();
164 bool empty()
const {
return !mData || this->isOutOfCore(); }
166 bool allocate() {
if (mData == NULL) mData =
new ValueType[SIZE];
return !this->empty(); }
170 void fill(
const ValueType& val)
172 this->detachFromFile();
174 ValueType* target = mData;
176 while (n--) *target++ = val;
188 #ifdef OPENVDB_2_ABI_COMPATIBLE 192 if (mData) mData[i] = val;
199 if (&other !=
this) {
200 #ifndef OPENVDB_2_ABI_COMPATIBLE 201 if (this->isOutOfCore()) {
202 this->detachFromFile();
207 mOutOfCore = other.mOutOfCore;
212 ValueType* target = mData;
213 const ValueType* source = other.
mData;
215 while (n--) *target++ = *source++;
216 #ifndef OPENVDB_2_ABI_COMPATIBLE 229 const ValueType *target = mData, *source = other.
mData;
230 if (!target && !source)
return true;
231 if (!target || !source)
return false;
243 std::swap(mData, other.
mData);
244 #ifndef OPENVDB_2_ABI_COMPATIBLE 245 std::swap(mOutOfCore, other.mOutOfCore);
252 size_t n =
sizeof(*this);
253 #ifdef OPENVDB_2_ABI_COMPATIBLE 254 if (mData) n += SIZE *
sizeof(ValueType);
256 if (this->isOutOfCore()) n +=
sizeof(
FileInfo);
257 else if (mData) n += SIZE *
sizeof(ValueType);
259 return static_cast<Index>(n);
269 #ifndef OPENVDB_2_ABI_COMPATIBLE 277 tbb::spin_mutex::scoped_lock lock(self->mMutex);
278 if (mData == NULL)
self->mData =
new ValueType[SIZE];
289 #ifndef OPENVDB_2_ABI_COMPATIBLE 291 if (mData == NULL) mData =
new ValueType[SIZE];
298 const ValueType& at(
Index i)
const 301 #ifdef OPENVDB_2_ABI_COMPATIBLE 307 if (mData)
return mData[i];
else return sZero;
316 ValueType& operator[](
Index i) {
return const_cast<ValueType&
>(this->at(i)); }
320 if (mData != NULL && !this->isOutOfCore()) {
328 #ifdef OPENVDB_2_ABI_COMPATIBLE 329 void setOutOfCore(
bool) {}
330 void loadValues()
const {}
331 void doLoad()
const {}
332 bool detachFromFile() {
return false; }
334 inline void setOutOfCore(
bool b) { mOutOfCore = b; }
337 inline void loadValues()
const {
if (this->isOutOfCore()) this->doLoad(); }
338 inline void doLoad()
const;
339 inline bool detachFromFile()
341 if (this->isOutOfCore()) {
344 this->setOutOfCore(
false);
351 friend class ::TestLeaf;
355 #ifdef OPENVDB_2_ABI_COMPATIBLE 363 tbb::spin_mutex mMutex;
366 static const ValueType sZero;
378 explicit LeafNode(
const Coord& coords,
379 const ValueType& value = zeroVal<ValueType>(),
380 bool active =
false);
383 #ifndef OPENVDB_2_ABI_COMPATIBLE 391 const ValueType& value = zeroVal<ValueType>(),
392 bool active =
false);
399 template<
typename OtherValueType>
403 template<
typename OtherValueType>
405 const ValueType& offValue,
const ValueType& onValue,
TopologyCopy);
408 template<
typename OtherValueType>
446 bool isEmpty()
const {
return mValueMask.isOff(); }
448 bool isDense()
const {
return mValueMask.isOn(); }
450 #ifndef OPENVDB_2_ABI_COMPATIBLE 451 bool isAllocated()
const {
return !mBuffer.isOutOfCore() && !mBuffer.empty(); }
463 void evalActiveBoundingBox(CoordBBox& bbox,
bool visitVoxels =
true)
const;
470 void setOrigin(
const Coord& origin) { mOrigin = origin; }
472 const Coord& origin()
const {
return mOrigin; }
474 void getOrigin(Coord& origin)
const { origin = mOrigin; }
479 static Index coordToOffset(
const Coord& xyz);
482 static Coord offsetToLocalCoord(
Index n);
484 Coord offsetToGlobalCoord(
Index n)
const;
487 std::string str()
const;
491 template<
typename OtherType, Index OtherLog2Dim>
507 template<
typename MaskIterT,
typename NodeT,
typename ValueT,
typename TagT>
512 MaskIterT, ValueIter<MaskIterT, NodeT, ValueT, TagT>, NodeT, ValueT>
517 ValueIter(
const MaskIterT& iter, NodeT* parent): BaseT(iter, parent) {}
519 ValueT&
getItem(
Index pos)
const {
return this->parent().getValue(pos); }
520 ValueT&
getValue()
const {
return this->parent().getValue(this->pos()); }
525 this->parent().setValueOnly(pos, value);
530 this->parent().setValueOnly(this->pos(), value);
534 template<
typename ModifyOp>
535 void modifyItem(
Index n,
const ModifyOp& op)
const { this->parent().modifyValue(n, op); }
537 template<
typename ModifyOp>
538 void modifyValue(
const ModifyOp& op)
const { this->parent().modifyValue(this->pos(), op); }
542 template<
typename MaskIterT,
typename NodeT,
typename TagT>
544 public SparseIteratorBase<MaskIterT, ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>
548 MaskIterT,
ChildIter<MaskIterT, NodeT, TagT>, NodeT, ValueType>(iter, parent) {}
551 template<
typename NodeT,
typename ValueT,
typename TagT>
553 MaskDenseIterator, DenseIter<NodeT, ValueT, TagT>, NodeT, void, ValueT>
559 DenseIter(
const MaskDenseIterator& iter, NodeT* parent): BaseT(iter, parent) {}
563 value = this->parent().getValue(pos);
574 this->parent().setValueOnly(pos, value);
592 ValueOnCIter
cbeginValueOn()
const {
return ValueOnCIter(mValueMask.beginOn(),
this); }
593 ValueOnCIter
beginValueOn()
const {
return ValueOnCIter(mValueMask.beginOn(),
this); }
594 ValueOnIter
beginValueOn() {
return ValueOnIter(mValueMask.beginOn(),
this); }
595 ValueOffCIter
cbeginValueOff()
const {
return ValueOffCIter(mValueMask.beginOff(),
this); }
596 ValueOffCIter
beginValueOff()
const {
return ValueOffCIter(mValueMask.beginOff(),
this); }
597 ValueOffIter
beginValueOff() {
return ValueOffIter(mValueMask.beginOff(),
this); }
598 ValueAllCIter
cbeginValueAll()
const {
return ValueAllCIter(mValueMask.beginDense(),
this); }
599 ValueAllCIter
beginValueAll()
const {
return ValueAllCIter(mValueMask.beginDense(),
this); }
600 ValueAllIter
beginValueAll() {
return ValueAllIter(mValueMask.beginDense(),
this); }
602 ValueOnCIter
cendValueOn()
const {
return ValueOnCIter(mValueMask.endOn(),
this); }
603 ValueOnCIter
endValueOn()
const {
return ValueOnCIter(mValueMask.endOn(),
this); }
604 ValueOnIter
endValueOn() {
return ValueOnIter(mValueMask.endOn(),
this); }
605 ValueOffCIter
cendValueOff()
const {
return ValueOffCIter(mValueMask.endOff(),
this); }
606 ValueOffCIter
endValueOff()
const {
return ValueOffCIter(mValueMask.endOff(),
this); }
607 ValueOffIter
endValueOff() {
return ValueOffIter(mValueMask.endOff(),
this); }
608 ValueAllCIter
cendValueAll()
const {
return ValueAllCIter(mValueMask.endDense(),
this); }
609 ValueAllCIter
endValueAll()
const {
return ValueAllCIter(mValueMask.endDense(),
this); }
610 ValueAllIter
endValueAll() {
return ValueAllIter(mValueMask.endDense(),
this); }
614 ChildOnCIter
cbeginChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
615 ChildOnCIter
beginChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
616 ChildOnIter
beginChildOn() {
return ChildOnIter(mValueMask.endOn(),
this); }
617 ChildOffCIter
cbeginChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
618 ChildOffCIter
beginChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
619 ChildOffIter
beginChildOff() {
return ChildOffIter(mValueMask.endOff(),
this); }
620 ChildAllCIter
cbeginChildAll()
const {
return ChildAllCIter(mValueMask.beginDense(),
this); }
621 ChildAllCIter
beginChildAll()
const {
return ChildAllCIter(mValueMask.beginDense(),
this); }
622 ChildAllIter
beginChildAll() {
return ChildAllIter(mValueMask.beginDense(),
this); }
624 ChildOnCIter
cendChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
625 ChildOnCIter
endChildOn()
const {
return ChildOnCIter(mValueMask.endOn(),
this); }
626 ChildOnIter
endChildOn() {
return ChildOnIter(mValueMask.endOn(),
this); }
627 ChildOffCIter
cendChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
628 ChildOffCIter
endChildOff()
const {
return ChildOffCIter(mValueMask.endOff(),
this); }
629 ChildOffIter
endChildOff() {
return ChildOffIter(mValueMask.endOff(),
this); }
630 ChildAllCIter
cendChildAll()
const {
return ChildAllCIter(mValueMask.endDense(),
this); }
631 ChildAllCIter
endChildAll()
const {
return ChildAllCIter(mValueMask.endDense(),
this); }
632 ChildAllIter
endChildAll() {
return ChildAllIter(mValueMask.endDense(),
this); }
649 void readTopology(std::istream& is,
bool fromHalf =
false);
653 void writeTopology(std::ostream& os,
bool toHalf =
false)
const;
658 void readBuffers(std::istream& is,
bool fromHalf =
false);
663 void readBuffers(std::istream& is,
const CoordBBox& bbox,
bool fromHalf =
false);
667 void writeBuffers(std::ostream& os,
bool toHalf =
false)
const;
669 size_t streamingSize(
bool toHalf =
false)
const;
675 const ValueType& getValue(
const Coord& xyz)
const;
677 const ValueType& getValue(
Index offset)
const;
682 bool probeValue(
const Coord& xyz, ValueType& val)
const;
686 bool probeValue(
Index offset, ValueType& val)
const;
692 void setActiveState(
const Coord& xyz,
bool on);
697 void setValueOnly(
const Coord& xyz,
const ValueType& val);
699 void setValueOnly(
Index offset,
const ValueType& val);
702 void setValueOff(
const Coord& xyz) { mValueMask.setOff(LeafNode::coordToOffset(xyz)); }
707 void setValueOff(
const Coord& xyz,
const ValueType& val);
709 void setValueOff(
Index offset,
const ValueType& val);
712 void setValueOn(
const Coord& xyz) { mValueMask.setOn(LeafNode::coordToOffset(xyz)); }
717 this->setValueOn(LeafNode::coordToOffset(xyz), val);
720 void setValue(
const Coord& xyz,
const ValueType& val) { this->setValueOn(xyz, val); }
723 mBuffer.setValue(offset, val);
724 mValueMask.setOn(offset);
729 template<
typename ModifyOp>
732 ValueType val = mBuffer[offset];
734 mBuffer.setValue(offset, val);
735 mValueMask.setOn(offset);
739 template<
typename ModifyOp>
742 this->modifyValue(this->coordToOffset(xyz), op);
746 template<
typename ModifyOp>
749 const Index offset = this->coordToOffset(xyz);
750 bool state = mValueMask.isOn(offset);
751 ValueType val = mBuffer[offset];
753 mBuffer.setValue(offset, val);
754 mValueMask.set(offset, state);
771 void clip(
const CoordBBox&,
const ValueType& background);
774 void fill(
const CoordBBox& bbox,
const ValueType&,
bool active =
true);
777 void fill(
const ValueType& value);
779 void fill(
const ValueType& value,
bool active);
792 template<
typename DenseT>
793 void copyToDense(
const CoordBBox& bbox, DenseT& dense)
const;
811 template<
typename DenseT>
812 void copyFromDense(
const CoordBBox& bbox,
const DenseT& dense,
813 const ValueType& background,
const ValueType& tolerance);
817 template<
typename AccessorT>
820 return this->getValue(xyz);
825 template<
typename AccessorT>
830 template<
typename AccessorT>
833 this->setValueOn(xyz, val);
839 template<
typename AccessorT>
842 this->setValueOnly(xyz, val);
848 template<
typename ModifyOp,
typename AccessorT>
851 this->modifyValue(xyz, op);
856 template<
typename ModifyOp,
typename AccessorT>
859 this->modifyValueAndActiveState(xyz, op);
864 template<
typename AccessorT>
867 this->setValueOff(xyz, value);
873 template<
typename AccessorT>
876 this->setActiveState(xyz, on);
882 template<
typename AccessorT>
885 return this->probeValue(xyz, val);
891 template<
typename AccessorT>
892 const ValueType&
getValue(
const Coord& xyz,
bool& state,
int& level, AccessorT&)
const 894 const Index offset = this->coordToOffset(xyz);
895 state = mValueMask.isOn(offset);
897 return mBuffer[offset];
902 template<
typename AccessorT>
914 void resetBackground(
const ValueType& oldBackground,
const ValueType& newBackground);
920 template<MergePolicy Policy>
void merge(
const LeafNode&);
921 template<MergePolicy Policy>
void merge(
const ValueType& tileValue,
bool tileActive);
922 template<MergePolicy Policy>
923 void merge(
const LeafNode& other,
const ValueType& ,
const ValueType& );
931 template<
typename OtherType>
945 template<
typename OtherType>
959 template<
typename OtherType>
962 template<
typename CombineOp>
963 void combine(
const LeafNode& other, CombineOp& op);
964 template<
typename CombineOp>
965 void combine(
const ValueType& value,
bool valueIsActive, CombineOp& op);
967 template<
typename CombineOp,
typename OtherType >
968 void combine2(
const LeafNode& other,
const OtherType&,
bool valueIsActive, CombineOp&);
969 template<
typename CombineOp,
typename OtherNodeT >
970 void combine2(
const ValueType&,
const OtherNodeT& other,
bool valueIsActive, CombineOp&);
971 template<
typename CombineOp,
typename OtherNodeT >
972 void combine2(
const LeafNode& b0,
const OtherNodeT& b1, CombineOp&);
979 template<
typename BBoxOp>
void visitActiveBBox(BBoxOp&)
const;
981 template<
typename VisitorOp>
void visit(VisitorOp&);
982 template<
typename VisitorOp>
void visit(VisitorOp&)
const;
984 template<
typename OtherLeafNodeType,
typename VisitorOp>
985 void visit2Node(OtherLeafNodeType& other, VisitorOp&);
986 template<
typename OtherLeafNodeType,
typename VisitorOp>
987 void visit2Node(OtherLeafNodeType& other, VisitorOp&)
const;
988 template<
typename IterT,
typename VisitorOp>
989 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false);
990 template<
typename IterT,
typename VisitorOp>
991 void visit2(IterT& otherIter, VisitorOp&,
bool otherIsLHS =
false)
const;
994 void prune(
const ValueType& = zeroVal<ValueType>()) {}
997 template<
typename AccessorT>
999 template<
typename NodeT>
1000 NodeT*
stealNode(
const Coord&,
const ValueType&,
bool) {
return NULL; }
1001 template<
typename NodeT>
1003 template<
typename NodeT>
1005 template<
typename ArrayT>
void getNodes(ArrayT&)
const {}
1006 template<
typename ArrayT>
void stealNodes(ArrayT&,
const ValueType&,
bool) {}
1009 void addTile(
Index level,
const Coord&,
const ValueType&,
bool);
1010 void addTile(
Index offset,
const ValueType&,
bool);
1011 template<
typename AccessorT>
1012 void addTileAndCache(
Index,
const Coord&,
const ValueType&,
bool, AccessorT&);
1015 LeafNode* touchLeaf(
const Coord&) {
return this; }
1017 template<
typename AccessorT>
1019 template<
typename NodeT,
typename AccessorT>
1023 if (!(boost::is_same<NodeT,LeafNode>::value))
return NULL;
1024 return reinterpret_cast<NodeT*
>(
this);
1028 template<
typename AccessorT>
1032 const LeafNode* probeConstLeaf(
const Coord&)
const {
return this; }
1034 template<
typename AccessorT>
1036 template<
typename AccessorT>
1039 template<
typename NodeT,
typename AccessorT>
1043 if (!(boost::is_same<NodeT,LeafNode>::value))
return NULL;
1044 return reinterpret_cast<const NodeT*
>(
this);
1058 bool isConstant(ValueType& constValue,
bool& state,
1059 const ValueType& tolerance = zeroVal<ValueType>())
const;
1072 bool isConstant(ValueType& minValue, ValueType& maxValue,
1073 bool& state,
const ValueType& tolerance = zeroVal<ValueType>())
const;
1079 friend class ::TestLeaf;
1080 template<
typename>
friend class ::TestLeafIO;
1119 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
1120 static inline void doVisit(NodeT&, VisitorOp&);
1122 template<
typename NodeT,
typename OtherNodeT,
typename VisitorOp,
1123 typename ChildAllIterT,
typename OtherChildAllIterT>
1124 static inline void doVisit2Node(NodeT&
self, OtherNodeT& other, VisitorOp&);
1126 template<
typename NodeT,
typename VisitorOp,
1127 typename ChildAllIterT,
typename OtherChildAllIterT>
1128 static inline void doVisit2(NodeT&
self, OtherChildAllIterT&, VisitorOp&,
bool otherIsLHS);
1134 NodeMaskType mValueMask;
1140 #ifndef OPENVDB_2_ABI_COMPATIBLE 1141 template<
typename T, Index Log2Dim>
1150 template<Index Dim1,
typename NodeT2>
1155 template<Index Dim1,
typename T2>
1163 template<
typename T, Index Log2Dim>
1172 template<
typename T, Index Log2Dim>
1177 mOrigin(xyz & (~(
DIM - 1)))
1182 #ifndef OPENVDB_2_ABI_COMPATIBLE 1183 template<
typename T, Index Log2Dim>
1188 mOrigin(xyz & (~(
DIM - 1)))
1194 template<
typename T, Index Log2Dim>
1197 mBuffer(other.mBuffer),
1198 mValueMask(other.mValueMask),
1199 mOrigin(other.mOrigin)
1205 template<
typename T, Index Log2Dim>
1206 template<
typename OtherValueType>
1209 mValueMask(other.mValueMask),
1210 mOrigin(other.mOrigin)
1214 static inline ValueType convertValue(
const OtherValueType& val) {
return ValueType(val); }
1218 mBuffer[i] = Local::convertValue(other.mBuffer[i]);
1223 template<
typename T, Index Log2Dim>
1224 template<
typename OtherValueType>
1228 mBuffer(background),
1229 mValueMask(other.mValueMask),
1230 mOrigin(other.mOrigin)
1235 template<
typename T, Index Log2Dim>
1236 template<
typename OtherValueType>
1239 const ValueType& offValue,
const ValueType& onValue,
TopologyCopy):
1240 mValueMask(other.mValueMask),
1241 mOrigin(other.mOrigin)
1244 mBuffer[i] = (mValueMask.
isOn(i) ? onValue : offValue);
1249 template<
typename T, Index Log2Dim>
1256 template<
typename T, Index Log2Dim>
1260 std::ostringstream ostr;
1261 ostr <<
"LeafNode @" << mOrigin <<
": " << mBuffer;
1269 template<
typename T, Index Log2Dim>
1273 assert ((xyz[0] & (
DIM-1u)) <
DIM && (xyz[1] & (
DIM-1u)) <
DIM && (xyz[2] & (
DIM-1u)) <
DIM);
1274 return ((xyz[0] & (
DIM-1u)) << 2*Log2Dim)
1275 + ((xyz[1] & (
DIM-1u)) << Log2Dim)
1276 + (xyz[2] & (
DIM-1u));
1279 template<
typename T, Index Log2Dim>
1283 assert(n<(1<< 3*Log2Dim));
1285 xyz.setX(n >> 2*Log2Dim);
1286 n &= ((1<<2*Log2Dim)-1);
1287 xyz.setY(n >> Log2Dim);
1288 xyz.setZ(n & ((1<<Log2Dim)-1));
1293 template<
typename T, Index Log2Dim>
1304 template<
typename ValueT, Index Log2Dim>
1305 inline const ValueT&
1311 template<
typename ValueT, Index Log2Dim>
1312 inline const ValueT&
1315 assert(offset <
SIZE);
1316 return mBuffer[offset];
1320 template<
typename T, Index Log2Dim>
1327 template<
typename T, Index Log2Dim>
1331 assert(offset <
SIZE);
1332 val = mBuffer[offset];
1333 return mValueMask.
isOn(offset);
1337 template<
typename T, Index Log2Dim>
1344 template<
typename T, Index Log2Dim>
1348 assert(offset <
SIZE);
1350 mValueMask.
setOff(offset);
1354 template<
typename T, Index Log2Dim>
1362 template<
typename T, Index Log2Dim>
1369 template<
typename T, Index Log2Dim>
1380 template<
typename T, Index Log2Dim>
1385 if (!clipBBox.hasOverlap(nodeBBox)) {
1387 this->
fill(background,
false);
1388 }
else if (clipBBox.isInside(nodeBBox)) {
1398 nodeBBox.intersect(clipBBox);
1400 int &x = xyz.x(), &y = xyz.y(), &z = xyz.z();
1401 for (x = nodeBBox.min().x(); x <= nodeBBox.max().x(); ++x) {
1402 for (y = nodeBBox.min().y(); y <= nodeBBox.max().y(); ++y) {
1403 for (z = nodeBBox.min().z(); z <= nodeBBox.max().z(); ++z) {
1420 template<
typename T, Index Log2Dim>
1424 #ifndef OPENVDB_2_ABI_COMPATIBLE 1428 for (
Int32 x = bbox.min().x(); x <= bbox.max().x(); ++x) {
1429 const Index offsetX = (x & (
DIM-1u)) << 2*Log2Dim;
1430 for (
Int32 y = bbox.min().y(); y <= bbox.max().y(); ++y) {
1431 const Index offsetXY = offsetX + ((y & (
DIM-1u)) << Log2Dim);
1432 for (
Int32 z = bbox.min().z(); z <= bbox.max().z(); ++z) {
1433 const Index offset = offsetXY + (z & (
DIM-1u));
1434 mBuffer[offset] = value;
1435 mValueMask.
set(offset, active);
1441 template<
typename T, Index Log2Dim>
1445 mBuffer.
fill(value);
1448 template<
typename T, Index Log2Dim>
1452 mBuffer.
fill(value);
1453 mValueMask.
set(active);
1460 template<
typename T, Index Log2Dim>
1461 template<
typename DenseT>
1465 #ifndef OPENVDB_2_ABI_COMPATIBLE 1469 typedef typename DenseT::ValueType DenseValueType;
1471 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1472 const Coord&
min = dense.bbox().min();
1473 DenseValueType* t0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1474 const T* s0 = &mBuffer[bbox.min()[2] & (
DIM-1u)];
1475 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0] + 1; x < ex; ++x) {
1476 DenseValueType* t1 = t0 + xStride * (x - min[0]);
1477 const T* s1 = s0 + ((x & (
DIM-1u)) << 2*Log2Dim);
1478 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1] + 1; y < ey; ++y) {
1479 DenseValueType* t2 = t1 + yStride * (y - min[1]);
1480 const T* s2 = s1 + ((y & (
DIM-1u)) << Log2Dim);
1481 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2] + 1; z < ez; ++z, t2 += zStride) {
1482 *t2 = DenseValueType(*s2++);
1489 template<
typename T, Index Log2Dim>
1490 template<
typename DenseT>
1493 const ValueType& background,
const ValueType& tolerance)
1495 #ifndef OPENVDB_2_ABI_COMPATIBLE 1499 typedef typename DenseT::ValueType DenseValueType;
1501 const size_t xStride = dense.xStride(), yStride = dense.yStride(), zStride = dense.zStride();
1502 const Coord&
min = dense.bbox().min();
1504 const DenseValueType* s0 = dense.data() + zStride * (bbox.min()[2] - min[2]);
1505 const Int32 n0 = bbox.min()[2] & (
DIM-1u);
1506 for (
Int32 x = bbox.min()[0], ex = bbox.max()[0]+1; x < ex; ++x) {
1507 const DenseValueType* s1 = s0 + xStride * (x - min[0]);
1509 for (
Int32 y = bbox.min()[1], ey = bbox.max()[1]+1; y < ey; ++y) {
1510 const DenseValueType* s2 = s1 + yStride * (y - min[1]);
1512 for (
Int32 z = bbox.min()[2], ez = bbox.max()[2]+1; z < ez; ++z, ++n2, s2 += zStride) {
1515 mBuffer[n2] = background;
1517 mValueMask.
setOn(n2);
1529 template<
typename T, Index Log2Dim>
1533 mValueMask.
load(is);
1537 template<
typename T, Index Log2Dim>
1541 mValueMask.
save(os);
1548 #ifndef OPENVDB_2_ABI_COMPATIBLE 1549 template<
typename T, Index Log2Dim>
1553 if (!this->isOutOfCore())
return;
1559 tbb::spin_mutex::scoped_lock lock(self->mMutex);
1560 if (!this->isOutOfCore())
return;
1562 boost::scoped_ptr<FileInfo> info(self->mFileInfo);
1563 assert(info.get() != NULL);
1564 assert(info->mapping.get() != NULL);
1565 assert(info->meta.get() != NULL);
1571 boost::shared_ptr<std::streambuf> buf = info->mapping->createBuffer();
1572 std::istream is(buf.get());
1577 is.seekg(info->maskpos);
1580 is.seekg(info->bufpos);
1583 self->setOutOfCore(
false);
1591 template<
typename T, Index Log2Dim>
1595 this->
readBuffers(is, CoordBBox::inf(), fromHalf);
1599 template<
typename T, Index Log2Dim>
1603 #ifndef OPENVDB_2_ABI_COMPATIBLE 1604 std::streamoff maskpos = is.tellg();
1608 mValueMask.
load(is);
1610 int8_t numBuffers = 1;
1613 is.read(reinterpret_cast<char*>(&mOrigin),
sizeof(Coord::ValueType) * 3);
1616 is.read(reinterpret_cast<char*>(&numBuffers),
sizeof(int8_t));
1620 if (!clipBBox.hasOverlap(nodeBBox)) {
1626 mBuffer.setOutOfCore(
false);
1628 #ifndef OPENVDB_2_ABI_COMPATIBLE 1634 const bool delayLoad = ((mappedFile.get() != NULL) && clipBBox.isInside(nodeBBox));
1637 mBuffer.setOutOfCore(
true);
1654 mBuffer.setOutOfCore(
false);
1657 T background = zeroVal<T>();
1659 background = *
static_cast<const T*
>(bgPtr);
1661 this->
clip(clipBBox, background);
1662 #ifndef OPENVDB_2_ABI_COMPATIBLE 1667 if (numBuffers > 1) {
1672 for (
int i = 1; i < numBuffers; ++i) {
1676 io::readData<T>(is, temp.
mData,
SIZE, zipped);
1683 template<
typename T, Index Log2Dim>
1688 mValueMask.
save(os);
1690 mBuffer.loadValues();
1693 mValueMask, NodeMaskType(), toHalf);
1700 template<
typename T, Index Log2Dim>
1704 return mOrigin == other.mOrigin &&
1705 mValueMask == other.mValueMask &&
1706 mBuffer == other.mBuffer;
1710 template<
typename T, Index Log2Dim>
1716 return sizeof(*this) + mBuffer.
memUsage() -
sizeof(mBuffer);
1720 template<
typename T, Index Log2Dim>
1725 if (bbox.isInside(this_bbox))
return;
1729 for(; iter; ++iter) this_bbox.expand(this->offsetToLocalCoord(iter.pos()));
1730 this_bbox.translate(this->
origin());
1732 bbox.expand(this_bbox);
1737 template<
typename T, Index Log2Dim>
1738 template<
typename OtherType, Index OtherLog2Dim>
1743 return (Log2Dim == OtherLog2Dim && mValueMask == other->
getValueMask());
1747 template<
typename T, Index Log2Dim>
1750 const ValueType& tolerance)
const 1752 state = mValueMask.
isOn();
1753 if (!(state || mValueMask.
isOff()))
return false;
1762 template<
typename T, Index Log2Dim>
1765 bool& state,
const ValueType& tolerance)
const 1767 state = mValueMask.
isOn();
1768 if (!(state || mValueMask.
isOff()))
return false;
1770 const T range = 2 * tolerance;
1771 minValue = maxValue = mBuffer[0];
1773 const T& v = mBuffer[i];
1775 if ((maxValue - v) > range)
return false;
1777 }
else if (v > maxValue) {
1778 if ((v - minValue) > range)
return false;
1788 template<
typename T, Index Log2Dim>
1795 template<
typename T, Index Log2Dim>
1799 assert(offset <
SIZE);
1804 template<
typename T, Index Log2Dim>
1805 template<
typename AccessorT>
1808 const ValueType& val,
bool active, AccessorT&)
1810 this->
addTile(level, xyz, val, active);
1817 template<
typename T, Index Log2Dim>
1820 const ValueType& newBackground)
1822 #ifndef OPENVDB_2_ABI_COMPATIBLE 1828 for (iter = this->mValueMask.
beginOff(); iter; ++iter) {
1829 ValueType &inactiveValue = mBuffer[iter.
pos()];
1831 inactiveValue = newBackground;
1839 template<
typename T, Index Log2Dim>
1840 template<MergePolicy Policy>
1844 #ifndef OPENVDB_2_ABI_COMPATIBLE 1851 for (; iter; ++iter) {
1853 if (mValueMask.
isOff(n)) {
1854 mBuffer[n] = other.mBuffer[n];
1855 mValueMask.
setOn(n);
1861 template<
typename T, Index Log2Dim>
1862 template<MergePolicy Policy>
1865 const ValueType& ,
const ValueType& )
1867 this->
template merge<Policy>(other);
1870 template<
typename T, Index Log2Dim>
1871 template<MergePolicy Policy>
1875 #ifndef OPENVDB_2_ABI_COMPATIBLE 1881 if (!tileActive)
return;
1884 const Index n = iter.pos();
1885 mBuffer[n] = tileValue;
1886 mValueMask.
setOn(n);
1892 template<
typename T, Index Log2Dim>
1893 template<
typename OtherType>
1900 template<
typename T, Index Log2Dim>
1901 template<
typename OtherType>
1909 template<
typename T, Index Log2Dim>
1910 template<
typename OtherType>
1918 template<
typename T, Index Log2Dim>
1922 #ifndef OPENVDB_2_ABI_COMPATIBLE 1926 mBuffer[i] = -mBuffer[i];
1934 template<
typename T, Index Log2Dim>
1935 template<
typename CombineOp>
1939 #ifndef OPENVDB_2_ABI_COMPATIBLE 1945 .setAIsActive(mValueMask.
isOn(i))
1946 .setBRef(other.mBuffer[i])
1947 .setBIsActive(other.mValueMask.
isOn(i))
1948 .setResultRef(mBuffer[i]));
1954 template<
typename T, Index Log2Dim>
1955 template<
typename CombineOp>
1959 #ifndef OPENVDB_2_ABI_COMPATIBLE 1963 args.
setBRef(value).setBIsActive(valueIsActive);
1966 .setAIsActive(mValueMask.
isOn(i))
1967 .setResultRef(mBuffer[i]));
1976 template<
typename T, Index Log2Dim>
1977 template<
typename CombineOp,
typename OtherType>
1980 bool valueIsActive, CombineOp& op)
1982 #ifndef OPENVDB_2_ABI_COMPATIBLE 1986 args.
setBRef(value).setBIsActive(valueIsActive);
1988 op(args.
setARef(other.mBuffer[i])
1989 .setAIsActive(other.mValueMask.
isOn(i))
1990 .setResultRef(mBuffer[i]));
1996 template<
typename T, Index Log2Dim>
1997 template<
typename CombineOp,
typename OtherNodeT>
2000 bool valueIsActive, CombineOp& op)
2002 #ifndef OPENVDB_2_ABI_COMPATIBLE 2006 args.
setARef(value).setAIsActive(valueIsActive);
2008 op(args.
setBRef(other.mBuffer[i])
2009 .setBIsActive(other.mValueMask.isOn(i))
2010 .setResultRef(mBuffer[i]));
2016 template<
typename T, Index Log2Dim>
2017 template<
typename CombineOp,
typename OtherNodeT>
2021 #ifndef OPENVDB_2_ABI_COMPATIBLE 2026 mValueMask.
set(i, b0.mValueMask.
isOn(i) || b1.mValueMask.isOn(i));
2027 op(args.
setARef(b0.mBuffer[i])
2028 .setAIsActive(b0.mValueMask.
isOn(i))
2029 .setBRef(b1.mBuffer[i])
2030 .setBIsActive(b1.mValueMask.isOn(i))
2031 .setResultRef(mBuffer[i]));
2040 template<
typename T, Index Log2Dim>
2041 template<
typename BBoxOp>
2045 if (op.template descent<LEVEL>()) {
2048 op.operator()<
LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
2050 op.template operator()<
LEVEL>(CoordBBox::createCube(i.getCoord(), 1));
2063 template<
typename T, Index Log2Dim>
2064 template<
typename VisitorOp>
2068 doVisit<LeafNode, VisitorOp, ChildAllIter>(*
this, op);
2072 template<
typename T, Index Log2Dim>
2073 template<
typename VisitorOp>
2077 doVisit<const LeafNode, VisitorOp, ChildAllCIter>(*
this, op);
2081 template<
typename T, Index Log2Dim>
2082 template<
typename NodeT,
typename VisitorOp,
typename ChildAllIterT>
2086 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
2095 template<
typename T, Index Log2Dim>
2096 template<
typename OtherLeafNodeType,
typename VisitorOp>
2101 typename OtherLeafNodeType::ChildAllIter>(*
this, other, op);
2105 template<
typename T, Index Log2Dim>
2106 template<
typename OtherLeafNodeType,
typename VisitorOp>
2111 typename OtherLeafNodeType::ChildAllCIter>(*
this, other, op);
2115 template<
typename T, Index Log2Dim>
2118 typename OtherNodeT,
2120 typename ChildAllIterT,
2121 typename OtherChildAllIterT>
2126 BOOST_STATIC_ASSERT(OtherNodeT::SIZE == NodeT::SIZE);
2127 BOOST_STATIC_ASSERT(OtherNodeT::LEVEL == NodeT::LEVEL);
2129 ChildAllIterT iter =
self.beginChildAll();
2130 OtherChildAllIterT otherIter = other.beginChildAll();
2132 for ( ; iter && otherIter; ++iter, ++otherIter) {
2133 op(iter, otherIter);
2141 template<
typename T, Index Log2Dim>
2142 template<
typename IterT,
typename VisitorOp>
2146 doVisit2<LeafNode, VisitorOp, ChildAllIter, IterT>(
2147 *
this, otherIter, op, otherIsLHS);
2151 template<
typename T, Index Log2Dim>
2152 template<
typename IterT,
typename VisitorOp>
2156 doVisit2<const LeafNode, VisitorOp, ChildAllCIter, IterT>(
2157 *
this, otherIter, op, otherIsLHS);
2161 template<
typename T, Index Log2Dim>
2165 typename ChildAllIterT,
2166 typename OtherChildAllIterT>
2169 VisitorOp& op,
bool otherIsLHS)
2171 if (!otherIter)
return;
2174 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
2175 op(otherIter, iter);
2178 for (ChildAllIterT iter =
self.
beginChildAll(); iter; ++iter) {
2179 op(iter, otherIter);
2188 template<
typename T, Index Log2Dim>
2189 inline std::ostream&
2190 operator<<(std::ostream& os, const typename LeafNode<T, Log2Dim>::Buffer& buf)
2192 for (
Index32 i = 0, N = buf.size(); i < N; ++i) os << buf.mData[i] <<
", ";
2207 #endif // OPENVDB_TREE_LEAFNODE_HAS_BEEN_INCLUDED LeafNode * touchLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1018
std::streamoff maskpos
Definition: LeafNode.h:101
void fill(const CoordBBox &bbox, const ValueType &, bool active=true)
Set all voxels within an axis-aligned box to the specified value and active state.
Definition: LeafNode.h:1422
void setValueOn(Index offset, const ValueType &val)
Set the value of the voxel at the given offset and mark the voxel as active.
Definition: LeafNode.h:722
T ValueType
Definition: LeafNode.h:68
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:116
bool isAllocated() const
Return true if memory for this node's buffer has been allocated.
Definition: LeafNode.h:452
ValueAllCIter cendValueAll() const
Definition: LeafNode.h:608
Index64 offVoxelCount() const
Return the number of voxels marked Off.
Definition: LeafNode.h:440
void writeBuffers(std::ostream &os, bool toHalf=false) const
Write buffers to a stream.
Definition: LeafNode.h:1685
void load(std::istream &is)
Definition: NodeMasks.h:555
Index32 Index
Definition: Types.h:58
ValueOffCIter cendValueOff() const
Definition: LeafNode.h:605
const ValueType * data() const
Return a const pointer to the array of voxel values.
Definition: LeafNode.h:267
static Index coordToOffset(const Coord &xyz)
Return the linear table offset of the given global or local coordinates.
Definition: LeafNode.h:1271
void setItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:523
ChildOffCIter cendChildOff() const
Definition: LeafNode.h:627
const NodeMaskType & getValueMask() const
Definition: LeafNode.h:1105
CombineArgs & setBRef(const BValueType &b)
Redirect the B value to a new external source.
Definition: Types.h:344
Coord offsetToGlobalCoord(Index n) const
Return the global coordinates for a linear table offset.
Definition: LeafNode.h:1295
Definition: LeafNode.h:504
void setValueOffAndCache(const Coord &xyz, const ValueType &value, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as inactive.
Definition: LeafNode.h:865
NodeT * probeNode(const Coord &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1002
const ValueType & getFirstValue() const
Return a const reference to the first value in the buffer.
Definition: LeafNode.h:908
Definition: LeafNode.h:552
ChildOnIter beginChildOn()
Definition: LeafNode.h:616
void addTile(Index level, const Coord &, const ValueType &, bool)
Definition: LeafNode.h:1790
ValueAllCIter endValueAll() const
Definition: LeafNode.h:609
void negate()
Definition: LeafNode.h:1920
LeafNode< OtherValueType, Log2Dim > Type
Definition: LeafNode.h:86
boost::shared_ptr< MappedFile > Ptr
Definition: io.h:135
Index32 pos() const
Definition: NodeMasks.h:193
const ValueType & getLastValue() const
Return a const reference to the last value in the buffer.
Definition: LeafNode.h:910
NodeT * stealNode(const Coord &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1000
void setValueMask(const NodeMaskType &mask)
Definition: LeafNode.h:1107
bool operator==(const LeafNode &other) const
Check for buffer, state and origin equivalence.
Definition: LeafNode.h:1702
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
Definition: LeafNode.h:50
static Index getLevel()
Return the level of this node, which by definition is zero for LeafNodes.
Definition: LeafNode.h:427
bool isEmpty() const
Return true if this node has no active voxels.
Definition: LeafNode.h:446
SparseIteratorBase< MaskIterT, ValueIter, NodeT, ValueT > BaseT
Definition: LeafNode.h:514
static const Index LEVEL
Definition: LeafNode.h:80
const ValueType & getValue(Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafNode.h:181
ValueOffIter beginValueOff()
Definition: LeafNode.h:597
void setValueMask(Index n, bool on)
Definition: LeafNode.h:1112
void swap(Buffer &other)
Exchange this buffer's values with the other buffer's values.
Definition: LeafNode.h:241
static Coord offsetToLocalCoord(Index n)
Return the local coordinates for a linear table offset, where offset 0 has coordinates (0...
Definition: LeafNode.h:1281
ChildOffCIter beginChildOff() const
Definition: LeafNode.h:618
ChildAllCIter cbeginChildAll() const
Definition: LeafNode.h:620
void setValue(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNode.h:720
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
static Index dim()
Return the number of voxels in each coordinate dimension.
Definition: LeafNode.h:421
bool probeValueAndCache(const Coord &xyz, ValueType &val, AccessorT &) const
Return true if the voxel at the given coordinates is active and return the voxel value in val...
Definition: LeafNode.h:883
SameConfiguration<OtherNodeType>::value is true if and only if OtherNodeType is the type of a LeafNod...
Definition: LeafNode.h:92
bool isValueOn(const Coord &xyz) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:763
CoordBBox getNodeBoundingBox() const
Return the bounding box of this node, i.e., the full index space spanned by this leaf node...
Definition: LeafNode.h:467
bool resultIsActive() const
Definition: Types.h:353
ChildIter< MaskOffIterator, const LeafNode, ChildOff > ChildOffCIter
Definition: LeafNode.h:588
ChildOnCIter cendChildOn() const
Definition: LeafNode.h:624
Definition: LeafNode.h:504
Bit mask for the internal and leaf nodes of VDB. This is a 64-bit implementation. ...
Definition: NodeMasks.h:304
void setValueOn(const Coord &xyz)
Mark the voxel at the given coordinates as active but don't change its value.
Definition: LeafNode.h:712
static Index32 nonLeafCount()
Return the non-leaf count for this node, which is zero.
Definition: LeafNode.h:435
Definition: NodeMasks.h:205
io::MappedFile::Ptr mapping
Definition: LeafNode.h:102
void writeCompressedValues(std::ostream &os, ValueT *srcBuf, Index srcCount, const MaskT &valueMask, const MaskT &childMask, bool toHalf)
Definition: Compression.h:431
Definition: NodeMasks.h:236
Buffer & buffer()
Definition: LeafNode.h:641
uint32_t Index32
Definition: Types.h:56
ValueType WordType
Definition: LeafNode.h:127
void getOrigin(Int32 &x, Int32 &y, Int32 &z) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:475
bool isOutOfCore() const
Return true if this buffer's values have not yet been read from disk.
Definition: LeafNode.h:162
void setActiveState(Index offset, bool on)
Set the active state of the voxel at the given offset but don't change its value. ...
Definition: LeafNode.h:694
void modifyValue(Index offset, const ModifyOp &op)
Apply a functor to the value of the voxel at the given offset and mark the voxel as active...
Definition: LeafNode.h:730
ValueOnCIter endValueOn() const
Definition: LeafNode.h:603
void topologyDifference(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Difference this node's set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if the original voxel is active in this LeafNode and inactive in the other LeafNode.
Definition: LeafNode.h:1912
Buffer(PartialCreate, const ValueType &)
Construct a buffer but don't allocate memory for the full array of values.
Definition: LeafNode.h:150
ValueOnCIter beginValueOn() const
Definition: LeafNode.h:593
DenseIter()
Definition: LeafNode.h:558
void visit(VisitorOp &)
Definition: LeafNode.h:2066
const Buffer & buffer() const
Definition: LeafNode.h:640
const ValueType & getValue(const Coord &xyz, bool &state, int &level, AccessorT &) const
Return the value of the voxel at the given coordinates and return its active state and level (i...
Definition: LeafNode.h:892
void setValueOn(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: LeafNode.h:716
ValueOnIter beginValueOn()
Definition: LeafNode.h:594
FileInfo()
Definition: LeafNode.h:99
void unsetItem(Index pos, const ValueT &value) const
Definition: LeafNode.h:572
bool isValueMaskOff(Index n) const
Definition: LeafNode.h:1103
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
DenseIter< const LeafNode, const ValueType, ChildAll > ChildAllCIter
Definition: LeafNode.h:590
ValueOnCIter cendValueOn() const
Definition: LeafNode.h:602
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:370
ValueAllCIter beginValueAll() const
Definition: LeafNode.h:599
void setValue(const ValueT &value) const
Definition: LeafNode.h:528
ValueOnIter endValueOn()
Definition: LeafNode.h:604
Array of fixed size that stores the voxel values of a LeafNode.
Definition: LeafNode.h:109
ValueIter< MaskDenseIterator, LeafNode, const ValueType, ValueAll > ValueAllIter
Definition: LeafNode.h:583
void resetBackground(const ValueType &oldBackground, const ValueType &newBackground)
Replace inactive occurrences of oldBackground with newBackground, and inactive occurrences of -oldBac...
Definition: LeafNode.h:1819
OPENVDB_API void setStreamMetadataPtr(std::ios_base &, boost::shared_ptr< StreamMetadata > &, bool transfer=true)
Associate the given stream with (a shared pointer to) an object that stores metadata (file format...
ValueT & getValue() const
Definition: LeafNode.h:520
bool isChildMaskOn(Index) const
Definition: LeafNode.h:1108
ValueIter< MaskOnIterator, const LeafNode, const ValueType, ValueOn > ValueOnCIter
Definition: LeafNode.h:580
Definition: LeafNode.h:508
Buffer(const ValueType &val)
Construct a buffer populated with the specified value.
Definition: LeafNode.h:132
void readBuffers(std::istream &is, bool fromHalf=false)
Read buffers from a stream.
Definition: LeafNode.h:1593
Definition: LeafNode.h:505
ValueOffCIter endValueOff() const
Definition: LeafNode.h:606
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 operator!=(const LeafNode &other) const
Definition: LeafNode.h:496
Index64 onLeafVoxelCount() const
Definition: LeafNode.h:441
ChildAllIter beginChildAll()
Definition: LeafNode.h:622
const ValueType & getValueAndCache(const Coord &xyz, AccessorT &) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:818
Index64 offLeafVoxelCount() const
Definition: LeafNode.h:442
ChildAllCIter beginChildAll() const
Definition: LeafNode.h:621
const NodeT * probeConstNodeAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1040
void visitActiveBBox(BBoxOp &) const
Calls the templated functor BBoxOp with bounding box information. An additional level argument is pro...
Definition: LeafNode.h:2043
OPENVDB_API boost::shared_ptr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
ValueAllCIter cbeginValueAll() const
Definition: LeafNode.h:598
const LeafNode * probeLeaf(const Coord &) const
Return a const pointer to this node.
Definition: LeafNode.h:1038
bool allocate()
Allocate memory for this node's buffer if it has not already been allocated.
Definition: LeafNode.h:454
bool hasSameTopology(const LeafNode< OtherType, OtherLog2Dim > *other) const
Return true if the given node (which may have a different ValueType than this node) has the same acti...
Definition: LeafNode.h:1740
bool isOn(Index32 n) const
Return true if the nth bit is on.
Definition: NodeMasks.h:499
Definition: version.h:110
void combine2(const LeafNode &other, const OtherType &, bool valueIsActive, CombineOp &)
Definition: LeafNode.h:1979
ChildIter< MaskOnIterator, const LeafNode, ChildOn > ChildOnCIter
Definition: LeafNode.h:586
~Buffer()
Destructor.
Definition: LeafNode.h:152
ChildAllCIter cendChildAll() const
Definition: LeafNode.h:630
ChildOffCIter endChildOff() const
Definition: LeafNode.h:628
Definition: PointIndexGrid.h:68
NodeT * probeNodeAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1020
Definition: Compression.h:211
static Index64 offTileCount()
Definition: LeafNode.h:444
ValueIter< MaskOffIterator, LeafNode, const ValueType, ValueOff > ValueOffIter
Definition: LeafNode.h:581
void modifyItem(Index n, const ModifyOp &op) const
Definition: LeafNode.h:535
#define OPENVDB_VERSION_NAME
Definition: version.h:43
ChildOffCIter cbeginChildOff() const
Definition: LeafNode.h:617
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
OffIterator beginOff() const
Definition: NodeMasks.h:351
const ValueType & operator[](Index i) const
Return a const reference to the i'th element of this buffer.
Definition: LeafNode.h:183
ValueIter()
Definition: LeafNode.h:516
void setValuesOn()
Mark all voxels as active but don't change their values.
Definition: LeafNode.h:758
~LeafNode()
Destructor.
Definition: LeafNode.h:1251
bool isChildMaskOff() const
Definition: LeafNode.h:1110
bool isInactive() const
Return true if all of this node's values are inactive.
Definition: LeafNode.h:1076
NodeMaskType::OnIterator MaskOnIterator
Definition: LeafNode.h:499
ChildOnIter endChildOn()
Definition: LeafNode.h:626
static Index getValueLevelAndCache(const Coord &, AccessorT &)
Return the LEVEL (=0) at which leaf node values reside.
Definition: LeafNode.h:903
void addLeafAndCache(LeafNode *, AccessorT &)
This function exists only to enable template instantiation.
Definition: LeafNode.h:998
bool empty() const
Return true if memory for this buffer has not yet been allocated.
Definition: LeafNode.h:164
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNode.h:740
void setActiveState(const Coord &xyz, bool on)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: LeafNode.h:1356
void clip(const CoordBBox &, const ValueType &background)
Set all voxels that lie outside the given axis-aligned box to the background.
Definition: LeafNode.h:1382
boost::shared_ptr< io::StreamMetadata > meta
Definition: LeafNode.h:103
void setActiveStateAndCache(const Coord &xyz, bool on, AccessorT &)
Set the active state of the voxel at the given coordinates without changing its value.
Definition: LeafNode.h:874
ChildIter()
Definition: LeafNode.h:546
ChildOnCIter beginChildOn() const
Definition: LeafNode.h:615
Definition: LeafNode.h:505
Buffer(const Buffer &other)
Copy constructor.
Definition: LeafNode.h:137
void readCompressedValues(std::istream &is, ValueT *destBuf, Index destCount, const MaskT &valueMask, bool fromHalf)
Definition: Compression.h:329
CombineArgs & setARef(const AValueType &a)
Redirect the A value to a new external source.
Definition: Types.h:342
Definition: LeafNode.h:505
ChildIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:547
Buffer & operator=(const Buffer &other)
Copy the other buffer's values into this buffer.
Definition: LeafNode.h:197
std::string str() const
Return a string representation of this node.
Definition: LeafNode.h:1258
ValueIter< MaskDenseIterator, const LeafNode, const ValueType, ValueAll > ValueAllCIter
Definition: LeafNode.h:584
void modifyValueAndActiveStateAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Definition: LeafNode.h:857
static void getNodeLog2Dims(std::vector< Index > &dims)
Append the Log2Dim of this LeafNode to the specified vector.
Definition: LeafNode.h:429
void set(Index32 n, bool On)
Set the nth bit to the specified state.
Definition: NodeMasks.h:459
Definition: Exceptions.h:39
void swap(Buffer &other)
Exchange this node's data buffer with the given data buffer without changing the active states of the...
Definition: LeafNode.h:639
BaseT::NonConstValueType NonConstValueT
Definition: LeafNode.h:556
std::streamoff bufpos
Definition: LeafNode.h:100
const LeafNode * probeLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1037
bool operator==(const Buffer &other) const
Return true if the contents of the other buffer exactly equal the contents of this buffer...
Definition: LeafNode.h:225
bool isOff(Index32 n) const
Return true if the nth bit is off.
Definition: NodeMasks.h:505
ValueIter< MaskOnIterator, LeafNode, const ValueType, ValueOn > ValueOnIter
Definition: LeafNode.h:579
OPENVDB_API uint32_t getDataCompression(std::ios_base &)
Return a bitwise OR of compression option flags (COMPRESS_ZIP, COMPRESS_ACTIVE_MASK, etc.) specifying whether and how input data is compressed or output data should be compressed.
ChildIter< MaskOffIterator, LeafNode, ChildOff > ChildOffIter
Definition: LeafNode.h:587
void visit2Node(OtherLeafNodeType &other, VisitorOp &)
Definition: LeafNode.h:2098
void topologyUnion(const LeafNode< OtherType, Log2Dim > &other)
Union this node's set of active values with the active values of the other node, whose ValueType may ...
Definition: LeafNode.h:1895
ValueOffCIter beginValueOff() const
Definition: LeafNode.h:596
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1306
void setValueMaskOff(Index n)
Definition: LeafNode.h:1114
void combine(const LeafNode &other, CombineOp &op)
Definition: LeafNode.h:1937
util::NodeMask< Log2Dim > NodeMaskType
Definition: LeafNode.h:71
bool isValueOnAndCache(const Coord &xyz, AccessorT &) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:826
void addTileAndCache(Index, const Coord &, const ValueType &, bool, AccessorT &)
Definition: LeafNode.h:1807
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
static Index size()
Return the number of values contained in this buffer.
Definition: LeafNode.h:262
ValueOnCIter cbeginValueOn() const
Definition: LeafNode.h:592
static Index32 leafCount()
Return the leaf count for this node, which is one.
Definition: LeafNode.h:433
ChildOnCIter cbeginChildOn() const
Definition: LeafNode.h:614
void readTopology(std::istream &is, bool fromHalf=false)
Read in just the topology.
Definition: LeafNode.h:1531
static void evalNodeOrigin(Coord &xyz)
Compute the origin of the leaf node that contains the voxel with the given coordinates.
Definition: LeafNode.h:1117
void copyToDense(const CoordBBox &bbox, DenseT &dense) const
Copy into a dense grid the values of the voxels that lie within a given bounding box.
Definition: LeafNode.h:1463
ValueType * data()
Return a pointer to the array of voxel values.
Definition: LeafNode.h:287
void setOff(Index32 n)
Set the nth bit off.
Definition: NodeMasks.h:454
ChildOffIter endChildOff()
Definition: LeafNode.h:629
Definition: LeafNode.h:97
Definition: NodeMasks.h:267
Index64 onVoxelCount() const
Return the number of voxels marked On.
Definition: LeafNode.h:438
bool isValueMaskOn(Index n) const
Definition: LeafNode.h:1101
DenseIteratorBase< MaskDenseIterator, DenseIter, NodeT, void, ValueT > BaseT
Definition: LeafNode.h:555
bool isDense() const
Return true if this node contains only active voxels.
Definition: LeafNode.h:448
static Index64 onTileCount()
Definition: LeafNode.h:443
static Index size()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:423
bool isValueOn(Index offset) const
Return true if the voxel at the given offset is active.
Definition: LeafNode.h:765
void modifyValueAndCache(const Coord &xyz, const ModifyOp &op, AccessorT &)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: LeafNode.h:849
static const Index SIZE
Definition: LeafNode.h:79
void setValueMaskOn(Index n)
Definition: LeafNode.h:1113
Leaf nodes have no children, so their child iterators have no get/set accessors.
Definition: LeafNode.h:543
bool isChildMaskOff(Index) const
Definition: LeafNode.h:1109
ChildAllIter endChildAll()
Definition: LeafNode.h:632
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
void getOrigin(Coord &origin) const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:474
bool operator!=(const Buffer &other) const
Return true if the contents of the other buffer are not exactly equal to the contents of this buffer...
Definition: LeafNode.h:238
void getNodes(ArrayT &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:1005
NodeMaskType & getValueMask()
Definition: LeafNode.h:1106
static void doVisit2(NodeT &self, OtherChildAllIterT &, VisitorOp &, bool otherIsLHS)
Definition: LeafNode.h:2168
static Index getChildDim()
Return the dimension of child nodes of this LeafNode, which is one for voxels.
Definition: LeafNode.h:431
ChildOffIter beginChildOff()
Definition: LeafNode.h:619
Index64 memUsage() const
Return the memory in bytes occupied by this node.
Definition: LeafNode.h:1712
ValueT & getItem(Index pos) const
Definition: LeafNode.h:519
bool probeValue(const Coord &xyz, ValueType &val) const
Return true if the voxel at the given coordinates is active.
Definition: LeafNode.h:1322
const NodeT * probeConstNode(const Coord &) const
This function exists only to enable template instantiation.
Definition: LeafNode.h:1004
static void doVisit2Node(NodeT &self, OtherNodeT &other, VisitorOp &)
Definition: LeafNode.h:2123
bool getItem(Index pos, void *&child, NonConstValueT &value) const
Definition: LeafNode.h:561
static Index getValueLevel(const Coord &)
Return the level (i.e., 0) at which leaf node values reside.
Definition: LeafNode.h:689
ChildAllCIter endChildAll() const
Definition: LeafNode.h:631
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:304
NodeMaskType::OffIterator MaskOffIterator
Definition: LeafNode.h:500
bool isValueMaskOn() const
Definition: LeafNode.h:1102
void setOn(Index32 n)
Set the nth bit on.
Definition: NodeMasks.h:449
void setValueOff(Index offset)
Mark the voxel at the given offset as inactive but don't change its value.
Definition: LeafNode.h:704
FileInfo * mFileInfo
Definition: LeafNode.h:360
int32_t Int32
Definition: Types.h:60
void setValueOnly(const Coord &xyz, const ValueType &val)
Set the value of the voxel at the given coordinates but don't change its active state.
Definition: LeafNode.h:1364
ValueAllIter endValueAll()
Definition: LeafNode.h:610
uint64_t Index64
Definition: Types.h:57
static const Index LOG2DIM
Definition: LeafNode.h:74
bool allocate()
Allocate memory for this buffer if it has not already been allocated.
Definition: LeafNode.h:167
LeafNode * probeLeafAndCache(const Coord &, AccessorT &)
Return a pointer to this node.
Definition: LeafNode.h:1029
Definition: Compression.h:79
ValueIter< MaskOffIterator, const LeafNode, const ValueType, ValueOff > ValueOffCIter
Definition: LeafNode.h:582
void voxelizeActiveTiles()
Definition: LeafNode.h:918
LeafNode()
Default constructor.
Definition: LeafNode.h:1165
void modifyValue(const ModifyOp &op) const
Definition: LeafNode.h:538
NodeMaskType::DenseIterator MaskDenseIterator
Definition: LeafNode.h:501
void setValue(Index i, const ValueType &val)
Set the i'th value of this buffer to the specified value.
Definition: LeafNode.h:185
static Index numValues()
Return the total number of voxels represented by this LeafNode.
Definition: LeafNode.h:425
static Index log2dim()
Return log2 of the dimension of this LeafNode, e.g. 3 if dimensions are 8^3.
Definition: LeafNode.h:419
OnIterator beginOn() const
Definition: NodeMasks.h:349
void setValueAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates and mark it as active.
Definition: LeafNode.h:831
ValueOffCIter cbeginValueOff() const
Definition: LeafNode.h:595
static bool hasActiveTiles()
Return false since leaf nodes never contain tiles.
Definition: LeafNode.h:768
ValueConverter<T>::Type is the type of a LeafNode having the same dimensions as this node but a diffe...
Definition: LeafNode.h:85
OPENVDB_API boost::shared_ptr< MappedFile > getMappedFilePtr(std::ios_base &)
Return a shared pointer to the memory-mapped file with which the given stream is associated, or a null pointer if the stream is not associated with a memory-mapped file.
void visit2(IterT &otherIter, VisitorOp &, bool otherIsLHS=false)
Definition: LeafNode.h:2144
void evalActiveBoundingBox(CoordBBox &bbox, bool visitVoxels=true) const
Definition: LeafNode.h:1722
void setValueOff(const Coord &xyz)
Mark the voxel at the given coordinates as inactive but don't change its value.
Definition: LeafNode.h:702
Templated block class to hold specific data types and a fixed number of values determined by Log2Dim...
Definition: LeafNode.h:65
DenseIter< LeafNode, ValueType, ChildAll > ChildAllIter
Definition: LeafNode.h:589
LeafNode< ValueType, Log2Dim > LeafNodeType
Definition: LeafNode.h:69
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Index memUsage() const
Return the memory footprint of this buffer in bytes.
Definition: LeafNode.h:250
ValueAllIter beginValueAll()
Definition: LeafNode.h:600
void addLeaf(LeafNode *)
This function exists only to enable template instantiation.
Definition: LeafNode.h:996
ChildOnCIter endChildOn() const
Definition: LeafNode.h:625
bool isValueMaskOff() const
Definition: LeafNode.h:1104
void copyFromDense(const CoordBBox &bbox, const DenseT &dense, const ValueType &background, const ValueType &tolerance)
Copy from a dense grid into this node the values of the voxels that lie within a given bounding box...
Definition: LeafNode.h:1492
ChildIter< MaskOnIterator, LeafNode, ChildOn > ChildOnIter
Definition: LeafNode.h:585
static const Index DIM
Definition: LeafNode.h:76
void fill(const ValueType &val)
Populate this buffer with a constant value.
Definition: LeafNode.h:170
Buffer()
Default constructor.
Definition: LeafNode.h:130
void setValueOn(Index offset)
Mark the voxel at the given offset as active but don't change its value.
Definition: LeafNode.h:714
void topologyIntersection(const LeafNode< OtherType, Log2Dim > &other, const ValueType &)
Intersect this node's set of active values with the active values of the other node, whose ValueType may be different. So a resulting voxel will be active only if both of the original voxels were active.
Definition: LeafNode.h:1903
ValueOffIter endValueOff()
Definition: LeafNode.h:607
OPENVDB_API bool getHalfFloat(std::ios_base &)
Return true if floating-point values should be quantized to 16 bits when writing to the given stream ...
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
ValueType * mData
Definition: LeafNode.h:359
boost::shared_ptr< LeafNode > Ptr
Definition: LeafNode.h:70
void merge(const LeafNode &)
Definition: LeafNode.h:1842
Definition: LeafNode.h:504
LeafNode * probeLeaf(const Coord &)
Return a pointer to this node.
Definition: LeafNode.h:1027
ValueIter(const MaskIterT &iter, NodeT *parent)
Definition: LeafNode.h:517
bool isConstant(ValueType &constValue, bool &state, const ValueType &tolerance=zeroVal< ValueType >()) const
Definition: LeafNode.h:1749
static void doVisit(NodeT &, VisitorOp &)
Definition: LeafNode.h:2084
void stealNodes(ArrayT &, const ValueType &, bool)
This function exists only to enable template instantiation.
Definition: LeafNode.h:1006
void writeTopology(std::ostream &os, bool toHalf=false) const
Write out just the topology.
Definition: LeafNode.h:1539
void setOrigin(const Coord &origin)
Set the grid index coordinates of this node's local origin.
Definition: LeafNode.h:470
void save(std::ostream &os) const
Definition: NodeMasks.h:551
DenseIter(const MaskDenseIterator &iter, NodeT *parent)
Definition: LeafNode.h:559
void setValueOnlyAndCache(const Coord &xyz, const ValueType &val, AccessorT &)
Change the value of the voxel at the given coordinates but preserve its state.
Definition: LeafNode.h:840
void setValuesOff()
Mark all voxels as inactive but don't change their values.
Definition: LeafNode.h:760
void modifyValueAndActiveState(const Coord &xyz, const ModifyOp &op)
Apply a functor to the voxel at the given coordinates.
Definition: LeafNode.h:747
const LeafNode * probeConstLeafAndCache(const Coord &, AccessorT &) const
Return a const pointer to this node.
Definition: LeafNode.h:1035
const Coord & origin() const
Return the grid index coordinates of this node's local origin.
Definition: LeafNode.h:473