octree_iterator.h 2.45 KB
Newer Older
Dave Partyka's avatar
Dave Partyka committed
1 2 3 4 5
#ifndef __octree_iterator
#define __octree_iterator

// Included by octree

6
#include <iterator>
Dave Partyka's avatar
Dave Partyka committed
7 8 9 10 11 12 13 14 15 16 17

/**\brief An octree iterator.
  *
  * Unlike most STL container iterators, octree iterators contain some state that most developers will be interested in.
  * Specifically, the iterator may be set to traverse siblings but not children, only leaf nodes, or all nodes in an octree.
  * Also, the bounding box of an octree node is implicit in its position in the hierarchy;
  * since octree nodes themselves do not contain their position relative to their parents it is up to the iterator
  * to provide bounding box information.
  *
  *\bug Const octree iterators don't seem to work -- comparison operators aren't defined properly?
  */
18 19
template< typename T_, typename R_, typename P_, typename O_, typename OP_, int d_ = 3 >
class octree_iterator : public octree_path<T_,R_,P_,O_,OP_,d_>
Dave Partyka's avatar
Dave Partyka committed
20 21
{
public:
22 23 24 25 26
  typedef O_ octree_type;
  typedef OP_ octree_pointer;
  typedef typename O_::allocator_type octree_allocator_type;
  typedef typename O_::octree_node_reference octree_node_reference;
  typedef typename O_::octree_node_pointer octree_node_pointer;
Dave Partyka's avatar
Dave Partyka committed
27

28
  typedef std::bidirectional_iterator_tag iterator_category;
Dave Partyka's avatar
Dave Partyka committed
29

30 31 32
  typedef octree_iterator< T_, T_&, T_*, O_, O_*, d_ > iterator;
  typedef octree_iterator< T_, const T_&, const T_*, O_, const O_*, d_ > const_iterator;
  typedef octree_iterator< T_, R_, P_, O_, OP_, d_ > self_iterator;
Dave Partyka's avatar
Dave Partyka committed
33 34 35 36 37

  bool _M_immediate_family;                 // Iterate over all the subnodes or just the direct children?
  bool _M_only_leaf_nodes;                  // Should the iterator visit all nodes or only leaf nodes?

  octree_iterator();
38
  octree_iterator( octree_node_pointer oroot, octree_node_pointer onode, bool only_leaves = true );
Dave Partyka's avatar
Dave Partyka committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  octree_iterator( const const_iterator& it );

  octree_node_pointer check_incr();
  octree_node_pointer check_decr();
  void immediate_family( bool state );
  bool immediate_family() const { return this->_M_immediate_family; }
  bool& immediate_family() { return this->_M_immediate_family; }

  self_iterator& operator ++ ()      { this->_M_current_node = check_incr(); return *this; }
  self_iterator  operator ++ ( int ) { self_iterator tmp = *this; this->_M_current_node = check_incr(); return tmp; }

  self_iterator& operator -- ()      { this->_M_current_node = check_decr(); return *this; }
  self_iterator  operator -- ( int ) { self_iterator tmp = *this; this->_M_current_node = check_decr(); return tmp; }

};

#endif // __octree_iterator