OTB  9.0.0
Orfeo Toolbox
otbSatelliteRSR.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 otbSatelliteRSR_hxx
22 #define otbSatelliteRSR_hxx
23 
24 #include "otbSatelliteRSR.h"
25 
26 namespace otb
27 {
28 
29 template <class TPrecision, class TValuePrecision>
31 {
32  // m_RSR = VectorType::New();
33  m_SortBands = true;
34  m_SolarIrradiance = SpectralResponseType::New();
35 }
36 
37 template <class TPrecision, class TValuePrecision>
38 void SatelliteRSR<TPrecision, TValuePrecision>::Load(const std::string& filename, ValuePrecisionType coefNormalization)
39 {
40  // Parse 6S file Reduce spectral response
41  // Begin by getting the number of band of the satellite
42  // unsigned int nbBands= this->SetNbBands ( filename );
43  std::ifstream fin(filename);
44  if (fin.fail())
45  {
46  itkExceptionMacro(<< "Error opening file" << filename);
47  }
48 
49  // For each band
50  for (unsigned int i = 0; i < m_NbBands; ++i)
51  {
52  // Create a SpectralResponse for the band i
53  SpectralResponsePointerType RSRBand = SpectralResponseType::New();
54  m_RSR.push_back(RSRBand);
55  }
56  PrecisionType currentLambda;
57  PrecisionType solarIrradiance;
58  while (!fin.eof())
59  {
60  // Parse the 6S.txt file
61  fin >> currentLambda;
62  fin >> solarIrradiance;
63 
64  m_SolarIrradiance->GetResponse().push_back(std::make_pair(currentLambda, solarIrradiance));
65  // for each band add a pair of values (wavelength and % response)
66  for (unsigned int i = 0; i < m_NbBands; ++i)
67  {
68  std::pair<TPrecision, TValuePrecision> currentPair;
69  currentPair.first = currentLambda;
70  fin >> currentPair.second;
71  currentPair.second = currentPair.second / coefNormalization;
72  // Include only non null value //TODO
73  m_RSR[i]->GetResponse().push_back(currentPair);
74  }
75  }
76  fin.close();
77 
78  if (m_SortBands)
79  {
80  // Sort the vector of SpectralResponse (band order by minimum wavelength first not null response
81  std::sort(m_RSR.begin(), m_RSR.end(), sort_band());
82  }
83 }
84 
85 template <class TPrecision, class TValuePrecision>
87  ValuePrecisionType coefNormalization)
88 {
89  m_NbBands = 1;
90  const double wavelengthPrecision = 0.0025; // in um
91 
92  if (0 == sampling)
93  {
94  sampling = wavelengthPrecision;
95  }
96 
97  // For each band
98  for (unsigned int i = 0; i < m_NbBands; ++i)
99  {
100  // Create a SpectralResponse for the band i
101  SpectralResponsePointerType RSRBand = SpectralResponseType::New();
102  m_RSR.push_back(RSRBand);
103  }
104 
105  PrecisionType currentLambda;
106  ValuePrecisionType value = 1.0;
107 
108  for (double j = lambdaMin; j < lambdaMax; j = j + sampling)
109  {
110  currentLambda = j;
111  std::pair<TPrecision, TValuePrecision> currentPair;
112  currentPair.first = currentLambda;
113  currentPair.second = value / coefNormalization;
114  m_RSR[0]->GetResponse().push_back(currentPair);
115  }
116 }
117 
118 template <class TPrecision, class TValuePrecision>
120 {
121  m_RSR.clear();
122  return true;
123 }
124 
125 template <class TPrecision, class TValuePrecision>
127 {
128  return m_RSR.size();
129 }
130 
131 template <class TPrecision, class TValuePrecision>
133  const unsigned int numBand)
134 {
135  // Get the response of the band number numBand at the wavelength lambda
136  if (numBand >= m_NbBands)
137  {
138  itkExceptionMacro(<< "There is no band num " << numBand << " in the RSR vector!(Size of the current RSR vector is " << m_NbBands << ")");
139  }
140  else
141  {
142  return (*(m_RSR[numBand]))(lambda);
143  }
144 }
145 
146 template <class TPrecision, class TValuePrecision>
147 void SatelliteRSR<TPrecision, TValuePrecision>::PrintSelf(std::ostream& os, itk::Indent indent) const
148 {
149  Superclass::PrintSelf(os, indent);
150  os << std::endl;
151 
152  // typename VectorPairType::iterator it = m_RSR.begin();
153  // it = m_RSR.at(0);
154  for (typename RSRVectorType::const_iterator it = m_RSR.begin(); it != m_RSR.end(); ++it)
155  {
156  os << indent << "Band Number " << it - m_RSR.begin() << std::endl;
157  (*it)->PrintSelf(os, indent);
158  os << std::endl;
159  }
160 }
161 
162 } // end namespace otb
163 
164 #endif
otb::SatelliteRSR::ValuePrecisionType
TValuePrecision ValuePrecisionType
Definition: otbSatelliteRSR.h:77
otb::SatelliteRSR::operator()
ValuePrecisionType operator()(const PrecisionType &lambda, const unsigned int numBand)
Definition: otbSatelliteRSR.hxx:132
otb::SatelliteRSR::sort_band
Definition: otbSatelliteRSR.h:97
otb::SatelliteRSR::PrecisionType
TPrecision PrecisionType
Definition: otbSatelliteRSR.h:72
otb::SatelliteRSR::SatelliteRSR
SatelliteRSR()
Definition: otbSatelliteRSR.hxx:30
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SatelliteRSR::Size
virtual int Size() const
Definition: otbSatelliteRSR.hxx:126
otb::SatelliteRSR::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbSatelliteRSR.hxx:147
otb::SatelliteRSR::Clear
virtual bool Clear()
Definition: otbSatelliteRSR.hxx:119
otb::SatelliteRSR::Load
void Load(const std::string &filename, ValuePrecisionType coefNormalization=1.0)
Definition: otbSatelliteRSR.hxx:38
otb::SatelliteRSR::SpectralResponsePointerType
SpectralResponseType::Pointer SpectralResponsePointerType
Definition: otbSatelliteRSR.h:80
otbSatelliteRSR.h