Orfeo Toolbox  3.16
itkImageSliceConstIteratorWithIndex.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageSliceConstIteratorWithIndex.txx,v $
5  Language: C++
6  Date: $Date: 2009-08-14 20:48:00 $
7  Version: $Revision: 1.13 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkImageSliceConstIteratorWithIndex_txx
18 #define __itkImageSliceConstIteratorWithIndex_txx
19 
21 
22 namespace itk
23 {
24 
25 //----------------------------------------------------------------------
26 // Advance to Next Line
27 //----------------------------------------------------------------------
28 template<class TImage>
29 void
32 {
33  // Move to next line
34  this->m_PositionIndex[ m_Direction_B ]++;
35  this->m_Position += m_LineJump;
36 
37  // Move to beginning of line
38  this->m_PositionIndex[ m_Direction_A ] = this->m_BeginIndex[ m_Direction_A ];
39  this->m_Position -= m_PixelJump *
40  ( this->m_EndIndex[ m_Direction_A ] - this->m_BeginIndex[ m_Direction_A ] );
41 }
42 
43 //----------------------------------------------------------------------
44 // Advance to Previous Line
45 //----------------------------------------------------------------------
46 template<class TImage>
47 void
50 {
51  // Move to previous line
52  this->m_PositionIndex[ m_Direction_B ]--;
53  this->m_Position -= m_LineJump;
54 
55  // Move to end of line
56  this->m_PositionIndex[ m_Direction_A ] = this->m_EndIndex[ m_Direction_A ]-1;
57  this->m_Position += m_PixelJump *
58  ( this->m_EndIndex[ m_Direction_A ] - this->m_BeginIndex[ m_Direction_A ] );
59 }
60 
61 //----------------------------------------------------------------------
62 // Go to the first pixel of the current slice
63 //----------------------------------------------------------------------
64 template<class TImage>
65 void
68 {
69  // Move to beginning of Slice
70  this->m_PositionIndex[m_Direction_B] = this->m_BeginIndex[m_Direction_B];
71  this->m_Position -= m_LineJump *
72  ( this->m_EndIndex[ m_Direction_B ] - this->m_BeginIndex[ m_Direction_B ] );
73 
74 }
75 
76 
77 //----------------------------------------------------------------------
78 // Advance to next slice
79 //----------------------------------------------------------------------
80 template<class TImage>
81 void
84 {
85 
86  // Move to beginning of Slice
87  this->m_Position -= m_LineJump *
88  ( this->m_PositionIndex[ m_Direction_B ] - this->m_BeginIndex[ m_Direction_B ] );
89  this->m_PositionIndex[m_Direction_B] = this->m_BeginIndex[m_Direction_B];
90 
91  for( unsigned int n=0; n<TImage::ImageDimension; n++ )
92  {
93 
94  this->m_Remaining = false;
95 
96  if( n == m_Direction_B || n == m_Direction_A )
97  {
98  continue;
99  }
100 
101  this->m_PositionIndex[ n ]++;
102  if( this->m_PositionIndex[n] < this->m_EndIndex[n] )
103  {
104  this->m_Position += this->m_OffsetTable[ n ];
105  this->m_Remaining = true;
106  break;
107  }
108  else
109  {
110  this->m_Position -= this->m_OffsetTable[ n+1 ] - this->m_OffsetTable[ n ];
111  this->m_PositionIndex[ n ] = this->m_BeginIndex[ n ];
112  }
113  }
114 }
115 
116 //----------------------------------------------------------------------
117 // Go Back to previous slice
118 //----------------------------------------------------------------------
119 template<class TImage>
120 void
123 {
124 
125  // Move to end of Slice
126  this->m_PositionIndex[m_Direction_B] = this->m_EndIndex[m_Direction_B] - 1;
127  this->m_Position += m_LineJump *
128  ( this->m_EndIndex[ m_Direction_B ] - this->m_BeginIndex[ m_Direction_B ] );
129 
130 
131  for( unsigned int n=0; n<TImage::ImageDimension; n++ )
132  {
133 
134  this->m_Remaining = false;
135 
136  if( n == m_Direction_B || n == m_Direction_A )
137  {
138  continue;
139  }
140 
141  this->m_PositionIndex[ n ]--;
142  if( this->m_PositionIndex[n] >= this->m_BeginIndex[n] )
143  {
144  this->m_Position -= this->m_OffsetTable[ n ];
145  this->m_Remaining = true;
146  break;
147  }
148  else
149  {
150  this->m_Position += this->m_OffsetTable[ n+1 ] - this->m_OffsetTable[ n ];
151  this->m_PositionIndex[ n ] = this->m_EndIndex[ n ] - 1;
152  }
153  }
154 }
155 
156 //----------------------------------------------------------------------
157 // Test for end of line
158 //----------------------------------------------------------------------
159 template<class TImage>
160 bool
163 {
164  return this->m_PositionIndex[m_Direction_A] >= this->m_EndIndex[m_Direction_A];
165 }
166 
167 //----------------------------------------------------------------------
168 // Test for end of slice
169 //----------------------------------------------------------------------
170 template<class TImage>
171 bool
174 {
175  return this->m_PositionIndex[m_Direction_B] >= this->m_EndIndex[m_Direction_B];
176 }
177 
178 //----------------------------------------------------------------------
179 // Test for begin of line
180 //----------------------------------------------------------------------
181 template<class TImage>
182 bool
185 {
186  return this->m_PositionIndex[m_Direction_A] < this->m_BeginIndex[m_Direction_A];
187 }
188 
189 //----------------------------------------------------------------------
190 // Test for begin of slice
191 //----------------------------------------------------------------------
192 template<class TImage>
193 bool
196 {
197  return this->m_PositionIndex[m_Direction_B] < this->m_BeginIndex[m_Direction_B];
198 }
199 
200 //----------------------------------------------------------------------
201 // Select the fastest changing direction
202 //----------------------------------------------------------------------
203 template<class TImage>
204 void
206 ::SetFirstDirection(unsigned int direction)
207 {
208  if( direction >= TImage::ImageDimension )
209  {
210  itkGenericExceptionMacro(<<"In image of dimension " << TImage::ImageDimension <<" Direction " << direction << " sas selected");
211  }
212  m_Direction_A = direction;
213  m_PixelJump = this->m_OffsetTable[ m_Direction_A ];
214 }
215 
216 //----------------------------------------------------------------------
217 // Select the second fastest changing direction
218 //----------------------------------------------------------------------
219 template<class TImage>
220 void
222 ::SetSecondDirection(unsigned int direction)
223 {
224  if( direction >= TImage::ImageDimension )
225  {
226  itkGenericExceptionMacro(<<"In image of dimension " << TImage::ImageDimension <<" Direction " << direction << " sas selected");
227  }
228  m_Direction_B = direction;
229  m_LineJump = this->m_OffsetTable[ m_Direction_B ];
230 }
231 
232 //----------------------------------------------------------------------
233 // Advance along a line
234 //----------------------------------------------------------------------
235 template<class TImage>
239 {
240  this->m_PositionIndex[ m_Direction_A ]++;
241  this->m_Position += m_PixelJump;
242  return *this;
243 }
244 
245 //----------------------------------------------------------------------
246 // Go back along a line
247 //----------------------------------------------------------------------
248 template<class TImage>
252 {
253  this->m_PositionIndex[ m_Direction_A ]--;
254  this->m_Position -= m_PixelJump;
255  return *this;
256 }
257 
258 } // end namespace itk
259 
260 
261 #endif

Generated at Sat Feb 2 2013 23:44:39 for Orfeo Toolbox with doxygen 1.8.1.1