OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
RefPoint.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/RefPoint.h>
13 #include <otb/Ephemeris.h>
14 #include <cstring>
16 
17 namespace ossimplugins
18 {
19 
20 
21 static const char PREFIX[] = "ref_point.";
22 static const char DISTANCE_KW[] = "distance";
23 static const char LINE_KW[] = "line";
24 static const char COL_KW[] = "col";
25 
27  _ephemeris(0),
28  _distance(0.0),
29  _pix_line(0.0),
30  _pix_col(0.0)
31 {
32 }
33 
35 {
36  if(_ephemeris != 0)
37  {
38  delete _ephemeris;
39  }
40 }
41 
43  _distance(rhs._distance),
44  _pix_line(rhs._pix_line),
45  _pix_col(rhs._pix_col)
46 {
47  _ephemeris = rhs._ephemeris->Clone();
48 }
49 
51 {
52  _distance = rhs._distance;
53  _pix_line = rhs._pix_line;
54  _pix_col = rhs._pix_col;
55  if(_ephemeris != 0)
56  {
57  delete _ephemeris;
58  _ephemeris = 0;
59  }
60  _ephemeris = rhs._ephemeris->Clone();
61 
62  return *this;
63 }
64 
66 {
67  if(_ephemeris != 0)
68  {
69  delete _ephemeris;
70  _ephemeris = 0;
71  }
72  _ephemeris = ephemeris->Clone();
73 }
74 
76 {
78 }
79 
80 void RefPoint::set_pix_line(double pix_line)
81 {
82  _pix_line = pix_line;
83 }
84 
85 void RefPoint::set_pix_col(double pix_col)
86 {
87  _pix_col = pix_col;
88 }
89 
91 {
92  return _ephemeris;
93 }
94 
95 double RefPoint::get_distance() const
96 {
97  return _distance;
98 }
99 
101 {
102  return _pix_line;
103 }
104 
105 double RefPoint::get_pix_col() const
106 {
107  return _pix_col;
108 }
109 
110 bool RefPoint::saveState(ossimKeywordlist& kwl, const char* prefix) const
111 {
112  bool result = true;
113 
114  std::string pfx;
115  if (prefix)
116  {
117  pfx = prefix;
118  }
119  pfx += PREFIX;
120 
121  if (_ephemeris)
122  {
123  result = _ephemeris->saveState(kwl, pfx.c_str());
124  }
125  else
126  {
127  result = false;
128  }
129 
130  kwl.add(pfx.c_str(), DISTANCE_KW, _distance);
131  kwl.add(pfx.c_str(), LINE_KW, _pix_line);
132  kwl.add(pfx.c_str(), COL_KW, _pix_col);
133 
134  return result;
135 }
136 
137 bool RefPoint::loadState(const ossimKeywordlist& kwl, const char* prefix)
138 {
139  bool result = true;
140 
141  std::string pfx;
142  if (prefix)
143  {
144  pfx = prefix;
145  }
146  pfx += PREFIX;
147 
148 
149  if (!_ephemeris)
150  {
151  _ephemeris = new Ephemeris();
152  }
153 
154  result = _ephemeris->loadState(kwl, pfx.c_str());
155 
156  const char* lookup = 0;
157  ossimString s;
158  double d;
159 
160  lookup = kwl.find(pfx.c_str(), DISTANCE_KW);
161  if (lookup)
162  {
163  s = lookup;
164  d = s.toDouble();
165  _distance = d;
166  }
167  else
168  {
169  result = false;
170  }
171 
172  lookup = kwl.find(pfx.c_str(), LINE_KW);
173  if (lookup)
174  {
175  s = lookup;
176  d = s.toDouble();
177  _pix_line = d;
178  }
179  else
180  {
181  result = false;
182  }
183 
184  lookup = kwl.find(pfx.c_str(), COL_KW);
185  if (lookup)
186  {
187  s = lookup;
188  d = s.toDouble();
189  _pix_col = d;
190  }
191  else
192  {
193  result = false;
194  }
195 
196  return result;
197 }
198 }
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
Definition: Ephemeris.cpp:78
bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
Definition: RefPoint.cpp:110
Represents serializable keyword/value map.
Ephemeris * get_ephemeris()
Definition: RefPoint.cpp:90
const char * find(const char *key) const
This class handles the referential point.
Definition: RefPoint.h:29
double get_distance() const
Definition: RefPoint.cpp:95
void set_pix_line(double pix_line)
Definition: RefPoint.cpp:80
void set_pix_col(double pix_col)
Definition: RefPoint.cpp:85
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
Definition: RefPoint.cpp:137
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
This class represents an ephemeris.
Definition: Ephemeris.h:28
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
Definition: Ephemeris.cpp:100
double toDouble() const
virtual Ephemeris * Clone()
This function creatse a copy of the current class.
Definition: Ephemeris.h:58
~RefPoint()
Destructor.
Definition: RefPoint.cpp:34
double get_pix_col() const
Definition: RefPoint.cpp:105
double get_pix_line() const
Definition: RefPoint.cpp:100
Ephemeris * _ephemeris
Definition: RefPoint.h:80
RefPoint & operator=(const RefPoint &rhs)
Affectation operator.
Definition: RefPoint.cpp:50
RefPoint()
Constuctor.
Definition: RefPoint.cpp:26
void set_ephemeris(Ephemeris *ephemeris)
Definition: RefPoint.cpp:65
float distance(double lat1, double lon1, double lat2, double lon2, int units)
void set_distance(double distance)
Definition: RefPoint.cpp:75