00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkRootTreeIterator_h
00018 #define __itkRootTreeIterator_h
00019
00020 #include <itkTreeIteratorBase.h>
00021
00022 namespace itk{
00023
00024 template <class TTreeType>
00025 class RootTreeIterator : public TreeIteratorBase<TTreeType>
00026 {
00027 public:
00028
00030 typedef TreeIteratorBase<TTreeType> Superclass;
00031 typedef TTreeType TreeType;
00032 typedef typename TTreeType::ValueType ValueType;
00033 typedef typename Superclass::TreeNodeType TreeNodeType;
00034
00036 RootTreeIterator( TreeType* tree, const TreeNodeType* start=NULL);
00037
00039 int GetType() const;
00040
00042 TreeIteratorBase<TTreeType>* Clone();
00043
00044 protected:
00045
00047 const ValueType& Next();
00048
00050 bool HasNext() const;
00051
00052 private:
00053
00055 const TreeNodeType* FindNextNode() const;
00056 };
00057
00058
00060 template <class TTreeType>
00061 RootTreeIterator<TTreeType>::RootTreeIterator(TTreeType* tree, const TreeNodeType* start)
00062 :TreeIteratorBase<TTreeType>(tree, start)
00063 {
00064 if(start)
00065 {
00066 this->m_Begin = const_cast<TreeNode<ValueType>*>(start);
00067 }
00068 this->m_Root = tree->GetRoot();
00069 this->m_Position = this->m_Begin;
00070 }
00071
00073 template <class TTreeType>
00074 int
00075 RootTreeIterator<TTreeType>::GetType() const
00076 {
00077 return TreeIteratorBase<TTreeType>::ROOT;
00078 }
00079
00081 template <class TTreeType>
00082 bool
00083 RootTreeIterator<TTreeType>::HasNext() const
00084 {
00085 if ( const_cast<TreeNodeType*>(FindNextNode()) != NULL )
00086 {
00087 return true;
00088 }
00089 return false;
00090 }
00091
00093 template <class TTreeType>
00094 const typename RootTreeIterator<TTreeType>::ValueType&
00095 RootTreeIterator<TTreeType>::Next()
00096 {
00097 this->m_Position = const_cast<TreeNodeType*>(FindNextNode());
00098 return this->m_Position->Get();
00099 }
00100
00102 template <class TTreeType>
00103 const typename RootTreeIterator<TTreeType>::TreeNodeType*
00104 RootTreeIterator<TTreeType>::FindNextNode() const
00105 {
00106 if ( this->m_Position == NULL )
00107 {
00108 return NULL;
00109 }
00110 if ( this->m_Position == this->m_Root )
00111 {
00112 return NULL;
00113 }
00114 return this->m_Position->GetParent();
00115 }
00116
00118 template <class TTreeType>
00119 TreeIteratorBase<TTreeType>* RootTreeIterator<TTreeType>::Clone()
00120 {
00121 RootTreeIterator<TTreeType>* clone = new RootTreeIterator<TTreeType>( const_cast<TTreeType*>(this->m_Tree), this->m_Position );
00122 *clone = *this;
00123 return clone;
00124 }
00125
00126 }
00127
00128 #endif