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 itkImageRegionConstIteratorWithIndex_hxx
19 #define itkImageRegionConstIteratorWithIndex_hxx
20 
21 #include "itkImageRegionConstIteratorWithIndex.h"
22 
23 namespace itk
24 {
25 //----------------------------------------------------------------------
26 //  Advance along the line
27 //----------------------------------------------------------------------
28 template< typename TImage >
29 ImageRegionConstIteratorWithIndex< TImage > &
30 ImageRegionConstIteratorWithIndex< TImage >
operator ++()31 ::operator++()
32 {
33   this->m_Remaining = false;
34   for ( unsigned int in = 0; in < TImage::ImageDimension; in++ )
35     {
36     this->m_PositionIndex[in]++;
37     if ( this->m_PositionIndex[in] < this->m_EndIndex[in] )
38       {
39       this->m_Position += this->m_OffsetTable[in];
40       this->m_Remaining = true;
41       break;
42       }
43     else
44       {
45       this->m_Position -= this->m_OffsetTable[in]
46                           * ( static_cast< OffsetValueType >( this->m_Region.GetSize()[in] ) - 1 );
47       this->m_PositionIndex[in] = this->m_BeginIndex[in];
48       }
49     }
50 
51   if ( !this->m_Remaining ) // It will not advance here otherwise
52     {
53     this->m_Position = this->m_End;
54     }
55 
56   return *this;
57 }
58 
59 //----------------------------------------------------------------------
60 //  Advance along the line in reverse direction
61 //----------------------------------------------------------------------
62 template< typename TImage >
63 ImageRegionConstIteratorWithIndex< TImage > &
64 ImageRegionConstIteratorWithIndex< TImage >
operator --()65 ::operator--()
66 {
67   this->m_Remaining = false;
68   for ( unsigned int in = 0; in < TImage::ImageDimension; in++ )
69     {
70     if ( this->m_PositionIndex[in] > this->m_BeginIndex[in] )
71       {
72       this->m_PositionIndex[in]--;
73       this->m_Position -= this->m_OffsetTable[in];
74       this->m_Remaining = true;
75       break;
76       }
77     else
78       {
79       this->m_Position += this->m_OffsetTable[in]
80                           * ( static_cast< OffsetValueType >( this->m_Region.GetSize()[in] ) - 1 );
81       this->m_PositionIndex[in] = this->m_EndIndex[in] - 1;
82       }
83     }
84 
85   if ( !this->m_Remaining ) // It will not advance here otherwise
86     {
87     this->m_Position = this->m_End;
88     }
89 
90   return *this;
91 }
92 } // end namespace itk
93 
94 #endif
95