KWStyle - itkImageConstIteratorWithIndex.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImageConstIteratorWithIndex.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:36 $
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 _itkImageConstIteratorWithIndex_txx
18 DEF #define _itkImageConstIteratorWithIndex_txx
19
20 #include "itkImageConstIteratorWithIndex.h"
21
22 namespace itk
23 {
24
25
26 EML
27 //----------------------------------------------------------------------
28 //  Constructor
29 //----------------------------------------------------------------------
30 template<class TImage>
31 ImageConstIteratorWithIndex<TImage>
32 ::ImageConstIteratorWithIndex()
33 {
34   m_Position  = 0;
35   m_Begin     = 0;
36   m_End       = 0;
37   m_Remaining = false;
38 }
39
40
41 EML
42 //----------------------------------------------------------------------
43 //  Constructor
44 //----------------------------------------------------------------------
45 template<class TImage>
46 ImageConstIteratorWithIndex<TImage>
47 ::ImageConstIteratorWithIndex(const Self& it)
48 {
49   m_Image = it.m_Image;     // copy the smart pointer
50
51   m_PositionIndex     = it.m_PositionIndex;
52   m_BeginIndex        = it.m_BeginIndex;
53   m_EndIndex          = it.m_EndIndex;
54   m_Region            = it.m_Region;
55
56   memcpy(m_OffsetTable, it.m_OffsetTable, 
57          (ImageDimension+1)*sizeof(unsigned long));
58   
59   m_Position    = it.m_Position;
60   m_Begin       = it.m_Begin;
61   m_End         = it.m_End;
62   m_Remaining   = it.m_Remaining;
63
64   m_PixelAccessor = it.m_PixelAccessor;
65   m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
66   m_PixelAccessorFunctor.SetBegin( m_Image->GetBufferPointer() );
67 }
68
69
70 EML
71 //----------------------------------------------------------------------
72 //  Constructor
73 //----------------------------------------------------------------------
74 template<class TImage>
75 ImageConstIteratorWithIndex<TImage>
76 ::ImageConstIteratorWithIndex( const TImage *ptr,
77                                const RegionType & region )
78 {
79   m_Image = ptr;
80
81   const InternalPixelType * buffer   = m_Image->GetBufferPointer();
82
83   m_BeginIndex        = region.GetIndex();
84   m_PositionIndex     = m_BeginIndex;
85   m_Region            = region;
86
87   memcpy(m_OffsetTable, m_Image->GetOffsetTable(), 
88 IND *********(ImageDimension+1)*sizeof(unsigned long));
89
90   // Compute the start position
91   long offs =  m_Image->ComputeOffset( m_BeginIndex );
92   m_Begin = buffer + offs;
93   m_Position = m_Begin;
94   
95   // Compute the end offset
96   m_Remaining = false;
97   IndexType pastEnd;
98   for (unsigned int i=0; i < ImageDimension; ++i)
99     {
100     unsigned long size = region.GetSize()[i];
101     if( size > 0 )
102       {
103       m_Remaining = true;
104       }
105     m_EndIndex[i] = m_BeginIndex[i] + static_cast<long>(size);
106     pastEnd[i]    = m_BeginIndex[i] + static_cast<long>(size)-1;
107     }
108   m_End = buffer + m_Image->ComputeOffset( pastEnd );
109
110   m_PixelAccessor = m_Image->GetPixelAccessor();
111   m_PixelAccessorFunctor.SetPixelAccessor( m_PixelAccessor );
112   m_PixelAccessorFunctor.SetBegin( buffer );
113
114   GoToBegin();
115
116 }
117  
118
119 //----------------------------------------------------------------------
120 //    Assignment Operator
121 //----------------------------------------------------------------------
122 template<class TImage>
123 ImageConstIteratorWithIndex<TImage> &
124 ImageConstIteratorWithIndex<TImage>
125 ::operator=(const Self& it)
126 {
127   m_Image = it.m_Image;     // copy the smart pointer
128
129   m_BeginIndex        = it.m_BeginIndex;
130   m_EndIndex          = it.m_EndIndex;
131   m_PositionIndex     = it.m_PositionIndex;
132   m_Region            = it.m_Region;
133
134   memcpy(m_OffsetTable, it.m_OffsetTable, 
135          (ImageDimension+1)*sizeof(unsigned long));
136   
137   m_Position    = it.m_Position;
138   m_Begin       = it.m_Begin;
139   m_End         = it.m_End;
140   m_Remaining   = it.m_Remaining;
141
142   m_PixelAccessor = it.m_PixelAccessor;
143   m_PixelAccessorFunctor = it.m_PixelAccessorFunctor;
144   m_PixelAccessorFunctor.SetBegin( m_Image->GetBufferPointer() );
145
146   return *this;
147
148   
149
150
151 //----------------------------------------------------------------------------
152 // Begin() is the first pixel in the region.
153 //----------------------------------------------------------------------------
154 template<class TImage>
155 ImageConstIteratorWithIndex<TImage> 
156 ImageConstIteratorWithIndex<TImage>
157 ::Begin() const
158 {
159   Self it( *this );
160   it.GoToBegin();
161   return it;
162 }
163
164
165 //----------------------------------------------------------------------------
166 // GoToBegin() is the first pixel in the region.
167 //----------------------------------------------------------------------------
168 template<class TImage>
169 void
170 ImageConstIteratorWithIndex<TImage>
171 ::GoToBegin()
172 {
173   // Set the position at begin
174
175   m_Position       = m_Begin;
176   m_PositionIndex  = m_BeginIndex;
177  
178   if( m_Region.GetNumberOfPixels() > 0 )
179     {
180     m_Remaining = true;
181     }
182   else
183     {
184     m_Remaining = false;
185     }
186
187 }
188
189
190 //----------------------------------------------------------------------------
191 // End() is the last pixel in the region.  DEPRECATED
192 //----------------------------------------------------------------------------
193 template<class TImage>
194 ImageConstIteratorWithIndex<TImage> 
195 ImageConstIteratorWithIndex<TImage>
196 ::End() const
197 {
198   Self it( *this );
199   it.GoToReverseBegin();
200   return it;
201 }
202
203
204 //----------------------------------------------------------------------------
205 // GoToReverseBegin() is the last pixel in the region.
206 //----------------------------------------------------------------------------
207 template<class TImage>
208 void
209 ImageConstIteratorWithIndex<TImage>
210 ::GoToReverseBegin()
211 {
212
213   for (unsigned int i=0; i < ImageDimension; ++i)
214     {
215     m_PositionIndex[i]  = m_EndIndex[i]-1;
216     }
217  
218   if( m_Region.GetNumberOfPixels() > 0 )
219     {
220     m_Remaining = true;
221     }
222   else
223     {
224     m_Remaining = false;
225     }
226
227
228   // Set the position at the end
229   const InternalPixelType * buffer   = m_Image->GetBufferPointer();
230 LEN   const unsigned long       offset   = m_Image->ComputeOffset( m_PositionIndex );
231   m_Position = buffer + offset;
232
233 }
234
235
236 // end namespace itk
237
238
239 EML
240 EML
241 #endif
242

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:13PM
© Kitware Inc.