| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkConstShapedNeighborhoodIterator.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:34 $ |
| 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 _itkConstShapedNeighborhoodIterator_txx |
| 18 |
DEF |
#define _itkConstShapedNeighborhoodIterator_txx |
| 19 |
|
#include "itkConstShapedNeighborhoodIterator.h" |
| 20 |
|
namespace itk { |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
template<class TImage, class TBoundaryCondition> |
| 24 |
|
void |
| 25 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 26 |
|
::PrintSelf(std::ostream &os, Indent indent) const |
| 27 |
|
{ |
| 28 |
|
os << indent << "ConstShapedNeighborhoodIterator {this = " << this; |
| 29 |
|
os << " m_ActiveIndexList = ["; |
| 30 |
|
for (IndexListType::const_iterator it = m_ActiveIndexList.begin(); |
| 31 |
|
it != m_ActiveIndexList.end(); ++it) |
| 32 |
|
{ os << *it << " "; } |
| 33 |
|
os << "] "; |
| 34 |
|
os << " m_CenterIsActive = " << m_CenterIsActive; |
| 35 |
|
os << "}" << std::endl; |
| 36 |
|
Superclass::PrintSelf(os, indent.GetNextIndent()); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
template<class TImage, class TBoundaryCondition> |
| 40 |
|
void |
| 41 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 42 |
|
::ActivateIndex(const unsigned int n) |
| 43 |
|
{ |
| 44 |
|
const OffsetValueType *OffsetTable = this->m_ConstImage->GetOffsetTable(); |
| 45 |
|
|
| 46 |
|
// Insert so that the list remains ordered. |
| 47 |
|
IndexListType::iterator it = m_ActiveIndexList.begin(); |
| 48 |
|
|
| 49 |
|
if (m_ActiveIndexList.empty()) { m_ActiveIndexList.push_front(n); } |
| 50 |
|
else |
| 51 |
|
{ |
| 52 |
|
while (n > *it) |
| 53 |
|
{ |
| 54 |
|
it++; |
| 55 |
|
if (it == m_ActiveIndexList.end()) { break; } |
| 56 |
|
} |
| 57 |
|
if (it == m_ActiveIndexList.end()) |
| 58 |
|
{ m_ActiveIndexList.insert(it, n); } |
| 59 |
|
else if (n != *it) |
| 60 |
|
{ m_ActiveIndexList.insert(it, n); } |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
// Adjust the begin and end iterators. |
| 64 |
|
m_ConstBeginIterator.GoToBegin(); |
| 65 |
|
m_ConstEndIterator.GoToEnd(); |
| 66 |
|
|
| 67 |
|
// Did we just activate the index at the center of the neighborhood? |
| 68 |
|
if ( n == this->GetCenterNeighborhoodIndex() ) |
| 69 |
|
{ m_CenterIsActive = true; } |
| 70 |
|
|
| 71 |
|
// Set the pointer in the neighborhood location just activated. |
| 72 |
|
this->GetElement(n) = this->GetCenterPointer(); |
| 73 |
|
for (unsigned i = 0; i < Dimension; ++i) |
| 74 |
|
{ this->GetElement(n) += OffsetTable[i] * this->GetOffset(n)[i]; } |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
template<class TImage, class TBoundaryCondition> |
| 78 |
|
void |
| 79 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 80 |
|
::DeactivateIndex(const unsigned int n) |
| 81 |
|
{ |
| 82 |
|
IndexListType::iterator it = m_ActiveIndexList.begin(); |
| 83 |
|
|
| 84 |
|
if (m_ActiveIndexList.empty()) return; |
| 85 |
|
else |
| 86 |
|
{ |
| 87 |
|
while (n != *it) |
| 88 |
|
{ |
| 89 |
|
it++; |
| 90 |
|
if (it == m_ActiveIndexList.end()) return; |
| 91 |
|
} |
| 92 |
|
m_ActiveIndexList.erase(it); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
// Adjust the begin and end iterators. |
| 96 |
|
m_ConstBeginIterator.GoToBegin(); |
| 97 |
|
m_ConstEndIterator.GoToEnd(); |
| 98 |
|
|
| 99 |
|
// Did we just deactivate the index at the center of the neighborhood? |
| 100 |
|
if ( n == this->GetCenterNeighborhoodIndex() ) |
| 101 |
|
{ m_CenterIsActive = false; } |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
template<class TImage, class TBoundaryCondition> |
| 106 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> & |
| 107 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 108 |
|
::operator++() |
| 109 |
|
{ |
| 110 |
|
unsigned int i; |
| 111 |
|
IndexListType::const_iterator it; |
| 112 |
|
|
| 113 |
|
// Repositioning neighborhood, previous bounds check on neighborhood |
| 114 |
|
// location is invalid. |
| 115 |
|
this->m_IsInBoundsValid = false; |
| 116 |
|
|
| 117 |
|
// Center pointer must be updated whether or not it is active. |
| 118 |
|
if (! m_CenterIsActive) |
| 119 |
|
{ |
| 120 |
|
this->GetElement( |
| 121 |
|
this->GetCenterNeighborhoodIndex() |
| 122 |
IND |
******)++; } |
| 123 |
|
|
| 124 |
|
// Increment pointers for only the active pixels. |
| 125 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 126 |
|
{ (this->GetElement(*it))++; } |
| 127 |
|
|
| 128 |
|
// Check loop bounds, wrap & add pointer offsets if needed. |
| 129 |
|
for (i=0; i<Dimension; ++i) |
| 130 |
|
{ |
| 131 |
|
this->m_Loop[i]++; |
| 132 |
|
if ( this->m_Loop[i] == this->m_Bound[i] ) |
| 133 |
|
{ |
| 134 |
|
this->m_Loop[i] = this->m_BeginIndex[i]; |
| 135 |
|
if (! m_CenterIsActive) |
| 136 |
LEN |
{ this->GetElement(this->GetCenterNeighborhoodIndex())+= this->m_WrapOffset[i]; } |
| 137 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 138 |
|
{ (this->GetElement(*it))+= this->m_WrapOffset[i]; } |
| 139 |
|
} |
| 140 |
|
else break; |
| 141 |
|
} |
| 142 |
|
return *this; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
template<class TImage, class TBoundaryCondition> |
| 146 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> & |
| 147 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 148 |
|
::operator--() |
| 149 |
|
{ |
| 150 |
|
unsigned int i; |
| 151 |
|
IndexListType::const_iterator it; |
| 152 |
|
|
| 153 |
|
// Repositioning neighborhood, previous bounds check on neighborhood |
| 154 |
|
// location is invalid. |
| 155 |
|
this->m_IsInBoundsValid = false; |
| 156 |
|
|
| 157 |
|
// Center pointer must be updated whether or not it is active. |
| 158 |
LEN |
if (! m_CenterIsActive) { this->GetElement(this->GetCenterNeighborhoodIndex())--; } |
| 159 |
|
|
| 160 |
|
// Decrement pointers for only the active pixels. |
| 161 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 162 |
|
{ (this->GetElement(*it))--; } |
| 163 |
|
|
| 164 |
|
// Check loop bounds, wrap & add pointer offsets if needed. |
| 165 |
|
for (i=0; i<Dimension; ++i) |
| 166 |
|
{ |
| 167 |
|
if (this->m_Loop[i] == this->m_BeginIndex[i]) |
| 168 |
|
{ |
| 169 |
|
this->m_Loop[i]= this->m_Bound[i] - 1; |
| 170 |
|
if (! m_CenterIsActive) |
| 171 |
LEN |
{ this->GetElement(this->GetCenterNeighborhoodIndex())-= this->m_WrapOffset[i]; } |
| 172 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 173 |
|
{ (this->GetElement(*it))-= this->m_WrapOffset[i]; } |
| 174 |
|
} |
| 175 |
|
else |
| 176 |
|
{ |
| 177 |
|
this->m_Loop[i]--; |
| 178 |
|
break; |
| 179 |
|
} |
| 180 |
|
} |
| 181 |
|
return *this; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
template<class TImage, class TBoundaryCondition> |
| 185 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> & |
| 186 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 187 |
|
::operator+=(const OffsetType & idx) |
| 188 |
|
{ |
| 189 |
|
unsigned int i; |
| 190 |
|
IndexListType::const_iterator it; |
| 191 |
|
OffsetValueType accumulator = 0; |
| 192 |
|
const OffsetValueType* stride = this->GetImagePointer()->GetOffsetTable(); |
| 193 |
|
|
| 194 |
|
// Repositioning neighborhood, previous bounds check on neighborhood |
| 195 |
|
// location is invalid. |
| 196 |
|
this->m_IsInBoundsValid = false; |
| 197 |
|
|
| 198 |
|
// Offset from the increment in the lowest dimension |
| 199 |
|
accumulator += idx[0]; |
| 200 |
|
|
| 201 |
|
// Offsets from the stride lengths in each dimension. |
| 202 |
|
// |
| 203 |
|
// Because the image offset table is based on its buffer size and not its |
| 204 |
|
// requested region size, we don't have to worry about adding in the wrapping |
| 205 |
|
// offsets. |
| 206 |
|
for (i = 1; i< Dimension; ++i) |
| 207 |
|
{ |
| 208 |
|
accumulator += idx[i] * stride[i]; |
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
// Center pointer is always updated even if not active. |
| 212 |
|
if (! m_CenterIsActive) |
| 213 |
|
{ this->GetElement(this->GetCenterNeighborhoodIndex())+= accumulator; } |
| 214 |
|
|
| 215 |
|
// Increment pointers only for those active pixels |
| 216 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 217 |
SEM |
{ (this->GetElement(*it))+= accumulator ; } |
| 218 |
|
|
| 219 |
|
// Update loop counter values |
| 220 |
|
this->m_Loop += idx; |
| 221 |
|
|
| 222 |
|
return *this; |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
template<class TImage, class TBoundaryCondition> |
| 226 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> & |
| 227 |
|
ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition> |
| 228 |
|
::operator-=(const OffsetType & idx) |
| 229 |
|
{ |
| 230 |
|
unsigned int i; |
| 231 |
|
IndexListType::const_iterator it; |
| 232 |
|
OffsetValueType accumulator = 0; |
| 233 |
|
const OffsetValueType* stride = this->GetImagePointer()->GetOffsetTable(); |
| 234 |
|
|
| 235 |
|
// Repositioning neighborhood, previous bounds check on neighborhood |
| 236 |
|
// location is invalid. |
| 237 |
|
this->m_IsInBoundsValid = false; |
| 238 |
|
|
| 239 |
|
// Offset from the increment in the lowest dimension |
| 240 |
|
accumulator += idx[0]; |
| 241 |
|
|
| 242 |
|
// Offsets from the stride lengths in each dimension. |
| 243 |
|
// |
| 244 |
|
// Because the image offset table is based on its buffer size and not its |
| 245 |
|
// requested region size, we don't have to worry about adding in the wrapping |
| 246 |
|
// offsets. |
| 247 |
|
for (i = 1; i< Dimension; ++i) |
| 248 |
|
{ |
| 249 |
|
accumulator += idx[i] * stride[i]; |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
// Center pointer is always updated even if not active. |
| 253 |
|
if (! m_CenterIsActive) |
| 254 |
|
{ this->GetElement(this->GetCenterNeighborhoodIndex()) -= accumulator; } |
| 255 |
|
|
| 256 |
|
// Increment pointers only for those active pixels |
| 257 |
|
for (it = m_ActiveIndexList.begin(); it != m_ActiveIndexList.end(); it++) |
| 258 |
SEM |
{ (this->GetElement(*it)) -= accumulator ; } |
| 259 |
|
|
| 260 |
|
// Update loop counter values |
| 261 |
|
this->m_Loop -= idx; |
| 262 |
|
|
| 263 |
|
return *this; |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
} // namespace itk |
| 267 |
|
|
| 268 |
|
#endif |
| 269 |
|
|
| 270 |
EOF |
|