OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTerraSarModel.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 #include <ossimTerraSarModel.h>
13 #include <ossimPluginCommon.h>
18 #include <ossim/base/ossimRefPtr.h>
19 #include <ossim/base/ossimTrace.h>
23 #include <ossim/base/ossimTrace.h>
25 #include <otb/GalileanEphemeris.h>
27 #include <otb/GMSTDateTime.h>
28 #include <otb/PlatformPosition.h>
29 #include <otb/SensorParams.h>
30 #include <otb/RefPoint.h>
31 #include <otb/SarSensor.h>
32 #include <cmath>
33 #include <iostream>
34 #include <sstream>
35 
36 
37 // Keyword constants:
38 static const char NUMBER_SRGR_COEFFICIENTS_KW[] = "sr_gr_coeffs_count";
39 static const char LOAD_FROM_PRODUCT_FILE_KW[] = "load_from_product_file_flag";
40 static const char PRODUCT_XML_FILE_KW[] = "product_xml_filename";
41 static const char SR_GR_R0_KW[] = "sr_gr_r0";
42 static const char SC_RT_KW[] = "sc_rt";
43 static const char SR_GR_SF_KW[] = "sc_gr_sf";
44 static const char ALT_SR_GR_COEFFICIENT0_KW[] = "alt_sr_gr_coeff0";
45 static const char ALT_SR_GR_COEFFICIENT1_KW[] = "alt_sr_gr_coeff1";
46 static const char ALT_SR_GR_COEFFICIENT2_KW[] = "alt_sr_gr_coeff2";
47 static const char PRODUCT_TYPE[] = "product_type";
48 static const char RADIOMETRIC_CORRECTION[] = "radiometricCorrection";
49 static const char AZ_START_TIME[] = "azimuth_start_time";
50 static const char AZ_STOP_TIME[] = "azimuth_stop_time";
51 static const char RG_FIRST_TIME[] = "range_first_time";
52 static const char RG_LAST_TIME[] = "range_last_time";
53 static const char GENERATION_TIME[] = "generation_time";
54 static const char ACQUISITION_INFO[] = "acquisitionInfo.";
55 static const char IMAGING_MODE[] = "imagingMode";
56 static const char SENSOR[] = "sensor";
57 static const char LOOK_DIRECTION[] = "lookDirection";
58 static const char POLARISATION_MODE[] = "polarisationMode";
59 static const char POLARISATION_LIST[] = "polarisationList";
60 static const char NUMBER_LAYERS[] = "numberOfLayers";
61 static const char CALIBRATION_CALFACTOR[] = "calibration.calibrationConstant.calFactor";
62 static const char RADAR_FREQUENCY[] = "radarFrequency";
63 
64 // Static trace for debugging
65 static ossimTrace traceDebug("ossimTerraSarModel:debug");
66 
67 namespace ossimplugins
68 {
69  RTTI_DEF1(ossimTerraSarModel,
70  "ossimTerraSarModel",
71  ossimGeometricSarSensorModel);
72 }
73 
76  _SrToGr_R0(0.0),
77  _SrToGr_exponent(),
78  _SrToGr_coeffs(),
79  _sceneCenterRangeTime(0.0),
80  _SrToGr_scaling_factor(0.0),
81  _alt_srgr_coefset(3),
82  _productType(),
83  _radiometricCorrection(),
84  _imagingMode(),
85  _acquisitionSensor(),
86  _lookDirection(),
87  _polarisationMode(),
88  _polLayer("UNDEFINED"),
89  _polLayerList(),
90  _noise(0),
91  _sceneCoord(0),
92  _calFactor(0.),
93  _radarFrequency(0.),
94  _numberOfLayers(0),
95  _azStartTime(),
96  _azStopTime(),
97  _rgFirstPixelTime(),
98  _rgLastPixelTime(),
99  _generationTime()
100 {
101 }
102 
104  const ossimTerraSarModel& rhs)
106  _SrToGr_R0(rhs._SrToGr_R0),
107  _SrToGr_exponent(rhs._SrToGr_exponent),
108  _SrToGr_coeffs(rhs._SrToGr_coeffs),
109  _sceneCenterRangeTime(rhs._sceneCenterRangeTime),
110  _SrToGr_scaling_factor(rhs._SrToGr_scaling_factor),
111  _alt_srgr_coefset(rhs._alt_srgr_coefset),
112  _productType(rhs._productType),
113  _radiometricCorrection(rhs._radiometricCorrection),
114  _imagingMode(rhs._imagingMode),
115  _acquisitionSensor(rhs._acquisitionSensor),
116  _lookDirection(rhs._lookDirection),
117  _polarisationMode(rhs._polarisationMode),
118  _polLayer(rhs._polLayer),
119  _polLayerList(rhs._polLayerList),
120  _noise(rhs._noise),
121  _sceneCoord( 0 ),
122  _calFactor(rhs._calFactor),
123  _radarFrequency(rhs._radarFrequency),
124  _numberOfLayers(rhs._numberOfLayers),
125  _azStartTime(rhs._azStartTime),
126  _azStopTime(rhs._azStopTime),
127  _rgFirstPixelTime(rhs._rgFirstPixelTime),
128  _rgLastPixelTime(rhs._rgLastPixelTime),
129  _generationTime(rhs._generationTime)
130 {
131  if ( rhs._sceneCoord )
132  {
133  _sceneCoord = new SceneCoord( *(rhs._sceneCoord) );
134  }
135 }
136 
138 {
139  _noise.clear();
140 
141 /*
142  * if (_noise != 0)
143  {
144  delete _noise;
145  }
146 */
147  if (_sceneCoord)
148  {
149  delete _sceneCoord;
150  _sceneCoord = 0;
151  }
152 }
153 
155 {
156  return ossimString("ossimTerraSarModel");
157 }
158 
160 {
161  return new ossimTerraSarModel(*this);
162 }
163 
164 // Note : ground range to slant range coputation could be performed in three ways :
165 // (1) Slant Range to Ground Range polynomial inversion (coefficients given at mid-scene)
166 // (2) use of a parabolic model from three geolocated points
167 // (3) interpolation from the geolocation grid (separate file, most precise technique)
168 // In this version, (1) and (2) were implemented but (1) is imprecise on the test products.
170 {
171  const double c = 2.99792458e+8;
172  double tn = _alt_srgr_coefset[0] + _alt_srgr_coefset[1] * col + _alt_srgr_coefset[2] * col*col ;
173  return tn * (c/2.0);
174 }
175 
177 {
178  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::open() -- ";
179 
180  _imageFilename = file.expand();
181  _productXmlFile = ossimFilename::NIL;
182  ossimFilename xmlfile;
183  bool foundMetadataFile = findTSXLeader(file, xmlfile);
184  while (foundMetadataFile) // use of while allows use of "break"
185  {
186  //---
187  // Instantiate the XML parser:
188  //---
190  if ( !xdoc->openFile(xmlfile) ) break;
191 
193  if (!tsDoc.isTerraSarX(xdoc.get())) break;
194 
195  ossimString s;
196  if ( tsDoc.getProjection(xdoc.get(), s) )
197  {
198  if ( s.upcase() == "MAP" ) break;
199  }
200 
201  // Set the base class number of lines and samples
202  // Set the base class clip rect.
203  // Set the sub image offset. tmp hard coded (drb).
204  if (!tsDoc.initImageSize(xdoc.get(), theImageSize)) break;
205  theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1);
206  theSubImageOffset.x = 0.0;
207  theSubImageOffset.y = 0.0;
208 
209  // Set the image ID to the scene ID.
210  if (!tsDoc.getSceneId(xdoc.get(), theImageID)) break;
211 
212  // Set the sensor ID to the mission ID.
213  if (!tsDoc.getMission(xdoc.get(), theSensorID)) break;
214 
215  // Set the base class gsd:
216  if (!tsDoc.initGsd(xdoc.get(), theGSD)) break;
217  theMeanGSD = (theGSD.x + theGSD.y)/2.0;
218 
219  initSRGR(xdoc.get(), tsDoc);
220 
221  if (!initPlatformPosition(xdoc.get(), tsDoc)) break;
222  if (!initSensorParams(xdoc.get(), tsDoc)) break;
223  if (!initRefPoint(xdoc.get(), tsDoc)) break;
224  if (!tsDoc.getProductType(xdoc.get(), _productType)) break;
225  if (!tsDoc.getRadiometricCorrection(xdoc.get(), _radiometricCorrection)) break;
226  if (!initAcquisitionInfo(xdoc.get(), tsDoc)) break;
227  if (!initNoise(xdoc.get(), tsDoc)) break;
228  if (!getPolLayerFromImageFile(xdoc.get(), file)) break;
229  if (!initCalibration(xdoc.get(), tsDoc)) break;
230 
231 // replaced by OTB by the initCalibration above
232 // if (!tsDoc.getCalFactor(xdoc.get(), s)) break;
233 // _calFactor = s.toFloat64();
234 
235  if (!tsDoc.getRadarFrequency(xdoc.get(), s)) break;
236  _radarFrequency= s.toFloat64();
237 
238  if (!tsDoc.getAzimuthStartTime(xdoc.get(), _azStartTime)) break;
239  if (!tsDoc.getAzimuthStopTime(xdoc.get(), _azStopTime)) break;
240  if (!tsDoc.getRangeFirstPixelTime(xdoc.get(), _rgFirstPixelTime)) break;
241  if (!tsDoc.getRangeLastPixelTime(xdoc.get(), _rgLastPixelTime)) break;
242  if (!tsDoc.getGenerationTime(xdoc.get(), _generationTime)) break;
243 // removed by OTB
244 // if (!initIncidenceAngles(xdoc.get(), tsDoc)) break;
245  if (!initSceneCoord(xdoc.get(), tsDoc)) break;
246 
247  xdoc = 0;
248 
249  _productXmlFile = xmlfile;
250  ossimSupportFilesList::instance()->add(_productXmlFile);
251 
252  // Assign the ossimSensorModel::theBoundGndPolygon
253  ossimGpt ul;
254  ossimGpt ur;
255  ossimGpt lr;
256  ossimGpt ll;
257  lineSampleToWorld(theImageClipRect.ul(), ul);
258  lineSampleToWorld(theImageClipRect.ur(), ur);
259  lineSampleToWorld(theImageClipRect.lr(), lr);
260  lineSampleToWorld(theImageClipRect.ll(), ll);
261  setGroundRect(ul, ur, lr, ll); // ossimSensorModel method.
262  if (traceDebug())
263  {
264  ossimNotify(ossimNotifyLevel_NOTICE) << MODULE << "Loaded support data file <"<<xmlfile
265  <<"> for image <"<<file<<">."<<std::endl;
266 
268  << "4 corners from Projection: " << "\n"
269  << ul << ", " << ur << ", " << lr << ", " << ll << "\n";
270  }
271 
272  // OSSIM preferences specifies whether a coarse grid needs to be generated:
273  if (!createReplacementOCG()) break;
274  return true;
275  }
276 
277  // If we broke out of the while, something happened...
278  return false;
279 
280 } // End of: bool ossimTerraSarModel::open(const ossimFilename& file)
281 
283  const char* prefix) const
284 {
285  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::saveState";
286 
287  if (traceDebug())
288  {
289  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
290  }
291 
292  bool result = false;
293 
294  if ( (_alt_srgr_coefset.size() == 3) &&
295  ( _SrToGr_exponent.size() == _SrToGr_coeffs.size()) )
296  {
297  // Save our state:
298  kwl.add(prefix, SR_GR_R0_KW, _SrToGr_R0);
299 
300  ossimString kw1 = "sr_gr_exponent_";
301  ossimString kw2 = "sr_gr_coeffs_";
302 
303  const ossim_uint32 COUNT = _SrToGr_exponent.size();
304 
305  kwl.add(prefix, NUMBER_SRGR_COEFFICIENTS_KW, COUNT);
306 
307  for(ossim_uint32 i = 0; i < COUNT; ++i)
308  {
310  ossimString kw = kw1;
311  kw += iStr;
312  kwl.add(prefix, kw, _SrToGr_exponent[i]);
313  kw = kw2;
314  kw += iStr;
315  kwl.add(prefix, kw, _SrToGr_coeffs[i]);
316  }
317  kwl.add(prefix, SC_RT_KW, _sceneCenterRangeTime);
318  kwl.add(prefix, SR_GR_SF_KW, _SrToGr_scaling_factor);
319  kwl.add(prefix, ALT_SR_GR_COEFFICIENT0_KW, _alt_srgr_coefset[0]);
320  kwl.add(prefix, ALT_SR_GR_COEFFICIENT1_KW, _alt_srgr_coefset[1]);
321  kwl.add(prefix, ALT_SR_GR_COEFFICIENT2_KW, _alt_srgr_coefset[2]);
322  kwl.add(prefix, PRODUCT_XML_FILE_KW, _productXmlFile.c_str());
323 
324  // Call base save state:
325  result = ossimGeometricSarSensorModel::saveState(kwl, prefix);
326  }
327 
328  //---
329  // Uncomment to force load from product file instead of loadState.
330  //---
331  if (result)
332  {
333  // kwl.add(prefix, LOAD_FROM_PRODUCT_FILE_KW, "true");
334  }
335 
336  kwl.add(prefix, PRODUCT_TYPE, _productType.c_str());
337 
338  kwl.add(prefix, RADIOMETRIC_CORRECTION, _radiometricCorrection.c_str());
339 
340  ossimString kw = ACQUISITION_INFO;
341  ossimString kw2 = kw + IMAGING_MODE;
342  kwl.add(prefix, kw2, _imagingMode.c_str());
343  kw2 = kw + SENSOR;
344  kwl.add(prefix, kw2, _acquisitionSensor.c_str());
345  kw2 = kw + LOOK_DIRECTION;
346  kwl.add(prefix, kw2, _lookDirection.c_str());
347  kw2 = kw + POLARISATION_MODE;
348  kwl.add(prefix, kw2, _polarisationMode.c_str());
349  kw2 = kw + POLARISATION_LIST;
350  for(ossim_uint32 i = 0; i < _numberOfLayers; ++i)
351  {
352  ossimString iStr = ossimString::toString(i)+"]";
353  ossimString kw3 = kw2+"[";
354  kw3 += iStr;
355  kwl.add(prefix, kw3, _polLayerList[i].c_str());
356  }
357 
358  if( _polLayer !="UNDEFINED")
359  {
360  ossim_uint32 polLayerIdx = 0;
361  for(ossim_uint32 idx = 0 ; idx < _polLayerList.size(); ++idx)
362  {
363  if(_polLayerList[idx] == _polLayer)
364  {
365  polLayerIdx = idx;
366  }
367  }
368  _noise[polLayerIdx].saveState(kwl,prefix);
369  }
370  else
371  {
372  for(ossim_uint32 i = 0; i < _numberOfLayers; ++i)
373  {
374  _noise[i].saveState(kwl,prefix);
375  }
376  }
377  _sceneCoord->saveState(kwl,prefix);
378 
379  for(ossim_uint32 i = 0; i < _numberOfLayers; ++i)
380  {
381  kwl.add(prefix, CALIBRATION_CALFACTOR, ossimString::toString(_calFactor[i]).c_str());
382  }
383  kwl.add(prefix, RADAR_FREQUENCY, ossimString::toString(_radarFrequency).c_str());
384  kwl.add(prefix, AZ_START_TIME, _azStartTime.c_str());
385  kwl.add(prefix, AZ_STOP_TIME, _azStopTime.c_str());
386  kwl.add(prefix, RG_FIRST_TIME, _rgFirstPixelTime.c_str());
387  kwl.add(prefix, RG_LAST_TIME, _rgLastPixelTime.c_str());
388 
389  kwl.add(prefix, GENERATION_TIME, _generationTime.c_str());
390 
391  if (traceDebug())
392  {
394  << MODULE << " exit status = " << (result?"true":"false\n")
395  << std::endl;
396  }
397 
398  return result;
399 }
400 
402  const char *prefix)
403 {
404  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::loadState";
405 
406  if (traceDebug())
407  {
408  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
409  }
410 
411  const char* lookup = 0;
412  ossimString s;
413 
414  // Check the type first.
415  lookup = kwl.find(prefix, ossimKeywordNames::TYPE_KW);
416  if (lookup)
417  {
418  s = lookup;
419  if (s != getClassName())
420  {
421  return false;
422  }
423  }
424 
425  // Get the product.xml file name.
426  lookup = kwl.find(prefix, PRODUCT_XML_FILE_KW);
427 
428  if (lookup)
429  {
430  _productXmlFile = lookup;
431 
432  // See if caller wants to load from xml vice keyword list.
433  lookup = kwl.find(prefix, LOAD_FROM_PRODUCT_FILE_KW);
434  if (lookup)
435  {
436  s = lookup;
437  if ( s.toBool() )
438  {
439  // Loading from product.xml file.
440  return open(_productXmlFile);
441  }
442  }
443  }
444 
445 
446  //---
447  // Temp: This must be cleared or you end up with a bounding rect of all
448  // zero's.
449  //---
450  theBoundGndPolygon.clear();
451 
452  // Load the base class.
453  bool result = ossimGeometricSarSensorModel::loadState(kwl, prefix);
454 
455  if (result)
456  {
457  lookup = kwl.find(prefix,SR_GR_R0_KW);
458  if (lookup)
459  {
460  s = lookup;
461  _SrToGr_R0 = s.toDouble();
462  }
463  else
464  {
465  if (traceDebug())
466  {
468  << MODULE
469  << "\nRequired keyword not found: "
470  << SR_GR_R0_KW << "\n";
471  }
472  result = false;
473  }
474 
475  ossim_uint32 count = 0;
476  lookup = kwl.find(prefix, NUMBER_SRGR_COEFFICIENTS_KW);
477  if (lookup)
478  {
479  s = lookup;
480  count = s.toUInt32();
481  }
482  else
483  {
484  if (traceDebug())
485  {
487  << MODULE
488  << "\nRequired keyword not found: "
489  << NUMBER_SRGR_COEFFICIENTS_KW << "\n";
490  }
491  result = false;
492  }
493 
495 
496  if (result && count)
497  {
498  _SrToGr_exponent.resize(count);
499  _SrToGr_coeffs.resize(count);
500 
501  ossimString kw1 = "sr_gr_exponent_";
502  ossimString kw2 = "sr_gr_coeffs_";
503 
504  for(ossim_uint32 i = 0; i < count; ++i)
505  {
506  ossimString kw;
508 
509  // sr_gr_exponents
510  kw = kw1;
511  kw += iStr;
512 
513  lookup = kwl.find(prefix, kw);
514  if (lookup)
515  {
516  s = lookup;
517  _SrToGr_exponent[i] = s.toInt();
518  }
519  else
520  {
521  if (traceDebug())
522  {
524  << MODULE
525  << "\nRequired keyword not found: "
526  << kw << "\n";
527  }
528  result = false;
529  }
530 
531  // _SrToGr_coeffs
532  kw = kw2;
533  kw += iStr;
534  lookup = kwl.find(prefix, kw);
535  if (lookup)
536  {
537  s = lookup;
538  _SrToGr_coeffs[i] = s.toDouble();
539  }
540  else
541  {
542  if (traceDebug())
543  {
545  << MODULE
546  << "\nRequired keyword not found: "
547  << kw << "\n";
548  }
549  result = false;
550  }
551  }
552 
553  } // matches: if (result && count)
554 
555  lookup = kwl.find(prefix, SC_RT_KW);
556  if (lookup)
557  {
558  s = lookup;
559  _sceneCenterRangeTime = s.toDouble();
560  }
561  else
562  {
563  if (traceDebug())
564  {
566  << MODULE
567  << "\nRequired keyword not found: "
568  << SC_RT_KW << "\n";
569  }
570  result = false;
571  }
572 
573  lookup = kwl.find(prefix, SR_GR_SF_KW);
574  if (lookup)
575  {
576  s = lookup;
577  _SrToGr_scaling_factor = s.toDouble();
578  }
579  else
580  {
581  if (traceDebug())
582  {
584  << MODULE
585  << "\nRequired keyword not found: "
586  << SR_GR_SF_KW << "\n";
587  }
588  result = false;
589  }
590 
591  lookup = kwl.find(prefix, ALT_SR_GR_COEFFICIENT0_KW);
592  if (lookup)
593  {
594  s = lookup;
595  _alt_srgr_coefset[0] = s.toDouble();
596  }
597  else
598  {
599  if (traceDebug())
600  {
602  << MODULE
603  << "\nRequired keyword not found: "
604  << ALT_SR_GR_COEFFICIENT0_KW << "\n";
605  }
606  result = false;
607  }
608  lookup = kwl.find(prefix, ALT_SR_GR_COEFFICIENT1_KW);
609  if (lookup)
610  {
611  s = lookup;
612  _alt_srgr_coefset[1] = s.toDouble();
613  }
614  else
615  {
616  if (traceDebug())
617  {
619  << MODULE
620  << "\nRequired keyword not found: "
621  << ALT_SR_GR_COEFFICIENT1_KW << "\n";
622  }
623  result = false;
624  }
625  lookup = kwl.find(prefix, ALT_SR_GR_COEFFICIENT2_KW);
626  if (lookup)
627  {
628  s = lookup;
629  _alt_srgr_coefset[2] = s.toDouble();
630  }
631  else
632  {
633  if (traceDebug())
634  {
636  << MODULE
637  << "\nRequired keyword not found: "
638  << ALT_SR_GR_COEFFICIENT2_KW << "\n";
639  }
640  result = false;
641  }
642 
643  lookup = kwl.find(prefix, PRODUCT_XML_FILE_KW);
644  if (lookup)
645  {
646  _productXmlFile = lookup;
647  }
648  else
649  {
650  if (traceDebug())
651  {
653  << MODULE
654  << "\nRequired keyword not found: "
655  << PRODUCT_XML_FILE_KW << "\n";
656  }
657  result = false;
658  }
659 
660  } // matches: if (result)
661 
662  // Load the base class.
663  /*
664  * TODO correct loadState
665  */
666 #if 0
667  if ( !_noise)
668  {
669  _noise = new Noise();
670  }
671  if ( _noise->loadState(kwl, prefix) == false )
672  {
673  if (traceDebug())
674  {
676  << MODULE
677  << "\n_noise->loadState failed!\n";
678  }
679  result = false;
680  }
681 #endif
682 
683 
684  // Load the base class.
685  if ( !_sceneCoord)
686  {
687  _sceneCoord = new SceneCoord();
688  }
689 
690  if ( _sceneCoord->loadState(kwl,prefix) == false )
691  {
692  if (traceDebug())
693  {
695  << MODULE
696  << "\n__sceneCoord->loadState failed!\n";
697  }
698  result = false;
699  }
700 
701  lookup = kwl.find(prefix, CALIBRATION_CALFACTOR);
702  if (lookup)
703  {
704  std::istringstream in(lookup);
705  ossimString tempValue;
706  for(ossim_uint32 idx = 0; idx < _numberOfLayers; ++idx)
707  {
708  in >> tempValue;
709  _calFactor[idx] = tempValue.toDouble();
710 
711  }
712  }
713  else
714  {
715  if (traceDebug())
716  {
718  << MODULE
719  << "\nRequired keyword not found: "
720  << CALIBRATION_CALFACTOR << "\n";
721  }
722  result = false;
723  }
724 
725  lookup = kwl.find(prefix, RADAR_FREQUENCY);
726  if (lookup)
727  {
728  s = lookup;
729  _radarFrequency= s.toDouble();
730  }
731  else
732  {
733  if (traceDebug())
734  {
736  << MODULE
737  << "\nRequired keyword not found: "
738  << RADAR_FREQUENCY << "\n";
739  }
740  result = false;
741  }
742 
743  lookup = kwl.find(prefix, AZ_START_TIME);
744  if (lookup)
745  {
746  _azStartTime = lookup;
747  }
748  else
749  {
750  if (traceDebug())
751  {
753  << MODULE
754  << "\nRequired keyword not found: "
755  << AZ_START_TIME << "\n";
756  }
757  result = false;
758  }
759 
760  lookup = kwl.find(prefix, AZ_STOP_TIME);
761  if (lookup)
762  {
763  _azStopTime = lookup;
764  }
765  else
766  {
767  if (traceDebug())
768  {
770  << MODULE
771  << "\nRequired keyword not found: "
772  << AZ_STOP_TIME << "\n";
773  }
774  result = false;
775  }
776 
777  lookup = kwl.find(prefix, RG_FIRST_TIME);
778  if (lookup)
779  {
780  _rgFirstPixelTime = lookup;
781  }
782  else
783  {
784  if (traceDebug())
785  {
787  << MODULE
788  << "\nRequired keyword not found: "
789  << RG_FIRST_TIME << "\n";
790  }
791  result = false;
792  }
793 
794  lookup = kwl.find(prefix, RG_LAST_TIME);
795  if (lookup)
796  {
797  _rgLastPixelTime = lookup;
798  }
799  else
800  {
801  if (traceDebug())
802  {
804  << MODULE
805  << "\nRequired keyword not found: "
806  << RG_LAST_TIME << "\n";
807  }
808  result = false;
809  }
810 
811 
812  lookup = kwl.find(prefix, GENERATION_TIME);
813  if (lookup)
814  {
815  _generationTime = lookup;
816  }
817  else
818  {
819  if (traceDebug())
820  {
822  << MODULE
823  << "\nRequired keyword not found: "
824  << GENERATION_TIME << "\n";
825  }
826  result = false;
827  }
828 
829  if (traceDebug())
830  {
832  << MODULE << " exit status = " << (result?"true":"false\n")
833  << std::endl;
834  }
835 
836  return result;
837 }
838 
840 {
841  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::print";
842  // Capture the original flags.
843  std::ios_base::fmtflags f = out.flags();
844 
845  out << setprecision(15) << setiosflags(ios::fixed)
846  << "\nossimTerraSarModelclass data members:\n"
847  << SR_GR_R0_KW << _SrToGr_R0 << "\n";
848 
849  ossim_uint32 i;
850 
851  ossimString kw1 = "sr_gr_exponent_";
852  for(i = 0; i < _SrToGr_exponent.size(); ++i)
853  {
855  ossimString kw = kw1;
856  kw += iStr;
857  kw += ": ";
858  out << kw << _SrToGr_exponent[i] << "\n";
859  }
860 
861  kw1 = "sr_gr_coeffs_";
862  for(i = 0; i < _SrToGr_coeffs.size(); ++i)
863  {
865  ossimString kw = kw1;
866  kw += iStr;
867  kw += ": ";
868  out << kw << _SrToGr_coeffs[i] << "\n";
869  }
870 
871  out << SC_RT_KW << ": " << _sceneCenterRangeTime << "\n"
872  << SR_GR_SF_KW << ": " << _SrToGr_scaling_factor << "\n"
873  << ALT_SR_GR_COEFFICIENT0_KW << ": " << _alt_srgr_coefset[0] << "\n"
874  << ALT_SR_GR_COEFFICIENT1_KW << ": " <<_alt_srgr_coefset[1] << "\n"
875  << ALT_SR_GR_COEFFICIENT2_KW << ": " <<_alt_srgr_coefset[2] << "\n"
876  << PRODUCT_XML_FILE_KW << ": " << _productXmlFile.c_str() << "\n";
877 
879  for(ossim_uint32 i = 0; i < _numberOfLayers; ++i)
880  {
881  if ( !_noise[i].print(out) )
882  {
883  if (traceDebug())
884  {
886  << MODULE
887  << "\n_noise->print failed!\n";
888  }
889  }
890  }
891 
892  if ( !_sceneCoord->print(out) )
893  {
894  if (traceDebug())
895  {
897  << MODULE
898  << "\n_sceneCoord->print failed!\n";
899  }
900  }
901 
902  out << NUMBER_LAYERS << ": " << _numberOfLayers << "\n";
903  for(ossim_uint32 idx = 0; idx < _numberOfLayers; ++idx)
904  {
905  out << CALIBRATION_CALFACTOR << "["<< idx << "]: " << _calFactor[idx] << "\n";
906  }
907  out << RADAR_FREQUENCY << ": " << _radarFrequency<< "\n";
908  out << AZ_START_TIME << ": " << _azStartTime << "\n";
909  out << AZ_STOP_TIME << ": " << _azStopTime << "\n";
910  out << RG_FIRST_TIME << ": " << _rgFirstPixelTime << "\n";
911  out << RG_LAST_TIME << ": " << _rgLastPixelTime << "\n";
912  out << GENERATION_TIME << ": " << _generationTime << "\n";
913 
914  // Reset flags.
915 
916  ossimString kw = ACQUISITION_INFO;
917  ossimString kw2 = kw + IMAGING_MODE;
918  out << kw2 << ": " << _imagingMode.c_str()<< "\n";
919  kw2 = kw + SENSOR;
920  out << kw2<< ": " << _acquisitionSensor.c_str()<< "\n";
921  kw2 = kw + LOOK_DIRECTION;
922  out << kw2<< ": " << _lookDirection.c_str()<< "\n";
923  kw2 = kw + POLARISATION_MODE;
924  out << kw2<< ": " << _polarisationMode.c_str()<< "\n";
925 /* kw2 = kw + POLARISATION_LIST;
926  for(ossim_uint32 i = 0; i < _numberOfLayers; ++i)
927  {
928  out << kw2 << "["<< i <<"] : " << _polLayer[i].c_str()<< "\n";
929  if ( _noise[i]->print(out) == false )
930  {
931  if (traceDebug())
932  {
933  ossimNotify(ossimNotifyLevel_WARN)
934  << MODULE
935  << "\n_noise->print failed!\n";
936  }
937  }
938  }
939 */
940 
941 
942  out.setf(f);
943 
944  return out;
945 }
946 
947 /*
948 // Version (1)
949 double ossimplugins::ossimTerraSarModel::getSlantRangeFromGeoreferenced(double col) const
950 {
951 // iterative polynomial inversion
952 const double CLUM = 2.99792458e+8 ;
953 double EPSILON = 0.0000001 ;
954 double iterError = 1.0 ;
955 int maxIter = 50, nIter=0 ;
956 double estimatedGroundRange, estimatedSlantRangeTime, actualGroundRange, estimatedSlantRange ;
957 
958 
959 // actual ground range computation relative to the image near side
960 // in the case of Georeferenced images, _refPoint->get_distance() contains the ground range
961 actualGroundRange = _refPoint->get_distance() - _sensor->get_col_direction() * (col-_refPoint->get_pix_col()) * _SrToGr_scaling_factor ;
962 
963 estimatedSlantRangeTime = _sceneCenterRangeTime ;
964 while ((fabs(iterError)>EPSILON)&& (nIter<maxIter)) {
965 // estimated ground range computation from SrToGr
966 estimatedGroundRange = 0.0 ;
967 for (int i=0; i<_SrToGr_coeffs.size(); i++) {
968 estimatedGroundRange += _SrToGr_coeffs[i]*pow(estimatedSlantRangeTime-_SrToGr_R0,_SrToGr_exponent[i]);
969 }
970 
971 // comparison between the estimated ground range and the actual ground range
972 iterError = actualGroundRange - estimatedGroundRange ;
973 
974 // estimated slant range update
975 estimatedSlantRangeTime += iterError * 2.0 / CLUM ;
976 
977 nIter++;
978 }
979 
980 estimatedSlantRange = estimatedSlantRangeTime* CLUM / 2.0 ;
981 
982 return estimatedSlantRange ;
983 }
984 */
985 
987  const ossimKeywordlist &kwl, const char *prefix)
988 {
989 
990 
991 
992 
993  const char* central_freq_str = kwl.find(prefix,"central_freq");
994  double central_freq = atof(central_freq_str);
995  const char* fr_str = kwl.find(prefix,"fr");
996  double fr = atof(fr_str);
997  const char* fa_str = kwl.find(prefix,"fa");
998  double fa = atof(fa_str);
999 
1000 
1001 
1002 
1003  //number of different looks
1004  // const char* n_azilok_str = kwl.find(prefix,"n_azilok");
1005  // double n_azilok = atof(n_azilok_str);
1006  const char* n_rnglok_str = kwl.find(prefix,"n_rnglok");
1007  double n_rnglok = atof(n_rnglok_str);
1008 
1009  //ellipsoid parameters
1010  const char* ellip_maj_str = kwl.find(prefix,"ellip_maj");
1011  double ellip_maj = atof(ellip_maj_str) * 1000.0; // km -> m
1012  const char* ellip_min_str = kwl.find(prefix,"ellip_min");
1013  double ellip_min = atof(ellip_min_str) * 1000.0; // km -> m
1014 
1015 
1016  if(_sensor != NULL)
1017  {
1018  delete _sensor;
1019  }
1020 
1021  _sensor = new SensorParams();
1022 
1023 
1024  if (_isProductGeoreferenced)
1025  {
1026  const char* orbitDirection_str = kwl.find(prefix,"orbitDirection");
1027  std::string orbitDirection(orbitDirection_str) ;
1028  int orbitDirectionSign ;
1029  if (orbitDirection=="DESCENDING") orbitDirectionSign = 1 ;
1030  else orbitDirectionSign = - 1 ;
1031 
1032  const char* imageDataStartWith_str = kwl.find(prefix,"imageDataStartWith");
1033  std::string imageDataStartWith(imageDataStartWith_str) ;
1034  if (imageDataStartWith=="EARLYAZNEARRG") {
1035  _sensor->set_col_direction(orbitDirectionSign);
1036  _sensor->set_lin_direction(orbitDirectionSign);
1037  } else if (imageDataStartWith=="EARLYAZFARRG") {
1038  _sensor->set_col_direction(-orbitDirectionSign);
1039  _sensor->set_lin_direction(orbitDirectionSign);
1040  } else if (imageDataStartWith=="LATEAZNEARRG") {
1041  _sensor->set_col_direction(orbitDirectionSign);
1042  _sensor->set_lin_direction(-orbitDirectionSign);
1043  } else if (imageDataStartWith=="LATEAZFARRG") {
1044  _sensor->set_col_direction(-orbitDirectionSign);
1045  _sensor->set_lin_direction(-orbitDirectionSign);
1046  } else {
1047  // COSAR Files are stored starting with early azimuth, near range
1048  _sensor->set_col_direction(orbitDirectionSign);
1049  _sensor->set_lin_direction(orbitDirectionSign);
1050  }
1051  }
1052  else
1053  {
1054  _sensor->set_col_direction(1);
1055  _sensor->set_lin_direction(1);
1056  }
1057 
1058  const char* lookDirection_str = kwl.find(prefix,"lookDirection");
1059  std::string lookDirection(lookDirection_str) ;
1060  if ((lookDirection == "Right")||(lookDirection == "RIGHT")) _sensor->set_sightDirection(SensorParams::Right) ;
1061  else _sensor->set_sightDirection(SensorParams::Left) ;
1062 
1063  _sensor->set_sf(fr);
1064  const double CLUM = 2.99792458e+8 ;
1065  double wave_length = CLUM / central_freq ;
1066  _sensor->set_rwl(wave_length);
1067  _sensor->set_nRangeLook(n_rnglok);
1068  _sensor->set_prf(fa) ;
1069  // fa is the processing PRF
1070  //_sensor->set_prf(fa * n_azilok); // number of looks disabled
1071 
1072  _sensor->set_semiMajorAxis(ellip_maj) ;
1073  _sensor->set_semiMinorAxis(ellip_min) ;
1074 
1075  return true;
1076 }
1077 
1079  const ossimKeywordlist &kwl, const char *prefix)
1080 {
1081  /*
1082  * Retrieval of ephemerisis number
1083  */
1084  const char* neph_str = kwl.find(prefix,"neph");
1085  int neph = atoi(neph_str);
1086 
1087  Ephemeris** ephemeris = new Ephemeris*[neph];
1088 
1089  /*
1090  * Retrieval of ephemerisis
1091  */
1092  for (int i=0;i<neph;i++)
1093  {
1094  double pos[3];
1095  double vit[3];
1096  char name[64];
1097 
1098 
1099  sprintf(name,"eph%i_date",i);
1100  const char* date_str = kwl.find(prefix,name);
1101 
1102  sprintf(name,"eph%i_posX",i);
1103  const char* px_str = kwl.find(prefix,name);
1104  pos[0] = atof(px_str);
1105 
1106  sprintf(name,"eph%i_posY",i);
1107  const char* py_str = kwl.find(prefix,name);
1108  pos[1] = atof(py_str);
1109 
1110  sprintf(name,"eph%i_posZ",i);
1111  const char* pz_str = kwl.find(prefix,name);
1112  pos[2] = atof(pz_str);
1113 
1114 
1115  sprintf(name,"eph%i_velX",i);
1116  const char* vx_str = kwl.find(prefix,name);
1117  vit[0] = atof(vx_str) ;
1118 
1119  sprintf(name,"eph%i_velY",i);
1120  const char* vy_str = kwl.find(prefix,name);
1121  vit[1] = atof(vy_str) ;
1122 
1123  sprintf(name,"eph%i_velZ",i);
1124  const char* vz_str = kwl.find(prefix,name);
1125  vit[2] = atof(vz_str) ;
1126 
1127  /*
1128  * Conversion to JSD Date
1129  */
1130  std::string utcString(date_str);
1131  CivilDateTime eph_civil_date;
1132  if (! ossim::iso8601TimeStringToCivilDate(utcString, eph_civil_date)) return false;
1133 
1134  JSDDateTime eph_jsd_date(eph_civil_date);
1135 
1136  GeographicEphemeris* eph = new GeographicEphemeris(eph_jsd_date,pos,vit);
1137 
1138  ephemeris[i] = eph;
1139  }
1140 
1141  /*
1142  * Creation of the platform position interpolator
1143  */
1144  if (_platformPosition != NULL)
1145  {
1146  delete _platformPosition;
1147  }
1148  _platformPosition = new PlatformPosition(ephemeris,neph);
1149 
1150  /*
1151  * Free of memory used by ephemerisis list : the constructor copies the ephemerisis
1152  */
1153  for (int i=0;i<neph;i++)
1154  {
1155  delete ephemeris[i];
1156  }
1157  delete[] ephemeris;
1158 
1159  return true;
1160 }
1161 
1163 {
1164  const char* sc_lin_str = kwl.find(prefix,"sc_lin");
1165  double sc_lin = atof(sc_lin_str);
1166 
1167  const char* sc_pix_str = kwl.find(prefix,"sc_pix");
1168  double sc_pix = atof(sc_pix_str);
1169 
1170  const char* inp_sctim_str = kwl.find(prefix,"inp_sctim");
1171  std::string inp_sctim_string(inp_sctim_str) ;
1172 
1173  const char* sceneCenterRangeTime_str = kwl.find(prefix,"sc_rng");
1174  _sceneCenterRangeTime = atof(sceneCenterRangeTime_str);
1175 
1176  if(_refPoint == NULL)
1177  {
1178  _refPoint = new RefPoint();
1179  }
1180 
1181  _refPoint->set_pix_col(sc_pix);
1182  _refPoint->set_pix_line(sc_lin);
1183 
1184  CivilDateTime * date = new CivilDateTime() ;
1185  if (! ossim::iso8601TimeStringToCivilDate(inp_sctim_string, *date)) return false ;
1186 
1187  if(_platformPosition != NULL)
1188  {
1189  Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)*date);
1190  if (ephemeris == NULL) return false ;
1191 
1192  _refPoint->set_ephemeris(ephemeris);
1193 
1194  delete ephemeris;
1195  }
1196  else
1197  {
1198  return false;
1199  }
1200 
1201  const double CLUM = 2.99792458e+8 ;
1202  double sceneCenterSlantRange = _sceneCenterRangeTime * CLUM / 2.0 ;
1203 
1204  _refPoint->set_distance(sceneCenterSlantRange);
1205 
1206  // in the case of Georeferenced images, the ground range is stored in place of the slant range
1207  // (used for SlantRange computation relative to reference point, necessary for optimization)
1208  if (_isProductGeoreferenced) {
1209  double estimatedGroundRange = 0.0 ;
1210  for (int i=0; i<static_cast<int>(_SrToGr_coeffs.size()); i++)
1211  {
1212  estimatedGroundRange += _SrToGr_coeffs[i]*pow(_sceneCenterRangeTime-_SrToGr_R0,_SrToGr_exponent[i]);
1213  }
1214  // SrToGr update : estimatedGroundRange = sc_pix * scaling_factor
1215  _SrToGr_scaling_factor = estimatedGroundRange / sc_pix ;
1216  _refPoint->set_distance(estimatedGroundRange);
1217  }
1218 
1219  // in order to use ossimSensorModel::lineSampleToWorld
1220  const char* nbCol_str = kwl.find(prefix,"nbCol");
1221  const char* nbLin_str = kwl.find(prefix,"nbLin");
1222  theImageSize.x = atoi(nbCol_str);
1223  theImageSize.y = atoi(nbLin_str);
1224  theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1);
1225 
1226  if (_isProductGeoreferenced) {
1227  std::string azimuthStartTime(kwl.find("azimuthStartTime"));
1228  std::string azimuthStopTime(kwl.find("azimuthStopTime"));
1229  CivilDateTime * dateStart = new CivilDateTime() ;
1230  if (! ossim::iso8601TimeStringToCivilDate(azimuthStartTime, *dateStart)) return false ;
1231  CivilDateTime * dateStop = new CivilDateTime() ;
1232  if (! ossim::iso8601TimeStringToCivilDate(azimuthStopTime, *dateStop)) return false ;
1233  double acq_msec_first = (double) dateStart->get_second()+dateStart->get_decimal();
1234  double acq_msec_last = (double) dateStop->get_second()+dateStop->get_decimal();
1235 
1236  double actualPRF = theImageSize.y/(acq_msec_last-acq_msec_first) ;
1237  _sensor->set_nAzimuthLook(_sensor->get_prf()/actualPRF);
1238  }
1239  else
1240  _sensor->set_nAzimuthLook(1.0);
1241 
1242  // Ground Control Points extracted from the model : scene center and corners
1243  std::list<ossimGpt> groundGcpCoordinates ;
1244  std::list<ossimDpt> imageGcpCoordinates ;
1245  char name[64];
1246  for (int k=0 ; k<5 ; k++) {
1247  sprintf(name,"cornersCol%i",k);
1248  const char* i_str = kwl.find(name);
1249  int i = atoi(i_str);
1250  sprintf(name,"cornersLin%i",k);
1251  const char* j_str = kwl.find(name);
1252  int j = atoi(j_str);
1253  sprintf(name,"cornersLon%i",k);
1254  const char* lon_str = kwl.find(name);
1255  double lon = atof(lon_str);
1256  sprintf(name,"cornersLat%i",k);
1257  const char* lat_str = kwl.find(name);
1258  double lat = atof(lat_str);
1259  const char* height_str = kwl.find("terrain_h");
1260  double height = atof(height_str) ;
1261 
1262  ossimDpt imageGCP(i,j);
1263  ossimGpt groundGCP(lat ,lon , height);
1264  groundGcpCoordinates.push_back(groundGCP) ;
1265  imageGcpCoordinates.push_back(imageGCP) ;
1266  }
1267 
1268  // Default optimization
1269  optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ;
1270 
1271  return true;
1272 }
1273 
1275 {
1276  const char* rangeProjectionType_str = kwl.find(prefix,"rangeProjectionType");
1277  std::string rangeProjectionType(rangeProjectionType_str);
1278 
1279  _isProductGeoreferenced = (rangeProjectionType=="GROUNDRANGE") ;
1280 
1281  // SRtoGR polynomial reference
1282  const char* SrToGr_R0_str = kwl.find(prefix,"SrToGr_R0");
1283  _SrToGr_R0 = atof(SrToGr_R0_str);
1284 
1285  // number of SRtoGR coefficients
1286  const char* SrToGr_coeffs_number_str = kwl.find(prefix,"SrToGr_coeffs_number");
1287  int srToGr_coeffs_number = atoi(SrToGr_coeffs_number_str);
1288 
1289  // SRtoGR coefficients and exponents
1290  char name[64];
1291  double coeff ;
1292  int exponent ;
1293  for(int i=0;i<srToGr_coeffs_number;i++)
1294  {
1295  sprintf(name,"SrToGr_coeffs_%i",i);
1296  const char* coeff_str = kwl.find(prefix,name);
1297  coeff = atof(coeff_str);
1298  _SrToGr_coeffs.push_back(coeff);
1299  sprintf(name,"SrToGr_exps_%i",i);
1300  const char* exp_str = kwl.find(prefix,name);
1301  exponent = atoi(exp_str);
1302  _SrToGr_exponent.push_back(exponent);
1303  }
1304 
1305  // ALTERNATIVE to provided coefficients
1306 
1307  // Range time for first mid and last pixel
1308  std::string orbitDirection(kwl.find(prefix,"orbitDirection")) ;
1309  double t1, t2, t3 ;
1310  if (orbitDirection=="DESCENDING") {
1311  t3 = atof(kwl.find("start_rng"));
1312  t2 = atof(kwl.find("sc_rng"));
1313  t1 = atof(kwl.find("end_rng"));
1314  }
1315  else {
1316  t1 = atof(kwl.find("start_rng"));
1317  t2 = atof(kwl.find("sc_rng"));
1318  t3 = atof(kwl.find("end_rng"));
1319  }
1320 
1321  // Range pixels numbers corresponding
1322  // double x1 = 0.0;
1323  double x2 = atof(kwl.find("sc_pix"));
1324  double x3 = 2.0*(x2+1.0) -1.0 ;
1325 
1326  _alt_srgr_coefset[0] = t1;
1327  _alt_srgr_coefset[1] = ((t2-t1)/(x2*x2)+(t1-t3)/(x3*x3))/((1.0/x2)-(1.0/x3));
1328  _alt_srgr_coefset[2] = ((t2-t1)/x2 + (t1-t3)/x3)/(x2-x3);
1329 
1330  return true;
1331 }
1332 
1334  const ossimTerraSarProductDoc& tsDoc)
1335 {
1336  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initSRGR";
1337 
1338  if (traceDebug())
1339  {
1340  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
1341  }
1342 
1343  bool result = true;
1344 
1345  ossimString s;
1346 
1347  _isProductGeoreferenced = tsDoc.isProductGeoreferenced(xdoc);
1348 
1349  // SRtoGR polynomial reference
1350  if ( tsDoc.getReferencePoint(xdoc, s) )
1351  {
1352  _SrToGr_R0 = s.toDouble();
1353  }
1354  else
1355  {
1356  //---
1357  // This value is only used if product is geo referenced,
1358  // (projection == GROUNDRANGE) so we won't error out if not.
1359  //---
1360  if (_isProductGeoreferenced)
1361  {
1362  result = false;
1363  }
1364  _SrToGr_R0 = 0.0;
1365  }
1366 
1367  // number of SRtoGR coefficients
1369  ossimString path =
1370  "/level1Product/productSpecific/projectedImageInfo/slantToGroundRangeProjection/coefficient";
1371  std::vector<ossimRefPtr<ossimXmlNode> > xnodes;
1372  const ossimString EXP = "exponent";
1373  xdoc->findNodes(path, xnodes);
1374  if ( xnodes.size() )
1375  {
1376  for (ossim_uint32 i = 0; i < xnodes.size(); ++i)
1377  {
1378  if (xnodes[i].valid())
1379  {
1380  xnodes[i]->getAttributeValue(s, EXP);
1381  _SrToGr_exponent.push_back(s.toInt32());
1382  _SrToGr_coeffs.push_back(xnodes[i]->getText().toDouble());
1383  }
1384  }
1385  }
1386  else
1387  {
1388  result = false;
1389  }
1390 
1391  // Range time for first mid and last pixel
1392 
1393  if ( tsDoc.getOrbitDirection(xdoc, s) )
1394  {
1395  bool desendingFlag = (s == "DESCENDING");
1396  double startRng = 0.0;
1397  double endRng = 0.0;
1398  double scRng = 0.0;
1399  double t1 = 0.0;
1400  double t2 = 0.0;
1401  double t3 = 0.0;
1402  double x2 = 0.0;
1403 
1404  if ( tsDoc.getRangeGateFirstPixel(xdoc, s) )
1405  {
1406  startRng = s.toDouble();
1407  }
1408  else
1409  {
1410  result = false;
1411  }
1412 
1413  if ( tsDoc.getRangeGateLastPixel(xdoc, s) )
1414  {
1415  endRng = s.toDouble();
1416  }
1417  else
1418  {
1419  result = false;
1420  }
1421 
1422  if ( tsDoc.getSceneCenterRangeTime(xdoc, s) )
1423  {
1424  scRng = s.toDouble();
1425  }
1426  else
1427  {
1428  result = false;
1429  }
1430 
1431  t2 = scRng;
1432 
1433  if (desendingFlag)
1434  {
1435  t3 = startRng;
1436  t1 = endRng;
1437  }
1438  else
1439  {
1440  t1 = startRng;
1441  t3 = endRng;
1442  }
1443 
1444  // Range pixels numbers corresponding
1445  if ( tsDoc.getSceneCenterRefColumn(xdoc, s) )
1446  {
1447  //---
1448  // TSX image coordinates start at (1,1),
1449  // while OSSIM image coordinates start at (0,0)
1450  //---
1451  x2 = s.toDouble() - 1.0;
1452  }
1453  else
1454  {
1455  result = false;
1456  }
1457 
1458  if (traceDebug())
1459  {
1461  << "startRng: " << startRng
1462  << "\nscRng: " << scRng
1463  << "\nendRng: " << endRng
1464  << "\nx2: " << x2
1465  << "\n";
1466  }
1467 
1468  double x3 = 2.0*(x2+1.0) -1.0 ;
1469 
1470  _alt_srgr_coefset[0] = t1;
1471  _alt_srgr_coefset[1] =
1472  ((t2-t1)/(x2*x2)+(t1-t3)/(x3*x3))/((1.0/x2)-(1.0/x3));
1473  _alt_srgr_coefset[2] = ((t2-t1)/x2 + (t1-t3)/x3)/(x2-x3);
1474  }
1475  else
1476  {
1477  result = false;
1478  }
1479 
1480  return result;
1481 }
1482 
1484  const ossimTerraSarProductDoc& tsDoc)
1485 {
1486  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initPlatformPosition";
1487 
1488  if (traceDebug())
1489  {
1490  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
1491  }
1492 
1493  // Initialize the platform position interpolator.
1494  if (_platformPosition)
1495  {
1496  delete _platformPosition;
1497  }
1498 
1499  _platformPosition = new PlatformPosition();
1500 
1501  bool result = tsDoc.initPlatformPosition(xdoc, _platformPosition);
1502 
1503  if (traceDebug())
1504  {
1506  << MODULE << " exit status = " << (result?"true":"false\n")
1507  << std::endl;
1508  }
1509 
1510  return result;
1511 }
1512 
1514  const ossimTerraSarProductDoc& tsDoc)
1515 {
1516  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initSensorParams";
1517 
1518  if (traceDebug())
1519  {
1520  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
1521  }
1522 
1523  if (_sensor )
1524  {
1525  delete _sensor;
1526  }
1527  _sensor = new SensorParams();
1528 
1529 
1530  bool result = tsDoc.initSensorParams(xdoc, _sensor);
1531 
1532  if (traceDebug())
1533  {
1535  << "result for tsDoc.initSensorParams " << result << endl;
1536  }
1537 
1538  if (!result)
1539  {
1540  delete _sensor;
1541  _sensor = 0;
1542  }
1543 
1544  if (traceDebug())
1545  {
1547  << MODULE << " exit status = " << (result?"true":"false\n")
1548  << std::endl;
1549  }
1550 
1551  return result;
1552 }
1553 
1555  const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc)
1556 {
1557  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initRefPoint";
1558 
1559  if (traceDebug())
1560  {
1561  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
1562  }
1563 
1564  if ( !_platformPosition )
1565  {
1566  return false;
1567  }
1568 
1569  bool result = true;
1570 
1571  ossimString s; // used throughout
1572 
1573  //---
1574  // Set the base class reference points.
1575  // Note the "ONE BASED" image points from xml doc.
1576  //---
1577 
1578  // Get the center sample.
1579  if ( tsDoc.getSceneCenterRefColumn(xdoc, s) )
1580  {
1581  theRefImgPt.x = s.toFloat64() - 1.0;
1582  }
1583  else
1584  {
1585  result = false;
1586  }
1587 
1588  // Get the center line.
1589  if ( tsDoc.getSceneCenterRefRow(xdoc, s) )
1590  {
1591  theRefImgPt.y = s.toFloat64() - 1.0;
1592  }
1593  else
1594  {
1595  result = false;
1596  }
1597 
1598  // Get the center latitude.
1599  if ( tsDoc.getSceneCenterLat(xdoc, s) )
1600  {
1601  theRefGndPt.lat = s.toFloat64();
1602  }
1603  else
1604  {
1605  result = false;
1606  }
1607 
1608  // Get the center longitude.
1609  if ( tsDoc.getSceneCenterLon(xdoc, s) )
1610  {
1611  theRefGndPt.lon = s.toFloat64();
1612  }
1613  else
1614  {
1615  result = false;
1616  }
1617 
1618  // Reference point.
1619  if (_refPoint)
1620  {
1621  delete _refPoint;
1622  }
1623  _refPoint = new RefPoint();
1624 
1625  _refPoint->set_pix_col(theRefImgPt.x);
1626  _refPoint->set_pix_line(theRefImgPt.y);
1627 
1628  if ( tsDoc.getSceneCenterAzimuthTime(xdoc, s) )
1629  {
1630  CivilDateTime date;
1631  if ( ossim::iso8601TimeStringToCivilDate(s, date) )
1632  {
1633  JSDDateTime jdate(date);
1634  Ephemeris * ephemeris = _platformPosition->Interpolate(jdate);
1635  if (ephemeris)
1636  {
1637  _refPoint->set_ephemeris(ephemeris);
1638  delete ephemeris;
1639  }
1640  else
1641  {
1642  result = false;
1643  }
1644  }
1645  else
1646  {
1647  result = false;
1648  }
1649  }
1650  else
1651  {
1652  result = false;
1653  }
1654 
1655  if ( tsDoc.getSceneCenterRangeTime(xdoc, s) )
1656  {
1657  _sceneCenterRangeTime = s.toDouble();
1658 
1659  const double CLUM = 2.99792458e+8;
1660  double sceneCenterSlantRange = _sceneCenterRangeTime * CLUM / 2.0;
1661  _refPoint->set_distance(sceneCenterSlantRange);
1662  }
1663  else
1664  {
1665  result = false;
1666  }
1667 
1668  //---
1669  // In the case of Georeferenced images, the ground range is stored in
1670  // place of the slant range
1671  // (used for SlantRange computation relative to reference point, necessary
1672  // for optimization)
1673  //---
1674  if (_isProductGeoreferenced)
1675  {
1676  double estimatedGroundRange = 0.0 ;
1677  for (int i=0; i<static_cast<int>(_SrToGr_coeffs.size()); i++)
1678  {
1679  estimatedGroundRange += _SrToGr_coeffs[i]*
1680  pow(_sceneCenterRangeTime - _SrToGr_R0, _SrToGr_exponent[i]);
1681  }
1682 
1683  // SrToGr update : estimatedGroundRange = sc_pix * scaling_factor
1684  _SrToGr_scaling_factor = estimatedGroundRange / theRefImgPt.x;
1685  _refPoint->set_distance(estimatedGroundRange);
1686 
1687  CivilDateTime dateStart;
1688  CivilDateTime dateStop;
1689 
1690  if (tsDoc.getAzimuthStartTime(xdoc, s) )
1691  {
1692  if (! ossim::iso8601TimeStringToCivilDate(s, dateStart) )
1693  {
1694  result = false;
1695  }
1696  }
1697  else
1698  {
1699  result = false;
1700  }
1701 
1702  if (tsDoc.getAzimuthStopTime(xdoc, s) )
1703  {
1704  if (! ossim::iso8601TimeStringToCivilDate(s, dateStop) )
1705  {
1706  result = false;
1707  }
1708  }
1709  else
1710  {
1711  result = false;
1712  }
1713 
1714  double acq_msec_first = (double) dateStart.get_second() +
1715  dateStart.get_decimal();
1716  double acq_msec_last = (double) dateStop.get_second() +
1717  dateStop.get_decimal();
1718 
1719  double actualPRF = theImageSize.y/(acq_msec_last - acq_msec_first) ;
1720  _sensor->set_nAzimuthLook(_sensor->get_prf()/actualPRF);
1721 
1722  }
1723  else
1724  {
1725  _sensor->set_nAzimuthLook(1.0);
1726  }
1727 
1728  // Ground Control Points extracted from the model.
1729  std::list<ossimGpt> groundGcpCoordinates;
1730  std::list<ossimDpt> imageGcpCoordinates;
1731  if ( tsDoc.initTiePoints(xdoc,
1732  groundGcpCoordinates,
1733  imageGcpCoordinates) == false )
1734  {
1735  if (traceDebug())
1736  {
1738  << MODULE << "initTiePoint error! exiting\n";
1739  }
1740  return false;
1741  }
1742 
1743  if (result)
1744  {
1745  // Default optimization
1746  optimizeModel(groundGcpCoordinates, imageGcpCoordinates);
1747  }
1748 
1749  if (traceDebug())
1750  {
1752  << MODULE << " exit status = true\n";
1753  }
1754 
1755  return true;
1756 }
1757 
1759  const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc)
1760 {
1761  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initAcquisitionInfo";
1762  bool result;
1763  ossimString s;
1764 
1765  if (traceDebug())
1766  {
1767  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entering...\n";
1768  }
1769 
1770  result = tsDoc.geNumberOfLayers(xdoc, s);
1771  if ( result == false )
1772  {
1773  if (traceDebug())
1774  {
1776  << "unable to get Number Of Layers \n";
1777  }
1778  setErrorStatus();
1779  return false;
1780  }
1781  _numberOfLayers = ossimString(s).toUInt32();
1782 
1783  result = tsDoc.getMission(xdoc, theSensorID);
1784  if ( result == false )
1785  {
1786  if (traceDebug())
1787  {
1789  << "unable to get theSensorID \n";
1790  }
1791  setErrorStatus();
1792  return false;
1793  }
1794 
1795  result = tsDoc.getImagingMode(xdoc, _imagingMode);
1796  if ( result == false )
1797  {
1798  if (traceDebug())
1799  {
1801  << "unable to get Imaging Mode \n";
1802  }
1803  setErrorStatus();
1804  return false;
1805  }
1806 
1807  result = tsDoc.getAcquisitionSensor(xdoc, _acquisitionSensor);
1808  if ( result == false )
1809  {
1810  if (traceDebug())
1811  {
1813  << "unable to get Acquisition Sensor \n";
1814  }
1815  setErrorStatus();
1816  return false;
1817  }
1818  result = tsDoc.getLookDirection(xdoc, _lookDirection);
1819  if ( result == false )
1820  {
1821  if (traceDebug())
1822  {
1824  << "unable to get Look direction \n";
1825  }
1826  setErrorStatus();
1827  return false;
1828  }
1829  result = tsDoc.getPolarisationMode(xdoc, _polarisationMode);
1830  if ( result == false )
1831  {
1832  if (traceDebug())
1833  {
1835  << "unable to get Polarisation Mode \n";
1836  }
1837  setErrorStatus();
1838  return false;
1839  }
1840  result = tsDoc.getPolLayerList(xdoc, _polLayerList);
1841  if ( result == false )
1842  {
1843  if (traceDebug())
1844  {
1846  << "unable to get Polarisation Layer list \n";
1847  }
1848  setErrorStatus();
1849  return false;
1850  }
1851 
1852  if (traceDebug())
1853  {
1854  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " leaving...\n";
1855  }
1856 
1857  return result;
1858 }
1859 
1861  const ossimXmlDocument* xdoc, const ossimTerraSarProductDoc& tsDoc)
1862 {
1863  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initSceneCoord";
1864 
1865  if (traceDebug())
1866  {
1867  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
1868  }
1869 
1870  if (_sceneCoord)
1871  {
1872  delete _sceneCoord;
1873  }
1874 
1875  _sceneCoord = new SceneCoord();
1876 
1877  bool result = tsDoc.initSceneCoord(xdoc, _sceneCoord);
1878 
1879  if (traceDebug())
1880  {
1882  << MODULE << " exit status = " << (result?"true":"false\n")
1883  << std::endl;
1884  }
1885 
1886  return result;
1887 }
1888 
1890  const ossimRefPtr<ossimXmlNode> xmlDocument, ossimplugins::Noise& noise)
1891 {
1892  ossimString xpath;
1893  std::vector<ossimRefPtr<ossimXmlNode> > xml_nodes;
1894  std::vector<ossimRefPtr<ossimXmlNode> > sub_nodes;
1895  std::vector<ossimRefPtr<ossimXmlNode> >::iterator node;
1896 
1897  std::vector<ImageNoise> tabImageNoise;
1898  ImageNoise ev;
1899  tabImageNoise.clear();
1900 
1901  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::getNoise";
1902 
1903  if (traceDebug())
1904  {
1905  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n";
1906  }
1907 
1908  if ( !xmlDocument )
1909  {
1910  setErrorStatus();
1911  if(traceDebug())
1912  {
1914  << MODULE << " DEBUG: one of the getNoise parameter of the method is NULL" << std::endl;
1915  }
1916  return false;
1917  }
1918 
1919  xml_nodes.clear();
1920  xpath = "numberOfNoiseRecords";
1921  xmlDocument->findChildNodes(xpath, xml_nodes);
1922  if(xml_nodes.size() == 0)
1923  {
1924  setErrorStatus();
1925  if(traceDebug())
1926  {
1928  << MODULE << " DEBUG:"
1929  << "\nCould not find: " << xpath
1930  << std::endl;
1931  }
1932  return false;
1933  }
1934 
1935  noise.set_numberOfNoiseRecords( xml_nodes[0]->getText().toInt32() );
1936 
1937 
1938  xml_nodes.clear();
1939  xpath = "imageNoise";
1940  xmlDocument->findChildNodes(xpath, xml_nodes);
1941  if(xml_nodes.size() == 0)
1942  {
1943  setErrorStatus();
1944  if(traceDebug())
1945  {
1947  << MODULE << " DEBUG:"
1948  << "\nCould not find: " << xpath
1949  << std::endl;
1950  }
1951  return false;
1952  }
1953 
1954  node = xml_nodes.begin();
1955  while (node != xml_nodes.end())
1956  {
1957  sub_nodes.clear();
1958  xpath = "timeUTC";
1959  (*node)->findChildNodes(xpath, sub_nodes);
1960  if (sub_nodes.size() == 0)
1961  {
1962  setErrorStatus();
1963  if(traceDebug())
1964  {
1966  << MODULE << " DEBUG:"
1967  << "\nCould not find: " << xpath
1968  << std::endl;
1969  }
1970  return false;
1971  }
1972  ev.set_timeUTC(sub_nodes[0]->getText());
1973 
1974  sub_nodes.clear();
1975  xpath = "noiseEstimate/validityRangeMin";
1976  (*node)->findChildNodes(xpath, sub_nodes);
1977  if (sub_nodes.size() == 0)
1978  {
1979  setErrorStatus();
1980  if(traceDebug())
1981  {
1983  << MODULE << " DEBUG:"
1984  << "\nCould not find: " << xpath
1985  << std::endl;
1986  }
1987  return false;
1988  }
1989  ev.set_validityRangeMin( sub_nodes[0]->getText().toDouble() );
1990 
1991  sub_nodes.clear();
1992  xpath = "noiseEstimate/validityRangeMax";
1993  (*node)->findChildNodes(xpath, sub_nodes);
1994  if (sub_nodes.size() == 0)
1995  {
1996  setErrorStatus();
1997  if(traceDebug())
1998  {
2000  << MODULE << " DEBUG:"
2001  << "\nCould not find: " << xpath
2002  << std::endl;
2003  }
2004  return false;
2005  }
2006  ev.set_validityRangeMax( sub_nodes[0]->getText().toDouble() );
2007 
2008  sub_nodes.clear();
2009  xpath = "noiseEstimate/referencePoint";
2010  (*node)->findChildNodes(xpath, sub_nodes);
2011  if (sub_nodes.size() == 0)
2012  {
2013  setErrorStatus();
2014  if(traceDebug())
2015  {
2017  << MODULE << " DEBUG:"
2018  << "\nCould not find: " << xpath
2019  << std::endl;
2020  }
2021  return false;
2022  }
2023  ev.set_referencePoint( sub_nodes[0]->getText().toDouble() );
2024 
2025  sub_nodes.clear();
2026  xpath = "noiseEstimate/polynomialDegree";
2027  (*node)->findChildNodes(xpath, sub_nodes);
2028  if (sub_nodes.size() == 0)
2029  {
2030  setErrorStatus();
2031  if(traceDebug())
2032  {
2034  << MODULE << " DEBUG:"
2035  << "\nCould not find: " << xpath
2036  << std::endl;
2037  }
2038  return false;
2039  }
2040  ev.set_polynomialDegree( sub_nodes[0]->getText().toInt32() );
2041 
2042  sub_nodes.clear();
2043  ossimXmlNode::ChildListType nodelist;
2044  (*node)->findChildNodes("noiseEstimate/coefficient",nodelist);
2045  ossimXmlNode::ChildListType::const_iterator child_iter = nodelist.begin();
2046  std::vector<double> polynomialCoefficients;
2047  while(child_iter != nodelist.end())
2048  {
2049  double coefficient = ((*child_iter)->getText()).toDouble() ;
2050  polynomialCoefficients.push_back(coefficient);
2051  ++child_iter;
2052  }
2053  ev.set_polynomialCoefficients( polynomialCoefficients );
2054 
2055  tabImageNoise.push_back(ev);
2056 
2057  ++node;
2058  }
2059 
2060  noise.set_imageNoise(tabImageNoise);
2061 
2062  if (traceDebug())
2063  {
2064  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " leaving...\n";
2065  }
2066 
2067  return true;
2068 }
2069 
2070 
2072  const ossimXmlDocument* xmlDocument, const ossimTerraSarProductDoc& /* tsDoc */ )
2073 {
2074  ossimString xpath;
2075  ossimString polLayerName;
2076  std::vector<ossimRefPtr<ossimXmlNode> > xml_nodes;
2077  std::vector<ossimRefPtr<ossimXmlNode> > sub_nodes;
2078  std::vector<ossimRefPtr<ossimXmlNode> >::iterator node;
2079  bool result;
2080 
2081  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initNoise";
2082 
2083  if (traceDebug())
2084  {
2085  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entering...\n";
2086  }
2087 
2088  _noise.resize(_numberOfLayers);
2089 
2090  xml_nodes.clear();
2091  xpath = "/level1Product/noise";
2092 
2093  xmlDocument->findNodes(xpath, xml_nodes);
2094  if(xml_nodes.size() == 0)
2095  {
2096  setErrorStatus();
2097  if(traceDebug())
2098  {
2100  << MODULE << " DEBUG:"
2101  << "\nCould not find: " << xpath
2102  << std::endl;
2103  }
2104  return false;
2105  }
2106 
2107  node = xml_nodes.begin();
2108  while (node != xml_nodes.end())
2109  {
2110  sub_nodes.clear();
2111  xpath = "polLayer";
2112  (*node)->findChildNodes(xpath, sub_nodes);
2113  if (sub_nodes.size() == 0)
2114  {
2115  setErrorStatus();
2116  if(traceDebug())
2117  {
2119  << MODULE << " DEBUG:"
2120  << "\nCould not find: " << xpath
2121  << std::endl;
2122  }
2123  return false;
2124  }
2125 
2126  polLayerName = sub_nodes[0]->getText();
2127 
2128  ossim_uint32 polLayerIdx = 0;
2129  bool polLayerIdxFound = false;
2130 
2131  for(ossim_uint32 idx = 0 ; idx < _polLayerList.size(); ++idx)
2132  {
2133  if(_polLayerList[idx] == polLayerName)
2134  {
2135  polLayerIdx = idx;
2136  polLayerIdxFound = true;
2137  }
2138  }
2139 
2140  if (!polLayerIdxFound)
2141  {
2142  setErrorStatus();
2143  if (traceDebug())
2144  {
2145  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: Unable to find polLayer in polLayer List"
2146  << std::endl;
2147  }
2148  return false;
2149  }
2150 
2151  sub_nodes.clear();
2152 
2153  //_noise[polLayerIdx] = new Noise();
2154  _noise[polLayerIdx].set_imagePolarisation(polLayerName);
2155 
2156  result = getNoiseAtGivenNode( (*node),_noise[polLayerIdx]);
2157  if(!result)
2158  {
2159  setErrorStatus();
2160  if (traceDebug())
2161  {
2162  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG: Unable to getNoise for the " << polLayerName
2163  << " layer image" << std::endl;
2164  }
2165  return false;
2166  }
2167 
2168  ++node;
2169  }
2170 
2171  if (traceDebug())
2172  {
2173  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " leaving...\n";
2174  }
2175 
2176  return true;
2177 }
2178 
2179 
2181  const ossimXmlDocument* xmlDocument, const ossimFilename& imageFilename)
2182 {
2183  ossimString xpath;
2184  ossimString polLayerName;
2185  ossimString polLayerFileName;
2186  std::vector<ossimRefPtr<ossimXmlNode> > xml_nodes;
2187  std::vector<ossimRefPtr<ossimXmlNode> > sub_nodes;
2188  std::vector<ossimRefPtr<ossimXmlNode> >::iterator node;
2189 
2190  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::getPolLayerFromImageFile";
2191 
2192  if (traceDebug())
2193  {
2194  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entering...\n";
2195  }
2196 
2197  xml_nodes.clear();
2198  xpath = "/level1Product/productComponents/imageData";
2199 
2200  xmlDocument->findNodes(xpath, xml_nodes);
2201  if(xml_nodes.size() == 0)
2202  {
2203  setErrorStatus();
2204  if(traceDebug())
2205  {
2207  << MODULE << " DEBUG:"
2208  << "\nCould not find: " << xpath
2209  << std::endl;
2210  }
2211  return false;
2212  }
2213 
2214  node = xml_nodes.begin();
2215  while (node != xml_nodes.end())
2216  {
2217  sub_nodes.clear();
2218  xpath = "polLayer";
2219  (*node)->findChildNodes(xpath, sub_nodes);
2220  if (sub_nodes.size() == 0)
2221  {
2222  setErrorStatus();
2223  if(traceDebug())
2224  {
2226  << MODULE << " DEBUG:"
2227  << "\nCould not find: " << xpath
2228  << std::endl;
2229  }
2230  return false;
2231  }
2232  polLayerName = sub_nodes[0]->getText();
2233 
2234  sub_nodes.clear();
2235  xpath = "file/location/filename";
2236  (*node)->findChildNodes(xpath, sub_nodes);
2237  if (sub_nodes.size() == 0)
2238  {
2239  setErrorStatus();
2240  if(traceDebug())
2241  {
2243  << MODULE << " DEBUG:"
2244  << "\nCould not find: " << xpath
2245  << std::endl;
2246  }
2247  return false;
2248  }
2249  polLayerFileName = sub_nodes[0]->getText();
2250 
2251  if (polLayerFileName == imageFilename.file())
2252  {
2253  _polLayer = polLayerName;
2254  }
2255  ++node;
2256  }
2257 
2258  if (traceDebug())
2259  {
2260  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " leaving...\n";
2261  }
2262  return true;
2263 }
2264 
2265 
2267  const ossimXmlDocument* xmlDocument, const ossimTerraSarProductDoc& /* tsDoc */ )
2268 {
2269  ossimString xpath;
2270  ossimString polLayerName;
2271  std::vector<ossimRefPtr<ossimXmlNode> > xml_nodes;
2272  std::vector<ossimRefPtr<ossimXmlNode> > sub_nodes;
2273  std::vector<ossimRefPtr<ossimXmlNode> >::iterator node;
2274 
2275  static const char MODULE[] = "ossimplugins::ossimTerraSarModel::initCalibration";
2276 
2277  if (traceDebug())
2278  {
2279  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entering...\n";
2280  }
2281 
2282  _calFactor.resize(_numberOfLayers);
2283 
2284  xml_nodes.clear();
2285  xpath = "/level1Product/calibration/calibrationConstant";
2286 
2287  xmlDocument->findNodes(xpath, xml_nodes);
2288  if(xml_nodes.size() == 0)
2289  {
2290  setErrorStatus();
2291  if(traceDebug())
2292  {
2294  << MODULE << " DEBUG:"
2295  << "\nCould not find: " << xpath
2296  << std::endl;
2297  }
2298  return false;
2299  }
2300 
2301  node = xml_nodes.begin();
2302  while (node != xml_nodes.end())
2303  {
2304  sub_nodes.clear();
2305  xpath = "polLayer";
2306  (*node)->findChildNodes(xpath, sub_nodes);
2307  if (sub_nodes.size() == 0)
2308  {
2309  setErrorStatus();
2310  if(traceDebug())
2311  {
2313  << MODULE << " DEBUG:"
2314  << "\nCould not find: " << xpath
2315  << std::endl;
2316  }
2317  return false;
2318  }
2319 
2320  polLayerName = sub_nodes[0]->getText();
2321 
2322  ossim_uint32 polLayerIdx = 0;
2323  bool polLayerIdxFound = false;
2324 
2325  for(ossim_uint32 idx = 0 ; idx < _polLayerList.size(); ++idx)
2326  {
2327  if(_polLayerList[idx] == polLayerName)
2328  {
2329  polLayerIdx = idx;
2330  polLayerIdxFound = true;
2331  }
2332  }
2333 
2334  if(!polLayerIdxFound)
2335  {
2336  setErrorStatus();
2337  if(traceDebug())
2338  {
2340  << MODULE << " DEBUG: Unable to found polLayer in polLayer List" << std::endl;
2341  }
2342  return false;
2343  }
2344 
2345  sub_nodes.clear();
2346  xpath = "calFactor";
2347  (*node)->findChildNodes(xpath, sub_nodes);
2348  if (sub_nodes.size() == 0)
2349  {
2350  setErrorStatus();
2351  if(traceDebug())
2352  {
2354  << MODULE << " DEBUG:"
2355  << "\nCould not find: " << xpath
2356  << std::endl;
2357  }
2358  return false;
2359  }
2360  _calFactor[polLayerIdx] = sub_nodes[0]->getText().toDouble();
2361  ++node;
2362  }
2363 
2364  if (traceDebug())
2365  {
2366  ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " leaving...\n";
2367  }
2368 
2369  return true;
2370 }
2371 
2372 
2374  ossimFilename& metadataFile)
2375 {
2376  bool res = false;
2377 
2378  if ( file.exists() && (file.ext().downcase() == "xml") )
2379  {
2380  metadataFile = file;
2381  res = true;
2382  }
2383  else if (!file.exists())
2384  {
2385  res = false;
2386  }
2387  else
2388  {
2389  if (traceDebug())
2390  {
2392  << "ossimplugins::ossimTerraSarModel::findTSXLeader "
2393  << " directory scan turned off. This is killing the factory open."
2394  << " We should never scan a directory. Need to resolve. "
2395  << std::endl;
2396  }
2397 
2398 #if 0
2399  ossimFilename imagePath = file.path();
2400  if (imagePath.empty())
2402 
2403  ossimDirectory directory = ossimDirectory(imagePath.path());
2404  std::vector<ossimFilename> vectName;
2405  ossimString reg = ".xml";
2406  directory.findAllFilesThatMatch( vectName, reg, 1 );
2407 
2408  bool goodFileFound = false;
2409  unsigned int loop = 0;
2410  while(loop<vectName.size() && !goodFileFound)
2411  {
2412  ossimFilename curFile = vectName[loop];
2413  if(curFile.file().beforePos(3) == ossimString("TSX"))
2414  goodFileFound = true;
2415  else
2416  loop++;
2417  }
2418  if(goodFileFound)
2419  {
2420  metadataFile = vectName[loop];
2421  res = true;
2422  }
2423  else
2424  {
2425  if (traceDebug())
2426  {
2427  if (res)
2428  {
2430  }
2431 
2433  << "ossimplugins::ossimTerraSarModel::findTSXLeader "
2434  << " exit status = " << (res?"true":"false\n")
2435  << std::endl;
2436  }
2437  }
2438 #endif
2439  }
2440 
2441  return res;
2442 }
2443 
2444 
2446 {
2447  os << "\n----------------- General Info on TSX-1 Image -------------------"
2448  << "\n "
2449  << "\n Sensor ID : " << theSensorID
2450  << "\n Imaging Mode : " << _imagingMode
2451  << "\n Acquisition Sensor : " << _acquisitionSensor
2452  << "\n Look direction : " << _lookDirection
2453  << "\n Polarisation Mode : " << _polarisationMode
2454  << "\n Number of Layers : " << _numberOfLayers
2455  << "\n Polarisation List Size : " << _polLayerList.size()
2456  << "\n"
2457  << "\n------------------------------------------------------------------";
2458  for(ossim_uint32 idx = 0 ; idx < _polLayerList.size(); ++idx)
2459  {
2460  os << "\n----------------- Info on " << _polLayerList[idx] <<" Layer Image -------------------"
2461  << "\n calFactor : " << _calFactor[idx]
2462 // << "\n Image Noise size : " << _noise[idx].get_imageNoise().size()
2463  << "\n------------------------------------------------------------";
2464  }
2465  os << std::endl;
2466 }
2467 
bool initSensorParams(const ossimXmlDocument *xdoc, SensorParams *sp) const
Method to initialize SensorParams object from TerraSAR product xml file.
This class represent an ephemeris in Geographic coordinates system.
bool getSceneCenterLon(const ossimXmlDocument *xdoc, ossimString &s) const
longitude
void clear()
Erases the entire container.
Definition: ossimString.h:432
Class to encapsulate parsing TerraSAR product xml file.
bool getSceneId(const ossimXmlDocument *xdoc, ossimString &s) const
virtual ~ossimTerraSarModel()
Destructor.
bool getReferencePoint(const ossimXmlDocument *xdoc, ossimString &s) const
bool findTSXLeader(const ossimFilename &file, ossimFilename &metadataFile)
Method to find the metadata file TerraSAR file (image or xml).
This class represents a date and time in the civil format.
Definition: CivilDateTime.h:30
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
bool getProjection(const ossimXmlDocument *xdoc, ossimString &s) const
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
virtual std::ostream & print(std::ostream &out) const
bool isTerraSarX(const ossimXmlDocument *xdoc) const
Checks for node /level1Product/generalHeader/mission containing "TSX-1".
This class represents Scence coordinate.
Definition: SceneCoord.h:29
void findChildNodes(const ossimString &rel_xpath, ossimXmlNode::ChildListType &nodelist) const
bool getAzimuthStartTime(const ossimXmlDocument *xdoc, ossimString &s) const
This class handles the platform position.
RTTI_DEF1(ossimAlosPalsarModel, "ossimAlosPalsarModel", ossimGeometricSarSensorModel)
Represents serializable keyword/value map.
bool isProductGeoreferenced(const ossimXmlDocument *xdoc) const
bool getPolLayerList(const ossimXmlDocument *xdoc, std::vector< ossimString > &s) const
bool getNoiseAtGivenNode(const ossimRefPtr< ossimXmlNode > xmlDocument, ossimplugins::Noise &noise)
Method to get ImageNoise parameters from TerraSAR product xml file at a given node.
bool getSceneCenterRefColumn(const ossimXmlDocument *xdoc, ossimString &s) const
one based
const char * find(const char *key) const
ossimFilename expand() const
Method to do file name expansion.
virtual ossimObject * dup() const
Returns pointer to a new instance, copy of this.
bool getRangeGateFirstPixel(const ossimXmlDocument *xdoc, ossimString &s) const
one based???
bool getImagingMode(const ossimXmlDocument *xdoc, ossimString &s) const
This class handles the referential point.
Definition: RefPoint.h:29
bool getSceneCenterRangeTime(const ossimXmlDocument *xdoc, ossimString &s) const
static ossimString toString(bool aValue)
Numeric to string methods.
void set_validityRangeMin(double value)
Definition: ImageNoise.h:78
ossimTerraSarModel()
default constructor
bool getRangeFirstPixelTime(const ossimXmlDocument *xdoc, ossimString &s) const
void set_validityRangeMax(double value)
Definition: ImageNoise.h:88
This class allows for direct localisation and indirect localisation using the TerraSar sensor model...
bool getRangeGateLastPixel(const ossimXmlDocument *xdoc, ossimString &s) const
one based???
void set_imageNoise(const std::vector< ImageNoise > &image_noise)
Definition: Noise.h:75
ossim_uint32 toUInt32() const
std::ostream & print(H5::H5File *file, std::ostream &out)
Print method.
Definition: ossimH5Util.cpp:41
bool iso8601TimeStringToCivilDate(const std::string &dataString, CivilDateTime &outputDate)
Converts date string from ISO 8601 format to CivilDateTime.
void findAllFilesThatMatch(std::vector< ossimFilename > &result, const ossimString &regularExpressionPattern, int flags=OSSIM_DIR_DEFAULT)
virtual double getSlantRangeFromGeoreferenced(double col) const
This function associates an image column number to a slant range when the image is georeferenced (gro...
This class handles the sensor parameters.
Definition: SensorParams.h:29
static const char * TYPE_KW
bool getPolarisationMode(const ossimXmlDocument *xdoc, ossimString &s) const
bool getRadiometricCorrection(const ossimXmlDocument *xdoc, ossimString &s) const
bool getLookDirection(const ossimXmlDocument *xdoc, ossimString &s) const
This class allows for direct localisation and indirect localisation using the geometric model of SAR ...
std::vector< ossimRefPtr< ossimXmlNode > > ChildListType
Definition: ossimXmlNode.h:30
ossim_int32 toInt32() const
bool getMission(const ossimXmlDocument *xdoc, ossimString &s) const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimFilename getCurrentWorkingDir() const
bool initPlatformPosition(const ossimXmlDocument *xdoc, PlatformPosition *pos) const
Method to initialize PlatformPosition object from TerraSAR product xml file.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
void add(const ossimFilename &f)
Add support data filename to the list:
This class represents an ephemeris.
Definition: Ephemeris.h:28
bool geNumberOfLayers(const ossimXmlDocument *xdoc, ossimString &s) const
virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix)
Initializes the Slant Range to Ground Range data sets : _SrToGr_R0,_SrToGr_coeffs_number,_SrToGr_exponent,_SrToGr_coeffs,_nbCol.
bool initRefPoint(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &rsDoc)
Method to initialize RefPoint object from TerraSAR product xml file.
bool openFile(const ossimFilename &filename)
This class represents an ImageNoise.
Definition: ImageNoise.h:30
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
bool exists() const
std::string::size_type size() const
Definition: ossimString.h:405
bool toBool() const
String to numeric methods.
std::string::iterator begin()
Definition: ossimString.h:420
unsigned int ossim_uint32
void set_polynomialDegree(unsigned int value)
Definition: ImageNoise.h:108
double toDouble() const
ossim_float64 toFloat64() const
bool initTiePoints(const ossimXmlDocument *xdoc, std::list< ossimGpt > &gcp, std::list< ossimDpt > &icp) const
Method to initialize image tie points from TerraSAR product xml file.
bool initSceneCoord(const ossimXmlDocument *xdoc, SceneCoord *pos) const
Method to initialize IncidenceAngles object from TerraSAR product xml file.
bool initPlatformPosition(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &rsDoc)
bool initAcquisitionInfo(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &tsDoc)
Method to initialize AcquisitionInfo parameters from TerraSAR product xml file.
bool initCalibration(const ossimXmlDocument *xmlDocument, const ossimTerraSarProductDoc &tsDoc)
Method to initialize Calibration parameters from TerraSAR product xml file.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
This class represents an Noise.
Definition: Noise.h:28
bool getPolLayerFromImageFile(const ossimXmlDocument *xmlDocument, const ossimFilename &imageFilename)
Method to find the polLayer from the image file.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
bool open(const ossimFilename &file)
Method to intantial model from a file.
bool initSRGR(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &rsDoc)
bool initImageSize(const ossimXmlDocument *xdoc, ossimIpt &imageSize) const
Method to initialize image size from TerraSAR product xml file.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
virtual std::ostream & print(std::ostream &out) const
static ossimEnvironmentUtility * instance()
void set_timeUTC(const ossimString &value)
Definition: ImageNoise.h:68
bool initSensorParams(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &rsDoc)
bool getSceneCenterLat(const ossimXmlDocument *xdoc, ossimString &s) const
latitude
virtual ossimString getClassName() const
Method to return the class name.
bool getGenerationTime(const ossimXmlDocument *xdoc, ossimString &s) const
virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix)
Initializes the Sensor Params from a projection keywordlist.
bool getSceneCenterRefRow(const ossimXmlDocument *xdoc, ossimString &s) const
one based
const char * getClassName(int idx)
bool getAzimuthStopTime(const ossimXmlDocument *xdoc, ossimString &s) const
bool getAcquisitionSensor(const ossimXmlDocument *xdoc, ossimString &s) const
ossimString beforePos(std::string::size_type pos) const
bool getOrbitDirection(const ossimXmlDocument *xdoc, ossimString &s) const
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
bool empty() const
Definition: ossimString.h:411
bool initNoise(const ossimXmlDocument *xmlDocument, const ossimTerraSarProductDoc &tsDoc)
Method to initialize ImageNoise parameters from TerraSAR product xml file.
ossimFilename file() const
ossimString ext() const
virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix)
Initializes the Platform Position from a projection keywordlist.
static ossimSupportFilesList * instance()
void findNodes(const ossimString &xpath, std::vector< ossimRefPtr< ossimXmlNode > > &nodelist) const
Appends any matching nodes to the list supplied (should be empty):
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
bool initGsd(const ossimXmlDocument *xdoc, ossimDpt &gsd) const
Method to initialize gsd from TerraSAR product xml file.
This class represents a date.
Definition: JSDDateTime.h:30
void set_referencePoint(double value)
Definition: ImageNoise.h:98
ossimFilename path() const
void set_numberOfNoiseRecords(const ossim_int32 &numberOfNoiseRecords)
Definition: Noise.h:71
bool getProductType(const ossimXmlDocument *xdoc, ossimString &s) const
int toInt() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void set_polynomialCoefficients(const std::vector< double > &value)
Definition: ImageNoise.h:119
bool initSceneCoord(const ossimXmlDocument *xdoc, const ossimTerraSarProductDoc &tsDoc)
Method to initialize InfoIncidenceAngle parameters from TerraSAR product xml file.
bool getRadarFrequency(const ossimXmlDocument *xdoc, ossimString &s) const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
bool getRangeLastPixelTime(const ossimXmlDocument *xdoc, ossimString &s) const
SceneCoord * _sceneCoord
SceneCoord (SceneInfo node)
virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix)
Initializes the Reference Point from a projection keywordlist.
bool getSceneCenterAzimuthTime(const ossimXmlDocument *xdoc, ossimString &s) const