OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimColumnVector3d.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 // Description: This is a 3-D vector without the homogeneous
8 // coordinate.
9 //
10 //*******************************************************************
11 // $Id: ossimColumnVector3d.cpp 15766 2009-10-20 12:37:09Z gpotts $
12 
13 #include <sstream>
15 #include <ossim/base/ossimCommon.h>
16 
18 {
20  os << setprecision(precision);
21 
22  os << "(";
23  if ( ossim::isnan(data[0]) == false)
24  {
25  os << data[0];
26  }
27  else
28  {
29  os << "nan";
30  }
31  os << ",";
32  if ( ossim::isnan(data[1]) == false )
33  {
34  os << data[1];
35  }
36  else
37  {
38  os << "nan";
39  }
40  os << ",";
41  if ( ossim::isnan(data[2]) == false )
42  {
43  os << data[2];
44  }
45  else
46  {
47  os << "nan";
48  }
49  os << ")";
50 
51  return ossimString(os.str());
52 }
53 
54 void ossimColumnVector3d::toPoint(const std::string& s)
55 {
56  // Nan out the column vector for starters.
57  data[0] = ossim::nan();
58  data[1] = ossim::nan();
59  data[2] = ossim::nan();
60 
61  std::istringstream is(s);
62 
63  // Check the stream.
64  if (!is) return;
65 
66  //---
67  // Expected input format:
68  // ( 0.0000000, 0.0000000, 0.00000000 )
69  // -----x---- -----y---- -----z----
70  //---
71 
72  const int SZ = 64; // Handle real big number...
73  ossimString os;
74  char buf[SZ];
75  char c = 0;
76 
77  //---
78  // X SECTION:
79  //---
80 
81  // Grab data up to the first comma.
82  is.get(buf, SZ, ',');
83 
84  if (!is) return;
85 
86  // Copy to ossim string.
87  os = buf;
88 
89  // Get rid of the '(' if there is any.
90  std::string::size_type pos = os.find('(');
91  if (pos != std::string::npos)
92  {
93  os.erase(pos, 1);
94  }
95 
96  if (os.contains("nan") == false)
97  {
98  data[0] = os.toFloat64();
99  }
100  else
101  {
102  data[0] = ossim::nan();
103  }
104 
105  // Eat the comma that we stopped at.
106  while (c != ',')
107  {
108  is.get(c);
109  if (!is) break;
110  }
111 
112  //---
113  // Y SECTION:
114  //---
115 
116  // Grab the data up to the next ','
117  is.get(buf, SZ, ',');
118 
119  if (!is) return;
120 
121  // Copy to ossim string.
122  os = buf;
123 
124  if (os.contains("nan") == false)
125  {
126  data[1] = os.toFloat64();
127  }
128  else
129  {
130  data[1] = ossim::nan();
131  }
132 
133  // Eat the comma that we stopped at.
134  c = 0;
135  while (c != ',')
136  {
137  is.get(c);
138  if (!is) break;
139  }
140 
141  //---
142  // Z SECTION:
143  //---
144 
145  // Grab the data up to the ')'
146  is.get(buf, SZ, ')');
147 
148  if (!is) return;
149 
150  // Copy to ossim string.
151  os = buf;
152 
153  if (os.contains("nan") == false)
154  {
155  data[2] = os.toFloat64();
156  }
157  else
158  {
159  data[2] = ossim::nan();
160  }
161 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool contains(char aChar) const
Definition: ossimString.h:58
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
ossimString toString(ossim_uint32 precision=15) const
To string method.
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
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 toPoint(const std::string &s)
Initializes this point from string.
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91