Commit 20955bab authored by Romain Garrigues's avatar Romain Garrigues
Browse files

Modifications pour prendre en compte les metadonnées OSSIM

parent a8ac8e36
......@@ -3,7 +3,7 @@
FILE(GLOB OTBIO_SRCS "*.cxx" )
ADD_LIBRARY(OTBIO ${OTBIO_SRCS})
TARGET_LINK_LIBRARIES (OTBIO gdal OTBCommon ITKIO ITKCommon)
TARGET_LINK_LIBRARIES (OTBIO gdal OTBCommon ITKIO ITKCommon ossim)
INSTALL(TARGETS OTBIO
RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
......
......@@ -26,7 +26,7 @@
#include "itkMetaDataObject.h"
#include "otbImageBase.h"
#include "otbImageKeywordlist.h"
namespace otb
{
......@@ -286,8 +286,9 @@ ImageBase::PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDiction
VectorType vvalue;
double dvalue;
OTB_GCP gcpvalue;
ImageKeywordlist ossimvalue;
unsigned int i ;
// Copy of the const metadata dictionary in a metadata dictionary to be used
// by the ExposeMetaData method
......@@ -331,9 +332,15 @@ ImageBase::PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDiction
os << indent << "---> " << keys[itkey] << std::endl;
gcpvalue.Print(os);
break;
}
case MetaDataKey::TOSSIMKEYWORDLIST:
itk::ExposeMetaData<ImageKeywordlist>(dict2, keys[itkey], ossimvalue);
os << indent << "---> " << keys[itkey] << std::endl;
ossimvalue.Print(os);
// ossimvalue.Print(os);
break;
}
}
......
......@@ -24,10 +24,18 @@
#include "itkImageRegion.h"
#include "itkPixelTraits.h"
#include "itkVectorImage.h"
#include "itkMetaDataObject.h"
#include "otbMacro.h"
#include "otbSystem.h"
#include "otbImageIOFactory.h"
#include "otbMetaDataKey.h"
#include "otbImageKeywordlist.h"
#include "imaging/ossimImageHandlerRegistry.h"
#include "imaging/ossimImageHandler.h"
#include "init/ossimInit.h"
#include "base/ossimKeywordlist.h"
#include <itksys/SystemTools.hxx>
#include <fstream>
......@@ -366,6 +374,68 @@ ImageFileReader<TOutputImage>
output->SetOrigin( origin ); // Set the image origin
output->SetDirection( direction ); // Set the image direction cosines
// Trying to read ossim MetaData
// Itinialize ossim environment
ossimImageHandler* handler = ossimImageHandlerRegistry::instance()->open(ossimFilename(this->m_FileName.c_str()));
if (!handler)
{
otbMsgDebugMacro( <<"OSSIM Open Image FAILED ! ");
}
else
{
ossimKeywordlist geom_kwl, tmp_kwl, tmp_kwl2;// = new ossimKeywordlist();
// Read OSSIM Keyword List
bool hasMetaData = handler->getImageGeometry(geom_kwl);
otbMsgDebugMacro( << " AVANT *geom_kwl : "<<geom_kwl<<std::endl);
if (!hasMetaData)
{
otbMsgDebugMacro( <<"OSSIM MetaData not present ! ");
}
else
{
otbMsgDebugMacro( <<"Image keyword lists are :" << std::endl << geom_kwl);
// 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);
itk::MetaDataDictionary& dico = this->m_ImageIO->GetMetaDataDictionary();
// otbMsgDebugMacro( <<"Before write ITK Dictionnary ? ");
itk::EncapsulateMetaData< ImageKeywordlist >(dico,
MetaDataKey::m_OSSIMKeywordlistKey,
otb_kwl);
// otbMsgDebugMacro( <<"After write ITK Dictionnary ? ");
// itk::ExposeMetaData< ImageKeywordlist >(dico,
// MetaDataKey::m_OSSIMKeywordlistKey,
// otb_tmp);
// otbMsgDebugMacro( <<"After read ITK Dictionnary ? ");
// otb_tmp.convertToOSSIMKeywordlist(tmp_kwl2);
// otbMsgDebugMacro( << " DEBUT THOMAS : Ossim key word list copy : "<<tmp_kwl2<<std::endl);
// otbMsgDebugMacro( <<"Image keyword lists in dictionnary are :" << std::endl << geom_tmp);
}
// Free memory
otbMsgDebugMacro( <<"OSSIM Free Memory ? ");
delete handler;
otbMsgDebugMacro( <<"OSSIM Free Memory OK ! ");
}
//Copy MetaDataDictionary from instantiated reader to output image.
output->SetMetaDataDictionary(this->m_ImageIO->GetMetaDataDictionary());
this->SetMetaDataDictionary(this->m_ImageIO->GetMetaDataDictionary());
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbImageKeywordlist.h"
namespace otb
{
ImageKeywordlist
::ImageKeywordlist()
{
}
ImageKeywordlist
::ImageKeywordlist(const Self& p): m_Keywordlist(p.m_Keywordlist) //m_Keywordlist(Self.m_Keywordlist), m_Delimiter(Self.m_Delimiter)
{
}
ImageKeywordlist
::~ImageKeywordlist()
{
}
void
ImageKeywordlist::
operator=(const Self& p)
{
m_Keywordlist = p.m_Keywordlist;
}
void
ImageKeywordlist::
Print(std::ostream& os) const
{
// Superclass::PrintSelf(os, indent);
ossimKeywordlist kwl;
convertToOSSIMKeywordlist(kwl);
os << " Ossim Keyword list:"<<std::endl;
os << kwl ;
// os << m_Keywordlist << std::endl;
// writeToStream
}
void
ImageKeywordlist::
convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const
{
kwl.getMap() = m_Keywordlist;
}
} //namespace otb
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbImageKeywordlist_h
#define __otbImageKeywordlist_h
#include "itkObject.h"
#include "itkObjectFactory.h"
//#include "itkSize.h"
//#include "itkImageRegion.h"
//#include "itkDefaultConvertPixelTraits.h"
#include "base/ossimString.h"
#include "base/ossimKeywordlist.h"
#include <map>
namespace otb
{
/** \class ImageKeywordlist
* \brief Stockage/Conversion des MetaDonnees OSSIM
*
* \sa ImageSeriesReader
* \sa ImageIOBase
*
* \ingroup Projections
*
*/
class ITKCommon_EXPORT ImageKeywordlist
{
public:
/** Standard class typedefs. */
typedef ImageKeywordlist Self;
typedef std::map<ossimString, ossimString> KeywordlistMap ;
void SetKeywordlist(const ossimKeywordlist& kwl)
{
m_Keywordlist = kwl.getMap();
}
virtual void convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const;
ImageKeywordlist() ;
virtual ~ImageKeywordlist() ;
void Print(std::ostream& os) const ;
ImageKeywordlist(const Self&);
void operator=(const Self&);
private:
/** Geo informations are in this map */
KeywordlistMap m_Keywordlist;
// char m_Delimiter;
// void operator=(const Self&); //purposely not implemented
};
} //namespace otb
#endif // __otbImageKeywordlist_h
......@@ -51,6 +51,9 @@ const std::string MetaDataKey::m_ColorTableNameKey = "ColorTableName";
const std::string MetaDataKey::m_ColorEntryCountKey = "ColorEntryCount";
const std::string MetaDataKey::m_ColorEntryAsRGBKey = "ColorEntryAsRGB";
const std::string MetaDataKey::m_OSSIMKeywordlistKey = "OSSIMKeywordlist";
const std::string MetaDataKey::m_OSSIMKeywordlistDelimiterKey = "OSSIMKeywordlistDelimiter";
/*const MetaDataKey::KeyTypeDef Types[] =
{
{MetaDataKey::m_DriverShortNameKey, MetaDataKey::TSTRING},
......@@ -87,10 +90,12 @@ const MetaDataKey::KeyTypeDef Types[] =
MetaDataKey::KeyTypeDef(MetaDataKey::m_LowerRightCornerKey, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::m_ColorTableNameKey, MetaDataKey::TSTRING),
MetaDataKey::KeyTypeDef(MetaDataKey::m_ColorEntryCountKey, MetaDataKey::TENTIER),
MetaDataKey::KeyTypeDef(MetaDataKey::m_ColorEntryAsRGBKey, MetaDataKey::TVECTOR)
MetaDataKey::KeyTypeDef(MetaDataKey::m_ColorEntryAsRGBKey, MetaDataKey::TVECTOR),
MetaDataKey::KeyTypeDef(MetaDataKey::m_OSSIMKeywordlistKey, MetaDataKey::TOSSIMKEYWORDLIST),
MetaDataKey::KeyTypeDef(MetaDataKey::m_OSSIMKeywordlistDelimiterKey,MetaDataKey::TSTRING)
};
MetaDataKey::KeyType MetaDataKey::GetKeyType(std::string name)
{
MetaDataKey::KeyType ktype;
......
......@@ -68,12 +68,16 @@ public:
static const std::string m_ColorEntryCountKey;
static const std::string m_ColorEntryAsRGBKey;
static const std::string m_OSSIMKeywordlistKey;
static const std::string m_OSSIMKeywordlistDelimiterKey;
enum KeyType {
TSTRING,
TENTIER,
TDOUBLE,
TOTB_GCP,
TVECTOR
TVECTOR,
TOSSIMKEYWORDLIST,
};
/*
typedef struct
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment