1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: itkNeighborhoodIteratorTest.cxx
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkNeighborhoodIteratorTestCommon.txx"
#include "itkNeighborhoodIterator.h"
int itkNeighborhoodIteratorTest(int, char* [] )
{
TestImageType::Pointer img = GetTestImage(10, 10, 5, 3);
itk::NeighborhoodIterator<TestImageType>::IndexType loc;
loc[0] = 4; loc[1] = 4; loc[2] = 2; loc[3] = 1;
itk::NeighborhoodIterator<TestImageType>::IndexType zeroIDX;
zeroIDX.Fill(0);
itk::NeighborhoodIterator<TestImageType>::RadiusType radius;
radius[0] = radius[1] = radius[2] = radius[3] = 1;
println("Creating NeighborhoodIterator");
itk::NeighborhoodIterator<TestImageType>
it(radius, img, img->GetRequestedRegion());
println("Moving iterator using Superclass::SetLocation()");
it.SetLocation(loc);
it.Print(std::cout);
println("Testing SetCenterPixel()");
it.SetCenterPixel(zeroIDX);
println("Testing SetPixel()");
it.SetPixel(6,zeroIDX);
println("Using Superclass::GetNeighborhood()");
itk::NeighborhoodIterator<TestImageType>::NeighborhoodType n
= it.GetNeighborhood();
println("Testing SetNeighborhood()");
it.SetNeighborhood(n);
it.GetNeighborhood().Print(std::cout);
println("Testing GetCenterPointer()");
std::cout << it.GetCenterPointer() << " = "
<< *(it.GetCenterPointer()) << std::endl;
println("Testing operator=");
it = itk::NeighborhoodIterator<TestImageType>(radius, img,
img->GetRequestedRegion());
println("Testing copy constructor");
itk::NeighborhoodIterator<TestImageType> it2(it);
it.Print(std::cout);
it2.Print(std::cout);
println("Creating 5x5x1x1 neighborhood");
radius[0] = 2; radius[1] = 2; radius[2] = 0; radius[3] = 0;
itk::NeighborhoodIterator<TestImageType> it3(radius, img, img->GetRequestedRegion());
println("Moving to location 2, 2, 0, 0");
loc[0] = 2; loc[1] = 2; loc[2] = 0; loc[3] = 0;
it3.SetLocation(loc);
it3.Print(std::cout);
unsigned x, y, i;
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetNext(0, 2, [0,0,0,0])");
itk::NeighborhoodIterator<TestImageType>::PixelType z;
z[0] = 0; z[1] = 0; z[2] = 0; z[3] = 0;
it3.SetNext(0,2,z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetNext(1, 2, [0,0,0,0])");
it3.SetNext(1,2,z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetNext(0, [0,0,0,0])");
it3.SetNext(0, z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetNext(1, [0,0,0,0])");
it3.SetNext(1, z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetPrevious(0, 2, [0,0,0,0])");
it3.SetPrevious(0,2,z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetPrevious(1, 2, [0,0,0,0])");
it3.SetPrevious(1,2,z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetPrevious(0, [0,0,0,0])");
it3.SetPrevious(0, z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetPrevious(1, [0,0,0,0])");
it3.SetPrevious(1, z);
for (y = 0, i=0; y < 5; y++)
{
for (x = 0; x < 5; x++, i++)
{
std::cout << it3.GetPixel(i) << " ";
}
std::cout << std::endl;
}
println("Testing SetPixel methods");
bool raised = false;
try
{
it3.GoToBegin();
it3.SetPixel( it.Size()/2, z); // in bounds
it3.SetPixel( 0, z); // out of bounds, should throw an exception
}
catch(itk::ExceptionObject &e)
{
std::cout << e << std::endl;
raised = true;
}
if( !raised )
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|