OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTieGptSet.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 
8 
9 using namespace std;
10 
11 const ossimTieGptSet&
13 {
14  if (this != &aSet)
15  {
16  theTies = aSet.getTiePoints();
17  theMasterPath = aSet.getMasterPath();
18  theSlavePath = aSet.getSlavePath();
19  theImageCov = aSet.getImageCov();
20  theGroundCov = aSet.getGroundCov();
21  }
22  return *this;
23 }
24 
25 void
27 {
28  theTies.push_back(aTiePt);
29 }
30 
31 void
33 {
34  theTies.clear();
35 }
36 
38 {
39  os<<"MasterPath: "<<getMasterPath()<<endl;
40  os<<"SlavePath: "<<getSlavePath()<<endl;
41  os<< std::setiosflags(std::ios::fixed) << std::setprecision(15);
42  os<<"ImageCov: (2) " <<symMatrixToText(getImageCov()) <<endl;
43  os<<"GroundCov: (3) "<<symMatrixToText(getGroundCov())<<endl;
44  os<<"TiePoints: ("<<endl;
45  for(vector<ossimRefPtr<ossimTieGpt> >::const_iterator it = theTies.begin(); it != theTies.end(); ++it)
46  {
47  (*it)->printTab(os);
48  os<<endl;
49  }
50  os<<")"<<endl;
51  return os;
52 }
53 
54 //constants for XML tags
55 const char* SLAVEPATH_TAG = "SlavePath";
56 const char* MASTERPATH_TAG = "MasterPath";
57 const char* IMAGECOV_TAG = "ImageCovariance";
58 const char* GROUNDCOV_TAG = "GroundCovariance";
59 const char* TIEPOINTS_TAG = "SimpleTiePoint";
60 
61 //exported constants
62 const char* ossimTieGptSet::TIEPTSET_TAG = "TiePointSet";
63 
64 //export as XML/GML
67 {
69 
70  node->setTag(TIEPTSET_TAG);
71  node->addAttribute("xmlns:gml","""http://www.opengis.net/gml"""); //namespace definition
72 
73  //add header information : general accuracy + path
74  node->addChildNode(MASTERPATH_TAG,getMasterPath());
75  node->addChildNode(SLAVEPATH_TAG,getSlavePath());
76  node->addChildNode(IMAGECOV_TAG ,symMatrixToText(getImageCov()));
77  node->addChildNode(GROUNDCOV_TAG,symMatrixToText(getGroundCov()));
78 
79  //add all tiepoints
80  for(vector<ossimRefPtr<ossimTieGpt> >::const_iterator it = theTies.begin(); it != theTies.end(); ++it)
81  {
82  ossimRefPtr<ossimXmlNode> tienode = (*it)->exportAsGmlNode(aGmlVersion);
83  node->addChildNode(tienode.get());
84  //TBD : add attribute / counter?
85  }
86 
87  return node;
88 }
89 
90 //import from XML/GML
91 bool
93 {
94  clearTiePoints();
95  //load master path
97  if (mpn.valid())
98  {
99  setMasterPath(mpn->getText());
100  } else {
101  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode no "<<MASTERPATH_TAG<<" tag found\n";
102  //not an error
103  setMasterPath("");
104  }
105  //load slave path
107  if (spn.valid())
108  {
109  setSlavePath(spn->getText());
110  } else {
111  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode no "<<SLAVEPATH_TAG<<" tag found\n";
112  //not an error
113  setSlavePath("");
114  }
115 
116  //load image covariance
118  if (icn.valid())
119  {
120  NEWMAT::SymmetricMatrix icm = textToSymMatrix(icn->getText(),2);
121  if (icm.Nrows()==2)
122  {
123  setImageCov(icm);
124  } else {
125  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode bad image covariance matrix\n";
126  return false;
127  }
128  } else {
129  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode tag "<<IMAGECOV_TAG<<" not found\n";
130  //not an error
131  setImageCov(NEWMAT::SymmetricMatrix(2)); //maybe use no matrix at all when no info ? TBC
132  }
133 
134  //load ground covariance
136  if (gcn.valid())
137  {
138  NEWMAT::SymmetricMatrix gcm = textToSymMatrix(gcn->getText(),3);
139  if (gcm.Nrows()==3)
140  {
141  setGroundCov(gcm);
142  } else {
143  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode bad ground covariance matrix\n";
144  return false;
145  }
146  } else {
147  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode tag "<<GROUNDCOV_TAG<<" not found\n";
148  //not an error
149  setGroundCov(NEWMAT::SymmetricMatrix(3)); //TBC : is it 0 matrix / should we use no matrix?
150  }
151 
152  //load all tie points (skip errors but report them)
153  vector< ossimRefPtr< ossimXmlNode > > tienodes;
154  aGmlNode->findChildNodes(TIEPOINTS_TAG, tienodes);
155  if (tienodes.size() <= 0)
156  {
157  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode no tag "<<TIEPOINTS_TAG<<" found\n";
158  return false;
159  }
160 
161  int badtiecount=0;
162 
163  for(vector< ossimRefPtr< ossimXmlNode > >::iterator it=tienodes.begin(); it!=tienodes.end(); ++it)
164  {
166  if (temp->importFromGmlNode(*it,aGmlVersion)) //pointer hacks nor beautiful nor direct
167  {
168  addTiePoint(temp);
169  } else {
170  badtiecount++;
171  }
172  }
173  if (badtiecount>0)
174  {
175  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::importFromGmlNode failed to import "<<badtiecount<<" tie point(s)\n";
176  }
177  return true;
178 }
179 
182  const NEWMAT::SymmetricMatrix& sym,
183  const ossimString& el_sep,
184  const ossimString& row_sep)const
185 {
186  // write lower half matrix (easier to see than upper half when left justifying)
187  // separate elements and rows
188  ossimString res = row_sep;
189  for (int i=1;i<=sym.Nrows();++i) //indices start at 1
190  {
191  for (int j=1;j<=i;++j)
192  {
193  if (j!=1) res += el_sep;
194  res += ossimString::toString(sym(i,j));
195  }
196  res += row_sep;
197  }
198  return res;
199 }
200 
201 
202 NEWMAT::SymmetricMatrix
204  const ossimString& text,
205  unsigned int dim,
206  const ossimString& seps)const
207 {
208  //sep can hold multiple possible separators characters
209  //we don't know the matrix size yet, so we put everything into a buffer
210  vector<double> buffer;
211 
212  vector<ossimString> vsv = text.explode(seps);
213  for(vector<ossimString>::const_iterator vit=vsv.begin(); vit!=vsv.end(); ++vit)
214  {
215  if (vit->size() > 0)
216  {
217  buffer.push_back(vit->toDouble());
218  }
219  }
220 
221  //check number of elements
222  if (buffer.size() != (dim*(dim+1))/2)
223  {
224  ossimNotify(ossimNotifyLevel_WARN) << "WARNING: ossimTieGptSet::textToSymMatrix wrong element number in sym. matrix : " << buffer.size() <<"\n";
225  return NEWMAT::SymmetricMatrix();
226  }
227 
228  //populate lower half sym matrix
229  vector<double>::const_iterator it = buffer.begin();
230  NEWMAT::SymmetricMatrix sym(dim);
231  for(unsigned int i=1;i<=dim;++i)
232  {
233  for(unsigned int j=1;j<=i;++j)
234  {
235  sym(i,j) = *(it++);
236  }
237  }
238  return sym;
239 }
240 
241 void
243  std::vector<ossimDpt>& imv,
244  std::vector<ossimGpt>& gdv)const
245 {
246  //re-dim
247  imv.resize(theTies.size());
248  gdv.resize(theTies.size());
249 
250  //fill
251  std::vector<ossimDpt>::iterator imvit = imv.begin();
252  std::vector<ossimGpt>::iterator gdvit = gdv.begin();
253 
254  for(vector<ossimRefPtr<ossimTieGpt> >::const_iterator it = theTies.begin(); it != theTies.end(); ++it,++imvit,++gdvit)
255  {
256  *imvit = (*it)->getImagePoint();
257  *gdvit = (*it)->getGroundPoint();
258  }
259 }
260 
261 void
263 {
264  //init
265  gBoundInf.lat = gBoundInf.lon = gBoundInf.hgt = OSSIM_DEFAULT_MAX_PIX_DOUBLE;
266  gBoundSup.lat = gBoundSup.lon = gBoundSup.hgt = OSSIM_DEFAULT_MIN_PIX_DOUBLE;
267 
268  //return image and/or ground bounds
269  for(vector<ossimRefPtr<ossimTieGpt> >::const_iterator it = theTies.begin(); it != theTies.end(); ++it)
270  {
271  const ossimTieGpt& gp = *(*it);
272  if (gp.lon > gBoundSup.lon) gBoundSup.lon = gp.lon;
273  if (gp.lon < gBoundInf.lon) gBoundInf.lon = gp.lon;
274  if (gp.lat > gBoundSup.lat) gBoundSup.lat = gp.lat;
275  if (gp.lat < gBoundInf.lat) gBoundInf.lat = gp.lat;
276  if (ossim::isnan(gp.hgt) == false)
277  {
278  if (gp.hgt > gBoundSup.hgt) gBoundSup.hgt = gp.hgt;
279  if (gp.hgt < gBoundInf.hgt) gBoundInf.hgt = gp.hgt;
280  }
281  }
282 }
void setTag(const ossimString &tag)
void getSlaveMasterPoints(std::vector< ossimDpt > &imv, std::vector< ossimGpt > &gdv) const
const char * SLAVEPATH_TAG
static const char * TIEPTSET_TAG
Public data members.
void findChildNodes(const ossimString &rel_xpath, ossimXmlNode::ChildListType &nodelist) const
#define OSSIM_DEFAULT_MAX_PIX_DOUBLE
bool valid() const
Definition: ossimRefPtr.h:75
const ossimTieGptSet & operator=(const ossimTieGptSet &)
static ossimString toString(bool aValue)
Numeric to string methods.
const char * IMAGECOV_TAG
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
const char * TIEPOINTS_TAG
const ossimRefPtr< ossimXmlNode > & findFirstNode(const ossimString &rel_xpath) const
const char * GROUNDCOV_TAG
bool importFromGmlNode(ossimRefPtr< ossimXmlNode > aGmlNode, ossimString aGmlVersion="2.1.2")
const ossimString & getText() const
Definition: ossimXmlNode.h:92
bool importFromGmlNode(ossimRefPtr< ossimXmlNode > aGmlNode, ossimString aGmlVersion="2.1.2")
#define OSSIM_DEFAULT_MIN_PIX_DOUBLE
ossim_float64 lon
Definition: ossimGpt.h:266
const vector< ossimRefPtr< ossimTieGpt > > & getTiePoints() const
const char * MASTERPATH_TAG
std::vector< ossimString > explode(const ossimString &delimeter) const
ossimRefPtr< ossimXmlNode > exportAsGmlNode(ossimString aGmlVersion="2.1.2") const
GML features (XML) serialization.
storage class for tie point between ground and image based on ossimGpt
Definition: ossimTieGpt.h:24
void getGroundBoundaries(ossimGpt &gBoundInf, ossimGpt &gBoundSup) const
void addTiePoint(ossimRefPtr< ossimTieGpt > aTiePt)
operations
std::ostream & printTab(std::ostream &os) const
text output : header + tab separated tie points
NEWMAT::SymmetricMatrix textToSymMatrix(const ossimString &text, unsigned int dim, const ossimString &seps=" ;\\) const
const NEWMAT::SymmetricMatrix & getGroundCov() const
storage class for a set of geographic tie points, between master and slave images ...
const NEWMAT::SymmetricMatrix & getImageCov() const
ossim_float64 lat
Definition: ossimGpt.h:265
void addAttribute(ossimRefPtr< ossimXmlAttribute > attribute)
ossimString symMatrixToText(const NEWMAT::SymmetricMatrix &sym, const ossimString &el_sep=" ", const ossimString &row_sep=";") const
ground error covariance matrix
const ossimString & getSlavePath() const
const ossimString & getMasterPath() const
void addChildNode(ossimRefPtr< ossimXmlNode > node)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
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