| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkRootTreeIterator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:47 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkRootTreeIterator_h |
| 18 |
|
#define __itkRootTreeIterator_h |
| 19 |
|
|
| 20 |
|
#include <itkTreeIteratorBase.h> |
| 21 |
|
|
| 22 |
NMS |
namespace itk{ |
| 23 |
|
|
| 24 |
|
template <class TTreeType> |
| 25 |
|
class RootTreeIterator : public TreeIteratorBase<TTreeType> |
| 26 |
|
{ |
| 27 |
|
public: |
| 28 |
|
|
| 29 |
|
/** Typedefs */ |
| 30 |
|
typedef TreeIteratorBase<TTreeType> Superclass; |
| 31 |
TDA |
typedef TTreeType TreeType; |
| 32 |
TDA |
typedef typename TTreeType::ValueType ValueType; |
| 33 |
TDA |
typedef typename Superclass::TreeNodeType TreeNodeType; |
| 34 |
|
|
| 35 |
|
/** Constructor */ |
| 36 |
|
RootTreeIterator( TreeType* tree, const TreeNodeType* start=NULL); |
| 37 |
|
|
| 38 |
|
/** Return the type of the iterator */ |
| 39 |
|
int GetType() const; |
| 40 |
|
|
| 41 |
|
/** Clone function */ |
| 42 |
|
TreeIteratorBase<TTreeType>* Clone(); |
| 43 |
|
|
| 44 |
|
protected: |
| 45 |
|
|
| 46 |
|
/** Return the next node */ |
| 47 |
|
const ValueType& Next(); |
| 48 |
|
|
| 49 |
|
/** Return true if the next node exists */ |
| 50 |
|
bool HasNext() const; |
| 51 |
|
|
| 52 |
|
private: |
| 53 |
|
|
| 54 |
|
/** Find the next node */ |
| 55 |
|
const TreeNodeType* FindNextNode() const; |
| 56 |
|
}; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
/** Constructor */ |
| 60 |
|
template <class TTreeType> |
| 61 |
LEN |
RootTreeIterator<TTreeType>::RootTreeIterator(TTreeType* tree, const TreeNodeType* start) |
| 62 |
IND |
**:TreeIteratorBase<TTreeType>(tree, start) |
| 63 |
|
{ |
| 64 |
|
if(start) |
| 65 |
|
{ |
| 66 |
|
this->m_Begin = const_cast<TreeNode<ValueType>*>(start); |
| 67 |
|
} |
| 68 |
|
this->m_Root = tree->GetRoot(); |
| 69 |
|
this->m_Position = this->m_Begin; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
/** Return the type of the iterator */ |
| 73 |
|
template <class TTreeType> |
| 74 |
|
int |
| 75 |
|
RootTreeIterator<TTreeType>::GetType() const |
| 76 |
|
{ |
| 77 |
|
return TreeIteratorBase<TTreeType>::ROOT; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
/** Return true if the next node exists */ |
| 81 |
|
template <class TTreeType> |
| 82 |
|
bool |
| 83 |
|
RootTreeIterator<TTreeType>::HasNext() const |
| 84 |
|
{ |
| 85 |
|
if ( const_cast<TreeNodeType*>(FindNextNode()) != NULL ) |
| 86 |
|
{ |
| 87 |
|
return true; |
| 88 |
|
} |
| 89 |
|
return false; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
/** Go to the next node */ |
| 93 |
|
template <class TTreeType> |
| 94 |
|
const typename RootTreeIterator<TTreeType>::ValueType& |
| 95 |
|
RootTreeIterator<TTreeType>::Next() |
| 96 |
|
{ |
| 97 |
|
this->m_Position = const_cast<TreeNodeType*>(FindNextNode()); |
| 98 |
|
return this->m_Position->Get(); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
/** Find the next node */ |
| 102 |
|
template <class TTreeType> |
| 103 |
|
const typename RootTreeIterator<TTreeType>::TreeNodeType* |
| 104 |
|
RootTreeIterator<TTreeType>::FindNextNode() const |
| 105 |
|
{ |
| 106 |
|
if ( this->m_Position == NULL ) |
| 107 |
|
{ |
| 108 |
|
return NULL; |
| 109 |
|
} |
| 110 |
|
if ( this->m_Position == this->m_Root ) |
| 111 |
|
{ |
| 112 |
|
return NULL; |
| 113 |
|
} |
| 114 |
|
return this->m_Position->GetParent(); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
/** Clone function */ |
| 118 |
|
template <class TTreeType> |
| 119 |
|
TreeIteratorBase<TTreeType>* RootTreeIterator<TTreeType>::Clone() |
| 120 |
|
{ |
| 121 |
LEN |
RootTreeIterator<TTreeType>* clone = new RootTreeIterator<TTreeType>( const_cast<TTreeType*>(this->m_Tree), this->m_Position ); |
| 122 |
|
*clone = *this; |
| 123 |
|
return clone; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
} // end namespace itk |
| 127 |
|
|
| 128 |
|
#endif |
| 129 |
|
|