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 itkImageScanlineConstIterator_hxx
19 #define itkImageScanlineConstIterator_hxx
20 
21 #include "itkImageScanlineConstIterator.h"
22 
23 namespace itk
24 {
25 
26 template< typename TImage >
27 void
28 ImageScanlineConstIterator< TImage >
Increment()29 ::Increment()
30 {
31   // increment to the next scanline
32 
33   // Get the index of the last pixel on the span (row)
34   IndexType ind = this->m_Image->ComputeIndex( static_cast< OffsetValueType >( m_SpanEndOffset -1 ) );
35 
36   const IndexType &startIndex = this->m_Region.GetIndex();
37   const SizeType &size = this->m_Region.GetSize();
38 
39   // Check to see if we are past the last pixel in the region
40   // Note that ++ind[0] moves to the next pixel along the row.
41   ++ind[0];
42   bool done = ( ind[0] == startIndex[0] + static_cast< IndexValueType >( size[0] ) );
43   for ( unsigned int i = 1; done && i < ImageIteratorDimension; ++i )
44     {
45     done = ( ind[i] == startIndex[i] + static_cast< IndexValueType >( size[i] ) - 1 );
46     }
47 
48  // if the iterator is outside the region (but not past region begin) then
49   // we need to wrap around the region
50   unsigned int dim = 0;
51   if ( !done )
52     {
53     while ( ( ( dim + 1 ) < ImageIteratorDimension )
54             && ( ind[dim] > startIndex[dim] +  static_cast< IndexValueType >( size[dim] ) - 1 ) )
55       {
56       ind[dim] = startIndex[dim];
57       ind[++dim]++;
58       }
59     }
60 
61   this->m_Offset = this->m_Image->ComputeOffset(ind);
62   m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( size[0] );
63   m_SpanBeginOffset = this->m_Offset;
64 }
65 
66 } // end namespace itk
67 
68 #endif
69