OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ImageNoise.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 
12 #include <otb/ImageNoise.h>
13 #include <ossim/base/ossimDpt3d.h>
15 #include <ossim/base/ossimNotify.h>
16 #include <ossim/base/ossimString.h>
17 
18 namespace ossimplugins
19 {
20 
21 
22 static const char PREFIX[] = "imageNoise.";
23 // static const char TIME_UTC[] = "timeUTC";
24 static const char UTC_TIME[] = "timeUTC";
25 static const char NOISE_ESTIMATE[] = "noiseEstimate.";
26 static const char REFERENCE_POINT[] = "referencePoint";
27 static const char VALIDITY_RANGE_MIN[] = "validityRangeMin";
28 static const char VALIDITY_RANGE_MAX[] = "validityRangeMax";
29 static const char POLYNOMIAL_DEGREE[] = "polynomialDegree";
30 static const char COEFFICIENT[] = "coefficient";
31 static const char NOISE_ESTIMATE_CONFIDENCE[] = "noiseEstimateConfidence";
32 
34  _timeUTC(),
35  _validityRangeMin(0.),
36  _validityRangeMax(0.),
37  _referencePoint(0.),
38  _polynomialDegree(0),
39  _polynomialCoefficients(0)
40 {
41 }
42 
44 {
45 }
46 
47 
49  _timeUTC(rhs._timeUTC),
50  _validityRangeMin(rhs._validityRangeMin),
51  _validityRangeMax(rhs._validityRangeMax),
52  _referencePoint(rhs._referencePoint),
53  _polynomialDegree(rhs._polynomialDegree),
54  _polynomialCoefficients(rhs._polynomialCoefficients)
55 {
56 }
57 
59 {
60  _timeUTC = rhs._timeUTC;
66  return *this;
67 }
68 
69 bool ImageNoise::saveState(ossimKeywordlist& kwl, const char* prefix) const
70 {
71  std::string pfx;
72  std::string pfx2;
73  if (prefix)
74  {
75  pfx = prefix;
76  }
77  pfx += PREFIX;
78  kwl.add(pfx.c_str(), UTC_TIME, _timeUTC);
79 
80  pfx2 = pfx + NOISE_ESTIMATE;
81  kwl.add(pfx2.c_str(), VALIDITY_RANGE_MIN, _validityRangeMin);
82  kwl.add(pfx2.c_str(), VALIDITY_RANGE_MAX, _validityRangeMax);
83  kwl.add(pfx2.c_str(), REFERENCE_POINT, _referencePoint);
84  kwl.add(pfx2.c_str(), POLYNOMIAL_DEGREE, _polynomialDegree);
85 
86  for(unsigned int i=0 ; i<_polynomialCoefficients.size();i++)
87  {
89  ossimString kw = ossimString(COEFFICIENT) + "["+iStr+ "]";
90  kwl.add(pfx2.c_str(), kw.c_str(), _polynomialCoefficients[i]);
91  }
92 
93  return true;
94 }
95 
96 bool ImageNoise::loadState(const ossimKeywordlist& kwl, const char* prefix)
97 {
98  static const char MODULE[] = "ImageNoise::loadState";
99  bool result = true;
100  std::string pfx;
101  std::string pfx2;
102  if (prefix)
103  {
104  pfx = prefix;
105  }
106  ossimString s;
107  const char* lookup = 0;
108 
109  pfx += PREFIX;
110  lookup = kwl.find(pfx.c_str(), UTC_TIME);
111  if (lookup)
112  {
113  s = lookup;
114  _timeUTC = s;
115  }
116  else
117  {
119  << MODULE << " Keyword not found: " << UTC_TIME << " in "<<pfx.c_str()<<" path.\n";
120  result = false;
121  }
122  pfx2 = pfx + NOISE_ESTIMATE;
123  lookup = kwl.find(pfx2.c_str(), VALIDITY_RANGE_MIN);
124  if (lookup)
125  {
126  s = lookup;
128  }
129  else
130  {
132  << MODULE << " Keyword not found: " << VALIDITY_RANGE_MIN << " in "<<pfx2.c_str()<<" path.\n";
133  result = false;
134  }
135  lookup = kwl.find(pfx2.c_str(), VALIDITY_RANGE_MAX);
136  if (lookup)
137  {
138  s = lookup;
140  }
141  else
142  {
144  << MODULE << " Keyword not found: " << VALIDITY_RANGE_MAX << " in "<<pfx2.c_str()<<" path\n";
145  result = false;
146  }
147  lookup = kwl.find(pfx2.c_str(), REFERENCE_POINT);
148  if (lookup)
149  {
150  s = lookup;
152  }
153  else
154  {
156  << MODULE << " Keyword not found: " << REFERENCE_POINT << " in "<<pfx2.c_str()<<" path\n";
157  result = false;
158  }
159  lookup = kwl.find(pfx2.c_str(), POLYNOMIAL_DEGREE);
160  if (lookup)
161  {
162  s = lookup;
164  }
165  else
166  {
168  << MODULE << " Keyword not found: " << POLYNOMIAL_DEGREE << " in "<<pfx2.c_str()<<" path\n";
169  result = false;
170  }
171 
172  for(unsigned int i=0 ; i<_polynomialDegree+1;i++)
173  {
175  ossimString kw = ossimString(COEFFICIENT) + "["+iStr+ "]";
176  lookup = kwl.find(pfx2.c_str(), kw.c_str());
177  if (lookup)
178  {
179  s = lookup;
180  _polynomialCoefficients.push_back( s.toDouble() );
181  }
182  else
183  {
185  << MODULE << " Keyword not found: " << kw.c_str() << " in "<<pfx2.c_str()<<" path\n";
186  result = false;
187  }
188  }
189 
190 
191 /*
192  pfx += "ImageNoise.";
193 
194  const char* lookup = 0;
195  ossimString s;
196  double d;
197 
198  lookup = kwl.find(pfx.c_str(), DATE_JULIAN_KW);
199  if (lookup)
200  {
201  s = lookup;
202  d = s.toDouble();
203  JulianDate jd(d);
204  _date.set_day0hTU(jd);
205  }
206  else
207  {
208  ossimNotify(ossimNotifyLevel_WARN)
209  << MODULE << " Keyword not found: " << DATE_JULIAN_KW << "\n";
210 
211  result = false;
212  }
213 
214  lookup = kwl.find(pfx.c_str(), DATE_SECOND_KW);
215  if (lookup)
216  {
217  s = lookup;
218  d = s.toDouble();
219  _date.set_second(d);
220  }
221  else
222  {
223  ossimNotify(ossimNotifyLevel_WARN)
224  << MODULE << " Keyword not found: " << DATE_SECOND_KW << "\n";
225  result = false;
226  }
227 
228  lookup = kwl.find(pfx.c_str(), DATE_DECIMAL_KW);
229  if (lookup)
230  {
231  s = lookup;
232  d = s.toDouble();
233  _date.set_decimal(d);
234  }
235  else
236  {
237  ossimNotify(ossimNotifyLevel_WARN)
238  << MODULE << " Keyword not found: " << DATE_DECIMAL_KW << "\n";
239  result = false;
240  }
241 
242  lookup = kwl.find(pfx.c_str(), POSITION_KW);
243  if (lookup)
244  {
245  std::string ps = lookup;
246 
247  ossimDpt3d pt;
248  pt.toPoint(ps);
249 
250  _position[0] = pt.x;
251  _position[1] = pt.y;
252  _position[2] = pt.z;
253  }
254  else
255  {
256  ossimNotify(ossimNotifyLevel_WARN)
257  << MODULE << " Keyword not found: " << POSITION_KW << "\n";
258  result = false;
259  }
260 
261  lookup = kwl.find(pfx.c_str(), VELOCITY_KW);
262  if (lookup)
263  {
264  std::string ps = lookup;
265 
266  ossimDpt3d pt;
267  pt.toPoint(ps);
268 
269  _speed[0] = pt.x;
270  _speed[1] = pt.y;
271  _speed[2] = pt.z;
272  }
273  else
274  {
275  ossimNotify(ossimNotifyLevel_WARN)
276  << MODULE << " Keyword not found: " << VELOCITY_KW << "\n";
277  result = false;
278  }
279 */
280  return result;
281 }
282 }
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
Definition: ImageNoise.cpp:69
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual ~ImageNoise()
Destructor.
Definition: ImageNoise.cpp:43
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_int32 toInt32() const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
double _validityRangeMin
ValidityRangeMin (Noise/ImageNoise node).
Definition: ImageNoise.h:139
This class represents an ImageNoise.
Definition: ImageNoise.h:30
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
Definition: ImageNoise.cpp:96
double toDouble() const
ImageNoise()
Constructor.
Definition: ImageNoise.cpp:33
double _referencePoint
Reference point (Noise/ImageNoise node).
Definition: ImageNoise.h:147
std::vector< double > _polynomialCoefficients
Polynomial coefficients (Noise/ImageNoise node).
Definition: ImageNoise.h:156
double _validityRangeMax
ValidityRangeMax (Noise/ImageNoise node).
Definition: ImageNoise.h:143
ossimString _timeUTC
TimeUTC (Noise/ImageNoise node).
Definition: ImageNoise.h:134
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
unsigned int _polynomialDegree
Polynomial degree (Noise/ImageNoise node).
Definition: ImageNoise.h:152
ImageNoise & operator=(const ImageNoise &rhs)
Affectation operator.
Definition: ImageNoise.cpp:58
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)