Orfeo Toolbox  4.0
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< typename 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< typename 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 }
72 
74 template< typename TTreeType >
77 {
79 }
80 
82 template< typename TTreeType >
83 bool
85 {
86  if ( const_cast< TreeNodeType * >( FindNextNode() ) != NULL )
87  {
88  return true;
89  }
90  return false;
91 }
92 
94 template< typename TTreeType >
97 {
98  this->m_Position = const_cast< TreeNodeType * >( FindNextNode() );
99  return this->m_Position->Get();
100 }
101 
103 template< typename TTreeType >
106 {
107  if ( this->m_Position == NULL )
108  {
109  return NULL;
110  }
111  if ( this->m_Position == this->m_Root )
112  {
113  return NULL;
114  }
115  return this->m_Position->GetParent();
116 }
117 
119 template< typename TTreeType >
121 {
122  RootTreeIterator< TTreeType > *clone = new RootTreeIterator< TTreeType >(const_cast< TTreeType * >( this->m_Tree ),
123  this->m_Position);
124  *clone = *this;
125  return clone;
126 }
127 } // end namespace itk
128 
129 #endif

Generated at Sat Mar 8 2014 15:28:30 for Orfeo Toolbox with doxygen 1.8.3.1