7 #include "ProcessExportPds.h"
14 #include "ExportPdsTable.h"
16 #include "IException.h"
18 #include "PixelType.h"
19 #include "Projection.h"
20 #include "ProjectionFactory.h"
22 #include "PvlFormat.h"
23 #include "PvlToPvlTranslationManager.h"
24 #include "PvlFormatPds.h"
25 #include "SpecialPixel.h"
36 ProcessExportPds::ProcessExportPds() {
39 m_exportType = Stream;
40 m_exportResolution = Meter;
43 m_forceBandName =
true;
44 m_forceCenterFilterWavelength =
true;
45 m_forceBandwidth =
true;
46 m_forceBandStorageType =
true;
48 m_forceScalingFactor =
true;
49 m_forceSampleBits =
true;
50 m_forceSampleBitMask =
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;
59 m_pdsFileType =
Image;
60 m_tableRecords.clear();
61 m_tableBuffers.clear();
68 ProcessExportPds::~ProcessExportPds() {
71 for (
unsigned int i = 0; i < m_tableBuffers.size(); i++) {
72 delete [] m_tableBuffers[i];
73 m_tableBuffers[i] = NULL;
75 m_tableBuffers.clear();
96 if(m_pdsFileType == ProcessExportPds::JP2Image) {
100 m_formatter =
new PvlFormatPds(
"$ISISROOT/appdata/translations/pdsExportRootGen.typ");
101 m_label->setFormat(m_formatter);
102 m_label->setTerminator(
"END");
104 if(type == ProcessExportPds::Image || type == ProcessExportPds::JP2Image) {
108 QString msg =
"Unsupported PDS output type";
109 throw IException(IException::User, msg, _FILEINFO_);
119 void ProcessExportPds::CreateImageLabel() {
121 Pvl &mainPvl = *m_label;
123 if(m_exportType == Stream) {
124 if(m_pdsFileType == ProcessExportPds::Image) {
125 StreamImageRoot(mainPvl);
127 else if(m_pdsFileType == ProcessExportPds::JP2Image) {
128 StreamJP2ImageRoot(mainPvl);
131 else if(m_exportType == Fixed) {
132 if(m_pdsFileType == ProcessExportPds::Image) {
133 FixedImageRoot(mainPvl);
135 else if(m_pdsFileType == ProcessExportPds::JP2Image) {
136 FixedJP2ImageRoot(mainPvl);
140 QString msg =
"Invalid PDS export type.";
141 throw IException(IException::Programmer, msg, _FILEINFO_);
144 if(m_pdsFileType == ProcessExportPds::JP2Image) {
145 StandardJP2Image(mainPvl);
148 StandardImageImage(mainPvl);
153 StandardAllMapping(mainPvl);
154 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportAllMapping.typ");
161 void ProcessExportPds::CreateQubeLabel() {
162 Pvl &mainPvl = *m_label;
172 StandardAllMapping(mapTmp);
173 if(mapTmp.
hasObject(
"IMAGE_MAP_PROJECTION")) {
182 void ProcessExportPds::CreateSpectralQubeLabel() {
183 Pvl &mainPvl = *m_label;
193 StandardAllMapping(mapTmp);
194 if(mapTmp.
hasObject(
"IMAGE_MAP_PROJECTION")) {
205 void ProcessExportPds::StreamImageRoot(
Pvl &mainPvl) {
207 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
208 mainPvl +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
211 mainPvl +=
PvlKeyword(
"LABEL_RECORDS",
"???????",
"BYTES");
212 if(m_detachedLabel) {
213 QString sImageFile = m_detachedPdsLabelFile;
214 int iFound = sImageFile.indexOf(
".lbl");
216 sImageFile.replace(iFound, 4,
".img");
219 sImageFile +=
".img";
225 mainPvl +=
PvlKeyword(
"^IMAGE",
"???????",
"BYTES");
228 if (canGenerateChecksum()) {
229 mainPvl +=
PvlKeyword(
"CHECKSUM",
"????????????????????????????????");
239 void ProcessExportPds::StreamJP2ImageRoot(
Pvl &mainPvl) {
240 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
242 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
243 QString sImageFile = m_detachedPdsLabelFile;
244 if(m_detachedLabel) {
245 int iFound = sImageFile.indexOf(
".lbl");
247 sImageFile.replace(iFound, 4,
".jp2");
250 sImageFile +=
".jp2";
254 QString msg =
"Labels must be detached for JP2 files.";
255 throw IException(IException::Programmer, msg, _FILEINFO_);
260 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
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_);
271 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
272 storagebytes = storagebytes * 2;
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;
295 void ProcessExportPds::FixedImageRoot(
Pvl &mainPvl) {
297 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
298 mainPvl +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
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");
308 sImageFile.replace(iFound, 4,
".img");
311 sImageFile +=
".img";
319 if (canGenerateChecksum()) {
320 mainPvl +=
PvlKeyword(
"CHECKSUM",
"????????????????????????????????");
330 void ProcessExportPds::FixedJP2ImageRoot(
Pvl &mainPvl) {
331 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
333 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
334 QString sImageFile = m_detachedPdsLabelFile;
335 if(m_detachedLabel) {
336 int iFound = sImageFile.indexOf(
".lbl");
338 sImageFile.replace(iFound, 4,
".jp2");
341 sImageFile +=
".jp2";
345 QString msg =
"Labels must be detached for JP2 files.";
346 throw IException(IException::Programmer, msg, _FILEINFO_);
351 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
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_);
362 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
363 storagebytes = storagebytes * 2;
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;
390 void ProcessExportPds::StandardImageImage(
Pvl &mainPvl) {
391 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportImageImage.typ");
394 Pvl *inputLabel = InputCubes[0]->label();
396 transfile =
"$ISISROOT/appdata/translations/pdsExportImageImage.trn";
398 Xlator.
Auto(mainPvl);
402 double multiplier = 1.0;
405 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
406 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
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]);
413 x1 = p_outputMinimum;
414 x2 = p_outputMaximum;
416 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
417 multiplier = (maximum - minimum) / (x2 - x1);
418 base = minimum - multiplier * x1;
420 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
421 multiplier = (maximum - minimum) / (x2 - x1);
422 base = minimum - multiplier * x1;
424 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
425 multiplier = (maximum - minimum) / (x2 - x1);
426 base = minimum - multiplier * x1;
435 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
438 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
440 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
443 if(p_pixelType == Isis::UnsignedByte) {
444 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
446 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
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");
454 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
455 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
457 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
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");
465 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
466 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
468 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
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");
476 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
477 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
479 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
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");
487 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
488 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
490 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
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");
498 else if(p_pixelType == Isis::Real) {
499 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
502 if(p_endianType == Isis::Msb) {
503 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
506 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
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");
516 QString msg =
"Unsupported PDS pixel type or sample size";
517 throw IException(IException::User, msg, _FILEINFO_);
531 void ProcessExportPds::StandardJP2Image(
Pvl &mainPvl) {
532 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportImageImage.typ");
533 if(m_pdsFileType == ProcessExportPds::JP2Image) {
534 mainPvl.format()->add(
"$ISISROOT/appdata/translations/pdsExportImageJP2.typ");
538 Pvl *inputLabel = InputCubes[0]->label();
540 transfile =
"$ISISROOT/appdata/translations/pdsExportImageJP2.trn";
542 Xlator.
Auto(mainPvl);
546 double multiplier = 1.0;
549 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
550 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
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]);
557 x1 = p_outputMinimum;
558 x2 = p_outputMaximum;
560 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
561 multiplier = (maximum - minimum) / (x2 - x1);
562 base = minimum - multiplier * x1;
564 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
565 multiplier = (maximum - minimum) / (x2 - x1);
566 base = minimum - multiplier * x1;
568 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
569 multiplier = (maximum - minimum) / (x2 - x1);
570 base = minimum - multiplier * x1;
579 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
582 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
584 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
587 if(p_pixelType == Isis::UnsignedByte) {
588 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
590 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
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");
598 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
599 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
601 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
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");
609 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
610 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
612 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
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");
620 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
621 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
623 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
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");
631 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
632 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
634 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
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");
642 else if(p_pixelType == Isis::Real) {
643 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
646 if(p_endianType == Isis::Msb) {
647 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
650 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
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");
660 QString msg =
"Unsupported PDS pixel type or sample size";
661 throw IException(IException::User, msg, _FILEINFO_);
674 void ProcessExportPds::StandardAllMapping(
Pvl &outputPvl) {
677 Pvl *inputLabel = InputCubes[0]->label();
679 !(inputLabel->
findObject(
"IsisCube").hasGroup(
"Mapping")))
return;
683 QString projName = ProjectionName(*inputLabel);
685 "$ISISROOT/appdata/translations/pdsExport" + projName +
".trn");
686 xlatSpecProj.
Auto(outputPvl);
690 "$ISISROOT/appdata/translations/pdsExportTarget.trn");
691 xlatTarget.
Auto(outputPvl);
700 PvlKeyword &aRadius = pdsMapObj[
"A_AXIS_RADIUS"];
701 QString unit = aRadius.
unit();
702 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
703 double dValue = (double)aRadius;
707 PvlKeyword &bRadius = pdsMapObj[
"B_AXIS_RADIUS"];
708 unit = bRadius.
unit();
709 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
710 double dValue = (double)bRadius;
714 PvlKeyword &cRadius = pdsMapObj[
"C_AXIS_RADIUS"];
715 unit = cRadius.
unit();
716 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
717 double dValue = (double)cRadius;
723 PvlKeyword &mapScale = pdsMapObj[
"MAP_SCALE"];
724 unit = mapScale.
unit();
726 if( (unit.toUpper() ==
"METERS/PIX") || (unit.toUpper() ==
"METERS/PIXEL") || (unit ==
"") ) {
727 if(m_exportResolution == Kilometer) {
728 double dValue = (double)mapScale;
736 PvlKeyword &mapRes = pdsMapObj[
"MAP_RESOLUTION"];
737 unit = mapRes.
unit();
739 if( (unit.toUpper() ==
"PIXELS/DEGREE") || (unit ==
"") ) {
740 mapRes.
setValue((QString)mapRes,
"PIX/DEG");
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") {
764 double lineOffset = inputMapping.
findKeyword(
"UpperLeftCornerY");
765 lineOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
769 double sampleOffset = inputMapping.
findKeyword(
"UpperLeftCornerX");
770 sampleOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
771 sampleOffset *= -1.0;
778 tempKey.
setValue(tempKey[0],
"DEG");
780 if(pdsMapObj.
hasKeyword(
"CENTER_LONGITUDE")) {
782 tempKey.
setValue(tempKey[0],
"DEG");
788 if(pdsMapObj.
hasKeyword(
"REFERENCE_LONGITUDE")) {
790 tempKey.
setValue(tempKey[0],
"DEG");
792 if(pdsMapObj.
hasKeyword(
"MAXIMUM_LATITUDE")) {
794 tempKey.
setValue(tempKey[0],
"DEG");
796 if(pdsMapObj.
hasKeyword(
"MINIMUM_LATITUDE")) {
798 tempKey.
setValue(tempKey[0],
"DEG");
800 if(pdsMapObj.
hasKeyword(
"EASTERNMOST_LONGITUDE")) {
802 tempKey.
setValue(tempKey[0],
"DEG");
804 if(pdsMapObj.
hasKeyword(
"WESTERNMOST_LONGITUDE")) {
806 tempKey.
setValue(tempKey[0],
"DEG");
808 if(pdsMapObj.
hasKeyword(
"MAP_PROJECTION_ROTATION")) {
810 tempKey.
setValue(tempKey[0],
"DEG");
823 QString ProcessExportPds::ProjectionName(
Pvl &inputLabel) {
824 Projection *proj = ProjectionFactory::Create(inputLabel);
825 QString name = proj->
Name();
837 int ProcessExportPds::LineBytes() {
838 Cube *cube = InputCubes[0];
839 int a =
SizeOf(p_pixelType);
850 int ProcessExportPds::LabelSize() {
852 if(m_label->format() != NULL) {
853 temp << *m_label << m_label->format()->formatEOL();
856 temp << *m_label << endl;
866 void ProcessExportPds::OutputDetachedLabel() {
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_);
873 std::ofstream sOutLabelStream(m_detachedPdsLabelFile.toLatin1().data());
874 OutputLabel(sOutLabelStream);
875 sOutLabelStream.close();
885 void ProcessExportPds::OutputLabel(std::ofstream &os) {
886 int labSize = LabelSize();
890 if(m_exportType == Stream) {
891 if(m_pdsFileType != ProcessExportPds::JP2Image) {
892 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labSize),
"BYTES");
893 if(!m_detachedLabel) {
894 (*m_label)[
"^IMAGE"].setValue(
toString(labSize + 1),
"BYTES");
897 if(m_label->format() != NULL) {
898 os << *m_label << m_label->format()->formatEOL();
901 os << *m_label << endl;
904 if(m_pdsFileType != ProcessExportPds::JP2Image) {
905 for(
int i = LabelSize(); i < labSize; ++i) os <<
' ';
908 else if(m_exportType == Fixed) {
911 if(m_pdsFileType != ProcessExportPds::JP2Image) {
912 lineBytes = LineBytes();
913 (*m_label)[
"RECORD_BYTES"].setValue(
toString(lineBytes));
917 labelRecords = (int)ceil((
double)labSize / (double)lineBytes);
918 if(m_label->hasKeyword(
"LABEL_RECORDS")) {
919 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labelRecords));
921 int totalTableRecords = 0;
922 for (
unsigned int i = 0; i < m_tableRecords.size(); i++) {
923 totalTableRecords += m_tableRecords[i];
925 int imageRecords = InputCubes[0]->lineCount()
926 * InputCubes[0]->bandCount();
927 int fileRecords = labelRecords + imageRecords + totalTableRecords;
928 (*m_label)[
"FILE_RECORDS"].setValue(
toString(fileRecords));
930 if(!m_detachedLabel) {
931 (*m_label)[
"^IMAGE"].setValue(
toString(labelRecords + 1));
934 if(m_label->format() != NULL) {
935 os << *m_label << m_label->format()->formatEOL();
938 os << *m_label << endl;
940 if(m_pdsFileType != ProcessExportPds::JP2Image) {
941 for(
int i = LabelSize(); i < labelRecords * lineBytes; ++i) os <<
' ';
953 void ProcessExportPds::updateChecksumInLabel(std::ofstream &pdsFileStream) {
959 pdsFileStream.seekp(0);
960 (*m_label)[
"CHECKSUM"].setValue(checksum());
961 pdsFileStream << *m_label;
996 void ProcessExportPds::ExportTable(
Table isisTable, QString detachedPdsTableFileName) {
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_);
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_);
1016 int fileRecordBytes = LineBytes();
1019 char *tableBuffer =
new char[isisTable.
Records() * fileRecordBytes];
1022 ByteOrderName(p_endianType));
1024 Pvl &mainPvl = *m_label;
1026 m_tableBuffers.push_back(tableBuffer);
1027 int labSize = LabelSize();
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];
1036 int tableStartRecord = 1 + labelRecords + imageRecords + totalTableRecords;
1040 mainPvl +=
PvlKeyword(
"^" + pdsTableName, detachedPdsTableFileName);
1041 FileName labelFile(m_detachedPdsLabelFile);
1042 QString tableFileWithPath = labelFile.
path() +
"/"
1043 + detachedPdsTableFileName;
1044 ofstream os(tableFileWithPath.toLatin1().data());
1045 os.write(tableBuffer, isisTable.
Records() * fileRecordBytes);
1049 m_tableRecords.push_back(isisTable.
Records());
1061 void ProcessExportPds::SetDetached(QString detachedLabelFile) {
1062 m_detachedLabel =
true;
1063 m_detachedPdsLabelFile = detachedLabelFile;
1072 void ProcessExportPds::SetAttached() {
1073 m_detachedLabel =
false;
1074 m_detachedPdsLabelFile =
"";
1082 bool ProcessExportPds::Detached() {
1083 return m_detachedLabel;
1091 bool ProcessExportPds::Attached() {
1092 return !m_detachedLabel;
1102 m_exportResolution = resolutionUnits;
1113 m_exportType = recordFormat;
1124 void ProcessExportPds::ForceBands(
bool force) {
1125 m_forceBands = force;
1137 void ProcessExportPds::ForceBandName(
bool force) {
1138 m_forceBandName = force;
1150 void ProcessExportPds::ForceCenterFilterWavelength(
bool force) {
1151 m_forceCenterFilterWavelength = force;
1163 void ProcessExportPds::ForceBandwidth(
bool force) {
1164 m_forceBandwidth = force;
1176 void ProcessExportPds::ForceBandStorageType(
bool force) {
1177 m_forceBandStorageType = force;
1189 void ProcessExportPds::ForceOffset(
bool force) {
1190 m_forceOffset = force;
1202 void ProcessExportPds::ForceScalingFactor(
bool force) {
1203 m_forceScalingFactor = force;
1215 void ProcessExportPds::ForceSampleBits(
bool force) {
1216 m_forceSampleBits = force;
1228 void ProcessExportPds::ForceSampleBitMask(
bool force) {
1229 m_forceSampleBitMask = force;
1241 void ProcessExportPds::ForceSampleType(
bool force) {
1242 m_forceSampleType = force;
1254 void ProcessExportPds::ForceCoreNull(
bool force) {
1255 m_forceCoreNull = force;
1267 void ProcessExportPds::ForceCoreLrs(
bool force) {
1268 m_forceCoreLrs = force;
1281 void ProcessExportPds::ForceCoreLis(
bool force) {
1282 m_forceCoreLis = force;
1295 void ProcessExportPds::ForceCoreHrs(
bool force) {
1296 m_forceCoreHrs = force;
1309 void ProcessExportPds::ForceCoreHis(
bool force) {
1310 m_forceCoreHis = force;
1320 void ProcessExportPds::StartProcess(std::ofstream &fout) {
1321 ProcessExport::StartProcess(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_);
1331 fout.write(m_tableBuffers[i], m_tableRecords[i]*LineBytes());