21 #ifndef otbReduceSpectralResponse_hxx
22 #define otbReduceSpectralResponse_hxx
25 #include "itkNumericTraits.h"
31 template <
class TSpectralResponse,
class TRSR>
37 template <
class TSpectralResponse,
class TRSR>
40 return (m_InputSatRSR->Clear() & m_InputSpectralResponse->Clear());
62 return (x2 - x1) * std::min(y1, y2) + (x2 - x1) * fabs(y2 - y1) * 0.5;
65 template <
class TSpectralResponse,
class TRSR>
69 if (numBand >= m_InputSatRSR->GetNbBands())
71 itkExceptionMacro(<<
"There is no band num " << numBand <<
" in the RSR vector!(Size of the current RSR vector is " << m_InputSatRSR->GetNbBands() <<
")");
76 typename InputRSRType::SpectralResponseType* solarIrradiance = this->m_InputSatRSR->GetSolarIrradiance();
78 if (m_ReflectanceMode)
80 if (solarIrradiance ==
nullptr)
82 itkExceptionMacro(<<
"Error occurs getting solar irradiance. Solar irradiance is mandatory using the reflectance mode.");
85 typename VectorPairType::const_iterator it;
86 VectorPairType pairs = (m_InputSatRSR->GetRSR())[numBand]->GetResponse();
91 while (it != pairs.end())
95 if (rsr1 > 0 || rsr2 > 0)
112 if (m_ReflectanceMode)
114 solarIrradiance1 = (*solarIrradiance)(lambda1);
115 solarIrradiance2 = (*solarIrradiance)(lambda2);
117 rsr1 *= solarIrradiance1;
118 rsr2 *= solarIrradiance2;
119 res +=
trapezoid_area(lambda1, lambda2, rsr1 * spectrum1, rsr2 * spectrum2);
124 return res / totalArea;
128 template <
class TSpectralResponse,
class TRSR>
131 m_ReduceResponse->Clear();
133 for (
unsigned int i = 0; i < m_InputSatRSR->GetNbBands(); ++i)
135 m_InputSpectralResponse->SetPosGuessMin((this->m_InputSatRSR->GetRSR())[i]->GetInterval().first);
136 m_InputSpectralResponse->SetUsePosGuess(
true);
139 pair.first = ((this->m_InputSatRSR->GetRSR())[i]->GetInterval().first + (this->m_InputSatRSR->GetRSR())[i]->GetInterval().second);
140 pair.first = pair.first / 2.0;
141 pair.second = (*this)(i);
142 m_ReduceResponse->GetResponse().push_back(pair);
143 m_InputSpectralResponse->SetUsePosGuess(
false);
148 template <
class TSpectralResponse,
class TRSR>
154 m_InputSpectralResponse = InputSpectralResponseType::New();
156 m_InputSpectralResponse->Load(spectralResponseFile, coefNormSpectre);
158 m_InputSatRSR = InputRSRType::New();
160 m_InputSatRSR->SetNbBands(nbRSRBands);
163 m_InputSatRSR->Load(RSRFile, coefNormRSR);
167 template <
class TSpectralResponse,
class TRSR>
170 Superclass::PrintSelf(os, indent);
172 os <<
"spectre " << m_InputSpectralResponse << std::endl;
173 os <<
"Sat RSR " << m_InputSatRSR << std::endl;
176 if (m_ReflectanceMode)
178 os <<
"Solar irradiance " << std::endl;
179 this->m_InputSatRSR->GetSolarIrradiance()->PrintSelf(os, indent);
181 os << indent <<
"[Center Wavelength (micrometers), Reflectance (percent)]" << std::endl;
185 os << indent <<
"[Center Wavelength (micrometers), Radiance (percent)]" << std::endl;
188 for (
typename VectorPairType::const_iterator it = m_ReduceResponse->GetResponse().begin(); it != m_ReduceResponse->GetResponse().end(); ++it)
190 os << indent <<
"Band Nb : " << it - m_ReduceResponse->GetResponse().begin() <<
": [" << (*it).first <<
"," << (*it).second <<
"]" << std::endl;