diff --git a/Code/IO/otbImageFileReader.h b/Code/IO/otbImageFileReader.h index d432b063eb823ea062a5f87fee9799681185832b..656db4d7cf71adcff8fa8391f0f2c3fd5da823db 100644 --- a/Code/IO/otbImageFileReader.h +++ b/Code/IO/otbImageFileReader.h @@ -61,6 +61,15 @@ public: /** The pixel type of the output image. */ //typedef typename TOutputImage::InternalPixelType OutputImagePixelType; + /** The reading option structure. */ + struct readerOptions + { + std::string fileName; + std::string extGEOMFileName; + unsigned int subDatasetIndex; + unsigned int resolutionFactor; + }; + /** Prepare image allocation at the first call of the pipeline processing */ virtual void GenerateOutputInformation(void); @@ -74,27 +83,17 @@ public: * enlarge the RequestedRegion to the size of the image on disk. */ virtual void EnlargeOutputRequestedRegion(itk::DataObject *output); - /** Set/Get the additional index to extract (starting at 0) - * used - * in the case of image file containing multiple datasets (Modis hdf files for example) - * or - * in the case of JPEG2000 image file containing multiple resolution - * */ - itkSetMacro(AdditionalNumber, unsigned int); - itkGetMacro(AdditionalNumber, unsigned int); - itkSetObjectMacro(Curl, CurlHelperInterface); - itkSetMacro(ExtGEOMFilename, std::string); - itkGetMacro(ExtGEOMFilename, std::string); + virtual void SetFileName(const char* extendedFileName); + virtual void SetFileName(std::string extendedFileName); + virtual const char* GetFileName () const; protected: ImageFileReader(); virtual ~ImageFileReader(); void PrintSelf(std::ostream& os, itk::Indent indent) const; - unsigned int m_AdditionalNumber; - private: /** Test whether the given filename exist and it is readable, this is intended to be called before attempting to use @@ -111,8 +110,11 @@ private: ImageFileReader(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented - std::string m_ExceptionMessage; - std::string m_ExtGEOMFilename; + std::string m_ExceptionMessage; + + std::string m_ExtendedFilename; + readerOptions m_Options; + CurlHelperInterface::Pointer m_Curl; }; diff --git a/Code/IO/otbImageFileReader.txx b/Code/IO/otbImageFileReader.txx index 86c14c99e19ddae6546d18168cb0715f4adbd0c1..f778211a5e771fef80ad7172136a5cfafe87d654 100644 --- a/Code/IO/otbImageFileReader.txx +++ b/Code/IO/otbImageFileReader.txx @@ -35,6 +35,8 @@ #include "otbTileMapImageIO.h" //FIXME avoid requiring TileMapImageIO here #include "otbCurlHelper.h" +#include <boost/algorithm/string.hpp> + namespace otb { @@ -51,9 +53,15 @@ bool PixelIsComplex(const T& /*dummy*/) template <class TOutputImage> ImageFileReader<TOutputImage> -::ImageFileReader() : itk::ImageFileReader<TOutputImage>(), m_AdditionalNumber(0) +::ImageFileReader() : itk::ImageFileReader<TOutputImage>() { m_Curl = CurlHelper::New(); + + // Reader options + m_Options.fileName = ""; + m_Options.extGEOMFileName = ""; + m_Options.subDatasetIndex = 0; + m_Options.resolutionFactor = 0; } template <class TOutputImage> @@ -299,14 +307,14 @@ ImageFileReader<TOutputImage> imageIO->SetIsVectorImage(false); // Pass the dataset number (used for hdf files for example) - imageIO->SetDatasetNumber(m_AdditionalNumber); + imageIO->SetDatasetNumber(m_Options.subDatasetIndex); } // Special actions for the JPEG2000ImageIO if( strcmp(this->m_ImageIO->GetNameOfClass(), "JPEG2000ImageIO") == 0 ) { itk::EncapsulateMetaData<unsigned int>(dict, - MetaDataKey::ResolutionFactor, m_AdditionalNumber); + MetaDataKey::ResolutionFactor, m_Options.resolutionFactor); itk::EncapsulateMetaData<unsigned int>(dict, MetaDataKey::CacheSizeInBytes, 135000000); } @@ -376,14 +384,14 @@ ImageFileReader<TOutputImage> // Update otb Keywordlist ImageKeywordlist otb_kwl; - if (m_ExtGEOMFilename == "") + if (m_Options.extGEOMFileName == "") { otb_kwl = ReadGeometryFromImage(lFileNameOssimKeywordlist); otbMsgDevMacro(<< "Loading internal kwl"); } else { - otb_kwl = ReadGeometryFromGEOMFile(m_ExtGEOMFilename); + otb_kwl = ReadGeometryFromGEOMFile(m_Options.extGEOMFileName); otbMsgDevMacro(<< "Loading external kwl"); } @@ -480,19 +488,6 @@ ImageFileReader<TOutputImage> return; } - // Test if we have a file with an additional information specified - // (used for hdf dataset or jpeg2000 resolution) - std::string realfile(this->m_FileName); - unsigned int addNum; - if (System::ParseFileNameForAdditonalInfo(this->m_FileName, realfile, addNum)) - { - otbMsgDevMacro(<< "Filename with additinal information specification detected"); - otbMsgDevMacro(<< " - " << realfile); - otbMsgDevMacro(<< " - " << addNum); - this->m_FileName = realfile; - m_AdditionalNumber = addNum; - } - // Test if the file exists. if (!itksys::SystemTools::FileExists(this->m_FileName.c_str())) { @@ -589,6 +584,59 @@ ImageFileReader<TOutputImage> return (fic_trouve); } +template <class TOutputImage> +void +ImageFileReader<TOutputImage> +::SetFileName(std::string extendedFileName) +{ + this->SetFileName(extendedFileName.c_str()); +} + +template <class TOutputImage> +void +ImageFileReader<TOutputImage> +::SetFileName(const char* extendedFileName) +{ + this->m_ExtendedFilename = extendedFileName; + std::vector<std::string> main; + std::vector<std::string> ops; + std::map< std::string, std::string > map; + + // Retrieve file name + boost::split(main, m_ExtendedFilename, boost::is_any_of("?"), boost::token_compress_on); + + // Retrieve options + if (main.size()>1) + { + boost::split(ops, main[1], boost::is_any_of("&"), boost::token_compress_on); + + for (unsigned int i=0; i<ops.size(); i++) + { + std::vector<std::string> tmp; + boost::split(tmp, ops[i], boost::is_any_of("="), boost::token_compress_on); + if (tmp.size()>1) + { + map[tmp[0]]=tmp[1]; + } + } + } + + m_Options.fileName = main[0]; + m_Options.extGEOMFileName = map["geom"]; + m_Options.subDatasetIndex = atoi(map["sdataidx"].c_str()); + m_Options.resolutionFactor = atoi(map["resol"].c_str()); + + this->m_FileName = m_Options.fileName; +} + +template <class TOutputImage> +const char* +ImageFileReader<TOutputImage> +::GetFileName () const +{ +return this->m_ExtendedFilename.c_str(); +} + } //namespace otb #endif