OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimIkonosRpcModel.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 // AUTHOR: Oscar Kramer
8 //
9 // DESCRIPTION: Contains implementation of class ossimIkonosRpcModel. This
10 // derived class implements the capability of reading Ikonos RPC support
11 // data.
12 //
13 // LIMITATIONS: None.
14 //
15 //*****************************************************************************
16 // $Id: ossimIkonosRpcModel.cpp 23323 2015-05-27 12:53:00Z gpotts $
17 
18 #include <cstdlib>
21 #include <ossim/base/ossimNotify.h>
25 #include <ossim/base/ossimTrace.h>
26 
27 
28 RTTI_DEF1(ossimIkonosRpcModel, "ossimIkonosRpcModel", ossimRpcModel);
29 
30 //***
31 // Define Trace flags for use within this file:
32 //***
33 static ossimTrace traceExec ("ossimIkonosRpcModel:exec");
34 static ossimTrace traceDebug ("ossimIkonosRpcModel:debug");
35 
36 const ossimFilename INIT_RPC_GEOM_FILENAME ("rpc_init.geom");
37 
38 static const char* MODEL_TYPE = "ossimIkonosRpcModel";
39 static const char* META_DATA_FILE = "meta_data_file";
40 static const char* RPC_DATA_FILE = "rpc_data_file";
41 static const char* LINE_OFF_KW = "LINE_OFF";
42 static const char* SAMP_OFF_KW = "SAMP_OFF";
43 static const char* LAT_OFF_KW = "LAT_OFF";
44 static const char* LONG_OFF_KW = "LONG_OFF";
45 static const char* HEIGHT_OFF_KW = "HEIGHT_OFF";
46 static const char* LINE_SCALE_KW = "LINE_SCALE";
47 static const char* SAMP_SCALE_KW = "SAMP_SCALE";
48 static const char* LAT_SCALE_KW = "LAT_SCALE";
49 static const char* LONG_SCALE_KW = "LONG_SCALE";
50 static const char* HEIGHT_SCALE_KW = "HEIGHT_SCALE";
51 static const char* LINE_NUM_COEFF_KW = "LINE_NUM_COEFF_";
52 static const char* LINE_DEN_COEFF_KW = "LINE_DEN_COEFF_";
53 static const char* SAMP_NUM_COEFF_KW = "SAMP_NUM_COEFF_";
54 static const char* SAMP_DEN_COEFF_KW = "SAMP_DEN_COEFF_";
55 
56 
58  :ossimRpcModel(),
59  theSupportData(new ossimIkonosMetaData())
60 {
61 }
62 
63 //*****************************************************************************
64 // CONSTRUCTOR: ossimIkonosRpcModel
65 //
66 // Constructs given a geometry file that specifies the filenames for the
67 // metadata and RPC data files.
68 //
69 //*****************************************************************************
71  : ossimRpcModel(),
72  theSupportData(new ossimIkonosMetaData())
73 {
74  if (traceExec())
75  {
77  << "DEBUG ossimIkonosRpcModel Constructor #1: entering..."
78  << std::endl;
79  }
80 
81  ossimKeywordlist kwl(geom_file);
82  const char* value;
83 
84  //***
85  // Assure this keywordlist contains correct type info:
86  //***
87  value = kwl.find(ossimKeywordNames::TYPE_KW);
88  if (!value || (strcmp(value, "ossimIkonosRpcModel")))
89  {
90  if (traceDebug())
91  {
93  << "DEBUG ossimIkonosRpcModel Constructor #1:"
94  << "\nFailed attempt to construct. sensor type \""<<value
95  << "\" does not match \"ossimIkonosRpcModel\"." << std::endl;
96  }
97 
99  if (traceExec())
100  {
102  << "DEBUG ossimIkonosRpcModel Constructor #1: returning..."
103  << std::endl;
104  }
105  return;
106  }
107 
108  //***
109  // Read meta data filename from geom file:
110  //***
111  value = kwl.find(META_DATA_FILE);
112  if (!value)
113  {
114  theErrorStatus++;
115  if (traceExec())
116  {
118  << "DEBUG ossimIkonosRpcModel Constructor #1: returning..."
119  << std::endl;
120  }
121  return;
122  }
123 
124  ossimFilename metadata (value);
125 
126  //***
127  // Read RPC data filename from geom file:
128  //***
129  value = kwl.find(RPC_DATA_FILE);
130  if (!value)
131  {
132  theErrorStatus++;
133  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1: returning..." << std::endl;
134  return;
135  }
136  ossimFilename rpcdata (value);
137 
138  parseMetaData(metadata);
139  parseRpcData (rpcdata);
141 
142  ossimString drivePart;
143  ossimString pathPart;
144  ossimString filePart;
145  ossimString extPart;
146  geom_file.split(drivePart,
147  pathPart,
148  filePart,
149  extPart);
150 
151 
152 
153  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG returning..." << std::endl;
154 
155  return;
156 }
157 
158 //*****************************************************************************
159 // CONSTRUCTOR: ossimIkonosRpcModel
160 //
161 // Constructs given filenames for metadata and RPC data.
162 //
163 //*****************************************************************************
165  const ossimFilename& rpcdata)
166  :
167  ossimRpcModel(),
168  theSupportData(new ossimIkonosMetaData())
169 {
170  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #2: entering..." << std::endl;
171 
172  parseMetaData(metadata);
173  parseRpcData (rpcdata);
175 
176  //***
177  // Save current state in RPC model format:
178  //***
179  ossimString drivePart;
180  ossimString pathPart;
181  ossimString filePart;
182  ossimString extPart;
183  metadata.split(drivePart,
184  pathPart,
185  filePart,
186  extPart);
187 
188  ossimFilename init_rpc_geom;
189  init_rpc_geom.merge(drivePart,
190  pathPart,
192  "");
193 // (metadata.path().dirCat(ossimRpcModel::INIT_RPC_GEOM_FILENAME));
194  ossimKeywordlist kwl (init_rpc_geom);
195  saveState(kwl);
196 
197  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #2: returning..." << std::endl;
198 }
199 
201 {
202  theSupportData = 0;
203 }
204 
205 //*****************************************************************************
206 // METHOD: ossimIkonosRpcModel::finishConstruction()
207 //
208 //*****************************************************************************
210 {
211  if (traceExec())
212  {
214  << "DEBUG ossimIkonosRpcModel finishConstruction(): entering..."
215  << std::endl;
216  }
217 
218  //***
219  // Assign other data members:
220  //***
221  thePolyType = B; // This may not be true for early RPC imagery
227 
228  //***
229  // Assign the bounding image space rectangle:
230  //***
231  theImageClipRect = ossimDrect(0.0, 0.0,
233 
234  //---
235  // NOTE: We must call "updateModel()" to set parameter used by base
236  // ossimRpcModel prior to calling lineSampleHeightToWorld or all
237  // the world points will be same.
238  //---
239  updateModel();
240 
241  //***
242  // Assign the bounding ground polygon:
243  //***
244  ossimGpt v0, v1, v2, v3;
245  ossimDpt ip0 (0.0, 0.0);
246  lineSampleHeightToWorld(ip0, 0.0, v0);
247  ossimDpt ip1 (theImageSize.samp-1.0, 0.0);
248  lineSampleHeightToWorld(ip1, 0.0, v1);
249  ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0);
250  lineSampleHeightToWorld(ip2, 0.0, v2);
251  ossimDpt ip3 (0.0, theImageSize.line-1.0);
252  lineSampleHeightToWorld(ip3, 0.0, v3);
254  = ossimPolygon (ossimDpt(v0), ossimDpt(v1), ossimDpt(v2), ossimDpt(v3));
255 
256  //---
257  // Call compute gsd:
258  //
259  // This will set theGSD and theMeanGSD using lineSampleHeightToWorld on
260  // three image points. Previously this was pulled from metadata. Some of
261  // which was in US Survey feet and not converted to meters. This method
262  // is more accurate as it uses the sensor model to compute.
263  //---
264  try
265  {
266  // Method throws ossimException.
267  computeGsd();
268  }
269  catch (const ossimException& e)
270  {
272  << "ossimIkonosRpcModel finishConstruction Caught Exception:\n"
273  << e.what() << std::endl;
274  }
275 
276  if (traceExec())
277  {
279  << "DEBUG ossimIkonosRpcModel finishConstruction(): returning..."
280  << std::endl;
281  }
282 }
283 
284 //*****************************************************************************
285 // PROTECTED METHOD: ossimIkonosRpcModel::parseMetaData()
286 //
287 // Parses the Ikonos metadata file.
288 //
289 //*****************************************************************************
291 {
292  if (traceExec())
293  {
295  << "DEBUG ossimIkonosRpcModel::parseMetaData(data_file): entering..."
296  << std::endl;
297  }
298 
299  FILE* fptr = fopen (data_file, "r");
300  if (!fptr)
301  {
302  ++theErrorStatus;
303  if (traceExec())
304  {
306  << "ossimIkonosRpcModel::parseMetaData(data_file) DEBUG:"
307  << "\nCould not open Meta data file: " << data_file
308  << "\nreturning with error..." << std::endl;
309  }
310  return;
311  }
312 
313  char* strptr;
314  // char linebuf[80];
315  char dummy[80], name[80];
316 
317  //***
318  // Read the file into a buffer:
319  //***
320  char filebuf[5000];
321  fread(filebuf, 1, 5000, fptr);
322 
323  //***
324  // Image ID:
325  //***
326  strptr = strstr(filebuf, "\nSource Image ID:");
327  if (!strptr)
328  {
329  if (traceDebug())
330  {
332  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
333  << "\n\tAborting construction. Error encountered parsing "
334  << "presumed meta-data file." << endl;
335  }
336 
337  fclose( fptr );
338  fptr = 0;
339  return;
340  }
341 
342  sscanf(strptr, "%17c %s", dummy, name);
343  theImageID = name;
344 
345  //***
346  // Sensor Type:
347  //***
348  strptr = strstr(strptr, "\nSensor:");
349  if (!strptr)
350  {
351  if(traceDebug())
352  {
354  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
355  << "\n\tAborting construction. Error encountered parsing "
356  << "presumed meta-data file." << endl;
357  }
358  fclose(fptr);
359  fptr = 0;
360  return;
361  }
362  sscanf(strptr, "%8c %s", dummy, name);
363  theSensorID = name;
364 
365  //***
366  // GSD: NOTE - this will be recomputed by computeGsd method later.
367  //***
368  strptr = strstr(strptr, "\nPixel Size X:");
369  if (!strptr)
370  {
371  if(traceDebug())
372  {
374  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
375  << "\n\tAborting construction. Error encountered parsing "
376  << "presumed meta-data file." << endl;
377 
378  }
379  fclose(fptr);
380  fptr = 0;
381  return;
382  }
383 
384  sscanf(strptr, "%14c %lf", dummy, &theGSD.samp);
385  strptr = strstr(strptr, "\nPixel Size Y:");
386  if (!strptr)
387  {
388  if(traceDebug())
389  {
391  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
392  << "\n\tAborting construction. Error encountered parsing "
393  << "presumed meta-data file." << endl;
394 
395  }
396  fclose(fptr);
397  fptr = 0;
398  return;
399  }
400  sscanf(strptr, "%14c %lf", dummy, &theGSD.line);
401 
402  //***
403  // Image size:
404  //***
405  strptr = strstr(strptr, "\nColumns:");
406  if (!strptr)
407  {
408  if(traceDebug())
409  {
411  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
412  << "\n\tAborting construction. Error encountered parsing "
413  << "presumed meta-data file." << endl;
414  }
415 
416  fclose(fptr);
417  fptr = 0;
418  return;
419  }
420  sscanf(strptr, "%s %d", dummy, &theImageSize.samp);
421  strptr = strstr(strptr, "\nRows:");
422  if (!strptr)
423  {
424  if(traceDebug())
425  {
427  << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): "
428  << "\n\tAborting construction. Error encountered parsing "
429  << "presumed meta-data file." << endl;
430  }
431 
432  fclose(fptr);
433  fptr = 0;
434  return;
435  }
436  sscanf(strptr, "%s %d", dummy, &theImageSize.line);
437 
438  if (traceExec())
439  {
441  << "DEBUG ossimIkonosRpcModel::parseMetaData(data_file): returning..."
442  << std::endl;
443  }
444  fclose(fptr);
445  fptr = 0;
446 }
447 
448 //*****************************************************************************
449 // PROTECTED METHOD: ossimIkonosRpcModel::parseHdrData()
450 //
451 // Parses the Ikonos hdr file.
452 //
453 //*****************************************************************************
455 {
456  if (traceExec())
457  {
459  << "DEBUG ossimIkonosRpcModel::parseHdrData(data_file): entering..."
460  << std::endl;
461  }
462 
463  if( !data_file.exists() )
464  {
465  if (traceDebug())
466  {
468  << "ossimIkonosRpcModel::parseHdrData(data_file) WARN:"
469  << "\nrpc data file <" << data_file << ">. "<< "doesn't exist..."
470  << std::endl;
471  }
472  return false;
473  }
474 
475  FILE* fptr = fopen (data_file, "r");
476  if (!fptr)
477  {
478  ++theErrorStatus;
479 
480  if (traceDebug())
481  {
483  << "ossimIkonosRpcModel::parseHdrData(data_file) WARN:"
484  << "\nCould not open hdr data file <" << data_file << ">. "
485  << "returning with error..." << std::endl;
486  }
487  return false;
488  }
489 
490  char* strptr = 0;
491  // char linebuf[80];
492  char dummy[80];
493  // , name[80];
494 
495  //***
496  // Read the file into a buffer:
497  //***
498  char filebuf[5000];
499  fread(filebuf, 1, 5000, fptr);
500 
501  //***
502  // GSD: NOTE - this will be recomputed by computeGsd method later.
503  //***
504  strptr = strstr(filebuf, "\nPixel Size X:");
505  if (!strptr)
506  {
507  if(traceDebug())
508  {
510  << "ossimIkonosRpcModel::parseHdrData(data_file):"
511  << "\n\tAborting construction. Error encountered parsing "
512  << "presumed hdr file." << endl;
513  }
514 
515  fclose( fptr ); // cleanup
516  fptr = 0;
517  return false;
518  }
519 
520  sscanf(strptr, "%14c %lf", dummy, &theGSD.samp);
521  strptr = strstr(strptr, "\nPixel Size Y:");
522  if (!strptr)
523  {
524  if(traceDebug())
525  {
527  << "ossimIkonosRpcModel::parseHdrData(data_file): "
528  << "\n\tAborting construction. Error encountered parsing "
529  << "presumed hdr file." << endl;
530  }
531 
532  fclose( fptr ); // cleanup
533  fptr = 0;
534  return false;
535  }
536 
537  sscanf(strptr, "%14c %lf", dummy, &theGSD.line);
538 
539  //***
540  // Image size:
541  //***
542  strptr = strstr(strptr, "\nColumns:");
543  if (!strptr)
544  {
545  if(traceDebug())
546  {
548  << "ossimIkonosRpcModel::parseHdrData(data_file): "
549  << "\n\tAborting construction. Error encountered parsing "
550  << "presumed hdr file." << endl;
551  }
552 
553  fclose( fptr ); // cleanup
554  fptr = 0;
555  return false;
556  }
557  sscanf(strptr, "%s %d", dummy, &theImageSize.samp);
558  strptr = strstr(strptr, "\nRows:");
559  if (!strptr)
560  {
561  if(traceDebug())
562  {
564  << "ossimIkonosRpcModel::parseHdrData(data_file): "
565  << "\n\tAborting construction. Error encountered parsing "
566  << "presumed hdr file." << endl;
567  }
568  fclose( fptr ); // cleanup
569  fptr = 0;
570 
571  return false;
572  }
573  sscanf(strptr, "%s %d", dummy, &theImageSize.line);
574 
575  fclose( fptr ); // cleanup
576  fptr = 0;
577 
578  if (traceExec())
579  {
581  << "DEBUG ossimIkonosRpcModel::parseHdrData(data_file): returning..."
582  << std::endl;
583  }
584  return true;
585 }
586 
587 //*****************************************************************************
588 // PROTECTED METHOD: ossimIkonosRpcModel::parseRpcData()
589 //
590 // Parses the Ikonos RPC data file.
591 //
592 //*****************************************************************************
594 {
595  if (traceExec())
596  {
598  << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): entering..."
599  << std::endl;
600  }
601 
602  if( !data_file.exists() )
603  {
604  if (traceDebug())
605  {
607  << "ossimIkonosRpcModel::parseRpcData(data_file) WARN:"
608  << "\nrpc data file <" << data_file << ">. "<< "doesn't exist..."
609  << std::endl;
610  }
611  ++theErrorStatus;
612  return;
613  }
614 
615  //***
616  // The Ikonos RPC data file is conveniently formatted as KWL file:
617  //***
618  ossimKeywordlist kwl (data_file);
619  if (kwl.getErrorStatus())
620  {
622  << "ERROR ossimIkonosRpcModel::parseRpcData(data_file): Could not open RPC data file <" << data_file << ">. " << "Aborting..." << std::endl;
623  ++theErrorStatus;
624  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG)
625  << "returning with error..." << std::endl;
626  return;
627  }
628 
629  const char* buf;
630  const char* keyword;
631 
632  //***
633  // Parse data from KWL:
634  //***
635  keyword = LINE_OFF_KW;
636  buf = kwl.find(keyword);
637  if (!buf)
638  {
639  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
640  << "\nAborting construction. Error looking up keyword: "
641  << keyword << std::endl;
642  return;
643  }
644  theLineOffset = atof(buf);
645 
646  keyword = SAMP_OFF_KW;
647  buf = kwl.find(keyword);
648  if (!buf)
649  {
650  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
651  << "\nAborting construction. Error looking up keyword: "
652  << keyword << std::endl;
653  return;
654  }
655  theSampOffset = atof(buf);
656 
657  keyword = LAT_OFF_KW;
658  buf = kwl.find(keyword);
659  if (!buf)
660  {
661  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
662  << "\nAborting construction. Error looking up keyword: "
663  << keyword << std::endl;
664  return;
665  }
666 
667  theLatOffset = atof(buf);
668 
669  keyword = LONG_OFF_KW;
670  buf = kwl.find(keyword);
671  if (!buf)
672  {
673  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
674  << "\nAborting construction. Error looking up keyword: "
675  << keyword << std::endl;
676  return;
677  }
678  theLonOffset = atof(buf);
679 
680  keyword = HEIGHT_OFF_KW;
681  buf = kwl.find(keyword);
682  if (!buf)
683  {
684  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
685  << "\nAborting construction. Error looking up keyword: "
686  << keyword << std::endl;
687  return;
688  }
689 
690  theHgtOffset = atof(buf);
691 
692  keyword = LINE_SCALE_KW;
693  buf = kwl.find(keyword);
694  if (!buf)
695  {
696  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
697  << "\nAborting construction. Error looking up keyword: "
698  << keyword << std::endl;
699  return;
700  }
701  theLineScale = atof(buf);
702 
703  keyword = SAMP_SCALE_KW;
704  buf = kwl.find(keyword);
705  if (!buf)
706  {
707  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
708  << "\nAborting construction. Error looking up keyword: "
709  << keyword << std::endl;
710  return;
711  }
712  theSampScale = atof(buf);
713 
714  keyword = LAT_SCALE_KW;
715  buf = kwl.find(keyword);
716  if (!buf)
717  {
718  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
719  << "\nAborting construction. Error looking up keyword: "
720  << keyword << std::endl;
721  return;
722  }
723  else
724  {
725  // copy ossimIkonosMetada-sensor into ossimIkonosRpcModel-sensorId
727  }
728 
729 
730  theLatScale = atof(buf);
731 
732  keyword = LONG_SCALE_KW;
733  buf = kwl.find(keyword);
734  if (!buf)
735  {
736  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
737  << "\nAborting construction. Error looking up keyword: "
738  << keyword << std::endl;
739  return;
740  }
741  theLonScale = atof(buf);
742 
743  keyword = HEIGHT_SCALE_KW;
744  buf = kwl.find(keyword);
745  if (!buf)
746  {
747  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
748  << "\nAborting construction. Error looking up keyword: "
749  << keyword << std::endl;
750  return;
751  }
752 
753  theHgtScale = atof(buf);
754 
755  char kwbuf[32];
756  keyword = kwbuf;
757  for(int i=1; i<=20; i++)
758  {
759  sprintf(kwbuf, "%s%d", LINE_NUM_COEFF_KW, i);
760  buf = kwl.find(keyword);
761  if (!buf)
762  {
763  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
764  << "\nAborting construction. Error looking up keyword: "
765  << keyword << std::endl;
766  return;
767  }
768 
769  theLineNumCoef[i-1] = atof(buf);
770 
771  sprintf(kwbuf, "%s%d", LINE_DEN_COEFF_KW, i);
772  buf = kwl.find(keyword);
773  if (!buf)
774  {
775  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
776  << "\nAborting construction. Error looking up keyword: "
777  << keyword << std::endl;
778  return;
779  }
780  theLineDenCoef[i-1] = atof(buf);
781 
782  sprintf(kwbuf, "%s%d", SAMP_NUM_COEFF_KW, i);
783  buf = kwl.find(keyword);
784  if (!buf)
785  {
786  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
787  << "\nAborting construction. Error looking up keyword: "
788  << keyword << std::endl;
789  return;
790  }
791  theSampNumCoef[i-1] = atof(buf);
792 
793  sprintf(kwbuf, "%s%d", SAMP_DEN_COEFF_KW, i);
794  buf = kwl.find(keyword);
795  if (!buf)
796  {
797  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
798  << "\nAborting construction. Error looking up keyword: "
799  << keyword << std::endl;
800  return;
801  }
802  theSampDenCoef[i-1] = atof(buf);
803  }
804 
805  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): returning..." << std::endl;
806  return;
807 
808  theErrorStatus++;
809  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): returning with error..." << std::endl;
810 
811  return;
812 }
813 
814 //*****************************************************************************
815 // METHOD: ossimIkonosRpcModel::writeGeomTemplate()
816 //
817 // Writes a template of an ossimIkonosRpcModel geometry file.
818 //
819 //*****************************************************************************
821 {
822  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcModel::writeGeomTemplate(os): entering..." << std::endl;
823 
824  os <<
825  "//**************************************************************\n"
826  "// Template for Ikonos RPC geometry keywordlist\n"
827  "//\n"
828  "// NOTE: It is preferable to select the full RPC geometry KWL \n"
829  "// that should have been created with the first use of the\n"
830  "// derived model type ossimIkonosRpcModel. Using this KWL \n"
831  "// implies that an initial geometry is being constructed \n"
832  "// with all adjustable parameters initialized to 0. \n"
833  "//**************************************************************\n"
834  << ossimKeywordNames::TYPE_KW << ": " << MODEL_TYPE << endl;
835  os << META_DATA_FILE << ": <string>\n"
836  << RPC_DATA_FILE << ": <string>\n" << endl;
837 
838  if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimRpcModel::writeGeomTemplate(os): returning..." << std::endl;
839  return;
840 }
841 
843  const char* prefix)const
844 {
845  if(theSupportData.valid())
846  {
847  ossimString supportPrefix = ossimString(prefix) + "support_data.";
848  // copy ossimIkonosMetada-sensor into ossimIkonosRpcModel-sensorId
849  theSupportData->saveState(kwl, supportPrefix);
850  }
851 
852  ossimRpcModel::saveState(kwl, prefix);
853 
854  // this model just sets the base class values so
855  // we do not need to re-construct this model so
856  // specify the type as the base class type
857  //
858 // kwl.add(prefix,
859 // ossimKeywordNames::TYPE_KW,
860 // STATIC_TYPE_NAME(ossimRpcModel),
861 // true);
862 
863  // cout << "kwl:\n" << kwl << std::endl;
864 
865  return true;
866 }
867 
869  const char* prefix)
870 {
871  if(theSupportData.valid())
872  {
873  ossimString supportPrefix = ossimString(prefix) + "support_data.";
874  theSupportData->loadState(kwl, supportPrefix);
875  }
876 
877  return ossimRpcModel::loadState(kwl, prefix);
878 }
879 
881 {
882  return parseTiffFile(file);
883 }
884 
886 {
887  bool result = false;
888 
890 
891  if ( tiff->open(filename) )
892  {
893  if ( !theSupportData )
894  {
896  }
897 
898  if ( theSupportData->open(filename) == false )
899  {
900  if(traceDebug())
901  {
902  // Currently not required by model so we will not error out here.
904  << "WARNING: ossimIkonosMetaData::open returned false.\n"
905  << std::endl;
906  }
907  }
908  else
909  {
910  // copy ossimIkonosMetada-sensor into ossimIkonosRpcModel-sensorId
912  }
913 
914  //convert file to rpc filename and hdr filename so we can get some info
915  ossimFilename rpcfile = filename.noExtension();
916  rpcfile += "_rpc.txt";
917 
918  ossimFilename hdrfile = filename;
919  hdrfile.setExtension(ossimString("hdr"));
920 
921  if( parseHdrData(hdrfile) )
922  {
923  // parseRpcData sets the error status on error.
924  parseRpcData (rpcfile);
925  if ( !getErrorStatus() ) //check for errors in parsing rpc data
926  {
928 
929  //---
930  // Save current state in RPC model format:
931  //---
932  ossimString drivePart;
933  ossimString pathPart;
934  ossimString filePart;
935  ossimString extPart;
936  filename.split(drivePart,
937  pathPart,
938  filePart,
939  extPart);
940 
941  ossimFilename init_rpc_geom;
942  init_rpc_geom.merge(drivePart,
943  pathPart,
945  "");
946 
947  ossimKeywordlist kwl (init_rpc_geom);
948  saveState(kwl);
949 
950  // If we get here set the return status to true.
951  result = true;
952 
953  } // matches: if ( !getErrorStatus() )
954 
955  } // matches: if( parseHdrData(hdrfile) )
956 
957  } // matches: if ( tiff->open(filename) )
958 
959  if ( traceExec() )
960  {
962  << "return status: " << (result?"true\n":"false\n")
963  << "DEBUG ossimIkonosRpcModel parseTiffFile: returning..."
964  << std::endl;
965  }
966 
967  return result;
968 }
969 
971 {
972  std::ifstream in(filename.c_str(), ios::in|ios::binary);
973 
974  if(in)
975  {
976  char nitfFile[4];
977  in.read((char*)nitfFile, 4);
978 
979  return (ossimString(nitfFile,
980  nitfFile+4) == "NITF");
981  }
982 
983  return false;
984 }
double theSampOffset
ossimString theSensorID
PolynomialType thePolyType
double theSampNumCoef[20]
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of the object to a keyword list.
ossimFilename noExtension() const
std::basic_filebuf< char > filebuf
Class for char file buffers.
Definition: ossimIosFwd.h:41
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Fulfills ossimObject base-class pure virtuals.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
Represents serializable keyword/value map.
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
ossimString theImageID
double samp
Definition: ossimDpt.h:164
void split(ossimString &drivePart, ossimString &pathPart, ossimString &filePart, ossimString &extPart) const
virtual void updateModel()
ossim_float64 hgt
Height in meters above the ellipsiod.
Definition: ossimGpt.h:274
ossimRefPtr< ossimIkonosMetaData > theSupportData
double theLonScale
double theLineScale
static const char * TYPE_KW
double theSampDenCoef[20]
double theLineNumCoef[20]
bool parseTiffFile(const ossimFilename &filename)
double theLatOffset
double theHgtOffset
double theLonOffset
void computeGsd()
This method computes the ground sample distance(gsd) and sets class attributes theGSD and theMeanGSD ...
double line
Definition: ossimDpt.h:165
bool exists() const
ossim_float64 lon
Definition: ossimGpt.h:266
double theLatScale
virtual const char * what() const
Returns the error message.
bool isNitf(const ossimFilename &filename)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saveState Fulfills ossimObject base-class pure virtuals.
const ossimFilename INIT_RPC_GEOM_FILENAME("rpc_init.geom")
ossimPolygon theBoundGndPolygon
virtual void lineSampleHeightToWorld(const ossimDpt &image_point, const double &heightEllipsoid, ossimGpt &worldPoint) const
void parseRpcData(const ossimFilename &rpcdata)
bool open(const ossimFilename &imageFile)
Open method that takes the image file, derives the metadata, header and rpc files, then calls parse methods parseMetaData, parseHdrData, and parseRpcData.
void parseMetaData(const ossimFilename &metadata)
static void writeGeomTemplate(ostream &os)
ossimDrect theImageClipRect
virtual bool parseFile(const ossimFilename &file)
ossim_int32 samp
Definition: ossimIpt.h:141
virtual ossimErrorCode getErrorStatus() const
RTTI_DEF1(ossimIkonosRpcModel, "ossimIkonosRpcModel", ossimRpcModel)
virtual bool open(const ossimFilename &image_file)
Returns true if the image_file can be opened and is a valid tiff file.
void merge(const ossimString &drivePart, const ossimString &pathPart, const ossimString &filePart, const ossimString &extPart)
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
double theSampScale
ossim_int32 line
Definition: ossimIpt.h:142
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Fulfills ossimObject base-class pure virtuals.
ossim_float64 lat
Definition: ossimGpt.h:265
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
loadState Fulfills ossimObject base-class pure virtuals.
double theLineDenCoef[20]
ossimString getSensorID() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
double theLineOffset
double theHgtScale
bool parseHdrData(const ossimFilename &data_file)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23