OTB  9.0.0
Orfeo Toolbox
otbGeometryMetadata.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 
74  void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
75 
77  static GCP FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
78 };
79 
80 
81 namespace Projection
82 {
83 
88 struct OTBMetadata_EXPORT GCPParam
89 {
90  std::string GCPProjection;
91 
92  std::vector<GCP> GCPs;
93 
94  // JSON export
95  std::string ToJSON(bool multiline=false) const;
96 
98  void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
99 
101  void FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
102 };
103 
130 struct OTBMetadata_EXPORT RPCParam
131 {
132  // Constructors
133  RPCParam() = default;
134  RPCParam(const RPCParam &) = default; // CopyConstructible required for boost::any
135  RPCParam& operator=(RPCParam &) = default; //CopyAssignment optional for boost::any
137 
138  // Offsets
139  double LineOffset = 0.0;
140  double SampleOffset = 0.0;
141  double LatOffset = 0.0;
142  double LonOffset = 0.0;
143  double HeightOffset = 0.0;
144 
145  // Scales
146  double LineScale = 0.0;
147  double SampleScale = 0.0;
148  double LatScale = 0.0;
149  double LonScale = 0.0;
150  double HeightScale = 0.0;
151 
152  // Line numerator coefficients
153  double LineNum[20] = {
154  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
155  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
156 
157  // Line denominator coefficients
158  double LineDen[20] = {
159  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
160  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
161 
162  // Sample numerator coefficients
163  double SampleNum[20] = {
164  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
165  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
166 
167  // Sample denominator coefficients
168  double SampleDen[20] = {
169  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
170  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
171 
172  // JSON export
173  std::string ToJSON(bool multiline=false) const;
174  inline static std::string doubleArrayToString(const double* array)
175  {
176  std::ostringstream oss;
177  oss << "[";
178  for (int loop = 0 ; loop < 20 ; loop++)
179  oss << " \"" << array[loop] << "\", ";
180  oss << "]";
181  return oss.str();
182  }
183 
184  // Equality comparison with tolerance
185  template <class BinaryPredicate>
186  bool Compare(const RPCParam & other, const BinaryPredicate & p) const
187  {
188  return p(LineOffset, other.LineOffset)
189  && p(SampleOffset, other.SampleOffset)
190  && p(LatOffset, other.LatOffset)
191  && p(LonOffset, other.LonOffset)
192  && p(HeightOffset, other.HeightOffset)
193  && p(LineScale, other.LineScale)
194  && p(SampleScale, other.SampleScale)
195  && p(LatScale, other.LatScale)
196  && p(LonScale, other.LonScale)
197  && p(HeightScale, other.HeightScale)
198  && std::equal(std::begin(LineNum), std::end(LineNum), std::begin(other.LineNum),p)
199  && std::equal(std::begin(LineDen), std::end(LineDen), std::begin(other.LineDen),p)
200  && std::equal(std::begin(SampleNum), std::end(SampleNum), std::begin(other.SampleNum),p)
201  && std::equal(std::begin(SampleDen), std::end(SampleDen), std::begin(other.SampleDen),p);
202  }
203 
204  // Equality comparison operator (hidden friend idiom)
205  friend bool operator==(const RPCParam & lhs, const RPCParam & rhs)
206  {
207  return lhs.Compare(rhs, [](double rhs, double lhs){return rhs == lhs;});
208  }
209 
210 };
211 
212 } // end namespace Projection
213 
214 } // end namespace otb
215 
216 #endif
217 
otb::Projection::RPCParam::Compare
bool Compare(const RPCParam &other, const BinaryPredicate &p) const
Definition: otbGeometryMetadata.h:186
otb::Projection::RPCParam::LonOffset
double LonOffset
Definition: otbGeometryMetadata.h:142
otb::Projection::GCPParam::GCPs
std::vector< GCP > GCPs
Definition: otbGeometryMetadata.h:92
otb::GCP::m_GCPRow
double m_GCPRow
Definition: otbGeometryMetadata.h:56
otb::Projection::RPCParam::LatScale
double LatScale
Definition: otbGeometryMetadata.h:148
otb::Projection::RPCParam::HeightOffset
double HeightOffset
Definition: otbGeometryMetadata.h:143
otb::Projection::GCPParam::GCPProjection
std::string GCPProjection
Definition: otbGeometryMetadata.h:90
otb::GCP::m_GCPCol
double m_GCPCol
Definition: otbGeometryMetadata.h:53
otb::Projection::RPCParam::SampleNum
double SampleNum[20]
Definition: otbGeometryMetadata.h:163
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Projection::RPCParam::operator==
friend bool operator==(const RPCParam &lhs, const RPCParam &rhs)
Definition: otbGeometryMetadata.h:205
otb::GCP::m_GCPX
double m_GCPX
Definition: otbGeometryMetadata.h:59
otb::Projection::RPCParam::LineOffset
double LineOffset
Definition: otbGeometryMetadata.h:139
otb::GCP::m_GCPZ
double m_GCPZ
Definition: otbGeometryMetadata.h:65
otb::Projection::RPCParam::LineScale
double LineScale
Definition: otbGeometryMetadata.h:146
otb::GCP::m_GCPY
double m_GCPY
Definition: otbGeometryMetadata.h:62
otb::Projection::RPCParam::LatOffset
double LatOffset
Definition: otbGeometryMetadata.h:141
otb::Projection::RPCParam::LineNum
double LineNum[20]
Definition: otbGeometryMetadata.h:153
otb::Projection::RPCParam::LonScale
double LonScale
Definition: otbGeometryMetadata.h:149
otbMetaDataKey.h
otb::Projection::RPCParam::LineDen
double LineDen[20]
Definition: otbGeometryMetadata.h:158
otb::Projection::RPCParam::HeightScale
double HeightScale
Definition: otbGeometryMetadata.h:150
otb::Projection::RPCParam::doubleArrayToString
static std::string doubleArrayToString(const double *array)
Definition: otbGeometryMetadata.h:174
otb::MetaData::Keywordlist
std::unordered_map< std::string, std::string > Keywordlist
Definition: otbMetaDataKey.h:233
otb::Projection::RPCParam::SampleOffset
double SampleOffset
Definition: otbGeometryMetadata.h:140
otb::Projection::RPCParam
Coefficients for RPC model (quite similar to GDALRPCInfo)
Definition: otbGeometryMetadata.h:130
otb::GCP::m_Info
std::string m_Info
Definition: otbGeometryMetadata.h:50
otb::Projection::RPCParam::SampleScale
double SampleScale
Definition: otbGeometryMetadata.h:147
otb::Projection::RPCParam::SampleDen
double SampleDen[20]
Definition: otbGeometryMetadata.h:168
otb::Projection::GCPParam
This structure handles the list of the GCP parameters.
Definition: otbGeometryMetadata.h:88
otb::GCP::m_Id
std::string m_Id
Definition: otbGeometryMetadata.h:47
otb::GCP
This GCP class is used to manage the GCP parameters in OTB.
Definition: otbGeometryMetadata.h:43