File failed to load: https://isis.astrogeology.usgs.gov/dev/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
CubeAttribute.h
Go to the documentation of this file.
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 "Endian.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) + "]";
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 + "]";
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("+")) {
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) {
175 QObject::tr("Attribute [%1] is ambiguous").arg(attribute),
176 _FILEINFO_);
177 }
178
179 legal = true;
180 }
181 }
182
183 if (!legal) {
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:
318 QStringList m_attributes;
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
527
528 using CubeAttribute<CubeAttributeOutput>::toString;
529
530
531 private:
532 bool isByteOrder(QString attribute) const;
533 bool isFileFormat(QString attribute) const;
534 bool isLabelAttachment(QString attribute) const;
535 bool isPixelType(QString attribute) const;
536 bool isRange(QString attribute) const;
537
538 static QString toString(Cube::Format);
539
546 enum RangeType {
547 PropagateRange,
548 RangeSet,
549 };
550
551 static QList<bool (CubeAttributeOutput::*)(QString) const> testers();
552 };
553};
554
555#endif
#define _FILEINFO_
Macro for the filename and line number.
Definition IException.h:24
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers, const FileName &fileName)
Constructs a CubeAttribute using the argument.
Definition CubeAttribute.h:117
void addAttributes(const FileName &fileNameWithAtts)
Append the attributes found in the filename to these cube attributes.
Definition CubeAttribute.h:201
void addAttribute(QString attribute)
Add a single attribute to these attributes.
Definition CubeAttribute.h:157
QString toString() const
Return a string-representation of this cube attributes.
Definition CubeAttribute.h:137
virtual ~CubeAttribute()
Destroys the object.
Definition CubeAttribute.h:125
void addAttributes(const QString &attributesString)
Append the attributes in the string to these cube attributes.
Definition CubeAttribute.h:227
QStringList attributeList(bool(ChildClass::*tester)(QString) const) const
Get a list of attributes that the tester returns true on.
Definition CubeAttribute.h:259
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
Definition CubeAttribute.h:241
void setAttribute(QString newValue, bool(ChildClass::*tester)(QString) const)
Set the attribute(s) for which tester returns true to newValue.
Definition CubeAttribute.h:284
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers)
Constructs an empty CubeAttribute.
Definition CubeAttribute.h:101
void addAttributes(const char *attributesString)
Append the attributes in the string to these cube attributes.
Definition CubeAttribute.h:214
void setBands(const std::vector< QString > &bands)
Set the band attribute according to the list of bands.
Definition CubeAttribute.cpp:117
QString bandsString() const
Return a string representation of all the bands.
Definition CubeAttribute.cpp:112
CubeAttributeInput()
Constructs an empty CubeAttributeInput.
Definition CubeAttribute.cpp:25
~CubeAttributeInput()
Destroys the object.
Definition CubeAttribute.cpp:34
std::vector< QString > bands() const
Return a vector of the input bands specified.
Definition CubeAttribute.cpp:82
double minimum() const
Return the output cube attribute minimum.
Definition CubeAttribute.cpp:320
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
Definition CubeAttribute.cpp:492
double maximum() const
Return the output cube attribute maximum.
Definition CubeAttribute.cpp:335
void setByteOrder(ByteOrder order)
Set the order according to the parameter order.
Definition CubeAttribute.cpp:511
bool propagateFileFormat() const
Return true if the file format is to be propagated from an input cube.
Definition CubeAttribute.cpp:182
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
Definition CubeAttribute.cpp:177
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
Definition CubeAttribute.cpp:165
Cube::Format fileFormat() const
Return the file format an Cube::Format.
Definition CubeAttribute.cpp:279
QString fileFormatString() const
Return the file format as a string.
Definition CubeAttribute.cpp:298
void setLabelAttachment(Cube::LabelAttachment attachment)
Set the label attachment type to the parameter value.
Definition CubeAttribute.cpp:421
QString byteOrderString() const
Return the byte order as a string.
Definition CubeAttribute.cpp:506
CubeAttributeOutput()
Constructs an empty CubeAttributeOutput.
Definition CubeAttribute.cpp:152
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
Definition CubeAttribute.cpp:386
void setMinimum(double min)
Set the output cube attribute minimum.
Definition CubeAttribute.cpp:350
void setMaximum(double max)
Set the output cube attribute maximum.
Definition CubeAttribute.cpp:368
Cube::LabelAttachment labelAttachment() const
Definition CubeAttribute.cpp:426
~CubeAttributeOutput()
Destroys the object.
Definition CubeAttribute.cpp:161
void setPixelType(PixelType type)
Set the pixel type to that given by the parameter.
Definition CubeAttribute.cpp:416
void setFileFormat(Cube::Format fmt)
Set the format to the fmt parameter.
Definition CubeAttribute.cpp:303
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
@ GdalLabel
Definition Cube.h:255
@ 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
File name manipulation and expansion.
Definition FileName.h:100
QString attributes() const
Returns a QString of the attributes in a filename, attributes are expected to be of type CubeAttribut...
Definition FileName.cpp:121
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
This is free and unencumbered software released into the public domain.
Definition BoxcarCachingAlgorithm.h:13
ByteOrder
Tests the current architecture for byte order.
Definition Endian.h:42
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.
Definition CubeAttribute.h:31
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:29
Cube::LabelAttachment LabelAttachmentEnumeration(const QString &labelType)
Return the appropriate LabelType depending on which of the valid values the argument spells.
Definition CubeAttribute.h:50