Skip to content
Snippets Groups Projects
Commit 2247d46c authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH : some checks on the input image filename, and catch exception when input file is not readable

parent 2c8bb3a7
Branches
Tags
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
=========================================================================*/ =========================================================================*/
#include "otbWrapperInputImageParameter.h" #include "otbWrapperInputImageParameter.h"
#include "itksys/SystemTools.hxx"
namespace otb namespace otb
{ {
...@@ -35,13 +36,29 @@ InputImageParameter::~InputImageParameter() ...@@ -35,13 +36,29 @@ InputImageParameter::~InputImageParameter()
void void
InputImageParameter::SetFromFileName(const std::string& filename) InputImageParameter::SetFromFileName(const std::string& filename)
{ {
ImageFileReaderType::Pointer reader = ImageFileReaderType::New(); // First clear previous file choosen
reader->SetFileName(filename); this->ClearValue();
reader->UpdateOutputInformation();
// everything went fine, store the object references // TODO : when the logger will be available, redirect the exception
m_Reader = reader; // in the logger (like what is done in MsgReporter)
m_Image = reader->GetOutput(); if (!filename.empty()
&& itksys::SystemTools::FileExists(filename.c_str()))
{
ImageFileReaderType::Pointer reader = ImageFileReaderType::New();
reader->SetFileName(filename);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject & err)
{
this->ClearValue();
}
// everything went fine, store the object references
m_Reader = reader;
m_Image = reader->GetOutput();
}
} }
std::string std::string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment