OTB  9.0.0
Orfeo Toolbox
otbGenericRSTransform.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 otbGenericRSTransform_hxx
22 #define otbGenericRSTransform_hxx
23 
24 #include "otbGenericRSTransform.h"
25 #include "otbMacro.h"
26 #include "otbRPCForwardTransform.h"
27 #include "otbRPCInverseTransform.h"
28 
29 #include "otbSpatialReference.h"
30 
31 #include "ogr_spatialref.h"
33 
34 namespace otb
35 {
36 
37 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
39 {
40  m_InputProjectionRef.clear();
41  m_OutputProjectionRef.clear();
42  m_InputSpacing.Fill(1);
43  m_InputOrigin.Fill(0);
44  m_OutputSpacing.Fill(1);
45  m_OutputOrigin.Fill(0);
46 
47  m_InputImd = nullptr;
48  m_OutputImd = nullptr;
49  m_Transform = nullptr;
50  m_InputTransform = nullptr;
51  m_OutputTransform = nullptr;
52  m_TransformUpToDate = false;
54 }
55 
56 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
59 {
60  itkDebugMacro("returning MapProjection address " << this->m_Transform);
61  if ((!m_TransformUpToDate) || (m_Transform.IsNull()))
62  {
63  itkExceptionMacro(<< "m_Transform not up-to-date, call InstantiateTransform() first");
64  }
65 
66  return this->m_Transform;
67 }
68 
72 template <class TScalarType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
74 {
75  m_Transform = TransformType::New();
76 
77  if (m_InputProjectionRef.empty() && m_InputImd != nullptr && m_InputImd->HasProjectedGeometry())
78  {
79  m_InputProjectionRef = m_InputImd->GetProjectionWKT();
80  }
81 
82  otbMsgDevMacro(<< "Information to instantiate transform: ");
83  otbMsgDevMacro(<< " * Input Origin: " << m_InputOrigin);
84  otbMsgDevMacro(<< " * Input Spacing: " << m_InputSpacing);
85  otbMsgDevMacro(<< " * Input metadata: " << ((m_InputImd == nullptr) ? "Empty" : "Full"));
86  otbMsgDevMacro(<< " * Input projection: " << m_InputProjectionRef);
87  otbMsgDevMacro(<< " * Output metadata: " << ((m_OutputImd == nullptr) ? "Empty" : "Full"));
88  otbMsgDevMacro(<< " * Output projection: " << m_OutputProjectionRef);
89  otbMsgDevMacro(<< " * Output Origin: " << m_OutputOrigin);
90  otbMsgDevMacro(<< " * Output Spacing: " << m_OutputSpacing);
91 
92  // Make sure that the state is clean:
93  m_InputTransform = nullptr;
94  m_OutputTransform = nullptr;
95 
96  bool inputTransformIsSensor = false;
97  bool inputTransformIsMap = false;
98  bool outputTransformIsSensor = false;
99  bool outputTransformIsMap = false;
100 
101 /*****************************
102  // Set the input transformation
103 
104 /*****************************
105 
106  // First, try to make a geo transform
107  if (!m_InputProjectionRef.empty()) // map projection
108  {
109  typedef otb::GenericMapProjection<TransformDirection::INVERSE, ScalarType, InputSpaceDimension, InputSpaceDimension> InverseMapProjectionType;
110  typename InverseMapProjectionType::Pointer mapTransform = InverseMapProjectionType::New();
111 
112  mapTransform->SetWkt(m_InputProjectionRef);
113  if (mapTransform->IsProjectionDefined())
114  {
115  m_InputTransform = mapTransform.GetPointer();
116  inputTransformIsMap = true;
117  otbMsgDevMacro(<< "Input projection set to map transform: " << m_InputTransform);
118  }
119  }
120 
121  // If not, try to make a sensor model
122  if ((m_InputTransform.IsNull()) && (m_InputImd != nullptr))
123  {
124  auto sensorModel = otb::SensorTransformFactory::GetInstance().CreateTransform
125  <double, InputSpaceDimension, OutputSpaceDimension>(*m_InputImd,TransformDirection::FORWARD);
126 
127  if (sensorModel != nullptr)
128  {
129  m_InputTransform = sensorModel.GetPointer();
130  inputTransformIsSensor = true;
131  otbMsgDevMacro(<< "Input projection set to RPC model.");
132  }
133  }
134 
135 /*****************************
136  // Set the output transformation
137 
152 
otb::GenericRSTransform::m_OutputProjectionRef
std::string m_OutputProjectionRef
Definition: otbGenericRSTransform.h:206
otb::GenericRSTransform::m_InputSpacing
SpacingType m_InputSpacing
Definition: otbGenericRSTransform.h:208
otb::GenericRSTransform::m_InputProjectionRef
std::string m_InputProjectionRef
Definition: otbGenericRSTransform.h:205
otb::GenericRSTransform::TransformType
otb::CompositeTransform< GenericTransformType, GenericTransformType > TransformType
Definition: otbGenericRSTransform.h:80
otb::GenericRSTransform::InstantiateTransform
virtual void InstantiateTransform()
otb::Projection::UNKNOWN
@ UNKNOWN
Definition: otbGenericRSTransform.h:35
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbSensorTransformFactory.h
otbRPCInverseTransform.h
otbMacro.h
otb::GenericRSTransform::m_InputOrigin
OriginType m_InputOrigin
Definition: otbGenericRSTransform.h:209
otbSpatialReference.h
otb::GenericRSTransform::m_TransformAccuracy
Projection::TransformAccuracy m_TransformAccuracy
Definition: otbGenericRSTransform.h:218
otb::GenericRSTransform::m_OutputImd
const ImageMetadata * m_OutputImd
Definition: otbGenericRSTransform.h:203
otb::GenericRSTransform::m_InputTransform
GenericTransformPointerType m_InputTransform
Definition: otbGenericRSTransform.h:215
otb::GenericRSTransform::GenericRSTransform
GenericRSTransform()
otb::GenericRSTransform::m_OutputSpacing
SpacingType m_OutputSpacing
Definition: otbGenericRSTransform.h:210
otbGenericRSTransform.h
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otbRPCForwardTransform.h
otb::GenericRSTransform::m_Transform
TransformPointerType m_Transform
Definition: otbGenericRSTransform.h:213
otb::GenericRSTransform::m_TransformUpToDate
bool m_TransformUpToDate
Definition: otbGenericRSTransform.h:217
otb::GenericRSTransform::m_OutputOrigin
OriginType m_OutputOrigin
Definition: otbGenericRSTransform.h:211
otb::GenericRSTransform::m_OutputTransform
GenericTransformPointerType m_OutputTransform
Definition: otbGenericRSTransform.h:216
otb::GenericRSTransform::m_InputImd
const ImageMetadata * m_InputImd
Definition: otbGenericRSTransform.h:202
otb::GenericRSTransform::GetTransform
virtual const TransformType * GetTransform() const