1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*
* Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbGeometryMetadata_h
#define otbGeometryMetadata_h
#include "OTBMetadataExport.h"
#include "otbMetaDataKey.h"
#include <string>
#include <vector>
#include <sstream>
namespace otb
{
/** \class GCP
*
* \brief This GCP class is used to manage the GCP parameters
* in OTB.
*
*
* \ingroup OTBMetadata
*/
class OTBMetadata_EXPORT GCP
{
public:
/** Unique identifier, often numeric */
std::string m_Id;
/** Informational message or "" */
std::string m_Info;
/** Pixel (x) location of GCP on raster */
double m_GCPCol;
/** Line (y) location of GCP on raster */
double m_GCPRow;
/** X position of GCP in georeferenced space */
double m_GCPX;
/** Y position of GCP in georeferenced space */
double m_GCPY;
/** Elevation of GCP, or zero if not known */
double m_GCPZ;
GCP() = default;
GCP(std::string id, std::string info, double col, double row, double px, double py, double pz);
void Print(std::ostream& os) const;
std::string ToJSON(bool multiline=false) const;
/** Keywordlist export */
void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
/** Keywordlist import */
static GCP FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
};
namespace Projection
{
/** \struct GCPParam
*
* \brief This structure handles the list of the GCP parameters
*/
struct OTBMetadata_EXPORT GCPParam
{
std::string GCPProjection;
std::vector<GCP> GCPs;
// JSON export
std::string ToJSON(bool multiline=false) const;
/** Keywordlist export */
void ToKeywordlist(MetaData::Keywordlist & kwl, const std::string & prefix) const;
/** Keywordlist import */
void FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
};
/** \struct RPCParam
*
* \brief Coefficients for RPC model (quite similar to GDALRPCInfo)
*
* Details of the mathematical model:
*
* x = (longitude - LonOffset) / LonScale
* y = (latitude - LatOffset) / LatScale
* z = (Height - HeightOffset) / HeightScale
* rn = (Row - LineOffset) / LineScale
* cn = (Column - SampleOffset) / SampleScale
*
* rn = LineNum(x,y,z) / LineDen(x,y,z)
* cn = SampleNum(x,y,z) / SampleDen(x,y,z)
*
* Each cubic polynomial function LineNum, LineDen, SampleNum, SampleDen has
* 20 coefficients:
*
* c1 + (order 0)
* c2*x + c3*y + c4*z + (order 1)
* c5*x*y + c6*x*z + c7*y*z + c8*x^2 + c9*y^2 + c10*z^2 + (order 2)
* c11*x*y*z + c12*x^3 + c13*x*y^2 + c14*x*z^2 + c15*x^2*y +
* c16*y^3 + c17*y*z^2 + c18*x^2*z + c19*y^2*z + c20*z^3 (order 3)
*
* \ingroup OTBMetadata
*/
struct OTBMetadata_EXPORT RPCParam
{
// Constructors
RPCParam() = default;
RPCParam(const RPCParam &) = default; // CopyConstructible required for boost::any
RPCParam& operator=(RPCParam &) = default; //CopyAssignment optional for boost::any
// Offsets
double LineOffset = 0.0;
double SampleOffset = 0.0;
double LatOffset = 0.0;
double LonOffset = 0.0;
double HeightOffset = 0.0;
// Scales
double LineScale = 0.0;
double SampleScale = 0.0;
double LatScale = 0.0;
double LonScale = 0.0;
double HeightScale = 0.0;
// Line numerator coefficients
double LineNum[20] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
// Line denominator coefficients
double LineDen[20] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
// Sample numerator coefficients
double SampleNum[20] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
// Sample denominator coefficients
double SampleDen[20] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
// JSON export
std::string ToJSON(bool multiline=false) const;
inline static std::string doubleArrayToString(const double* array)
{
std::ostringstream oss;
oss << "[";
for (int loop = 0 ; loop < 20 ; loop++)
oss << " \"" << array[loop] << "\", ";
oss << "]";
return oss.str();
}
// Equality comparison with tolerance
template <class BinaryPredicate>
bool Compare(const RPCParam & other, const BinaryPredicate & p) const
{
return p(LineOffset, other.LineOffset)
&& p(SampleOffset, other.SampleOffset)
&& p(LatOffset, other.LatOffset)
&& p(LonOffset, other.LonOffset)
&& p(HeightOffset, other.HeightOffset)
&& p(LineScale, other.LineScale)
&& p(SampleScale, other.SampleScale)
&& p(LatScale, other.LatScale)
&& p(LonScale, other.LonScale)
&& p(HeightScale, other.HeightScale)
&& std::equal(std::begin(LineNum), std::end(LineNum), std::begin(other.LineNum),p)
&& std::equal(std::begin(LineDen), std::end(LineDen), std::begin(other.LineDen),p)
&& std::equal(std::begin(SampleNum), std::end(SampleNum), std::begin(other.SampleNum),p)
&& std::equal(std::begin(SampleDen), std::end(SampleDen), std::begin(other.SampleDen),p);
}
// Equality comparison operator (hidden friend idiom)
friend bool operator==(const RPCParam & lhs, const RPCParam & rhs)
{
return lhs.Compare(rhs, [](double rhs, double lhs){return rhs == lhs;});
}
};
} // end namespace Projection
} // end namespace otb
#endif
|