ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkLevelOrderTreeIterator_h 00019 #define __itkLevelOrderTreeIterator_h 00020 00021 #include <queue> 00022 #include <climits> 00023 #include "itkTreeIteratorBase.h" 00024 00025 namespace itk 00026 { 00033 template< class TTreeType > 00034 class LevelOrderTreeIterator:public TreeIteratorBase< TTreeType > 00035 { 00036 public: 00037 00039 typedef LevelOrderTreeIterator Self; 00040 typedef TreeIteratorBase< TTreeType > Superclass; 00041 typedef TTreeType TreeType; 00042 typedef typename TTreeType::ValueType ValueType; 00043 typedef typename Superclass::TreeNodeType TreeNodeType; 00044 typedef typename Superclass::NodeType NodeType; 00045 00047 LevelOrderTreeIterator(TreeType *tree, int endLevel = INT_MAX, const TreeNodeType *start = NULL); 00048 00050 LevelOrderTreeIterator(TreeType *tree, int startLevel, int endLevel, const TreeNodeType *start = NULL); 00051 00052 virtual ~LevelOrderTreeIterator() {} 00053 00055 NodeType GetType() const; 00056 00058 int GetStartLevel() const; 00059 00061 int GetEndLevel() const; 00062 00064 int GetLevel() const; 00065 00067 TreeIteratorBase< TTreeType > * Clone(); 00068 00070 const Self & operator=(const Self & iterator) 00071 { 00072 this->Superclass::operator=(iterator); 00073 m_StartLevel = iterator.m_StartLevel; 00074 m_EndLevel = iterator.m_EndLevel; 00075 m_Queue = iterator.m_Queue; 00076 return *this; 00077 } 00079 00080 protected: 00081 00083 const ValueType & Next(); 00084 00086 bool HasNext() const; 00087 00088 private: 00089 00090 const TreeNodeType * FindNextNode() const; 00091 00092 const TreeNodeType * FindNextNodeHelp() const; 00093 00094 int GetLevel(const TreeNodeType *node) const; 00095 00096 int m_StartLevel; 00097 int m_EndLevel; 00098 mutable std::queue< const TreeNodeType * > m_Queue; 00099 }; 00100 00101 } // end namespace itk 00102 00103 #ifndef ITK_MANUAL_INSTANTIATION 00104 #include "itkLevelOrderTreeIterator.hxx" 00105 #endif 00106 00107 #endif 00108