ON_RTreeIterator Class Reference

#include <opennurbs_rtree.h>

Public Member Functions

 ON_RTreeIterator ()
 Construct an empty iterator. Call Initialize() to attach the iterator to an R-tree. Remark: Any calls to ON_RTree::Insert() or ON_RTree::Remove() that modify an R-tree being iterated invalidate the iterator. The iterator must be re-initialized before being used again. More...
 
 ON_RTreeIterator (const class ON_RTree &a_rtree)
 
 ~ON_RTreeIterator ()
 
bool First ()
 Reset the iterator so the current leaf is the first leaf in the R-tree. The Initialize() functions automatically do this, but First() can be called if an iterator needs to be used more than once or to make code easy to read and understand. More...
 
bool Initialize (const class ON_RTree &a_rtree)
 Initialize an iterator to iterate every leaf in the rtree. More...
 
bool Initialize (const struct ON_RTreeNode *a_node)
 Initialize an iterator to iterate every leaf on or below a_node. More...
 
bool Last ()
 Set the iterator so the current leaf is the last leaf in the R-tree. More...
 
bool Next ()
 Increment the iterator to the next leaf in the R-tree. More...
 
bool Prev ()
 Decrement the iterator to the previous leaf in the R-tree. More...
 
const ON_RTreeBranchValue () const
 Get the value of the current leaf element. Calling Value() does not increment or decrement the iterator. More...
 

Constructor & Destructor Documentation

◆ ON_RTreeIterator() [1/2]

ON_RTreeIterator::ON_RTreeIterator ( )

Construct an empty iterator. Call Initialize() to attach the iterator to an R-tree. Remark: Any calls to ON_RTree::Insert() or ON_RTree::Remove() that modify an R-tree being iterated invalidate the iterator. The iterator must be re-initialized before being used again.

There is no connection between the order elements are inserted in an R-tree and the order the elements are iterated by an iterator.

◆ ON_RTreeIterator() [2/2]

ON_RTreeIterator::ON_RTreeIterator ( const class ON_RTree a_rtree)

◆ ~ON_RTreeIterator()

ON_RTreeIterator::~ON_RTreeIterator ( )

Member Function Documentation

◆ First()

bool ON_RTreeIterator::First ( )

Reset the iterator so the current leaf is the first leaf in the R-tree. The Initialize() functions automatically do this, but First() can be called if an iterator needs to be used more than once or to make code easy to read and understand.

Returns
True if a call to Value() will return a non-null pointer.
Iterate every leaf in an R-tree.
@verbatim
ON_RTree rtree;
...
ON_RtreeIterator rit(rtree);
const ON_RTreeBranch* rtree_leaf;
for ( rit.First(); 0 != (rtree_leaf = rit.Value()); rit.Next() )
{
// leaf id = rtree_leaf->m_id
// leaf bounding box = rtree->m_rect
}
@endverbatim
See also
ON_RTreeIterator::Last();

◆ Initialize() [1/2]

bool ON_RTreeIterator::Initialize ( const class ON_RTree a_rtree)

Initialize an iterator to iterate every leaf in the rtree.

Parameters
a_rtree[in]
Rtree to iterate
Returns
True if a_rtree has at least one element.

Any calls to ON_RTree::Insert() or ON_RTree::Remove() that modify this node or its children will invalidate this iterator and it must be re-initialized.

There is no connection between the order elements are inserted in an R-tree and the order the elements are iterated by an iterator.

See the comment for ON_RTreeIterator::First().

◆ Initialize() [2/2]

bool ON_RTreeIterator::Initialize ( const struct ON_RTreeNode a_node)

Initialize an iterator to iterate every leaf on or below a_node.

Parameters
a_node[in]
Rtree node to iterate
Returns
True if a_node has at least one element.

Any calls to ON_RTree::Insert() or ON_RTree::Remove() that modify this node or its children will invalidate this iterator and it must be re-initialized.

There is no connection between the order elements are inserted in an R-tree and the order the elements are iterated by an iterator.

See the comment for ON_RTreeIterator::First().

◆ Last()

bool ON_RTreeIterator::Last ( )

Set the iterator so the current leaf is the last leaf in the R-tree.

Returns
True if a call to Value() will return a non-null pointer.
Iterate an R-tree in reverse order.
@verbatim
ON_RTree rtree;
...
ON_RTreeIterator rit(rtree);
const ON_RTreeBranch* rtree_leaf;
for ( rit.Last(); 0 != (rtree_leaf = rit.Value()); rit.Prev() )
{
// leaf id = rtree_leaf->m_id
// leaf bounding box = rtree->m_rect
}
@endverbatim
See also
ON_RTreeIterator::First();

◆ Next()

bool ON_RTreeIterator::Next ( )

Increment the iterator to the next leaf in the R-tree.

Returns
True if a call to Value() will return a non-null pointer. False if there is not a next leaf and all susequent calls to Value() will return null.
See the comment for ON_RTreeIterator::First()
See also
ON_RTreeIterator::Prev();

◆ Prev()

bool ON_RTreeIterator::Prev ( )

Decrement the iterator to the previous leaf in the R-tree.

Returns
True if a call to Value() will return a non-null pointer. False if there is not a previous leaf and all susequent calls to Value() will return null.
See the comment for ON_RTreeIterator::Last()
See also
ON_RTreeIterator::Next();

◆ Value()

const ON_RTreeBranch* ON_RTreeIterator::Value ( ) const

Get the value of the current leaf element. Calling Value() does not increment or decrement the iterator.

See the comment for ON_RTreeIterator::First().
Return:
Null pointer if there are no more leaves to iterate
A pointer to the current R-tree leaf. When there are no more leaves,
the returned pointer is null.