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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkLineIteratorTest.cxx,v $
Language: C++
Date: $Date: 2007-08-20 13:00:21 $
Version: $Revision: 1.5 $
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
// Testcode for the itk::LineIterator.
#include <iostream>
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkLineIterator.h"
#include "itkTimeProbe.h"
int itkLineIteratorTest(int argc, char*argv[])
{
const int Dimension = 2;
typedef unsigned char PixelType;
typedef itk::Image<PixelType, Dimension> ImageType;
typedef ImageType::RegionType::IndexType IndexType;
typedef IndexType::IndexValueType IndexValueType;
if (argc < 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " outputfilename" << std::endl;
return EXIT_FAILURE;
}
// Set up a test image
ImageType::RegionType::IndexType index;
index.Fill(0);
ImageType::RegionType::SizeType size;
size.Fill(200);
ImageType::RegionType region;
region.SetIndex(index);
region.SetSize(size);
ImageType::Pointer output = ImageType::New();
output->SetRegions(region);
output->Allocate();
output->FillBuffer(0);
// First test: empty line
IndexType startIndex;
IndexType endIndex;
startIndex[0] = 11;
startIndex[1] = 13;
endIndex[0] = 11;
endIndex[1] = 13;
typedef itk::LineIterator<ImageType> LineIteratorType;
LineIteratorType across(output, startIndex, endIndex);
// First test: currentIndex initialization
if (startIndex != across.GetIndex())
{
std::cerr << "Error! Index should be startIndex.\n";
return EXIT_FAILURE;
}
// Second test: IsAtEnd() is one pixel past the endIndex
if (across.IsAtEnd())
{
std::cerr << "Error! Iterator should not be at end.\n";
return EXIT_FAILURE;
}
++across;
if (!across.IsAtEnd())
{
std::cerr << "Error! Iterator should be at end.\n";
return EXIT_FAILURE;
}
// Third test: draw some lines.
itk::TimeProbe timer;
timer.Start();
startIndex.Fill(10);
endIndex.Fill(189);
LineIteratorType it(output, startIndex, endIndex);
while (!it.IsAtEnd())
{
it.Set(255);
++it;
}
startIndex.Fill(50);
endIndex[0] = 150;
endIndex[1] = startIndex[1];
it = LineIteratorType(output, startIndex, endIndex);
while (!it.IsAtEnd())
{
it.Set(150);
++it;
}
startIndex.Fill(120);
endIndex[0] = 50;
endIndex[1] = 100;
it = LineIteratorType(output, startIndex, endIndex);
while (!it.IsAtEnd())
{
it.Set(150);
++it;
}
timer.Stop();
std::cerr << "Line drawing took " << timer.GetMeanTime() << " seconds.\n";
typedef itk::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(output);
writer->SetFileName(argv[1]);
writer->Update();
return EXIT_SUCCESS;
}
|