ITK  5.0.0
Insight Segmentation and Registration Toolkit
WikiExamples/Iterators/ImageRandomConstIteratorWithIndex.cxx
#include "itkImage.h"
int main(int, char *[])
{
using ImageType = itk::Image<unsigned char, 2>;
ImageType::Pointer image = ImageType::New();
ImageType::SizeType regionSize;
regionSize[0] = 5;
regionSize[1] = 4;
ImageType::IndexType regionIndex;
regionIndex[0] = 0;
regionIndex[1] = 0;
region.SetSize(regionSize);
region.SetIndex(regionIndex);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
itk::ImageRandomConstIteratorWithIndex<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
imageIterator.SetNumberOfSamples(200);
imageIterator.GoToBegin();
while(!imageIterator.IsAtEnd())
{
std::cout << imageIterator.GetIndex() << std::endl;
++imageIterator;
}
return EXIT_SUCCESS;
}