int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile projectionDirection"
<< std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned short;
using SliceIteratorType =
try
{
inputImage = itk::ReadImage<ImageType3D>(argv[1]);
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
auto projectionDirection = static_cast<unsigned int>(std::stoi(argv[3]));
unsigned int i;
unsigned int j;
unsigned int direction[2];
for (i = 0, j = 0; i < 3; ++i)
{
if (i != projectionDirection)
{
direction[j] = i;
j++;
}
}
index[direction[0]] = requestedRegion.
GetIndex()[direction[0]];
index[1 - direction[0]] = requestedRegion.
GetIndex()[direction[1]];
size[direction[0]] = requestedRegion.GetSize()[direction[0]];
size[1 - direction[0]] = requestedRegion.GetSize()[direction[1]];
region.SetSize(size);
region.SetIndex(index);
outputImage->SetRegions(region);
outputImage->Allocate();
SliceIteratorType inputIt(inputImage, inputImage->GetRequestedRegion());
LinearIteratorType outputIt(outputImage, outputImage->GetRequestedRegion());
inputIt.SetFirstDirection(direction[1]);
inputIt.SetSecondDirection(direction[0]);
outputIt.SetDirection(1 - direction[0]);
outputIt.GoToBegin();
while (!outputIt.IsAtEnd())
{
while (!outputIt.IsAtEndOfLine())
{
++outputIt;
}
outputIt.NextLine();
}
inputIt.GoToBegin();
outputIt.GoToBegin();
while (!inputIt.IsAtEnd())
{
while (!inputIt.IsAtEndOfSlice())
{
while (!inputIt.IsAtEndOfLine())
{
outputIt.Set(std::max(outputIt.Get(), inputIt.Get()));
++inputIt;
++outputIt;
}
outputIt.NextLine();
inputIt.NextLine();
}
outputIt.GoToBegin();
inputIt.NextSlice();
}
try
{
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}