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