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";
237 mainPvl +=
PvlKeyword(
"^IMAGE",
"???????",
"BYTES");
240 if (canGenerateChecksum()) {
241 mainPvl +=
PvlKeyword(
"CHECKSUM",
"????????????????????????????????");
251 void ProcessExportPds::StreamJP2ImageRoot(
Pvl &mainPvl) {
252 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
254 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
255 QString sImageFile = m_detachedPdsLabelFile;
256 if(m_detachedLabel) {
257 int iFound = sImageFile.indexOf(
".lbl");
259 sImageFile.replace(iFound, 4,
".jp2");
262 sImageFile +=
".jp2";
266 QString msg =
"Labels must be detached for JP2 files.";
272 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
274 cmpObj +=
PvlKeyword(
"ENCODING_TYPE_VERSION_NAME",
"ISO/IEC15444-1:2004");
275 cmpObj +=
PvlKeyword(
"INTERCHANGE_FORMAT",
"BINARY");
276 FileName infilename(InputCubes[0]->fileName());
277 cmpObj +=
PvlKeyword(
"UNCOMPRESSED_FILE_NAME", infilename.
name());
278 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
279 if(p_pixelType == Isis::Real) {
280 QString msg =
"JPEG2000 does not support floating point data.";
283 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
284 storagebytes = storagebytes * 2;
290 ucmpObj +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
291 int recordbytes = InputCubes[0]->sampleCount();
292 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
293 recordbytes = recordbytes * 2;
307 void ProcessExportPds::FixedImageRoot(
Pvl &mainPvl) {
309 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
310 mainPvl +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
313 mainPvl +=
PvlKeyword(
"RECORD_BYTES",
"???????");
314 mainPvl +=
PvlKeyword(
"FILE_RECORDS",
"???????");
315 mainPvl +=
PvlKeyword(
"LABEL_RECORDS",
"????");
316 if(m_detachedLabel) {
317 QString sImageFile = m_detachedPdsLabelFile;
318 int iFound = sImageFile.indexOf(
".lbl");
320 sImageFile.replace(iFound, 4,
".img");
323 sImageFile +=
".img";
331 if (canGenerateChecksum()) {
332 mainPvl +=
PvlKeyword(
"CHECKSUM",
"????????????????????????????????");
342 void ProcessExportPds::FixedJP2ImageRoot(
Pvl &mainPvl) {
343 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
345 mainPvl +=
PvlKeyword(
"PDS_VERSION_ID",
"PDS3");
346 QString sImageFile = m_detachedPdsLabelFile;
347 if(m_detachedLabel) {
348 int iFound = sImageFile.indexOf(
".lbl");
350 sImageFile.replace(iFound, 4,
".jp2");
353 sImageFile +=
".jp2";
357 QString msg =
"Labels must be detached for JP2 files.";
363 cmpObj +=
PvlKeyword(
"RECORD_TYPE",
"UNDEFINED");
365 cmpObj +=
PvlKeyword(
"ENCODING_TYPE_VERSION_NAME",
"ISO/IEC15444-1:2004");
366 cmpObj +=
PvlKeyword(
"INTERCHANGE_FORMAT",
"BINARY");
367 FileName infilename(InputCubes[0]->fileName());
368 cmpObj +=
PvlKeyword(
"UNCOMPRESSED_FILE_NAME", infilename.
name());
369 int storagebytes = InputCubes[0]->sampleCount() * InputCubes[0]->lineCount();
370 if(p_pixelType == Isis::Real) {
371 QString msg =
"JPEG2000 does not support floating point data.";
374 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
375 storagebytes = storagebytes * 2;
381 ucmpObj +=
PvlKeyword(
"RECORD_TYPE",
"FIXED_LENGTH");
382 int recordbytes = InputCubes[0]->sampleCount();
383 if(p_pixelType == Isis::UnsignedWord || p_pixelType == Isis::SignedWord) {
384 recordbytes = recordbytes * 2;
402 void ProcessExportPds::StandardImageImage(
Pvl &mainPvl) {
403 mainPvl.format()->add(
"$base/translations/pdsExportImageImage.typ");
406 Pvl *inputLabel = InputCubes[0]->label();
408 transfile =
"$base/translations/pdsExportImageImage.trn";
410 Xlator.
Auto(mainPvl);
414 double multiplier = 1.0;
417 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
418 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
420 for(
unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
421 minimum = std::min(minimum, p_inputMinimum[i]);
422 maximum = std::max(maximum, p_inputMaximum[i]);
425 x1 = p_outputMinimum;
426 x2 = p_outputMaximum;
428 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
429 multiplier = (maximum - minimum) / (x2 - x1);
430 base = minimum - multiplier * x1;
432 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
433 multiplier = (maximum - minimum) / (x2 - x1);
434 base = minimum - multiplier * x1;
436 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
437 multiplier = (maximum - minimum) / (x2 - x1);
438 base = minimum - multiplier * x1;
447 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
450 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
452 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
455 if(p_pixelType == Isis::UnsignedByte) {
456 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
458 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
460 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
461 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
462 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
463 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
464 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel8.typ");
466 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
467 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
469 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
471 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
472 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
473 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
474 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
475 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
477 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
478 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
480 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
482 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
483 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
484 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
485 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
486 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
488 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
489 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
491 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
493 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
494 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
495 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
496 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
497 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
499 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
500 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
502 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
504 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
505 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
506 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
507 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
508 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
510 else if(p_pixelType == Isis::Real) {
511 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
514 if(p_endianType == Isis::Msb) {
515 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
518 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
521 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString(Isis::ILOW_REPR_SAT4));
522 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString(Isis::ILOW_INSTR_SAT4));
523 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString(Isis::IHIGH_REPR_SAT4));
524 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString(Isis::IHIGH_INSTR_SAT4));
525 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel32.typ");
528 QString msg =
"Unsupported PDS pixel type or sample size";
543 void ProcessExportPds::StandardJP2Image(
Pvl &mainPvl) {
544 mainPvl.format()->add(
"$base/translations/pdsExportImageImage.typ");
545 if(m_pdsFileType == ProcessExportPds::JP2Image) {
546 mainPvl.format()->add(
"$base/translations/pdsExportImageJP2.typ");
550 Pvl *inputLabel = InputCubes[0]->label();
552 transfile =
"$base/translations/pdsExportImageJP2.trn";
554 Xlator.
Auto(mainPvl);
558 double multiplier = 1.0;
561 double minimum = (p_inputMinimum.size()) ? p_inputMinimum[0] : 0.0;
562 double maximum = (p_inputMaximum.size()) ? p_inputMaximum[0] : 0.0;
564 for(
unsigned int i = 0; i < p_inputMinimum.size(); i ++) {
565 minimum = std::min(minimum, p_inputMinimum[i]);
566 maximum = std::max(maximum, p_inputMaximum[i]);
569 x1 = p_outputMinimum;
570 x2 = p_outputMaximum;
572 if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedByte) {
573 multiplier = (maximum - minimum) / (x2 - x1);
574 base = minimum - multiplier * x1;
576 else if(p_inputMinimum.size() && p_pixelType == Isis::SignedWord) {
577 multiplier = (maximum - minimum) / (x2 - x1);
578 base = minimum - multiplier * x1;
580 else if(p_inputMinimum.size() && p_pixelType == Isis::UnsignedWord) {
581 multiplier = (maximum - minimum) / (x2 - x1);
582 base = minimum - multiplier * x1;
591 if(!m_forceCenterFilterWavelength && imgObj.
hasKeyword(
"CENTER_FILTER_WAVELENGTH")) imgObj.
deleteKeyword(
"CENTER_FILTER_WAVELENGTH");
594 if(m_forceBandStorageType) imgObj +=
PvlKeyword(
"BAND_STORAGE_TYPE",
"BAND_SEQUENTIAL");
596 if(m_forceScalingFactor) imgObj +=
PvlKeyword(
"SCALING_FACTOR",
toString(multiplier));
599 if(p_pixelType == Isis::UnsignedByte) {
600 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"8");
602 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
604 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
605 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
606 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
607 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
608 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel8.typ");
610 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Msb)) {
611 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
613 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_UNSIGNED_INTEGER");
615 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
616 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
617 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
618 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
619 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
621 else if((p_pixelType == Isis::UnsignedWord) && (p_endianType == Isis::Lsb)) {
622 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
624 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_UNSIGNED_INTEGER");
626 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
627 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
628 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
629 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
630 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
632 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Msb)) {
633 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
635 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"MSB_INTEGER");
637 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
638 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
639 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
640 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
641 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
643 else if((p_pixelType == Isis::SignedWord) && (p_endianType == Isis::Lsb)) {
644 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"16");
646 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"LSB_INTEGER");
648 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString((
int)OutputLrs()));
649 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString((
int)OutputLis()));
650 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString((
int)OutputHrs()));
651 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString((
int)OutputHis()));
652 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel16.typ");
654 else if(p_pixelType == Isis::Real) {
655 if(m_forceSampleBits) imgObj +=
PvlKeyword(
"SAMPLE_BITS",
"32");
658 if(p_endianType == Isis::Msb) {
659 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"IEEE_REAL");
662 if(m_forceSampleType) imgObj +=
PvlKeyword(
"SAMPLE_TYPE",
"PC_REAL");
665 if(m_forceCoreLrs) imgObj +=
PvlKeyword(
"CORE_LOW_REPR_SATURATION",
toString(Isis::ILOW_REPR_SAT4));
666 if(m_forceCoreLis) imgObj +=
PvlKeyword(
"CORE_LOW_INSTR_SATURATION",
toString(Isis::ILOW_INSTR_SAT4));
667 if(m_forceCoreHrs) imgObj +=
PvlKeyword(
"CORE_HIGH_REPR_SATURATION",
toString(Isis::IHIGH_REPR_SAT4));
668 if(m_forceCoreHis) imgObj +=
PvlKeyword(
"CORE_HIGH_INSTR_SATURATION",
toString(Isis::IHIGH_INSTR_SAT4));
669 mainPvl.format()->add(
"$base/translations/pdsExportImageImagePixel32.typ");
672 QString msg =
"Unsupported PDS pixel type or sample size";
686 void ProcessExportPds::StandardAllMapping(
Pvl &outputPvl) {
689 Pvl *inputLabel = InputCubes[0]->label();
691 !(inputLabel->
findObject(
"IsisCube").hasGroup(
"Mapping")))
return;
695 QString projName = ProjectionName(*inputLabel);
697 "$base/translations/pdsExport" + projName +
".trn");
698 xlatSpecProj.
Auto(outputPvl);
702 "$base/translations/pdsExportTarget.trn");
703 xlatTarget.
Auto(outputPvl);
712 PvlKeyword &aRadius = pdsMapObj[
"A_AXIS_RADIUS"];
713 QString unit = aRadius.
unit();
714 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
715 double dValue = (double)aRadius;
719 PvlKeyword &bRadius = pdsMapObj[
"B_AXIS_RADIUS"];
720 unit = bRadius.
unit();
721 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
722 double dValue = (double)bRadius;
726 PvlKeyword &cRadius = pdsMapObj[
"C_AXIS_RADIUS"];
727 unit = cRadius.
unit();
728 if( (unit.toUpper() ==
"METERS") || (unit ==
"") ) {
729 double dValue = (double)cRadius;
735 PvlKeyword &mapScale = pdsMapObj[
"MAP_SCALE"];
736 unit = mapScale.
unit();
738 if( (unit.toUpper() ==
"METERS/PIX") || (unit.toUpper() ==
"METERS/PIXEL") || (unit ==
"") ) {
739 if(m_exportResolution == Kilometer) {
740 double dValue = (double)mapScale;
748 PvlKeyword &mapRes = pdsMapObj[
"MAP_RESOLUTION"];
749 unit = mapRes.
unit();
751 if( (unit.toUpper() ==
"PIXELS/DEGREE") || (unit ==
"") ) {
752 mapRes.
setValue((QString)mapRes,
"PIX/DEG");
757 QString lonDir = isisLonDir[0];
758 lonDir = lonDir.toUpper();
759 if (inputMapping.
hasKeyword(
"MaximumLongitude") && inputMapping.
hasKeyword(
"MinimumLongitude")) {
760 double maxLon = inputMapping.
findKeyword(
"MaximumLongitude");
761 double minLon = inputMapping.
findKeyword(
"MinimumLongitude");
762 if(lonDir ==
"POSITIVEEAST") {
776 double lineOffset = inputMapping.
findKeyword(
"UpperLeftCornerY");
777 lineOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
781 double sampleOffset = inputMapping.
findKeyword(
"UpperLeftCornerX");
782 sampleOffset /= (double)inputMapping.
findKeyword(
"PixelResolution");
783 sampleOffset *= -1.0;
790 tempKey.
setValue(tempKey[0],
"DEG");
792 if(pdsMapObj.
hasKeyword(
"CENTER_LONGITUDE")) {
794 tempKey.
setValue(tempKey[0],
"DEG");
800 if(pdsMapObj.
hasKeyword(
"REFERENCE_LONGITUDE")) {
802 tempKey.
setValue(tempKey[0],
"DEG");
804 if(pdsMapObj.
hasKeyword(
"MAXIMUM_LATITUDE")) {
806 tempKey.
setValue(tempKey[0],
"DEG");
808 if(pdsMapObj.
hasKeyword(
"MINIMUM_LATITUDE")) {
810 tempKey.
setValue(tempKey[0],
"DEG");
812 if(pdsMapObj.
hasKeyword(
"EASTERNMOST_LONGITUDE")) {
814 tempKey.
setValue(tempKey[0],
"DEG");
816 if(pdsMapObj.
hasKeyword(
"WESTERNMOST_LONGITUDE")) {
818 tempKey.
setValue(tempKey[0],
"DEG");
820 if(pdsMapObj.
hasKeyword(
"MAP_PROJECTION_ROTATION")) {
822 tempKey.
setValue(tempKey[0],
"DEG");
835 QString ProcessExportPds::ProjectionName(
Pvl &inputLabel) {
836 Projection *proj = ProjectionFactory::Create(inputLabel);
837 QString name = proj->
Name();
849 int ProcessExportPds::LineBytes() {
850 Cube *cube = InputCubes[0];
851 int a =
SizeOf(p_pixelType);
862 int ProcessExportPds::LabelSize() {
864 if(m_label->format() != NULL) {
865 temp << *m_label << m_label->format()->formatEOL();
868 temp << *m_label << endl;
878 void ProcessExportPds::OutputDetachedLabel() {
879 if(!m_detachedLabel) {
880 QString msg =
"Unable to output detached label. Use " 881 "ProcessExportPds::SetDetached() to set the " 882 "output PDS label file name.";
885 std::ofstream sOutLabelStream(m_detachedPdsLabelFile.toLatin1().data());
886 OutputLabel(sOutLabelStream);
887 sOutLabelStream.close();
897 void ProcessExportPds::OutputLabel(std::ofstream &os) {
898 int labSize = LabelSize();
902 if(m_exportType == Stream) {
903 if(m_pdsFileType != ProcessExportPds::JP2Image) {
904 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labSize),
"BYTES");
905 if(!m_detachedLabel) {
906 (*m_label)[
"^IMAGE"].setValue(
toString(labSize + 1),
"BYTES");
909 if(m_label->format() != NULL) {
910 os << *m_label << m_label->format()->formatEOL();
913 os << *m_label << endl;
916 if(m_pdsFileType != ProcessExportPds::JP2Image) {
917 for(
int i = LabelSize(); i < labSize; ++i) os <<
' ';
920 else if(m_exportType == Fixed) {
923 if(m_pdsFileType != ProcessExportPds::JP2Image) {
924 lineBytes = LineBytes();
925 (*m_label)[
"RECORD_BYTES"].setValue(
toString(lineBytes));
929 labelRecords = (int)ceil((
double)labSize / (double)lineBytes);
930 if(m_label->hasKeyword(
"LABEL_RECORDS")) {
931 (*m_label)[
"LABEL_RECORDS"].setValue(
toString(labelRecords));
933 int totalTableRecords = 0;
934 for (
unsigned int i = 0; i < m_tableRecords.size(); i++) {
935 totalTableRecords += m_tableRecords[i];
937 int imageRecords = InputCubes[0]->lineCount()
938 * InputCubes[0]->bandCount();
939 int fileRecords = labelRecords + imageRecords + totalTableRecords;
940 (*m_label)[
"FILE_RECORDS"].setValue(
toString(fileRecords));
942 if(!m_detachedLabel) {
943 (*m_label)[
"^IMAGE"].setValue(
toString(labelRecords + 1));
946 if(m_label->format() != NULL) {
947 os << *m_label << m_label->format()->formatEOL();
950 os << *m_label << endl;
952 if(m_pdsFileType != ProcessExportPds::JP2Image) {
953 for(
int i = LabelSize(); i < labelRecords * lineBytes; ++i) os <<
' ';
965 void ProcessExportPds::updateChecksumInLabel(std::ofstream &pdsFileStream) {
971 pdsFileStream.seekp(0);
972 (*m_label)[
"CHECKSUM"].setValue(checksum());
973 pdsFileStream << *m_label;
1008 void ProcessExportPds::ExportTable(
Table isisTable, QString detachedPdsTableFileName) {
1010 if(Attached() && detachedPdsTableFileName !=
"") {
1011 QString msg =
"The output PDS file has been set to attached and a " 1012 "detached PDS table file name has been given. If detached " 1013 "is preferred, set the process to detached SetDetached() " 1014 "and call StandardPdsLabel() before calling ExportTable().";
1018 if(Detached() && detachedPdsTableFileName ==
"") {
1019 QString msg =
"The output PDS file has been set to detached. A file name " 1020 "for the detached ouput PDS table file is required. " 1021 "If an attached output file is prefered, use the method " 1022 "ProcessExportPds::SetAttached() before calling ExportTable().";
1028 int fileRecordBytes = LineBytes();
1031 char *tableBuffer =
new char[isisTable.
Records() * fileRecordBytes];
1034 ByteOrderName(p_endianType));
1036 Pvl &mainPvl = *m_label;
1038 m_tableBuffers.push_back(tableBuffer);
1039 int labSize = LabelSize();
1040 int labelRecords = (int)ceil((
double)labSize / (double)fileRecordBytes);
1041 int imageRecords = InputCubes[0]->lineCount()
1042 * InputCubes[0]->bandCount();
1043 int totalTableRecords = 0;
1044 for (
unsigned int i = 0; i < m_tableRecords.size(); i++) {
1045 totalTableRecords += m_tableRecords[i];
1048 int tableStartRecord = 1 + labelRecords + imageRecords + totalTableRecords;
1052 mainPvl +=
PvlKeyword(
"^" + pdsTableName, detachedPdsTableFileName);
1053 FileName labelFile(m_detachedPdsLabelFile);
1054 QString tableFileWithPath = labelFile.
path() +
"/" 1055 + detachedPdsTableFileName;
1056 ofstream os(tableFileWithPath.toLatin1().data());
1057 os.write(tableBuffer, isisTable.
Records() * fileRecordBytes);
1061 m_tableRecords.push_back(isisTable.
Records());
1073 void ProcessExportPds::SetDetached(QString detachedLabelFile) {
1074 m_detachedLabel =
true;
1075 m_detachedPdsLabelFile = detachedLabelFile;
1084 void ProcessExportPds::SetAttached() {
1085 m_detachedLabel =
false;
1086 m_detachedPdsLabelFile =
"";
1094 bool ProcessExportPds::Detached() {
1095 return m_detachedLabel;
1103 bool ProcessExportPds::Attached() {
1104 return !m_detachedLabel;
1114 m_exportResolution = resolutionUnits;
1125 m_exportType = recordFormat;
1136 void ProcessExportPds::ForceBands(
bool force) {
1137 m_forceBands = force;
1149 void ProcessExportPds::ForceBandName(
bool force) {
1150 m_forceBandName = force;
1162 void ProcessExportPds::ForceCenterFilterWavelength(
bool force) {
1163 m_forceCenterFilterWavelength = force;
1175 void ProcessExportPds::ForceBandwidth(
bool force) {
1176 m_forceBandwidth = force;
1188 void ProcessExportPds::ForceBandStorageType(
bool force) {
1189 m_forceBandStorageType = force;
1201 void ProcessExportPds::ForceOffset(
bool force) {
1202 m_forceOffset = force;
1214 void ProcessExportPds::ForceScalingFactor(
bool force) {
1215 m_forceScalingFactor = force;
1227 void ProcessExportPds::ForceSampleBits(
bool force) {
1228 m_forceSampleBits = force;
1240 void ProcessExportPds::ForceSampleBitMask(
bool force) {
1241 m_forceSampleBitMask = force;
1253 void ProcessExportPds::ForceSampleType(
bool force) {
1254 m_forceSampleType = force;
1266 void ProcessExportPds::ForceCoreNull(
bool force) {
1267 m_forceCoreNull = force;
1279 void ProcessExportPds::ForceCoreLrs(
bool force) {
1280 m_forceCoreLrs = force;
1293 void ProcessExportPds::ForceCoreLis(
bool force) {
1294 m_forceCoreLis = force;
1307 void ProcessExportPds::ForceCoreHrs(
bool force) {
1308 m_forceCoreHrs = force;
1321 void ProcessExportPds::ForceCoreHis(
bool force) {
1322 m_forceCoreHis = force;
1332 void ProcessExportPds::StartProcess(std::ofstream &fout) {
1333 ProcessExport::StartProcess(fout);
1334 if (!m_detachedLabel) {
1335 for (
unsigned int i = 0; i < m_tableBuffers.size(); i++) {
1336 if (m_tableBuffers[i] == NULL) {
1337 QString msg =
"Unable to add tables to PDS output file.";
1343 fout.write(m_tableBuffers[i], m_tableRecords[i]*LineBytes());
long long int BigInt
Big int.
int Records() const
Returns the number of records.
QString path() const
Returns the path of the file name.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
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...
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
File name manipulation and expansion.
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType.
Namespace for the standard library.
PdsFileType
File type to be exported.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Allows applications to translate simple text files.
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 ...
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
void addObject(const PvlObject &object)
Add a PvlObject.
PvlObject exportTable(char *pdsTableBuffer, int pdsFileRecordBytes, QString pdsByteOrder)
This methods fills the given buffer with the binary PDS table data and returns label information...
Base class for Map Projections.
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
PdsExportType
Record format type of exported PDS file.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
This represents a cube in a project-based GUI interface.
Container for cube-like labels.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Class for storing Table blobs information.
PdsResolution
Resolution units per pixel of the exported PDS file.
QString formatPdsTableName()
Format the PDS table object name using the Isis3 table name.
Namespace for ISIS/Bullet specific routines.
void Auto(Pvl &outputLabel)
Automatically translate all the output names found in the translation table If a output name does not...
Export a PDS table from an Isis3 Table.
void setValue(QString value, QString unit="")
Sets new values.
Contains Pvl Groups and Pvl Objects.
virtual QString Name() const =0
This method returns the name of the map projection.
void deleteKeyword(const QString &name)
Remove a specified keyword.
IO Handler for Isis Cubes.