Isis 3 Developer Reference
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 
85  // Set up special kludge for double precision initialization
87  typedef union {
88  unsigned int i[2];
89  double d;
90  } DBL_UNION;
91 
92 #if ISIS_LITTLE_ENDIAN
93 # define DBL_INIT(a,b) {(b), (a)}
94 #else
95 # define DBL_INIT(a,b) {(a), (b)}
96 #endif
97 
99  // Define 8-byte special pixel values for IEEE floating point
100  const DBL_UNION IVALID_MIN8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFA) };
101  const double VALID_MIN8 = IVALID_MIN8.d;
102  const double ValidMinimum = IVALID_MIN8.d;
108  const DBL_UNION INULL8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFB) };
109  const double NULL8 = INULL8.d;
110  const double Null = INULL8.d;
111 
112  const DBL_UNION ILOW_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFC) };
113  const double LOW_REPR_SAT8 = ILOW_REPR_SAT8.d;
114  const double Lrs = ILOW_REPR_SAT8.d;
118  const DBL_UNION ILOW_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFD) };
119  const double LOW_INSTR_SAT8 = ILOW_INSTR_SAT8.d;
120  const double Lis = ILOW_INSTR_SAT8.d;
124  const DBL_UNION IHIGH_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFE) };
126  const double His = IHIGH_INSTR_SAT8.d;
130  const DBL_UNION IHIGH_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFF) };
131  const double HIGH_REPR_SAT8 = IHIGH_REPR_SAT8.d;
132  const double Hrs = IHIGH_REPR_SAT8.d;
136  const double VALID_MAX8 = DBL_MAX;
137  const double ValidMaximum = DBL_MAX;
141 #undef DBL_INIT
142 
143  // Define 4-byte special pixel values for IEEE floating point
144  const int IVALID_MIN4 = 0xFF7FFFFA;
145  const float VALID_MIN4 = (*((const float *) &IVALID_MIN4));
146 
147 
148  const int INULL4 = 0xFF7FFFFB;
149  const float NULL4 = (*((const float *) &INULL4));
150 
151  const int ILOW_REPR_SAT4 = 0xFF7FFFFC;
152  const float LOW_REPR_SAT4 = (*((const float *) &ILOW_REPR_SAT4));
153 
154  const int ILOW_INSTR_SAT4 = 0xFF7FFFFD;
155  const float LOW_INSTR_SAT4 = (*((const float *) &ILOW_INSTR_SAT4));
156 
157  const int IHIGH_INSTR_SAT4 = 0xFF7FFFFE;
158  const float HIGH_INSTR_SAT4 = (*((const float *) &IHIGH_INSTR_SAT4));
159 
160  const int IHIGH_REPR_SAT4 = 0xFF7FFFFF;
161  const float HIGH_REPR_SAT4 = (*((const float *) &IHIGH_REPR_SAT4));
162 
163 
164  const float VALID_MAX4 = FLT_MAX;
165  const int IVALID_MAX4 = (*((const int *) &VALID_MAX4));
166 
167  // 2-byte signed special pixel values
168  const short VALID_MIN2 = ((short)(-32752));
169  const short NULL2 = ((short)(-32768));
170  const short LOW_REPR_SAT2 = ((short)(-32767));
171  const short LOW_INSTR_SAT2 = ((short)(-32766));
172  const short HIGH_INSTR_SAT2 = ((short)(-32765));
173  const short HIGH_REPR_SAT2 = ((short)(-32764));
174  const short VALID_MAX2 = ((short) 32767);
175 
176  // 2-byte unsigned special pixel values
177  const unsigned short VALID_MINU2 = ((unsigned short) 3);
178  const unsigned short NULLU2 = ((unsigned short) 0);
179  const unsigned short LOW_REPR_SATU2 = ((unsigned short) 1);
180  const unsigned short LOW_INSTR_SATU2 = ((unsigned short) 2);
181  const unsigned short HIGH_INSTR_SATU2 = ((unsigned short) 65534);
182  const unsigned short HIGH_REPR_SATU2 = ((unsigned short) 65535);
183  const unsigned short VALID_MAXU2 = ((unsigned short) 65522);
184 
185  // 4-byte unsigned special pixel values
186  const unsigned int VALID_MINUI4 = ((unsigned int) 3);
187  const unsigned int NULLUI4 = ((unsigned int) 0);
188  const unsigned int LOW_REPR_SATUI4 = ((unsigned int) 1);
189  const unsigned int LOW_INSTR_SATUI4 = ((unsigned int) 2);
190  const unsigned int HIGH_INSTR_SATUI4 = ((unsigned int) 4294967294);
191  const unsigned int HIGH_REPR_SATUI4 = ((unsigned int) 4294967295);
192  const unsigned int VALID_MAXUI4 = ((unsigned int) 4294967282);
193 
194 
195  // 1-byte special pixel values
196  const unsigned char VALID_MIN1 = ((unsigned char) 1);
197  const unsigned char NULL1 = ((unsigned char) 0);
198  const unsigned char LOW_REPR_SAT1 = ((unsigned char) 0);
199  const unsigned char LOW_INSTR_SAT1 = ((unsigned char) 0);
200  const unsigned char HIGH_INSTR_SAT1 = ((unsigned char) 255);
201  const unsigned char HIGH_REPR_SAT1 = ((unsigned char) 255);
202  const unsigned char VALID_MAX1 = ((unsigned char) 254);
203 
212  inline bool IsSpecial(const double d) {
213  return (d < VALID_MIN8);
214  }
215 
216 
226  inline bool IsSpecial(const float f) {
227  return (f < VALID_MIN4);
228  }
229 
230 
238  inline bool IsValidPixel(const double d) {
239  return (d >= VALID_MIN8);
240  }
241 
242 
250  inline bool IsNullPixel(const double d) {
251  return (d == NULL8);
252  }
253 
254 
262  inline bool IsHighPixel(const double d) {
263  return (d == HIGH_REPR_SAT8) || (d == HIGH_INSTR_SAT8);
264  }
265 
266 
274  inline bool IsLowPixel(const double d) {
275  return (d == LOW_REPR_SAT8) || (d == LOW_INSTR_SAT8);
276  }
277 
278 
286  inline bool IsHrsPixel(const double d) {
287  return (d == HIGH_REPR_SAT8);
288  }
289 
290 
298  inline bool IsHisPixel(const double d) {
299  return (d == HIGH_INSTR_SAT8);
300  }
301 
302 
310  inline bool IsLisPixel(const double d) {
311  return (d == LOW_INSTR_SAT8);
312  }
313 
314 
322  inline bool IsLrsPixel(const double d) {
323  return (d == LOW_REPR_SAT8);
324  }
325 
326 
334  inline double TestPixel(const float t) {
335  if(t < VALID_MIN4) {
336  if(t == NULL4) return (NULL8);
337  if(t == LOW_REPR_SAT4) return (LOW_REPR_SAT8);
338  if(t == LOW_INSTR_SAT4) return (LOW_INSTR_SAT8);
339  if(t == HIGH_REPR_SAT4) return (HIGH_REPR_SAT8);
340  if(t == HIGH_INSTR_SAT4) return (HIGH_INSTR_SAT8);
341  return (LOW_REPR_SAT8);
342  }
343  else if(t > VALID_MAX4) {
344  return (HIGH_REPR_SAT8);
345  }
346  else {
347  return ((double) t);
348  }
349  }
350 
351 
360  inline float TestPixel(const double t) {
361  if(t < (double) VALID_MIN4) {
362  if(t == NULL8) return (NULL4);
363  if(t == LOW_REPR_SAT8) return (LOW_REPR_SAT4);
364  if(t == LOW_INSTR_SAT8) return (LOW_INSTR_SAT4);
365  if(t == HIGH_INSTR_SAT8) return (HIGH_INSTR_SAT4);
366  if(t == HIGH_REPR_SAT8) return (HIGH_REPR_SAT4);
367  return (LOW_REPR_SAT4);
368  }
369  else if(t > (double) VALID_MAX4) {
370  return (HIGH_REPR_SAT8);
371  }
372  else {
373  return ((float) t);
374  }
375  }
376 
377 
386  inline QString PixelToString(double d) {
387  if(Isis::IsSpecial(d)) {
388  if(Isis::IsNullPixel(d)) return "Null";
389  if(Isis::IsLrsPixel(d)) return "Lrs";
390  if(Isis::IsHrsPixel(d)) return "Hrs";
391  if(Isis::IsHisPixel(d)) return "His";
392  if(Isis::IsLisPixel(d)) return "Lis";
393  return "Invalid";
394  }
395 
396  QString result;
397  return result.setNum(d, 'g', 8);
398  }
399 
400 
409  inline double StringToPixel(const QString &str) {
410 
411  QString s = str.toUpper();
412 
413  QStringList legal;
414  legal.push_back("NULL");
415  legal.push_back("HRS");
416  legal.push_back("LRS");
417  legal.push_back("HIS");
418  legal.push_back("LIS");
419  int matches = 0;
420  for(int i = 0; i < (int) legal.size(); i++) {
421  if(legal[i].mid(0, s.size()) == s) {
422  matches++;
423  }
424  }
425  if(matches > 1) {
426  QString msg = "Input [" + str + "] is not a unique abbreviation. Use " + s + "I or " + s + "R.";
428  }
429  if(matches == 0) {
430  try {
431  return toDouble(s);
432  }
433  catch(IException &e) {
434  QString msg = "Input [" + str + "] does not appear to be a legal special pixel abbreviation or double value.";
435  throw IException(e, IException::User, msg, _FILEINFO_);
436  }
437  }
438  if(s[0] == 'N') return Null;
439  if(s.mid(0, 2) == "HR") return Hrs;
440  if(s.mid(0, 2) == "LR") return Lrs;
441  if(s.mid(0, 2) == "HI") return His;
442  else return Lis;//(s.substr(0,2) == "LI")
443 
444  }
445 }
446 
447 #endif
448 
const int IVALID_MAX4
Definition: SpecialPixel.h:165
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
Definition: SpecialPixel.h:310
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:110
const unsigned char VALID_MAX1
Definition: SpecialPixel.h:202
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
Definition: SpecialPixel.h:322
const unsigned char LOW_REPR_SAT1
Definition: SpecialPixel.h:198
const double ValidMinimum
The minimum valid double value for Isis pixels.
Definition: SpecialPixel.h:102
const float HIGH_REPR_SAT4
Definition: SpecialPixel.h:161
const unsigned int VALID_MINUI4
Definition: SpecialPixel.h:186
const unsigned short HIGH_INSTR_SATU2
Definition: SpecialPixel.h:181
const unsigned char HIGH_INSTR_SAT1
Definition: SpecialPixel.h:200
const double NULL8
Definition: SpecialPixel.h:109
bool IsLowPixel(const double d)
Returns if the input pixel is one of the low saturation types.
Definition: SpecialPixel.h:274
const DBL_UNION IHIGH_INSTR_SAT8
Definition: SpecialPixel.h:124
const unsigned short VALID_MAXU2
Definition: SpecialPixel.h:183
double StringToPixel(const QString &str)
Takes the name of the pixel type as a string and returns a double pixel value.
Definition: SpecialPixel.h:409
const unsigned int NULLUI4
Definition: SpecialPixel.h:187
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
Definition: SpecialPixel.h:238
const unsigned int LOW_INSTR_SATUI4
Definition: SpecialPixel.h:189
const double VALID_MAX8
Definition: SpecialPixel.h:136
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:298
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
Definition: SpecialPixel.h:286
const unsigned short HIGH_REPR_SATU2
Definition: SpecialPixel.h:182
const unsigned short VALID_MINU2
Definition: SpecialPixel.h:177
const double Lis
Value for an Isis Low Instrument Saturation pixel.
Definition: SpecialPixel.h:120
const double LOW_REPR_SAT8
Definition: SpecialPixel.h:113
const float LOW_INSTR_SAT4
Definition: SpecialPixel.h:155
const int IHIGH_INSTR_SAT4
Definition: SpecialPixel.h:157
const float HIGH_INSTR_SAT4
Definition: SpecialPixel.h:158
const int IHIGH_REPR_SAT4
Definition: SpecialPixel.h:160
const DBL_UNION IVALID_MIN8
Manipulate special pixel values.
Definition: SpecialPixel.h:100
const short HIGH_REPR_SAT2
Definition: SpecialPixel.h:173
const int IVALID_MIN4
Definition: SpecialPixel.h:144
const double HIGH_INSTR_SAT8
Definition: SpecialPixel.h:125
const int ILOW_REPR_SAT4
Definition: SpecialPixel.h:151
const short LOW_INSTR_SAT2
Definition: SpecialPixel.h:171
const short HIGH_INSTR_SAT2
Definition: SpecialPixel.h:172
const DBL_UNION INULL8
Definition: SpecialPixel.h:108
const DBL_UNION ILOW_REPR_SAT8
Definition: SpecialPixel.h:112
const unsigned int VALID_MAXUI4
Definition: SpecialPixel.h:192
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
const short VALID_MIN2
Definition: SpecialPixel.h:168
double TestPixel(const float t)
Converts float pixels to double pixels with special pixel translations.
Definition: SpecialPixel.h:334
const double HIGH_REPR_SAT8
Definition: SpecialPixel.h:131
const unsigned short LOW_INSTR_SATU2
Definition: SpecialPixel.h:180
const unsigned int LOW_REPR_SATUI4
Definition: SpecialPixel.h:188
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
const float VALID_MIN4
Definition: SpecialPixel.h:145
const float VALID_MAX4
Definition: SpecialPixel.h:164
const short VALID_MAX2
Definition: SpecialPixel.h:174
const int INULL4
Definition: SpecialPixel.h:148
const unsigned short LOW_REPR_SATU2
Definition: SpecialPixel.h:179
const DBL_UNION ILOW_INSTR_SAT8
Definition: SpecialPixel.h:118
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition: SpecialPixel.h:212
const unsigned char VALID_MIN1
Definition: SpecialPixel.h:196
const double VALID_MIN8
Definition: SpecialPixel.h:101
const float LOW_REPR_SAT4
Definition: SpecialPixel.h:152
const unsigned char HIGH_REPR_SAT1
Definition: SpecialPixel.h:201
const float NULL4
Definition: SpecialPixel.h:149
const double LOW_INSTR_SAT8
Definition: SpecialPixel.h:119
const unsigned int HIGH_REPR_SATUI4
Definition: SpecialPixel.h:191
const double ValidMaximum
The maximum valid double value for Isis pixels.
Definition: SpecialPixel.h:137
const short LOW_REPR_SAT2
Definition: SpecialPixel.h:170
const unsigned short NULLU2
Definition: SpecialPixel.h:178
bool IsHighPixel(const double d)
Returns if the input pixel is one of the high saturation types.
Definition: SpecialPixel.h:262
const unsigned int HIGH_INSTR_SATUI4
Definition: SpecialPixel.h:190
QString PixelToString(double d)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition: SpecialPixel.h:386
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool IsNullPixel(const double d)
Returns if the input pixel is null.
Definition: SpecialPixel.h:250
const double Lrs
Value for an Isis Low Representation Saturation pixel.
Definition: SpecialPixel.h:114
const DBL_UNION IHIGH_REPR_SAT8
Definition: SpecialPixel.h:130
const short NULL2
Definition: SpecialPixel.h:169
const double His
Value for an Isis High Instrument Saturation pixel.
Definition: SpecialPixel.h:126
const unsigned char LOW_INSTR_SAT1
Definition: SpecialPixel.h:199
const int ILOW_INSTR_SAT4
Definition: SpecialPixel.h:154
const unsigned char NULL1
Definition: SpecialPixel.h:197
const double Hrs
Value for an Isis High Representation Saturation pixel.
Definition: SpecialPixel.h:132