OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimQuickbirdRpcHeader.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: ossimQuickbirdRpcHeader.cpp 9094 2006-06-13 19:12:40Z dburken $
9 
11 #include <iostream>
12 #include <fstream>
13 #include <algorithm>
14 #include <iterator>
15 
17  const ossimQuickbirdRpcHeader& data)
18 {
19  out << "theSatId = " << data.theSatId << std::endl
20  << "theBandId = " << data.theBandId << std::endl
21  << "theSpecId = " << data.theSpecId << std::endl
22  << "theErrBias = " << data.theErrBias << std::endl
23  << "theLineOffset = " << data.theLineOffset << std::endl
24  << "theSampOffset = " << data.theSampOffset << std::endl
25  << "theLatOffset = " << data.theLatOffset << std::endl
26  << "theLonOffset = " << data.theLonOffset << std::endl
27  << "theHeightOffset = " << data.theHeightOffset << std::endl
28  << "theLineScale = " << data.theLineScale << std::endl
29  << "theSampScale = " << data.theSampScale << std::endl
30  << "theLatScale = " << data.theLatScale << std::endl
31  << "theLonScale = " << data.theLonScale << std::endl
32  << "theHeightScale = " << data.theHeightScale << std::endl;
33 
34  out << "lineNumCoef = " << std::endl;
35  std::copy(data.theLineNumCoeff.begin(),
36  data.theLineNumCoeff.end(),
37  std::ostream_iterator<double>(out, "\n"));
38  out << "lineDenCoef = " << std::endl;
39  std::copy(data.theLineDenCoeff.begin(),
40  data.theLineDenCoeff.end(),
41  std::ostream_iterator<double>(out, "\n"));
42  out << "sampNumCoef = " << std::endl;
43  std::copy(data.theSampNumCoeff.begin(),
44  data.theSampNumCoeff.end(),
45  std::ostream_iterator<double>(out, "\n"));
46  out << "sampDenCoef = " << std::endl;
47  std::copy(data.theSampDenCoeff.begin(),
48  data.theSampDenCoeff.end(),
49  std::ostream_iterator<double>(out, "\n"));
50 
51  return out;
52 }
53 
54 
56 : theErrBias(0),
57  theErrRand(0),
58  theLineOffset(0),
59  theSampOffset(0),
60  theLatOffset(0),
61  theLonOffset(0),
62  theHeightOffset(0),
63  theLineScale(0),
64  theSampScale(0),
65  theLatScale(0),
66  theLonScale(0),
67  theHeightScale(0)
68 {
69 }
70 
72 {
73  theFilename = file;
74  std::ifstream in(file.c_str(), std::ios::in|std::ios::binary);
75 
76  char test[64];
77 
78  in.read((char*)test, 63);
79  test[63] = '\0';
80  in.seekg(0);
81  ossimString line = test;
82  line = line.upcase();
83 
84  if(parseNameValue(line))
85  {
87  getline(in,
88  line);
90  {
91  line = line.upcase();
92  if(line.contains("LINENUMCOEF"))
93  {
94  if(!readCoeff(in, theLineNumCoeff))
95  {
97  break;
98  }
99  }
100  else if(line.contains("LINEDENCOEF"))
101  {
102  if(!readCoeff(in, theLineDenCoeff))
103  {
104  setErrorStatus();
105  break;
106  }
107  }
108  else if(line.contains("SAMPNUMCOEF"))
109  {
110  if(!readCoeff(in, theSampNumCoeff))
111  {
112  setErrorStatus();
113  break;
114  }
115  }
116  else if(line.contains("SAMPDENCOEF"))
117  {
118  if(!readCoeff(in, theSampDenCoeff))
119  {
120  setErrorStatus();
121  break;
122  }
123  }
124  else if(!parseNameValue(line))
125  {
126  setErrorStatus();
127  break;
128  }
129  getline(in,
130  line);
131  }
132  }
133  else
134  {
135  setErrorStatus();
136  }
138 }
139 
141  std::vector<double>& coeff)
142 {
143  coeff.clear();
144  bool done = false;
145  ossimString line;
146  while(!in.eof()&&!in.bad()&&!done)
147  {
148  getline(in,
149  line);
150  line.trim();
151  line.trim(',');
152  if(line.contains(");"))
153  {
154  done = true;
155  line.trim(';');
156  line.trim(')');
157  }
158  coeff.push_back(line.toDouble());
159  }
160  return done;
161 }
162 
164 {
165  bool result = true;
166  ossimString lineCopy = line;
167 
168  if(lineCopy.contains("SATID"))
169  {
170  theSatId = lineCopy.after("\"");
171  theSatId = theSatId.before("\"");
172  }
173  else if(lineCopy.contains("BANDID"))
174  {
175  theBandId = lineCopy.after("\"");
176  theBandId = theBandId.before("\"");
177  }
178  else if(lineCopy.contains("SPECID"))
179  {
180  theSpecId = lineCopy.after("\"");
181  theSpecId = theSpecId.before("\"");
182  }
183  else if(lineCopy.contains("BEGIN_GROUP"))
184  {
185  }
186  else if(lineCopy.contains("ERRBIAS"))
187  {
188  lineCopy = lineCopy.after("=");
189  theErrBias = lineCopy.before(";").toDouble();
190  }
191  else if(lineCopy.contains("ERRRAND"))
192  {
193  lineCopy = lineCopy.after("=");
194  theErrRand = lineCopy.before(";").toDouble();
195  }
196  else if(lineCopy.contains("LINEOFFSET"))
197  {
198  lineCopy = lineCopy.after("=");
199  theLineOffset = lineCopy.before(";").toInt();
200  }
201  else if(lineCopy.contains("SAMPOFFSET"))
202  {
203  lineCopy = lineCopy.after("=");
204  theSampOffset = lineCopy.before(";").toInt();
205  }
206  else if(lineCopy.contains("LATOFFSET"))
207  {
208  lineCopy = lineCopy.after("=");
209  theLatOffset = lineCopy.before(";").toDouble();
210  }
211  else if(lineCopy.contains("LONGOFFSET"))
212  {
213  lineCopy = lineCopy.after("=");
214  theLonOffset = lineCopy.before(";").toDouble();
215  }
216  else if(lineCopy.contains("HEIGHTOFFSET"))
217  {
218  lineCopy = lineCopy.after("=");
219  theHeightOffset = lineCopy.before(";").toDouble();
220  }
221  else if(lineCopy.contains("LINESCALE"))
222  {
223  lineCopy = lineCopy.after("=");
224  theLineScale = lineCopy.before(";").toDouble();
225  }
226  else if(lineCopy.contains("SAMPSCALE"))
227  {
228  lineCopy = lineCopy.after("=");
229  theSampScale = lineCopy.before(";").toDouble();
230  }
231  else if(lineCopy.contains("LATSCALE"))
232  {
233  lineCopy = lineCopy.after("=");
234  theLatScale = lineCopy.before(";").toDouble();
235  }
236  else if(lineCopy.contains("LONGSCALE"))
237  {
238  lineCopy = lineCopy.after("=");
239  theLonScale = lineCopy.before(";").toDouble();
240  }
241  else if(lineCopy.contains("HEIGHTSCALE"))
242  {
243  lineCopy = lineCopy.after("=");
244  theHeightScale = lineCopy.before(";").toDouble();
245  }
246  else if(lineCopy.contains("END_GROUP"))
247  {
248  }
249  else if(lineCopy.contains("END"))
250  {
251  }
252  else
253  {
254  result = false;
255  }
256 
257  return result;
258 }
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
static const ossimErrorCode OSSIM_OK
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool contains(char aChar) const
Definition: ossimString.h:58
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
bool open(const ossimFilename &file)
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
std::ostream & operator<<(std::ostream &out, const ossimQuickbirdRpcHeader &data)
bool readCoeff(std::istream &in, std::vector< double > &coeff)
std::vector< double > theSampNumCoeff
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
std::vector< double > theLineNumCoeff
bool parseNameValue(const ossimString &line)
std::vector< double > theSampDenCoeff
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
int toInt() const
std::vector< double > theLineDenCoeff
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23