diff --git a/Code/IO/otbImageFileReader.txx b/Code/IO/otbImageFileReader.txx index fd7f6177a31dd2360095040d768431280e2a58c2..62b5bc95ee56fd2e6bfcf5ff129426706c98dfcd 100644 --- a/Code/IO/otbImageFileReader.txx +++ b/Code/IO/otbImageFileReader.txx @@ -34,7 +34,9 @@ #include "base/ossimKeywordlist.h" // #include "ossim/projection/ossimProjectionFactoryRegistry.h" // #include "ossim/ossimPluginProjectionFactory.h" -#include "ossim/ossimPluginReaderFactory.h" +#include "projection/ossimProjection.h" +#include "projection/ossimProjectionFactoryRegistry.h" +#include "ossim/ossimPluginProjectionFactory.h" #include <itksys/SystemTools.hxx> #include <fstream> @@ -332,68 +334,70 @@ ImageFileReader<TOutputImage> output->SetDirection( direction ); // Set the image direction cosines // Trying to read ossim MetaData + bool hasMetaData = false; + ossimKeywordlist geom_kwl, tmp_kwl, tmp_kwl2;// = new ossimKeywordlist(); // Add the plugins factory - ossimImageHandlerRegistry::instance()->addFactory(ossimPluginReaderFactory::instance()); - - // Add the radar factory - ossimImageHandlerRegistry::instance()->addFactory(ossimImageHandlerSarFactory::instance()); - - - ossimImageHandler* handler = ossimImageHandlerRegistry::instance() - ->open(ossimFilename(lFileNameOssimKeywordlist.c_str())); - - if (!handler) + ossimProjectionFactoryRegistry::instance()->registerFactory(ossimPluginProjectionFactory::instance()); + ossimProjection * projection = ossimProjectionFactoryRegistry::instance() + ->createProjection(ossimFilename(lFileNameOssimKeywordlist.c_str()),0); + if (!projection) { - otbMsgDevMacro( <<"OSSIM Open Image FAILED ! "); + otbMsgDevMacro( <<"OSSIM Instanciate projection FAILED ! "); } - else { - otbMsgDevMacro( <<"OSSIM Open Image SUCCESS ! "); - ossimKeywordlist geom_kwl, tmp_kwl, tmp_kwl2;// = new ossimKeywordlist(); + otbMsgDevMacro( <<"OSSIM Instanciate projection SUCCESS ! "); + hasMetaData = projection->saveState(geom_kwl); + // Free memory + delete projection; + } + + if (!hasMetaData) + { + // Add the radar factory + ossimImageHandlerRegistry::instance()->addFactory(ossimImageHandlerSarFactory::instance()); + - // Read OSSIM Keyword List - bool hasMetaData = handler->getImageGeometry(geom_kwl); - if (!hasMetaData) + ossimImageHandler* handler = ossimImageHandlerRegistry::instance() + ->open(ossimFilename(lFileNameOssimKeywordlist.c_str())); + + if (!handler) { - otbMsgDebugMacro( <<"OSSIM MetaData not present ! "); + otbMsgDevMacro( <<"OSSIM Open Image FAILED ! "); } + else { - otbMsgDebugMacro( <<"OSSIM MetaData present ! "); - - // Update otb Keywordlist - ImageKeywordlist otb_kwl; - otb_kwl.SetKeywordlist( geom_kwl ); - - // Update itk MetaData Dictionnary -// otbMsgDebugMacro( <<"Start update ITK Dictionnary ? "); - - otb_kwl.convertToOSSIMKeywordlist(tmp_kwl); + otbMsgDevMacro( <<"OSSIM Open Image SUCCESS ! "); + hasMetaData = handler->getImageGeometry(geom_kwl); + } + // Free memory + delete handler; + } - itk::MetaDataDictionary& dico = this->m_ImageIO->GetMetaDataDictionary(); + if (!hasMetaData) + { + otbMsgDevMacro( <<"OSSIM MetaData not present ! "); + } + else + { + otbMsgDevMacro( <<"OSSIM MetaData present ! "); -// otbMsgDebugMacro( <<"Before write ITK Dictionnary ? "); - itk::EncapsulateMetaData< ImageKeywordlist >(dico, - MetaDataKey::OSSIMKeywordlistKey, - otb_kwl); + otbMsgDevMacro( << geom_kwl); -// otbMsgDebugMacro( <<"After write ITK Dictionnary ? "); -// itk::ExposeMetaData< ImageKeywordlist >(dico, -// MetaDataKey::OSSIMKeywordlistKey, -// otb_tmp); -// otbMsgDebugMacro( <<"After read ITK Dictionnary ? "); + // Update otb Keywordlist + ImageKeywordlist otb_kwl; + otb_kwl.SetKeywordlist( geom_kwl ); -// otb_tmp.convertToOSSIMKeywordlist(tmp_kwl2); -// otbMsgDebugMacro( << " DEBUT THOMAS : Ossim key word list copy : "<<tmp_kwl2<<std::endl); + // Update itk MetaData Dictionnary - // otbMsgDebugMacro( <<"Image keyword lists in dictionnary are :" << std::endl << geom_tmp); + itk::MetaDataDictionary& dict = this->m_ImageIO->GetMetaDataDictionary(); - } - // Free memory - delete handler; + itk::EncapsulateMetaData< ImageKeywordlist >(dict, + MetaDataKey::OSSIMKeywordlistKey, + otb_kwl); } //Copy MetaDataDictionary from instantiated reader to output image. diff --git a/Code/Projections/otbSensorModelBase.txx b/Code/Projections/otbSensorModelBase.txx index 268b7ced450d5036ef6f65650a641cc81d948473..44a0f64eae86abb2159ceea8af588ab0cefca1b4 100644 --- a/Code/Projections/otbSensorModelBase.txx +++ b/Code/Projections/otbSensorModelBase.txx @@ -28,6 +28,7 @@ PURPOSE. See the above copyright notices for more information. #include "base/ossimRefPtr.h" #include "imaging/ossimImageHandlerRegistry.h" #include "imaging/ossimImageHandler.h" +#include "ossim/ossimPluginProjectionFactory.h" namespace otb { @@ -148,6 +149,10 @@ SensorModelBase< TScalarType,NInputDimensions,NOutputDimensions,NParametersDimen m_Model = ossimSensorModelFactory::instance()->createProjection(geom); if ( m_Model == NULL) + { + m_Model = ossimPluginProjectionFactory::instance()->createProjection(geom); + } + if ( m_Model == NULL) { itkExceptionMacro(<< "Invalid Model pointer m_Model == NULL !\n The ossim keywordlist is bad!"); } diff --git a/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.h b/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.h index a30de2619692672bab3cac0b4805e1c9dd08aa26..a0c69de8b86232b0dd85e74d9ba10839a2169380 100644 --- a/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.h +++ b/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // // License: LGPL -// +// // See LICENSE.txt file in the top level directory for more details. // //---------------------------------------------------------------------------- @@ -14,7 +14,7 @@ class ossimPluginProjectionFactory : public ossimProjectionFactoryBase { public: - + static ossimPluginProjectionFactory* instance(); /** * takes a filename. This filename can be an image file or @@ -25,29 +25,29 @@ public: */ virtual ossimProjection* createProjection(const ossimFilename& filename, ossim_uint32 entryIdx)const; - + /** * Take a projection type name. */ virtual ossimProjection* createProjection(const ossimString& name)const; - + /** * Take a keywordlist. */ virtual ossimProjection* createProjection(const ossimKeywordlist& kwl, - const char* prefix)const; - + const char* prefix=0)const; + virtual ossimObject* createObject(const ossimString& typeName)const; - + /*! * Creates and object given a keyword list. */ virtual ossimObject* createObject(const ossimKeywordlist& kwl, const char* prefix=0)const; - + virtual void getTypeNameList(std::vector<ossimString>& typeList)const; protected: ossimPluginProjectionFactory(){} - + }; #endif