OTB  6.7.0
Orfeo Toolbox
otbSentinel1ImageMetadataInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbSentinel1ImageMetadataInterface_h
22 #define otbSentinel1ImageMetadataInterface_h
23 
25 
26 
27 namespace otb
28 {
38 {
39 public:
40 
45 
47  itkNewMacro(Self);
48 
49 
52 
53  typedef Superclass::ImageType ImageType;
54  typedef Superclass::MetaDataDictionaryType MetaDataDictionaryType;
57  typedef Superclass::ImageKeywordlistType ImageKeywordlistType;
59  typedef Superclass::LookupDataPointerType LookupDataPointerType;
60 
62  int GetProductionDay() const override;
63 
65  int GetProductionMonth() const override;
66 
68  int GetProductionYear() const override;
69 
71  bool CanRead() const override;
72 
73  int GetDay() const override;
74 
75  int GetMonth() const override;
76 
77  int GetYear() const override;
78 
79  int GetHour() const override;
80 
81  int GetMinute() const override;
82 
83  UIntVectorType GetDefaultDisplay() const override;
84 
85  /*SarImageMetadataInterface pure virutals rituals */
86  double GetPRF() const override;
87 
88  double GetRSF() const override;
89 
90  double GetRadarFrequency() const override;
91 
92  double GetCenterIncidenceAngle() const override;
93 
94  /*get lookup data for calculating backscatter */
95  void CreateCalibrationLookupData(const short type) override;
96 
97 protected:
98 
99  /* class ctor */
101 
102  /* class dtor */
104 
105 private:
106 
107  Sentinel1ImageMetadataInterface(const Self &) = delete;
108  void operator =(const Self&) = delete;
109 
110 /* Helper function to parse date and time into a std::vector<std::string>
111  * using boost::split() expect date time in yyyy-mm-ddThh:mm:ss.ms
112  * the date-time string is to be found in keywordlist with key 'key'
113  * fills argument dateFields of type std::vector<std::string> which is mutable!
114  * TODO: move this method into base class
115  */
116  void ParseDateTime(const char* key, std::vector<int>& dateFields) const;
117 
118  mutable std::vector<int> m_ProductionDateFields;
119  mutable std::vector<int> m_AcquisitionDateFields;
120 };
121 
122 
123 
125 {
126 public:
127  double timeMJD;
128  double deltaMJD; // time difference to previous MJD in the list
129  int line;
130  std::vector<int> pixels;
131  std::vector<double> deltaPixels;
132  std::vector<float> vect;
133 };
134 
136 {
137 public:
138 
144 
146  itkNewMacro(Self);
147 
150 
152 
154  : firstLineTime(0.)
155  , lastLineTime(0.)
156  , numOfLines(0)
157  , count(0)
158  , lineTimeInterval(0.)
159  {
160  }
161 
163  {
164  }
165 
166  void InitParameters(short type, double ft, double lt,
167  int lines, int c,
168  std::vector<Sentinel1CalibrationStruct> const& vlist)
169  {
170  firstLineTime = ft;
171  lastLineTime = lt;
172  numOfLines = lines;
173  count = c;
174  calibrationVectorList = vlist;
175  this->SetType(type);
176  lineTimeInterval = (lt - ft) / ((lines - 1) * 1.0);
177  }
178 
179  double GetValue(const IndexValueType x, const IndexValueType y) const override
180  {
181  const int calVecIdx = GetVectorIndex(y);
182  assert(calVecIdx>=0 && calVecIdx < count-1);
183  const Sentinel1CalibrationStruct & vec0 = calibrationVectorList[calVecIdx];
184  const Sentinel1CalibrationStruct & vec1 = calibrationVectorList[calVecIdx + 1];
185  const double azTime = firstLineTime + y * lineTimeInterval;
186  const double muY = (azTime - vec0.timeMJD) / vec1.deltaMJD;
187  const int pixelIdx = GetPixelIndex(x, calibrationVectorList[calVecIdx]);
188  const double muX = (x - vec0.pixels[pixelIdx]) / vec0.deltaPixels[pixelIdx + 1];
189  const double lutVal
190  = (1 - muY) * ((1 - muX) * vec0.vect[pixelIdx] + muX * vec0.vect[pixelIdx + 1])
191  + muY * ((1 - muX) * vec1.vect[pixelIdx] + muX * vec1.vect[pixelIdx + 1]);
192  return lutVal;
193  }
194 
195  int GetVectorIndex(int y) const
196  {
197  for (int i = 1; i < count; i++)
198  {
199  if (y < calibrationVectorList[i].line)
200  {
201  return i - 1;
202  }
203  }
204  return -1;
205  }
206 
207  int GetPixelIndex(int x, const Sentinel1CalibrationStruct& calVec) const
208  {
209  const int size = calVec.pixels.size();
210  std::vector<int>::const_iterator wh = std::upper_bound(calVec.pixels.begin(), calVec.pixels.end(), x);
211  return wh == calVec.pixels.end() ? size - 2 : std::distance(calVec.pixels.begin(),wh)-1;
212  }
213 
214 private:
215 
216  Sentinel1CalibrationLookupData(const Self&) = delete;
217 
218  void operator =(const Self&) = delete;
219 
221  double lastLineTime;
223  int count;
224  std::vector<Sentinel1CalibrationStruct> calibrationVectorList;
226 };
227 
228 
229 } // end namespace otb
230 
231 #endif
int GetPixelIndex(int x, const Sentinel1CalibrationStruct &calVec) const
std::vector< unsigned int > UIntVectorType
std::vector< double > VectorType
void InitParameters(short type, double ft, double lt, int lines, int c, std::vector< Sentinel1CalibrationStruct > const &vlist)
Superclass::MetaDataDictionaryType MetaDataDictionaryType
signed long IndexValueType
itk::VariableLengthVector< double > VariableLengthVectorType
Class for SAR captor metadata reading.
std::vector< Sentinel1CalibrationStruct > calibrationVectorList
Monteverdi_FLOATING_TYPE RealType
Definition: mvdTypes.h:84
Creation of an "otb" Sentinel1ImageMetadataInterface that gets metadata.
double GetValue(const IndexValueType x, const IndexValueType y) const override
void operator=(const Self &)=delete
Superclass::ImageKeywordlistType ImageKeywordlistType
Superclass::LookupDataPointerType LookupDataPointerType
Superclass::VariableLengthVectorType VariableLengthVectorType