ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkShapedNeighborhoodIterator.h
Go to the documentation of this file.
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 __itkShapedNeighborhoodIterator_h
00019 #define __itkShapedNeighborhoodIterator_h
00020 
00021 #include <vector>
00022 #include <list>
00023 #include "itkConstShapedNeighborhoodIterator.h"
00024 
00025 namespace itk
00026 {
00150 template< class TImage,  class TBoundaryCondition =
00151             ZeroFluxNeumannBoundaryCondition< TImage > >
00152 class ITK_EXPORT ShapedNeighborhoodIterator:
00153   public ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
00154 {
00155 public:
00157   typedef typename TImage::InternalPixelType InternalPixelType;
00158   typedef typename TImage::PixelType         PixelType;
00159 
00161   itkStaticConstMacro(Dimension, unsigned int, TImage::ImageDimension);
00162 
00164   typedef ShapedNeighborhoodIterator Self;
00165   typedef ConstShapedNeighborhoodIterator< TImage, TBoundaryCondition >
00166   Superclass;
00167 
00169   typedef typename Superclass::OffsetType                        OffsetType;
00170   typedef typename OffsetType::OffsetValueType                   OffsetValueType;
00171   typedef typename Superclass::RadiusType                        RadiusType;
00172   typedef typename Superclass::SizeType                          SizeType;
00173   typedef typename Superclass::SizeValueType                     SizeValueType;
00174   typedef typename Superclass::ConstIterator                     ConstIterator;
00175   typedef typename Superclass::IndexListType                     IndexListType;
00176   typedef typename Superclass::BoundaryConditionType             BoundaryConditionType;
00177   typedef typename Superclass::ImageBoundaryConditionPointerType ImageBoundaryConditionPointerType;
00178   typedef typename Superclass::NeighborhoodType                  NeighborhoodType;
00179   typedef typename Superclass::IndexType                         IndexType;
00180   typedef typename Superclass::ImageType                         ImageType;
00181   typedef typename Superclass::RegionType                        RegionType;
00182   typedef typename Superclass::IndexValueType                    IndexValueType;
00183 
00185   struct Iterator:public ConstIterator {
00186     Iterator() {}
00187     Iterator(Self *s):ConstIterator(s) {}
00189 
00190     ~Iterator() {}
00191     const Iterator & operator=(const Iterator & o)
00192     {
00193       ConstIterator::operator=(o);
00194       return *this;
00195     }
00196 
00197     // Promote to public
00198     void Set(const PixelType & v) const
00199     { ConstIterator::ProtectedSet(v); }
00200   };
00201 
00203   ShapedNeighborhoodIterator()
00204   {
00205     m_BeginIterator = Iterator(this);
00206     m_EndIterator = Iterator(this);
00207     m_EndIterator.GoToEnd();
00208   }
00210 
00212   virtual ~ShapedNeighborhoodIterator() {}
00213 
00216   ShapedNeighborhoodIterator(const SizeType & radius,
00217                              const ImageType *ptr,
00218                              const RegionType & region
00219                              ):Superclass(radius, const_cast< ImageType * >( ptr ),
00220                                           region)
00221   {
00222     m_BeginIterator = Iterator(this);
00223     m_EndIterator = Iterator(this);
00224     m_EndIterator.GoToEnd();
00225   }
00227 
00228   // Expose the following methods from the superclass.  This is a restricted
00229   // subset of the methods available for NeighborhoodIterator.
00230   using Superclass::SetPixel;
00231   using Superclass::SetCenterPixel;
00232 
00233 
00235   Self & operator=(const Self & orig)
00236   {
00237     Superclass::operator=(orig);
00238 
00239     // Reset begin and end pointer locations
00240     m_BeginIterator.GoToBegin();
00241     m_EndIterator.GoToEnd();
00242     return *this;
00243   }
00244 
00246   virtual void PrintSelf(std::ostream &, Indent) const;
00247 
00250   Iterator & Begin() {    return m_BeginIterator;  }
00251   Iterator & End()   {   return m_EndIterator;     }
00253 
00256   const ConstIterator & End() const
00257   { return this->m_ConstEndIterator; }
00258 
00259   void ClearActiveList()
00260   {
00261     Superclass::ClearActiveList();
00262     m_EndIterator.GoToEnd();
00263     m_BeginIterator.GoToBegin();
00264   }
00265 
00266 protected:
00267 
00269   ShapedNeighborhoodIterator(const ShapedNeighborhoodIterator & o);
00270   // purposely not implemented
00271 
00272   typedef typename Superclass::NeighborIndexType NeighborIndexType;
00273 
00274   void ActivateIndex(NeighborIndexType n)
00275   {
00276     Superclass::ActivateIndex(n);
00277     m_EndIterator.GoToEnd();
00278     m_BeginIterator.GoToBegin();
00279   }
00280 
00281   void DeactivateIndex(NeighborIndexType n)
00282   {
00283     Superclass::DeactivateIndex(n);
00284     m_EndIterator.GoToEnd();
00285     m_BeginIterator.GoToBegin();
00286   }
00287 
00288   Iterator m_EndIterator;
00289   Iterator m_BeginIterator;
00290 };
00291 } // namespace itk
00292 
00293 #ifndef ITK_MANUAL_INSTANTIATION
00294 #include "itkShapedNeighborhoodIterator.hxx"
00295 #endif
00296 
00297 #endif
00298