Isis 3 Programmer Reference
ProcessExportPds.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "ProcessExportPds.h"
8
9#include <cmath>
10#include <iostream>
11#include <sstream>
12
13#include "Endian.h"
14#include "ExportPdsTable.h"
15#include "FileName.h"
16#include "IException.h"
17#include "IString.h"
18#include "PixelType.h"
19#include "Projection.h"
20#include "ProjectionFactory.h"
21#include "Pvl.h"
22#include "PvlFormat.h"
23#include "PvlToPvlTranslationManager.h"
24#include "PvlFormatPds.h"
25#include "SpecialPixel.h"
26#include "Table.h"
27
28
29using namespace std;
30
31namespace Isis {
37 m_label = NULL;
38 m_formatter = NULL;
41
42 m_forceBands = true;
43 m_forceBandName = true;
45 m_forceBandwidth = true;
47 m_forceOffset = true;
49 m_forceSampleBits = true;
51 m_forceSampleType = true;
52 m_forceCoreNull = true;
53 m_forceCoreLrs = true;
54 m_forceCoreLis = true;
55 m_forceCoreHrs = true;
56 m_forceCoreHis = true;
57 m_detachedLabel = false;
58
60 m_tableRecords.clear();
61 m_tableBuffers.clear();
62 }
63
69 delete m_label;
70 delete m_formatter;
71 for (unsigned int i = 0; i < m_tableBuffers.size(); i++) {
72 delete [] m_tableBuffers[i];
73 m_tableBuffers[i] = NULL;
74 }
75 m_tableBuffers.clear();
76 }
77
93 m_label = new Pvl;
94
95 m_pdsFileType = type;
98 }
99
100 m_formatter = new PvlFormatPds("$ISISROOT/appdata/translations/pdsExportRootGen.typ");
101 m_label->setFormat(m_formatter);
102 m_label->setTerminator("END");
103
106 }
107 else {
108 QString msg = "Unsupported PDS output type";
109 throw IException(IException::User, msg, _FILEINFO_);
110 }
111
112 return *m_label;
113 }
114
115
120
121 Pvl &mainPvl = *m_label;
122
123 if(m_exportType == Stream) {
125 StreamImageRoot(mainPvl);
126 }
128 StreamJP2ImageRoot(mainPvl);
129 }
130 }
131 else if(m_exportType == Fixed) {
133 FixedImageRoot(mainPvl);
134 }
136 FixedJP2ImageRoot(mainPvl);
137 }
138 }
139 else {
140 QString msg = "Invalid PDS export type.";
141 throw IException(IException::Programmer, msg, _FILEINFO_);
142 }
143
145 StandardJP2Image(mainPvl);
146 }
147 else {
148 StandardImageImage(mainPvl);
149 }
150
151 // The IMAGE_MAP_PROJECTION group is located in the ROOT for PDS IMAGEs. The
152 // standard routines will add the IMAGE_MAP_PROJECTION correctly
153 StandardAllMapping(mainPvl);
154 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportAllMapping.typ");
155 }
156
157
162 Pvl &mainPvl = *m_label;
163
164// StandardQubeRoot (mainPvl);
165// StandardQubeQube (mainPvl);
166
167 // The IMAGE_MAP_PROJECTION group is located inside the QUBE object for PDS
168 // QUBEs. Create a temporary PVL so the StandardAllMapping member can add an
169 // IMAGE_MAP_PROJECTION group then later it can be extracted and added to
170 // the output PDS label.
171 Pvl mapTmp;
172 StandardAllMapping(mapTmp);
173 if(mapTmp.hasObject("IMAGE_MAP_PROJECTION")) {
174 mainPvl.findObject("QUBE").addObject(mapTmp.findObject("IMAGE_MAP_PROJECTION"));
175 }
176 }
177
178
183 Pvl &mainPvl = *m_label;
184
185// StandardSpectralQubeRoot (mainPvl);
186// StandardSpectralQubeSpectralQube (mainPvl);
187
188 // The IMAGE_MAP_PROJECTION group is located inside the SPECTRAL_QUBE object
189 // for PDS SPECTRAL_QUBEs. Create a temporary PVL so the StandardAllMapping
190 // member can add an IMAGE_MAP_PROJECTION group then later it can be
191 // extracted and added to the output PDS label.
192 Pvl mapTmp;
193 StandardAllMapping(mapTmp);
194 if(mapTmp.hasObject("IMAGE_MAP_PROJECTION")) {
195 mainPvl.findObject("QUBE").addObject(mapTmp.findObject("IMAGE_MAP_PROJECTION"));
196 }
197 }
198
199
206 // Create standard ROOT object keywords
207 mainPvl += PvlKeyword("PDS_VERSION_ID", "PDS3");
208 mainPvl += PvlKeyword("RECORD_TYPE", "UNDEFINED");
209 // NOTE: WARNING: If the number of "?"s in the next few lines changes, you
210 // must also changes the corresponding lines in the OutputLabel member
211 mainPvl += PvlKeyword("LABEL_RECORDS", "???????", "BYTES");
212 if(m_detachedLabel) {
213 QString sImageFile = m_detachedPdsLabelFile;
214 int iFound = sImageFile.indexOf(".lbl");
215 if(iFound != -1) {
216 sImageFile.replace(iFound, 4, ".img");
217 }
218 else {
219 sImageFile += ".img";
220 }
221 FileName outFile(sImageFile);
222 mainPvl += PvlKeyword("^IMAGE", outFile.name());
223 }
224 else {
225 mainPvl += PvlKeyword("^IMAGE", "???????", "BYTES");
226 }
227 // MD5 checksums are 128-bit -> 32 characters when stringified from hex.
228 if (canGenerateChecksum()) {
229 mainPvl += PvlKeyword("CHECKSUM", "????????????????????????????????");
230 }
231 }
232
233
240 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
241 // Create standard ROOT object keywords
242 mainPvl += PvlKeyword("PDS_VERSION_ID", "PDS3");
243 QString sImageFile = m_detachedPdsLabelFile;
244 if(m_detachedLabel) {
245 int iFound = sImageFile.indexOf(".lbl");
246 if(iFound != -1) {
247 sImageFile.replace(iFound, 4, ".jp2");
248 }
249 else {
250 sImageFile += ".jp2";
251 }
252 }
253 else {
254 QString msg = "Labels must be detached for JP2 files.";
255 throw IException(IException::Programmer, msg, _FILEINFO_);
256 }
257 FileName outFile(sImageFile);
258 PvlObject cmpObj("COMPRESSED_FILE");
259 cmpObj += PvlKeyword("FILE_NAME", outFile.name());
260 cmpObj += PvlKeyword("RECORD_TYPE", "UNDEFINED");
261 cmpObj += PvlKeyword("ENCODING_TYPE", "JP2");
262 cmpObj += PvlKeyword("ENCODING_TYPE_VERSION_NAME", "ISO/IEC15444-1:2004");
263 cmpObj += PvlKeyword("INTERCHANGE_FORMAT", "BINARY");
264 FileName infilename(InputCubes[0]->fileName());
265 cmpObj += PvlKeyword("UNCOMPRESSED_FILE_NAME", infilename.name());
266 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
267 if(p_pixelType == Isis::Real) {
268 QString msg = "JPEG2000 does not support floating point data.";
269 throw IException(IException::Programmer, msg, _FILEINFO_);
270 }
271 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
272 storagebytes = storagebytes * 2;
273 }
274 cmpObj += PvlKeyword("REQUIRED_STORAGE_BYTES", toString(storagebytes));
275 mainPvl.addObject(cmpObj);
276 PvlObject ucmpObj("UNCOMPRESSED_FILE");
277 ucmpObj += PvlKeyword("FILE_NAME", infilename.name());
278 ucmpObj += PvlKeyword("RECORD_TYPE", "FIXED_LENGTH");
279 int recordbytes = InputCubes[0]->sampleCount();
280 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
281 recordbytes = recordbytes * 2;
282 }
283 ucmpObj += PvlKeyword("RECORD_BYTES", toString(recordbytes));
284 ucmpObj += PvlKeyword("FILE_RECORDS", toString(InputCubes[0]->lineCount()));
285 ucmpObj += PvlKeyword("^IMAGE", infilename.name());
286 mainPvl.addObject(ucmpObj);
287 }
288
289
296 //Create fixed ROOT object keywords
297 mainPvl += PvlKeyword("PDS_VERSION_ID", "PDS3");
298 mainPvl += PvlKeyword("RECORD_TYPE", "FIXED_LENGTH");
299 // NOTE: WARNING: If the number of "?"s in the next few lines changes, you
300 // must also changes the corresponding lines in the OutputLabel member
301 mainPvl += PvlKeyword("RECORD_BYTES", "???????");
302 mainPvl += PvlKeyword("FILE_RECORDS", "???????");
303 mainPvl += PvlKeyword("LABEL_RECORDS", "????");
304 if(m_detachedLabel) {
305 QString sImageFile = m_detachedPdsLabelFile;
306 int iFound = sImageFile.indexOf(".lbl");
307 if(iFound != -1) {
308 sImageFile.replace(iFound, 4, ".img");
309 }
310 else {
311 sImageFile += ".img";
312 }
313 FileName outFile(sImageFile);
314 mainPvl += PvlKeyword("^IMAGE", outFile.name());
315 }
316 else {
317 mainPvl += PvlKeyword("^IMAGE", "???");
318 }
319 if (canGenerateChecksum()) {
320 mainPvl += PvlKeyword("CHECKSUM", "????????????????????????????????");
321 }
322 }
323
324
331 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
332 //Create fixed ROOT object keywords
333 mainPvl += PvlKeyword("PDS_VERSION_ID", "PDS3");
334 QString sImageFile = m_detachedPdsLabelFile;
335 if(m_detachedLabel) {
336 int iFound = sImageFile.indexOf(".lbl");
337 if(iFound != -1) {
338 sImageFile.replace(iFound, 4, ".jp2");
339 }
340 else {
341 sImageFile += ".jp2";
342 }
343 }
344 else {
345 QString msg = "Labels must be detached for JP2 files.";
346 throw IException(IException::Programmer, msg, _FILEINFO_);
347 }
348 FileName outFile(sImageFile);
349 PvlObject cmpObj("COMPRESSED_FILE");
350 cmpObj += PvlKeyword("FILE_NAME", outFile.name());
351 cmpObj += PvlKeyword("RECORD_TYPE", "UNDEFINED");
352 cmpObj += PvlKeyword("ENCODING_TYPE", "JP2");
353 cmpObj += PvlKeyword("ENCODING_TYPE_VERSION_NAME", "ISO/IEC15444-1:2004");
354 cmpObj += PvlKeyword("INTERCHANGE_FORMAT", "BINARY");
355 FileName infilename(InputCubes[0]->fileName());
356 cmpObj += PvlKeyword("UNCOMPRESSED_FILE_NAME", infilename.name());
357 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
358 if(p_pixelType == Isis::Real) {
359 QString msg = "JPEG2000 does not support floating point data.";
360 throw IException(IException::Programmer, msg, _FILEINFO_);
361 }
362 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
363 storagebytes = storagebytes * 2;
364 }
365 cmpObj += PvlKeyword("REQUIRED_STORAGE_BYTES", toString(storagebytes));
366 mainPvl.addObject(cmpObj);
367 PvlObject ucmpObj("UNCOMPRESSED_FILE");
368 ucmpObj += PvlKeyword("FILE_NAME", infilename.name());
369 ucmpObj += PvlKeyword("RECORD_TYPE", "FIXED_LENGTH");
370 int recordbytes = InputCubes[0]->sampleCount();
371 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
372 recordbytes = recordbytes * 2;
373 }
374 ucmpObj += PvlKeyword("RECORD_BYTES", toString(recordbytes));
375 ucmpObj += PvlKeyword("FILE_RECORDS", toString(InputCubes[0]->lineCount()));
376 ucmpObj += PvlKeyword("^IMAGE", infilename.name());
377 mainPvl.addObject(ucmpObj);
378 }
379
380
391 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImage.typ");
392 // Build up an IMAGE object:
393 // Auto translate standard keywords for the IMAGE object
394 Pvl *inputLabel = InputCubes[0]->label();
395 FileName transfile;
396 transfile = "$ISISROOT/appdata/translations/pdsExportImageImage.trn";
397 PvlToPvlTranslationManager Xlator(*inputLabel, transfile.expanded());
398 Xlator.Auto(mainPvl);
399
400 // Calculate the core base/mult for this cube
401 double base = 0.0;
402 double multiplier = 1.0;
403 double x1, x2;
404
405 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
406 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
407
408 for(unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
409 minimum = std::min(minimum, p_inputMinimum[i]);
410 maximum = std::max(maximum, p_inputMaximum[i]);
411 }
412
413 x1 = p_outputMinimum;
414 x2 = p_outputMaximum;
415
416 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
417 multiplier = (maximum - minimum) / (x2 - x1);
418 base = minimum - multiplier * x1;
419 }
420 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
421 multiplier = (maximum - minimum) / (x2 - x1);
422 base = minimum - multiplier * x1;
423 }
424 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
425 multiplier = (maximum - minimum) / (x2 - x1);
426 base = minimum - multiplier * x1;
427 }
428
429 // Manually set the keyword for the number of bits in a pixel
430 // NOTE: this is dependent on settings in ProcessExport and not the cube
431 PvlObject &imgObj = mainPvl.findObject("IMAGE");
432
433 if(!m_forceBands) imgObj.deleteKeyword("BANDS");
434 if(!m_forceBandName && imgObj.hasKeyword("BAND_NAME")) imgObj.deleteKeyword("BAND_NAME");
435 if(!m_forceCenterFilterWavelength && imgObj.hasKeyword("CENTER_FILTER_WAVELENGTH")) imgObj.deleteKeyword("CENTER_FILTER_WAVELENGTH");
436 if(!m_forceBandwidth && imgObj.hasKeyword("BANDWIDTH")) imgObj.deleteKeyword("BANDWIDTH");
437
438 if(m_forceBandStorageType) imgObj += PvlKeyword("BAND_STORAGE_TYPE", "BAND_SEQUENTIAL");
439 if(m_forceOffset) imgObj += PvlKeyword("OFFSET", toString(base));
440 if(m_forceScalingFactor) imgObj += PvlKeyword("SCALING_FACTOR", toString(multiplier));
441
442 // Manually set the keyword for pixel type and special pixels
443 if(p_pixelType == Isis::UnsignedByte) {
444 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "8");
445 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xff));
446 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_UNSIGNED_INTEGER");
447 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
448 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
449 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
450 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
451 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
452 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel8.typ");
453 }
454 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
455 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
456 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
457 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_UNSIGNED_INTEGER");
458 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
459 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
460 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
461 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
462 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
463 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
464 }
465 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
466 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
467 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
468 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "LSB_UNSIGNED_INTEGER");
469 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
470 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
471 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
472 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
473 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
474 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
475 }
476 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
477 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
478 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
479 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_INTEGER");
480 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
481 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
482 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
483 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
484 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
485 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
486 }
487 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
488 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
489 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString((BigInt)0xffff));
490 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "LSB_INTEGER");
491 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
492 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
493 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
494 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
495 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
496 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
497 }
498 else if(p_pixelType == Isis::Real) {
499 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "32");
500 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString((BigInt)0xffffffff));
501
502 if(p_endianType == Isis::Msb) {
503 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "IEEE_REAL");
504 }
505 else {
506 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "PC_REAL");
507 }
508 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString(Isis::INULL4));
509 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString(Isis::ILOW_REPR_SAT4));
510 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString(Isis::ILOW_INSTR_SAT4));
511 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString(Isis::IHIGH_REPR_SAT4));
512 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString(Isis::IHIGH_INSTR_SAT4));
513 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel32.typ");
514 }
515 else {
516 QString msg = "Unsupported PDS pixel type or sample size";
517 throw IException(IException::User, msg, _FILEINFO_);
518 }
519 }
520
521
532 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImage.typ");
534 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
535 }
536 // Build up a JP2 IMAGE object:
537 // Auto translate standard keywords for the IMAGE object
538 Pvl *inputLabel = InputCubes[0]->label();
539 FileName transfile;
540 transfile = "$ISISROOT/appdata/translations/pdsExportImageJP2.trn";
541 PvlToPvlTranslationManager Xlator(*inputLabel, transfile.expanded());
542 Xlator.Auto(mainPvl);
543
544 // Calculate the core base/mult for this cube
545 double base = 0.0;
546 double multiplier = 1.0;
547 double x1, x2;
548
549 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
550 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
551
552 for(unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
553 minimum = std::min(minimum, p_inputMinimum[i]);
554 maximum = std::max(maximum, p_inputMaximum[i]);
555 }
556
557 x1 = p_outputMinimum;
558 x2 = p_outputMaximum;
559
560 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
561 multiplier = (maximum - minimum) / (x2 - x1);
562 base = minimum - multiplier * x1;
563 }
564 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
565 multiplier = (maximum - minimum) / (x2 - x1);
566 base = minimum - multiplier * x1;
567 }
568 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
569 multiplier = (maximum - minimum) / (x2 - x1);
570 base = minimum - multiplier * x1;
571 }
572
573 // Manually set the keyword for the number of bits in a pixel
574 // NOTE: this is dependent on settings in ProcessExport and not the cube
575 PvlObject &imgObj = mainPvl.findObject("UNCOMPRESSED_FILE").findObject("IMAGE");
576
577 if(!m_forceBands) imgObj.deleteKeyword("BANDS");
578 if(!m_forceBandName && imgObj.hasKeyword("BAND_NAME")) imgObj.deleteKeyword("BAND_NAME");
579 if(!m_forceCenterFilterWavelength && imgObj.hasKeyword("CENTER_FILTER_WAVELENGTH")) imgObj.deleteKeyword("CENTER_FILTER_WAVELENGTH");
580 if(!m_forceBandwidth && imgObj.hasKeyword("BANDWIDTH")) imgObj.deleteKeyword("BANDWIDTH");
581
582 if(m_forceBandStorageType) imgObj += PvlKeyword("BAND_STORAGE_TYPE", "BAND_SEQUENTIAL");
583 if(m_forceOffset) imgObj += PvlKeyword("OFFSET", toString(base));
584 if(m_forceScalingFactor) imgObj += PvlKeyword("SCALING_FACTOR", toString(multiplier));
585
586 // Manually set the keyword for pixel type and special pixels
587 if(p_pixelType == Isis::UnsignedByte) {
588 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "8");
589 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xff));
590 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_UNSIGNED_INTEGER");
591 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
592 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
593 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
594 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
595 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
596 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel8.typ");
597 }
598 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
599 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
600 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
601 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_UNSIGNED_INTEGER");
602 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
603 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
604 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
605 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
606 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
607 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
608 }
609 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
610 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
611 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
612 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "LSB_UNSIGNED_INTEGER");
613 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
614 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
615 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
616 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
617 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
618 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
619 }
620 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
621 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
622 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString(0xffff));
623 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "MSB_INTEGER");
624 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
625 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
626 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
627 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
628 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
629 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
630 }
631 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
632 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "16");
633 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString((BigInt)0xffff));
634 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "LSB_INTEGER");
635 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString((int)OutputNull()));
636 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString((int)OutputLrs()));
637 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString((int)OutputLis()));
638 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString((int)OutputHrs()));
639 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString((int)OutputHis()));
640 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel16.typ");
641 }
642 else if(p_pixelType == Isis::Real) {
643 if(m_forceSampleBits) imgObj += PvlKeyword("SAMPLE_BITS", "32");
644 if(m_forceSampleBitMask) imgObj += PvlKeyword("SAMPLE_BIT_MASK", toString((BigInt)0xffffffff));
645
646 if(p_endianType == Isis::Msb) {
647 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "IEEE_REAL");
648 }
649 else {
650 if(m_forceSampleType) imgObj += PvlKeyword("SAMPLE_TYPE", "PC_REAL");
651 }
652 if(m_forceCoreNull) imgObj += PvlKeyword("CORE_NULL", toString(Isis::INULL4));
653 if(m_forceCoreLrs) imgObj += PvlKeyword("CORE_LOW_REPR_SATURATION", toString(Isis::ILOW_REPR_SAT4));
654 if(m_forceCoreLis) imgObj += PvlKeyword("CORE_LOW_INSTR_SATURATION", toString(Isis::ILOW_INSTR_SAT4));
655 if(m_forceCoreHrs) imgObj += PvlKeyword("CORE_HIGH_REPR_SATURATION", toString(Isis::IHIGH_REPR_SAT4));
656 if(m_forceCoreHis) imgObj += PvlKeyword("CORE_HIGH_INSTR_SATURATION", toString(Isis::IHIGH_INSTR_SAT4));
657 mainPvl.format()->add("$ISISROOT/appdata/translations/pdsExportImageImagePixel32.typ");
658 }
659 else {
660 QString msg = "Unsupported PDS pixel type or sample size";
661 throw IException(IException::User, msg, _FILEINFO_);
662 }
663 }
664
665
675
676 // Get the input Isis cube label and find the Mapping group if it has one
677 Pvl *inputLabel = InputCubes[0]->label();
678 if(inputLabel->hasObject("IsisCube") &&
679 !(inputLabel->findObject("IsisCube").hasGroup("Mapping"))) return;
680 PvlGroup &inputMapping = inputLabel->findGroup("Mapping", Pvl::Traverse);
681
682 // Translate the projection specific keywords for a PDS IMAGE_MAP_PROJECTION
683 QString projName = ProjectionName(*inputLabel);
684 PvlToPvlTranslationManager xlatSpecProj(*inputLabel,
685 "$ISISROOT/appdata/translations/pdsExport" + projName + ".trn");
686 xlatSpecProj.Auto(outputPvl);
687
688 // Translate the target name
689 PvlToPvlTranslationManager xlatTarget(*inputLabel,
690 "$ISISROOT/appdata/translations/pdsExportTarget.trn");
691 xlatTarget.Auto(outputPvl);
692
693 // Add keywords to the PDS labels that could not be handled automatically
694 PvlObject &pdsMapObj = outputPvl.findObject("IMAGE_MAP_PROJECTION");
695
696 // Add the projection name
697// pdsMapObj += PvlKeyword ("MAP_PROJECTION_TYPE", projName.toUpper());
698
699 // Modify the radii to be km.
700 PvlKeyword &aRadius = pdsMapObj["A_AXIS_RADIUS"];
701 QString unit = aRadius.unit();
702 if( (unit.toUpper() == "METERS") || (unit == "") ) { //if no units, assume in meters
703 double dValue = (double)aRadius;
704 dValue /= 1000.0;
705 aRadius.setValue(toString(dValue), "KM");
706 }
707 PvlKeyword &bRadius = pdsMapObj["B_AXIS_RADIUS"];
708 unit = bRadius.unit();
709 if( (unit.toUpper() == "METERS") || (unit == "") ) {
710 double dValue = (double)bRadius;
711 dValue /= 1000.0;
712 bRadius.setValue(toString(dValue), "KM");
713 }
714 PvlKeyword &cRadius = pdsMapObj["C_AXIS_RADIUS"];
715 unit = cRadius.unit();
716 if( (unit.toUpper() == "METERS") || (unit == "") ) {
717 double dValue = (double)cRadius;
718 dValue /= 1000.0;
719 cRadius.setValue(toString(dValue), "KM");
720 }
721
722 // Modify the units on MAP_SCALE and MAP_RESOLUTION
723 PvlKeyword &mapScale = pdsMapObj["MAP_SCALE"];
724 unit = mapScale.unit();
725 //if no units, assume in meters/pixel
726 if( (unit.toUpper() == "METERS/PIX") || (unit.toUpper() == "METERS/PIXEL") || (unit == "") ) {
728 double dValue = (double)mapScale;
729 dValue /= 1000.0;
730 mapScale.setValue(toString(dValue), "KM/PIXEL");
731 }
732 else {
733 mapScale.setValue(toString((double)mapScale), "METERS/PIXEL");
734 }
735 }
736 PvlKeyword &mapRes = pdsMapObj["MAP_RESOLUTION"];
737 unit = mapRes.unit();
738 //if no units, asume in pixels/degree
739 if( (unit.toUpper() == "PIXELS/DEGREE") || (unit == "") ) {
740 mapRes.setValue((QString)mapRes, "PIX/DEG");
741 }
742
743 // Add the EASTERNMOST AND WESTERNMOST LONGITUDE keywords
744 PvlKeyword &isisLonDir = inputMapping.findKeyword("LongitudeDirection");
745 QString lonDir = isisLonDir[0];
746 lonDir = lonDir.toUpper();
747 if (inputMapping.hasKeyword("MaximumLongitude") && inputMapping.hasKeyword("MinimumLongitude")) {
748 double maxLon = inputMapping.findKeyword("MaximumLongitude");
749 double minLon = inputMapping.findKeyword("MinimumLongitude");
750 if(lonDir == "POSITIVEEAST") {
751 pdsMapObj += PvlKeyword("EASTERNMOST_LONGITUDE", toString(maxLon));
752 pdsMapObj += PvlKeyword("WESTERNMOST_LONGITUDE", toString(minLon));
753 }
754 else {
755 pdsMapObj += PvlKeyword("EASTERNMOST_LONGITUDE", toString(minLon));
756 pdsMapObj += PvlKeyword("WESTERNMOST_LONGITUDE", toString(maxLon));
757 }
758 }
759
760 // Add the LINE_PROJECTION_OFFSET and SAMPLE_PROJECTION_OFFSET keywords
761 // These keywords are the distance from the origin of the image to the
762 // origin of the projection. The units are line or samples. The image origin
763 // is the middle of pixel (1,1)
764 double lineOffset = inputMapping.findKeyword("UpperLeftCornerY");
765 lineOffset /= (double)inputMapping.findKeyword("PixelResolution");
766 lineOffset *= 1.0;
767 lineOffset -= 0.5; // Add half a line to get to the center of (1,1)
768 pdsMapObj += PvlKeyword("LINE_PROJECTION_OFFSET", toString(lineOffset), "PIXEL");
769 double sampleOffset = inputMapping.findKeyword("UpperLeftCornerX");
770 sampleOffset /= (double)inputMapping.findKeyword("PixelResolution");
771 sampleOffset *= -1.0;
772 sampleOffset -= 0.5; // Add half a sample to get to the center of (1,1)
773 pdsMapObj += PvlKeyword("SAMPLE_PROJECTION_OFFSET", toString(sampleOffset), "PIXEL");
774
775 // Add units to keywords already in the IMAGE_MAP_PROJECTION object as necessary
776 if(pdsMapObj.hasKeyword("CENTER_LATITUDE")) {
777 PvlKeyword &tempKey = pdsMapObj.findKeyword("CENTER_LATITUDE");
778 tempKey.setValue(tempKey[0], "DEG");
779 }
780 if(pdsMapObj.hasKeyword("CENTER_LONGITUDE")) {
781 PvlKeyword &tempKey = pdsMapObj.findKeyword("CENTER_LONGITUDE");
782 tempKey.setValue(tempKey[0], "DEG");
783 }
784// if (pdsMapObj.hasKeyword("REFERENCE_LATITUDE")) {
785// PvlKeyword &tempKey = pdsMapObj.findKeyword("REFERENCE_LATITUDE");
786// tempKey.setValue(tempKey[0], "DEG");
787// }
788 if(pdsMapObj.hasKeyword("REFERENCE_LONGITUDE")) {
789 PvlKeyword &tempKey = pdsMapObj.findKeyword("REFERENCE_LONGITUDE");
790 tempKey.setValue(tempKey[0], "DEG");
791 }
792 if(pdsMapObj.hasKeyword("MAXIMUM_LATITUDE")) {
793 PvlKeyword &tempKey = pdsMapObj.findKeyword("MAXIMUM_LATITUDE");
794 tempKey.setValue(tempKey[0], "DEG");
795 }
796 if(pdsMapObj.hasKeyword("MINIMUM_LATITUDE")) {
797 PvlKeyword &tempKey = pdsMapObj.findKeyword("MINIMUM_LATITUDE");
798 tempKey.setValue(tempKey[0], "DEG");
799 }
800 if(pdsMapObj.hasKeyword("EASTERNMOST_LONGITUDE")) {
801 PvlKeyword &tempKey = pdsMapObj.findKeyword("EASTERNMOST_LONGITUDE");
802 tempKey.setValue(tempKey[0], "DEG");
803 }
804 if(pdsMapObj.hasKeyword("WESTERNMOST_LONGITUDE")) {
805 PvlKeyword &tempKey = pdsMapObj.findKeyword("WESTERNMOST_LONGITUDE");
806 tempKey.setValue(tempKey[0], "DEG");
807 }
808 if(pdsMapObj.hasKeyword("MAP_PROJECTION_ROTATION")) {
809 PvlKeyword &tempKey = pdsMapObj.findKeyword("MAP_PROJECTION_ROTATION");
810 tempKey.setValue(tempKey[0], "DEG");
811 }
812
813 }
814
815
824 Projection *proj = ProjectionFactory::Create(inputLabel);
825 QString name = proj->Name();
826 delete proj;
827 return name;
828 }
829
830
838 Cube *cube = InputCubes[0];
839 int a = SizeOf(p_pixelType);
840 int b = cube->sampleCount();
841 return b * a ;
842 }
843
844
851 ostringstream temp;
852 if(m_label->format() != NULL) {
853 temp << *m_label << m_label->format()->formatEOL();
854 }
855 else {
856 temp << *m_label << endl;
857 }
858 return temp.tellp();
859 }
860
867 if(!m_detachedLabel) {
868 QString msg = "Unable to output detached label. Use "
869 "ProcessExportPds::SetDetached() to set the "
870 "output PDS label file name.";
871 throw IException(IException::Unknown, msg, _FILEINFO_);
872 }
873 std::ofstream sOutLabelStream(m_detachedPdsLabelFile.toLatin1().data());
874 OutputLabel(sOutLabelStream);
875 sOutLabelStream.close();
876 }
877
885 void ProcessExportPds::OutputLabel(std::ofstream &os) {
886 int labSize = LabelSize(); // labSize will be the old label size with "?"
887 // NOTE: WARNING: If anything changes in the next two lines, you must also changes the
888 // corresponding lines in the StandardImageRoot member
889
890 if(m_exportType == Stream) {
892 (*m_label)["LABEL_RECORDS"].setValue(toString(labSize), "BYTES");
893 if(!m_detachedLabel) {
894 (*m_label)["^IMAGE"].setValue(toString(labSize + 1), "BYTES");
895 }
896 }
897 if(m_label->format() != NULL) {
898 os << *m_label << m_label->format()->formatEOL();
899 }
900 else {
901 os << *m_label << endl;
902 }
903 // Fill the difference between the old and new label size with spaces.
905 for(int i = LabelSize(); i < labSize; ++i) os << ' ';
906 }
907 }
908 else if(m_exportType == Fixed) {
909 int lineBytes;
910 int labelRecords;
912 lineBytes = LineBytes();
913 (*m_label)["RECORD_BYTES"].setValue(toString(lineBytes));
914
915 // The number of label records is dependent on the number of label bytes
916 // and the lint bytes
917 labelRecords = (int)ceil((double)labSize / (double)lineBytes);
918 if(m_label->hasKeyword("LABEL_RECORDS")) { //LRO MRF doesn't have this keyword
919 (*m_label)["LABEL_RECORDS"].setValue(toString(labelRecords));
920 }
921 int totalTableRecords = 0;
922 for (unsigned int i = 0; i < m_tableRecords.size(); i++) {
923 totalTableRecords += m_tableRecords[i];
924 }
925 int imageRecords = InputCubes[0]->lineCount()
926 * InputCubes[0]->bandCount();
927 int fileRecords = labelRecords + imageRecords + totalTableRecords;
928 (*m_label)["FILE_RECORDS"].setValue(toString(fileRecords));
929
930 if(!m_detachedLabel) {
931 (*m_label)["^IMAGE"].setValue(toString(labelRecords + 1));
932 }
933 }
934 if(m_label->format() != NULL) {
935 os << *m_label << m_label->format()->formatEOL();
936 }
937 else {
938 os << *m_label << endl;
939 }
941 for(int i = LabelSize(); i < labelRecords * lineBytes; ++i) os << ' ';
942 }
943 }
944
945 }
946
947
953 void ProcessExportPds::updateChecksumInLabel(std::ofstream &pdsFileStream) {
954 // This occurs after application has called its StartProcess and the checksum has been
955 // generated. We need to seek to the top of the file to rewrite the label. Since the
956 // CHECKSUM is MD5, we set aside 32 characters for the value of this keyword. Since
957 // OuputLabel() has already created the label and necessary padding, we can simply update
958 // the CHECKSUM value to the generated checksum and re-write the entire label.
959 pdsFileStream.seekp(0);
960 (*m_label)["CHECKSUM"].setValue(checksum());
961 pdsFileStream << *m_label;
962 }
963
964
996 void ProcessExportPds::ExportTable(Table isisTable, QString detachedPdsTableFileName) {
997
998 if(Attached() && detachedPdsTableFileName != "") {
999 QString msg = "The output PDS file has been set to attached and a "
1000 "detached PDS table file name has been given. If detached "
1001 "is preferred, set the process to detached SetDetached() "
1002 "and call StandardPdsLabel() before calling ExportTable().";
1003 throw IException(IException::Unknown, msg, _FILEINFO_);
1004 }
1005
1006 if(Detached() && detachedPdsTableFileName == "") {
1007 QString msg = "The output PDS file has been set to detached. A file name "
1008 "for the detached ouput PDS table file is required. "
1009 "If an attached output file is prefered, use the method "
1010 "ProcessExportPds::SetAttached() before calling ExportTable().";
1011 throw IException(IException::Unknown, msg, _FILEINFO_);
1012 }
1013
1014 // create an ExportPdsTable to fill file stream with PDS Table info
1015 ExportPdsTable pdsTable(isisTable);
1016 int fileRecordBytes = LineBytes();
1017 // return metadata pvl containing needed information for the output label.
1018
1019 char *tableBuffer = new char[isisTable.Records() * fileRecordBytes];
1020 PvlObject metadata = pdsTable.exportTable(tableBuffer,
1021 fileRecordBytes,
1022 ByteOrderName(p_endianType));
1023 QString pdsTableName = pdsTable.formatPdsTableName();
1024 Pvl &mainPvl = *m_label;
1025 if (Attached()) {
1026 m_tableBuffers.push_back(tableBuffer);
1027 int labSize = LabelSize(); // labSize will be the old label size with "?"
1028 int labelRecords = (int)ceil((double)labSize / (double)fileRecordBytes);
1029 int imageRecords = InputCubes[0]->lineCount()
1030 * InputCubes[0]->bandCount();
1031 int totalTableRecords = 0;
1032 for (unsigned int i = 0; i < m_tableRecords.size(); i++) {
1033 totalTableRecords += m_tableRecords[i];
1034 }
1035 // for start record values, indexing begins with 1
1036 int tableStartRecord = 1 + labelRecords + imageRecords + totalTableRecords;
1037 mainPvl += PvlKeyword("^" + pdsTableName, toString(tableStartRecord));
1038 }
1039 else {
1040 mainPvl += PvlKeyword("^" + pdsTableName, detachedPdsTableFileName);
1042 QString tableFileWithPath = labelFile.path() + "/"
1043 + detachedPdsTableFileName;
1044 ofstream os(tableFileWithPath.toLatin1().data());
1045 os.write(tableBuffer, isisTable.Records() * fileRecordBytes);
1046 os.close();
1047 }
1048 mainPvl.addObject(metadata);
1049 m_tableRecords.push_back(isisTable.Records());
1050 return;
1051 }
1052
1061 void ProcessExportPds::SetDetached(QString detachedLabelFile) {
1062 m_detachedLabel = true;
1063 m_detachedPdsLabelFile = detachedLabelFile;
1064 return;
1065 }
1066
1076
1083 return m_detachedLabel;
1084 }
1085
1092 return !m_detachedLabel;
1093 }
1094
1102 m_exportResolution = resolutionUnits;
1103 }
1104
1113 m_exportType = recordFormat;
1114 }
1115
1125 m_forceBands = force;
1126 }
1127
1138 m_forceBandName = force;
1139 }
1140
1153
1164 m_forceBandwidth = force;
1165 }
1166
1179
1190 m_forceOffset = force;
1191 }
1192
1203 m_forceScalingFactor = force;
1204 }
1205
1216 m_forceSampleBits = force;
1217 }
1218
1229 m_forceSampleBitMask = force;
1230 }
1231
1242 m_forceSampleType = force;
1243 }
1244
1255 m_forceCoreNull = force;
1256 }
1257
1268 m_forceCoreLrs = force;
1269 }
1270
1282 m_forceCoreLis = force;
1283 }
1284
1296 m_forceCoreHrs = force;
1297 }
1298
1310 m_forceCoreHis = force;
1311 }
1312
1320 void ProcessExportPds::StartProcess(std::ofstream &fout) {
1322 if (!m_detachedLabel) {
1323 for (unsigned int i = 0; i < m_tableBuffers.size(); i++) {
1324 if (m_tableBuffers[i] == NULL) {
1325 QString msg = "Unable to add tables to PDS output file.";
1326 throw IException(IException::Unknown, msg, _FILEINFO_);
1327 }
1328 // write each table buffer to fout.
1329 // For each table, use (number of records)*(bytes per record) to
1330 // determine how many bytes to write out.
1331 fout.write(m_tableBuffers[i], m_tableRecords[i]*LineBytes());
1332 }
1333 }
1334 return;
1335 }
1336
1337} // End of Isis namespace
IO Handler for Isis Cubes.
Definition Cube.h:168
int sampleCount() const
Definition Cube.cpp:1813
Export a PDS table from an ISIS Table.
File name manipulation and expansion.
Definition FileName.h:100
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
double OutputNull()
Return the output special pixel value for NULL.
double OutputHis()
Return the output special pixel value for HIS.
double OutputLrs()
Return the output special pixel value for LRS.
QString checksum()
@description Generates a file checksum.
double OutputLis()
Return the output special pixel value for LIS.
double p_outputMinimum
Desired minimum pixel value in the Buffer.
double p_outputMaximum
Desired maximum pixel value in the Buffer.
double OutputHrs()
Return the output special pixel value for HRS.
std::vector< double > p_inputMaximum
Maximum pixel value in the input cube to be mapped to the maximum value in the Buffer.
virtual void StartProcess(void funct(Isis::Buffer &in))
This method invokes the process operation over a single input cube.
bool canGenerateChecksum()
@description Return if we can generate a checksum
@ JP2
Compressed JPEG2000.
PixelType p_pixelType
The bits per pixel of the output image.
ByteOrder p_endianType
The byte order of the output file.
void setFormat(ExportFormat format)
Sets the storage order of the output file.
std::vector< double > p_inputMinimum
Minimum pixel value in the input cube to be mapped to the minimum value in the Buffer.
void SetAttached()
Mutator method to set the output PDS file to attached.
bool m_forceOffset
Indicates whether to add the OFFSET keyword in the PDS labels.
void ForceCoreHrs(bool force)
Mutator method to set how the CORE_HIGH_REPR_SATURATION keyword will be handled.
bool m_detachedLabel
Indicates whether the PDS file will be detached.
PdsExportType m_exportType
Stream or Fixed.
void StandardAllMapping(Pvl &mainPvl)
Create the standard keywords for the IMAGE_MAP_PROJECTION group in a PDS label.
void FixedImageRoot(Pvl &mainPvl)
Create the fixed keywords for the ROOT object in a PDS IMAGE file.
void StreamJP2ImageRoot(Pvl &mainPvl)
Create the standard keywords for the ROOT object in a PDS JP2 IMAGE file.
void StartProcess(std::ofstream &fout)
This method fills the image data of the PDS file using the parent class ProcessExport::StartProcess,...
void ForceSampleBits(bool force)
Mutator method to set how the SAMPLE_BITS keyword will be handled.
ProcessExportPds()
Default Constructor - Set to default the data members.
bool Detached()
Accessor function returns true if the output PDS file is set to detached.
void SetDetached(QString detachedLabelFile)
Mutator method to set the output PDS file to detached.
std::vector< char * > m_tableBuffers
Vector containing the binary table data for each of the added tables.
void updateChecksumInLabel(std::ofstream &pdsFileStream)
Updates the CHECKSUM value on the label and rewrites to the output file.
void OutputDetachedLabel()
Write the PDS label to the a detached file.
void ForceScalingFactor(bool force)
Mutator method to set how the SCALING_FACTOR keyword will be handled.
PvlFormatPds * m_formatter
Used to determine how to format the keyword values in the PDS file.
virtual void CreateImageLabel()
Create a standard PDS label for type IMAGE.
bool m_forceBands
Indicates whether to keep the BANDS keyword in the PDS labels.
bool m_forceCoreHrs
Indicates whether to add the CORE_HIGH_REPR_SATURATION keyword in the PDS labels.
int LineBytes()
Return the line bytes (record size) for the input cube, at present this is based on the number of sam...
void StreamImageRoot(Pvl &mainPvl)
Create the standard keywords for the ROOT object in a PDS IMAGE file.
void CreateSpectralQubeLabel()
Create a standard PDS label for type SPECTRAL_QUBE.
void SetPdsResolution(PdsResolution resolutionUnits)
Mutator method to set the output PDS image resolution to meters per pixel or kilometers per pixel.
void CreateQubeLabel()
Create a standard PDS label for type QUBE.
void ExportTable(Isis::Table isisTable, QString detachedPdsTableFileName="")
This method will add a table to be exported to PDS.
void ForceCoreNull(bool force)
Mutator method to set how the CORE_NULL keyword will be handled.
void ForceCoreLrs(bool force)
Mutator method to set how the CORE_LOW_REPR_SATURATION keyword will be handled.
bool m_forceBandName
Indicates whether to keep the BAND_NAME keyword in the PDS labels.
std::vector< int > m_tableRecords
Number of records in each added table.
bool m_forceCenterFilterWavelength
Indicates whether to keep the CENTER_FILTER_WAVELENGTH keyword in the PDS labels.
QString ProjectionName(Pvl &inputLabel)
Return a projection name.
void ForceBandwidth(bool force)
Mutator method to set how the BANDWIDTH keyword will be handled.
bool m_forceSampleBitMask
Indicates whether to add the SAMPLE_BIT_MASK keyword in the PDS labels.
void ForceSampleType(bool force)
Mutator method to set how the SAMPLE_TYPE keyword will be handled.
void ForceCoreLis(bool force)
Mutator method to set how the CORE_LOW_INSTR_SATURATION keyword will be handled.
QString m_detachedPdsLabelFile
The name of the detached PDS label file.
PdsFileType m_pdsFileType
Image, Qube, Spectral Qube, or JP2 Image.
PdsResolution m_exportResolution
Meters or kilometers.
bool m_forceSampleBits
Indicates whether to add the SAMPLE_BITS keyword in the PDS labels.
int LabelSize()
Return the size of the output PDS label.
void ForceBandName(bool force)
Mutator method to set how the BAND_NAME keyword will be handled.
void StandardJP2Image(Pvl &mainPvl)
Create the standard keywords for an IMAGE object in a PDS JP2 IMAGE file.
void SetExportType(PdsExportType recordFormat)
Mutator method to set the output PDS image record type to stream or fixed.
void ForceSampleBitMask(bool force)
Mutator method to set how the SAMPLE_BIT_MASK keyword will be handled.
virtual Pvl & StandardPdsLabel(ProcessExportPds::PdsFileType type)
Create a standard PDS label of the type specified.
bool m_forceCoreLis
Indicates whether to add the CORE_LOW_INSTR_SATURATION keyword in the PDS labels.
void StandardImageImage(Pvl &mainPvl)
Create the standard keywords for an IMAGE object in a PDS IMAGE file.
bool m_forceCoreHis
Indicates whether to add the CORE_HIGH_INSTR_SATURATION keyword in the PDS labels.
void FixedJP2ImageRoot(Pvl &mainPvl)
Create the fixed keywords for the ROOT object in a PDS JP2 IMAGE file.
void OutputLabel(std::ofstream &pdsFileStream)
Write the PDS label to the supplied stream.
PdsResolution
Resolution units per pixel of the exported PDS file.
@ Meter
Meters per pixel.
@ Kilometer
Kilometers per pixel.
PdsExportType
Record format type of exported PDS file.
@ Stream
Stream Records. This type is generally used for ASCII files.
@ Fixed
Fixed length records.
void ForceBandStorageType(bool force)
Mutator method to set how the BAND_STORAGE_TYPE keyword will be handled.
void ForceBands(bool force)
Mutator method to set how the the BANDS keyword will be handled.
bool m_forceBandwidth
Indicates whether to keep the BANDWIDTH keyword in the PDS labels.
bool m_forceSampleType
Indicates whether to add the SAMPLE_TYPE keyword in the PDS labels.
PdsFileType
File type to be exported.
@ Image
Two dimensional array of line/sample values.
@ JP2Image
Image coding system JPEG 2000 formatted image.
bool m_forceScalingFactor
Indicates whether to add the SCALING_FACTOR keyword in the PDS labels.
void ForceCoreHis(bool force)
Mutator method to set how the CORE_HIGH_INSTR_SATURATION keyword will be handled.
void ForceOffset(bool force)
Mutator method to set how the OFFSET keyword will be handled.
Pvl * m_label
Exported PDS label.
void ForceCenterFilterWavelength(bool force)
Mutator method to set how the CENTER_FILTER_WAVELENGTH keyword will be handled.
bool m_forceCoreNull
Indicates whether to add the CORE_NULL keyword in the PDS labels.
bool m_forceCoreLrs
Indicates whether to add the CORE_LOW_REPR_SATURATION keyword in the PDS labels.
bool m_forceBandStorageType
Indicates whether to add the BAND_STORAGE_TYPE keyword in the PDS labels.
bool Attached()
Accessor function returns true if the output PDS file is set to attached.
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
Definition Process.h:185
static Isis::Projection * Create(Isis::Pvl &label, bool allowDefaults=false)
This method returns a pointer to a Projection object.
Base class for Map Projections.
Definition Projection.h:155
Formats the value of a PvlKeyword into a PDS complient string.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
void setTerminator(const QString &term)
Sets the terminator used to signify the end of the PVL informationDefaults to "END".
Definition Pvl.h:144
A single keyword-value pair.
Definition PvlKeyword.h:87
QString unit(const int index=0) const
Returns the units of measurement of the element of the array of values for the object at the specifie...
void setValue(QString value, QString unit="")
Sets new values.
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
bool hasKeyword(const QString &kname, FindOptions opts) const
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition PvlObject.h:276
@ Traverse
Search child objects.
Definition PvlObject.h:158
Allows applications to translate simple text files.
Class for storing Table blobs information.
Definition Table.h:61
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType.
Definition PixelType.h:46
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
long long int BigInt
Big int.
Definition Constants.h:49
Namespace for the standard library.