OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Data.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 <RadarSat/Data/Data.h>
16 
17 #include <ossim/base/ossimTrace.h>
18 
19 namespace ossimplugins
20 {
21 // Static trace for debugging
22 static ossimTrace traceDebug("Data:debug");
23 
27 
29 {
30 }
31 
33 {
34  ClearRecords();
35 }
36 
38 {
39  std::map<int, RadarSatRecord*>::const_iterator it = data._records.begin();
40  while(it != data._records.end())
41  {
42  (*it).second->Write(os);
43  ++it;
44  }
45  return os;
46 
47 }
48 
50 {
51  DataFactory factory;
52 
53  data.ClearRecords();
54 
55  if (sizeof(int)!=4) ossimNotify(ossimNotifyLevel_WARN) << "RadarSat Data WARNING : (int) not coded over 32 bits, metadata might not be byte swapped correctly"<< std::endl ;
56  if (sizeof(float)!=4) ossimNotify(ossimNotifyLevel_WARN) << "RadarSat Data WARNING : (float) not coded over 32 bits, metadata might not be byte swapped correctly"<< std::endl ;
57  if (sizeof(double)!=8) ossimNotify(ossimNotifyLevel_WARN) << "RadarSat Data WARNING : (double) not coded over 64 bits, metadata might not be byte swapped correctly"<< std::endl ;
58 
59  RadarSatRecordHeader header;
60  bool eof = false;
61 
62  int nbLin = 0 ; // number of image lines
63  int lineLength = 0 ; // size of any ProcessedDataRecord
64 
65  is.seekg(0, std::ios::end) ;
66  int lengthOfFile = is.tellg(); // total length of file
67  is.seekg(0, std::ios::beg);
68  while(!eof)
69  {
70  is>>header;
71  if(is.eof())
72  {
73  eof = true;
74  }
75  else
76  {
77  if (header.get_rec_seq() == 1)
78  { // ImageOptionsFileDescriptor
79  RadarSatRecord* record = factory.Instanciate(header.get_rec_seq());
80  if (record != NULL)
81  {
82  record->Read(is);
84 
85  nbLin = ((ImageOptionsFileDescriptor *) record)->get_nlin() ;
86  if (nbLin == -1)
87  {
88  ossimNotify(ossimNotifyLevel_DEBUG) << "WARNING: nbLin is not read in the file !" << std::endl;
89  }
90  }
91  else
92  {
93  char* buff = new char[header.get_length()-12];
94  is.read(buff, header.get_length()-12);
95  delete[] buff;
96  }
97  }
98  else if ((header.get_rec_seq() == 2))
99  { // First line ProcessedDataRecord
100  lineLength = header.get_length() ;
101  RadarSatRecord* record = factory.Instanciate(2);
102  if (record != NULL)
103  {
104  record->Read(is);
106 
107  char* buff = new char[header.get_length()-192];
108  is.read(buff, header.get_length()-192); // Reads the rest of the line
109  delete[] buff;
110  }
111  else
112  {
113  char* buff = new char[header.get_length()-12];
114  is.read(buff, header.get_length()-12);
115  delete[] buff;
116  }
117  }
118  else if ((header.get_rec_seq() == (1+nbLin)))
119  { // Last line ProcessedDataRecord
120  RadarSatRecord* record = factory.Instanciate(2);
121  if (record != NULL)
122  {
123  record->Read(is);
125 
126  char* buff = new char[header.get_length()-192];
127  is.read(buff, header.get_length()-192); // Reads the rest of the line
128  delete[] buff;
129  }
130  else
131  {
132  char* buff = new char[header.get_length()-12];
133  is.read(buff, header.get_length()-12);
134  delete[] buff;
135  }
136  }
137  else
138  {
139  // all lines between the first and last ones are skipped
140  if (lineLength != 0)
141  {
142  if (nbLin == -1)
143  {
144  // Compute the number of line per dataset from the size of file and current position
145  int nbLines = ( ( lengthOfFile - is.tellg() ) / lineLength ) + 2;
146  ossimNotify(ossimNotifyLevel_DEBUG) << "To move in the dat file we compute the nb of lines = " << nbLines << std::endl;
147 
148  // We move in the file to the last line
149  is.seekg((nbLines - 2) * lineLength - 12, std::ios::cur);
150 
151  // We save the nbLines computed in data
152  nbLin = nbLines;
154  record->set_nlin(nbLin);
156  }
157  else
158  {
159  // We move in the file
160  is.seekg((nbLin - 2) * lineLength - 12, std::ios::cur);
161  }
162  }
163  else
164  {
165  // We move to the end of the file
166  is.seekg(0, std::ios::end) ;
167  }
168  }
169  }
170  }
171  return is;
172 }
173 
174 
175 Data::Data(const Data& rhs)
176 {
177  std::map<int, RadarSatRecord*>::const_iterator it = rhs._records.begin();
178  while(it != rhs._records.end())
179  {
180  _records[(*it).first] = (*it).second->Clone();
181  ++it;
182  }
183 }
184 
186 {
187  std::map<int, RadarSatRecord*>::const_iterator it = _records.begin();
188  while(it != _records.end())
189  {
190  delete (*it).second;
191  ++it;
192  }
193  _records.clear();
194 
195  it = rhs._records.begin();
196  while(it != rhs._records.end())
197  {
198  _records[(*it).first] = (*it).second->Clone();
199  ++it;
200  }
201 
202  return *this;
203 }
204 
206 {
207  std::map<int, RadarSatRecord*>::const_iterator it = _records.begin();
208  while(it != _records.end())
209  {
210  delete (*it).second;
211  ++it;
212  }
213  _records.clear();
214 }
215 
216 void Data::InsertRecord(int id, RadarSatRecord* record)
217 {
218  _records[id] = record;
219 }
220 
222 {
224 }
225 
227 {
229 }
230 
232 {
234 }
235 }
RadarSatRecord * Instanciate(int id)
Instanciates a new Record.
void set_nlin(int inNbLines)
Set the number of lines per data set.
~Data()
Destructor.
Definition: Data.cpp:32
ProcessedDataRecord * get_FirstProcessedDataRecord()
Definition: Data.cpp:226
This class is the base class of all the record classes.
virtual void Read(std::istream &is)=0
Reads the class data from a stream.
Data & operator=(const Data &rhs)
Copy operator.
Definition: Data.cpp:185
std::ostream & operator<<(std::ostream &os, const AlosPalsarData &data)
static const int LastProcessedDataRecordID
Definition: Data.h:81
This class is able to read an Processed Data Record.
ProcessedDataRecord * get_LastProcessedDataRecord()
Definition: Data.cpp:231
std::istream & operator>>(std::istream &is, AlosPalsarData &data)
static const int ImageOptionsFileDescriptorID
Definition: Data.h:79
This class is able to read an Image options file descriptor record.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
std::map< int, RadarSatRecord * > _records
Definition: Data.h:78
static const int FirstProcessedDataRecordID
Definition: Data.h:80
This class is able to read a record header.
void ClearRecords()
Removes all the previous records from the Data.
Definition: Data.cpp:205
This class is able to read the data file of the RadarSat file structure.
Definition: Data.h:31
void InsertRecord(int id, RadarSatRecord *record)
Inserts an existing record in the Data.
Definition: Data.cpp:216
Data()
Constructor.
Definition: Data.cpp:28
This class is a factory able to construct Record base classes.
Definition: DataFactory.h:25
ImageOptionsFileDescriptor * get_ImageOptionsFileDescriptor()
Definition: Data.cpp:221
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23