OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTieGpt.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
8 
9 //*******************************************************************
10 
12 {
13  os << "( ";
14  os << dynamic_cast<const ossimGpt&>(*this);
15  os << ", ";
16  os << tie;
17  os << ", ";
18  if (ossim::isnan(score) == false)
19  {
20  os << std::setiosflags(std::ios::fixed) << std::setprecision(15);
21  os << score;
22  } else {
23  os << "nan";
24  }
25  os << " )";
26 
27  return os;
28 }
29 
31 {
32  os << std::setiosflags(std::ios::fixed) << std::setprecision(15);
33  os<< lond() ;
34  os<<"\t"<< latd();
35  os<<"\t"<< height();
36  os<<"\t"<< tie.x;
37  os<<"\t"<< tie.y;
38  os<<"\t"<< score;
39 
40  return os;
41 }
42 
44 {
45  return pt.print(os);
46 }
47 
49 {
50  //---
51  // Expected input format:
52  // ( (ossimDPt), (ossimDpt), score )
53  // score is real or nan
54  //---
55 
56  // Start with a nan point.
57  pt.makeNan();
58  // Check the stream.
59  if (!is) return is;
60 
61  ossimString tempString;
62 
63  // Gobble the "(".
64  is >> tempString;
65 
66  //get the first point
67  is>>dynamic_cast<ossimGpt&>(pt);
68 
69  // Eat the ",".
70  char c;
71  is.get(c);
72 
73  //get the second point
74  is>>pt.tie;
75 
76  // Eat the second ",".
77  is.get(c);
78 
79  // Get the score
80  const int SZ = 64; // real number buffer size
81  char tempChars[SZ];
82  is.get(tempChars, SZ, ',');
83  if (!is) return is;
84  tempChars[SZ-1] = '\0';
85  tempString = tempChars;
86  tempString.trim();
87  if (tempString == "nan")
88  {
89  pt.score = ossim::nan();
90  }
91  else
92  {
93  pt.score = tempString.toDouble();
94  }
95 
96  // Gobble the trailing ")".
97  is >> tempString;
98 
99  // Finished
100  return is;
101 }
102 
103 //constants for GML 2.1.2
104 const char* GROUND_GML2 = "ground/gml:Point";
105 const char* IMAGE_GML2 = "image/gml:Point";
106 const char* SCORE_GML2 = "score";
107 const char* COORD_GML2 = "gml:coord";
108 const char* COORDINATES_GML2 = "gml:coordinates";
109 
112 {
114  // check datum to be WGS84
115  if ( !(datum()->operator==(*(ossimDatumFactory::instance()->wgs84()))) )
116  {
117  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::exportAsGmlNode datum must be WGS84\n";
118  return node;
119  }
120  // check nans in lon/lat and in tie
121  if (isLatNan() || isLonNan() || tie.hasNans())
122  {
123  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::exportAsGmlNode positions have nan\n";
124  return node;
125  }
126  if (aGmlVersion[static_cast<std::string::size_type>(0)] == '2')
127  {
128  node->setTag("SimpleTiePoint");
129  // note: no "fid" attribute (feature id")
130  //store Ground Point WGS84 + height above ellipsoid in meters
132  gcoord->addChildNode("X",ossimString::toString(lond()));
133  gcoord->addChildNode("Y",ossimString::toString(latd()));
134  if (!isHgtNan())
135  {
136  gcoord->addChildNode("Z",ossimString::toString(height())); //above ellipsoid
137  }
138 
139  // store image tie point
141  tcoord->addChildNode("X",ossimString::toString(tie.x));
142  tcoord->addChildNode("Y",ossimString::toString(tie.y));
143 
144  //store score (change name to confidence?)
146  } else {
147  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::exportAsGmlNode Unsupported GML version : " << aGmlVersion <<"\n";
148  }
149  return node;
150 }
151 
152 bool
154 {
155  //assuming datum is EPSG:4326 (aka WGS84)
156  //feature has to be a SimpleTiePoint feature
157  //TBD : add support for coord instead of coordinates
158  //TBD : more robust type checks (for X,Y,Z and score) - create extra protected function
159 
160  //clear data
161  makeNan();
162  tie.makeNan();
163  score = 0;
164 
165  if (aGmlVersion[static_cast<std::string::size_type>(0)] == '2')
166  {
167  //read ground point
170  if (gcoord.valid())
171  {
172  //read coord
173  ossimRefPtr<ossimXmlNode> gx = gcoord->findFirstNode("X");
174  if (gx.valid())
175  {
176  lond(ossimString(gx->getText()).toDouble());
177  } else {
178  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode no ground X found in coord\n";
179  return false;
180  }
181  ossimRefPtr<ossimXmlNode> gy = gcoord->findFirstNode("Y");
182  if (gy.valid())
183  {
184  latd(ossimString(gy->getText()).toDouble());
185  } else {
186  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode no ground Y found in coord\n";
187  return false;
188  }
189  ossimRefPtr<ossimXmlNode> gz = gcoord->findFirstNode("Z");
190  if (gz.valid())
191  {
192  height(ossimString(gz->getText()).toDouble());
193  } // no Z value is possible
194  }
195  else {
196  //try to read coordinates
197  //TBD
198  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode gml:coordinates not developed yet for ground\n";
199  return false;
200  }
201 
202  //read image point
205  if (icoord.valid())
206  {
207  //read coord
208  ossimRefPtr<ossimXmlNode> ix = icoord->findFirstNode("X");
209  if (ix.valid())
210  {
211  tie.x = ossimString(ix->getText()).toDouble();
212  } else {
213  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode no image X found in coord\n";
214  return false;
215  }
216  ossimRefPtr<ossimXmlNode> iy = icoord->findFirstNode("Y");
217  if (iy.valid())
218  {
219  tie.y = ossimString(iy->getText()).toDouble();
220  } else {
221  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode no image Y found in coord\n";
222  return false;
223  }
224  //don't read Z value (shouldn't be any)
225  }
226  else {
227  //try to read coordinates
228  //TBD
229  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode gml:coordinates not developed yet for image\n";
230  return false;
231  }
232 
233  //read score
235  if (scoren.valid())
236  {
237  score = ossimString(scoren->getText()).toDouble();
238  } else {
239  score = 0.0;
240  }
241  return true;
242  } else {
243  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGpt::importFromGmlNode Unsupported GML version : " << aGmlVersion <<"\n";
244  return false;
245  }
246 }
void setTag(const ossimString &tag)
const char * SCORE_GML2
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
bool isLonNan() const
Definition: ossimGpt.h:140
bool valid() const
Definition: ossimRefPtr.h:75
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
void makeNan()
Definition: ossimTieGpt.h:66
double y
Definition: ossimDpt.h:165
static ossimString toString(bool aValue)
Numeric to string methods.
std::ostream & print(std::ostream &os) const
text serialization
Definition: ossimTieGpt.cpp:11
const char * COORD_GML2
ossimDpt tie
Public data members.
Definition: ossimTieGpt.h:108
const char * IMAGE_GML2
ossimRefPtr< ossimXmlNode > addNode(const ossimString &relPath, const ossimString &text="")
const ossimRefPtr< ossimXmlNode > & findFirstNode(const ossimString &rel_xpath) const
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
bool isLatNan() const
Definition: ossimGpt.h:139
bool isHgtNan() const
Definition: ossimGpt.h:143
const ossimDatum * datum() const
datum().
Definition: ossimGpt.h:196
bool importFromGmlNode(ossimRefPtr< ossimXmlNode > aGmlNode, ossimString aGmlVersion="2.1.2")
const ossimString & getText() const
Definition: ossimXmlNode.h:92
const char * COORDINATES_GML2
std::istream & operator>>(std::istream &is, ossimTieGpt &pt)
Definition: ossimTieGpt.cpp:48
const char * GROUND_GML2
std::ostream & printTab(std::ostream &os) const
Definition: ossimTieGpt.cpp:30
double height() const
Definition: ossimGpt.h:107
static ossimDatumFactory * instance()
bool hasNans() const
Definition: ossimDpt.h:67
ossimRefPtr< ossimXmlNode > exportAsGmlNode(ossimString aGmlVersion="2.1.2") const
GML feauture (XML) serialization.
storage class for tie point between ground and image based on ossimGpt
Definition: ossimTieGpt.h:24
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
double x
Definition: ossimDpt.h:164
ossim_float64 score
Definition: ossimTieGpt.h:109
std::ostream & operator<<(std::ostream &os, const ossimTieGpt &pt)
Definition: ossimTieGpt.cpp:43
void addChildNode(ossimRefPtr< ossimXmlNode > node)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
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