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 itkImageLinearConstIteratorWithIndex_hxx
19 #define itkImageLinearConstIteratorWithIndex_hxx
20 
21 #include "itkImageLinearConstIteratorWithIndex.h"
22 
23 namespace itk
24 {
25 //----------------------------------------------------------------------
26 //  Constructor
27 //----------------------------------------------------------------------
28 template< typename TImage >
29 ImageLinearConstIteratorWithIndex< TImage >
ImageLinearConstIteratorWithIndex(const ImageType * ptr,const RegionType & region)30 ::ImageLinearConstIteratorWithIndex(
31   const ImageType *ptr,
32   const RegionType & region):
33   ImageConstIteratorWithIndex< TImage >(ptr, region)
34 {
35   this->SetDirection(0);
36 }
37 
38 //----------------------------------------------------------------------
39 //  Go to the last pixel of the current line
40 //----------------------------------------------------------------------
41 template< typename TImage >
42 void
43 ImageLinearConstIteratorWithIndex< TImage >
GoToReverseBeginOfLine()44 ::GoToReverseBeginOfLine()
45 {
46   OffsetValueType distanceToEnd =
47     this->m_EndIndex[m_Direction] - this->m_PositionIndex[m_Direction] - 1;
48 
49   this->m_Position += m_Jump * distanceToEnd;
50   this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction] - 1;
51 }
52 
53 //----------------------------------------------------------------------
54 //  Go to the first pixel of the current line
55 //----------------------------------------------------------------------
56 template< typename TImage >
57 void
58 ImageLinearConstIteratorWithIndex< TImage >
GoToBeginOfLine()59 ::GoToBeginOfLine()
60 {
61   OffsetValueType distanceToBegin =
62     this->m_PositionIndex[m_Direction] - this->m_BeginIndex[m_Direction];
63 
64   this->m_Position -= m_Jump * distanceToBegin;
65 
66   this->m_PositionIndex[m_Direction] = this->m_BeginIndex[m_Direction];
67 }
68 
69 //----------------------------------------------------------------------
70 //  Pass to the past last pixel of the current line
71 //----------------------------------------------------------------------
72 template< typename TImage >
73 void
74 ImageLinearConstIteratorWithIndex< TImage >
GoToEndOfLine()75 ::GoToEndOfLine()
76 {
77   OffsetValueType distanceToEnd =
78     this->m_EndIndex[m_Direction] - this->m_PositionIndex[m_Direction];
79 
80   this->m_Position += m_Jump * distanceToEnd;
81 
82   this->m_PositionIndex[m_Direction] = this->m_EndIndex[m_Direction];
83 }
84 } // end namespace itk
85 
86 #endif
87