ITK  4.13.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< 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 = ITK_NULLPTR);
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 }
73 
75 template< typename TTreeType >
78 {
80 }
81 
83 template< typename TTreeType >
84 bool
86 {
87  if ( const_cast< TreeNodeType * >( FindNextNode() ) != ITK_NULLPTR )
88  {
89  return true;
90  }
91  return false;
92 }
94 
96 template< typename TTreeType >
99 {
100  this->m_Position = const_cast< TreeNodeType * >( FindNextNode() );
101  return this->m_Position->Get();
102 }
104 
106 template< typename TTreeType >
109 {
110  if ( this->m_Position == ITK_NULLPTR )
111  {
112  return ITK_NULLPTR;
113  }
114  if ( this->m_Position == this->m_Root )
115  {
116  return ITK_NULLPTR;
117  }
118  return this->m_Position->GetParent();
119 }
121 
123 template< typename 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
Superclass::NodeType NodeType
Represents a node in a tree.
Definition: itkTreeNode.h:43
TreeIteratorBase< TTreeType > * Clone()
TTreeType::TreeNodeType TreeNodeType
RootTreeIterator(TreeType *tree, const TreeNodeType *start=nullptr)
const ValueType & Next()
Superclass::TreeNodeType TreeNodeType
TTreeType::ValueType ValueType
const TreeNodeType * FindNextNode() const
This class provides the base implementation for tree iterators.
TreeIteratorBase< TTreeType > Superclass
const TreeNodeType * m_Root
NodeType GetType() const