forked from ngageoint/csm
-
Notifications
You must be signed in to change notification settings - Fork 13
/
NitfIsd.h
300 lines (244 loc) · 9.28 KB
/
NitfIsd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//#############################################################################
//
// FILENAME: NitfIsd.h
//
// CLASSIFICATION: Unclassified
//
// DESCRIPTION:
//
// Header for the NITF 2.0 and 2.1 ISD classes derived from the csm::Isd
// base class. This class provides portions of the NITF file that are
// useful for initializing a model.
//
// LIMITATIONS: None
//
// SOFTWARE HISTORY:
// Date Author Comment
// ----------- ------ -------
// 01-Jul-2003 LMT Initial version.
// 06-Feb-2004 KRW Incorporated changes approved by
// January and February configuration
// control board.
// 01-Oct-2004 KRW October 2004 CCB
// 02-Mar-2012 SCM Refactored interfaces.
// 29-Oct-2012 SCM Fixed NitfIsd to return const vector references.
// 30-Oct-2012 SCM Renamed to NitfIsd.h
// 06-Dec-2012 JPK Made Filename parameter optional, replaced
// TRE and DES with Tre and Des for consistency
// 17-Dec-2012 BAH Documentation updates.
// 10-Sep-2013 SCM Added std namespace to atoi() calls.
//
// NOTES:
//
//#############################################################################
#ifndef __CSM_NITFISD_H
#define __CSM_NITFISD_H
#include "Isd.h"
#include <vector>
#include <cstdlib>
namespace csm
{
//***
// CLASS: Des
//> NITF Data Extension Segment (DES) class. DESs can be used to hold overflow
// TREs that did not fit in a NITF image segment.
//<
//***
class CSM_EXPORT_API Des
{
public:
Des() : theSubHeader(), theData() {}
Des(const std::string& aSubHeader, const std::string& aData)
: theSubHeader(aSubHeader), theData(aData) {}
~Des() {}
void clear() { theSubHeader = theData = ""; }
const std::string& subHeader() const { return theSubHeader; }
const std::string& data() const { return theData; }
void setSubHeader(const std::string& sh) { theSubHeader = sh; }
void setData(const std::string& data) { theData = data; }
private:
std::string theSubHeader;
std::string theData;
//> This contains the data in the DES. It might contain overflow TREs.
//<
};
//***
// CLASS: Tre
//> NITF Tagged Record Extension (TRE) class. TREs contain most of the support
// data needed to instantiate a model.
//<
//***
class CSM_EXPORT_API Tre
{
public:
Tre() : theName(), theLength(0), theData() {}
explicit Tre(const std::string& treData)
: theName(), theLength(0), theData() { setTre(treData); }
Tre(const std::string& aName, unsigned int aLength, const std::string& aData)
: theName(aName), theLength(aLength), theData(aData) {}
~Tre() {}
const std::string& name() const { return theName; }
const unsigned int length() const { return theLength; }
const std::string& data() const { return theData; }
const void setName(const std::string& aName) { theName = aName; }
const void setLength(unsigned int aLength) { theLength = aLength; }
const void setData(const std::string& aData) { theData = aData; }
void setTre(const std::string& treData)
{
if (treData.length() < 11) return;
theName = treData.substr(0, 6);
theLength = std::atoi(treData.substr(6, 5).c_str());
theData = treData.substr(11);
}
//> This method extracts the TRE's name, length and data from treData.
//
// Note that this function extracts all six characters of the TRE name,
// which might include trailing spaces.
//
// Note that theLength is set to the value in the TRE's CEL field,
// which should match the length of theData.
//<
void clear() { theName = ""; theLength = 0; theData = ""; }
private:
std::string theName;
//> This string contains the six-character TRE name.
//<
unsigned int theLength;
//> This integer contains the TRE data length given by the TRE's CEL
// field, which should be same as the length of theData.
//<
std::string theData;
//> This string contains the TRE data.
//<
};
//***
// CLASS: Image
//> NITF image subheader class. The image subheader contains the image support
// data, including TREs. The image data section of the NITF file consists of
// the image pixels and is not part of the CSM API.
//<
//***
class CSM_EXPORT_API Image
{
public:
Image() : theSubHeader(), theImageTres() {}
Image(const std::string& aSubHeader, const std::vector<Tre>& tres)
: theSubHeader(aSubHeader), theImageTres(tres) {}
//> This method constructs the Image object with the given image
// subheader data (including the TRE data) and list of parsed TREs.
//<
~Image() {}
const std::string& subHeader() const { return theSubHeader; }
//> This method returns the entire image subheader, including a copy of
// the TRE data.
//<
const std::vector<Tre>& imageTres() const { return theImageTres; }
//> This method returns the list of image subheader TREs.
//<
void setSubHeader(const std::string& sh) { theSubHeader = sh; }
//> This method sets the entire image subheader, including a copy of
// the TRE data. When using this method, it is important to also set
// the separated TREs as necessary using the methods below.
//<
void clearImageTres() { theImageTres.clear(); }
//> This method removes all Tre objects from the list.
//<
void addImageTre(const Tre& tre) { theImageTres.push_back(tre); }
//> This method adds the given Tre object to the list.
//<
void setImageTres(const std::vector<Tre>& tres) { theImageTres = tres; }
//> This method sets the Tre list to the given vector.
//<
private:
std::string theSubHeader;
//> This string contains the entire image subheader, including a copy of
// the TRE data.
//<
std::vector<Tre> theImageTres;
//> This contains the parsed TREs.
//<
};
//***
// CLASS: NitfIsd
//> NITF ISD class. This is an intermediary class that the NITF 2.0 and
// NITF 2.1 ISD classes are derived from. Do not construct this class
// directly. Construct the appropriate derived class to set the NITF format
// that the calling application needs to parse the data. Then this class
// can be used to retrieve the format and access the data.
//<
//***
class CSM_EXPORT_API NitfIsd : public Isd
{
public:
virtual ~NitfIsd();
const std::string& fileHeader() const { return theFileHeader; }
//> This method returns the entire file subheader, including a copy of
// the TRE data.
//<
const std::vector<Tre>& fileTres() const { return theFileTres; }
//> This method returns the file header Tre objects.
//<
const std::vector<Des>& fileDess() const { return theFileDess; }
//> This method returns the Des objects in this NITF.
//<
const std::vector<Image>& images() const { return theImages; }
//> This method returns the Image objects in this NITF.
//<
void setFileHeader(const std::string& head) { theFileHeader = head; }
//> This method sets the file header, which can include TRE data.
// When using this method, it is important to also set the separated
// file header TREs as necessary using the methods below.
//<
void clearFileTres() { theFileTres.clear(); }
//> This method removes all file header Tre objects from the list.
//<
void addFileTre(const Tre& tre) { theFileTres.push_back(tre); }
//> This method adds the given file header Tre object to the list.
//<
void setFileTres(const std::vector<Tre>& tres) { theFileTres = tres; }
//> This method sets the file header Tre list to the given vector.
//<
void clearFileDess() { theFileDess.clear(); }
//> This method removes all Des objects from the list.
//<
void addFileDes(const Des& des) { theFileDess.push_back(des); }
//> This method adds the given Des object to the list.
//<
void setFileDess(const std::vector<Des>& dess) { theFileDess = dess; }
//> This method sets the Des list to the given vector.
//<
void clearImages() { theImages.clear(); }
//> This method removes all Image objects from the list.
//<
void addImage(const Image& image) { theImages.push_back(image); }
//> This method adds the given Image object to the list.
//<
void setImages(const std::vector<Image>& images) { theImages = images; }
//> This method sets the Image list to the given vector.
//<
protected:
NitfIsd(const std::string& format, const std::string& filename = "")
: Isd(format,filename),theFileHeader(),theFileTres(),theFileDess(),theImages() {}
private:
std::string theFileHeader;
//> This string contains the full file header text, including a copy of
// the file level TRE data.
//<
std::vector<Tre> theFileTres;
std::vector<Des> theFileDess;
std::vector<Image> theImages;
};
class CSM_EXPORT_API Nitf20Isd : public NitfIsd
{
public:
Nitf20Isd(const std::string& filename = "") : NitfIsd("NITF2.0", filename) {}
virtual ~Nitf20Isd();
};
class CSM_EXPORT_API Nitf21Isd : public NitfIsd
{
public:
Nitf21Isd(const std::string& filename = "") : NitfIsd("NITF2.1", filename) {}
virtual ~Nitf21Isd();
};
} // namespace csm
#endif