#include "vnl/vnl_math.h"
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;
}
typedef unsigned short PixelType;
> SliceIteratorType;
ImageType3D::ConstPointer inputImage;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
inputImage = reader->GetOutput();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
unsigned int projectionDirection =
static_cast<unsigned int>( ::atoi( argv[3] ) );
unsigned int i, j;
unsigned int direction[2];
for (i = 0, j = 0; i < 3; ++i )
{
if (i != projectionDirection)
{
direction[j] = i;
j++;
}
}
ImageType2D::RegionType region;
ImageType2D::RegionType::SizeType size;
ImageType2D::RegionType::IndexType index;
ImageType3D::RegionType requestedRegion = inputImage->GetRequestedRegion();
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 );
ImageType2D::Pointer outputImage = ImageType2D::New();
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( vnl_math_max( outputIt.Get(), inputIt.Get() ));
++inputIt;
++outputIt;
}
outputIt.NextLine();
inputIt.NextLine();
}
outputIt.GoToBegin();
inputIt.NextSlice();
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput(outputImage);
try
{
writer->Update();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}