ITK/Examples/Iterators/ImageRandomNonRepeatingConstIteratorWithIndex

From KitwarePublic
< ITK‎ | Examples
Revision as of 12:17, 26 February 2011 by Daviddoria (talk | contribs) (Created page with "==ImageRandomNonRepeatingConstIteratorWithIndex.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageRandomNonRepeatingConstIteratorW...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

ImageRandomNonRepeatingConstIteratorWithIndex.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileReader.h"
  3. include "itkImageRandomNonRepeatingConstIteratorWithIndex.h"

int main(int argc, char*argv[]) {

 typedef itk::Image<unsigned char, 2>  ImageType;
 ImageType::Pointer image = ImageType::New();
 ImageType::SizeType regionSize;
 regionSize.Fill(3);
 ImageType::IndexType regionIndex;
 regionIndex.Fill(0);
 ImageType::RegionType region(regionIndex, regionSize);
 
 image->SetRegions(region);
 image->Allocate();
 image->FillBuffer(0);
 itk::ImageRandomNonRepeatingConstIteratorWithIndex<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
 imageIterator.SetNumberOfSamples(region.GetNumberOfPixels());
 imageIterator.GoToBegin();
 while(!imageIterator.IsAtEnd())
   {
   std::cout << imageIterator.GetIndex() << std::endl;
   ++imageIterator;
   }
 return EXIT_SUCCESS;

}

</source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(ImageRandomNonRepeatingConstIteratorWithIndex)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ImageRandomNonRepeatingConstIteratorWithIndex ImageRandomNonRepeatingConstIteratorWithIndex.cxx) TARGET_LINK_LIBRARIES(ImageRandomNonRepeatingConstIteratorWithIndex ITKNumerics ITKBasicFilters ITKCommon ITKIO)

</source>