Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkRootTreeIterator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkRootTreeIterator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-03-03 15:09:06 $
00007   Version:   $Revision: 1.3 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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 }
00072 
00074 template <class TTreeType>
00075 int 
00076 RootTreeIterator<TTreeType>::GetType() const 
00077 {
00078   return TreeIteratorBase<TTreeType>::ROOT;
00079 }
00080 
00082 template <class TTreeType>
00083 bool 
00084 RootTreeIterator<TTreeType>::HasNext() const
00085 {
00086   if ( const_cast<TreeNodeType*>(FindNextNode()) != NULL )
00087     {
00088     return true;
00089     }
00090   return false;
00091 }
00093 
00095 template <class TTreeType>
00096 const typename RootTreeIterator<TTreeType>::ValueType& 
00097 RootTreeIterator<TTreeType>::Next() 
00098 {
00099   this->m_Position = const_cast<TreeNodeType*>(FindNextNode());
00100   return this->m_Position->Get();
00101 }
00103 
00105 template <class TTreeType>
00106 const typename RootTreeIterator<TTreeType>::TreeNodeType* 
00107 RootTreeIterator<TTreeType>::FindNextNode() const
00108 {  
00109   if ( this->m_Position == NULL )
00110     {
00111     return NULL;
00112     }
00113   if ( this->m_Position == this->m_Root )
00114     {
00115     return NULL;
00116     }
00117   return this->m_Position->GetParent();
00118 }
00120 
00122 template <class TTreeType>
00123 TreeIteratorBase<TTreeType>* RootTreeIterator<TTreeType>::Clone() 
00124 {
00125   RootTreeIterator<TTreeType>* clone = new RootTreeIterator<TTreeType>( const_cast<TTreeType*>(this->m_Tree), this->m_Position );
00126   *clone = *this;  
00127   return clone;
00128 }
00130 
00131 } // end namespace itk
00132 
00133 #endif
00134 

Generated at Mon Jul 12 2010 19:41:27 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000