7#include "CubeAttribute.h"
12#include <QRegularExpression>
15#include "IException.h"
16#include "Preference.h"
17#include "SpecialPixel.h"
84 vector<QString> result;
86 QString str =
toString().remove(QRegularExpression(
"^\\+"));
88 QStringList strSplit = str.split(
",", Qt::SkipEmptyParts);
89 foreach (QString commaTok, strSplit) {
91 if (commaTok.contains(
'-')) {
93 int start = toInt(commaTok.mid(0, commaTok.indexOf(
"-")));
94 int end = toInt(commaTok.mid(commaTok.indexOf(
"-") + 1));
96 direction = (start <= end) ? 1 : -1;
98 for (
int band = start; band != end; band += direction) {
105 result.push_back(commaTok);
123 bool CubeAttributeInput::isBandRange(QString attribute)
const {
124 return QRegularExpression(
"[0-9,\\-]+").match(attribute).hasMatch();
130 for (
unsigned int i = 0; i <
bands.size(); i++) {
144 result.append(&CubeAttributeInput::isBandRange);
171 if (pixelTypeAtts.isEmpty() || pixelTypeAtts.last() ==
"PROPAGATE")
179 return attributeList(&CubeAttributeOutput::isRange).isEmpty();
188 if (fileFormatAtts.isEmpty() || fileFormatAtts.last() ==
"PROPAGATE")
285 if (!formatList.isEmpty()) {
286 QString formatString = formatList.last();
288 if (formatString ==
"BSQ" || formatString ==
"BANDSEQUENTIAL")
290 else if(formatString ==
"GTIFF") {
291 result = Cube::GTiff;
306 setAttribute(
"Tile", &CubeAttributeOutput::isFileFormat);
309 setAttribute(
"BandSequential", &CubeAttributeOutput::isFileFormat);
311 else if (fmt == Cube::GTiff) {
312 setAttribute(
"GTiff", &CubeAttributeOutput::isFileFormat);
315 QString msg =
"Unsupported format [" +
toString(fmt) +
"]";
316 IException(IException::Programmer, msg, _FILEINFO_);
322 double result = Null;
325 QString range =
attributeList(&CubeAttributeOutput::isRange).last();
328 if (rangeList.count() == 2 && rangeList.first() !=
"")
329 result = toDouble(rangeList.first());
337 double result = Null;
340 QString range =
attributeList(&CubeAttributeOutput::isRange).last();
343 if (rangeList.count() == 2 && rangeList.last() !=
"")
344 result = toDouble(rangeList.last());
352 if (!IsSpecial(min)) {
360 else if (!IsSpecial(
maximum())) {
370 if (!IsSpecial(max)) {
378 else if (!IsSpecial(
minimum())) {
388 PixelType result = None;
391 QString pixelTypeAtt =
attributeList(&CubeAttributeOutput::isPixelType).last();
393 if (pixelTypeAtt ==
"8BIT" || pixelTypeAtt ==
"8-BIT" || pixelTypeAtt ==
"UNSIGNEDBYTE") {
394 result = UnsignedByte;
396 else if (pixelTypeAtt ==
"16BIT" || pixelTypeAtt ==
"16-BIT" || pixelTypeAtt ==
"SIGNEDWORD") {
399 else if (pixelTypeAtt ==
"16UBIT" || pixelTypeAtt ==
"16-UBIT" || pixelTypeAtt ==
"UNSIGNEDWORD") {
400 result = UnsignedWord;
402 else if (pixelTypeAtt ==
"32BIT" || pixelTypeAtt ==
"32-BIT" || pixelTypeAtt ==
"REAL") {
405 else if (pixelTypeAtt ==
"32UINT" || pixelTypeAtt ==
"32-UINT" || pixelTypeAtt ==
"UNSIGNEDINTEGER") {
406 result = UnsignedInteger;
408 else if (pixelTypeAtt ==
"32INT" || pixelTypeAtt ==
"32-INT" || pixelTypeAtt ==
"SIGNEDINTEGER") {
409 result = SignedInteger;
418 setAttribute(PixelTypeName(type), &CubeAttributeOutput::isPixelType);
431 if (!labelAttachmentAtts.isEmpty()) {
432 QString labelAttachmentAtt = labelAttachmentAtts.last();
434 if (labelAttachmentAtt ==
"DETACHED")
436 else if (labelAttachmentAtt ==
"EXTERNAL")
444 bool CubeAttributeOutput::isByteOrder(QString attribute)
const {
445 return QRegularExpression(
"(M|L)SB").match(attribute).hasMatch();
449 bool CubeAttributeOutput::isFileFormat(QString attribute)
const {
450 return QRegularExpression(
"(BANDSEQUENTIAL|BSQ|TILE|GTIFF)").match(attribute).hasMatch();
454 bool CubeAttributeOutput::isLabelAttachment(QString attribute)
const {
455 return QRegularExpression(
"(ATTACHED|DETACHED|EXTERNAL)").match(attribute).hasMatch();
459 bool CubeAttributeOutput::isPixelType(QString attribute)
const {
460 QString expressions =
"(8-?BIT|16-?BIT|32-?BIT|UNSIGNEDBYTE|SIGNEDWORD|UNSIGNEDWORD|REAL";
461 expressions +=
"|32-?UINT|32-?INT|UNSIGNEDINTEGER|SIGNEDINTEGER)";
462 return QRegularExpression(expressions).match(attribute).hasMatch();
467 bool CubeAttributeOutput::isRange(QString attribute)
const {
468 return QRegularExpression(
"[\\-+E0-9.]*:[\\-+E0-9.]*").match(attribute).hasMatch();
479 result =
"BandSequential";
481 else if (format == Cube::GTiff) {
485 QString msg =
"Format [" + QString::number(format) +
"] cannot be translated to string";
486 throw IException(IException::Programmer, msg, _FILEINFO_);
494 ByteOrder result = IsLsb()? Lsb : Msb;
498 if (!byteOrderAtts.isEmpty()) {
499 QString byteOrderAtt = byteOrderAtts.last();
500 result = (byteOrderAtt ==
"LSB")? Lsb : Msb;
514 &CubeAttributeOutput::isByteOrder);
521 result.append(&CubeAttributeOutput::isByteOrder);
522 result.append(&CubeAttributeOutput::isFileFormat);
523 result.append(&CubeAttributeOutput::isLabelAttachment);
524 result.append(&CubeAttributeOutput::isPixelType);
525 result.append(&CubeAttributeOutput::isRange);
QStringList attributeList(bool(CubeAttributeOutput::*tester)(QString) const) const
void setAttributes(const FileName &fileName)
void setAttribute(QString newValue, bool(CubeAttributeOutput::*tester)(QString) const)
CubeAttribute(QList< bool(CubeAttributeInput::*)(QString) const > testers)
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.
void setByteOrder(ByteOrder order)
Set the order according to the parameter order.
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.
QString fileFormatString() const
Return the file format as a string.
void setLabelAttachment(Cube::LabelAttachment attachment)
Set the label attachment type to the parameter value.
QString byteOrderString() const
Return the byte order as a string.
CubeAttributeOutput()
Constructs an empty CubeAttributeOutput.
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
void setMinimum(double min)
Set the output cube attribute minimum.
void setMaximum(double max)
Set the output cube attribute maximum.
~CubeAttributeOutput()
Destroys the object.
void setPixelType(PixelType type)
Set the pixel type to that given by the parameter.
void setFileFormat(Cube::Format fmt)
Set the format to the fmt parameter.
LabelAttachment
Input cube label type tracker.
@ ExternalLabel
The label is pointing to an external DN file - the label is also external to the data.
@ AttachedLabel
The input label is embedded in the image file.
@ DetachedLabel
The input label is in a separate data file from the image.
Format
These are the possible storage formats of ISIS cubes.
@ Tile
Cubes are stored in tile format, that is the order of the pixels in the file (on disk) is BSQ within ...
@ Bsq
Cubes are stored in band-sequential format, that is the order of the pixels in the file (on disk) is:
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.
QString LabelAttachmentName(Cube::LabelAttachment labelType)
Return the string representation of the contents of a variable of type LabelAttachment.
Namespace for the standard library.