ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkImageRegionConstIterator_h 00019 #define __itkImageRegionConstIterator_h 00020 00021 #include "itkImageIterator.h" 00022 00023 namespace itk 00024 { 00107 template< typename TImage > 00108 class ITK_EXPORT ImageRegionConstIterator:public ImageConstIterator< TImage > 00109 { 00110 public: 00112 typedef ImageRegionConstIterator Self; 00113 typedef ImageConstIterator< TImage > Superclass; 00114 00119 itkStaticConstMacro(ImageIteratorDimension, unsigned int, 00120 Superclass::ImageIteratorDimension); 00121 00128 typedef typename Superclass::IndexType IndexType; 00129 typedef typename Superclass::SizeType SizeType; 00130 typedef typename Superclass::OffsetType OffsetType; 00131 typedef typename Superclass::RegionType RegionType; 00132 typedef typename Superclass::ImageType ImageType; 00133 typedef typename Superclass::PixelContainer PixelContainer; 00134 typedef typename Superclass::PixelContainerPointer PixelContainerPointer; 00135 typedef typename Superclass::InternalPixelType InternalPixelType; 00136 typedef typename Superclass::PixelType PixelType; 00137 typedef typename Superclass::AccessorType AccessorType; 00138 00140 itkTypeMacro(ImageRegionConstIterator, ImageIterator); 00141 00143 ImageRegionConstIterator():ImageConstIterator< TImage >() 00144 { 00145 m_SpanBeginOffset = 0; 00146 m_SpanEndOffset = 0; 00147 } 00148 00151 ImageRegionConstIterator(const ImageType *ptr, 00152 const RegionType & region): 00153 ImageConstIterator< TImage >(ptr, region) 00154 { 00155 m_SpanBeginOffset = this->m_BeginOffset; 00156 m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00157 } 00159 00166 ImageRegionConstIterator(const ImageIterator< TImage > & it) 00167 { 00168 this->ImageConstIterator< TImage >::operator=(it); 00169 00170 IndexType ind = this->GetIndex(); 00171 m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ) 00172 - ( ind[0] - this->m_Region.GetIndex()[0] ); 00173 m_SpanBeginOffset = m_SpanEndOffset 00174 - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00175 } 00176 00183 ImageRegionConstIterator(const ImageConstIterator< TImage > & it) 00184 { 00185 this->ImageConstIterator< TImage >::operator=(it); 00186 00187 IndexType ind = this->GetIndex(); 00188 m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ) 00189 - ( ind[0] - this->m_Region.GetIndex()[0] ); 00190 m_SpanBeginOffset = m_SpanEndOffset 00191 - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00192 } 00193 00196 void GoToBegin() 00197 { 00198 Superclass::GoToBegin(); 00199 00200 // reset the span offsets 00201 m_SpanBeginOffset = this->m_BeginOffset; 00202 m_SpanEndOffset = this->m_BeginOffset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00203 } 00204 00207 void GoToEnd() 00208 { 00209 Superclass::GoToEnd(); 00210 00211 // reset the span offsets 00212 m_SpanEndOffset = this->m_EndOffset; 00213 m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00214 } 00215 00219 Self Begin(void) const; 00220 00224 Self End(void) const; 00225 00229 void SetIndex(const IndexType & ind) 00230 { 00231 Superclass::SetIndex(ind); 00232 m_SpanEndOffset = this->m_Offset + static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ) 00233 - ( ind[0] - this->m_Region.GetIndex()[0] ); 00234 m_SpanBeginOffset = m_SpanEndOffset - static_cast< OffsetValueType >( this->m_Region.GetSize()[0] ); 00235 } 00237 00245 Self & 00246 operator++() 00247 { 00248 if ( ++this->m_Offset >= m_SpanEndOffset ) 00249 { 00250 this->Increment(); 00251 } 00252 return *this; 00253 } 00255 00263 Self & operator--() 00264 { 00265 if ( --this->m_Offset < m_SpanBeginOffset ) 00266 { 00267 this->Decrement(); 00268 } 00269 return *this; 00270 } 00272 00273 protected: 00274 OffsetValueType m_SpanBeginOffset; // one pixel before the beginning of the span 00275 // (row) 00276 OffsetValueType m_SpanEndOffset; // one pixel past the end of the span (row) 00277 00278 private: 00279 void Increment(); // advance in a direction other than the fastest moving 00280 00281 void Decrement(); // go back in a direction other than the fastest moving 00282 }; 00283 } // end namespace itk 00284 00285 // Define instantiation macro for this template. 00286 #define ITK_TEMPLATE_ImageRegionConstIterator(_, EXPORT, TypeX, TypeY) \ 00287 namespace itk \ 00288 { \ 00289 _( 1 ( class EXPORT ImageRegionConstIterator< ITK_TEMPLATE_1 TypeX > ) ) \ 00290 namespace Templates \ 00291 { \ 00292 typedef ImageRegionConstIterator< ITK_TEMPLATE_1 TypeX > ImageRegionConstIterator##TypeY; \ 00293 } \ 00294 } 00295 00296 #if ITK_TEMPLATE_EXPLICIT 00297 #include "Templates/itkImageRegionConstIterator+-.h" 00298 #endif 00299 00300 #if ITK_TEMPLATE_TXX 00301 #include "itkImageRegionConstIterator.hxx" 00302 #endif 00303 00304 #endif 00305