124
124
// Bytes 30-35: 'SENSOR'
125
125
// Bytes 36: Sensor Name (NULL terminated)
127
if (std::strncmp(pimpl_->seg_data.buffer, "RFMODEL ", 8)) {
127
if (std::strncmp(pimpl_->seg_data.buffer, "RFMODEL ", 8))
129
pimpl_->seg_data.Put("RFMODEL",0,8);
130
pimpl_->userrpc = false;
131
pimpl_->adjusted = false;
132
pimpl_->seg_data.Put("DS",22,2);
133
pimpl_->downsample = 1;
134
pimpl_->seg_data.Put("SENSOR",30,6);
135
pimpl_->num_coeffs = 20;
128
138
// Something has gone terribly wrong!
129
throw PCIDSKException("A segment that was previously identified as an RFMODEL "
139
/*throw PCIDSKException("A segment that was previously identified as an RFMODEL "
130
140
"segment does not contain the appropriate data. Found: [%s]",
131
std::string(pimpl_->seg_data.buffer, 8).c_str());
141
std::string(pimpl_->seg_data.buffer, 8).c_str());*/
134
144
// Determine if this is user-provided
135
pimpl_->userrpc = pimpl_->seg_data.buffer[8] == 0 ? true : false;
145
pimpl_->userrpc = pimpl_->seg_data.buffer[8] == '1' ? true : false;
137
147
// Check for the DS characters
138
148
pimpl_->downsample = 1;
139
if (!std::strncmp(&pimpl_->seg_data.buffer[22], "DS", 2)) {
149
if (!std::strncmp(&pimpl_->seg_data.buffer[22], "DS", 2))
140
151
// Read the downsample factor
141
152
pimpl_->downsample = pimpl_->seg_data.GetInt(24, 3);
144
// I don't know what 2ND means yet.
155
//This is requiered if writting with PCIDSKIO
156
//and reading with GDBIO (probably because of legacy issue)
157
// see Bugzilla 255 and 254.
158
bool bSecond = false;
159
if (!std::strncmp(&pimpl_->seg_data.buffer[27], "2ND", 3))
147
165
if (!std::strncmp(&pimpl_->seg_data.buffer[30], "SENSOR", 6)) {
166
184
// Bytes 222-243: line scale
167
185
// Bytes 244-375: Adjusted X coefficients (5 * 22 bytes)
168
186
// Bytes 376-507: Adjusted Y coefficients (5 * 22 bytes)
170
pimpl_->num_coeffs = pimpl_->seg_data.GetInt(512, 4);
172
if (pimpl_->num_coeffs * 22 > 512) {
173
// this segment is malformed. Throw an exception.
174
throw PCIDSKException("RFMODEL segment coefficient count requires more "
175
"than one block to store. There is an error in this segment. The "
176
"number of coefficients according to the segment is %d.", pimpl_->num_coeffs);
179
pimpl_->lines = pimpl_->seg_data.GetInt(512 + 4, 10);
180
pimpl_->pixels = pimpl_->seg_data.GetInt(512 + 14, 10);
181
pimpl_->y_off = pimpl_->seg_data.GetDouble(512 + 24, 22);
182
pimpl_->y_scale = pimpl_->seg_data.GetDouble(512 + 46, 22);
183
pimpl_->x_off = pimpl_->seg_data.GetDouble(512 + 68, 22);
184
pimpl_->x_scale = pimpl_->seg_data.GetDouble(512 + 90, 22);
185
pimpl_->z_off = pimpl_->seg_data.GetDouble(512 + 112, 22);
186
pimpl_->z_scale = pimpl_->seg_data.GetDouble(512 + 134, 22);
187
pimpl_->pix_off = pimpl_->seg_data.GetDouble(512 + 156, 22);
188
pimpl_->pix_scale = pimpl_->seg_data.GetDouble(512 + 178, 22);
189
pimpl_->line_off = pimpl_->seg_data.GetDouble(512 + 200, 22);
190
pimpl_->line_scale = pimpl_->seg_data.GetDouble(512 + 222, 22);
192
// Read in adjusted X coefficients
193
for (unsigned int i = 0; i <= 5; i++) {
194
double tmp = pimpl_->seg_data.GetDouble(512 + 244 + (i * 22), 22);
195
pimpl_->x_adj.push_back(tmp);
198
// Read in adjusted Y coefficients
199
for (unsigned int i = 0; i <= 5; i++) {
200
double tmp = pimpl_->seg_data.GetDouble(512 + 376 + (i * 22), 22);
201
pimpl_->y_adj.push_back(tmp);
187
// if bSecond is false, then the coefficient are stored
188
// at others positions
189
// every value takes 22 bytes.
193
pimpl_->num_coeffs = pimpl_->seg_data.GetInt(512, 4);
195
if (pimpl_->num_coeffs * 22 > 512) {
196
// this segment is malformed. Throw an exception.
197
throw PCIDSKException("RFMODEL segment coefficient count requires more "
198
"than one block to store. There is an error in this segment. The "
199
"number of coefficients according to the segment is %d.", pimpl_->num_coeffs);
202
pimpl_->lines = pimpl_->seg_data.GetInt(512 + 4, 10);
203
pimpl_->pixels = pimpl_->seg_data.GetInt(512 + 14, 10);
204
pimpl_->x_off = pimpl_->seg_data.GetDouble(512 + 24, 22);
205
pimpl_->x_scale = pimpl_->seg_data.GetDouble(512 + 46, 22);
206
pimpl_->y_off = pimpl_->seg_data.GetDouble(512 + 68, 22);
207
pimpl_->y_scale = pimpl_->seg_data.GetDouble(512 + 90, 22);
208
pimpl_->z_off = pimpl_->seg_data.GetDouble(512 + 112, 22);
209
pimpl_->z_scale = pimpl_->seg_data.GetDouble(512 + 134, 22);
210
pimpl_->pix_off = pimpl_->seg_data.GetDouble(512 + 156, 22);
211
pimpl_->pix_scale = pimpl_->seg_data.GetDouble(512 + 178, 22);
212
pimpl_->line_off = pimpl_->seg_data.GetDouble(512 + 200, 22);
213
pimpl_->line_scale = pimpl_->seg_data.GetDouble(512 + 222, 22);
215
pimpl_->adjusted = false;
216
// Read in adjusted X coefficients
217
for (unsigned int i = 0; i <= 5; i++)
219
double tmp = pimpl_->seg_data.GetDouble(512 + 244 + (i * 22), 22);
220
pimpl_->x_adj.push_back(tmp);
223
pimpl_->adjusted = true;
227
// Read in adjusted Y coefficients
228
for (unsigned int i = 0; i <= 5; i++)
230
double tmp = pimpl_->seg_data.GetDouble(512 + 376 + (i * 22), 22);
231
pimpl_->y_adj.push_back(tmp);
234
pimpl_->adjusted = true;
240
pimpl_->num_coeffs = pimpl_->seg_data.GetInt(512, 22);
242
if (pimpl_->num_coeffs * 22 > 512) {
243
// this segment is malformed. Throw an exception.
244
throw PCIDSKException("RFMODEL segment coefficient count requires more "
245
"than one block to store. There is an error in this segment. The "
246
"number of coefficients according to the segment is %d.", pimpl_->num_coeffs);
249
pimpl_->lines = pimpl_->seg_data.GetInt(512 + 22, 22);
250
pimpl_->pixels = pimpl_->seg_data.GetInt(512 + 2*22,22);
251
pimpl_->x_off = pimpl_->seg_data.GetDouble(512 + 3*22, 22);
252
pimpl_->x_scale = pimpl_->seg_data.GetDouble(512 + 4*22, 22);
253
pimpl_->y_off = pimpl_->seg_data.GetDouble(512 + 5*22, 22);
254
pimpl_->y_scale = pimpl_->seg_data.GetDouble(512 + 6*22, 22);
255
pimpl_->z_off = pimpl_->seg_data.GetDouble(512 + 7*22, 22);
256
pimpl_->z_scale = pimpl_->seg_data.GetDouble(512 + 8*22, 22);
257
pimpl_->pix_off = pimpl_->seg_data.GetDouble(512 + 9*22, 22);
258
pimpl_->pix_scale = pimpl_->seg_data.GetDouble(512 + 10*22, 22);
259
pimpl_->line_off = pimpl_->seg_data.GetDouble(512 + 11*22, 22);
260
pimpl_->line_scale = pimpl_->seg_data.GetDouble(512 + 12*22, 22);
262
pimpl_->adjusted = false;
263
// Read in adjusted X coefficients
264
for (unsigned int i = 0; i <= 3; i++)
266
double tmp = pimpl_->seg_data.GetDouble(512 + 12*22 + (i * 22), 22);
267
pimpl_->x_adj.push_back(tmp);
270
pimpl_->adjusted = true;
273
pimpl_->x_adj.push_back(0.0);
274
pimpl_->x_adj.push_back(0.0);
275
pimpl_->x_adj.push_back(0.0);
277
// Read in adjusted Y coefficients
278
for (unsigned int i = 0; i <= 3; i++)
280
double tmp = pimpl_->seg_data.GetDouble(512 + 16*22 + (i * 22), 22);
281
pimpl_->y_adj.push_back(tmp);
284
pimpl_->adjusted = true;
287
pimpl_->y_adj.push_back(0.0);
288
pimpl_->y_adj.push_back(0.0);
289
pimpl_->y_adj.push_back(0.0);
243
331
void CPCIDSKRPCModelSegment::Write(void)
333
//We are not writing if nothing was loaded.
338
// The RPC Model Segment is defined as follows:
339
// RFMODEL Segment: 7 512-byte blocks
342
// Bytes 0-7: 'RFMODEL '
343
// Byte 8: User Provided RPC (1: user-provided, 0: computed from GCPs)
345
// Bytes 24-26: Downsample factor used during Epipolar Generation
346
// Bytes 27-29: '2ND' -- no clue what this means
347
// Bytes 30-35: 'SENSOR'
348
// Bytes 36: Sensor Name (NULL terminated)
349
pimpl_->seg_data.Put("RFMODEL",0,8);
351
// Determine if this is user-provided
352
pimpl_->seg_data.buffer[8] = pimpl_->userrpc ? '1' : '0';
354
// Check for the DS characters
355
pimpl_->seg_data.Put("DS",22,2);
356
pimpl_->seg_data.Put(pimpl_->downsample,24,3);
358
//This is requiered if writting with PCIDSKIO
359
//and reading with GDBIO (probably because of legacy issue)
360
// see Bugzilla 255 and 254.
361
pimpl_->seg_data.Put("2ND",27,3);
364
pimpl_->seg_data.Put("SENSOR",30,6);
365
pimpl_->seg_data.Put(pimpl_->sensor_name.c_str(),36,pimpl_->sensor_name.size());
368
// Bytes 0-3: Number of coefficients
369
// Bytes 4-13: Number of pixels
370
// Bytes 14-23: Number of lines
371
// Bytes 24-45: Longitude offset
372
// Bytes 46-67: Longitude scale
373
// Bytes 68-89: Latitude Offset
374
// Bytes 90-111: Latitude Scale
375
// Bytes 112-133: Height offset
376
// Bytes 134-155: Height scale
377
// Bytes 156-177: Sample offset
378
// Bytes 178-199: Sample scale
379
// Bytes 200-221: Line offset
380
// Bytes 222-243: line scale
381
// Bytes 244-375: Adjusted X coefficients (5 * 22 bytes)
382
// Bytes 376-507: Adjusted Y coefficients (5 * 22 bytes)
384
if (pimpl_->num_coeffs * 22 > 512) {
385
// this segment is malformed. Throw an exception.
386
throw PCIDSKException("RFMODEL segment coefficient count requires more "
387
"than one block to store. There is an error in this segment. The "
388
"number of coefficients according to the segment is %d.", pimpl_->num_coeffs);
391
pimpl_->seg_data.Put(pimpl_->num_coeffs,512, 4);
393
pimpl_->seg_data.Put(pimpl_->lines,512 + 4, 10);
394
pimpl_->seg_data.Put(pimpl_->pixels,512 + 14, 10);
395
pimpl_->seg_data.Put(pimpl_->x_off,512 + 24, 22,"%22.14f");
396
pimpl_->seg_data.Put(pimpl_->x_scale,512 + 46, 22,"%22.14f");
397
pimpl_->seg_data.Put(pimpl_->y_off,512 + 68, 22,"%22.14f");
398
pimpl_->seg_data.Put(pimpl_->y_scale,512 + 90, 22,"%22.14f");
399
pimpl_->seg_data.Put(pimpl_->z_off,512 + 112, 22,"%22.14f");
400
pimpl_->seg_data.Put(pimpl_->z_scale,512 + 134, 22,"%22.14f");
401
pimpl_->seg_data.Put(pimpl_->pix_off,512 + 156, 22,"%22.14f");
402
pimpl_->seg_data.Put(pimpl_->pix_scale,512 + 178, 22,"%22.14f");
403
pimpl_->seg_data.Put(pimpl_->line_off,512 + 200, 22,"%22.14f");
404
pimpl_->seg_data.Put(pimpl_->line_scale,512 + 222, 22,"%22.14f");
406
// Read in adjusted X coefficients
407
for (unsigned int i = 0; i <= 5; i++)
409
pimpl_->seg_data.Put(pimpl_->x_adj[i],512 + 244 + (i * 22), 22,"%22.14f");
410
if(pimpl_->x_adj[i] != 0.0)
412
pimpl_->adjusted = true;
416
// Read in adjusted Y coefficients
417
for (unsigned int i = 0; i <= 5; i++)
419
pimpl_->seg_data.Put(pimpl_->y_adj[i],512 + 376 + (i * 22), 22,"%22.14f");
420
if(pimpl_->y_adj[i] != 0.0)
422
pimpl_->adjusted = true;
427
// Block 3 contains the numerator coefficients for the pixel rational polynomial
428
// Number of Coefficients * 22 bytes
429
for (unsigned int i = 0; i < pimpl_->num_coeffs; i++)
431
pimpl_->seg_data.Put(pimpl_->pixel_num[i],2 * 512 + (i * 22), 22,"%22.14f");
435
// Block 4 contains the denominator coefficients for the pixel rational polynomial
436
// Number of Coefficients * 22 bytes
437
for (unsigned int i = 0; i < pimpl_->num_coeffs; i++)
439
pimpl_->seg_data.Put(pimpl_->pixel_denom[i],3 * 512 + (i * 22), 22,"%22.14f");
443
// Block 5 contains the numerator coefficients for the line rational polynomial
444
// Number of Coefficients * 22 bytes
445
for (unsigned int i = 0; i < pimpl_->num_coeffs; i++)
447
pimpl_->seg_data.Put(pimpl_->line_num[i],4 * 512 + (i * 22), 22,"%22.14f");
451
// Block 6 contains the denominator coefficients for the line rational polynomial
452
// Number of Coefficients * 22 bytes
453
for (unsigned int i = 0; i < pimpl_->num_coeffs; i++)
455
pimpl_->seg_data.Put(pimpl_->line_denom[i],5 * 512 + (i * 22), 22,"%22.14f");
459
// Bytes 0-15: MapUnits string
460
// Bytes 256-511: ProjInfo_t, serialized
461
pimpl_->seg_data.Put(pimpl_->map_units.c_str(),6 * 512, 16);
463
WriteToFile(pimpl_->seg_data.buffer,0,data_size-1024);
248
467
std::vector<double> CPCIDSKRPCModelSegment::GetXNumerator(void) const