OTB  9.0.0
Orfeo Toolbox
otbRPCTransformBase.hxx
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 otbRPCTransformBase_hxx
22 #define otbRPCTransformBase_hxx
23 
24 #include "otbRPCTransformBase.h"
25 #include "otbRPCSolver.h"
26 
27 namespace otb
28 {
29 
30 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
32 {
33  if (!imd.Has(MDGeom::RPC))
34  return false;
35  const boost::any any_rpc = imd[MDGeom::RPC];
36  if (any_rpc.empty())
37  return false;
38  try
39  {
40  this->m_RPCParam = std::make_unique<Projection::RPCParam>(boost::any_cast<Projection::RPCParam>(imd[MDGeom::RPC]));
41  }
42  catch (const boost::bad_any_cast&)
43  {
44  return false;
45  }
46 
47  constexpr bool useDEM = NInputDimensions == 2 ? true : false;
48  this->m_Transformer = std::make_unique<GDALRPCTransformer>(*m_RPCParam, useDEM);
49  return true;
50 }
51 
52 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
54 {
55  return m_Transformer != nullptr;
56 }
57 
61 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
63 {
64  Superclass::PrintSelf(os, indent);
65  os << indent << "RPC Model: " << this->m_RPCParam.get()->ToJSON() << std::endl;
66 }
68 
69 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
71 {
72  Projection::RPCParam refinedRPCParams;
74 
75  //Build GCPS from tiepoints
76  for(auto it=tiepoints.begin();it!=tiepoints.end();it++)
77  {
80 
81  sensorGCP[0] = it->first[0];
82  sensorGCP[1] = it->first[1];
83  groundGCP[0] = it->second[0];
84  groundGCP[1] = it->second[1];
85  groundGCP[2] = it->second[2];
86 
87  gcps.push_back({sensorGCP,groundGCP});
88  }
89  RPCSolver::Solve(gcps, rmsError, refinedRPCParams);
90  imd.Add(MDGeom::RPC,refinedRPCParams);
91  this->SetMetadata(imd);
92 }
93 
94 } // namespace otb
95 
96 #endif
otb::SensorTransformBase::TiePointsType
std::vector< std::pair< InputPointType, OutputPointType > > TiePointsType
Definition: otbSensorTransformBase.h:61
otb::RPCSolver::Point3DType
itk::Point< double, 3 > Point3DType
Definition: otbRPCSolver.h:32
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::RPCTransformBase::OptimizeParameters
void OptimizeParameters(ImageMetadata &imd, const TiePointsType &tiepoints, double &rmsError) final
Definition: otbRPCTransformBase.hxx:70
otb::MDGeom::RPC
@ RPC
otb::RPCTransformBase::IsValidSensorModel
bool IsValidSensorModel() const override
Definition: otbRPCTransformBase.hxx:53
otb::ImageMetadataBase::Has
bool Has(MDGeom key) const
otb::RPCTransformBase::SetMetadata
bool SetMetadata(const ImageMetadata &imd) override
Definition: otbRPCTransformBase.hxx:31
otb::RPCSolver::GCPsContainerType
std::vector< GCPType > GCPsContainerType
Definition: otbRPCSolver.h:34
otb::RPCSolver::Point2DType
itk::Point< double, 2 > Point2DType
Definition: otbRPCSolver.h:31
otb::Projection::RPCParam
Coefficients for RPC model (quite similar to GDALRPCInfo)
Definition: otbGeometryMetadata.h:130
otb::ImageMetadata
Generic class containing image metadata used in OTB.
Definition: otbImageMetadata.h:270
otb::ImageMetadata::Add
void Add(MDNum, const MetaDataKey::VariableLengthVectorType)
otb::RPCTransformBase::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbRPCTransformBase.hxx:62
otb::RPCSolver::Solve
void Solve(const GCPsContainerType &gcpContainer, double &rmsError, Projection::RPCParam &outputParams)
otbRPCSolver.h
otbRPCTransformBase.h