#include <cstdlib>
#include <cstdio>
int
main(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << std::endl;
std::cerr << " <OutputFileName>" << std::endl;
return EXIT_FAILURE;
}
const char * out_file_name = argv[1];
index[0] = 0;
index[1] = 0;
size[0] = 100;
size[1] = 100;
region.SetSize(size);
indexA[0] = 9;
indexA[1] = 9;
sizeA[0] = 50;
sizeA[1] = 50;
regionA.SetSize(sizeA);
indexB[0] = 39;
indexB[1] = 39;
sizeB[0] = 50;
sizeB[1] = 50;
regionB.SetSize(sizeB);
regionC.PadByRadius(10);
RGBPixelType pix_black;
pix_black.Fill(0);
RGBPixelType pix_red;
pix_red.Fill(0);
pix_red[0] = 255;
RGBPixelType pix_green;
pix_green.Fill(0);
pix_green[1] = 255;
RGBPixelType pix_blue;
pix_blue.Fill(0);
pix_blue[2] = 255;
RGBImageType::Pointer image = RGBImageType::New();
image->SetRegions(region);
image->Allocate();
image->FillBuffer(pix_black);
IteratorType itA(image, regionA);
itA.GoToBegin();
while (!itA.IsAtEnd())
{
itA.Set(itA.Get() + pix_red);
++itA;
}
IteratorType itB(image, regionB);
itB.GoToBegin();
while (!itB.IsAtEnd())
{
itB.Set(itB.Get() + pix_green);
++itB;
}
IteratorType itC(image, regionC);
itC.GoToBegin();
while (!itC.IsAtEnd())
{
itC.Set(itC.Get() + pix_blue);
++itC;
}
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName(out_file_name);
writer->SetInput(image);
try
{
writer->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}