12#include "SessionLog.h"
16#include "IException.h"
18#include "Preference.h"
19#include "Application.h"
21#include "OriginalLabel.h"
22#include "LineManager.h"
72 if(att.
bands().size() != 0) {
73 vector<QString> lame = att.
bands();
78 if(requirements & Isis::ReadWrite) {
79 cube->
open(fname,
"rw");
83 cube->
open(FileName(fname).expanded());
86 catch(IException &e) {
112 if(inCube != NULL && inCube->
isOpen()) {
114 AddInputCube(inCube,
false);
117 QString message =
"Input cube does not exist";
118 throw IException(IException::User, message, _FILEINFO_);
140 const int requirements) {
143 return SetInputCube(FileName(fname).expanded(), att, requirements);
166 QString message =
"No input images have been selected ... therefore";
167 message +=
"the output image size can not be determined";
168 throw IException(IException::Programmer, message, _FILEINFO_);
199 QString message =
"No input images have been selected ... therefore";
200 message +=
"the output image size can not be determined";
201 throw IException(IException::Programmer, message, _FILEINFO_);
234 const int nl,
const int nb) {
236 if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
237 ostringstream message;
238 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
239 <<
",nb=" << nb <<
"]";
240 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
278 if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
279 ostringstream message;
280 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
281 <<
",nb=" << nb <<
"]";
282 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
317 const int ns,
const int nl,
320 if ((ns <= 0) || (nl <= 0) || (nb <= 0)) {
321 ostringstream message;
322 message <<
"Invalid cube size specifications [ns=" << ns <<
",nl=" << nl
323 <<
",nb=" << nb <<
"]";
324 throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
348 QString msg =
"You told me to propagate PixelType from input to output";
349 msg +=
" cube but there are no input cubes loaded";
350 throw IException(IException::Programmer, msg, _FILEINFO_);
362 QString msg =
"You told me to propagate base/multiplier from input to output";
363 msg +=
" cube but there are no input cubes loaded";
364 throw IException(IException::Programmer, msg, _FILEINFO_);
371 else if((cube->
pixelType() != Isis::Real) &&
372 (cube->
pixelType() != Isis::UnsignedByte) &&
373 (cube->
pixelType() != Isis::UnsignedWord) &&
374 (cube->
pixelType() != Isis::SignedWord) &&
375 (cube->
pixelType() != Isis::UnsignedInteger) &&
376 (cube->
pixelType() != Isis::SignedInteger)) {
377 QString msg =
"Looks like your refactoring to add different pixel types";
378 msg +=
" you'll need to make changes here";
379 throw IException(IException::Programmer, msg, _FILEINFO_);
382 QString msg =
"You've chosen to reduce your output PixelType for [" +
383 fname +
"] you must specify the output pixel range too";
384 throw IException(IException::User, msg, _FILEINFO_);
393 int needLabBytes =
InputCubes[0]->labelSize(
true) + (1024 * 6);
404 Isis::PvlObject &incube =
405 InputCubes[0]->label()->findObject(
"IsisCube");
406 Isis::PvlObject &outcube = cube->
label()->findObject(
"IsisCube");
407 for(
int i = 0; i < incube.groups(); i++) {
408 outcube.addGroup(incube.group(i));
411 if (
InputCubes[0]->label()->hasObject(
"NaifKeywords")) {
412 cube->
label()->addObject(
413 InputCubes[0]->label()->findObject(
"NaifKeywords"));
420 for(
int i = 0; i < inlab.objects(); i++) {
421 if(inlab.object(i).isNamed(
"Table") || inlab.object(i).isNamed(
"String")) {
422 Isis::Blob t((QString)inlab.object(i)[
"Name"], inlab.object(i).name());
432 for(
int i = 0; i < inlab.objects(); i++) {
433 if(inlab.object(i).isNamed(
"Polygon")) {
434 Isis::Blob t((QString)inlab.object(i)[
"Name"], inlab.object(i).name());
444 for(
int i = 0; i < inlab.objects(); i++) {
445 if(inlab.object(i).isNamed(
"OriginalLabel")) {
455 catch (IException &e) {
485 void Process::AddInputCube(
Cube *cube,
bool owned) {
491 void Process::AddOutputCube(Cube *cube,
bool owned) {
524 if(requirements & Isis::AllMatchOrOne) {
528 QString message =
"The number of lines in the secondary input cubes must match";
529 message +=
" the primary input cube or be exactly one";
530 throw IException(IException::User, message, _FILEINFO_);
536 QString message =
"The number of samples in the secondary input cubes must match";
537 message +=
" the primary input cube or be exactly one";
538 throw IException(IException::User, message, _FILEINFO_);
543 QString message =
"The number of bands in the secondary input cubes must match";
544 message +=
" the primary input cube or be exactly one";
545 throw IException(IException::User, message, _FILEINFO_);
550 requirements = requirements & !Isis::SpatialMatch;
555 if(requirements & Isis::SizeMatch) {
558 QString message =
"The number of lines in the input cubes must match";
559 throw IException(IException::User, message, _FILEINFO_);
562 QString message =
"The number of samples in the input cubes must match";
563 throw IException(IException::User, message, _FILEINFO_);
566 QString message =
"The number of bands in the input cubes must match";
567 throw IException(IException::User, message, _FILEINFO_);
573 if(requirements & Isis::SpatialMatch) {
576 QString message =
"The number of lines in the input cubes must match";
577 throw IException(IException::User, message, _FILEINFO_);
580 QString message =
"The number of samples in the input cubes must match";
581 throw IException(IException::User, message, _FILEINFO_);
587 if(requirements & Isis::OneBand) {
589 QString message =
"Input cube [" + cube->
fileName() +
"] must have one band";
590 throw IException(IException::User, message, _FILEINFO_);
595 if(requirements & Isis::BandMatchOrOne) {
599 QString message =
"The number of bands in the secondary input cubes must match";
600 message +=
" the primary input cube or be exactly one";
601 throw IException(IException::User, message, _FILEINFO_);
625 for (
unsigned int i = 0; i <
InputCubes.size(); i++) {
640 for (
unsigned int i = 0; i <
OutputCubes.size(); i++) {
675 Isis::Pvl inLabels(cube);
679 Isis::PvlObject &inCubeLabels = inLabels.findObject(
"IsisCube");
682 Isis::PvlObject &outCubeLabels = outLabels.findObject(
"IsisCube");
684 for(
int g = 0; g < inCubeLabels.groups(); g++) {
685 outCubeLabels.addGroup(inCubeLabels.group(g));
688 if (inLabels.hasObject(
"NaifKeywords")) {
689 outLabels.addObject(inLabels.findObject(
"NaifKeywords"));
725 fromCube->
open(fromName);
726 const Pvl *fromLabels = fromCube->
label();
728 for (
unsigned int i = 0; i <
OutputCubes.size(); i++) {
729 for (
int j = 0; j < fromLabels->objects(); j++) {
730 const PvlObject &
object = fromLabels->object(j);
732 if (
object.isNamed(
"Table")) {
733 if (tableNames.isEmpty() || tableNames.contains(
object[
"Name"])) {
734 Blob table((QString)
object[
"Name"],
object.name());
735 fromCube->
read(table);
798 bool highestVersion) {
799 Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup(
"DataDirectory");
800 QString dir = dataDir[mission];
803 Isis::FileName installed(dir);
804 if(!installed.fileExists()) {
805 QString message =
"Data directory for mission [" + mission +
"] " +
806 "is not installed at your site";
807 throw IException(IException::Io, message, _FILEINFO_);
810 Isis::FileName expanded(dir +
"/" + file);
814 if (highestVersion) {
815 expanded = expanded.highestVersion();
818 if (!expanded.fileExists()) {
819 QString message =
"The file [" + expanded.original() +
"] " +
820 "cannot be found under [" + mission +
"]";
821 throw IException(IException::Io, message, _FILEINFO_);
824 return expanded.expanded();
833 bool addedHist =
false;
836 for(
int i = 0; i < inlab.objects(); i++) {
837 if(inlab.object(i).isNamed(
"History") && Isis::iApp != NULL) {
838 QString histBlobName = (QString)inlab.object(i)[
"Name"];
841 cube.
write(h, histBlobName);
847 if(!addedHist && Isis::iApp != NULL) {
868 for(
unsigned cubeNum = 0; cubeNum <
InputCubes.size(); cubeNum++) {
879 QString cubeNumStr =
toString(cubeNum + 1);
881 QString msg =
"Calculating statistics for cube " + cubeNumStr +
" of " + totalCubes;
889 vector<Statistics *> allBandStats;
890 for(
int useBand = bandStart; useBand <= bandStop; useBand++) {
893 for(
int i = 1; i <= cube->
lineCount(); i++) {
901 allBandStats.push_back(bandStats);
static UserInterface & GetUserInterface()
Returns the UserInterface object.
int size() const
Returns the total number of pixels in the shape buffer.
double * DoubleBuffer() const
Returns the value of the shape buffer.
Manipulate and parse attributes of output cube filenames.
double minimum() const
Return the output cube attribute minimum.
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
double maximum() const
Return the output cube attribute maximum.
bool propagateFileFormat() const
Return true if the file format is to be propagated from an input cube.
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
Cube::Format fileFormat() const
Return the file format an Cube::Format.
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
IO Handler for Isis Cubes.
void setPixelType(PixelType pixelType)
Used prior to the Create method, this will specify the output pixel type.
void setFormat(Format format)
Used prior to the Create method, this will specify the format of the cube, either band,...
void setDimensions(int ns, int nl, int nb)
Used prior to the Create method to specify the size of the cube.
bool isOpen() const
Test if a cube file has been opened/created.
void setBaseMultiplier(double base, double mult)
Used prior to the Create method, this will specify the base and multiplier for converting 8-bit/16-bi...
void setMinMax(double min, double max)
Used prior to the Create method, this will compute a good base and multiplier value given the minimum...
void create(const QString &cfile)
This method will create an isis cube for writing.
void open(const QString &cfile, QString access="r")
This method will try to open a file as either a cube or geotiff in either read or read/write.
PixelType pixelType() const
void setVirtualBands(const QList< QString > &vbands)
This allows the programmer to specify a subset of bands to work with.
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
void setLabelSize(int labelBytes)
Used prior to the Create method, this will allocate a specific number of bytes in the label area for ...
virtual QString fileName() const
Returns the opened cube's filename.
void write(Blob &blob, bool overwrite=true)
This method will write a blob of data (e.g.
void close(bool remove=false)
Closes the cube and updates the labels.
History readHistory(const QString &name="IsisCube") const
Read the History from the Cube.
int labelSize(bool actual=false) const
Returns the number of bytes used by the label.
void setLabelsAttached(LabelAttachment attached)
Use prior to calling create, this sets whether or not to use separate label and data files.
virtual int bandCount() const
Returns the number of virtual bands for the cube.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
void setByteOrder(ByteOrder byteOrder)
Used prior to the Create method, this will specify the byte order of pixels, either least or most sig...
void AddEntry()
Adds History PvlObject.
Buffer manager, for moving through a cube in lines.
bool SetLine(const int line, const int band=1)
Positions the buffer at the requested line and returns a status indicator if the set was succesful or...
Read and store original labels.
void PropagateLabels(const bool prop)
This method allows the programmer to turn on/off the propagation of labels from the 1st input cube to...
bool p_propagatePolygons
Flag indicating if blobs are be propagated to output cubes.
virtual void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
void PropagateHistory(const bool prop)
This method allows the programmer to propagate history to the output cube (default is true)
bool p_propagateOriginalLabel
Flag indicating if original lable is to be propagated to output cubes.
bool p_propagateLabels
Flag indicating if labels are be propagated to output cubes.
std::vector< std::vector< Isis::Statistics * > > p_bandStats
Holds the calculated statistics for each band separately of every input cubei after the CalculateStat...
virtual ~Process()
Destroys the Process Object. It will close all opened cubes.
std::vector< Isis::Statistics * > p_cubeStats
Holds the calculated statistics for every band together of every input cubei after the CalculateStati...
void PropagateOriginalLabel(const bool prop)
This method allows the programmer to propagate original labels to the output cube (default is true)
Process()
Constructs a Process Object.
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
QString MissionData(const QString &mission, const QString &file, bool highestVersion=false)
This method reads the mission specific data directory from the user preference file,...
void PropagateTables(const bool prop)
This method allows the programmer to propagate input tables to the output cube (default is true)
void WriteHistory(Cube &cube)
Writes out the History blob to the cube.
virtual Isis::Cube * SetOutputCubeStretch(const QString ¶meter, UserInterface *ui=nullptr)
Allocates a user-specified output cube whose size matches the first input cube.
QSet< Isis::Cube * > * m_ownedCubes
A list of cubes owned by this instant.
bool p_propagateHistory
Flag indicating if history is to be propagated to output cubes.
Isis::Progress * p_progress
Pointer to a Progress object.
virtual Isis::Cube * SetOutputCube(const QString ¶meter)
Allocates a user-specified output cube whose size matches the first input cube.
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
void CalculateStatistics()
Calculates and stores off statistics on every band of every cube added to this process via the SetInp...
void CheckRequirements(const Cube *cube, const int requirements)
Checks to make sure the input cube meets the inputted requirements.
virtual Isis::Cube * SetInputCube(const QString ¶meter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
void PropagatePolygons(const bool prop)
This method allows the programmer to propagate input blobs to the output cube (default is true)
void ClearInputCubes()
Close owned input cubes from the list and clear the list.
bool p_propagateTables
Flag indicating if tables are be propagated to output cubes.
void ClearOutputCubes()
Close owned output cubes from the list and clear the list.
void ClearCubes()
Close owned cubes from the list and clear the list.
virtual void Finalize()
Cleans up by closing cubes and freeing memory for owned cubes.
Program progress reporter.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
void CheckStatus()
Checks and updates the status.
This class is used to accumulate statistics on double arrays.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
Command Line and Xml loader, validation, and access.
Isis::CubeAttributeInput & GetInputAttribute(const QString ¶mName)
Gets the attributes for an input cube.
QString GetCubeName(const QString ¶mName, QString extension="") const
Retrieves of a value for a parameter of type "cubename".
Isis::CubeAttributeOutput & GetOutputAttribute(const QString ¶mName)
Gets the attributes for an output cube.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.
Namespace for the standard library.