| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkImageSliceConstIteratorWithIndex.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 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 |
DEF |
#ifndef _itkImageSliceConstIteratorWithIndex_txx |
| 18 |
DEF |
#define _itkImageSliceConstIteratorWithIndex_txx |
| 19 |
|
#include "itkImageSliceConstIteratorWithIndex.h" |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
//---------------------------------------------------------------------- |
| 26 |
|
// Advance to Next Line |
| 27 |
|
//---------------------------------------------------------------------- |
| 28 |
|
template<class TImage> |
| 29 |
|
void |
| 30 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 31 |
|
::NextLine(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 |
LEN |
this->m_PositionIndex[ m_Direction_A ] = this->m_BeginIndex[ m_Direction_A ]; |
| 39 |
|
this->m_Position -= m_PixelJump * |
| 40 |
LEN,IND |
****( this->m_EndIndex[ m_Direction_A ] - this->m_BeginIndex[ m_Direction_A ] ); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
|
| 44 |
EML |
|
| 45 |
EML |
|
| 46 |
|
//---------------------------------------------------------------------- |
| 47 |
|
// Advance to Previous Line |
| 48 |
|
//---------------------------------------------------------------------- |
| 49 |
|
template<class TImage> |
| 50 |
|
void |
| 51 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 52 |
|
::PreviousLine(void) |
| 53 |
|
{ |
| 54 |
|
// Move to previous line |
| 55 |
|
this->m_PositionIndex[ m_Direction_B ]--; |
| 56 |
|
this->m_Position -= m_LineJump; |
| 57 |
|
|
| 58 |
|
// Move to end of line |
| 59 |
LEN |
this->m_PositionIndex[ m_Direction_A ] = this->m_EndIndex[ m_Direction_A ]-1; |
| 60 |
|
this->m_Position += m_PixelJump * |
| 61 |
LEN,IND |
****( this->m_EndIndex[ m_Direction_A ] - this->m_BeginIndex[ m_Direction_A ] ); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
EML |
|
| 66 |
EML |
|
| 67 |
EML |
|
| 68 |
EML |
|
| 69 |
|
//---------------------------------------------------------------------- |
| 70 |
|
// Advance to next slice |
| 71 |
|
//---------------------------------------------------------------------- |
| 72 |
|
template<class TImage> |
| 73 |
|
void |
| 74 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 75 |
|
::NextSlice(void) |
| 76 |
|
{ |
| 77 |
|
|
| 78 |
|
// Move to beginning of Slice |
| 79 |
|
this->m_PositionIndex[m_Direction_B] = this->m_BeginIndex[m_Direction_B]; |
| 80 |
|
this->m_Position -= m_LineJump * |
| 81 |
LEN,IND |
****( this->m_EndIndex[ m_Direction_B ] - this->m_BeginIndex[ m_Direction_B ] ); |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
for( unsigned int n=0; n<TImage::ImageDimension; n++ ) |
| 85 |
|
{ |
| 86 |
|
|
| 87 |
|
this->m_Remaining = false; |
| 88 |
|
|
| 89 |
|
if( n == m_Direction_B || n == m_Direction_A ) |
| 90 |
|
{ |
| 91 |
|
continue; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
this->m_PositionIndex[ n ]++; |
| 95 |
|
if( this->m_PositionIndex[n] < this->m_EndIndex[n] ) |
| 96 |
|
{ |
| 97 |
|
this->m_Position += this->m_OffsetTable[ n ]; |
| 98 |
|
this->m_Remaining = true; |
| 99 |
|
break; |
| 100 |
|
} |
| 101 |
|
else |
| 102 |
|
{ |
| 103 |
|
this->m_Position -= this->m_OffsetTable[ n+1 ] - this->m_OffsetTable[ n ]; |
| 104 |
|
this->m_PositionIndex[ n ] = this->m_BeginIndex[ n ]; |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
EML |
|
| 111 |
EML |
|
| 112 |
|
//---------------------------------------------------------------------- |
| 113 |
|
// Go Back to previous slice |
| 114 |
|
//---------------------------------------------------------------------- |
| 115 |
|
template<class TImage> |
| 116 |
|
void |
| 117 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 118 |
|
::PreviousSlice(void) |
| 119 |
|
{ |
| 120 |
|
|
| 121 |
|
// Move to end of Slice |
| 122 |
|
this->m_PositionIndex[m_Direction_B] = this->m_EndIndex[m_Direction_B] - 1; |
| 123 |
|
this->m_Position += m_LineJump * |
| 124 |
LEN,IND |
****( this->m_EndIndex[ m_Direction_B ] - this->m_BeginIndex[ m_Direction_B ] ); |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
for( unsigned int n=0; n<TImage::ImageDimension; n++ ) |
| 128 |
|
{ |
| 129 |
|
|
| 130 |
|
this->m_Remaining = false; |
| 131 |
|
|
| 132 |
|
if( n == m_Direction_B || n == m_Direction_A ) |
| 133 |
|
{ |
| 134 |
|
continue; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
this->m_PositionIndex[ n ]--; |
| 138 |
|
if( this->m_PositionIndex[n] >= this->m_BeginIndex[n] ) |
| 139 |
|
{ |
| 140 |
|
this->m_Position -= this->m_OffsetTable[ n ]; |
| 141 |
|
this->m_Remaining = true; |
| 142 |
|
break; |
| 143 |
|
} |
| 144 |
|
else |
| 145 |
|
{ |
| 146 |
|
this->m_Position += this->m_OffsetTable[ n+1 ] - this->m_OffsetTable[ n ]; |
| 147 |
|
this->m_PositionIndex[ n ] = this->m_EndIndex[ n ] - 1; |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
EML |
|
| 154 |
EML |
|
| 155 |
EML |
|
| 156 |
|
//---------------------------------------------------------------------- |
| 157 |
|
// Test for end of line |
| 158 |
|
//---------------------------------------------------------------------- |
| 159 |
|
template<class TImage> |
| 160 |
|
bool |
| 161 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 162 |
|
::IsAtEndOfLine(void) |
| 163 |
|
{ |
| 164 |
LEN |
return this->m_PositionIndex[m_Direction_A] >= this->m_EndIndex[m_Direction_A]; |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
EML |
|
| 169 |
EML |
|
| 170 |
|
//---------------------------------------------------------------------- |
| 171 |
|
// Test for end of slice |
| 172 |
|
//---------------------------------------------------------------------- |
| 173 |
|
template<class TImage> |
| 174 |
|
bool |
| 175 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 176 |
|
::IsAtEndOfSlice(void) |
| 177 |
|
{ |
| 178 |
LEN |
return this->m_PositionIndex[m_Direction_B] >= this->m_EndIndex[m_Direction_B]; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
EML |
|
| 183 |
EML |
|
| 184 |
|
//---------------------------------------------------------------------- |
| 185 |
|
// Test for begin of line |
| 186 |
|
//---------------------------------------------------------------------- |
| 187 |
|
template<class TImage> |
| 188 |
|
bool |
| 189 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 190 |
|
::IsAtReverseEndOfLine(void) |
| 191 |
|
{ |
| 192 |
LEN |
return this->m_PositionIndex[m_Direction_A] < this->m_BeginIndex[m_Direction_A]; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
|
| 196 |
EML |
|
| 197 |
EML |
|
| 198 |
|
//---------------------------------------------------------------------- |
| 199 |
|
// Test for begin of slice |
| 200 |
|
//---------------------------------------------------------------------- |
| 201 |
|
template<class TImage> |
| 202 |
|
bool |
| 203 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 204 |
|
::IsAtReverseEndOfSlice(void) |
| 205 |
|
{ |
| 206 |
LEN |
return this->m_PositionIndex[m_Direction_B] < this->m_BeginIndex[m_Direction_B]; |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
|
| 210 |
EML |
|
| 211 |
EML |
|
| 212 |
EML |
|
| 213 |
EML |
|
| 214 |
|
//---------------------------------------------------------------------- |
| 215 |
|
// Select the fastest changing direction |
| 216 |
|
//---------------------------------------------------------------------- |
| 217 |
|
template<class TImage> |
| 218 |
|
void |
| 219 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 220 |
|
::SetFirstDirection(unsigned int direction) |
| 221 |
|
{ |
| 222 |
|
if( direction >= TImage::ImageDimension ) |
| 223 |
|
{ |
| 224 |
LEN |
itkGenericExceptionMacro(<<"In image of dimension " << TImage::ImageDimension <<" Direction " << direction << " sas selected"); |
| 225 |
|
} |
| 226 |
|
m_Direction_A = direction; |
| 227 |
|
m_PixelJump = this->m_OffsetTable[ m_Direction_A ]; |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
|
| 231 |
EML |
|
| 232 |
EML |
|
| 233 |
|
//---------------------------------------------------------------------- |
| 234 |
|
// Select the second fastest changing direction |
| 235 |
|
//---------------------------------------------------------------------- |
| 236 |
|
template<class TImage> |
| 237 |
|
void |
| 238 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 239 |
|
::SetSecondDirection(unsigned int direction) |
| 240 |
|
{ |
| 241 |
|
if( direction >= TImage::ImageDimension ) |
| 242 |
|
{ |
| 243 |
LEN |
itkGenericExceptionMacro(<<"In image of dimension " << TImage::ImageDimension <<" Direction " << direction << " sas selected"); |
| 244 |
|
} |
| 245 |
|
m_Direction_B = direction; |
| 246 |
|
m_LineJump = this->m_OffsetTable[ m_Direction_B ]; |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
|
| 250 |
EML |
|
| 251 |
|
//---------------------------------------------------------------------- |
| 252 |
|
// Advance along a line |
| 253 |
|
//---------------------------------------------------------------------- |
| 254 |
|
template<class TImage> |
| 255 |
|
ImageSliceConstIteratorWithIndex<TImage> & |
| 256 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 257 |
|
::operator++() |
| 258 |
|
{ |
| 259 |
|
this->m_PositionIndex[ m_Direction_A ]++; |
| 260 |
|
this->m_Position += m_PixelJump; |
| 261 |
|
return *this; |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
EML |
|
| 266 |
|
//---------------------------------------------------------------------- |
| 267 |
|
// Go back along a line |
| 268 |
|
//---------------------------------------------------------------------- |
| 269 |
|
template<class TImage> |
| 270 |
|
ImageSliceConstIteratorWithIndex<TImage> & |
| 271 |
|
ImageSliceConstIteratorWithIndex<TImage> |
| 272 |
|
::operator--() |
| 273 |
|
{ |
| 274 |
|
this->m_PositionIndex[ m_Direction_A ]--; |
| 275 |
|
this->m_Position -= m_PixelJump; |
| 276 |
|
return *this; |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
EML |
|
| 281 |
EML |
|
| 282 |
EML |
|
| 283 |
EML |
|
| 284 |
|
} // end namespace itk |
| 285 |
|
|
| 286 |
|
|
| 287 |
|
#endif |
| 288 |
|
|