OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
RadarSat2NoiseLevel.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
13 #include <ossim/base/ossimDpt3d.h>
15 #include <ossim/base/ossimNotify.h>
16 #include <ossim/base/ossimString.h>
17 
18 
19 namespace ossimplugins
20 {
21 static const char NOISE[] = "referenceNoiseLevel";
22 
23 static const char BETA_NOUGHT[] ="BetaNought";
24 static const char SIGMA_NOUGHT[] ="SigmaNought";
25 static const char GAMMA[] ="Gamma";
26 
27 static const char INCIDENCE_ANGLE_CORRECTION_NAME_KW[] = "incidenceAngleCorrectionName";
28 static const char PIXEL_FIRST_NOISE_VALUE_KW[] = "pixelFirstNoiseValue";
29 static const char STEP_SIZE_KW[] = "stepSize";
30 static const char NUMBER_OF_NOISE_LEVEL_VALUE_KW[] = "numberOfNoiseLevelValues";
31 static const char NOISE_LEVEL_VALUES_KW[] = "noiseLevelValues";
32 static const char UNITS_KW[] = "units";
33 static const char OFFSET_KW[] = "offset";
34 static const char GAIN_KW[] = "gain";
35 static const char SIZE_KW[] = "size";
36 
38  _incidenceAngleCorrectionName("Unknown"),
39  _pixelFirstNoiseValue(0),
40  _stepSize(0),
41  _numberOfNoiseLevelValues(0),
42  _noiseLevelValues(),
43  _units("Unknown"),
44  _offset(0.0),
45  _gain()
46 {
47 }
48 
50 {
51 }
52 
53 
55  _incidenceAngleCorrectionName(rhs._incidenceAngleCorrectionName),
56  _pixelFirstNoiseValue(rhs._pixelFirstNoiseValue),
57  _stepSize(rhs._stepSize),
58  _numberOfNoiseLevelValues(rhs._numberOfNoiseLevelValues),
59  _noiseLevelValues(rhs._noiseLevelValues),
60  _units(rhs._units),
61  _offset(rhs._offset),
62  _gain(rhs._gain)
63 {
64 }
65 
67 {
70  _stepSize = rhs._stepSize;
73  _units = rhs._units;
74  _offset = rhs._offset;
75  _gain = rhs._gain;
76  return *this;
77 }
78 
79 bool RadarSat2NoiseLevel::saveState(ossimKeywordlist& kwl, const char* prefix) const
80 {
81  std::string pfx;
82  if (prefix)
83  {
84  pfx = prefix;
85  }
86  pfx += NOISE;
87 
88  if(_incidenceAngleCorrectionName == "Gamma")
89  {
90  pfx = pfx + "["+ GAMMA +"]";
91  }
92  if(_incidenceAngleCorrectionName == "Sigma Nought")
93  {
94  pfx = pfx + "["+ SIGMA_NOUGHT +"]";
95  }
96  if(_incidenceAngleCorrectionName == "Beta Nought")
97  {
98  pfx = pfx + "["+ BETA_NOUGHT +"]";
99  }
100 
101  pfx +=".";
102 
103  std::string s = pfx + INCIDENCE_ANGLE_CORRECTION_NAME_KW;
104  kwl.add(prefix, s.c_str(), _incidenceAngleCorrectionName);
105 
106  s = pfx + PIXEL_FIRST_NOISE_VALUE_KW;
107  kwl.add(prefix, s.c_str(), _pixelFirstNoiseValue);
108 
109  s = pfx + STEP_SIZE_KW;
110  kwl.add(prefix, s.c_str(), _stepSize);
111 
112  s = pfx + NUMBER_OF_NOISE_LEVEL_VALUE_KW;
113  kwl.add(prefix, s.c_str(), _numberOfNoiseLevelValues);
114 
115  s = pfx + UNITS_KW;
116  kwl.add(prefix, s.c_str(), _units);
117 
118  for (unsigned int i = 0; i < _noiseLevelValues.size(); ++i)
119  {
120  s = pfx + NOISE_LEVEL_VALUES_KW + "[" + ossimString::toString(i).chars() + "]";
121  kwl.add(prefix, s.c_str(), _noiseLevelValues[i]);
122  }
123 
124  s = pfx + OFFSET_KW;
125  kwl.add(prefix, s.c_str(), _offset);
126 
127  s = pfx + GAIN_KW;
128  kwl.add(prefix, s.c_str(), _gain);
129 
130  return true;
131 }
132 
133 bool RadarSat2NoiseLevel::loadState(const ossimKeywordlist& kwl, const char* prefix)
134 {
135  static const char MODULE[] = "RadarSat2NoiseLevel::loadState";
136 
137  //bool result = true;
138  ossimString s;
139  const char* lookup = 0;
140 
141  std::string pfx("");
142  if (prefix)
143  {
144  pfx = prefix;
145  }
146 
147  pfx += NOISE;
148 
149  if(_incidenceAngleCorrectionName == "Gamma")
150  {
151  pfx = pfx + "["+ GAMMA +"]";
152  }
153  if(_incidenceAngleCorrectionName == "Sigma Nought")
154  {
155  pfx = pfx + "["+ SIGMA_NOUGHT +"]";
156  }
157  if(_incidenceAngleCorrectionName == "Beta Nought")
158  {
159  pfx = pfx + "["+ BETA_NOUGHT +"]";
160  }
161 
162 
163 
164  std::string s1 = pfx + "["+ GAMMA +"]";
165  lookup = kwl.find(s1.c_str(), INCIDENCE_ANGLE_CORRECTION_NAME_KW);
166  if (!lookup)
167  {
168  std::string s1 = pfx + "["+ SIGMA_NOUGHT +"]";
169  lookup = kwl.find(s1.c_str(), INCIDENCE_ANGLE_CORRECTION_NAME_KW);
170  if (!lookup)
171  {
172  std::string s1 = pfx + "["+ BETA_NOUGHT +"]";
173  lookup = kwl.find(s1.c_str(), INCIDENCE_ANGLE_CORRECTION_NAME_KW);
174  if (!lookup)
175  {
177  << MODULE << " Keyword not found: " << INCIDENCE_ANGLE_CORRECTION_NAME_KW << "\n";
178  return false;
179  }
180  }
181  }
182 
184  pfx= s1;
185 
186  lookup = kwl.find(s1.c_str(), PIXEL_FIRST_NOISE_VALUE_KW);
187  if (lookup)
188  {
189  s = lookup;
191  }
192  else
193  {
195  << MODULE << " Keyword not found: " << PIXEL_FIRST_NOISE_VALUE_KW << "\n";
196  return false;
197  }
198 
199  lookup = kwl.find(s1.c_str(), STEP_SIZE_KW);
200  if (lookup)
201  {
202  s = lookup;
203  _stepSize = s.toUInt32();
204  }
205  else
206  {
208  << MODULE << " Keyword not found: " << STEP_SIZE_KW << "\n";
209  return false;
210  }
211 
212  lookup = kwl.find(s1.c_str(), NUMBER_OF_NOISE_LEVEL_VALUE_KW);
213  if (lookup)
214  {
215  s = lookup;
217  }
218  else
219  {
221  << MODULE << " Keyword not found: " << NUMBER_OF_NOISE_LEVEL_VALUE_KW << "\n";
222  return false;
223  }
224 
225 
226  lookup = kwl.find(s1.c_str(), UNITS_KW);
227  if (lookup)
228  {
229  _units = lookup;
230  }
231  else
232  {
234  << MODULE << " Keyword not found: " << UNITS_KW << "\n";
235  return false;
236  }
237 
238  _noiseLevelValues.clear();
239  for (unsigned int i = 0; i < _numberOfNoiseLevelValues; ++i)
240  {
241  s = pfx + NOISE_LEVEL_VALUES_KW + "[" + ossimString::toString(i) + "]";
242  lookup = kwl.find(s.c_str(), "");
243  if (lookup)
244  {
245  s = lookup;
246  _noiseLevelValues.push_back( s.toDouble() );
247  }
248  }
249 
251  {
253  << MODULE
254  << " Keyword " << NOISE_LEVEL_VALUES_KW
255  << " is different with the number of noise level values"
256  << std::endl;
257  return false;
258  }
259 
260  lookup = kwl.find(s1.c_str(), GAIN_KW);
261  if (lookup)
262  {
263  _gain = lookup;;
264  }
265  else
266  {
268  << MODULE << " Keyword not found: " << GAIN_KW << "\n";
269  return false;
270  }
271 
272  lookup = kwl.find(s1.c_str(), OFFSET_KW);
273  if (lookup)
274  {
275  s = lookup;
276  _offset = s.toFloat64();
277  }
278  else
279  {
281  << MODULE << " Keyword not found: " << OFFSET_KW << "\n";
282  return false;
283  }
284 
286  {
288  << MODULE
289  << " Keyword " << NOISE_LEVEL_VALUES_KW
290  << " is different with the number of noise level values"
291  << std::endl;
292  return false;
293  }
294 
295 
296  return true;
297 }
298 
299 
301 {
302  out << setprecision(15) << setiosflags(ios::fixed)
303  << "\n RadarSat2NoiseLevel class data members:\n";
304 
305  //const char* prefix = 0;
306  //ossimKeywordlist kwl;
307  //ossimString pfx;
308 
309  /* TODO Add print method*/
310 
311  //out << kwl;
312 
313  return out;
314 }
315 
316 }
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual std::ostream & print(std::ostream &out) const
RadarSat2NoiseLevel & operator=(const RadarSat2NoiseLevel &rhs)
Affectation operator.
static ossimString toString(bool aValue)
Numeric to string methods.
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
ossim_uint32 toUInt32() const
ossimString _incidenceAngleCorrectionName
Incidence Angle correction Name.
std::vector< ossim_float64 > _noiseLevelValues
noise Level Values
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
double toDouble() const
ossim_float64 toFloat64() const
ossim_uint32 _pixelFirstNoiseValue
pixel First Noise Value
This class represents an Noise.
ossim_uint32 _numberOfNoiseLevelValues
number Of Noise Level Values
ossim_float64 _offset
offset value
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual ~RadarSat2NoiseLevel()
Destructor.
ossimString _units
noise Level units
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23