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_hxx
19 #define itkCorrespondenceDataStructureIterator_hxx
20 
21 #include "itkCorrespondenceDataStructureIterator.h"
22 
23 namespace itk
24 {
25 /** Constructor.  Initializes iterators, pointers, and m_IsAtEnd. */
26 template< typename TStructureType >
27 CorrespondenceDataStructureIterator< TStructureType >
CorrespondenceDataStructureIterator(TStructureType * StructurePtr)28 ::CorrespondenceDataStructureIterator(TStructureType *StructurePtr)
29 {
30   m_Structure = StructurePtr;
31   m_NodeListPointer = StructurePtr->m_NodeList;
32   m_NodeListIterator = m_NodeListPointer->begin();
33   m_SecondaryListPointer = &( *m_NodeListIterator );
34   m_SecondaryListIterator = m_SecondaryListPointer->begin();
35   m_CorrespondingListPointer = &( *m_SecondaryListIterator );
36   m_CorrespondingListIterator = m_CorrespondingListPointer->begin();
37 
38   m_IsAtEnd = false;
39 }
40 
41 /** Used to verify that the iterator is at the end of the data structure. */
42 template< typename TStructureType >
43 bool
44 CorrespondenceDataStructureIterator< TStructureType >
IsAtEnd() const45 ::IsAtEnd() const
46 {
47   return m_IsAtEnd;
48 }
49 
50 /** Goes to the next corresponding node clique in the structure,
51  *  moving on to the next base node clique if necessary. */
52 template< typename TStructureType >
53 void
54 CorrespondenceDataStructureIterator< TStructureType >
GoToNext()55 ::GoToNext()
56 {
57   m_CorrespondingListIterator++;
58 
59   if ( m_CorrespondingListIterator == m_CorrespondingListPointer->end() )
60     {
61       this->GoToNextBaseGroup();
62     }
63 }
64 
65 /** Goes to the next base node clique. */
66 template< typename TStructureType >
67 void
68 CorrespondenceDataStructureIterator< TStructureType >
GoToNextBaseGroup()69 ::GoToNextBaseGroup()
70 {
71   m_SecondaryListIterator++;
72   if ( m_SecondaryListIterator != m_SecondaryListPointer->end() )
73     {
74     m_CorrespondingListPointer = &( *m_SecondaryListIterator );
75     m_CorrespondingListIterator = m_CorrespondingListPointer->begin();
76     }
77   else if ( m_SecondaryListIterator == m_SecondaryListPointer->end() )
78     {
79     m_NodeListIterator++;
80 
81     if ( m_NodeListIterator != m_NodeListPointer->end() )
82       {
83       m_SecondaryListPointer = &( *m_NodeListIterator );
84       m_SecondaryListIterator = m_SecondaryListPointer->begin();
85 
86       m_CorrespondingListPointer = &( *m_SecondaryListIterator );
87       m_CorrespondingListIterator = m_CorrespondingListPointer->begin();
88       }
89     else if ( m_NodeListIterator == m_NodeListPointer->end() )
90       {
91       m_IsAtEnd = true;
92       }
93     }
94 }
95 
96 /** Resets the iterator to the default settings/placement.*/
97 template< typename TStructureType >
98 void
99 CorrespondenceDataStructureIterator< TStructureType >
Reset()100 ::Reset()
101 {
102   m_IsAtEnd = false;
103 
104   m_NodeListPointer = m_Structure->m_NodeList;
105   m_NodeListIterator = m_NodeListPointer->begin();
106 
107   m_SecondaryListPointer = &( *m_NodeListIterator );
108   m_SecondaryListIterator = m_SecondaryListPointer->begin();
109 
110   m_CorrespondingListPointer = &( *m_SecondaryListIterator );
111   m_CorrespondingListIterator = m_CorrespondingListPointer->begin();
112 }
113 } // end namespace itk
114 
115 #endif
116