OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
EnvisatAsarData.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 
14 
15 #include <EnvisatAsar/sph.h>
16 #include <EnvisatAsar/mph.h>
17 #include <EnvisatAsar/SQ_ADSR.h>
24 
25 namespace ossimplugins
26 {
27 
29 {
30 }
31 
33 {
34  ClearRecords();
35 }
36 
38 {
39  std::list<EnvisatAsarRecord*>::const_iterator it = data._records.begin();
40  while(it != data._records.end())
41  {
42  (*it)->Write(os);
43  ++it;
44  }
45  return os;
46 
47 }
48 
50 {
51  EnvisatAsarDataFactory factory;
52 
53  if (sizeof(int)!=4) std::cout << "EnvisatAsarData WARNING : (int) not coded over 32 bits, metadata might not be byte swapped correctly"<< std::endl ;
54  if (sizeof(float)!=4) std::cout << "EnvisatAsarData WARNING : (float) not coded over 32 bits, metadata might not be byte swapped correctly"<< std::endl ;
55  if (sizeof(double)!=8) std::cout << "EnvisatAsarData WARNING : (double) not coded over 64 bits, metadata might not be byte swapped correctly"<< std::endl ;
56 
57  data.ClearRecords();
58 
59  // read the first record (MPH)
60  EnvisatAsarRecord* mph_record = factory.Instanciate("MPH");
61  mph_record->Read(is);
62  data._records.push_back(mph_record);
63 
64  // read the second record (sph) and update it with the mph (number of dsd)
65  EnvisatAsarRecord* sph_record = factory.Instanciate("SPH");
66  ((sph*)sph_record)->update_sph_from_mph(*((mph *)mph_record));
67  sph_record->Read(is);
68  data._records.push_back(sph_record);
69 
70  std::vector<dsd> dsd_vector = ((sph*)sph_record)->get_dsd_vector();
71 
72  // For each dsd, check if present in the file and in the record factory.
73  // If true, instanciate it and add to the EnvisatAsarRecord list.
74  std::vector<dsd>::iterator it = dsd_vector.begin();
75  while(it != dsd_vector.end())
76  {
77  std::string str = (it->get_ds_name());
78 
79  if ( (it->get_ds_size()) != 0)
80  {
81  for (int i = 0; i<(it->get_num_dsr()); i++)
82  {
83  EnvisatAsarRecord* record = factory.Instanciate(str);
84  if (record != NULL)
85  {
86  is.seekg((std::streampos)(it->get_ds_offset())+ (std::streampos)(i*(it->get_dsr_size())));
87  record->Read(is);
88  data._records.push_back(record);
89  }
90  }
91  }
92  ++it;
93  }
94 
95  return is;
96 }
97 
98 
100 {
101  std::list<EnvisatAsarRecord*>::const_iterator it = rhs._records.begin();
102  while(it != rhs._records.end())
103  {
104  _records.push_back((*it)->Clone());
105  ++it;
106  }
107 }
108 
110 {
111  ClearRecords();
112  std::list<EnvisatAsarRecord*>::const_iterator it = rhs._records.begin();
113  while(it != rhs._records.end())
114  {
115  _records.push_back((*it)->Clone());
116  ++it;
117  }
118 
119  return *this;
120 }
121 
123 {
124  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
125  while(it != _records.end())
126  {
127  delete (*it);
128  ++it;
129  }
130  _records.clear();
131 }
133 {
134  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
135  while(it != _records.end())
136  {
137  if ((*it)->get_mnemonic().compare("mph_rec") == 0) return (mph*)(*it);
138  ++it;
139  }
140  return NULL;
141 }
143 {
144  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
145  while(it != _records.end())
146  {
147  if ((*it)->get_mnemonic().compare("sph_rec") == 0) return (sph*)(*it);
148  ++it;
149  }
150  return NULL;
151 }
152 
154 {
155  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
156  while(it != _records.end())
157  {
158  if ((*it)->get_mnemonic().compare("SQ_ADSR_rec") == 0) return (SQ_ADSR*)(*it);
159  ++it;
160  }
161  return NULL;
162 }
164 {
165  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
166  while(it != _records.end())
167  {
168  if ((*it)->get_mnemonic().compare("MainProcessingParameters_rec") == 0) return (MainProcessingParameters*)(*it);
169  ++it;
170  }
171  return NULL;
172 }
174 {
175  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
176  while(it != _records.end())
177  {
178  if ((*it)->get_mnemonic().compare("DopplerCentroidParameters_rec") == 0) return (DopplerCentroidParameters*)(*it);
179  ++it;
180  }
181  return NULL;
182 }
184 {
185  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
186  int cpt = 0;
187  while(it != _records.end())
188  {
189  if ((*it)->get_mnemonic().compare("SRGRConversionParameters_rec") == 0)
190  {
191  if (cpt == pos) {
192  return (SRGRConversionParameters*)(*it);
193  }
194  else cpt++;
195  }
196  ++it;
197  }
198  return NULL;
199 }
201 {
202  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
203  while(it != _records.end())
204  {
205  if ((*it)->get_mnemonic().compare("ChirpParameters_rec") == 0) return (ChirpParameters*)(*it);
206  ++it;
207  }
208  return NULL;
209 }
211 {
212  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
213  while(it != _records.end())
214  {
215  if ((*it)->get_mnemonic().compare("AntennaElevationPatterns_rec") == 0) return (AntennaElevationPatterns*)(*it);
216  ++it;
217  }
218  return NULL;
219 }
220 
221 // Return the first Geolocation Grid Record
222 //GeolocationGrid * EnvisatAsarData::get_GeolocationGrid()
223 //{
224 // std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
225 // while(it != _records.end())
226 // {
227 // std::string str = (*it)->get_mnemonic();
228 // if ((*it)->get_mnemonic().compare("GeolocationGrid_rec") == 0)
229 // {
230 // return (GeolocationGrid*)(*it);
231 // }
232 // ++it;
233 // }
234 // return NULL;
235 //}
236 
237 // Return the num_ds Geolocation Grid Record
239 {
240  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
241 
242  int total_num_ds = 0;
243  while(it != _records.end())
244  {
245  std::string str = (*it)->get_mnemonic();
246  if ((*it)->get_mnemonic().compare("GeolocationGrid_rec") == 0) total_num_ds += 1;
247  ++it;
248  }
249 
250  int cpt = 0;
251  it = _records.begin();
252  while(it != _records.end())
253  {
254  std::string str = (*it)->get_mnemonic();
255  if ((*it)->get_mnemonic().compare("GeolocationGrid_rec") == 0)
256  {
257  if ((cpt == num_ds) || (cpt == total_num_ds-1)) return (GeolocationGrid*)(*it);
258  cpt +=1;
259 
260  }
261  ++it;
262  }
263  return NULL;
264 }
265 
266 
268 {
269  if (record == NULL) return 0;
270  std::list<EnvisatAsarRecord*>::const_iterator it = _records.begin();
271  int cpt = 0;
272  while(it != _records.end())
273  {
274  std::string str = (*it)->get_mnemonic();
275  if ((*it)->get_mnemonic().compare(record->get_mnemonic()) == 0)
276  {
277  cpt++;
278  }
279  ++it;
280  }
281  return cpt;
282 }
283 }
This class is able to read the SAR sph record of the ASAR file.
Definition: sph.h:27
MainProcessingParameters * get_MainProcessingParameters()
This class is a factory able to construct Record base classes.
std::string get_mnemonic()
Returns the mnemonic of the record.
GeolocationGrid * get_GeolocationGrid(int num_ds=0)
ChirpParameters * get_ChirpParameters()
This class is able to read the ASAR SQ_ADSR record.
Definition: SQ_ADSR.h:24
EnvisatAsarData & operator=(const EnvisatAsarData &rhs)
Copy operator.
DopplerCentroidParameters * get_DopplerCentroidParameters()
std::ostream & operator<<(std::ostream &os, const AlosPalsarData &data)
This class is able to read the ASAR DopplerCentroidParameters record.
This class is able to read the ASAR MainProcessingParameters record.
This class is able to read the Envisat file structure.
virtual void Read(std::istream &is)=0
Reads the class data from a stream.
This class is able to read the ASAR ChirpParameters record.
This class is able to read the ASAR mph record of the leader file.
Definition: mph.h:25
std::istream & operator>>(std::istream &is, AlosPalsarData &data)
void ClearRecords()
Removes all the previous records from the EnvisatAsarData.
std::list< EnvisatAsarRecord * > _records
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
This class is able to read the ASAR SRGRConversionParameters record.
EnvisatAsarRecord * Instanciate(std::string id)
Instanciatse a new Record.
SRGRConversionParameters * get_SRGRConversionParameters(int pos=0)
This class is the base class of all the Envisat ASAR record classes.
This class is able to read the ASAR GeolocationGrid record.
This class is able to read the ASAR AntennaElevationPatterns record.
AntennaElevationPatterns * get_AntennaElevationPatterns()
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int get_num_ds(EnvisatAsarRecord *record)