OTB  9.0.0
Orfeo Toolbox
otbSurfaceReflectanceToReflectanceFilter.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 otbSurfaceReflectanceToReflectanceFilter_hxx
22 #define otbSurfaceReflectanceToReflectanceFilter_hxx
23 
25 
26 namespace otb
27 {
28 
32 template <class TInputImage, class TOutputImage>
34  : m_IsSetAtmosphericRadiativeTerms(false), m_IsSetAtmoCorrectionParameters(false), m_IsSetAcquiCorrectionParameters(false), m_UseGenerateParameters(true)
35 {
39 }
41 
42 
43 template <class TInputImage, class TOutputImage>
45 {
46  if (this->GetInput() == nullptr)
47  {
48  itkExceptionMacro(<< "Input must be set before updating the atmospheric radiative terms");
49  }
50 
51  // Atmospheric parameters
52  if (!m_IsSetAtmoCorrectionParameters)
53  {
54  itkExceptionMacro(<< "Atmospheric correction parameters must be provided before updating the atmospheric radiative terms");
55  }
56 
57  // Acquisition parameters
58  if (!m_IsSetAcquiCorrectionParameters) // Get info from image metadata
59  {
60  const auto & metadata = this->GetInput()->GetImageMetadata();
61 
62  m_AcquiCorrectionParameters = AcquiCorrectionParametersType::New();
63 
64  m_AcquiCorrectionParameters->SetSolarZenithalAngle(90. - metadata[MDNum::SunElevation]);
65  m_AcquiCorrectionParameters->SetSolarAzimutalAngle(metadata[MDNum::SunAzimuth]);
66  m_AcquiCorrectionParameters->SetViewingZenithalAngle(90. - metadata[MDNum::SatElevation]);
67  m_AcquiCorrectionParameters->SetViewingAzimutalAngle(metadata[MDNum::SatAzimuth]);
68 
69  m_AcquiCorrectionParameters->SetDay(metadata[MDTime::AcquisitionDate].GetDay());
70  m_AcquiCorrectionParameters->SetMonth(metadata[MDTime::AcquisitionDate].GetMonth());
71 
72 
73  if (metadata.HasBandMetadata(MDL1D::SpectralSensitivity))
74  {
75  auto spectralSensitivity = AcquiCorrectionParametersType::InternalWavelengthSpectralBandVectorType::New();
76  for (const auto & band : metadata.Bands)
77  {
78  const auto & spectralSensitivityLUT = band[MDL1D::SpectralSensitivity];
79  const auto & axis = spectralSensitivityLUT.Axis[0];
80  auto filterFunction = FilterFunctionValues::New();
81  // LUT1D stores a double vector whereas FilterFunctionValues stores a float vector
82  std::vector<float> vec(spectralSensitivityLUT.Array.begin(), spectralSensitivityLUT.Array.end());
83  filterFunction->SetFilterFunctionValues(vec);
84  filterFunction->SetMinSpectralValue(axis.Origin);
85  filterFunction->SetMaxSpectralValue(axis.Origin + axis.Spacing * (axis.Size-1));
86  filterFunction->SetUserStep(axis.Spacing);
87  spectralSensitivity->PushBack(filterFunction);
88  }
89 
90  m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralSensitivity);
91  }
92  else
93  {
94  otbMsgDevMacro(<< "use dummy filter");
95  WavelengthSpectralBandVectorType spectralDummy = AcquiCorrectionParametersType::InternalWavelengthSpectralBandVectorType::New();
96  spectralDummy->Clear();
97  for (unsigned int i = 0; i < this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
98  {
99  spectralDummy->PushBack(FilterFunctionValuesType::New());
100  }
101  m_AcquiCorrectionParameters->SetWavelengthSpectralBand(spectralDummy);
102  }
103 
104  }
105 
106  m_AtmosphericRadiativeTerms = CorrectionParametersToRadiativeTermsType::Compute(m_AtmoCorrectionParameters, m_AcquiCorrectionParameters);
107 }
108 
109 
110 template <class TInputImage, class TOutputImage>
112 {
113  Superclass::BeforeThreadedGenerateData();
114  if (m_UseGenerateParameters)
115  this->GenerateParameters();
116 }
117 
118 template <class TInputImage, class TOutputImage>
120 {
121  Superclass::Modified();
122  m_FunctorParametersHaveBeenComputed = false;
123 }
124 
125 template <class TInputImage, class TOutputImage>
127 {
128  // this->GetFunctor().clear();
129 
130  // for (unsigned int i = 0; i<this->GetInput()->GetNumberOfComponentsPerPixel(); ++i)
131  for (unsigned int i = 0; i < m_AtmosphericRadiativeTerms->GetWavelengthSpectralBand().size(); ++i)
132  {
133  double coef;
134  double res;
135  coef = static_cast<double>(m_AtmosphericRadiativeTerms->GetTotalGaseousTransmission(i) * m_AtmosphericRadiativeTerms->GetDownwardTransmittance(i) *
136  m_AtmosphericRadiativeTerms->GetUpwardTransmittance(i));
137  // coef = 1. / coef;
138  // res = -m_AtmosphericRadiativeTerms->GetIntrinsicAtmosphericReflectance(i) * coef;
139  res = m_AtmosphericRadiativeTerms->GetIntrinsicAtmosphericReflectance(i);
140  FunctorType functor;
141  functor.SetCoefficient(coef);
142  functor.SetResidu(res);
143  functor.SetSphericalAlbedo(static_cast<double>(m_AtmosphericRadiativeTerms->GetSphericalAlbedo(i)));
144 
145  this->GetFunctorVector().push_back(functor);
146  // this->SetFunctor(functor);
147  }
148 }
149 
150 
151 template <class TInputImage, class TOutputImage>
153 {
154 
155  if (!m_IsSetAtmosphericRadiativeTerms)
156  {
157  this->UpdateAtmosphericRadiativeTerms();
158  m_IsSetAtmosphericRadiativeTerms = true;
159  }
160 
161  if (!m_FunctorParametersHaveBeenComputed)
162  {
163  this->UpdateFunctors();
164  m_FunctorParametersHaveBeenComputed = true;
165  }
166 }
167 }
168 
169 #endif
otb::MDNum::SatElevation
@ SatElevation
otb::SurfaceReflectanceToReflectanceFilter::m_AtmosphericRadiativeTerms
AtmosphericRadiativeTermsPointerType m_AtmosphericRadiativeTerms
Definition: otbSurfaceReflectanceToReflectanceFilter.h:297
otb::MDTime::AcquisitionDate
@ AcquisitionDate
otb::Functor::ReflectanceToSurfaceReflectanceImageFunctor
Compute the surface reflectance pixel from a TOA reflectance.
Definition: otbReflectanceToSurfaceReflectanceImageFilter.h:50
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::ReflectanceToSurfaceReflectanceImageFunctor::SetCoefficient
void SetCoefficient(double coef)
Definition: otbReflectanceToSurfaceReflectanceImageFilter.h:80
otb::SurfaceReflectanceToReflectanceFilter::m_AtmoCorrectionParameters
AtmoCorrectionParametersPointerType m_AtmoCorrectionParameters
Definition: otbSurfaceReflectanceToReflectanceFilter.h:298
otb::SurfaceReflectanceToReflectanceFilter::UpdateAtmosphericRadiativeTerms
void UpdateAtmosphericRadiativeTerms()
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:44
otb::Functor::ReflectanceToSurfaceReflectanceImageFunctor::SetResidu
void SetResidu(double res)
Definition: otbReflectanceToSurfaceReflectanceImageFilter.h:93
otb::Functor::ReflectanceToSurfaceReflectanceImageFunctor::SetSphericalAlbedo
void SetSphericalAlbedo(double albedo)
Definition: otbReflectanceToSurfaceReflectanceImageFilter.h:67
otb::SurfaceReflectanceToReflectanceFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:111
otb::SurfaceReflectanceToReflectanceFilter::m_AcquiCorrectionParameters
AcquiCorrectionParametersPointerType m_AcquiCorrectionParameters
Definition: otbSurfaceReflectanceToReflectanceFilter.h:299
otb::MDNum::SunAzimuth
@ SunAzimuth
otb::MDNum::SatAzimuth
@ SatAzimuth
otb::SurfaceReflectanceToReflectanceFilter::WavelengthSpectralBandVectorType
AcquiCorrectionParametersType::WavelengthSpectralBandVectorType WavelengthSpectralBandVectorType
Definition: otbSurfaceReflectanceToReflectanceFilter.h:219
otb::SurfaceReflectanceToReflectanceFilter::Modified
void Modified() const override
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:119
otb::FilterFunctionValues::New
static Pointer New()
otbSurfaceReflectanceToReflectanceFilter.h
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::ImageMetadataCorrectionParameters::New
static Pointer New()
otb::AtmosphericRadiativeTerms::New
static Pointer New()
otb::SurfaceReflectanceToReflectanceFilter::SurfaceReflectanceToReflectanceFilter
SurfaceReflectanceToReflectanceFilter()
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:33
otb::AtmosphericCorrectionParameters::New
static Pointer New()
otb::SurfaceReflectanceToReflectanceFilter::GenerateParameters
void GenerateParameters()
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:152
otb::MDL1D::SpectralSensitivity
@ SpectralSensitivity
otb::MDNum::SunElevation
@ SunElevation
otb::SurfaceReflectanceToReflectanceFilter::UpdateFunctors
void UpdateFunctors()
Definition: otbSurfaceReflectanceToReflectanceFilter.hxx:126