ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkRootTreeIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkRootTreeIterator_h
19 #define __itkRootTreeIterator_h
20 
21 #include "itkTreeIteratorBase.h"
22 
23 namespace itk
24 {
25 template< class TTreeType >
26 class RootTreeIterator:public TreeIteratorBase< TTreeType >
27 {
28 public:
29 
32  typedef TTreeType TreeType;
33  typedef typename TTreeType::ValueType ValueType;
35  typedef typename Superclass::NodeType NodeType;
36 
38  RootTreeIterator(TreeType *tree, const TreeNodeType *start = NULL);
39 
41  NodeType GetType() const;
42 
45 
46 protected:
47 
49  const ValueType & Next();
50 
52  bool HasNext() const;
53 
54 private:
55 
57  const TreeNodeType * FindNextNode() const;
58 };
59 
61 template< class TTreeType >
63  TreeIteratorBase< TTreeType >(tree, start)
64 {
65  if ( start )
66  {
67  this->m_Begin = const_cast< TreeNode< ValueType > * >( start );
68  }
69  this->m_Root = tree->GetRoot();
70  this->m_Position = this->m_Begin;
71 }
73 
75 template< class TTreeType >
78 {
80 }
81 
83 template< class TTreeType >
84 bool
86 {
87  if ( const_cast< TreeNodeType * >( FindNextNode() ) != NULL )
88  {
89  return true;
90  }
91  return false;
92 }
94 
96 template< class TTreeType >
99 {
100  this->m_Position = const_cast< TreeNodeType * >( FindNextNode() );
101  return this->m_Position->Get();
102 }
104 
106 template< class TTreeType >
109 {
110  if ( this->m_Position == NULL )
111  {
112  return NULL;
113  }
114  if ( this->m_Position == this->m_Root )
115  {
116  return NULL;
117  }
118  return this->m_Position->GetParent();
119 }
121 
123 template< class TTreeType >
125 {
126  RootTreeIterator< TTreeType > *clone = new RootTreeIterator< TTreeType >(const_cast< TTreeType * >( this->m_Tree ),
127  this->m_Position);
128  *clone = *this;
129  return clone;
130 }
131 } // end namespace itk
133 
134 #endif
135