| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkPathConstIterator.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:43 $ |
| 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 _itkPathConstIterator_txx |
| 18 |
DEF |
#define _itkPathConstIterator_txx |
| 19 |
|
|
| 20 |
|
#include "itkPathConstIterator.h" |
| 21 |
|
#include "itkOffset.h" // for operator++ |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
template<class TImage, class TPath> |
| 27 |
|
PathConstIterator<TImage, TPath> |
| 28 |
|
::PathConstIterator(const ImageType *imagePtr, const PathType *pathPtr) |
| 29 |
|
{ |
| 30 |
|
m_ZeroOffset.Fill(0); |
| 31 |
|
|
| 32 |
|
m_Image = imagePtr; |
| 33 |
|
m_Path = pathPtr; |
| 34 |
|
|
| 35 |
|
m_ImageOrigin = m_Image->GetOrigin(); |
| 36 |
|
m_ImageSpacing = m_Image->GetSpacing(); |
| 37 |
|
m_Region = m_Image->GetLargestPossibleRegion(); |
| 38 |
|
m_ImageSize = m_Region.GetSize().m_Size; |
| 39 |
|
|
| 40 |
|
m_VisitStartIndexAsLastIndexIfClosed=true; |
| 41 |
|
|
| 42 |
|
GoToBegin(); |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
template<class TImage, class TPath> |
| 47 |
|
PathConstIterator<TImage, TPath> & |
| 48 |
|
PathConstIterator<TImage, TPath> |
| 49 |
|
::operator=(const Self & it) |
| 50 |
|
{ |
| 51 |
|
m_Image = it.m_Image; // copy the smart pointer |
| 52 |
|
m_Path = it.m_Path; // copy the smart pointer |
| 53 |
|
m_Region = it.m_Region; |
| 54 |
|
m_ImageOrigin = it.m_ImageOrigin; |
| 55 |
|
m_ImageSpacing = it.m_ImageSpacing; |
| 56 |
|
m_ImageSize = it.m_ImageSize; |
| 57 |
|
m_CurrentPathPosition = it.m_CurrentPathPosition; |
| 58 |
|
m_CurrentImageIndex = it.m_CurrentImageIndex; |
| 59 |
|
m_VisitStartIndexAsLastIndexIfClosed=it.m_VisitStartIndexAsLastIndexIfClosed; |
| 60 |
|
return *this; |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
template<class TImage, class TPath> |
| 65 |
|
void |
| 66 |
|
PathConstIterator<TImage, TPath> |
| 67 |
|
::GoToBegin() |
| 68 |
|
{ |
| 69 |
WCM |
// Go the the beginning |
| 70 |
|
m_CurrentPathPosition = m_Path->StartOfInput(); |
| 71 |
|
|
| 72 |
|
// But don't visit the first index twice for closed paths (unless told to) |
| 73 |
|
if( m_VisitStartIndexAsLastIndexIfClosed ) |
| 74 |
|
{ |
| 75 |
|
// Are the first and last indices coincident? |
| 76 |
|
if( m_Path->EvaluateToIndex(m_Path->EndOfInput()) == |
| 77 |
IND |
*********m_Path->EvaluateToIndex(m_Path->StartOfInput()) ) |
| 78 |
|
{ |
| 79 |
|
// Skip the starting index; we will visit it later. |
| 80 |
|
m_Path->IncrementInput(m_CurrentPathPosition); |
| 81 |
|
} |
| 82 |
|
} |
| 83 |
|
// Update the other member data |
| 84 |
|
m_CurrentImageIndex = m_Path->EvaluateToIndex( m_CurrentPathPosition ); |
| 85 |
|
m_IsAtEnd = false; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
template<class TImage, class TPath> |
| 90 |
|
void |
| 91 |
|
PathConstIterator<TImage, TPath> |
| 92 |
|
::operator++() |
| 93 |
|
{ |
| 94 |
|
// We need to modify m_CurrentPathPosition, m_CurrentImageIndex, m_IsAtEnd |
| 95 |
|
OffsetType offset; |
| 96 |
|
|
| 97 |
|
offset = m_Path->IncrementInput(m_CurrentPathPosition); |
| 98 |
|
|
| 99 |
|
if( m_ZeroOffset == offset ) |
| 100 |
|
{ |
| 101 |
|
// We tried to go past the end (and we are still there) |
| 102 |
|
m_IsAtEnd = true; |
| 103 |
|
} |
| 104 |
|
else if( ! m_Region.IsInside( m_CurrentImageIndex ) ) |
| 105 |
|
{ |
| 106 |
|
// The new index is outside the acceptable region. We can iterate no |
| 107 |
|
// farther, call this the end. NOTE THAT INPUT IS STILL INCREMENTED. |
| 108 |
|
m_IsAtEnd = true; |
| 109 |
|
itkWarningMacro(<<"Path left region; unable to finish tracing it"); |
| 110 |
|
} |
| 111 |
|
else |
| 112 |
|
{ |
| 113 |
|
m_CurrentImageIndex += offset; |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
} // end namespace itk |
| 118 |
|
|
| 119 |
|
#endif |
| 120 |
|
|