OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDpt.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 //
7 // Description:
8 // Contains class definitions for ossimDpt.
9 //
10 //*******************************************************************
11 // $Id: ossimDpt.cpp 20204 2011-11-04 15:12:28Z dburken $
12 
13 #include <iostream>
14 #include <iomanip>
15 #include <sstream>
16 
17 #include <ossim/base/ossimDpt.h>
18 #include <ossim/base/ossimDpt3d.h>
19 #include <ossim/base/ossimIpt.h>
20 #include <ossim/base/ossimFpt.h>
21 #include <ossim/base/ossimGpt.h>
22 
23 //*******************************************************************
24 // Public Constructor:
25 //*******************************************************************
27  :
28  x(pt.x), y(pt.y)
29 {
30  if(pt.hasNans())
31  {
32  makeNan();
33  }
34  }
35 
36 //*******************************************************************
37 // Public Constructor:
38 //*******************************************************************
40  :
41  x(pt.x), y(pt.y)
42 {
43  if(pt.hasNans())
44  {
45  makeNan();
46  }
47 }
48 
49 //*******************************************************************
50 // Public Constructor:
51 //*******************************************************************
53  :
54  x(pt.x), y(pt.y)
55 {
56 }
57 
58 //*******************************************************************
59 // Public Constructor:
60 //*******************************************************************
62  :
63  x(pt.lon), y(pt.lat)
64 {
65 }
66 
67 //*******************************************************************
68 // Public Method:
69 //*******************************************************************
71 {
72  if(pt.hasNans())
73  {
74  makeNan();
75  }
76  else
77  {
78  x = pt.x;
79  y = pt.y;
80  }
81  return *this;
82 }
83 
84 //*******************************************************************
85 // Public Method:
86 //*******************************************************************
88 {
89  if(pt.hasNans())
90  {
91  makeNan();
92  }
93  else
94  {
95  x = pt.x;
96  y = pt.y;
97  }
98  return *this;
99 }
100 
101 //*******************************************************************
102 // Public Method:
103 //*******************************************************************
105 {
106  x = pt.x;
107  y = pt.y;
108  return *this;
109 }
110 
112 {
113  x = pt.lon;
114  y = pt.lat;
115  return *this;
116 }
117 
119 {
120  os << std::setiosflags(std::ios::fixed) << std::setprecision(precision)
121  << "( ";
122 
123  if (ossim::isnan(x) == false)
124  {
125  os << x;
126  }
127  else
128  {
129  os << "nan";
130  }
131 
132  os << ", ";
133 
134  if (ossim::isnan(y) == false)
135  {
136  os << y;
137  }
138  else
139  {
140  os << "nan";
141  }
142 
143  os << " )";
144 
145  return os;
146 }
147 
149 {
150  return pt.print(os);
151 }
152 
153 bool ossimDpt::isEqualTo(const ossimDpt& rhs, ossimCompareType /* compareType */)const
154 {
155  if(rhs.isNan()&&isNan()) return true;
156  return (ossim::almostEqual(x, rhs.x)&&
157  ossim::almostEqual(y, rhs.y));
158 }
159 
161 {
163  os << std::setprecision(precision);
164 
165  os << "(";
166  if (ossim::isnan(x) == false)
167  {
168  os << x;
169  }
170  else
171  {
172  os << "nan";
173  }
174 
175  os << ",";
176 
177  if (ossim::isnan(y) == false)
178  {
179  os << y;
180  }
181  else
182  {
183  os << "nan";
184  }
185 
186  os << ")";
187 
188  //print(os, precision);
189  return ossimString(os.str());
190 }
191 
192 void ossimDpt::toPoint(const std::string& s)
193 {
194  std::istringstream is(s);
195  is >> *this;
196 }
197 
199 {
200  //---
201  // Expected input format:
202  // ( 30.00000000000000, -90.00000000000000 )
203  // --------x-------- ---------y--------
204  //---
205 
206  // Start with a nan point.
207  pt.makeNan();
208 
209  // Check the stream.
210  if (!is) return is;
211 
212  const int SZ = 64; // Handle real big number...
213  ossimString os;
214  char buf[SZ];
215 
216  //---
217  // X SECTION:
218  //---
219 
220  // Grab data up to the first comma.
221  is.get(buf, SZ, ',');
222 
223  if (!is) return is;
224 
225  // Copy to ossim string.
226  os = buf;
227 
228  // Get rid of the '(' if there is any.
229  std::string::size_type pos = os.find('(');
230  if (pos != std::string::npos)
231  {
232  os.erase(pos, 1);
233  }
234 
235  if (os.contains("nan") == false)
236  {
237  pt.x = os.toFloat64();
238  }
239  else
240  {
241  pt.x = ossim::nan();
242  }
243 
244  //---
245  // Y SECTION:
246  //---
247 
248  // Grab the data up to the ')'
249  is.get(buf, SZ, ')');
250 
251  if (!is) return is;
252 
253  // Copy to ossim string.
254  os = buf;
255 
256  // Get rid of the ',' if there is any.
257  pos = os.find(',');
258  if (pos != std::string::npos)
259  {
260  os.erase(pos, 1);
261  }
262 
263  if (os.contains("nan") == false)
264  {
265  pt.y = os.toFloat64();
266  }
267  else
268  {
269  pt.y = ossim::nan();
270  }
271 
272  // Gobble the trailing ")".
273  char c = '\0';
274  while (c != ')')
275  {
276  is.get(c);
277  if (!is) break;
278  }
279 
280  // Finished
281  return is;
282 }
ossim_uint32 x
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
bool isEqualTo(const ossimDpt &rhs, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
Definition: ossimDpt.cpp:153
ossim_uint32 y
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
double y
Definition: ossimDpt.h:165
bool contains(char aChar) const
Definition: ossimString.h:58
ossimCompareType
bool isNan() const
Definition: ossimDpt.h:72
ossimDpt()
Definition: ossimDpt.h:33
ossim_float32 x
Definition: ossimFpt.h:70
std::ostream & print(std::ostream &os, ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:118
ossim_float64 lon
Definition: ossimGpt.h:266
std::istream & operator>>(std::istream &is, ossimDpt &pt)
Definition: ossimDpt.cpp:198
unsigned int ossim_uint32
std::string::iterator erase(std::string::iterator p)
Erases the character at position p.
Definition: ossimString.h:736
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimDpt.cpp:192
ossim_float64 toFloat64() const
bool hasNans() const
Definition: ossimFpt.h:58
const ossimDpt & operator=(const ossimFpt &)
Definition: ossimDpt.cpp:70
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossimString toString(ossim_uint32 precision=15) const
Definition: ossimDpt.cpp:160
ossim_int32 y
Definition: ossimIpt.h:142
double x
Definition: ossimDpt.h:164
double x
Definition: ossimDpt3d.h:143
ossim_int32 x
Definition: ossimIpt.h:141
ossim_float64 lat
Definition: ossimGpt.h:265
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
double y
Definition: ossimDpt3d.h:144
bool hasNans() const
Definition: ossimIpt.h:58
ossim_float32 y
Definition: ossimFpt.h:71
std::ostream & operator<<(std::ostream &os, const ossimDpt &pt)
Definition: ossimDpt.cpp:148
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
void makeNan()
Definition: ossimDpt.h:65
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91