Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

Common/itkImageSliceIteratorTest.cxx

MORE INFORMATION
For a complete description of the ITK Image Iterators and their API, please see the Iterators chapter in the ITK Software Guide. The ITK Software Guide is available in print and as a free .pdf download from http://www.itk.org.
See also:
ImageConstIterator

ConditionalConstIterator

ConstNeighborhoodIterator

ConstShapedNeighborhoodIterator

ConstSliceIterator

CorrespondenceDataStructureIterator

FloodFilledFunctionConditionalConstIterator

FloodFilledImageFunctionConditionalConstIterator

FloodFilledImageFunctionConditionalIterator

FloodFilledSpatialFunctionConditionalConstIterator

FloodFilledSpatialFunctionConditionalIterator

ImageConstIterator

ImageConstIteratorWithIndex

ImageIterator

ImageIteratorWithIndex

ImageLinearConstIteratorWithIndex

ImageLinearIteratorWithIndex

ImageRandomConstIteratorWithIndex

ImageRandomIteratorWithIndex

ImageRegionConstIterator

ImageRegionConstIteratorWithIndex

ImageRegionExclusionConstIteratorWithIndex

ImageRegionExclusionIteratorWithIndex

ImageRegionIterator

ImageRegionIteratorWithIndex

ImageRegionReverseConstIterator

ImageRegionReverseIterator

ImageReverseConstIterator

ImageReverseIterator

ImageSliceConstIteratorWithIndex

ImageSliceIteratorWithIndex

NeighborhoodIterator

PathConstIterator

PathIterator

ShapedNeighborhoodIterator

SliceIterator

ImageConstIteratorWithIndex

00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageSliceIteratorTest.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:30:09 $
00007   Version:   $Revision: 1.12 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #if defined(_MSC_VER)
00018 #pragma warning ( disable : 4786 )
00019 #endif
00020 
00021 #include <iostream>
00022 
00023 #include "itkImage.h"
00024 #include "itkImageSliceIteratorWithIndex.h"
00025 #include "itkImageSliceConstIteratorWithIndex.h"
00026 
00027 
00028 
00029 
00030 int itkImageSliceIteratorTest(int, char* [] )
00031 {
00032   std::cout << "Creating an image of indices" << std::endl;
00033 
00034   const unsigned int ImageDimension = 3;
00035 
00036   typedef itk::Index< ImageDimension >             PixelType;
00037 
00038   typedef itk::Image< PixelType, ImageDimension >  ImageType;
00039 
00040 
00041   ImageType::Pointer myImage = ImageType::New();
00042   
00043   ImageType::SizeType size;
00044 
00045   size[0] = 100;
00046   size[1] = 100;
00047   size[2] = 100;
00048 
00049   ImageType::IndexType start;
00050   start.Fill(0);
00051 
00052   ImageType::RegionType region;
00053   region.SetIndex( start );
00054   region.SetSize( size );
00055 
00056   myImage->SetLargestPossibleRegion( region );
00057   myImage->SetBufferedRegion( region );
00058   myImage->SetRequestedRegion( region );
00059   myImage->Allocate();
00060 
00061   typedef itk::ImageSliceIteratorWithIndex< ImageType > IteratorType;
00062 
00063   typedef itk::ImageSliceConstIteratorWithIndex< ImageType > ConstIteratorType;
00064 
00065   IteratorType it( myImage, region );
00066 
00067   it.GoToBegin();
00068   it.SetFirstDirection( 0 );  // 0=x, 1=y, 2=z
00069   it.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00070 
00071   ImageType::IndexType index;
00072   
00073   while( !it.IsAtEnd() )
00074   {
00075     while( !it.IsAtEndOfSlice() )
00076     {
00077       while( !it.IsAtEndOfLine() )
00078       {
00079         index = it.GetIndex();
00080         it.Set( index );
00081         ++it;
00082       }
00083       it.NextLine();
00084     }
00085     it.NextSlice();
00086   }
00087 
00088   { 
00089   // Verification 
00090   std::cout << "Verifying for iterator...";
00091   IteratorType ot( myImage, region );
00092 
00093   ot.GoToBegin();
00094   ot.SetFirstDirection( 0 ); // 0=x, 1=y, 2=z
00095   ot.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00096  
00097   while( !ot.IsAtEnd() )
00098   {
00099     while( !ot.IsAtEndOfSlice() )
00100     {
00101       while( !ot.IsAtEndOfLine() )
00102       {
00103         index = ot.GetIndex();
00104         if( ot.Get() != index )
00105         {
00106           std::cerr << "Values don't correspond to what was stored "
00107             << std::endl;
00108           std::cerr << "Test failed at index ";
00109           std::cerr << index << std::endl;
00110           std::cerr << "It should be ";
00111           std::cerr << ot.Get() << std::endl;
00112           return EXIT_FAILURE;
00113         }
00114         ++ot;
00115       }
00116       ot.NextLine();
00117     }
00118     ot.NextSlice();
00119   }
00120   std::cout << "  Done !" << std::endl;
00121 
00122 
00123   // Verification 
00124   std::cout << "Verifying for const iterator...";
00125   ConstIteratorType cot( myImage, region );
00126 
00127   cot.GoToBegin();
00128   cot.SetFirstDirection( 0 ); // 0=x, 1=y, 2=z
00129   cot.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00130  
00131   while( !cot.IsAtEnd() )
00132   {
00133     while( !cot.IsAtEndOfSlice() )
00134     {
00135       while( !cot.IsAtEndOfLine() )
00136       {
00137         index = cot.GetIndex();
00138         if( cot.Get() != index )
00139         {
00140           std::cerr << "Values don't correspond to what was stored "
00141             << std::endl;
00142           std::cerr << "Test failed at index ";
00143           std::cerr << index << std::endl;
00144           std::cerr << "It should be ";
00145           std::cerr << cot.Get() << std::endl;
00146           return EXIT_FAILURE;
00147         }
00148         ++cot;
00149       }
00150       cot.NextLine();
00151     }
00152     cot.NextSlice();
00153   }
00154   std::cout << "  Done !" << std::endl;
00155 
00156 
00157 
00158 
00159   // Verification 
00160   std::cout << "Verifying iterator in reverse direction... ";
00161 
00162   IteratorType ior( myImage, region );
00163 
00164   ior.GoToReverseBegin();
00165   ior.SetFirstDirection( 0 );  // 0=x, 1=y, 2=z
00166   ior.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00167  
00168   while( !ior.IsAtReverseEnd() )
00169   {
00170     while( !ior.IsAtReverseEndOfSlice() )
00171     {
00172       while( !ior.IsAtReverseEndOfLine() )
00173       {
00174         index = ior.GetIndex();
00175         if( ior.Get() != index )
00176         {
00177           std::cerr << "Values don't correspond to what was stored "
00178             << std::endl;
00179           std::cerr << "Test failed at index ";
00180           std::cerr << index << " value is " << ior.Get() <<  std::endl;
00181           return EXIT_FAILURE;
00182         }
00183         --ior;
00184       }
00185       ior.PreviousLine();
00186     }
00187     ior.PreviousSlice();
00188   }
00189 
00190   std::cout << "   Done ! " << std::endl;
00191 
00192 
00193 
00194   // Verification 
00195   std::cout << "Verifying const iterator in reverse direction... ";
00196 
00197   ConstIteratorType cor( myImage, region );
00198 
00199   cor.GoToReverseBegin();
00200   cor.SetFirstDirection( 0 );  // 0=x, 1=y, 2=z
00201   cor.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00202  
00203   while( !cor.IsAtReverseEnd() )
00204   {
00205     while( !cor.IsAtReverseEndOfSlice() )
00206     {
00207       while( !cor.IsAtReverseEndOfLine() )
00208       {
00209         index = cor.GetIndex();
00210         if( cor.Get() != index )
00211         {
00212           std::cerr << "Values don't correspond to what was stored "
00213             << std::endl;
00214           std::cerr << "Test failed at index ";
00215           std::cerr << index << " value is " << cor.Get() <<  std::endl;
00216           return EXIT_FAILURE;
00217         }
00218         --cor;
00219       }
00220       cor.PreviousLine();
00221     }
00222     cor.PreviousSlice();
00223   }
00224   std::cout << "   Done ! " << std::endl;
00225 
00226   }
00227 
00228   { 
00229   // Verification 
00230   std::cout << "Test in a region < LargestPossibleRegion" << std::endl;
00231   std::cout << "Verifying for iterator...";
00232 
00233   size[0]  = 50;
00234   size[1]  = 50;
00235   size[2]  = 50;
00236 
00237   start[0] = 25;
00238   start[1] = 25;
00239   start[2] = 25;
00240 
00241   region.SetIndex( start );
00242   region.SetSize( size );
00243 
00244   IteratorType ot( myImage, region );
00245 
00246   ot.GoToBegin();
00247   ot.SetFirstDirection( 0 ); // 0=x, 1=y, 2=z
00248   ot.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00249  
00250   while( !ot.IsAtEnd() )
00251   {
00252     while( !ot.IsAtEndOfSlice() )
00253     {
00254       while( !ot.IsAtEndOfLine() )
00255       {
00256         index = ot.GetIndex();
00257         if( ot.Get() != index )
00258         {
00259           std::cerr << "Values don't correspond to what was stored "
00260             << std::endl;
00261           std::cerr << "Test failed at index ";
00262           std::cerr << index << std::endl;
00263           std::cerr << "It should be ";
00264           std::cerr << ot.Get() << std::endl;
00265           return EXIT_FAILURE;
00266         }
00267         ++ot;
00268       }
00269       ot.NextLine();
00270     }
00271     ot.NextSlice();
00272   }
00273   std::cout << "  Done !" << std::endl;
00274 
00275 
00276   // Verification 
00277   std::cout << "Verifying for const iterator...";
00278   ConstIteratorType cot( myImage, region );
00279 
00280   cot.GoToBegin();
00281   cot.SetFirstDirection( 0 ); // 0=x, 1=y, 2=z
00282   cot.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00283  
00284   while( !cot.IsAtEnd() )
00285   {
00286     while( !cot.IsAtEndOfSlice() )
00287     {
00288       while( !cot.IsAtEndOfLine() )
00289       {
00290         index = cot.GetIndex();
00291         if( cot.Get() != index )
00292         {
00293           std::cerr << "Values don't correspond to what was stored "
00294             << std::endl;
00295           std::cerr << "Test failed at index ";
00296           std::cerr << index << std::endl;
00297           std::cerr << "It should be ";
00298           std::cerr << cot.Get() << std::endl;
00299           return EXIT_FAILURE;
00300         }
00301         ++cot;
00302       }
00303       cot.NextLine();
00304     }
00305     cot.NextSlice();
00306   }
00307   std::cout << "  Done !" << std::endl;
00308 
00309 
00310 
00311 
00312   // Verification 
00313   std::cout << "Verifying iterator in reverse direction... ";
00314 
00315   IteratorType ior( myImage, region );
00316 
00317   ior.GoToReverseBegin();
00318   ior.SetFirstDirection( 0 );  // 0=x, 1=y, 2=z
00319   ior.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00320  
00321   while( !ior.IsAtReverseEnd() )
00322   {
00323     while( !ior.IsAtReverseEndOfSlice() )
00324     {
00325       while( !ior.IsAtReverseEndOfLine() )
00326       {
00327         index = ior.GetIndex();
00328         if( ior.Get() != index )
00329         {
00330           std::cerr << "Values don't correspond to what was stored "
00331             << std::endl;
00332           std::cerr << "Test failed at index ";
00333           std::cerr << index << " value is " << ior.Get() <<  std::endl;
00334           return EXIT_FAILURE;
00335         }
00336         --ior;
00337       }
00338       ior.PreviousLine();
00339     }
00340     ior.PreviousSlice();
00341   }
00342 
00343   std::cout << "   Done ! " << std::endl;
00344 
00345 
00346 
00347   // Verification 
00348   std::cout << "Verifying const iterator in reverse direction... ";
00349 
00350   ConstIteratorType cor( myImage, region );
00351 
00352   cor.GoToReverseBegin();
00353   cor.SetFirstDirection( 0 );  // 0=x, 1=y, 2=z
00354   cor.SetSecondDirection( 1 ); // 0=x, 1=y, 2=z
00355  
00356   while( !cor.IsAtReverseEnd() )
00357   {
00358     while( !cor.IsAtReverseEndOfSlice() )
00359     {
00360       while( !cor.IsAtReverseEndOfLine() )
00361       {
00362         index = cor.GetIndex();
00363         if( cor.Get() != index )
00364         {
00365           std::cerr << "Values don't correspond to what was stored "
00366             << std::endl;
00367           std::cerr << "Test failed at index ";
00368           std::cerr << index << " value is " << cor.Get() <<  std::endl;
00369           return EXIT_FAILURE;
00370         }
00371         --cor;
00372       }
00373       cor.PreviousLine();
00374     }
00375     cor.PreviousSlice();
00376   }
00377   std::cout << "   Done ! " << std::endl;
00378 
00379   }
00380 
00381 
00382 
00383   std::cout << "Test passed" << std::endl;
00384 
00385   return EXIT_SUCCESS;
00386 
00387 }
00388 
00389 
00390 

Generated at Sun Mar 11 23:25:27 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000