Isis 3 Programmer Reference
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::number(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 
397  class CubeAttributeInput : public CubeAttribute<CubeAttributeInput> {
398 
399  public:
400 
403 
404 
414  CubeAttributeInput(const FileName &fileName);
415 
416 
419 
420 
422  std::vector<QString> bands() const;
423 
435  QString bandsString() const;
436 
438  void setBands(const std::vector<QString> &bands);
439 
441 
442  private:
443  bool isBandRange(QString attribute) const;
444 
445  static QString toString(const std::vector<QString> &bands);
447 
448  private:
449  std::vector<QString> m_bands;
450  };
451 
452 
489  class CubeAttributeOutput : public CubeAttribute<CubeAttributeOutput> {
490 
491  public:
492 
495 
508  CubeAttributeOutput(const FileName &fileName);
509 
510 
513 
514 
516  bool propagatePixelType() const;
517 
519  bool propagateMinimumMaximum() const;
520 
522  Cube::Format fileFormat() const;
523 
525  QString fileFormatString() const;
526 
528  void setFileFormat(Cube::Format fmt);
529 
531  ByteOrder byteOrder() const;
532 
534  QString byteOrderString() const;
535 
537  void setByteOrder(ByteOrder order);
538 
540  double minimum() const;
541 
543  double maximum() const;
544 
546  void setMinimum(double min);
547 
549  void setMaximum(double max);
550 
552  PixelType pixelType() const;
553 
555  void setPixelType(PixelType type);
556 
558  void setLabelAttachment(LabelAttachment attachment);
559 
560  LabelAttachment labelAttachment() const;
561 
563 
564 
565  private:
566  bool isByteOrder(QString attribute) const;
567  bool isFileFormat(QString attribute) const;
568  bool isLabelAttachment(QString attribute) const;
569  bool isPixelType(QString attribute) const;
570  bool isRange(QString attribute) const;
571 
572  static QString toString(Cube::Format);
573 
580  enum RangeType {
583  };
584 
586  };
587 };
588 
589 #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
PixelType pixelType() const
Return the pixel type as an Isis::PixelType.
LabelAttachment LabelAttachmentEnumeration(const QString &labelType)
Return the appropriate LabelType depending on which of the valid values the argument spells...
Definition: CubeAttribute.h:86
ByteOrder byteOrder() const
Return the byte order as an Isis::ByteOrder.
File name manipulation and expansion.
Definition: FileName.h:116
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.
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:59
bool propagatePixelType() const
Return true if the pixel type is to be propagated from an input cube.
void setAttributes(const FileName &fileName)
Replaces the current attributes with the attributes in the given file name.
bool propagateMinimumMaximum() const
Return true if the min/max are to be propagated from an input cube.
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.
QString byteOrderString() const
Return the byte order as a string.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
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:40
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:134
QString LabelAttachmentName(LabelAttachment labelType)
Return the string representation of the contents of a variable of type LabelAttachment.
Definition: CubeAttribute.h:68
double maximum() const
Return the output cube attribute maximum.
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
Cube::Format fileFormat() const
Return the file format an Cube::Format.
void setPixelType(PixelType type)
Set the pixel type to that given by the parameter.
QString fileFormatString() const
Return the file format as a string.
The range has been set.
void setMinimum(double min)
Set the output cube attribute minimum.
QString bandsString() const
Return a string representation of all the bands.
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:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Propagate the range from an input cube.
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers)
Constructs an empty CubeAttribute.
std::vector< QString > bands() const
Return a vector of the input bands specified.
Parent class for CubeAttributeInput and CubeAttributeOutput.
void setBands(const std::vector< QString > &bands)
Set the band attribute according to the list of bands.
QString attributes() const
Returns a QString of the attributes in a filename, attributes are expected to be of type CubeAttribut...
Definition: FileName.cpp:137
double minimum() const
Return the output cube attribute minimum.
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:180
QString toString() const
Return a string-representation of this cube attributes.
void setByteOrder(ByteOrder order)
Set the order according to the parameter order.
void setMaximum(double max)
Set the output cube attribute maximum.
CubeAttribute(QList< bool(ChildClass::*)(QString) const > testers, const FileName &fileName)
Constructs a CubeAttribute using the argument.
QStringList attributeList(bool(ChildClass::*tester)(QString) const) const
Get a list of attributes that the tester returns true on.