12 #include "SessionLog.h"
16 #include "IException.h"
18 #include "Preference.h"
19 #include "Application.h"
21 #include "OriginalLabel.h"
22 #include "LineManager.h"
32 p_progress->SetText(
"Working");
33 p_propagateLabels =
true;
34 p_propagateTables =
true;
35 p_propagatePolygons =
true;
36 p_propagateHistory =
true;
37 p_propagateOriginalLabel =
true;
70 if(att.
bands().size() != 0) {
71 vector<QString> lame = att.
bands();
76 if(requirements & Isis::ReadWrite) {
77 cube->
open(fname,
"rw");
88 CheckRequirements(cube, requirements);
107 void Process::SetInputCube(
Isis::Cube *inCube,
const int requirements)
109 if(inCube != NULL && inCube->
isOpen()) {
110 CheckRequirements(inCube, requirements);
111 AddInputCube(inCube,
false);
114 QString message =
"Input cube does not exist";
115 throw IException(IException::User, message, _FILEINFO_);
137 const int requirements) {
138 QString fname = Application::GetUserInterface().GetFileName(parameter);
140 return SetInputCube(fname, att, requirements);
160 Isis::Cube *Process::SetOutputCube(
const QString ¶meter) {
162 if(InputCubes.size() == 0) {
163 QString message =
"No input images have been selected ... therefore";
164 message +=
"the output image size can not be determined";
165 throw IException(IException::Programmer, message, _FILEINFO_);
168 int nl = InputCubes[0]->lineCount();
169 int ns = InputCubes[0]->sampleCount();
170 int nb = InputCubes[0]->bandCount();
171 return SetOutputCube(parameter, ns, nl, nb);
195 if(InputCubes.size() == 0) {
196 QString message =
"No input images have been selected ... therefore";
197 message +=
"the output image size can not be determined";
198 throw IException(IException::Programmer, message, _FILEINFO_);
201 int nl = InputCubes[0]->lineCount();
202 int ns = InputCubes[0]->sampleCount();
203 int nb = InputCubes[0]->bandCount();
204 return SetOutputCubeStretch(parameter, ns, nl, nb, ui);
229 Isis::Cube *Process::SetOutputCube(
const QString ¶meter,
const int ns,
230 const int nl,
const int nb) {
232 if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
233 ostringstream message;
234 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
235 <<
",nb=" << nb <<
"]";
236 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
240 fname = Application::GetUserInterface().GetFileName(parameter);
241 atts = Application::GetUserInterface().GetOutputAttribute(parameter);
242 return SetOutputCube(fname, atts, ns, nl, nb);
270 Isis::Cube *Process::SetOutputCubeStretch(
const QString ¶meter,
const int ns,
273 if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
274 ostringstream message;
275 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
276 <<
",nb=" << nb <<
"]";
277 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
282 fname = Application::GetUserInterface().GetFileName(parameter);
283 atts = Application::GetUserInterface().GetOutputAttribute(parameter);
289 return SetOutputCube(fname, atts, ns, nl, nb);
311 const int ns,
const int nl,
314 if ((ns <= 0) || (nl <= 0) || (nb <= 0)) {
315 ostringstream message;
316 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
317 <<
",nb=" << nb <<
"]";
318 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
329 if(InputCubes.size() > 0) {
333 QString msg =
"You told me to propagate PixelType from input to output";
334 msg +=
" cube but there are no input cubes loaded";
335 throw IException(IException::Programmer, msg, _FILEINFO_);
346 else if(InputCubes.size() == 0) {
347 QString msg =
"You told me to propagate base/multiplier from input to output";
348 msg +=
" cube but there are no input cubes loaded";
349 throw IException(IException::Programmer, msg, _FILEINFO_);
351 else if(cube->
pixelType() >= InputCubes[0]->pixelType()) {
352 double base = InputCubes[0]->base();
353 double mult = InputCubes[0]->multiplier();
356 else if((cube->
pixelType() != Isis::Real) &&
357 (cube->
pixelType() != Isis::UnsignedByte) &&
358 (cube->
pixelType() != Isis::UnsignedWord) &&
359 (cube->
pixelType() != Isis::SignedWord) &&
360 (cube->
pixelType() != Isis::UnsignedInteger) &&
361 (cube->
pixelType() != Isis::SignedInteger)) {
362 QString msg =
"Looks like your refactoring to add different pixel types";
363 msg +=
" you'll need to make changes here";
364 throw IException(IException::Programmer, msg, _FILEINFO_);
367 QString msg =
"You've chosen to reduce your output PixelType for [" +
368 fname +
"] you must specify the output pixel range too";
369 throw IException(IException::User, msg, _FILEINFO_);
377 if(InputCubes.size() > 0) {
378 int needLabBytes = InputCubes[0]->labelSize(
true) + (1024 * 6);
388 if((p_propagateLabels) && (InputCubes.size() > 0)) {
390 InputCubes[0]->label()->
findObject(
"IsisCube");
392 for(
int i = 0; i < incube.
groups(); i++) {
396 if (InputCubes[0]->label()->hasObject(
"NaifKeywords")) {
398 InputCubes[0]->label()->findObject(
"NaifKeywords"));
403 if((p_propagateTables) && (InputCubes.size() > 0)) {
404 Isis::Pvl &inlab = *InputCubes[0]->label();
405 for(
int i = 0; i < inlab.
objects(); i++) {
408 InputCubes[0]->read(t);
415 if((p_propagatePolygons) && (InputCubes.size() > 0)) {
416 Isis::Pvl &inlab = *InputCubes[0]->label();
417 for(
int i = 0; i < inlab.
objects(); i++) {
420 InputCubes[0]->read(t);
427 if((p_propagateOriginalLabel) && (InputCubes.size() > 0)) {
428 Isis::Pvl &inlab = *InputCubes[0]->label();
429 for(
int i = 0; i < inlab.
objects(); i++) {
455 void Process::EndProcess() {
463 void Process::Finalize() {
467 void Process::AddInputCube(
Cube *cube,
bool owned) {
468 InputCubes.push_back(cube);
469 if (owned) m_ownedCubes->insert(cube);
472 void Process::AddOutputCube(Cube *cube,
bool owned) {
473 OutputCubes.push_back(cube);
474 if (owned) m_ownedCubes->insert(cube);
503 void Process::CheckRequirements(
const Cube *cube,
int requirements) {
505 if(requirements & Isis::AllMatchOrOne) {
506 if(InputCubes.size() > 0) {
508 if(cube->
lineCount() != InputCubes[0]->lineCount()) {
509 QString message =
"The number of lines in the secondary input cubes must match";
510 message +=
" the primary input cube or be exactly one";
511 throw IException(IException::User, message, _FILEINFO_);
516 if(cube->
sampleCount() != InputCubes[0]->sampleCount()) {
517 QString message =
"The number of samples in the secondary input cubes must match";
518 message +=
" the primary input cube or be exactly one";
519 throw IException(IException::User, message, _FILEINFO_);
523 if(cube->
bandCount() != InputCubes[0]->bandCount()) {
524 QString message =
"The number of bands in the secondary input cubes must match";
525 message +=
" the primary input cube or be exactly one";
526 throw IException(IException::User, message, _FILEINFO_);
531 requirements = requirements & !Isis::SpatialMatch;
536 if(requirements & Isis::SizeMatch) {
537 if(InputCubes.size() > 0) {
538 if(cube->
lineCount() != InputCubes[0]->lineCount()) {
539 QString message =
"The number of lines in the input cubes must match";
540 throw IException(IException::User, message, _FILEINFO_);
542 if(cube->
sampleCount() != InputCubes[0]->sampleCount()) {
543 QString message =
"The number of samples in the input cubes must match";
544 throw IException(IException::User, message, _FILEINFO_);
546 if(cube->
bandCount() != InputCubes[0]->bandCount()) {
547 QString message =
"The number of bands in the input cubes must match";
548 throw IException(IException::User, message, _FILEINFO_);
554 if(requirements & Isis::SpatialMatch) {
555 if(InputCubes.size() > 0) {
556 if(cube->
lineCount() != InputCubes[0]->lineCount()) {
557 QString message =
"The number of lines in the input cubes must match";
558 throw IException(IException::User, message, _FILEINFO_);
560 if(cube->
sampleCount() != InputCubes[0]->sampleCount()) {
561 QString message =
"The number of samples in the input cubes must match";
562 throw IException(IException::User, message, _FILEINFO_);
568 if(requirements & Isis::OneBand) {
570 QString message =
"Input cube [" + cube->
fileName() +
"] must have one band";
571 throw IException(IException::User, message, _FILEINFO_);
576 if(requirements & Isis::BandMatchOrOne) {
578 if(InputCubes.size() > 0) {
579 if(cube->
bandCount() != InputCubes[0]->bandCount()) {
580 QString message =
"The number of bands in the secondary input cubes must match";
581 message +=
" the primary input cube or be exactly one";
582 throw IException(IException::User, message, _FILEINFO_);
593 void Process::ClearCubes() {
597 m_ownedCubes->clear();
603 void Process::ClearInputCubes() {
605 for (
unsigned int i = 0; i < InputCubes.size(); i++) {
606 if (m_ownedCubes->contains(InputCubes[i])) {
607 InputCubes[i]->close();
608 delete InputCubes[i];
617 void Process::ClearOutputCubes() {
619 for (
unsigned int i = 0; i < OutputCubes.size(); i++) {
620 if (m_ownedCubes->contains(OutputCubes[i])) {
621 OutputCubes[i]->close();
622 delete OutputCubes[i];
639 void Process::PropagateLabels(
const bool prop) {
640 p_propagateLabels = prop;
650 void Process::PropagateLabels(
const QString &cube) {
655 for(
int i = 0; i < (int)OutputCubes.size(); i++) {
658 Isis::Pvl &outLabels(*OutputCubes[i]->label());
661 for(
int g = 0; g < inCubeLabels.
groups(); g++) {
665 if (inLabels.
hasObject(
"NaifKeywords")) {
678 void Process::PropagateTables(
const bool prop) {
679 p_propagateTables = prop;
698 void Process::PropagateTables(
const QString &fromName,
const QList<QString> &tableNames) {
700 fromCube->
open(fromName);
701 const Pvl *fromLabels = fromCube->
label();
703 for (
unsigned int i = 0; i < OutputCubes.size(); i++) {
704 for (
int j = 0; j < fromLabels->
objects(); j++) {
707 if (
object.isNamed(
"Table")) {
708 if (tableNames.isEmpty() || tableNames.contains(
object[
"Name"])) {
709 Blob table((QString)
object[
"Name"],
object.name());
710 fromCube->
read(table);
711 OutputCubes[i]->write(table);
727 void Process::PropagatePolygons(
const bool prop) {
728 p_propagatePolygons = prop;
737 void Process::PropagateHistory(
const bool prop) {
738 p_propagateHistory = prop;
748 void Process::PropagateOriginalLabel(
const bool prop) {
749 p_propagateOriginalLabel = prop;
768 QString Process::MissionData(
const QString &mission,
const QString &file,
769 bool highestVersion) {
771 QString dir = dataDir[mission];
776 QString message =
"Data directory for mission [" + mission +
"] " +
777 "is not installed at your site";
778 throw IException(IException::Io, message, _FILEINFO_);
789 void Process::WriteHistory(
Cube &cube) {
790 if(p_propagateHistory) {
791 bool addedHist =
false;
792 if(InputCubes.size() > 0) {
793 Isis::Pvl & inlab = *InputCubes[0]->label();
794 for(
int i = 0; i < inlab.
objects(); i++) {
795 if(inlab.
object(i).
isNamed(
"History") && Isis::iApp != NULL) {
796 QString histBlobName = (QString)inlab.
object(i)[
"Name"];
797 History h = InputCubes[0]->readHistory(histBlobName);
799 cube.
write(h, histBlobName);
805 if(!addedHist && Isis::iApp != NULL) {
824 void Process::CalculateStatistics() {
825 for(
unsigned cubeNum = 0; cubeNum < InputCubes.size(); cubeNum++) {
826 Cube *cube = InputCubes[cubeNum];
836 QString cubeNumStr =
toString(cubeNum + 1);
837 QString totalCubes =
toString((
int)InputCubes.size());
838 QString msg =
"Calculating statistics for cube " + cubeNumStr +
" of " + totalCubes;
846 vector<Statistics *> allBandStats;
847 for(
int useBand = bandStart; useBand <= bandStop; useBand++) {
850 for(
int i = 1; i <= cube->
lineCount(); i++) {
858 allBandStats.push_back(bandStats);
861 p_bandStats.push_back(allBandStats);
862 p_cubeStats.push_back(cubeStats);