OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ErsSarLeader.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 <cstdio>
13 
14 #include "erssar/ErsSarLeader.h"
17 
22 
23 #include <ossim/base/ossimTrace.h>
26 
27 // Static trace for debugging
28 static ossimTrace traceDebug("ossimErsSarLeader:debug");
29 
30 namespace ossimplugins
31 {
32 
38 
40 {
41 }
42 
44 {
45  ClearRecords();
46 }
47 
49 {
50  std::map<int, ErsSarRecord*>::const_iterator it = data.theRecords.begin();
51  while (it != data.theRecords.end())
52  {
53  (*it).second->Write(os);
54  ++it;
55  }
56  return os;
57 
58 }
59 
61 {
62  ErsSarLeaderFactory factory;
63 
64  data.ClearRecords();
65 
66  ErsSarRecordHeader header;
67  bool eof = false;
68  while (!eof)
69  {
70  is >> header;
71  if (is.eof())
72  {
73  eof = true;
74  }
75  else
76  {
77  ErsSarRecord* record = factory.Instanciate(header.get_rec_seq());
78  if (record != NULL)
79  {
80  record->Read(is);
81  data.theRecords[header.get_rec_seq()] = record;
82  }
83  else
84  {
85  char* buff = new char[header.get_length()-12];
86  is.read(buff, header.get_length() - 12);
87  delete [] buff;
88  }
89  }
90  }
91  return is;
92 }
93 
94 
96 {
97  std::map<int, ErsSarRecord*>::const_iterator it = rhs.theRecords.begin();
98  while (it != rhs.theRecords.end())
99  {
100  theRecords[(*it).first] = (*it).second->Clone();
101  ++it;
102  }
103 }
104 
106 {
107  ClearRecords();
108  std::map<int, ErsSarRecord*>::const_iterator it = rhs.theRecords.begin();
109  while (it != rhs.theRecords.end())
110  {
111  theRecords[(*it).first] = (*it).second->Clone();
112  ++it;
113  }
114 
115  return *this;
116 }
117 
119 {
120  std::map<int, ErsSarRecord*>::const_iterator it = theRecords.begin();
121  while (it != theRecords.end())
122  {
123  delete(*it).second;
124  ++it;
125  }
126  theRecords.clear();
127 }
128 
130  const char* prefix) const
131 {
132 
133  static const char MODULE[] = "ErsSarLeader::saveState";
134 
135  if (traceDebug())
136  {
137  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
138  }
139 
140  bool result = true;
141 
142  char name[64];
143 
144  kwl.add(prefix, ossimKeywordNames::TYPE_KW, "ossimErsSarModel", true);
145  /*
146  * Adding metadata necessary to the sensor model in the keywordlist
147  */
148  const ErsSarFileDescriptor *leaderfiledesc = get_ErsSarFileDescriptor();
149  if (leaderfiledesc != NULL)
150  {
151  kwl.add(prefix, "filename", leaderfiledesc->get_file_name().c_str(), true);
152  }
153  else
154  {
155  result = false;
156  }
157 
158  /*
159  * Adding metadata necessary to the sensor model in the keywordlist
160  */
161  const ErsSarDataSetSummary *datasetSummary = get_ErsSarDataSetSummary();
162  if ((datasetSummary != NULL) && (result == true))
163  {
164  kwl.add(prefix, "inp_sctim", (datasetSummary->get_inp_sctim()).c_str(), true);
165  kwl.add(prefix, "ellip_maj", datasetSummary->get_ellip_maj(), true);
166  kwl.add(prefix, "ellip_min", datasetSummary->get_ellip_min(), true);
167  kwl.add(prefix, "sc_lin", datasetSummary->get_sc_lin(), true);
168  kwl.add(prefix, "sc_pix", datasetSummary->get_sc_pix(), true);
169  kwl.add(prefix, "wave_length", datasetSummary->get_wave_length(), true);
170  kwl.add(prefix, "fr", datasetSummary->get_fr(), true);
171  kwl.add(prefix, "fa", datasetSummary->get_fa(), true);
172  kwl.add(prefix, "time_dir_pix", (datasetSummary->get_time_dir_pix()).c_str(), true);
173  kwl.add(prefix, "time_dir_lin", (datasetSummary->get_time_dir_lin()).c_str(), true);
174  kwl.add(prefix, "line_spacing", datasetSummary->get_line_spacing(), true);
175  kwl.add(prefix, "pix_spacing", datasetSummary->get_pix_spacing(), true);
176  kwl.add(prefix, "nlooks_az", datasetSummary->get_n_azilok(), true);
177  kwl.add(prefix, "n_rnglok", datasetSummary->get_n_rnglok(), true);
178  kwl.add(prefix, "zero_dop_range_time_f_pixel", datasetSummary->get_zero_dop_range_time_f_pixel(), true);
179  kwl.add(prefix, "zero_dop_range_time_c_pixel", datasetSummary->get_zero_dop_range_time_c_pixel(), true);
180  kwl.add(prefix, "zero_dop_range_time_l_pixel", datasetSummary->get_zero_dop_range_time_l_pixel(), true);
181  }
182  else
183  {
184  result = false;
185  }
186 
187  const ErsSarMapProjectionData *mapprojectiondata = get_ErsSarMapProjectionData();
188  if ((mapprojectiondata != NULL) && (result == true))
189  {
190  kwl.add(prefix, "map_proj_des", (mapprojectiondata->get_map_proj_des()).c_str(), true);
191  kwl.add(prefix, "num_lines", (double) mapprojectiondata->get_num_lines(), true);
192  kwl.add(prefix, "num_pix", (double) mapprojectiondata->get_num_pix_in_line(), true);
193  kwl.add(prefix, "first_line_first_pixel_lat", mapprojectiondata->get_first_line_first_pixel_lat(), true);
194  kwl.add(prefix, "first_line_first_pixel_lon", mapprojectiondata->get_first_line_first_pixel_lon(), true);
195  kwl.add(prefix, "first_line_last_pixel_lat", mapprojectiondata->get_first_line_last_pixel_lat(), true);
196  kwl.add(prefix, "first_line_last_pixel_lon", mapprojectiondata->get_first_line_last_pixel_lon(), true);
197  kwl.add(prefix, "last_line_first_pixel_lat", mapprojectiondata->get_last_line_first_pixel_lat(), true);
198  kwl.add(prefix, "last_line_first_pixel_lon", mapprojectiondata->get_last_line_first_pixel_lon(), true);
199  kwl.add(prefix, "last_line_last_pixel_lat", mapprojectiondata->get_last_line_last_pixel_lat(), true);
200  kwl.add(prefix, "last_line_last_pixel_lon", mapprojectiondata->get_last_line_last_pixel_lon(), true);
201  }
202  else
203  {
204  result = false;
205  }
206 
208  if ((platformposition != NULL) && (result == true))
209  {
210  kwl.add(prefix, "neph", platformposition->get_ndata(), true);
211  kwl.add(prefix, "eph_year", platformposition->get_year(), true);
212  kwl.add(prefix, "eph_month", platformposition->get_month(), true);
213  kwl.add(prefix, "eph_day", platformposition->get_day(), true);
214  kwl.add(prefix, "eph_gmt_day", platformposition->get_gmt_day(), true);
215  kwl.add(prefix, "eph_sec", platformposition->get_gmt_sec(), true);
216  kwl.add(prefix, "eph_hr_angle", platformposition->get_hr_angle(), true);
217  kwl.add(prefix, "eph_int", platformposition->get_data_int(), true);
218 
219  for (int i = 0; i < platformposition->get_ndata(); i++)
220  {
221  sprintf(name, "eph%i_posX", i);
222  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[0], true);
223  sprintf(name, "eph%i_posY", i);
224  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[1], true);
225  sprintf(name, "eph%i_posZ", i);
226  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_pos()[2], true);
227 
228  sprintf(name, "eph%i_velX", i);
229  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[0], true);
230  sprintf(name, "eph%i_velY", i);
231  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[1], true);
232  sprintf(name, "eph%i_velZ", i);
233  kwl.add(prefix, name, (platformposition->get_pos_vect()[i]).get_vel()[2], true);
234  }
235  }
236  else
237  {
238  result = false;
239  }
240  /*
241  * Adding metadata necessary to the sensor model in the keywordlist
242  */
243  const ErsSarFacilityData *facilitydata = get_ErsSarFacilityData();
244  if ((facilitydata != NULL) && (result == true))
245  {
246  kwl.add(prefix, "coef_ground_range_1", facilitydata->get_coef_ground_range_1(), true);
247  kwl.add(prefix, "coef_ground_range_2", facilitydata->get_coef_ground_range_2(), true);
248  kwl.add(prefix, "coef_ground_range_3", facilitydata->get_coef_ground_range_3(), true);
249  kwl.add(prefix, "coef_ground_range_4", facilitydata->get_coef_ground_range_4(), true);
250  }
251  else
252  {
253  result = false;
254  }
255 
256 
257  if (traceDebug())
258  {
260  << MODULE << " exit status = " << (result ? "true" : "false\n")
261  << std::endl;
262  }
263 
264 
265  return result;
266 }
267 
269 {
270  return dynamic_cast<const ErsSarFacilityData*>(theRecords.find(ErsSarFacilityDataID)->second);
271 }
273 {
274  return dynamic_cast<const ErsSarPlatformPositionData*>(theRecords.find(ErsSarPlatformPositionDataID)->second);
275 }
277 {
278  return dynamic_cast<const ErsSarMapProjectionData*>(theRecords.find(ErsSarMapProjectionDataID)->second);
279 }
280 
282 {
283  return dynamic_cast<const ErsSarDataSetSummary*>(theRecords.find(ErsSarDataSetSummaryID)->second);
284 }
285 
287 {
288  return dynamic_cast<const ErsSarFileDescriptor*>(theRecords.find(ErsSarFileDescriptorID)->second);
289 }
290 }
double get_hr_angle() const
Greenwich mean hour angle.
This class is able to read the Leader file of the ErsSar file structure.
Definition: ErsSarLeader.h:40
This class is able to read a Platform position data record.
This class is able to read the SAR leader data set summary record of the leader file.
Represents serializable keyword/value map.
int get_num_pix_in_line() const
num_pix_in_line
double get_ellip_min() const
Ellipsoid semi_minor axis, km.
ErsSarLeader & operator=(const ErsSarLeader &rhs)
Copy operator.
double get_wave_length() const
Radar wave length.
const ErsSarMapProjectionData * get_ErsSarMapProjectionData() const
std::string get_inp_sctim() const
Input scene centre time.
double get_first_line_last_pixel_lon() const
first_line_last_pixel_lon
int get_sc_lin() const
Scene centre line number.
const ErsSarFileDescriptor * get_ErsSarFileDescriptor() const
double get_last_line_last_pixel_lat() const
last_line_last_pixel_lat
const ErsSarDataSetSummary * get_ErsSarDataSetSummary() const
static const int ErsSarMapProjectionDataID
Definition: ErsSarLeader.h:100
static const char * TYPE_KW
double get_n_azilok() const
Number of azimuth looks.
double get_ellip_maj() const
Ellipsoid semi-major axis, km.
static const int ErsSarPlatformPositionDataID
Definition: ErsSarLeader.h:99
double get_zero_dop_range_time_c_pixel() const
zero doppler range time (two way) of mid pixel
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
This class is able to read the SAR leader data set summary record of the leader file.
const ErsSarPlatformPositionData * get_ErsSarPlatformPositionData() const
void ClearRecords()
Remove all the previous records from the ErsSarLeader.
std::ostream & operator<<(std::ostream &os, const AlosPalsarData &data)
static const int ErsSarFacilityDataID
Definition: ErsSarLeader.h:98
double get_coef_ground_range_3() const
coef_ground_range_3
double get_coef_ground_range_1() const
coef_ground_range_1
double get_first_line_last_pixel_lat() const
first_line_last_pixel _lat
double get_data_int() const
Data sampling interval.
double get_fr() const
Range sampling rate.
std::string get_file_name() const
File name.
const ErsSarFacilityData * get_ErsSarFacilityData() const
double get_line_spacing() const
Line spacing, meters.
std::string get_map_proj_des() const
map_proj_des
This class is able to read the SAR leader data set summary record of the leader file.
ErsSarRecord * Instanciate(int id)
Instanciate a new Record.
double get_last_line_first_pixel_lat() const
last_line_first_pixel_lat
double get_coef_ground_range_4() const
coef_ground_range_4
This class is able to read a record header.
This class is the base class of all the record classes.
Definition: ErsSarRecord.h:27
std::istream & operator>>(std::istream &is, AlosPalsarData &data)
double get_first_line_first_pixel_lat() const
first_line_first_pixel _lat
double get_n_rnglok() const
Number of range looks.
double get_last_line_first_pixel_lon() const
last_line_first_pixel_lon
std::string get_time_dir_lin() const
Line time direction indicator.
This class is able to read the SAR leader file descriptor record of the leader file.
std::string get_time_dir_pix() const
Pixel time direction indicator.
std::map< int, ErsSarRecord * > theRecords
Definition: ErsSarLeader.h:96
int get_ndata() const
Number of data points.
double get_zero_dop_range_time_l_pixel() const
zero doppler range time (two way) of last pixel
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
virtual void Read(std::istream &is)=0
Read the class data from a stream.
int get_sc_pix() const
Scene centre pixel number.
double get_zero_dop_range_time_f_pixel() const
zero doppler range time (two way) of first pixel
This class is a facory able to construct Record base classes.
static const int ErsSarDataSetSummaryID
Definition: ErsSarLeader.h:101
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save object state to a keyword list.
double get_last_line_last_pixel_lon() const
last_line_last_pixel_lon
double get_pix_spacing() const
Pixel spacing, meters.
virtual ~ErsSarLeader()
Destructor.
double get_first_line_first_pixel_lon() const
first_line_first_pixel_lon
double get_coef_ground_range_2() const
coef_ground_range_2
const ErsSarPositionVectorRecord * get_pos_vect() const
Data point position/velocity.
double get_fa() const
Nominal PRF, Hz.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
static const int ErsSarFileDescriptorID
Definition: ErsSarLeader.h:102