OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
AlosPalsarLeader.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 // "Copyright Centre for Remote Imaging, Sensing and Processing"
5 //
6 // License: LGPL
7 //
8 // See LICENSE.txt file in the top level directory for more details.
9 //
10 //----------------------------------------------------------------------------
11 // $Id$
12 
16 
20 
21 #include <ossim/base/ossimTrace.h>
24 
25 // Static trace for debugging
26 static ossimTrace traceDebug("ossimAlosPalsarLeader:debug");
27 
28 namespace ossimplugins
29 {
30 
34 // const int AlosPalsarLeader::AlosPalsarMapProjectionDataID = 3; //
37 
39 {
40 }
41 
43 {
44  ClearRecords();
45 }
46 
48 {
49  std::map<int, AlosPalsarRecord*>::const_iterator it = data._records.begin();
50  while (it != data._records.end())
51  {
52  (*it).second->Write(os);
53  ++it;
54  }
55  return os;
56 
57 }
58 
60 {
62 
63  data.ClearRecords();
64 
66  bool eof = false;
67  while (!eof)
68  {
69  is >> header;
70  if (is.eof())
71  {
72  eof = true;
73  }
74  else
75  {
76  AlosPalsarRecord* record = factory.Instanciate(header.get_rec_seq());
77  if (record != NULL)
78  {
79  record->Read(is);
80  data._records[header.get_rec_seq()] = record;
81  }
82  else
83  {
84  if (header.get_length() > 12)
85  {
86  char* buff = new char[header.get_length()-12];
87  is.read(buff, header.get_length() - 12);
88  delete [] buff;
89  }
90  }
91  }
92  }
93  return is;
94 }
95 
96 
98 {
99  std::map<int, AlosPalsarRecord*>::const_iterator it = rhs._records.begin();
100  while (it != rhs._records.end())
101  {
102  _records[(*it).first] = (*it).second->Clone();
103  ++it;
104  }
105 }
106 
108 {
109  ClearRecords();
110  std::map<int, AlosPalsarRecord*>::const_iterator it = rhs._records.begin();
111  while (it != rhs._records.end())
112  {
113  _records[(*it).first] = (*it).second->Clone();
114  ++it;
115  }
116 
117  return *this;
118 }
119 
121 {
122  std::map<int, AlosPalsarRecord*>::const_iterator it = _records.begin();
123  while (it != _records.end())
124  {
125  delete(*it).second;
126  ++it;
127  }
128  _records.clear();
129 }
130 
132  const char* prefix) const
133 {
134 
135  static const char MODULE[] = "AlosPalsarLeader::saveState";
136 
137  if (traceDebug())
138  {
139  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
140  }
141 
142  bool result = true;
143 
144  char name[64];
145 
146  //kwl.add(prefix, ossimKeywordNames::TYPE_KW, "ossimAlosPalsarModel", true);
147  /*
148  * Adding metadata necessary to the sensor model in the keywordlist
149  */
150  const AlosPalsarFileDescriptor *leaderfiledesc = get_AlosPalsarFileDescriptor();
151  if (leaderfiledesc != NULL)
152  {
153  kwl.add(prefix, "filename", leaderfiledesc->get_file_name().c_str(), true);
154  }
155  else
156  {
157  result = false;
158  }
159 
160  /*
161  * Adding metadata necessary to the sensor model in the keywordlist
162  */
163  const AlosPalsarDataSetSummary *datasetSummary = get_AlosPalsarDataSetSummary();
164  if ((datasetSummary != NULL) && (result == true))
165  {
166  kwl.add(prefix, "inp_sctim", (datasetSummary->get_inp_sctim()).c_str(), true);
167  kwl.add(prefix, "ellip_maj", datasetSummary->get_ellip_maj(), true);
168  kwl.add(prefix, "ellip_min", datasetSummary->get_ellip_min(), true);
169  kwl.add(prefix, "sc_lin", datasetSummary->get_sc_lin(), true);
170  kwl.add(prefix, "sc_pix", datasetSummary->get_sc_pix(), true);
171  kwl.add(prefix, "wave_length", datasetSummary->get_wave_length(), true);
172  kwl.add(prefix, "fr", datasetSummary->get_fr(), true);
173  kwl.add(prefix, "fa", datasetSummary->get_fa(), true);
174  kwl.add(prefix, "time_dir_pix", (datasetSummary->get_time_dir_pix()).c_str(), true);
175  kwl.add(prefix, "time_dir_lin", (datasetSummary->get_time_dir_lin()).c_str(), true);
176  kwl.add(prefix, "line_spacing", datasetSummary->get_line_spacing(), true);
177  kwl.add(prefix, "pix_spacing", datasetSummary->get_pix_spacing(), true);
178  kwl.add(prefix, "nlooks_az", datasetSummary->get_n_azilok(), true);
179  kwl.add(prefix, "n_rnglok", datasetSummary->get_n_rnglok(), true);
180  kwl.add(prefix, "alt_dopcen[0]", datasetSummary->get_alt_dopcen()[0], true);
181  kwl.add(prefix, "crt_dopcen[0]", datasetSummary->get_crt_dopcen()[0], true);
182  kwl.add(prefix, "crt_dopcen[1]", datasetSummary->get_crt_dopcen()[1], true);
183  kwl.add(prefix, "dopcen_range[0]", datasetSummary->get_dopcen_range()[0], true);
184  kwl.add(prefix, "dopcen_range[1]", datasetSummary->get_dopcen_range()[1], true);
185  //FIXME check if those data are available
186 // kwl.add(prefix, "zero_dop_range_time_f_pixel", datasetSummary->get_zero_dop_range_time_f_pixel(),true);
187 // kwl.add(prefix, "zero_dop_range_time_c_pixel", datasetSummary->get_zero_dop_range_time_c_pixel(),true);
188 // kwl.add(prefix, "zero_dop_range_time_l_pixel", datasetSummary->get_zero_dop_range_time_l_pixel(),true);
189  }
190  else
191  {
192  result = false;
193  }
194 
195  // FIXME do not handle Alos map projection information for now...
196 // const AlosPalsarMapProjectionData *mapprojectiondata = get_AlosPalsarMapProjectionData();
197 // if ( (mapprojectiondata != NULL) && (result == true) )
198 // {
199 // kwl.add(prefix, "map_proj_des",(mapprojectiondata->get_map_proj_des()).c_str(),true);
200 // kwl.add(prefix, "num_lines",(double) mapprojectiondata->get_num_lines(),true);
201 // kwl.add(prefix, "num_pix",(double) mapprojectiondata->get_num_pix_in_line(),true);
202 // kwl.add(prefix, "first_line_first_pixel_lat",mapprojectiondata->get_first_line_first_pixel_lat(), true);
203 // kwl.add(prefix, "first_line_first_pixel_lon",mapprojectiondata->get_first_line_first_pixel_lon(), true);
204 // kwl.add(prefix, "first_line_last_pixel_lat",mapprojectiondata->get_first_line_last_pixel_lat(), true);
205 // kwl.add(prefix, "first_line_last_pixel_lon",mapprojectiondata->get_first_line_last_pixel_lon(), true);
206 // kwl.add(prefix, "last_line_first_pixel_lat",mapprojectiondata->get_last_line_first_pixel_lat(), true);
207 // kwl.add(prefix, "last_line_first_pixel_lon",mapprojectiondata->get_last_line_first_pixel_lon(), true);
208 // kwl.add(prefix, "last_line_last_pixel_lat",mapprojectiondata->get_last_line_last_pixel_lat(), true);
209 // kwl.add(prefix, "last_line_last_pixel_lon",mapprojectiondata->get_last_line_last_pixel_lon(), true);
210 // }
211 // else
212 // {
213 // result = false;
214 // }
215 
217  if ((platformposition != NULL) && (result == true))
218  {
219  kwl.add(prefix, "neph", platformposition->get_ndata(), true);
220  kwl.add(prefix, "eph_year", platformposition->get_year(), true);
221  kwl.add(prefix, "eph_month", platformposition->get_month(), true);
222  kwl.add(prefix, "eph_day", platformposition->get_day(), true);
223  kwl.add(prefix, "eph_gmt_day", platformposition->get_gmt_day(), true);
224  kwl.add(prefix, "eph_sec", platformposition->get_gmt_sec(), true);
225  kwl.add(prefix, "eph_hr_angle", platformposition->get_hr_angle(), true);
226  kwl.add(prefix, "eph_int", platformposition->get_data_int(), true);
227 
228  for (int i = 0; i < platformposition->get_ndata(); i++)
229  {
230  sprintf(name, "eph%i_posX", i);
231  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[0], true);
232  sprintf(name, "eph%i_posY", i);
233  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[1], true);
234  sprintf(name, "eph%i_posZ", i);
235  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[2], true);
236 
237  sprintf(name, "eph%i_velX", i);
238  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[0], true);
239  sprintf(name, "eph%i_velY", i);
240  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[1], true);
241  sprintf(name, "eph%i_velZ", i);
242  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[2], true);
243  }
244  }
245  else
246  {
247  result = false;
248  }
249 
250  const AlosPalsarRadiometricData *radiometricdata = get_AlosPalsarRadiometricData();
251  if ((radiometricdata != NULL) && (result == true))
252  {
253  kwl.add(prefix, "calibration_factor", radiometricdata->get_calibration_factor(), true);
254  }
255  else
256  {
257  result = false;
258  }
259 
260  // FIXME Do not handle Palsar facility-related data for now...
261  // The current code corresponds to the ERS facility-related data
262  // which is completely different from that for PALSAR
263  /*
264  const AlosPalsarFacilityData *facilitydata = get_AlosPalsarFacilityData();
265  if ((facilitydata != NULL) && (result == true))
266  {
267  kwl.add(prefix, "coef_ground_range_1", facilitydata->get_coef_ground_range_1(), true);
268  kwl.add(prefix, "coef_ground_range_2", facilitydata->get_coef_ground_range_2(), true);
269  kwl.add(prefix, "coef_ground_range_3", facilitydata->get_coef_ground_range_3(), true);
270  kwl.add(prefix, "coef_ground_range_4", facilitydata->get_coef_ground_range_4(), true);
271  }
272  else
273  {
274  result = false;
275  }
276  */
277 
278  if (traceDebug())
279  {
281  << MODULE << " exit status = " << (result ? "true" : "false\n")
282  << std::endl;
283  }
284 
285 
286  return result;
287 }
288 
290 {
291 // return const_cast<const AlosPalsarFacilityData*>(dynamic_cast<AlosPalsarFacilityData*>(_records[AlosPalsarFacilityDataID]));
292 // RecordType::const_iterator it = _records.find(AlosPalsarFacilityDataID)->second;
293 // return dynamic_cast<const AlosPalsarFacilityData*>(it.find(AlosPalsarFacilityDataID));
294  return dynamic_cast<const AlosPalsarFacilityData*>(_records.find(AlosPalsarFacilityDataID)->second);
295 }
296 
298 {
299  return dynamic_cast<const AlosPalsarRadiometricData*>(_records.find(AlosPalsarRadiometricDataID)->second);
300 }
301 
303 {
304  return dynamic_cast<const AlosPalsarPlatformPositionData*>(_records.find(AlosPalsarPlatformPositionDataID)->second);
305 }
306 
307 /*
308 const AlosPalsarMapProjectionData * AlosPalsarLeader::get_AlosPalsarMapProjectionData() const
309 {
310 // return (AlosPalsarMapProjectionData*)_records[AlosPalsarMapProjectionDataID];
311  return dynamic_cast<const AlosPalsarMapProjectionData*>(_records.find(AlosPalsarMapProjectionDataID)->second);
312 }
313 */
314 // no map projection data for level 1.1
315 
317 {
318  return dynamic_cast<const AlosPalsarDataSetSummary*>(_records.find(AlosPalsarDataSetSummaryID)->second);
319 }
320 
322 {
323  return dynamic_cast<const AlosPalsarFileDescriptor*>(_records.find(AlosPalsarFileDescriptorID)->second);
324 }
325 
326 }
double get_ellip_maj() const
Ellipsoid semi-major axis, km.
double get_n_rnglok() const
Number of range looks.
double get_pix_spacing() const
Pixel spacing, meters.
AlosPalsarRecord * Instanciate(int id)
Instanciate a new Record.
static const int AlosPalsarRadiometricDataID
double get_hr_angle() const
Greenwich mean hour angle.
static const int AlosPalsarDataSetSummaryID
double get_n_azilok() const
Number of azimuth looks.
std::string get_time_dir_lin() const
Line time direction indicator.
double get_fr() const
Range sampling rate.
double get_ellip_min() const
Ellipsoid semi_minor axis, km.
This class is able to read the Leader file of the AlosPalsar file structure.
This class is able to read a record header.
Represents serializable keyword/value map.
const double * get_alt_dopcen() const
Along track Doppler frequency terms.
std::string get_file_name() const
File name.
int get_sc_lin() const
Scene centre line number.
This class is a facory able to construct Record base classes.
const AlosPalsarDataSetSummary * get_AlosPalsarDataSetSummary() const
const AlosPalsarPositionVectorRecord * get_pos_vect() const
Data point position/velocity.
std::string get_inp_sctim() const
Input scene centre time.
This class is the base class of all the record classes.
virtual ~AlosPalsarLeader()
Destructor.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
const double * get_dopcen_range() const
Along track Doppler frequency terms (in range unit: km)
static const int AlosPalsarFileDescriptorID
double get_data_int() const
Data sampling interval.
std::ostream & operator<<(std::ostream &os, const AlosPalsarData &data)
This class is able to read the SAR leader data set summary record of the leader file.
static const int AlosPalsarPlatformPositionDataID
This class is able to read a Platform position data record.
const AlosPalsarRadiometricData * get_AlosPalsarRadiometricData() const
const AlosPalsarPlatformPositionData * get_AlosPalsarPlatformPositionData() const
static const int AlosPalsarFacilityDataID
std::string get_time_dir_pix() const
Pixel time direction indicator.
const AlosPalsarFacilityData * get_AlosPalsarFacilityData() const
std::istream & operator>>(std::istream &is, AlosPalsarData &data)
This class is able to read the SAR leader data set summary record of the leader file.
double get_wave_length() const
Radar wave length.
double get_calibration_factor() const
Calibration factor.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
void ClearRecords()
Remove all the previous records from the AlosPalsarLeader.
This class is able to read a radiometric data record.
AlosPalsarLeader & operator=(const AlosPalsarLeader &rhs)
Copy operator.
virtual void Read(std::istream &is)=0
Read the class data from a stream.
double get_line_spacing() const
Line spacing, meters.
const AlosPalsarFileDescriptor * get_AlosPalsarFileDescriptor() const
This class is able to read the SAR leader file descriptor record of the leader file.
const double * get_crt_dopcen() const
Cross track Doppler frequency terms.
int get_sc_pix() const
Scene centre pixel number.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23