Isis 3.0 Programmer Reference
Back | Home
CubeAttribute.h
Go to the documentation of this file.
1 #ifndef CubeAttribute_h
2 #define CubeAttribute_h
3 
26 #include <typeinfo>
27 
28 #include <QDebug>
29 #include <QStringList>
30 
31 #include "Cube.h"
32 #include "Endian.h"
33 #include "FileName.h"
34 #include "IException.h"
35 #include "PixelType.h"
36 
37 
38 namespace Isis {
50 
57  };
58 
59 
68  inline QString LabelAttachmentName(LabelAttachment labelType) {
69  if(labelType == AttachedLabel) return "Attached";
70  if(labelType == DetachedLabel) return "Detached";
71  if(labelType == ExternalLabel) return "External";
72 
73  QString msg = "Invalid label attachment type [" + QString(labelType) + "]";
75  }
76 
77 
86  inline LabelAttachment LabelAttachmentEnumeration(const QString &labelType) {
87  QString temp = labelType.toUpper();
88  if(temp == "ATTACHED") return AttachedLabel;
89  if(temp == "DETACHED") return DetachedLabel;
90  if(temp == "External") return ExternalLabel;
91 
92  QString msg = "Invalid label attachment type string [" + labelType + "]";
94  }
95 
96 
97 
134  template<typename ChildClass> class CubeAttribute {
135  public:
136 
138  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers) {
139  m_attributeTypeTesters = testers;
140  }
141 
142 
154  CubeAttribute(QList< bool (ChildClass::*)(QString) const > testers,
155  const FileName &fileName) {
156  m_attributeTypeTesters = testers;
157  setAttributes(fileName);
158  }
159 
160 
162  virtual ~CubeAttribute() {
163  }
164 
165 
174  QString toString() const {
175  QString result;
176 
177  if (!m_attributes.isEmpty())
178  result = "+" + m_attributes.join("+");
179 
180  return result;
181  }
182 
183 
194  void addAttribute(QString attribute) {
195  QString upcaseAtt = attribute.toUpper();
196 
197  if (attribute.contains("+")) {
199  "Individual attributes (for example, BSQ) cannot contain the '+' "
200  "character because that is used to denote the separation of individual "
201  "attributes",
202  _FILEINFO_);
203  }
204 
205  // Verify this attribute is legal
206  bool legal = false;
207  bool (ChildClass::*tester)(QString) const;
208  foreach (tester, m_attributeTypeTesters) {
209  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
210  if (legal) {
212  QObject::tr("Attribute [%1] is ambiguous").arg(attribute),
213  _FILEINFO_);
214  }
215 
216  legal = true;
217  }
218  }
219 
220  if (!legal) {
222  QObject::tr("Attribute [%1] is not recognized").arg(attribute),
223  _FILEINFO_);
224  }
225 
226  m_attributes.append(attribute);
227  }
228 
229 
238  void addAttributes(const FileName &fileNameWithAtts) {
239  addAttributes(fileNameWithAtts.attributes());
240  }
241 
242 
251  void addAttributes(const char *attributesString) {
252  addAttributes(QString(attributesString));
253  }
254 
255 
264  void addAttributes(const QString &attributesString) {
265  setAttributes(toString() + "+" + attributesString);
266  }
267 
268 
278  void setAttributes(const FileName &fileName) {
279  QStringList attributes = fileName.attributes().split("+", QString::SkipEmptyParts);
280 
281  m_attributes.clear();
282  foreach (QString attribute, attributes)
283  addAttribute(attribute);
284  }
285 
286 
287  protected:
296  QStringList attributeList(bool (ChildClass::*tester)(QString) const) const {
297  QStringList relevantAttributes;
298 
299  foreach (QString attribute, m_attributes) {
300  QString upcaseAtt = attribute.toUpper();
301  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
302  relevantAttributes.append(upcaseAtt);
303  }
304  }
305 
306  return relevantAttributes;
307  }
308 
309 
321  void setAttribute(QString newValue, bool (ChildClass::*tester)(QString) const) {
322  QMutableListIterator<QString> it(m_attributes);
323 
324  bool found = false;
325  while (it.hasNext()) {
326  QString &attribute = it.next();
327 
328  QString upcaseAtt = attribute.toUpper();
329  if ( (static_cast<const ChildClass *>(this)->*tester)(upcaseAtt) ) {
330  if (found || newValue == "") {
331  // already found one (remove the duplicate) or just deleting it
332  it.remove();
333  }
334  else {
335  // modify existing attribute value
336  attribute = newValue;
337  }
338 
339  found = true;
340  }
341  }
342 
343  // Attribute doesn't exist, add it
344  if (!found && newValue != "") {
345  m_attributes.append(newValue);
346  }
347  }
348 
349  private:
356 
365  };
366 
367 
395  class CubeAttributeInput : public CubeAttribute<CubeAttributeInput> {
396 
397  public:
398 
401 
402 
412  CubeAttributeInput(const FileName &fileName);
413 
414 
417 
418 
420  std::vector<QString> bands() const;
421 
433  QString bandsString() const;
434 
436  void setBands(const std::vector<QString> &bands);
437 
439 
440  private:
441  bool isBandRange(QString attribute) const;
442 
443  static QString toString(const std::vector<QString> &bands);
445 
446  private:
447  std::vector<QString> m_bands;
448  };
449 
450 
485  class CubeAttributeOutput : public CubeAttribute<CubeAttributeOutput> {
486 
487  public:
488 
491 
504  CubeAttributeOutput(const FileName &fileName);
505 
506 
509 
510 
512  bool propagatePixelType() const;
513 
515  bool propagateMinimumMaximum() const;
516 
518  Cube::Format fileFormat() const;
519 
521  QString fileFormatString() const;
522 
524  void setFileFormat(Cube::Format fmt);
525 
527  ByteOrder byteOrder() const;
528 
530  QString byteOrderString() const;
531 
533  void setByteOrder(ByteOrder order);
534 
536  double minimum() const;
537 
539  double maximum() const;
540 
542  void setMinimum(double min);
543 
545  void setMaximum(double max);
546 
548  PixelType pixelType() const;
549 
551  void setPixelType(PixelType type);
552 
554  void setLabelAttachment(LabelAttachment attachment);
555 
556  LabelAttachment labelAttachment() const;
557 
559 
560 
561  private:
562  bool isByteOrder(QString attribute) const;
563  bool isFileFormat(QString attribute) const;
564  bool isLabelAttachment(QString attribute) const;
565  bool isPixelType(QString attribute) const;
566  bool isRange(QString attribute) const;
567 
568  static QString toString(Cube::Format);
569 
576  enum RangeType {
579  };
580 
582  };
583 };
584 
585 #endif
Manipulate and parse attributes of input cube filenames.
virtual ~CubeAttribute()
Destroys the object.
The label is pointing to an external DN file - the label is also external to the data.
Definition: CubeAttribute.h:56
LabelAttachment LabelAttachmentEnumeration(const QString &labelType)
Return the appropriate LabelType depending on which of the valid values the argument spells...
Definition: CubeAttribute.h:86
QString byteOrderString() const
Return the byte order as a string.
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
double maximum() const
Return the output cube attribute maximum.
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
File name manipulation and expansion.
Definition: FileName.h:111
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers)
Constructs an empty CubeAttribute.
void addAttribute(QString attribute)
Add a single attribute to these attributes.
void addAttributes(const char *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.
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:59
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
void setLabelAttachment(LabelAttachment attachment)
Set the label attachment type to the parameter value.
void setFileFormat(Cube::Format fmt)
Set the format to the fmt parameter.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:154
QList< bool(ChildClass::*)(QString) const > m_attributeTypeTesters
These testers determine if an attribute looks like a particular option.
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:43
CubeAttributeOutput()
Constructs an empty CubeAttributeOutput.
~CubeAttributeInput()
Destroys the object.
The input label is in a separate data file from the image.
Definition: CubeAttribute.h:49
void setAttribute(QString newValue, bool(ChildClass::*tester)(QString) const)
Set the attribute(s) for which tester returns true to newValue.
QStringList m_attributes
These are the attributes that this cube attribute stores.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
Manipulate and parse attributes of output cube filenames.
std::vector< QString > m_bands
A list of the specified bands.
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:126
QString LabelAttachmentName(LabelAttachment labelType)
Return the string representation of the contents of a variable of type LabelAttachment.
Definition: CubeAttribute.h:68
Cube::Format fileFormat() const
Return the file format an Cube::Format.
void addAttributes(const QString &attributesString)
Append the attributes in the string to these cube attributes.
The input label is embedded in the image file.
Definition: CubeAttribute.h:48
double minimum() const
Return the output cube attribute minimum.
void setPixelType(PixelType type)
Set the pixel type to that given by the parameter.
The range has been set.
void setMinimum(double min)
Set the output cube attribute minimum.
QString fileFormatString() const
Return the file format as a string.
void addAttributes(const FileName &fileNameWithAtts)
Append the attributes found in the filename to these cube attributes.
RangeType
Output cube range tracker.
~CubeAttributeOutput()
Destroys the object.
Isis exception class.
Definition: IException.h:99
std::vector< QString > bands() const
Return a vector of the input bands specified.
Propagate the range from an input cube.
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers, const FileName &fileName)
Constructs a CubeAttribute using the argument.
Parent class for CubeAttributeInput and CubeAttributeOutput.
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.
QString toString() const
Return a string-representation of this cube attributes.
CubeAttributeInput()
Constructs an empty CubeAttributeInput.
LabelAttachment
Input cube label type tracker.
Definition: CubeAttribute.h:47
Format
These are the possible storage formats of Isis3 cubes.
Definition: Cube.h:168
void setByteOrder(ByteOrder order)
Set the order according to the parameter order.
void setMaximum(double max)
Set the output cube attribute maximum.
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:16:55