Isis Developer Reference
CubeAttribute.h
Go to the documentation of this file.
1 #ifndef CubeAttribute_h
2 #define CubeAttribute_h
3 
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 
22 namespace Isis {
34 
41  };
42 
43 
52  inline QString LabelAttachmentName(LabelAttachment labelType) {
53  if(labelType == AttachedLabel) return "Attached";
54  if(labelType == DetachedLabel) return "Detached";
55  if(labelType == ExternalLabel) return "External";
56 
57  QString msg = "Invalid label attachment type [" + QString::number(labelType) + "]";
59  }
60 
61 
70  inline LabelAttachment LabelAttachmentEnumeration(const QString &labelType) {
71  QString temp = labelType.toUpper();
72  if(temp == "ATTACHED") return AttachedLabel;
73  if(temp == "DETACHED") return DetachedLabel;
74  if(temp == "External") return ExternalLabel;
75 
76  QString msg = "Invalid label attachment type string [" + labelType + "]";
78  }
79 
80 
81 
118  template<typename ChildClass> class CubeAttribute {
119  public:
120 
122  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers) {
123  m_attributeTypeTesters = testers;
124  }
125 
126 
138  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers,
139  const FileName &fileName) {
140  m_attributeTypeTesters = testers;
141  setAttributes(fileName);
142  }
143 
144 
146  virtual ~CubeAttribute() {
147  }
148 
149 
158  QString toString() const {
159  QString result;
160 
161  if (!m_attributes.isEmpty())
162  result = "+" + m_attributes.join("+");
163 
164  return result;
165  }
166 
167 
178  void addAttribute(QString attribute) {
179  QString upcaseAtt = attribute.toUpper();
180 
181  if (attribute.contains("+")) {
183  "Individual attributes (for example, BSQ) cannot contain the '+' "
184  "character because that is used to denote the separation of individual "
185  "attributes",
186  _FILEINFO_);
187  }
188 
189  // Verify this attribute is legal
190  bool legal = false;
191  bool (ChildClass::*tester)(QString) const;
192  foreach (tester, m_attributeTypeTesters) {
193  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
194  if (legal) {
196  QObject::tr("Attribute [%1] is ambiguous").arg(attribute),
197  _FILEINFO_);
198  }
199 
200  legal = true;
201  }
202  }
203 
204  if (!legal) {
206  QObject::tr("Attribute [%1] is not recognized").arg(attribute),
207  _FILEINFO_);
208  }
209 
210  m_attributes.append(attribute);
211  }
212 
213 
222  void addAttributes(const FileName &fileNameWithAtts) {
223  addAttributes(fileNameWithAtts.attributes());
224  }
225 
226 
235  void addAttributes(const char *attributesString) {
236  addAttributes(QString(attributesString));
237  }
238 
239 
248  void addAttributes(const QString &attributesString) {
249  setAttributes(toString() + "+" + attributesString);
250  }
251 
252 
262  void setAttributes(const FileName &fileName) {
263  QStringList attributes = fileName.attributes().split("+", QString::SkipEmptyParts);
264 
265  m_attributes.clear();
266  foreach (QString attribute, attributes)
267  addAttribute(attribute);
268  }
269 
270 
271  protected:
280  QStringList attributeList(bool (ChildClass::*tester)(QString) const) const {
281  QStringList relevantAttributes;
282 
283  foreach (QString attribute, m_attributes) {
284  QString upcaseAtt = attribute.toUpper();
285  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
286  relevantAttributes.append(upcaseAtt);
287  }
288  }
289 
290  return relevantAttributes;
291  }
292 
293 
305  void setAttribute(QString newValue, bool (ChildClass::*tester)(QString) const) {
306  QMutableListIterator<QString> it(m_attributes);
307 
308  bool found = false;
309  while (it.hasNext()) {
310  QString &attribute = it.next();
311 
312  QString upcaseAtt = attribute.toUpper();
313  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
314  if (found || newValue == "") {
315  // already found one (remove the duplicate) or just deleting it
316  it.remove();
317  }
318  else {
319  // modify existing attribute value
320  attribute = newValue;
321  }
322 
323  found = true;
324  }
325  }
326 
327  // Attribute doesn't exist, add it
328  if (!found && newValue != "") {
329  m_attributes.append(newValue);
330  }
331  }
332 
333  private:
339  QStringList m_attributes;
340 
348  QList< bool (ChildClass::*)(QString) const > m_attributeTypeTesters;
349  };
350 
351 
381  class CubeAttributeInput : public CubeAttribute<CubeAttributeInput> {
382 
383  public:
384 
387 
388 
398  CubeAttributeInput(const FileName &fileName);
399 
400 
403 
404 
406  std::vector<QString> bands() const;
407 
419  QString bandsString() const;
420 
422  void setBands(const std::vector<QString> &bands);
423 
425 
426  private:
427  bool isBandRange(QString attribute) const;
428 
429  static QString toString(const std::vector<QString> &bands);
430  static QList<bool (CubeAttributeInput::*)(QString) const> testers();
431 
432  private:
433  std::vector<QString> m_bands;
434  };
435 
436 
473  class CubeAttributeOutput : public CubeAttribute<CubeAttributeOutput> {
474 
475  public:
476 
479 
492  CubeAttributeOutput(const FileName &fileName);
493 
494 
497 
498 
500  bool propagatePixelType() const;
501 
503  bool propagateMinimumMaximum() const;
504 
506  Cube::Format fileFormat() const;
507 
509  QString fileFormatString() const;
510 
512  void setFileFormat(Cube::Format fmt);
513 
515  ByteOrder byteOrder() const;
516 
518  QString byteOrderString() const;
519 
521  void setByteOrder(ByteOrder order);
522 
524  double minimum() const;
525 
527  double maximum() const;
528 
530  void setMinimum(double min);
531 
533  void setMaximum(double max);
534 
536  PixelType pixelType() const;
537 
539  void setPixelType(PixelType type);
540 
542  void setLabelAttachment(LabelAttachment attachment);
543 
545 
547 
548 
549  private:
550  bool isByteOrder(QString attribute) const;
551  bool isFileFormat(QString attribute) const;
552  bool isLabelAttachment(QString attribute) const;
553  bool isPixelType(QString attribute) const;
554  bool isRange(QString attribute) const;
555 
556  static QString toString(Cube::Format);
557 
564  enum RangeType {
565  PropagateRange,
566  RangeSet,
567  };
568 
569  static QList<bool (CubeAttributeOutput::*)(QString) const> testers();
570  };
571 };
572 
573 #endif
Isis::Cube::Format
Format
These are the possible storage formats of ISIS cubes.
Definition: Cube.h:178
FileName.h
Isis::CubeAttributeOutput::setMaximum
void setMaximum(double max)
Set the output cube attribute maximum.
Definition: CubeAttribute.cpp:342
Cube.h
Isis::DetachedLabel
@ DetachedLabel
The input label is in a separate data file from the image.
Definition: CubeAttribute.h:33
Isis::CubeAttributeInput::~CubeAttributeInput
~CubeAttributeInput()
Destroys the object.
Definition: CubeAttribute.cpp:34
Isis::CubeAttributeOutput::setPixelType
void setPixelType(PixelType type)
Set the pixel type to that given by the parameter.
Definition: CubeAttribute.cpp:390
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::CubeAttribute::CubeAttribute
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers, const FileName &fileName)
Constructs a CubeAttribute using the argument.
Definition: CubeAttribute.h:138
Isis::LabelAttachmentName
QString LabelAttachmentName(LabelAttachment labelType)
Return the string representation of the contents of a variable of type LabelAttachment.
Definition: CubeAttribute.h:52
Isis::CubeAttribute< CubeAttributeOutput >::attributeList
QStringList attributeList(bool(ChildClass::*tester)(QString) const) const
Get a list of attributes that the tester returns true on.
Definition: CubeAttribute.h:280
Isis::IsLsb
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition: Endian.h:67
SpecialPixel.h
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::CubeAttribute< CubeAttributeOutput >::setAttribute
void setAttribute(QString newValue, bool(ChildClass::*tester)(QString) const)
Set the attribute(s) for which tester returns true to newValue.
Definition: CubeAttribute.h:305
Isis::CubeAttribute::~CubeAttribute
virtual ~CubeAttribute()
Destroys the object.
Definition: CubeAttribute.h:146
Isis::CubeAttribute::addAttributes
void addAttributes(const QString &attributesString)
Append the attributes in the string to these cube attributes.
Definition: CubeAttribute.h:248
Isis::UnsignedWord
@ UnsignedWord
Definition: PixelType.h:31
Isis::CubeAttributeOutput
Manipulate and parse attributes of output cube filenames.
Definition: CubeAttribute.h:473
Isis::SignedWord
@ SignedWord
Definition: PixelType.h:32
QStringList
Preference.h
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::IsSpecial
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:197
Isis::CubeAttributeOutput::setFileFormat
void setFileFormat(Cube::Format fmt)
Set the format to the fmt parameter.
Definition: CubeAttribute.cpp:288
Isis::CubeAttribute::addAttributes
void addAttributes(const char *attributesString)
Append the attributes in the string to these cube attributes.
Definition: CubeAttribute.h:235
Isis::ByteOrder
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:42
Isis::CubeAttributeInput::bandsString
QString bandsString() const
Return a string representation of all the bands.
Definition: CubeAttribute.cpp:112
Isis::LabelAttachmentEnumeration
LabelAttachment LabelAttachmentEnumeration(const QString &labelType)
Return the appropriate LabelType depending on which of the valid values the argument spells.
Definition: CubeAttribute.h:70
Isis::CubeAttribute::addAttributes
void addAttributes(const FileName &fileNameWithAtts)
Append the attributes found in the filename to these cube attributes.
Definition: CubeAttribute.h:222
Isis::CubeAttribute< CubeAttributeInput >::setAttributes
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
Definition: CubeAttribute.h:262
Endian.h
Isis::AttachedLabel
@ AttachedLabel
The input label is embedded in the image file.
Definition: CubeAttribute.h:32
Isis::CubeAttributeOutput::setByteOrder
void setByteOrder(ByteOrder order)
Set the order according to the parameter order.
Definition: CubeAttribute.cpp:474
Isis::LabelAttachment
LabelAttachment
Input cube label type tracker.
Definition: CubeAttribute.h:31
PixelType.h
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::toInt
int toInt(const QString &string)
Global function to convert from a string to an integer.
Definition: IString.cpp:93
Isis::Cube::Tile
@ Tile
Cubes are stored in tile format, that is the order of the pixels in the file (on disk) is BSQ within ...
Definition: Cube.h:232
Isis::CubeAttributeOutput::pixelType
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
Definition: CubeAttribute.cpp:360
Isis::CubeAttributeOutput::propagateMinimumMaximum
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
Definition: CubeAttribute.cpp:177
Isis::CubeAttributeInput::setBands
void setBands(const std::vector< QString > &bands)
Set the band attribute according to the list of bands.
Definition: CubeAttribute.cpp:117
Isis::Msb
@ Msb
Definition: Endian.h:45
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::CubeAttributeOutput::byteOrderString
QString byteOrderString() const
Return the byte order as a string.
Definition: CubeAttribute.cpp:469
Isis::CubeAttributeOutput::fileFormatString
QString fileFormatString() const
Return the file format as a string.
Definition: CubeAttribute.cpp:283
Isis::CubeAttributeOutput::CubeAttributeOutput
CubeAttributeOutput()
Constructs an empty CubeAttributeOutput.
Definition: CubeAttribute.cpp:152
Isis::CubeAttributeOutput::~CubeAttributeOutput
~CubeAttributeOutput()
Destroys the object.
Definition: CubeAttribute.cpp:161
Isis::CubeAttributeInput::CubeAttributeInput
CubeAttributeInput()
Constructs an empty CubeAttributeInput.
Definition: CubeAttribute.cpp:25
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Isis::Cube::Bsq
@ Bsq
Cubes are stored in band-sequential format, that is the order of the pixels in the file (on disk) is:
Definition: Cube.h:199
Isis::CubeAttributeOutput::labelAttachment
LabelAttachment labelAttachment() const
Definition: CubeAttribute.cpp:400
Isis::PixelType
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:27
Isis::UnsignedInteger
@ UnsignedInteger
Definition: PixelType.h:33
IException.h
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
Isis::CubeAttributeInput::bands
std::vector< QString > bands() const
Return a vector of the input bands specified.
Definition: CubeAttribute.cpp:82
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
std
Namespace for the standard library.
Isis::CubeAttributeOutput::byteOrder
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
Definition: CubeAttribute.cpp:455
Isis::CubeAttributeOutput::setLabelAttachment
void setLabelAttachment(LabelAttachment attachment)
Set the label attachment type to the parameter value.
Definition: CubeAttribute.cpp:395
Isis::PixelTypeName
QString PixelTypeName(Isis::PixelType pixelType)
Returns string name of PixelType enumeration entered as input parameter.
Definition: PixelType.h:66
Isis::SignedInteger
@ SignedInteger
Definition: PixelType.h:34
Isis::CubeAttributeInput
Manipulate and parse attributes of input cube filenames.
Definition: CubeAttribute.h:381
Isis::CubeAttributeOutput::maximum
double maximum() const
Return the output cube attribute maximum.
Definition: CubeAttribute.cpp:309
Isis::CubeAttributeOutput::minimum
double minimum() const
Return the output cube attribute minimum.
Definition: CubeAttribute.cpp:294
Isis::ByteOrderName
QString ByteOrderName(Isis::ByteOrder byteOrder)
Definition: Endian.h:48
Isis::CubeAttribute::CubeAttribute
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers)
Constructs an empty CubeAttribute.
Definition: CubeAttribute.h:122
Isis::Lsb
@ Lsb
Definition: Endian.h:44
Isis::CubeAttributeOutput::fileFormat
Cube::Format fileFormat() const
Return the file format an Cube::Format.
Definition: CubeAttribute.cpp:267
Isis::CubeAttribute
Parent class for CubeAttributeInput and CubeAttributeOutput.
Definition: CubeAttribute.h:118
Isis::UnsignedByte
@ UnsignedByte
Definition: PixelType.h:29
Isis::CubeAttributeOutput::propagatePixelType
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
Definition: CubeAttribute.cpp:165
Isis::ExternalLabel
@ ExternalLabel
The label is pointing to an external DN file - the label is also external to the data.
Definition: CubeAttribute.h:40
Isis::CubeAttribute::addAttribute
void addAttribute(QString attribute)
Add a single attribute to these attributes.
Definition: CubeAttribute.h:178
Isis::CubeAttributeOutput::setMinimum
void setMinimum(double min)
Set the output cube attribute minimum.
Definition: CubeAttribute.cpp:324
CubeAttribute.h
Isis::FileName::attributes
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
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::CubeAttribute< CubeAttributeInput >::toString
QString toString() const
Return a string-representation of this cube attributes.
Definition: CubeAttribute.h:158
Isis::Real
@ Real
Definition: PixelType.h:35
Isis::None
@ None
Definition: PixelType.h:28