#include "itkUnaryFunctorImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkThresholdImageFilter.h"
#include "itkMacro.h"
int main(
int argc,
char* argv[])
{
if (argc < 10)
{
std::cout << argv[0]
<< " output filename , pretty output filename , Longitude Output Origin point , Latitude Output Origin point , X Output Size, Y Output size , X "
"Spacing , Y Spacing, DEM folder path"
<< std::endl;
return EXIT_FAILURE;
}
char* folderPath = argv[9];
char* outputName = argv[1];
const unsigned int Dimension = 2;
DEMToImageGeneratorType::Pointer object = DEMToImageGeneratorType::New();
using SizeType = DEMToImageGeneratorType::SizeType;
using SpacingType = DEMToImageGeneratorType::SpacingType;
using PointType = DEMToImageGeneratorType::PointType;
WriterType::Pointer writer = WriterType::New();
PointType origin;
origin[0] = ::atof(argv[3]);
origin[1] = ::atof(argv[4]);
object->SetOutputOrigin(origin);
SizeType size;
size[0] = ::atoi(argv[5]);
size[1] = ::atoi(argv[6]);
object->SetOutputSize(size);
SpacingType spacing;
spacing[0] = ::atof(argv[7]);
spacing[1] = ::atof(argv[8]);
object->SetOutputSpacing(spacing);
writer->SetFileName(outputName);
writer->SetInput(object->GetOutput());
try
{
writer->Update();
}
catch (itk::ExceptionObject& err)
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch (...)
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
using RescalerType = itk::RescaleIntensityImageFilter<ImageType, OutputPrettyImageType>;
using ThresholderType = itk::ThresholdImageFilter<ImageType>;
ThresholderType::Pointer thresholder = ThresholderType::New();
RescalerType::Pointer rescaler = RescalerType::New();
WriterPrettyType::Pointer prettyWriter = WriterPrettyType::New();
thresholder->SetInput(object->GetOutput());
thresholder->SetOutsideValue(0.0);
thresholder->ThresholdBelow(0.0);
thresholder->Update();
rescaler->SetInput(thresholder->GetOutput());
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(255);
prettyWriter->SetFileName(argv[2]);
prettyWriter->SetInput(rescaler->GetOutput());
try
{
prettyWriter->Update();
}
catch (itk::ExceptionObject& excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
catch (...)
{
std::cout << "Unknown exception !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}