19 #include "ProcessExportPds.h"
48 ProcessExportPds::ProcessExportPds() {
51 m_exportType = Stream;
52 m_exportResolution = Meter;
55 m_forceBandName =
true;
56 m_forceCenterFilterWavelength =
true;
57 m_forceBandwidth =
true;
58 m_forceBandStorageType =
true;
60 m_forceScalingFactor =
true;
61 m_forceSampleBits =
true;
62 m_forceSampleBitMask =
true;
63 m_forceSampleType =
true;
64 m_forceCoreNull =
true;
65 m_forceCoreLrs =
true;
66 m_forceCoreLis =
true;
67 m_forceCoreHrs =
true;
68 m_forceCoreHis =
true;
69 m_detachedLabel =
false;
71 m_pdsFileType =
Image;
72 m_tableRecords.clear();
73 m_tableBuffers.clear();
80 ProcessExportPds::~ProcessExportPds() {
83 for (
unsigned int i = 0; i < m_tableBuffers.size(); i++) {
84 delete [] m_tableBuffers[i];
85 m_tableBuffers[i] = NULL;
87 m_tableBuffers.clear();
107 m_pdsFileType = type;
108 if(m_pdsFileType == ProcessExportPds::JP2Image) {
112 m_formatter =
new PvlFormatPds(
"$base/translations/pdsExportRootGen.typ");
113 m_label->setFormat(m_formatter);
114 m_label->setTerminator(
"END");
116 if(type == ProcessExportPds::Image || type == ProcessExportPds::JP2Image) {
120 QString msg =
"Unsupported PDS output type";
131 void ProcessExportPds::CreateImageLabel() {
133 Pvl &mainPvl = *m_label;
135 if(m_exportType == Stream) {
136 if(m_pdsFileType == ProcessExportPds::Image) {
137 StreamImageRoot(mainPvl);
139 else if(m_pdsFileType == ProcessExportPds::JP2Image) {
140 StreamJP2ImageRoot(mainPvl);
143 else if(m_exportType == Fixed) {
144 if(m_pdsFileType == ProcessExportPds::Image) {
145 FixedImageRoot(mainPvl);
147 else if(m_pdsFileType == ProcessExportPds::JP2Image) {
148 FixedJP2ImageRoot(mainPvl);
152 QString msg =
"Invalid PDS export type";
156 if(m_pdsFileType == ProcessExportPds::JP2Image) {
157 StandardJP2Image(mainPvl);
160 StandardImageImage(mainPvl);
165 StandardAllMapping(mainPvl);
166 mainPvl.format()->add(
"$base/translations/pdsExportAllMapping.typ");
173 void ProcessExportPds::CreateQubeLabel() {
174 Pvl &mainPvl = *m_label;
184 StandardAllMapping(mapTmp);
185 if(mapTmp.
hasObject(
"IMAGE_MAP_PROJECTION")) {
194 void ProcessExportPds::CreateSpectralQubeLabel() {
195 Pvl &mainPvl = *m_label;
205 StandardAllMapping(mapTmp);
206 if(mapTmp.
hasObject(
"IMAGE_MAP_PROJECTION")) {
217 void ProcessExportPds::StreamImageRoot(
Pvl &mainPvl) {
219 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
220 mainPvl +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
223 mainPvl +=
PvlKeyword(
"LABEL_RECORDS",
"???????",
"BYTES");
224 if(m_detachedLabel) {
225 QString sImageFile = m_detachedPdsLabelFile;
226 int iFound = sImageFile.indexOf(
".lbl");
228 sImageFile.replace(iFound, 4,
".img");
231 sImageFile +=
".img";
234 mainPvl +=
PvlKeyword(
"^IMAGE", outFile.name());
237 mainPvl +=
PvlKeyword(
"^IMAGE",
"???????",
"BYTES");
247 void ProcessExportPds::StreamJP2ImageRoot(
Pvl &mainPvl) {
248 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
250 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
251 QString sImageFile = m_detachedPdsLabelFile;
252 if(m_detachedLabel) {
253 int iFound = sImageFile.indexOf(
".lbl");
255 sImageFile.replace(iFound, 4,
".jp2");
258 sImageFile +=
".jp2";
262 QString msg =
"Labels must be detached for JP2 files";
267 cmpObj +=
PvlKeyword(
"FILE_NAME", outFile.name());
268 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
270 cmpObj +=
PvlKeyword(
"ENCODING_TYPE_VERSION_NAME",
"ISO/IEC15444-1:2004");
271 cmpObj +=
PvlKeyword(
"INTERCHANGE_FORMAT",
"BINARY");
272 FileName infilename(InputCubes[0]->fileName());
273 cmpObj +=
PvlKeyword(
"UNCOMPRESSED_FILE_NAME", infilename.name());
274 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
275 if(p_pixelType == Isis::Real) {
276 QString msg =
"JPEG2000 does not support floating point data";
279 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
280 storagebytes = storagebytes * 2;
285 ucmpObj +=
PvlKeyword(
"FILE_NAME", infilename.name());
286 ucmpObj +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
287 int recordbytes = InputCubes[0]->sampleCount();
288 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
289 recordbytes = recordbytes * 2;
293 ucmpObj +=
PvlKeyword(
"^IMAGE", infilename.name());
303 void ProcessExportPds::FixedImageRoot(
Pvl &mainPvl) {
305 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
306 mainPvl +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
309 mainPvl +=
PvlKeyword(
"RECORD_BYTES",
"???????");
310 mainPvl +=
PvlKeyword(
"FILE_RECORDS",
"???????");
311 mainPvl +=
PvlKeyword(
"LABEL_RECORDS",
"????");
312 if(m_detachedLabel) {
313 QString sImageFile = m_detachedPdsLabelFile;
314 int iFound = sImageFile.indexOf(
".lbl");
316 sImageFile.replace(iFound, 4,
".img");
319 sImageFile +=
".img";
322 mainPvl +=
PvlKeyword(
"^IMAGE", outFile.name());
335 void ProcessExportPds::FixedJP2ImageRoot(
Pvl &mainPvl) {
336 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
338 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
339 QString sImageFile = m_detachedPdsLabelFile;
340 if(m_detachedLabel) {
341 int iFound = sImageFile.indexOf(
".lbl");
343 sImageFile.replace(iFound, 4,
".jp2");
346 sImageFile +=
".jp2";
350 QString msg =
"Labels must be detached for JP2 files";
355 cmpObj +=
PvlKeyword(
"FILE_NAME", outFile.name());
356 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
358 cmpObj +=
PvlKeyword(
"ENCODING_TYPE_VERSION_NAME",
"ISO/IEC15444-1:2004");
359 cmpObj +=
PvlKeyword(
"INTERCHANGE_FORMAT",
"BINARY");
360 FileName infilename(InputCubes[0]->fileName());
361 cmpObj +=
PvlKeyword(
"UNCOMPRESSED_FILE_NAME", infilename.name());
362 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
363 if(p_pixelType == Isis::Real) {
364 QString msg =
"JPEG2000 does not support floating point data";
367 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
368 storagebytes = storagebytes * 2;
373 ucmpObj +=
PvlKeyword(
"FILE_NAME", infilename.name());
374 ucmpObj +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
375 int recordbytes = InputCubes[0]->sampleCount();
376 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
377 recordbytes = recordbytes * 2;
381 ucmpObj +=
PvlKeyword(
"^IMAGE", infilename.name());
395 void ProcessExportPds::StandardImageImage(
Pvl &mainPvl) {
396 mainPvl.format()->add(
"$base/translations/pdsExportImageImage.typ");
399 Pvl *inputLabel = InputCubes[0]->label();
401 transfile =
"$base/translations/pdsExportImageImage.trn";
403 Xlator.Auto(mainPvl);
407 double multiplier = 1.0;
410 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
411 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
413 for(
unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
414 minimum = std::min(minimum, p_inputMinimum[i]);
415 maximum = std::max(maximum, p_inputMaximum[i]);
418 x1 = p_outputMinimum;
419 x2 = p_outputMaximum;
421 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
422 multiplier = (maximum - minimum) / (x2 - x1);
423 base = minimum - multiplier * x1;
425 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
426 multiplier = (maximum - minimum) / (x2 - x1);
427 base = minimum - multiplier * x1;
429 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
430 multiplier = (maximum - minimum) / (x2 - x1);
431 base = minimum - multiplier * x1;
440 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
443 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
445 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
448 if(p_pixelType == Isis::UnsignedByte) {
449 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
451 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
453 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
454 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
455 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
456 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
457 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel8.typ");
459 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
460 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
462 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
464 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
465 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
466 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
467 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
468 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
470 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
471 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
473 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
475 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
476 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
477 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
478 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
479 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
481 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
482 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
484 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
486 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
487 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
488 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
489 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
490 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
492 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
493 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
494 if(m_forceSampleBitMask) imgObj +=
PvlKeyword(
"SAMPLE_BIT_MASK",
toString((BigInt)0xffff));
495 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
497 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
498 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
499 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
500 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
501 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
503 else if(p_pixelType == Isis::Real) {
504 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
505 if(m_forceSampleBitMask) imgObj +=
PvlKeyword(
"SAMPLE_BIT_MASK",
toString((BigInt)0xffffffff));
507 if(p_endianType == Isis::Msb) {
508 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
511 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
514 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString(Isis::ILOW_REPR_SAT4));
515 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString(Isis::ILOW_INSTR_SAT4));
516 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString(Isis::IHIGH_REPR_SAT4));
517 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString(Isis::IHIGH_INSTR_SAT4));
518 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel32.typ");
521 QString msg =
"Unsupported PDS pixel type or sample size";
536 void ProcessExportPds::StandardJP2Image(
Pvl &mainPvl) {
537 mainPvl.format()->add(
"$base/translations/pdsExportImageImage.typ");
538 if(m_pdsFileType == ProcessExportPds::JP2Image) {
539 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
543 Pvl *inputLabel = InputCubes[0]->label();
545 transfile =
"$base/translations/pdsExportImageJP2.trn";
547 Xlator.Auto(mainPvl);
551 double multiplier = 1.0;
554 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
555 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
557 for(
unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
558 minimum = std::min(minimum, p_inputMinimum[i]);
559 maximum = std::max(maximum, p_inputMaximum[i]);
562 x1 = p_outputMinimum;
563 x2 = p_outputMaximum;
565 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
566 multiplier = (maximum - minimum) / (x2 - x1);
567 base = minimum - multiplier * x1;
569 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
570 multiplier = (maximum - minimum) / (x2 - x1);
571 base = minimum - multiplier * x1;
573 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
574 multiplier = (maximum - minimum) / (x2 - x1);
575 base = minimum - multiplier * x1;
584 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
587 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
589 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
592 if(p_pixelType == Isis::UnsignedByte) {
593 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
595 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
597 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
598 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
599 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
600 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
601 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel8.typ");
603 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
604 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
606 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
608 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
609 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
610 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
611 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
612 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
614 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
615 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
617 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
619 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
620 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
621 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
622 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
623 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
625 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
626 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
628 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
630 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
631 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
632 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
633 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
634 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
636 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
637 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
638 if(m_forceSampleBitMask) imgObj +=
PvlKeyword(
"SAMPLE_BIT_MASK",
toString((BigInt)0xffff));
639 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
641 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
642 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
643 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
644 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
645 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
647 else if(p_pixelType == Isis::Real) {
648 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
649 if(m_forceSampleBitMask) imgObj +=
PvlKeyword(
"SAMPLE_BIT_MASK",
toString((BigInt)0xffffffff));
651 if(p_endianType == Isis::Msb) {
652 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
655 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
658 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString(Isis::ILOW_REPR_SAT4));
659 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString(Isis::ILOW_INSTR_SAT4));
660 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString(Isis::IHIGH_REPR_SAT4));
661 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString(Isis::IHIGH_INSTR_SAT4));
662 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel32.typ");
665 QString msg =
"Unsupported PDS pixel type or sample size";
679 void ProcessExportPds::StandardAllMapping(
Pvl &outputPvl) {
682 Pvl *inputLabel = InputCubes[0]->label();
684 !(inputLabel->
findObject(
"IsisCube").hasGroup(
"Mapping")))
return;
688 "$base/translations/pdsExportAllMapping.trn");
689 xlatGenProj.Auto(outputPvl);
692 QString projName = ProjectionName(*inputLabel);
694 "$base/translations/pdsExport" + projName +
".trn");
695 xlatSpecProj.Auto(outputPvl);
699 "$base/translations/pdsExportTarget.trn");
700 xlatTarget.Auto(outputPvl);
709 PvlKeyword &aRadius = pdsMapObj[
"A_AXIS_RADIUS"];
710 QString unit = aRadius.
unit();
711 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
712 double dValue = (double)aRadius;
716 PvlKeyword &bRadius = pdsMapObj[
"B_AXIS_RADIUS"];
717 unit = bRadius.
unit();
718 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
719 double dValue = (double)bRadius;
723 PvlKeyword &cRadius = pdsMapObj[
"C_AXIS_RADIUS"];
724 unit = cRadius.
unit();
725 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
726 double dValue = (double)cRadius;
732 PvlKeyword &mapScale = pdsMapObj[
"MAP_SCALE"];
733 unit = mapScale.
unit();
735 if( (unit.toUpper() ==
"METERS/PIX") || (unit.toUpper() ==
"METERS/PIXEL") || (unit ==
"") ) {
736 if(m_exportResolution == Kilometer) {
737 double dValue = (double)mapScale;
745 PvlKeyword &mapRes = pdsMapObj[
"MAP_RESOLUTION"];
746 unit = mapRes.
unit();
748 if( (unit.toUpper() ==
"PIXELS/DEGREE") || (unit ==
"") ) {
749 mapRes.
setValue((QString)mapRes,
"PIX/DEG");
754 QString lonDir = isisLonDir[0];
755 lonDir = lonDir.toUpper();
756 if(lonDir ==
"POSITIVEEAST") {
757 double maxLon = inputMapping.
findKeyword(
"MaximumLongitude");
759 double minLon = inputMapping.
findKeyword(
"MinimumLongitude");
763 double minLon = inputMapping.
findKeyword(
"MinimumLongitude");
765 double maxLon = inputMapping.
findKeyword(
"MaximumLongitude");
773 double lineOffset = inputMapping.
findKeyword(
"UpperLeftCornerY");
774 lineOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
778 double sampleOffset = inputMapping.
findKeyword(
"UpperLeftCornerX");
779 sampleOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
780 sampleOffset *= -1.0;
787 tempKey.
setValue(tempKey[0],
"DEG");
789 if(pdsMapObj.
hasKeyword(
"CENTER_LONGITUDE")) {
791 tempKey.
setValue(tempKey[0],
"DEG");
797 if(pdsMapObj.
hasKeyword(
"REFERENCE_LONGITUDE")) {
799 tempKey.
setValue(tempKey[0],
"DEG");
801 if(pdsMapObj.
hasKeyword(
"MAXIMUM_LATITUDE")) {
803 tempKey.
setValue(tempKey[0],
"DEG");
805 if(pdsMapObj.
hasKeyword(
"MINIMUM_LATITUDE")) {
807 tempKey.
setValue(tempKey[0],
"DEG");
809 if(pdsMapObj.
hasKeyword(
"EASTERNMOST_LONGITUDE")) {
811 tempKey.
setValue(tempKey[0],
"DEG");
813 if(pdsMapObj.
hasKeyword(
"WESTERNMOST_LONGITUDE")) {
815 tempKey.
setValue(tempKey[0],
"DEG");
817 if(pdsMapObj.
hasKeyword(
"MAP_PROJECTION_ROTATION")) {
819 tempKey.
setValue(tempKey[0],
"DEG");
832 QString ProcessExportPds::ProjectionName(
Pvl &inputLabel) {
833 Projection *proj = ProjectionFactory::Create(inputLabel);
834 QString name = proj->
Name();
846 int ProcessExportPds::LineBytes() {
847 Cube *cube = InputCubes[0];
848 int a =
SizeOf(p_pixelType);
859 int ProcessExportPds::LabelSize() {
861 if(m_label->format() != NULL) {
862 temp << *m_label << m_label->format()->formatEOL();
865 temp << *m_label << endl;
875 void ProcessExportPds::OutputDetachedLabel() {
876 if(!m_detachedLabel) {
877 QString msg =
"Unable to output detached label. Use "
878 "ProcessExportPds::SetDetached() to set the "
879 "output PDS label file name.";
882 std::ofstream sOutLabelStream(m_detachedPdsLabelFile.toAscii().data());
883 OutputLabel(sOutLabelStream);
884 sOutLabelStream.close();
894 void ProcessExportPds::OutputLabel(std::ofstream &os) {
895 int labSize = LabelSize();
898 if(m_exportType == Stream) {
899 if(m_pdsFileType != ProcessExportPds::JP2Image) {
900 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labSize),
"BYTES");
901 if(!m_detachedLabel) {
902 (*m_label)[
"^IMAGE"].setValue(
toString(labSize + 1),
"BYTES");
905 if(m_label->format() != NULL) {
906 os << *m_label << m_label->format()->formatEOL();
909 os << *m_label << endl;
912 if(m_pdsFileType != ProcessExportPds::JP2Image) {
913 for(
int i = LabelSize(); i < labSize; ++i) os <<
' ';
916 else if(m_exportType == Fixed) {
919 if(m_pdsFileType != ProcessExportPds::JP2Image) {
920 lineBytes = LineBytes();
921 (*m_label)[
"RECORD_BYTES"].setValue(
toString(lineBytes));
925 labelRecords = (int)ceil((
double)labSize / (double)lineBytes);
926 if(m_label->hasKeyword(
"LABEL_RECORDS")) {
927 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labelRecords));
929 int totalTableRecords = 0;
930 for (
unsigned int i = 0; i < m_tableRecords.size(); i++) {
931 totalTableRecords += m_tableRecords[i];
933 int imageRecords = InputCubes[0]->lineCount()
934 * InputCubes[0]->bandCount();
935 int fileRecords = labelRecords + imageRecords + totalTableRecords;
936 (*m_label)[
"FILE_RECORDS"].setValue(
toString(fileRecords));
938 if(!m_detachedLabel) {
939 (*m_label)[
"^IMAGE"].setValue(
toString(labelRecords + 1));
942 if(m_label->format() != NULL) {
943 os << *m_label << m_label->format()->formatEOL();
946 os << *m_label << endl;
948 if(m_pdsFileType != ProcessExportPds::JP2Image) {
949 for(
int i = LabelSize(); i < labelRecords * lineBytes; ++i) os <<
' ';
986 void ProcessExportPds::ExportTable(
Table isisTable, QString detachedPdsTableFileName) {
988 if(Attached() && detachedPdsTableFileName !=
"") {
989 QString msg =
"The output PDS file has been set to attached and a "
990 "detached PDS table file name has been given. If detached "
991 "is preferred, set the process to detached SetDetached() "
992 "and call StandardPdsLabel() before calling ExportTable().";
996 if(Detached() && detachedPdsTableFileName ==
"") {
997 QString msg =
"The output PDS file has been set to detached. A file name "
998 "for the detached ouput PDS table file is required. "
999 "If an attached output file is prefered, use the method "
1000 "ProcessExportPds::SetAttached() before calling ExportTable().";
1006 int fileRecordBytes = LineBytes();
1009 char *tableBuffer =
new char[isisTable.
Records() * fileRecordBytes];
1012 ByteOrderName(p_endianType));
1014 Pvl &mainPvl = *m_label;
1016 m_tableBuffers.push_back(tableBuffer);
1017 int labSize = LabelSize();
1018 int labelRecords = (int)ceil((
double)labSize / (double)fileRecordBytes);
1019 int imageRecords = InputCubes[0]->lineCount()
1020 * InputCubes[0]->bandCount();
1021 int totalTableRecords = 0;
1022 for (
unsigned int i = 0; i < m_tableRecords.size(); i++) {
1023 totalTableRecords += m_tableRecords[i];
1026 int tableStartRecord = 1 + labelRecords + imageRecords + totalTableRecords;
1030 mainPvl +=
PvlKeyword(
"^" + pdsTableName, detachedPdsTableFileName);
1031 FileName labelFile(m_detachedPdsLabelFile);
1032 QString tableFileWithPath = labelFile.
path() +
"/"
1033 + detachedPdsTableFileName;
1034 ofstream os(tableFileWithPath.toAscii().data());
1035 os.write(tableBuffer, isisTable.
Records() * fileRecordBytes);
1039 m_tableRecords.push_back(isisTable.
Records());
1051 void ProcessExportPds::SetDetached(QString detachedLabelFile) {
1052 m_detachedLabel =
true;
1053 m_detachedPdsLabelFile = detachedLabelFile;
1062 void ProcessExportPds::SetAttached() {
1063 m_detachedLabel =
false;
1064 m_detachedPdsLabelFile =
"";
1072 bool ProcessExportPds::Detached() {
1073 return m_detachedLabel;
1081 bool ProcessExportPds::Attached() {
1082 return !m_detachedLabel;
1092 m_exportResolution = resolutionUnits;
1103 m_exportType = recordFormat;
1114 void ProcessExportPds::ForceBands(
bool force) {
1115 m_forceBands = force;
1127 void ProcessExportPds::ForceBandName(
bool force) {
1128 m_forceBandName = force;
1140 void ProcessExportPds::ForceCenterFilterWavelength(
bool force) {
1141 m_forceCenterFilterWavelength = force;
1153 void ProcessExportPds::ForceBandwidth(
bool force) {
1154 m_forceBandwidth = force;
1166 void ProcessExportPds::ForceBandStorageType(
bool force) {
1167 m_forceBandStorageType = force;
1179 void ProcessExportPds::ForceOffset(
bool force) {
1180 m_forceOffset = force;
1192 void ProcessExportPds::ForceScalingFactor(
bool force) {
1193 m_forceScalingFactor = force;
1205 void ProcessExportPds::ForceSampleBits(
bool force) {
1206 m_forceSampleBits = force;
1218 void ProcessExportPds::ForceSampleBitMask(
bool force) {
1219 m_forceSampleBitMask = force;
1231 void ProcessExportPds::ForceSampleType(
bool force) {
1232 m_forceSampleType = force;
1244 void ProcessExportPds::ForceCoreNull(
bool force) {
1245 m_forceCoreNull = force;
1257 void ProcessExportPds::ForceCoreLrs(
bool force) {
1258 m_forceCoreLrs = force;
1271 void ProcessExportPds::ForceCoreLis(
bool force) {
1272 m_forceCoreLis = force;
1285 void ProcessExportPds::ForceCoreHrs(
bool force) {
1286 m_forceCoreHrs = force;
1299 void ProcessExportPds::ForceCoreHis(
bool force) {
1300 m_forceCoreHis = force;
1310 void ProcessExportPds::StartProcess(std::ofstream &fout) {
1311 ProcessExport::StartProcess(fout);
1312 if (!m_detachedLabel) {
1313 for (
unsigned int i = 0; i < m_tableBuffers.size(); i++) {
1314 if (m_tableBuffers[i] == NULL) {
1315 QString msg =
"Unable to add tables to PDS output file.";
1321 fout.write(m_tableBuffers[i], m_tableRecords[i]*LineBytes());