35 #ifndef OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED
36 #define OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED
39 #include <boost/static_assert.hpp>
40 #include <boost/type_traits/is_const.hpp>
41 #include <boost/type_traits/remove_const.hpp>
42 #include <openvdb/util/NodeMasks.h>
43 #include <openvdb/Exceptions.h>
57 template<
typename MaskIterT,
typename NodeT>
63 mParentNode(parent), mMaskIter(iter) {}
67 mParentNode = other.mParentNode;
68 mMaskIter = other.mMaskIter;
73 return (mParentNode == other.mParentNode) && (mMaskIter == other.mMaskIter);
77 return !(*
this == other);
94 Index pos()
const {
return mMaskIter.offset(); }
97 bool test()
const {
return mMaskIter.test(); }
99 operator bool()
const {
return this->test(); }
102 bool next() {
return mMaskIter.next(); }
112 bool isValueOn()
const {
return parent().isValueMaskOn(this->pos()); }
115 void setValueOn(
bool on =
true)
const { parent().setValueMask(this->pos(), on); }
120 void setValueOff()
const { parent().mValueMask.setOff(this->pos()); }
123 Coord
getCoord()
const {
return parent().offsetToGlobalCoord(this->pos()); }
134 mutable NodeT* mParentNode;
154 static const bool IsSparseIterator =
true, IsDenseIterator =
false;
162 ItemT& getItem(
Index)
const;
165 void setItem(
Index,
const ItemT&)
const;
175 return static_cast<const IterT*
>(
this)->getItem(this->pos());
181 BOOST_STATIC_ASSERT(!boost::is_const<NodeT>::value);
182 static_cast<const IterT*
>(
this)->setItem(this->pos(), value);
189 template<
typename ModifyOp>
192 BOOST_STATIC_ASSERT(!boost::is_const<NodeT>::value);
193 static_cast<const IterT*
>(
this)->modifyItem(this->pos(), op);
219 static const bool IsSparseIterator =
false, IsDenseIterator =
true;
229 bool getItem(
Index, SetItemT*& child, NonConstValueType& value)
const;
232 void setItem(
Index, SetItemT*)
const;
235 void unsetItem(
Index,
const UnsetItemT&)
const;
238 bool isChildNode()
const {
return this->parent().isChildMaskOn(this->pos()); }
244 SetItemT* child = NULL;
245 static_cast<const IterT*
>(
this)->getItem(this->pos(), child, value);
253 child = probeChild(value);
254 return (child != NULL);
261 SetItemT* child = NULL;
262 const bool isChild =
static_cast<const IterT*
>(
this)->
263 getItem(this->pos(), child, value);
271 static_cast<const IterT*
>(
this)->setItem(this->pos(), child);
278 static_cast<const IterT*
>(
this)->unsetItem(this->pos(), value);
286 #endif // OPENVDB_TREE_ITERATOR_HAS_BEEN_INCLUDED
NodeT * getParentNode() const
Return a pointer to the node (if any) over which this iterator is iterating.
Definition: Iterator.h:81
bool operator==(const IteratorBase &other) const
Definition: Iterator.h:71
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:269
Coord getCoord() const
Return the coordinates of the item to which this iterator is pointing.
Definition: Iterator.h:123
Index offset() const
Return this iterator's position as an index into the parent node's table.
Definition: Iterator.h:91
bool test() const
Return true if this iterator is not yet exhausted.
Definition: Iterator.h:97
boost::remove_const< UnsetItemT >::type NonConstValueType
Definition: Iterator.h:217
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Definition: Exceptions.h:88
ItemT & getValue() const
Return the item to which this iterator is pointing.
Definition: Iterator.h:173
IteratorBase()
Definition: Iterator.h:61
boost::remove_const< NodeT >::type NonConstNodeType
Definition: Iterator.h:216
Index32 Index
Definition: Types.h:56
IteratorBase & operator++()
Advance to the next item in the parent node's table.
Definition: Iterator.h:106
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:115
SetItemT ChildNodeType
Definition: Iterator.h:215
bool next()
Advance to the next item in the parent node's table.
Definition: Iterator.h:102
Base class for sparse iterators over internal and leaf nodes.
Definition: Iterator.h:148
bool operator!=(const IteratorBase &other) const
Definition: Iterator.h:75
ItemT * operator->() const
Return a pointer to the item to which this iterator is pointing.
Definition: Iterator.h:170
NodeT & parent() const
Return a reference to the node over which this iterator is iterating.
Definition: Iterator.h:84
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:276
DenseIteratorBase()
Definition: Iterator.h:221
boost::remove_const< NodeT >::type NonConstNodeType
Definition: Iterator.h:152
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:190
NodeT NodeType
Definition: Iterator.h:213
SparseIteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:157
boost::remove_const< SetItemT >::type NonConstChildNodeType
Definition: Iterator.h:218
void setValueOff() const
If this iterator is pointing to a value, mark the value as inactive.
Definition: Iterator.h:120
#define OPENVDB_VERSION_NAME
Definition: version.h:45
bool isChildNode() const
Return true if this iterator is pointing to a child node.
Definition: Iterator.h:238
Base class for iterators over internal and leaf nodes.
Definition: Iterator.h:58
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:112
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:179
NodeT NodeType
Definition: Iterator.h:150
Base class for dense iterators over internal and leaf nodes.
Definition: Iterator.h:211
void increment(Index n)
Advance n items in the parent node's table.
Definition: Iterator.h:108
DenseIteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:222
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:251
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
void operator=(const IteratorBase &other)
Definition: Iterator.h:65
SetItemT * probeChild(NonConstValueType &value) const
If this iterator is pointing to a child node, return a pointer to the node. Otherwise, return NULL and, in value, the value to which this iterator is pointing.
Definition: Iterator.h:242
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:259
ItemT ValueType
Definition: Iterator.h:151
UnsetItemT ValueType
Definition: Iterator.h:214
ItemT & operator*() const
Return a reference to the item to which this iterator is pointing.
Definition: Iterator.h:168
SparseIteratorBase()
Definition: Iterator.h:156
Index pos() const
Identical to offset.
Definition: Iterator.h:94
boost::remove_const< ItemT >::type NonConstValueType
Definition: Iterator.h:153
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
void increment()
Advance to the next item in the parent node's table.
Definition: Iterator.h:104
IteratorBase(const MaskIterT &iter, NodeT *parent)
Definition: Iterator.h:62
void getCoord(Coord &xyz) const
Return in xyz the coordinates of the item to which this iterator is pointing.
Definition: Iterator.h:125