#include <iostream>
template <class T, unsigned int VImageDimension>
{
T vec;
vec[0] = 5;
vec[1] = 4;
vec[2] = 3;
vec[3] = 2;
vec[4] = 1;
out[regionStartIndex3D] = vec;
out[regionEndIndex3D] = in[regionStartIndex3D];
}
int itkImageIteratorTest(int, char* [] )
{
const unsigned int ImageDimension = 3;
std::cout << "Creating an image" << std::endl;
float origin3D[ImageDimension] = { 5, 2.1, 8.1};
float spacing3D[ImageDimension] = { 1.5, 2.1, 1};
region.SetSize(imageSize3D);
region.SetIndex(startIndex3D);
std::cout << "Setting/Getting a pixel" << std::endl;
vec[0] = 5;
vec[1] = 4;
vec[2] = 3;
vec[3] = 2;
vec[4] = 1;
(*o3)[regionStartIndex3D] = vec;
(*o3)[regionEndIndex3D] = (*o3)[regionStartIndex3D];
TestConstPixelAccess(*o3, *o3);
VectorImageIterator itr1( o3, region );
VectorImageConstIterator itr2( o3, region );
VectorImageIterator itr3( itr1 );
VectorImageIterator itr4;
itr4 = itr1;
if( itr4 != itr1 )
{
std::cerr << "Error in operator= or operator!=" << std::endl;
return EXIT_FAILURE;
}
if( !( itr4 == itr1 ) )
{
std::cerr << "Error in operator= or operator==" << std::endl;
return EXIT_FAILURE;
}
if( !( itr4 <= itr1 ) )
{
std::cerr << "Error in operator= or operator<=" << std::endl;
return EXIT_FAILURE;
}
if( itr4 < itr1 )
{
std::cerr << "Error in operator= or operator<" << std::endl;
return EXIT_FAILURE;
}
if( !( itr4 >= itr1 ) )
{
std::cerr << "Error in operator= or operator>=" << std::endl;
return EXIT_FAILURE;
}
if( itr4 > itr1 )
{
std::cerr << "Error in operator= or operator>" << std::endl;
return EXIT_FAILURE;
}
if( itr1.GetImageIteratorDimension() != ImageDimension )
{
std::cerr << "Error in GetImageIteratorDimension" << std::endl;
return EXIT_FAILURE;
}
VectorImageType::IndexType index1 = itr1.GetIndex();
if( index1 != startIndex3D )
{
std::cerr << "Error in GetIndex()" << std::endl;
return EXIT_FAILURE;
}
VectorImageType::IndexType index2 = index1;
index2[0]++;
VectorImageIterator itr5 = itr1;
itr5.SetIndex( index2 );
if( itr5.GetIndex() != index2 )
{
std::cerr << "Error in GetIndex() and/or SetIndex()" << std::endl;
return EXIT_FAILURE;
}
if( itr5.GetIndex() == itr1.GetIndex() )
{
std::cerr << "Error in GetIndex() and/or SetIndex()" << std::endl;
return EXIT_FAILURE;
}
VectorImageType::RegionType region1 = itr1.GetRegion();
if( region1 != region )
{
std::cerr << "Error in GetRegion()" << std::endl;
return EXIT_FAILURE;
}
VectorImageType * image1 = itr1.GetImage();
if( image1 != o3.GetPointer() )
{
std::cerr << "Error in GetImage()" << std::endl;
return EXIT_FAILURE;
}
const VectorImageType * image2 = itr2.GetImage();
if( image2 != o3.GetPointer() )
{
std::cerr << "Error in GetImage()" << std::endl;
return EXIT_FAILURE;
}
{
VectorPixelType vp1 = itr1.Get();
VectorPixelType vp2 = itr2.Get();
std::cout << "vp1: " << vp1 << std::endl;
std::cout << "vp2: " << vp2 << std::endl;
if( vp1 != vp2 )
{
std::cerr << "Error in Get()" << std::endl;
return EXIT_FAILURE;
}
vp1[0]++;
itr1.Set( vp1 );
vp2 = itr2.Get();
if( vp1 != vp2 )
{
std::cerr << "Error in Get() and/or Set()" << std::endl;
return EXIT_FAILURE;
}
}
{
VectorPixelType vp1 = itr1.Value();
VectorPixelType vp2 = itr2.Value();
if( vp1 != vp2 )
{
std::cerr << "Error in Value()" << std::endl;
return EXIT_FAILURE;
}
vp1[0]++;
itr1.Value() = vp1;
vp2 = itr2.Value();
if( vp1 != vp2 )
{
std::cerr << "Error in Get() and/or Set()" << std::endl;
return EXIT_FAILURE;
}
}
{
itr1.GoToBegin();
if( !itr1.IsAtBegin() )
{
std::cerr << "Error in Begin() and/or IsAtBegin()" << std::endl;
return EXIT_FAILURE;
}
if( itr1.IsAtEnd() )
{
std::cerr << "Error in Begin() and/or IsAtEnd()" << std::endl;
return EXIT_FAILURE;
}
}
{
itr1.GoToEnd();
if( !itr1.IsAtEnd() )
{
std::cerr << "Error in End() and/or IsAtEnd()" << std::endl;
return EXIT_FAILURE;
}
if( itr1.IsAtBegin() )
{
std::cerr << "Error in End() and/or IsAtBegin()" << std::endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}