diff --git a/Code/IO/otbImageSeriesFileReader.txx b/Code/IO/otbImageSeriesFileReader.txx index b9642131a562ae643318e97ed78944966ec180be..2f0ab0dc2ea5ef78de84185c8ef5ae7c7605e901 100644 --- a/Code/IO/otbImageSeriesFileReader.txx +++ b/Code/IO/otbImageSeriesFileReader.txx @@ -20,7 +20,6 @@ #ifndef __otbImageSeriesFileReader__txx #define __otbImageSeriesFileReader__txx - #include "otbImageSeriesFileReader.h" namespace otb { @@ -50,11 +49,11 @@ void ImageSeriesFileReader< TImage, TInternalImage > ::GenerateData( unsigned int idx ) { - itk::OStringStream msg; - msg << "Something wrong... Check the template definition of this class in the program...\n"; - msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; - ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); - throw e; + itk::OStringStream msg; + msg << "Something wrong... Check the template definition of this class in the program...\n"; + msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; + ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); + throw e; } /* ********************************************************** @@ -122,8 +121,6 @@ void ImageSeriesFileReader< Image< TPixel, 2 >, Image< TInternalPixel, 2 > > ::GenerateData( unsigned int idx ) { - std::cerr << "Reading " << idx << "th image: " << this->m_ListOfFileNames[ idx ] << "\n"; - otbMsgDebugMacro( << "Reading " << idx << "th image: " << this->m_ListOfFileNames[ idx ] ); ReaderType * reader @@ -186,15 +183,15 @@ void ImageSeriesFileReader< Image< TPixel, 2 >, VectorImage< TInternalPixel, 2 > > ::TestBandSelection ( std::vector<unsigned int> & bands ) { - if ( bands.size() != 1 ) - { - itk::OStringStream msg; - msg << "Unable to handle multicomponent file from Image<> class as output\n"; - msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; - ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); - throw e; - } - return; + if ( bands.size() != 1 ) + { + itk::OStringStream msg; + msg << "Unable to handle multicomponent file from Image<> class as output\n"; + msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n"; + ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); + throw e; + } + return; } /** @@ -276,14 +273,14 @@ ImageSeriesFileReader< VectorImage< TPixel, 2 >, VectorImage< TInternalPixel, 2 ExtractSelectionType * selection = static_cast<ExtractSelectionType*>( this->m_ExtractorList->GetNthElement( idx ) ); - selection->SetExtractionRegion( this->m_ListOfRegionSelection[ idx ] ); + selection->SetExtractionRegion( this->m_ListOfRegionSelection[ idx ] ); - for ( std::vector<unsigned int>::iterator band = this->m_ListOfBandSelection[ idx ].begin(); - band != this->m_ListOfBandSelection[ idx ].end(); - ++band ) - { - selection->SetChannel( *band ); - } + for ( std::vector<unsigned int>::iterator band = this->m_ListOfBandSelection[ idx ].begin(); + band != this->m_ListOfBandSelection[ idx ].end(); + ++band ) + { + selection->SetChannel( *band ); + } selection->SetInput( reader->GetOutput() ); selection->GraftOutput( this->m_OutputList->GetNthElement( idx ) ); diff --git a/Code/IO/otbImageSeriesFileReaderBase.txx b/Code/IO/otbImageSeriesFileReaderBase.txx index 1e4ec13a166ffdcaca3f34c40bf3347c161fed24..6a007144ce6fb59677ca948257ab154f0503819a 100644 --- a/Code/IO/otbImageSeriesFileReaderBase.txx +++ b/Code/IO/otbImageSeriesFileReaderBase.txx @@ -20,7 +20,6 @@ #ifndef __otbImageSeriesFileReaderBase__txx #define __otbImageSeriesFileReaderBase__txx - #include "otbImageSeriesFileReaderBase.h" namespace otb { @@ -71,7 +70,7 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > ::GetOutput () { if ( this->GetNumberOfOutputs() < 1 ) - return 0; + throw ImageSeriesFileReaderException (__FILE__, __LINE__,"No data to output",ITK_LOCATION); return static_cast<OutputImageListType*>( this->m_OutputList ); } @@ -82,10 +81,10 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > ::GetOutput ( unsigned int idx ) { if ( this->GetNumberOfOutputs() < 1 ) - return 0; + throw ImageSeriesFileReaderException (__FILE__, __LINE__,"No data to output",ITK_LOCATION); if ( idx >= m_OutputList->Size() ) - return 0; + throw ImageSeriesFileReaderException (__FILE__, __LINE__,"Index out of bounds",ITK_LOCATION); return static_cast<OutputImageType*>( this->m_OutputList->GetNthElement( idx ) ); } @@ -104,9 +103,9 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > std::string aLine; std::ifstream inputFile ( m_FileName.c_str(), std::ios_base::in ); - inputFile >> aLine; - if ( aLine != "ENVI" ) - { + inputFile >> aLine; + if ( aLine != "ENVI" ) + { inputFile.close(); itk::OStringStream msg; msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n"; @@ -116,8 +115,8 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > } inputFile >> aLine; - if ( aLine != "META" ) - { + if ( aLine != "META" ) + { inputFile.close(); itk::OStringStream msg; msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n"; @@ -138,16 +137,16 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > } while ( 1 ) - { + { /* * Reading the filenames */ do { - inputFile >> aLine; - //std::cerr << "-> '" << aLine << "'\n"; - } while ( aLine != "File" && inputFile.good() ); + inputFile >> aLine; + //std::cerr << "-> '" << aLine << "'\n"; + } while ( aLine != "File" && inputFile.good() ); - if ( inputFile.good() ) + if ( inputFile.good() ) { do { inputFile >> aLine; @@ -183,9 +182,9 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > * Reading the Band number */ do { - inputFile >> aLine; - //std::cerr << "-> '" << aLine << "'\n"; - } while ( aLine != "Bands:" && inputFile.good() ); + inputFile >> aLine; + //std::cerr << "-> '" << aLine << "'\n"; + } while ( aLine != "Bands:" && inputFile.good() ); if ( !inputFile.good() ) { @@ -227,28 +226,28 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > } // Storing band selection - try { - TestBandSelection( bands ); - } - catch ( ImageSeriesFileReaderException & e ) - { - itk::OStringStream msg; - msg << e.GetDescription(); - msg << "Image FileName : " << imageFileName << "\n"; - e.SetDescription( msg.str().c_str() ); - throw e; - } - m_ListOfBandSelection.push_back( bands ); + try { + TestBandSelection( bands ); + } + catch ( ImageSeriesFileReaderException & e ) + { + itk::OStringStream msg; + msg << e.GetDescription(); + msg << "Image FileName : " << imageFileName << "\n"; + e.SetDescription( msg.str().c_str() ); + throw e; + } + m_ListOfBandSelection.push_back( bands ); /* * Reading the Region selection */ do { - inputFile >> aLine; - //std::cerr << "-> '" << aLine << "'\n"; - } while ( aLine != "Dims" && inputFile.good() ); + inputFile >> aLine; + //std::cerr << "-> '" << aLine << "'\n"; + } while ( aLine != "Dims" && inputFile.good() ); - if ( inputFile.good() ) + if ( inputFile.good() ) { do { inputFile >> aLine; @@ -320,11 +319,11 @@ void ImageSeriesFileReaderBase< TImage, TInternalImage > ::GenerateData( unsigned int idx ) { - itk::OStringStream msg; - msg << "Something wrong... Check the template definition of this class in the program...\n"; - msg << "\"ENVI META FILE\" FileName: " << m_FileName << "\n"; - ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); - throw e; + itk::OStringStream msg; + msg << "Something wrong... Check the template definition of this class in the program...\n"; + msg << "\"ENVI META FILE\" FileName: " << m_FileName << "\n"; + ImageSeriesFileReaderException e(__FILE__, __LINE__,msg.str().c_str(),ITK_LOCATION); + throw e; } template < class TImage, class TInternalImage > @@ -344,8 +343,8 @@ typename ImageSeriesFileReaderBase< TImage, TInternalImage >::OutputImageListTyp ImageSeriesFileReaderBase< TImage, TInternalImage > ::GenerateOutput() { - this->Update(); - return this->GetOutput(); + this->Update(); + return this->GetOutput(); } template < class TImage, class TInternalImage > @@ -353,8 +352,8 @@ typename ImageSeriesFileReaderBase< TImage, TInternalImage >::OutputImageType * ImageSeriesFileReaderBase< TImage, TInternalImage > ::GenerateOutput( unsigned int idx ) { - this->GenerateData( idx ); - return this->GetOutput( idx ); + this->GenerateData( idx ); + return this->GetOutput( idx ); } @@ -368,7 +367,7 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > if ( m_ListOfFileNames.size() > 0 ) { - std::vector< std::vector< unsigned int > >::const_iterator bandSelection = m_ListOfBandSelection.begin(); + std::vector< std::vector< unsigned int > >::const_iterator bandSelection = m_ListOfBandSelection.begin(); os << indent << "Image File(s) to be read\n"; for ( unsigned int i = 0; i < GetNumberOfOutputs(); ++i ) { @@ -388,7 +387,7 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > } os << "\n"; - ++bandSelection; + ++bandSelection; } } } @@ -416,13 +415,13 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > } else { - std::vector< std::string > fullPath; + std::vector< std::string > fullPath; fullPath.push_back( itksys::SystemTools::GetFilenamePath( m_FileName ) ); fullPath.push_back( "/" ); fullPath.push_back( file ); - std::string fullFileName = itksys::SystemTools::JoinPath( fullPath ); - + std::string fullFileName = itksys::SystemTools::JoinPath( fullPath ); + if ( !itksys::SystemTools::FileExists( fullFileName.c_str() ) ) { ImageSeriesFileReaderException e(__FILE__, __LINE__); @@ -438,7 +437,7 @@ ImageSeriesFileReaderBase< TImage, TInternalImage > else { // At this step, image file name is modified to add its path - file = fullFileName; + file = fullFileName; } } }