18 #ifndef itkPostOrderTreeIterator_h
19 #define itkPostOrderTreeIterator_h
25 template <
typename TTreeType>
69 template <
typename TTreeType>
73 if (tree->GetRoot() ==
nullptr)
79 const auto * root = dynamic_cast<const TreeNodeType *>(tree->GetRoot());
82 itkGenericExceptionMacro(<<
"Can't downcast root node to TreeNodeType *");
84 this->
m_Position = const_cast<TreeNodeType *>(root);
92 template <
typename TTreeType>
100 template <
typename TTreeType>
104 if (const_cast<TreeNodeType *>(FindNextNode()) !=
nullptr)
113 template <
typename TTreeType>
117 this->m_Position = const_cast<TreeNodeType *>(FindNextNode());
118 return this->m_Position->Get();
123 template <
typename TTreeType>
127 if (this->m_Position ==
nullptr || this->m_Position == this->m_Root)
131 auto * sister = const_cast<TreeNodeType *>(FindSister(this->m_Position));
134 if (sister !=
nullptr)
136 return FindMostRightLeaf(sister);
138 if (this->m_Position->GetParent() ==
nullptr)
142 auto * rval = dynamic_cast<TreeNodeType *>(this->m_Position->GetParent());
145 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
151 template <
typename TTreeType>
155 if (!node->HasParent())
160 auto * parent = dynamic_cast<TreeNodeType *>(node->GetParent());
161 if (parent ==
nullptr)
163 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
166 int childPosition = parent->ChildPosition(node);
167 int lastChildPosition = parent->CountChildren() - 1;
169 while (childPosition < lastChildPosition)
171 if (parent->GetChild(childPosition + 1) ==
nullptr)
177 auto * sister = dynamic_cast<TreeNodeType *>(parent->GetChild(childPosition + 1));
178 if (sister ==
nullptr)
180 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
189 template <
typename TTreeType>
193 while (node->HasChildren())
196 int childCount = node->CountChildren();
202 if (node->GetChild(i) ==
nullptr)
208 helpNode = dynamic_cast<TreeNodeType *>(node->GetChild(i));
209 if (helpNode ==
nullptr)
211 itkGenericExceptionMacro(<<
"Can't downcast to TreeNodeType *");
215 }
while (helpNode ==
nullptr && i < childCount);
217 if (helpNode ==
nullptr)
227 template <
typename TTreeType>