ITK/Examples/Iterators/ImageRegionExclusionConstIteratorWithIndex

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

ImageRegionExclusionConstIteratorWithIndex.cxx

<source lang="cpp">

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

typedef itk::Image<int, 2> ImageType;

void CreateImage(ImageType::Pointer);

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

 ImageType::SizeType exclusionRegionSize;
 exclusionRegionSize.Fill(2);
 ImageType::IndexType exclusionRegionIndex;
 exclusionRegionIndex.Fill(0);
 ImageType::RegionType exclusionRegion(exclusionRegionIndex, exclusionRegionSize);
 ImageType::Pointer image = ImageType::New();
 CreateImage(image);
 
 itk::ImageRegionExclusionConstIteratorWithIndex<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
 imageIterator.SetExclusionRegion(exclusionRegion);
 unsigned int numberVisited = 0;
 while(!imageIterator.IsAtEnd())
   {
   std::cout << imageIterator.Get() << std::endl;
   ++imageIterator;
   ++numberVisited;
   }
   
 std::cout << "Visited " << numberVisited << std::endl;
 
 return EXIT_SUCCESS;

}

void CreateImage(ImageType::Pointer image) {

 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);
 

} </source>

CMakeLists.txt

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

PROJECT(ImageRegionExclusionConstIteratorWithIndex)

include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/)

FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})

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

ADD_EXECUTABLE(ImageRegionExclusionConstIteratorWithIndex ImageRegionExclusionConstIteratorWithIndex.cxx) TARGET_LINK_LIBRARIES(ImageRegionExclusionConstIteratorWithIndex vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO)

</source>