OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDpt3d.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 //----------------------------------------------------------------------------
8 // $Id: ossimDpt3d.cpp 22937 2014-11-01 11:30:13Z okramer $
9 
10 #include <sstream>
11 #include <ossim/base/ossimDpt3d.h>
12 #include <ossim/base/ossimIpt.h>
13 #include <ossim/base/ossimDpt.h>
14 #include <ossim/base/ossimGpt.h>
15 #include <ossim/base/ossimString.h>
16 
17 
19  :x(aPt.x),
20  y(aPt.y),
21  z(0)
22 {
23  if(aPt.isNan())
24  {
25  makeNan();
26  }
27 }
28 
30  :x(aPt.x),
31  y(aPt.y),
32  z(0)
33 {
34  if(aPt.isNan())
35  makeNan();
36 }
37 
39 {
40  if(gPt.hasNans())
41  {
42  makeNan();
43  }
44  else
45  {
46  ossimGpt wgs84Pt (gPt);
47  wgs84Pt.changeDatum(ossimDatumFactory::instance()->wgs84());
48  x = wgs84Pt.lon;
49  y = wgs84Pt.lat;
50  z = wgs84Pt.hgt;
51  }
52 }
53 
54 
55 std::string ossimDpt3d::toString(ossim_uint32 precision) const
56 {
58  os << setprecision(precision);
59 
60  os << "(";
61  if ( ossim::isnan(x) == false)
62  {
63  os << x;
64  }
65  else
66  {
67  os << "nan";
68  }
69  os << ",";
70  if ( ossim::isnan(y) == false )
71  {
72  os << y;
73  }
74  else
75  {
76  os << "nan";
77  }
78  os << ",";
79  if ( ossim::isnan(z) == false )
80  {
81  os << z;
82  }
83  else
84  {
85  os << "nan";
86  }
87  os << ")";
88 
89  return os.str();
90 }
91 
92 void ossimDpt3d::toPoint(const std::string& s)
93 {
94  // Nan out the column vector for starters.
95  x = ossim::nan();
96  y = ossim::nan();
97  z = ossim::nan();
98 
99  std::istringstream is(s);
100 
101  // Check the stream.
102  if (!is) return;
103 
104  //---
105  // Expected input format:
106  // ( 0.0000000, 0.0000000, 0.00000000 )
107  // -----x---- -----y---- -----z----
108  //---
109 
110  const int SZ = 64; // Handle real big number...
111  ossimString os;
112  char buf[SZ];
113  char c = 0;
114 
115  //---
116  // X SECTION:
117  //---
118 
119  // Grab data up to the first comma.
120  is.get(buf, SZ, ',');
121 
122  if (!is) return;
123 
124  // Copy to ossim string.
125  os = buf;
126 
127  // Get rid of the '(' if there is any.
128  std::string::size_type pos = os.find('(');
129  if (pos != std::string::npos)
130  {
131  os.erase(pos, 1);
132  }
133 
134  if (os.contains("nan") == false)
135  {
136  x = os.toFloat64();
137  }
138  else
139  {
140  x = ossim::nan();
141  }
142 
143  // Eat the comma that we stopped at.
144  while (c != ',')
145  {
146  is.get(c);
147  if (!is) break;
148  }
149 
150  //---
151  // Y SECTION:
152  //---
153 
154  // Grab the data up to the next ','
155  is.get(buf, SZ, ',');
156 
157  if (!is) return;
158 
159  // Copy to ossim string.
160  os = buf;
161 
162  if (os.contains("nan") == false)
163  {
164  y = os.toFloat64();
165  }
166  else
167  {
168  y = ossim::nan();
169  }
170 
171  // Eat the comma that we stopped at.
172  c = 0;
173  while (c != ',')
174  {
175  is.get(c);
176  if (!is) break;
177  }
178 
179  //---
180  // Z SECTION:
181  //---
182 
183  // Grab the data up to the ')'
184  is.get(buf, SZ, ')');
185 
186  if (!is) return;
187 
188  // Copy to ossim string.
189  os = buf;
190 
191  if (os.contains("nan") == false)
192  {
193  z = os.toFloat64();
194  }
195  else
196  {
197  z = ossim::nan();
198  }
199 }
200 
202 {
203  std::string s = rhs.toString(15);
204  out << s;
205  return out;
206 }
ossim_uint32 x
void toPoint(const std::string &s)
Initializes this point from string.
Definition: ossimDpt3d.cpp:92
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossim_uint32 y
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool contains(char aChar) const
Definition: ossimString.h:58
bool isNan() const
Definition: ossimIpt.h:62
std::string toString(ossim_uint32 precision=15) const
To string method.
Definition: ossimDpt3d.cpp:55
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
bool isNan() const
Definition: ossimDpt.h:72
void changeDatum(const ossimDatum *datum)
This will actually perform a shift.
Definition: ossimGpt.cpp:316
double z
Definition: ossimDpt3d.h:145
ossim_float64 lon
Definition: ossimGpt.h:266
unsigned int ossim_uint32
std::string::iterator erase(std::string::iterator p)
Erases the character at position p.
Definition: ossimString.h:736
ossim_float64 toFloat64() const
static ossimDatumFactory * instance()
void makeNan()
Definition: ossimDpt3d.h:61
std::ostream & operator<<(std::ostream &out, const ossimDpt3d &rhs)
Definition: ossimDpt3d.cpp:201
bool hasNans() const
Definition: ossimGpt.h:135
double x
Definition: ossimDpt3d.h:143
ossim_float64 lat
Definition: ossimGpt.h:265
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
ossimDpt3d(const double &aX=0, const double &aY=0, const double &aZ=0)
Definition: ossimDpt3d.h:35
double y
Definition: ossimDpt3d.h:144
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
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