Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
CubeAttribute.h
1#ifndef CubeAttribute_h
2#define CubeAttribute_h
7
8/* SPDX-License-Identifier: CC0-1.0 */
9
10#include <typeinfo>
11
12#include <QDebug>
13#include <QStringList>
14
15#include "Cube.h"
16#include "IEndian.h"
17#include "FileName.h"
18#include "IException.h"
19#include "PixelType.h"
20
21
22namespace Isis {
31 inline QString LabelAttachmentName(Cube::LabelAttachment labelType) {
32 if(labelType == Cube::AttachedLabel) return "Attached";
33 if(labelType == Cube::DetachedLabel) return "Detached";
34 if(labelType == Cube::ExternalLabel) return "External";
35 if(labelType == Cube::GdalLabel) return "Gdal";
36
37 QString msg = "Invalid label attachment type [" + QString::number(labelType) + "]";
38 throw IException(IException::Programmer, msg, _FILEINFO_);
39 }
40
41
50 inline Cube::LabelAttachment LabelAttachmentEnumeration(const QString &labelType) {
51 QString temp = labelType.toUpper();
52 if(temp == "ATTACHED") return Cube::AttachedLabel;
53 if(temp == "DETACHED") return Cube::DetachedLabel;
54 if(temp == "EXTERNAL") return Cube::ExternalLabel;
55 if(temp == "GDAL") return Cube::GdalLabel;
56
57 QString msg = "Invalid label attachment type string [" + labelType + "]";
58 throw IException(IException::Unknown, msg, _FILEINFO_);
59 }
60
97 template<typename ChildClass> class CubeAttribute {
98 public:
99
101 CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers) {
102 m_attributeTypeTesters = testers;
103 }
104
105
117 CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers,
118 const FileName &fileName) {
119 m_attributeTypeTesters = testers;
120 setAttributes(fileName);
121 }
122
123
125 virtual ~CubeAttribute() {
126 }
127
128
137 QString toString() const {
138 QString result;
139
140 if (!m_attributes.isEmpty())
141 result = "+" + m_attributes.join("+");
142
143 return result;
144 }
145
146
157 void addAttribute(QString attribute) {
158 QString upcaseAtt = attribute.toUpper();
159
160 if (attribute.contains("+")) {
161 throw IException(IException::Unknown,
162 "Individual attributes (for example, BSQ) cannot contain the '+' "
163 "character because that is used to denote the separation of individual "
164 "attributes",
165 _FILEINFO_);
166 }
167
168 // Verify this attribute is legal
169 bool legal = false;
170 bool (ChildClass::*tester)(QString) const;
171 foreach (tester, m_attributeTypeTesters) {
172 if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
173 if (legal) {
174 throw IException(IException::Unknown,
175 QObject::tr("Attribute [%1] is ambiguous").arg(attribute),
176 _FILEINFO_);
177 }
178
179 legal = true;
180 }
181 }
182
183 if (!legal) {
184 throw IException(IException::Unknown,
185 QObject::tr("Attribute [%1] is not recognized").arg(attribute),
186 _FILEINFO_);
187 }
188
189 m_attributes.append(attribute);
190 }
191
192
201 void addAttributes(const FileName &fileNameWithAtts) {
202 addAttributes(fileNameWithAtts.attributes());
203 }
204
205
214 void addAttributes(const char *attributesString) {
215 addAttributes(QString(attributesString));
216 }
217
218
227 void addAttributes(const QString &attributesString) {
228 setAttributes(toString() + "+" + attributesString);
229 }
230
231
241 void setAttributes(const FileName &fileName) {
242 QStringList attributes = fileName.attributes().split("+", Qt::SkipEmptyParts);
243
244 m_attributes.clear();
245 foreach (QString attribute, attributes)
246 addAttribute(attribute);
247 }
248
249
250 protected:
259 QStringList attributeList(bool (ChildClass::*tester)(QString) const) const {
260 QStringList relevantAttributes;
261
262 foreach (QString attribute, m_attributes) {
263 QString upcaseAtt = attribute.toUpper();
264 if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
265 relevantAttributes.append(upcaseAtt);
266 }
267 }
268
269 return relevantAttributes;
270 }
271
272
284 void setAttribute(QString newValue, bool (ChildClass::*tester)(QString) const) {
285 QMutableListIterator<QString> it(m_attributes);
286
287 bool found = false;
288 while (it.hasNext()) {
289 QString &attribute = it.next();
290
291 QString upcaseAtt = attribute.toUpper();
292 if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
293 if (found || newValue == "") {
294 // already found one (remove the duplicate) or just deleting it
295 it.remove();
296 }
297 else {
298 // modify existing attribute value
299 attribute = newValue;
300 }
301
302 found = true;
303 }
304 }
305
306 // Attribute doesn't exist, add it
307 if (!found && newValue != "") {
308 m_attributes.append(newValue);
309 }
310 }
311
312 private:
319
327 QList< bool (ChildClass::*)(QString) const > m_attributeTypeTesters;
328 };
329
330
360 class CubeAttributeInput : public CubeAttribute<CubeAttributeInput> {
361
362 public:
363
366
367
377 CubeAttributeInput(const FileName &fileName);
378
379
382
383
385 std::vector<QString> bands() const;
386
398 QString bandsString() const;
399
401 void setBands(const std::vector<QString> &bands);
402
403 using CubeAttribute<CubeAttributeInput>::toString;
404
405 private:
406 bool isBandRange(QString attribute) const;
407
408 static QString toString(const std::vector<QString> &bands);
409 static QList<bool (CubeAttributeInput::*)(QString) const> testers();
410
411 private:
412 std::vector<QString> m_bands;
413 };
414
415
452 class CubeAttributeOutput : public CubeAttribute<CubeAttributeOutput> {
453
454 public:
455
458
471 CubeAttributeOutput(const FileName &fileName);
472
473
476
477
479 bool propagatePixelType() const;
480
482 bool propagateMinimumMaximum() const;
483
485 bool propagateFileFormat() const;
486
488 Cube::Format fileFormat() const;
489
491 QString fileFormatString() const;
492
494 void setFileFormat(Cube::Format fmt);
495
497 ByteOrder byteOrder() const;
498
500 QString byteOrderString() const;
501
503 void setByteOrder(ByteOrder order);
504
506 double minimum() const;
507
509 double maximum() const;
510
512 void setMinimum(double min);
513
515 void setMaximum(double max);
516
518 PixelType pixelType() const;
519
521 void setPixelType(PixelType type);
522
525
526 Cube::LabelAttachment labelAttachment() const;
527
528 using CubeAttribute<CubeAttributeOutput>::toString;
529
530 static QString toString(Cube::Format);
531
532 private:
533 bool isByteOrder(QString attribute) const;
534 bool isFileFormat(QString attribute) const;
535 bool isLabelAttachment(QString attribute) const;
536 bool isPixelType(QString attribute) const;
537 bool isRange(QString attribute) const;
538
549
550 static QList<bool (CubeAttributeOutput::*)(QString) const> testers();
551 };
552};
553
554#endif
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers, const FileName &fileName)
Constructs a CubeAttribute using the argument.
void addAttributes(const FileName &fileNameWithAtts)
Append the attributes found in the filename to these cube attributes.
void addAttribute(QString attribute)
Add a single attribute to these attributes.
QString toString() const
Return a string-representation of this cube attributes.
virtual ~CubeAttribute()
Destroys the object.
void addAttributes(const QString &attributesString)
Append the attributes in the string to these cube attributes.
QStringList attributeList(bool(ChildClass::*tester)(QString) const) const
Get a list of attributes that the tester returns true on.
QList< bool(ChildClass::*)(QString) const > m_attributeTypeTesters
These testers determine if an attribute looks like a particular option.
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
QStringList m_attributes
These are the attributes that this cube attribute stores.
void setAttribute(QString newValue, bool(ChildClass::*tester)(QString) const)
Set the attribute(s) for which tester returns true to newValue.
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers)
Constructs an empty CubeAttribute.
void addAttributes(const char *attributesString)
Append the attributes in the string to these cube attributes.
std::vector< QString > m_bands
A list of the specified bands.
void setBands(const std::vector< QString > &bands)
Set the band attribute according to the list of bands.
QString bandsString() const
Return a string representation of all the bands.
CubeAttributeInput()
Constructs an empty CubeAttributeInput.
~CubeAttributeInput()
Destroys the object.
std::vector< QString > bands() const
Return a vector of the input bands specified.
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.
RangeType
Output cube range tracker.
@ PropagateRange
Propagate the range from an input cube.
@ RangeSet
The range has been set.
LabelAttachment
Input cube label type tracker.
Definition Cube.h:245
@ ExternalLabel
The label is pointing to an external DN file - the label is also external to the data.
Definition Cube.h:254
@ AttachedLabel
The input label is embedded in the image file.
Definition Cube.h:246
@ DetachedLabel
The input label is in a separate data file from the image.
Definition Cube.h:247
Format
These are the possible storage formats of ISIS cubes.
Definition Cube.h:179
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString LabelAttachmentName(Cube::LabelAttachment labelType)
Return the string representation of the contents of a variable of type LabelAttachment.
Cube::LabelAttachment LabelAttachmentEnumeration(const QString &labelType)
Return the appropriate LabelType depending on which of the valid values the argument spells.