otbImageKeywordlist.h 4.38 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
OTB Bot committed
81
  //{return "ImageKeywordlist"; }
82

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

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

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

  void Clear(void)
95
  {
96
    m_Keywordlist.clear();
97
  }
98 99
 
  KeywordlistMapSizeType GetSize(void) const
100 101 102
  {
    return m_Keywordlist.size();
  }
OTB Bot's avatar
OTB Bot committed
103

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

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

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

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

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

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

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

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

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

132 133 134 135 136 137 138
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;

139
private:
140
  /** Geo information are in this map */
141
  KeywordlistMap m_Keywordlist;
142

143 144 145
//  char m_Delimiter;

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

147 148
};

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

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

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

165 166 167
} //namespace otb

#endif // __otbImageKeywordlist_h