Isis 3.0
Home
SpecialPixel.h
Go to the documentation of this file.
1 #ifndef SpecialPixel_h
2 #define SpecialPixel_h
3 
24 #include <vector>
25 #include <cmath>
26 #include <cfloat>
27 #include <QString>
28 #include <QStringList>
29 
30 #include "IException.h"
31 #include "IString.h"
32 
33 namespace Isis {
34 
84  // Set up special kludge for double precision initialization
86  typedef union {
87  unsigned int i[2];
88  double d;
89  } DBL_UNION;
90 
91 #if ISIS_LITTLE_ENDIAN
92 # define DBL_INIT(a,b) {(b), (a)}
93 #else
94 # define DBL_INIT(a,b) {(a), (b)}
95 #endif
96 
98  // Define 8-byte special pixel values for IEEE floating point
99  const DBL_UNION IVALID_MIN8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFA) };
100  const double VALID_MIN8 = IVALID_MIN8.d;
101  const double ValidMinimum = IVALID_MIN8.d;
107  const DBL_UNION INULL8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFB) };
108  const double NULL8 = INULL8.d;
109  const double Null = INULL8.d;
110 
111  const DBL_UNION ILOW_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFC) };
112  const double LOW_REPR_SAT8 = ILOW_REPR_SAT8.d;
113  const double Lrs = ILOW_REPR_SAT8.d;
117  const DBL_UNION ILOW_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFD) };
118  const double LOW_INSTR_SAT8 = ILOW_INSTR_SAT8.d;
119  const double Lis = ILOW_INSTR_SAT8.d;
123  const DBL_UNION IHIGH_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFE) };
125  const double His = IHIGH_INSTR_SAT8.d;
129  const DBL_UNION IHIGH_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFF) };
130  const double HIGH_REPR_SAT8 = IHIGH_REPR_SAT8.d;
131  const double Hrs = IHIGH_REPR_SAT8.d;
135  const double VALID_MAX8 = DBL_MAX;
136  const double ValidMaximum = DBL_MAX;
140 #undef DBL_INIT
141 
142  // Define 4-byte special pixel values for IEEE floating point
143  const int IVALID_MIN4 = 0xFF7FFFFA;
144  const float VALID_MIN4 = (*((const float *) &IVALID_MIN4));
145 
146  const int INULL4 = 0xFF7FFFFB;
147  const float NULL4 = (*((const float *) &INULL4));
148 
149  const int ILOW_REPR_SAT4 = 0xFF7FFFFC;
150  const float LOW_REPR_SAT4 = (*((const float *) &ILOW_REPR_SAT4));
151 
152  const int ILOW_INSTR_SAT4 = 0xFF7FFFFD;
153  const float LOW_INSTR_SAT4 = (*((const float *) &ILOW_INSTR_SAT4));
154 
155  const int IHIGH_INSTR_SAT4 = 0xFF7FFFFE;
156  const float HIGH_INSTR_SAT4 = (*((const float *) &IHIGH_INSTR_SAT4));
157 
158  const int IHIGH_REPR_SAT4 = 0xFF7FFFFF;
159  const float HIGH_REPR_SAT4 = (*((const float *) &IHIGH_REPR_SAT4));
160 
161  const float VALID_MAX4 = FLT_MAX;
162  const int IVALID_MAX4 = (*((const int *) &VALID_MAX4));
163 
164  // 2-byte signed special pixel values
165  const short VALID_MIN2 = ((short)(-32752));
166  const short NULL2 = ((short)(-32768));
167  const short LOW_REPR_SAT2 = ((short)(-32767));
168  const short LOW_INSTR_SAT2 = ((short)(-32766));
169  const short HIGH_INSTR_SAT2 = ((short)(-32765));
170  const short HIGH_REPR_SAT2 = ((short)(-32764));
171  const short VALID_MAX2 = ((short) 32767);
172 
173  // 2-byte unsigned special pixel values
174  const unsigned short VALID_MINU2 = ((unsigned short) 3);
175  const unsigned short NULLU2 = ((unsigned short) 0);
176  const unsigned short LOW_REPR_SATU2 = ((unsigned short) 1);
177  const unsigned short LOW_INSTR_SATU2 = ((unsigned short) 2);
178  const unsigned short HIGH_INSTR_SATU2 = ((unsigned short) 65534);
179  const unsigned short HIGH_REPR_SATU2 = ((unsigned short) 65535);
180  const unsigned short VALID_MAXU2 = ((unsigned short) 65522);
181 
182  // 1-byte special pixel values
183  const unsigned char VALID_MIN1 = ((unsigned char) 1);
184  const unsigned char NULL1 = ((unsigned char) 0);
185  const unsigned char LOW_REPR_SAT1 = ((unsigned char) 0);
186  const unsigned char LOW_INSTR_SAT1 = ((unsigned char) 0);
187  const unsigned char HIGH_INSTR_SAT1 = ((unsigned char) 255);
188  const unsigned char HIGH_REPR_SAT1 = ((unsigned char) 255);
189  const unsigned char VALID_MAX1 = ((unsigned char) 254);
190 
199  inline bool IsSpecial(const double d) {
200  return (d < VALID_MIN8);
201  }
202 
203 
213  inline bool IsSpecial(const float f) {
214  return (f < VALID_MIN4);
215  }
216 
217 
225  inline bool IsValidPixel(const double d) {
226  return (d >= VALID_MIN8);
227  }
228 
229 
237  inline bool IsNullPixel(const double d) {
238  return (d == NULL8);
239  }
240 
241 
249  inline bool IsHighPixel(const double d) {
250  return (d == HIGH_REPR_SAT8) || (d == HIGH_INSTR_SAT8);
251  }
252 
253 
261  inline bool IsLowPixel(const double d) {
262  return (d == LOW_REPR_SAT8) || (d == LOW_INSTR_SAT8);
263  }
264 
265 
273  inline bool IsHrsPixel(const double d) {
274  return (d == HIGH_REPR_SAT8);
275  }
276 
277 
285  inline bool IsHisPixel(const double d) {
286  return (d == HIGH_INSTR_SAT8);
287  }
288 
289 
297  inline bool IsLisPixel(const double d) {
298  return (d == LOW_INSTR_SAT8);
299  }
300 
301 
309  inline bool IsLrsPixel(const double d) {
310  return (d == LOW_REPR_SAT8);
311  }
312 
313 
321  inline double TestPixel(const float t) {
322  if(t < VALID_MIN4) {
323  if(t == NULL4) return (NULL8);
324  if(t == LOW_REPR_SAT4) return (LOW_REPR_SAT8);
325  if(t == LOW_INSTR_SAT4) return (LOW_INSTR_SAT8);
326  if(t == HIGH_REPR_SAT4) return (HIGH_REPR_SAT8);
327  if(t == HIGH_INSTR_SAT4) return (HIGH_INSTR_SAT8);
328  return (LOW_REPR_SAT8);
329  }
330  else if(t > VALID_MAX4) {
331  return (HIGH_REPR_SAT8);
332  }
333  else {
334  return ((double) t);
335  }
336  }
337 
338 
347  inline float TestPixel(const double t) {
348  if(t < (double) VALID_MIN4) {
349  if(t == NULL8) return (NULL4);
350  if(t == LOW_REPR_SAT8) return (LOW_REPR_SAT4);
351  if(t == LOW_INSTR_SAT8) return (LOW_INSTR_SAT4);
352  if(t == HIGH_INSTR_SAT8) return (HIGH_INSTR_SAT4);
353  if(t == HIGH_REPR_SAT8) return (HIGH_REPR_SAT4);
354  return (LOW_REPR_SAT4);
355  }
356  else if(t > (double) VALID_MAX4) {
357  return (HIGH_REPR_SAT8);
358  }
359  else {
360  return ((float) t);
361  }
362  }
363 
364 
373  inline QString PixelToString(double d) {
374  if(Isis::IsSpecial(d)) {
375  if(Isis::IsNullPixel(d)) return "Null";
376  if(Isis::IsLrsPixel(d)) return "Lrs";
377  if(Isis::IsHrsPixel(d)) return "Hrs";
378  if(Isis::IsHisPixel(d)) return "His";
379  if(Isis::IsLisPixel(d)) return "Lis";
380  return "Invalid";
381  }
382 
383  QString result;
384  return result.setNum(d, 'g', 8);
385  }
386 
387 
396  inline double StringToPixel(const QString &str) {
397 
398  QString s = str.toUpper();
399 
400  QStringList legal;
401  legal.push_back("NULL");
402  legal.push_back("HRS");
403  legal.push_back("LRS");
404  legal.push_back("HIS");
405  legal.push_back("LIS");
406  int matches = 0;
407  for(int i = 0; i < (int) legal.size(); i++) {
408  if(legal[i].mid(0, s.size()) == s) {
409  matches++;
410  }
411  }
412  if(matches > 1) {
413  QString msg = "Input [" + str + "] is not a unique abbreviation. Use " + s + "I or " + s + "R.";
415  }
416  if(matches == 0) {
417  try {
418  return toDouble(s);
419  }
420  catch(IException &e) {
421  QString msg = "Input [" + str + "] does not appear to be a legal special pixel abbreviation or double value.";
422  throw IException(e, IException::User, msg, _FILEINFO_);
423  }
424  }
425  if(s[0] == 'N') return Null;
426  if(s.mid(0, 2) == "HR") return Hrs;
427  if(s.mid(0, 2) == "LR") return Lrs;
428  if(s.mid(0, 2) == "HI") return His;
429  else return Lis;//(s.substr(0,2) == "LI")
430 
431  }
432 }
433 
434 #endif
435 
const int IVALID_MAX4
Definition: SpecialPixel.h:162
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
Definition: SpecialPixel.h:297
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:109
const unsigned char VALID_MAX1
Definition: SpecialPixel.h:189
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
Definition: SpecialPixel.h:309
const unsigned char LOW_REPR_SAT1
Definition: SpecialPixel.h:185
const double ValidMinimum
The minimum valid double value for Isis pixels.
Definition: SpecialPixel.h:101
const float HIGH_REPR_SAT4
Definition: SpecialPixel.h:159
const unsigned short HIGH_INSTR_SATU2
Definition: SpecialPixel.h:178
const unsigned char HIGH_INSTR_SAT1
Definition: SpecialPixel.h:187
const double NULL8
Definition: SpecialPixel.h:108
bool IsLowPixel(const double d)
Returns if the input pixel is one of the low saturation types.
Definition: SpecialPixel.h:261
const DBL_UNION IHIGH_INSTR_SAT8
Definition: SpecialPixel.h:123
const unsigned short VALID_MAXU2
Definition: SpecialPixel.h:180
double StringToPixel(const QString &str)
Takes the name of the pixel type as a string and returns a double pixel value.
Definition: SpecialPixel.h:396
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
Definition: SpecialPixel.h:225
const double VALID_MAX8
Definition: SpecialPixel.h:135
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:164
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
Definition: SpecialPixel.h:285
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
Definition: SpecialPixel.h:273
const unsigned short HIGH_REPR_SATU2
Definition: SpecialPixel.h:179
const unsigned short VALID_MINU2
Definition: SpecialPixel.h:174
const double Lis
Value for an Isis Low Instrument Saturation pixel.
Definition: SpecialPixel.h:119
const double LOW_REPR_SAT8
Definition: SpecialPixel.h:112
const float LOW_INSTR_SAT4
Definition: SpecialPixel.h:153
const int IHIGH_INSTR_SAT4
Definition: SpecialPixel.h:155
const float HIGH_INSTR_SAT4
Definition: SpecialPixel.h:156
const int IHIGH_REPR_SAT4
Definition: SpecialPixel.h:158
const DBL_UNION IVALID_MIN8
Manipulate special pixel values.
Definition: SpecialPixel.h:99
const short HIGH_REPR_SAT2
Definition: SpecialPixel.h:170
const int IVALID_MIN4
Definition: SpecialPixel.h:143
const double HIGH_INSTR_SAT8
Definition: SpecialPixel.h:124
const int ILOW_REPR_SAT4
Definition: SpecialPixel.h:149
const short LOW_INSTR_SAT2
Definition: SpecialPixel.h:168
const short HIGH_INSTR_SAT2
Definition: SpecialPixel.h:169
const DBL_UNION INULL8
Definition: SpecialPixel.h:107
const DBL_UNION ILOW_REPR_SAT8
Definition: SpecialPixel.h:111
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
const short VALID_MIN2
Definition: SpecialPixel.h:165
double TestPixel(const float t)
Converts float pixels to double pixels with special pixel translations.
Definition: SpecialPixel.h:321
const double HIGH_REPR_SAT8
Definition: SpecialPixel.h:130
const unsigned short LOW_INSTR_SATU2
Definition: SpecialPixel.h:177
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:134
const float VALID_MIN4
Definition: SpecialPixel.h:144
const float VALID_MAX4
Definition: SpecialPixel.h:161
const short VALID_MAX2
Definition: SpecialPixel.h:171
const int INULL4
Definition: SpecialPixel.h:146
const unsigned short LOW_REPR_SATU2
Definition: SpecialPixel.h:176
const DBL_UNION ILOW_INSTR_SAT8
Definition: SpecialPixel.h:117
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:199
const unsigned char VALID_MIN1
Definition: SpecialPixel.h:183
const double VALID_MIN8
Definition: SpecialPixel.h:100
const float LOW_REPR_SAT4
Definition: SpecialPixel.h:150
const unsigned char HIGH_REPR_SAT1
Definition: SpecialPixel.h:188
const float NULL4
Definition: SpecialPixel.h:147
const double LOW_INSTR_SAT8
Definition: SpecialPixel.h:118
const double ValidMaximum
The maximum valid double value for Isis pixels.
Definition: SpecialPixel.h:136
const short LOW_REPR_SAT2
Definition: SpecialPixel.h:167
const unsigned short NULLU2
Definition: SpecialPixel.h:175
bool IsHighPixel(const double d)
Returns if the input pixel is one of the high saturation types.
Definition: SpecialPixel.h:249
QString PixelToString(double d)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition: SpecialPixel.h:373
Isis exception class.
Definition: IException.h:99
bool IsNullPixel(const double d)
Returns if the input pixel is null.
Definition: SpecialPixel.h:237
const double Lrs
Value for an Isis Low Representation Saturation pixel.
Definition: SpecialPixel.h:113
const DBL_UNION IHIGH_REPR_SAT8
Definition: SpecialPixel.h:129
const short NULL2
Definition: SpecialPixel.h:166
const double His
Value for an Isis High Instrument Saturation pixel.
Definition: SpecialPixel.h:125
const unsigned char LOW_INSTR_SAT1
Definition: SpecialPixel.h:186
const int ILOW_INSTR_SAT4
Definition: SpecialPixel.h:152
const unsigned char NULL1
Definition: SpecialPixel.h:184
const double Hrs
Value for an Isis High Representation Saturation pixel.
Definition: SpecialPixel.h:131