35 #ifndef OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED 36 #define OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED 39 #include <type_traits> 40 #include <openvdb/util/NodeMasks.h> 41 #include <openvdb/Exceptions.h> 55 template<
typename MaskIterT,
typename NodeT>
60 IteratorBase(
const MaskIterT& iter, NodeT* parent): mParentNode(parent), mMaskIter(iter) {}
66 return (mParentNode == other.mParentNode) && (mMaskIter == other.mMaskIter);
70 return !(*
this == other);
87 Index pos()
const {
return mMaskIter.offset(); }
90 bool test()
const {
return mMaskIter.test(); }
92 operator bool()
const {
return this->test(); }
95 bool next() {
return mMaskIter.next(); }
105 bool isValueOn()
const {
return parent().isValueMaskOn(this->pos()); }
108 void setValueOn(
bool on =
true)
const { parent().setValueMask(this->pos(), on); }
113 void setValueOff()
const { parent().mValueMask.setOff(this->pos()); }
116 Coord getCoord()
const {
return parent().offsetToGlobalCoord(this->pos()); }
127 mutable NodeT* mParentNode;
147 static const bool IsSparseIterator =
true, IsDenseIterator =
false;
155 ItemT& getItem(
Index)
const;
158 void setItem(
Index,
const ItemT&)
const;
168 return static_cast<const IterT*
>(
this)->getItem(this->pos());
174 static_assert(!std::is_const<NodeT>::value,
"setValue() not allowed for const iterators");
175 static_cast<const IterT*
>(
this)->setItem(this->pos(), value);
182 template<
typename ModifyOp>
185 static_assert(!std::is_const<NodeT>::value,
186 "modifyValue() not allowed for const iterators");
187 static_cast<const IterT*
>(
this)->modifyItem(this->pos(), op);
213 static const bool IsSparseIterator =
false, IsDenseIterator =
true;
226 void setItem(
Index, SetItemT*)
const;
229 void unsetItem(
Index,
const UnsetItemT&)
const;
232 bool isChildNode()
const {
return this->parent().isChildMaskOn(this->pos()); }
238 SetItemT* child =
nullptr;
239 static_cast<const IterT*
>(
this)->getItem(this->pos(), child, value);
247 child = probeChild(value);
248 return (child !=
nullptr);
255 SetItemT* child =
nullptr;
256 const bool isChild =
static_cast<const IterT*
>(
this)->
257 getItem(this->pos(), child, value);
265 static_cast<const IterT*
>(
this)->setItem(this->pos(), child);
272 static_cast<const IterT*
>(
this)->unsetItem(this->pos(), value);
280 #endif // OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED bool isValueOn() const
Return true if this iterator is pointing to an active value. Return false if it is pointing to either...
Definition: Iterator.h:105
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:205
NodeT NodeType
Definition: Iterator.h:207
typename std::remove_const< ValueT >::type NonConstValueType
Definition: Iterator.h:146
ItemT & getValue() const
Return the item to which this iterator is pointing.
Definition: Iterator.h:166
DenseIteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:216
ValueT ValueType
Definition: Iterator.h:144
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
bool isChildNode() const
Return true if this iterator is pointing to a child node.
Definition: Iterator.h:232
bool next()
Advance to the next item in the parent node's table.
Definition: Iterator.h:95
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
typename std::remove_const< ChildT >::type NonConstChildNodeType
Definition: Iterator.h:212
void increment(Index n)
Advance n items in the parent node's table.
Definition: Iterator.h:101
NodeT * getParentNode() const
Return a pointer to the node (if any) over which this iterator is iterating.
Definition: Iterator.h:74
NodeT & parent() const
Return a reference to the node over which this iterator is iterating.
Definition: Iterator.h:77
SparseIteratorBase()
Definition: Iterator.h:149
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:141
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:56
void setValueOff() const
If this iterator is pointing to a value, mark the value as inactive.
Definition: Iterator.h:113
DenseIteratorBase()
Definition: Iterator.h:215
SetItemT * probeChild(NonConstValueType &value) const
If this iterator is pointing to a child node, return a pointer to the node. Otherwise, return nullptr and, in value, the value to which this iterator is pointing.
Definition: Iterator.h:236
typename std::remove_const< NodeT >::type NonConstNodeType
Definition: Iterator.h:210
void setValue(const UnsetItemT &value) const
Replace with the given value the item in the parent node's table to which this iterator is pointing...
Definition: Iterator.h:270
void increment()
Advance to the next item in the parent node's table.
Definition: Iterator.h:97
void getCoord(Coord &xyz) const
Return in xyz the coordinates of the item to which this iterator is pointing.
Definition: Iterator.h:118
IteratorBase & operator++()
Advance to the next item in the parent node's table.
Definition: Iterator.h:99
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
void setValue(const ItemT &value) const
Set the value of the item to which this iterator is pointing. (Not valid for const iterators...
Definition: Iterator.h:172
IteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:60
Definition: Exceptions.h:92
ChildT ChildNodeType
Definition: Iterator.h:209
Definition: Exceptions.h:40
bool operator!=(const IteratorBase &other) const
Definition: Iterator.h:68
Index32 Index
Definition: Types.h:61
ItemT * operator->() const
Return a pointer to the item to which this iterator is pointing.
Definition: Iterator.h:163
void modifyValue(const ModifyOp &op) const
Apply a functor to the item to which this iterator is pointing. (Not valid for const iterators...
Definition: Iterator.h:183
Index pos() const
Identical to offset.
Definition: Iterator.h:87
Index offset() const
Return this iterator's position as an index into the parent node's table.
Definition: Iterator.h:84
ValueT ValueType
Definition: Iterator.h:208
bool probeChild(SetItemT *&child, NonConstValueType &value) const
If this iterator is pointing to a child node, return true and return a pointer to the child node in c...
Definition: Iterator.h:245
void setChild(SetItemT *child) const
Replace with the given child node the item in the parent node's table to which this iterator is point...
Definition: Iterator.h:263
typename std::remove_const< ValueT >::type NonConstValueType
Definition: Iterator.h:211
bool probeValue(NonConstValueType &value) const
Return true if this iterator is pointing to a value and return the value in value. Otherwise, return false.
Definition: Iterator.h:253
ItemT & operator*() const
Return a reference to the item to which this iterator is pointing.
Definition: Iterator.h:161
IteratorBase()
Definition: Iterator.h:59
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:645
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
SparseIteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:150
NodeT NodeType
Definition: Iterator.h:143
bool test() const
Return true if this iterator is not yet exhausted.
Definition: Iterator.h:90
void setValueOn(bool on=true) const
If this iterator is pointing to a value, set the value's active state. Otherwise, do nothing...
Definition: Iterator.h:108
bool operator==(const IteratorBase &other) const
Definition: Iterator.h:64
Coord getCoord() const
Return the coordinates of the item to which this iterator is pointing.
Definition: Iterator.h:116
typename std::remove_const< NodeT >::type NonConstNodeType
Definition: Iterator.h:145