ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkImageRandomConstIteratorWithIndex.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 __itkImageRandomConstIteratorWithIndex_h
00019 #define __itkImageRandomConstIteratorWithIndex_h
00020 
00021 #include "itkImageConstIteratorWithIndex.h"
00022 #include "itkMersenneTwisterRandomVariateGenerator.h"
00023 
00024 namespace itk
00025 {
00115 template< typename TImage >
00116 class ITK_EXPORT ImageRandomConstIteratorWithIndex:public ImageConstIteratorWithIndex< TImage >
00117 {
00118 public:
00120   typedef ImageRandomConstIteratorWithIndex     Self;
00121   typedef ImageConstIteratorWithIndex< TImage > Superclass;
00122 
00124   typedef typename Superclass::IndexType             IndexType;
00125   typedef typename Superclass::SizeType              SizeType;
00126   typedef typename Superclass::OffsetType            OffsetType;
00127   typedef typename Superclass::RegionType            RegionType;
00128   typedef typename Superclass::ImageType             ImageType;
00129   typedef typename Superclass::PixelContainer        PixelContainer;
00130   typedef typename Superclass::PixelContainerPointer PixelContainerPointer;
00131   typedef typename Superclass::InternalPixelType     InternalPixelType;
00132   typedef typename Superclass::PixelType             PixelType;
00133   typedef typename Superclass::AccessorType          AccessorType;
00134   typedef typename Superclass::IndexValueType        IndexValueType;
00135   typedef typename Superclass::OffsetValueType       OffsetValueType;
00136   typedef typename Superclass::SizeValueType         SizeValueType;
00137 
00139   ImageRandomConstIteratorWithIndex();
00140   ~ImageRandomConstIteratorWithIndex() {}
00141 
00144   ImageRandomConstIteratorWithIndex(const ImageType *ptr, const RegionType & region);
00145 
00152   ImageRandomConstIteratorWithIndex(const ImageConstIteratorWithIndex< TImage > & it)
00153   {
00154     this->ImageConstIteratorWithIndex< TImage >::operator=(it);
00155   }
00156 
00158   void GoToBegin(void)
00159   {
00160     this->RandomJump();
00161     m_NumberOfSamplesDone = 0L;
00162   }
00164 
00166   void GoToEnd(void)
00167   {
00168     this->RandomJump();
00169     m_NumberOfSamplesDone = m_NumberOfSamplesRequested;
00170   }
00172 
00174   bool IsAtBegin(void) const
00175   {
00176     return ( m_NumberOfSamplesDone == 0L );
00177   }
00178 
00180   bool IsAtEnd(void) const
00181   {
00182     return ( m_NumberOfSamplesDone >= m_NumberOfSamplesRequested );
00183   }
00184 
00187   Self & operator++()
00188   {
00189     this->RandomJump();
00190     m_NumberOfSamplesDone++;
00191     return *this;
00192   }
00194 
00197   Self & operator--()
00198   {
00199     this->RandomJump();
00200     m_NumberOfSamplesDone--;
00201     return *this;
00202   }
00204 
00206   void SetNumberOfSamples(SizeValueType number);
00207 
00208   SizeValueType GetNumberOfSamples(void) const;
00209 
00211   void ReinitializeSeed();
00212 
00213   void ReinitializeSeed(int);
00214 
00215 private:
00216   void RandomJump();
00217 
00218   typedef Statistics::MersenneTwisterRandomVariateGenerator::Pointer GeneratorPointer;
00219   GeneratorPointer m_Generator;
00220   SizeValueType    m_NumberOfSamplesRequested;
00221   SizeValueType    m_NumberOfSamplesDone;
00222   SizeValueType    m_NumberOfPixelsInRegion;
00223 };
00224 } // end namespace itk
00225 
00226 #ifndef ITK_MANUAL_INSTANTIATION
00227 #include "itkImageRandomConstIteratorWithIndex.hxx"
00228 #endif
00229 
00230 #endif
00231