otbImageKeywordlist.h 4.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


13 14
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 16 17 18 19 20
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbImageKeywordlist_h
#define __otbImageKeywordlist_h

21
#include <iostream>
22
#include <map>
23

24 25
#include "gdal.h"

26
#include "itkObject.h"
27
#include "itkObjectFactory.h"
28 29 30

//forward declaration
class ossimKeywordlist;
31 32 33 34

namespace otb
{

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
namespace internal
{
  /**
   * Converts index coordinates from OTB into OSSIM. It is intended for sensor
   * images where the centre of the top-left pixel is expected to be :
   *   [0.5,0.5] in OTB physical space
   *   [ 0 , 0 ] in OSSIM
   * \param[in] val  coordinate value to modify (along X or Y)
   */
  inline double ConvertToOSSIMFrame(double val)
    {
    return (val - 0.5);
    }

  /**
   * Converts index coordinates from OSSIM into OTB. It is intended for sensor
   * images where the centre of the top-left pixel is expected to be :
   *   [0.5,0.5] in OTB physical space
   *   [ 0 , 0 ] in OSSIM
    * \param[in] val  coordinate value to modify (along X or Y)
   */
  inline double ConvertFromOSSIMFrame(double val)
    {
    return (val + 0.5);
    }

} // namespace internal

63
/** \class ImageKeywordlist
64
 * \brief Storage and conversion for OSSIM metadata
65 66 67
 *
 * \sa ImageSeriesReader
 * \sa ImageIOBase
68
 *
69 70
 * \ingroup Projections
 *
71 72
 *
 * \ingroup OTBOSSIMAdapters
73
 */
74
class ITK_EXPORT ImageKeywordlist
75 76 77
{
public:
  /** Standard class typedefs. */
78
  typedef ImageKeywordlist Self;
79

80
  //virtual const char *GetNameOfClass() const
OTB Bot's avatar
STYLE  
OTB Bot committed
81
  //{return "ImageKeywordlist"; }
Emmanuel Christophe's avatar
Emmanuel Christophe committed
82

83
  typedef std::map<std::string, std::string> KeywordlistMap;
84

85
  /** Get the internal map container */
OTB Bot's avatar
STYLE  
OTB Bot committed
86
  const KeywordlistMap& GetKeywordlist() const
87 88 89
  {
    return m_Keywordlist;
  }
OTB Bot's avatar
STYLE  
OTB Bot committed
90

91
  void SetKeywordlist(const ossimKeywordlist& kwl);
92 93

  void Clear(void)
94
  {
95
    m_Keywordlist.clear();
96
  }
97

98 99 100 101
  unsigned int GetSize(void) const
  {
    return m_Keywordlist.size();
  }
OTB Bot's avatar
STYLE  
OTB Bot committed
102

103
  /** Get the Data object descriptor corresponding to the given key */
104
  const std::string& GetMetadataByKey(const std::string& key) const;
OTB Bot's avatar
STYLE  
OTB Bot committed
105

106 107 108
  /** return true if the key is in the dictionary */
  bool HasKey(const std::string& key) const;

109 110 111
  /** Clear a given field of the keyword list */
  virtual void ClearMetadataByKey(const std::string& key);

112 113
  virtual void AddKey(const std::string& key, const std::string& value);

114
  virtual void convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const;
115 116 117 118
  
  /** try to convert the image keywordlist into a GDALRpcInfo structure
   *  return true if successful, false otherwise */
  virtual bool convertToGDALRPC(GDALRPCInfo &rpc) const;
119

OTB Bot's avatar
STYLE  
OTB Bot committed
120
  virtual void Print(std::ostream& os, itk::Indent indent = 0) const;
121

Emmanuel Christophe's avatar
Emmanuel Christophe committed
122 123
  ImageKeywordlist();
  virtual ~ImageKeywordlist();
124

OTB Bot's avatar
STYLE  
OTB Bot committed
125 126
  ImageKeywordlist(const Self &);
  void operator =(const Self&);
127 128 129

  bool operator ==(const Self&) const;
  inline bool operator != ( const Self & ) const;
130

131 132 133 134 135 136 137
protected:
  /** Methods invoked by Print() to print information about the object
   * Typically not called by the user (use Print()
   * instead) but used in the hierarchical print process to combine the
   * output of several classes.  */
  virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;

138 139 140
private:
  /** Geo informations are in this map */
  KeywordlistMap m_Keywordlist;
141

142 143 144
//  char m_Delimiter;

//  void operator=(const Self&); //purposely not implemented
145

146 147
};

148
std::ostream & operator <<(std::ostream& os, const ImageKeywordlist& kwl);
149

150
// Free function to handle the keywordlist <-> files
151
ImageKeywordlist ReadGeometryFromImage(const std::string& filename, bool checkRpcTag=true);
152
ImageKeywordlist ReadGeometryFromGEOMFile(const std::string& filename);
153
ImageKeywordlist ReadGeometryFromRPCTag(const std::string& filename);
154 155
void WriteGeometry(const ImageKeywordlist& otb_kwl, const std::string& filename);

156 157 158 159 160 161 162 163
inline
bool
ImageKeywordlist
::operator !=( const Self & p ) const
{
  return !this->operator == ( p );
}

164 165 166
} //namespace otb

#endif // __otbImageKeywordlist_h