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 itkCorrespondenceDataStructureIterator_h
19 #define itkCorrespondenceDataStructureIterator_h
20 
21 #include "itkMacro.h"
22 
23 namespace itk
24 {
25 /** \class CorrespondenceDataStructureIterator
26  * \brief An iterator designed to easily traverse an
27  *        CorrespondenceDataStructure.
28  *
29  * \ingroup ITKCommon
30  */
31 template< typename TStructureType >
32 class ITK_TEMPLATE_EXPORT CorrespondenceDataStructureIterator
33 {
34 public:
35   /** Standard class type aliases. */
36   using Self = CorrespondenceDataStructureIterator;
37 
38   /** Get the dimension (size) of the index. */
GetIteratorDimension()39   static unsigned int GetIteratorDimension()
40   {
41     return TStructureType::dim;
42   }
43 
44   /** Is the iterator at the end of the region? */
45   bool IsAtEnd() const;
46 
47   /** Walk forward one index. (prefix) */
48   void operator++(){ GoToNext(); }
49 
50   /** Walk forward one index. (postfix) */
51   void operator++(int){ GoToNext(); }
52 
53   /** Goes to the next corresponding node clique in the structure,
54    *  moving on to the next base node clique if necessary. */
55   void GoToNext();
56 
57   /** Goes to the next base node clique. */
58   void GoToNextBaseGroup();
59 
60   /** Resets the iterator. */
61   void Reset();
62 
63   /** Constructor */
64   CorrespondenceDataStructureIterator(TStructureType *StructurePtr);
65 
66   /** Destructor */
67   virtual ~CorrespondenceDataStructureIterator() = default;
68 
69   using CorrespondingListType = typename TStructureType::CorrespondingListType;
70   using ItemType = typename TStructureType::ItemType;
71   using SecondaryNodeListType = typename TStructureType::SecondaryNodeListType;
72   using NodeListType = typename TStructureType::NodeListType;
73 
74   using CorrespondingListIterator = typename CorrespondingListType::iterator;
75   using SecondaryNodeListIterator = typename SecondaryNodeListType::iterator;
76   using NodeListIterator = typename NodeListType::iterator;
77 
78   /** Get m_CorrespondingListPointer.  */
GetCorrespondingListPointer()79   CorrespondingListType * GetCorrespondingListPointer()
80   {
81     return m_CorrespondingListPointer;
82   }
83 
84   CorrespondingListIterator m_CorrespondingListIterator;
85   SecondaryNodeListIterator m_SecondaryListIterator;
86 
87   typename TStructureType::NodeListType::iterator m_NodeListIterator;
88 
89 protected:
90 
91   /** Is the iterator at the end of its walk? */
92   bool                   m_IsAtEnd;
93   TStructureType *       m_Structure;
94   ItemType *             m_CorrespondingNodePointer;
95   CorrespondingListType *m_CorrespondingListPointer;
96   SecondaryNodeListType *m_SecondaryListPointer;
97   NodeListType *         m_NodeListPointer;
98 };
99 } // end namespace itk
100 
101 #ifndef ITK_MANUAL_INSTANTIATION
102 #include "itkCorrespondenceDataStructureIterator.hxx"
103 #endif
104 
105 #endif
106