OTB  10.0.0
Orfeo Toolbox
otbGeometryMetadata.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbGeometryMetadata_h
22 #define otbGeometryMetadata_h
23 
24 #include "OTBMetadataExport.h"
25 #include "otbMetaDataKey.h"
26 
27 
28 #include <string>
29 #include <vector>
30 #include <sstream>
31 
32 namespace otb
33 {
34 
43 class OTBMetadata_EXPORT GCP
44 {
45 public:
47  std::string m_Id;
48 
50  std::string m_Info;
51 
53  double m_GCPCol;
54 
56  double m_GCPRow;
57 
59  double m_GCPX;
60 
62  double m_GCPY;
63 
65  double m_GCPZ;
66 
67  GCP() = default;
68  GCP(std::string id, std::string info, double col, double row, double px, double py, double pz);
69 
70  void Print(std::ostream& os) const;
71  std::string ToJSON(bool multiline=false) const;
72 
73  friend bool operator==(const GCP& lhs,const GCP& rhs)
74  {
75  return (lhs.m_GCPCol == rhs.m_GCPCol) && (lhs.m_GCPRow == rhs.m_GCPRow);
76  }
78  void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
79 
81  static GCP FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
82 };
83 
84 
85 namespace Projection
86 {
87 
92 struct OTBMetadata_EXPORT GCPParam
93 {
94  std::string GCPProjection;
95 
96  std::vector<GCP> GCPs;
97 
98  // JSON export
99  std::string ToJSON(bool multiline=false) const;
100 
102  void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
103 
105  void FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
106 };
107 
134 struct OTBMetadata_EXPORT RPCParam
135 {
136  // Constructors
137  RPCParam() = default;
138  RPCParam(const RPCParam &) = default; // CopyConstructible required for boost::any
139  RPCParam& operator=(RPCParam &) = default; //CopyAssignment optional for boost::any
141 
142  // Offsets
143  double LineOffset = 0.0;
144  double SampleOffset = 0.0;
145  double LatOffset = 0.0;
146  double LonOffset = 0.0;
147  double HeightOffset = 0.0;
148 
149  // Scales
150  double LineScale = 0.0;
151  double SampleScale = 0.0;
152  double LatScale = 0.0;
153  double LonScale = 0.0;
154  double HeightScale = 0.0;
155 
156  // Line numerator coefficients
157  double LineNum[20] = {
158  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
159  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
160 
161  // Line denominator coefficients
162  double LineDen[20] = {
163  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
164  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
165 
166  // Sample numerator coefficients
167  double SampleNum[20] = {
168  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
169  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
170 
171  // Sample denominator coefficients
172  double SampleDen[20] = {
173  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
174  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
175 
176  // JSON export
177  std::string ToJSON(bool multiline=false) const;
178  inline static std::string doubleArrayToString(const double* array)
179  {
180  std::ostringstream oss;
181  oss << "[";
182  for (int loop = 0 ; loop < 20 ; loop++)
183  oss << " \"" << array[loop] << "\", ";
184  oss << "]";
185  return oss.str();
186  }
187 
188  // Equality comparison with tolerance
189  template <class BinaryPredicate>
190  bool Compare(const RPCParam & other, const BinaryPredicate & p) const
191  {
192  return p(LineOffset, other.LineOffset)
193  && p(SampleOffset, other.SampleOffset)
194  && p(LatOffset, other.LatOffset)
195  && p(LonOffset, other.LonOffset)
196  && p(HeightOffset, other.HeightOffset)
197  && p(LineScale, other.LineScale)
198  && p(SampleScale, other.SampleScale)
199  && p(LatScale, other.LatScale)
200  && p(LonScale, other.LonScale)
201  && p(HeightScale, other.HeightScale)
202  && std::equal(std::begin(LineNum), std::end(LineNum), std::begin(other.LineNum),p)
203  && std::equal(std::begin(LineDen), std::end(LineDen), std::begin(other.LineDen),p)
204  && std::equal(std::begin(SampleNum), std::end(SampleNum), std::begin(other.SampleNum),p)
205  && std::equal(std::begin(SampleDen), std::end(SampleDen), std::begin(other.SampleDen),p);
206  }
207 
208  // Equality comparison operator (hidden friend idiom)
209  friend bool operator==(const RPCParam & lhs, const RPCParam & rhs)
210  {
211  return lhs.Compare(rhs, [](double rhs, double lhs){return rhs == lhs;});
212  }
213 
214 };
215 
216 } // end namespace Projection
217 
218 } // end namespace otb
219 
220 #endif
221 
This GCP class is used to manage the GCP parameters in OTB.
std::string ToJSON(bool multiline=false) const
GCP()=default
void ToKeywordlist(MetaData::Keywordlist &kwl, const std::string &prefix) const
std::string m_Id
friend bool operator==(const GCP &lhs, const GCP &rhs)
void Print(std::ostream &os) const
std::string m_Info
static GCP FromKeywordlist(const MetaData::Keywordlist &kwl, const std::string &prefix)
GCP(std::string id, std::string info, double col, double row, double px, double py, double pz)
std::unordered_map< std::string, std::string > Keywordlist
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
This structure handles the list of the GCP parameters.
void FromKeywordlist(const MetaData::Keywordlist &kwl, const std::string &prefix)
std::string ToJSON(bool multiline=false) const
void ToKeywordlist(MetaData::Keywordlist &kwl, const std::string &prefix) const
Coefficients for RPC model (quite similar to GDALRPCInfo)
friend bool operator==(const RPCParam &lhs, const RPCParam &rhs)
static std::string doubleArrayToString(const double *array)
RPCParam & operator=(RPCParam &)=default
bool Compare(const RPCParam &other, const BinaryPredicate &p) const
RPCParam(const RPCParam &)=default
std::string ToJSON(bool multiline=false) const