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