18 #ifndef itkPostOrderTreeIterator_h
19 #define itkPostOrderTreeIterator_h
25 template<
typename TTreeType >
64 template<
typename TTreeType >
68 if ( tree->GetRoot() == ITK_NULLPTR )
75 if(root == ITK_NULLPTR)
77 itkGenericExceptionMacro(<<
"Can't downcast root node to TreeNodeType *");
87 template<
typename TTreeType >
95 template<
typename TTreeType >
99 if ( const_cast< TreeNodeType * >( FindNextNode() ) != ITK_NULLPTR )
108 template<
typename TTreeType >
112 this->m_Position =
const_cast< TreeNodeType *
>( FindNextNode() );
113 return this->m_Position->Get();
118 template<
typename TTreeType >
122 if ( this->m_Position == ITK_NULLPTR || this->m_Position == this->m_Root )
129 if ( sister != ITK_NULLPTR )
131 return FindMostRightLeaf(sister);
133 if(this->m_Position->GetParent() == ITK_NULLPTR)
138 if(rval == ITK_NULLPTR)
140 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
146 template<
typename TTreeType >
150 if ( !node->HasParent() )
156 if(parent == ITK_NULLPTR)
158 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
161 int childPosition = parent->ChildPosition(node);
162 int lastChildPosition = parent->CountChildren() - 1;
164 while ( childPosition < lastChildPosition )
166 if(parent->GetChild(childPosition + 1) == ITK_NULLPTR)
173 if ( sister == ITK_NULLPTR)
175 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
184 template<
typename TTreeType >
188 while ( node->HasChildren() )
191 int childCount = node->CountChildren();
197 if(node->GetChild(i) == ITK_NULLPTR)
199 helpNode = ITK_NULLPTR;
203 helpNode =
dynamic_cast<TreeNodeType *
>(node->GetChild(i));
204 if(helpNode == ITK_NULLPTR)
206 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
211 while ( helpNode == ITK_NULLPTR && i < childCount );
213 if ( helpNode == ITK_NULLPTR )
223 template<
typename TTreeType >
TTreeType::TreeNodeType TreeNodeType
const TreeNodeType * FindSister(TreeNodeType *node) const
PostOrderTreeIterator Self
TreeIteratorBase< TTreeType > * Clone()
const TreeNodeType * FindMostRightLeaf(TreeNodeType *node) const
PostOrderTreeIterator(TreeType *tree)
const TreeNodeType * FindNextNode() const
TreeIteratorBase< TTreeType > Superclass
This class provides the base implementation for tree iterators.
Superclass::NodeType NodeType
Superclass::TreeNodeType TreeNodeType
TreeNodeType * m_Position
TTreeType::ValueType ValueType