OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Noise.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/Noise.h>
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[] = "noise";
22 static const char NUMBER_OF_NOISE_RECORDS_KW[] = "numberOfNoiseRecords";
23 static const char NAME_OF_NOISE_POLARISATION_KW[] = "nameOfNoisePolarisation";
24 
26  _numberOfNoiseRecords(0),
27  _tabImageNoise(),
28  _polarisation("UNDEFINED")
29 {
30 }
31 
33 {
34 }
35 
36 
37 Noise::Noise(const Noise& rhs):
38  _numberOfNoiseRecords(rhs._numberOfNoiseRecords),
39  _tabImageNoise(rhs._tabImageNoise),
40  _polarisation(rhs._polarisation)
41 {
42 }
43 
45 {
49  return *this;
50 }
51 
52 bool Noise::saveState(ossimKeywordlist& kwl, const char* prefix) const
53 {
54  std::string pfx;
55  if (prefix)
56  {
57  pfx = prefix;
58  }
59  pfx += NOISE;
60 
61 
62  std::string s = pfx + "." + NAME_OF_NOISE_POLARISATION_KW;
63  kwl.add(prefix, s.c_str(), _polarisation);
64 
65  s = pfx + "." + NUMBER_OF_NOISE_RECORDS_KW;
66  kwl.add(prefix, s.c_str(), _numberOfNoiseRecords);
67 
68  for (unsigned int i = 0; i < _tabImageNoise.size(); ++i)
69  {
70  ossimString s2 = pfx + "[" + ossimString::toString(i).c_str() + "]";
71  _tabImageNoise[i].saveState(kwl, s2.c_str());
72  }
73 
74  return true;
75 }
76 
77 bool Noise::loadState(const ossimKeywordlist& kwl, const char* prefix)
78 {
79  static const char MODULE[] = "Noise::loadState";
80 
81  bool result = true;
82 
83  std::string pfx("");
84  if (prefix)
85  {
86  pfx = prefix;
87  }
88  pfx += NOISE;
89 
90  ossimString s;
91  const char* lookup = 0;
92  std::string s1 = pfx + ".";
93 
94  lookup = kwl.find(s1.c_str(), NAME_OF_NOISE_POLARISATION_KW);
95  if (lookup)
96  {
97  _polarisation = lookup;
98  }
99  else
100  {
102  << MODULE << " Keyword not found: " << NAME_OF_NOISE_POLARISATION_KW << "\n";
103  result = false;
104  }
105 
106  lookup = kwl.find(s1.c_str(), NUMBER_OF_NOISE_RECORDS_KW);
107  if (lookup)
108  {
109  s = lookup;
111  }
112  else
113  {
115  << MODULE << " Keyword not found: " << NUMBER_OF_NOISE_RECORDS_KW << "\n";
116  result = false;
117  }
118 
119  _tabImageNoise.clear();
120  for (unsigned int i = 0; i < _numberOfNoiseRecords; ++i)
121  {
122  std::string s2 = pfx + "[" + ossimString::toString(i).c_str() + "]";
123  ImageNoise in;
124  result = in.loadState(kwl, s2.c_str());
125  _tabImageNoise.push_back(in);
126  }
127  if( _numberOfNoiseRecords != _tabImageNoise.size() )
128  {
130  << MODULE << " Keyword " << NUMBER_OF_NOISE_RECORDS_KW << " is different with the number of ImageNoise nodes \n";
131  }
132  return result;
133 }
134 
135 
137 {
138  out << setprecision(15) << setiosflags(ios::fixed)
139  << "\n Noise class data members:\n";
140 
141  const char* prefix = 0;
142  ossimKeywordlist kwl;
143  ossimString pfx;
144  pfx += NOISE;
145  ossimString s = pfx + "." + NUMBER_OF_NOISE_RECORDS_KW;
146  kwl.add(prefix, s.c_str(), _numberOfNoiseRecords);
147  s = pfx + "." + NAME_OF_NOISE_POLARISATION_KW;
148  kwl.add(prefix, s.chars(), _polarisation);
149  for (unsigned int i = 0; i < _tabImageNoise.size(); ++i)
150  {
151  ossimString s2 = pfx + "[" + ossimString::toString(i).c_str() + "]";
152  _tabImageNoise[i].saveState(kwl, s2.c_str());
153  }
154 
155  out << kwl;
156 
157  return out;
158 }
159 
160 }
Represents serializable keyword/value map.
const char * find(const char *key) const
virtual std::ostream & print(std::ostream &out) const
Definition: Noise.cpp:136
static ossimString toString(bool aValue)
Numeric to string methods.
ossim_uint32 toUInt32() const
Noise & operator=(const Noise &rhs)
Affectation operator.
Definition: Noise.cpp:44
std::vector< ImageNoise > _tabImageNoise
Image Noise.
Definition: Noise.h:106
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual ~Noise()
Destructor.
Definition: Noise.cpp:32
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: Noise.cpp:77
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
const char * chars() const
For backward compatibility.
Definition: ossimString.h:77
This class represents an Noise.
Definition: Noise.h:28
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
Noise()
Constructor.
Definition: Noise.cpp:25
ossimString _polarisation
Noise Polarisation Layer.
Definition: Noise.h:111
ossim_uint32 _numberOfNoiseRecords
Image Noise.
Definition: Noise.h:102
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
Definition: Noise.cpp:52