File failed to load: https://isis.astrogeology.usgs.gov/dev/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
SpecialPixel.h
Go to the documentation of this file.
1#ifndef SpecialPixel_h
2#define SpecialPixel_h
7
8/* SPDX-License-Identifier: CC0-1.0 */
9#include <vector>
10#include <cmath>
11#include <cfloat>
12#include <QString>
13#include <QStringList>
14
15#include "IException.h"
16#include "IString.h"
17
18namespace Isis {
19
69
71 // Set up special kludge for double precision initialization
72 typedef union {
73 unsigned int i[2];
74 double d;
75 } DBL_UNION;
76
77#if ISIS_LITTLE_ENDIAN
78# define DBL_INIT(a,b) {(b), (a)}
79#else
80# define DBL_INIT(a,b) {(a), (b)}
81#endif
83
84 // Define 8-byte special pixel values for IEEE floating point
85 const DBL_UNION IVALID_MIN8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFA) };
86 const double VALID_MIN8 = IVALID_MIN8.d;
87 const double ValidMinimum = IVALID_MIN8.d;
92
93 const DBL_UNION INULL8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFB) };
94 const double NULL8 = INULL8.d;
95 const double Null = INULL8.d;
96
97 const DBL_UNION ILOW_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFC) };
98 const double LOW_REPR_SAT8 = ILOW_REPR_SAT8.d;
99 const double Lrs = ILOW_REPR_SAT8.d;
102
103 const DBL_UNION ILOW_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFD) };
105 const double Lis = ILOW_INSTR_SAT8.d;
108
109 const DBL_UNION IHIGH_INSTR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFE) };
111 const double His = IHIGH_INSTR_SAT8.d;
114
115 const DBL_UNION IHIGH_REPR_SAT8 = { DBL_INIT(0xFFEFFFFF, 0xFFFFFFFF) };
117 const double Hrs = IHIGH_REPR_SAT8.d;
120
121 const double VALID_MAX8 = DBL_MAX;
122 const double ValidMaximum = DBL_MAX;
124
125
126#undef DBL_INIT
127
128 // Define 4-byte special pixel values for IEEE floating point
129 const int IVALID_MIN4 = 0xFF7FFFFA;
130 const float VALID_MIN4 = (*((const float *) &IVALID_MIN4));
131
132
133 const int INULL4 = 0xFF7FFFFB;
134 const float NULL4 = (*((const float *) &INULL4));
135
136 const int ILOW_REPR_SAT4 = 0xFF7FFFFC;
137 const float LOW_REPR_SAT4 = (*((const float *) &ILOW_REPR_SAT4));
138
139 const int ILOW_INSTR_SAT4 = 0xFF7FFFFD;
140 const float LOW_INSTR_SAT4 = (*((const float *) &ILOW_INSTR_SAT4));
141
142 const int IHIGH_INSTR_SAT4 = 0xFF7FFFFE;
143 const float HIGH_INSTR_SAT4 = (*((const float *) &IHIGH_INSTR_SAT4));
144
145 const int IHIGH_REPR_SAT4 = 0xFF7FFFFF;
146 const float HIGH_REPR_SAT4 = (*((const float *) &IHIGH_REPR_SAT4));
147
148
149 const float VALID_MAX4 = FLT_MAX;
150 const int IVALID_MAX4 = (*((const int *) &VALID_MAX4));
151
152 // 2-byte signed special pixel values
153 const short VALID_MIN2 = ((short)(-32752));
154 const short NULL2 = ((short)(-32768));
155 const short LOW_REPR_SAT2 = ((short)(-32767));
156 const short LOW_INSTR_SAT2 = ((short)(-32766));
157 const short HIGH_INSTR_SAT2 = ((short)(-32765));
158 const short HIGH_REPR_SAT2 = ((short)(-32764));
159 const short VALID_MAX2 = ((short) 32767);
160
161 // 2-byte unsigned special pixel values
162 const unsigned short VALID_MINU2 = ((unsigned short) 3);
163 const unsigned short NULLU2 = ((unsigned short) 0);
164 const unsigned short LOW_REPR_SATU2 = ((unsigned short) 1);
165 const unsigned short LOW_INSTR_SATU2 = ((unsigned short) 2);
166 const unsigned short HIGH_INSTR_SATU2 = ((unsigned short) 65534);
167 const unsigned short HIGH_REPR_SATU2 = ((unsigned short) 65535);
168 const unsigned short VALID_MAXU2 = ((unsigned short) 65522);
169
170 // 4-byte signed special pixel values
171 const int VALID_MINI4 = ((int)(-2147483632));
172 const int NULLI4 = ((int)(-2147483648));
173 const int LOW_REPR_SATI4 = ((int)(-2147483647));
174 const int LOW_INSTR_SATI4 = ((int)(-2147483646));
175 const int HIGH_INSTR_SATI4 = ((int)(-2147483645));
176 const int HIGH_REPR_SATI4 = ((int)(-2147483644));
177 const int VALID_MAXI4 = ((int) 2147483647 );
178
179 // 4-byte unsigned special pixel values
180 const unsigned int VALID_MINUI4 = ((unsigned int) 3);
181 const unsigned int NULLUI4 = ((unsigned int) 0);
182 const unsigned int LOW_REPR_SATUI4 = ((unsigned int) 1);
183 const unsigned int LOW_INSTR_SATUI4 = ((unsigned int) 2);
184 const unsigned int HIGH_INSTR_SATUI4 = ((unsigned int) 4294967294);
185 const unsigned int HIGH_REPR_SATUI4 = ((unsigned int) 4294967295);
186 const unsigned int VALID_MAXUI4 = ((unsigned int) 4294967282);
187
188 // 1-byte signed special pixel values
189 const char VALID_MINS1 = ((char) -126);
190 const char NULLS1 = ((char) -128);
191 const char LOW_REPR_SATS1 = ((char) -128);
192 const char LOW_INSTR_SATS1 = ((char) -128);
193 const char HIGH_INSTR_SATS1 = ((char) -127);
194 const char HIGH_REPR_SATS1 = ((char) -127);
195 const char VALID_MAXS1 = ((char) 127);
196
197 // 1-byte unsigned special pixel values
198 const unsigned char VALID_MIN1 = ((unsigned char) 1);
199 const unsigned char NULL1 = ((unsigned char) 0);
200 const unsigned char LOW_REPR_SAT1 = ((unsigned char) 0);
201 const unsigned char LOW_INSTR_SAT1 = ((unsigned char) 0);
202 const unsigned char HIGH_INSTR_SAT1 = ((unsigned char) 255);
203 const unsigned char HIGH_REPR_SAT1 = ((unsigned char) 255);
204 const unsigned char VALID_MAX1 = ((unsigned char) 254);
205
214 inline bool IsSpecial(const double d) {
215 return (d < VALID_MIN8);
216 }
217
218
228 inline bool IsSpecial(const float f) {
229 return (f < VALID_MIN4);
230 }
231
232
240 inline bool IsValidPixel(const double d) {
241 return (d >= VALID_MIN8);
242 }
243
244
252 inline bool IsNullPixel(const double d) {
253 return (d == NULL8);
254 }
255
256
264 inline bool IsHighPixel(const double d) {
265 return (d == HIGH_REPR_SAT8) || (d == HIGH_INSTR_SAT8);
266 }
267
268
276 inline bool IsLowPixel(const double d) {
277 return (d == LOW_REPR_SAT8) || (d == LOW_INSTR_SAT8);
278 }
279
280
288 inline bool IsHrsPixel(const double d) {
289 return (d == HIGH_REPR_SAT8);
290 }
291
292
300 inline bool IsHisPixel(const double d) {
301 return (d == HIGH_INSTR_SAT8);
302 }
303
304
312 inline bool IsLisPixel(const double d) {
313 return (d == LOW_INSTR_SAT8);
314 }
315
316
324 inline bool IsLrsPixel(const double d) {
325 return (d == LOW_REPR_SAT8);
326 }
327
328
336 inline double TestPixel(const float t) {
337 if(t < VALID_MIN4) {
338 if(t == NULL4) return (NULL8);
339 if(t == LOW_REPR_SAT4) return (LOW_REPR_SAT8);
340 if(t == LOW_INSTR_SAT4) return (LOW_INSTR_SAT8);
341 if(t == HIGH_REPR_SAT4) return (HIGH_REPR_SAT8);
342 if(t == HIGH_INSTR_SAT4) return (HIGH_INSTR_SAT8);
343 return (LOW_REPR_SAT8);
344 }
345 else if(t > VALID_MAX4) {
346 return (HIGH_REPR_SAT8);
347 }
348 else {
349 return ((double) t);
350 }
351 }
352
353
362 inline float TestPixel(const double t) {
363 if(t < (double) VALID_MIN4) {
364 if(t == NULL8) return (NULL4);
365 if(t == LOW_REPR_SAT8) return (LOW_REPR_SAT4);
366 if(t == LOW_INSTR_SAT8) return (LOW_INSTR_SAT4);
367 if(t == HIGH_INSTR_SAT8) return (HIGH_INSTR_SAT4);
368 if(t == HIGH_REPR_SAT8) return (HIGH_REPR_SAT4);
369 return (LOW_REPR_SAT4);
370 }
371 else if(t > (double) VALID_MAX4) {
372 return (HIGH_REPR_SAT8);
373 }
374 else {
375 return ((float) t);
376 }
377 }
378
379
388 inline QString PixelToString(double d, double precision=8) {
389 if(Isis::IsSpecial(d)) {
390 if(Isis::IsNullPixel(d)) return "Null";
391 if(Isis::IsLrsPixel(d)) return "Lrs";
392 if(Isis::IsHrsPixel(d)) return "Hrs";
393 if(Isis::IsHisPixel(d)) return "His";
394 if(Isis::IsLisPixel(d)) return "Lis";
395 return "Invalid";
396 }
397
398 QString result;
399 return result.setNum(d, 'g', precision);
400 }
401
402
411 inline double StringToPixel(const QString &str) {
412
413 QString s = str.toUpper();
414
415 QStringList legal;
416 legal.push_back("NULL");
417 legal.push_back("HRS");
418 legal.push_back("LRS");
419 legal.push_back("HIS");
420 legal.push_back("LIS");
421 int matches = 0;
422 for(int i = 0; i < (int) legal.size(); i++) {
423 if(legal[i].mid(0, s.size()) == s) {
424 matches++;
425 }
426 }
427 if(matches > 1) {
428 QString msg = "Input [" + str + "] is not a unique abbreviation. Use " + s + "I or " + s + "R.";
430 }
431 if(matches == 0) {
432 try {
433 return toDouble(s);
434 }
435 catch(IException &e) {
436 QString msg = "Input [" + str + "] does not appear to be a legal special pixel abbreviation or double value.";
437 throw IException(e, IException::User, msg, _FILEINFO_);
438 }
439 }
440 if(s[0] == 'N') return Null;
441 if(s.mid(0, 2) == "HR") return Hrs;
442 if(s.mid(0, 2) == "LR") return Lrs;
443 if(s.mid(0, 2) == "HI") return His;
444 else return Lis;//(s.substr(0,2) == "LI")
445
446 }
447}
448
449#endif
450
#define _FILEINFO_
Macro for the filename and line number.
Definition IException.h:24
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
const DBL_UNION IVALID_MIN8
Manipulate special pixel values.
Definition SpecialPixel.h:85
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const int IHIGH_REPR_SAT4
Definition SpecialPixel.h:145
const double His
Value for an Isis High Instrument Saturation pixel.
Definition SpecialPixel.h:111
double StringToPixel(const QString &str)
Takes the name of the pixel type as a string and returns a double pixel value.
Definition SpecialPixel.h:411
const unsigned short NULLU2
Definition SpecialPixel.h:163
const unsigned int LOW_REPR_SATUI4
Definition SpecialPixel.h:182
const double Hrs
Value for an Isis High Representation Saturation pixel.
Definition SpecialPixel.h:117
const unsigned short VALID_MAXU2
Definition SpecialPixel.h:168
const char HIGH_REPR_SATS1
Definition SpecialPixel.h:194
const int IVALID_MAX4
Definition SpecialPixel.h:150
const char LOW_INSTR_SATS1
Definition SpecialPixel.h:192
bool IsLrsPixel(const double d)
Returns if the input pixel is low representation saturation.
Definition SpecialPixel.h:324
const double ValidMaximum
The maximum valid double value for Isis pixels.
Definition SpecialPixel.h:122
const DBL_UNION IHIGH_REPR_SAT8
Definition SpecialPixel.h:115
const char VALID_MINS1
Definition SpecialPixel.h:189
const int HIGH_REPR_SATI4
Definition SpecialPixel.h:176
const short VALID_MIN2
Definition SpecialPixel.h:153
const DBL_UNION ILOW_INSTR_SAT8
Definition SpecialPixel.h:103
const double HIGH_REPR_SAT8
Definition SpecialPixel.h:116
const unsigned short LOW_REPR_SATU2
Definition SpecialPixel.h:164
const short VALID_MAX2
Definition SpecialPixel.h:159
const unsigned char HIGH_REPR_SAT1
Definition SpecialPixel.h:203
const int INULL4
Definition SpecialPixel.h:133
const float LOW_REPR_SAT4
Definition SpecialPixel.h:137
const int NULLI4
Definition SpecialPixel.h:172
bool IsNullPixel(const double d)
Returns if the input pixel is null.
Definition SpecialPixel.h:252
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
Definition SpecialPixel.h:288
const double VALID_MAX8
Definition SpecialPixel.h:121
const unsigned int LOW_INSTR_SATUI4
Definition SpecialPixel.h:183
const unsigned short HIGH_REPR_SATU2
Definition SpecialPixel.h:167
const short HIGH_INSTR_SAT2
Definition SpecialPixel.h:157
const char HIGH_INSTR_SATS1
Definition SpecialPixel.h:193
const int LOW_INSTR_SATI4
Definition SpecialPixel.h:174
const char NULLS1
Definition SpecialPixel.h:190
const unsigned short HIGH_INSTR_SATU2
Definition SpecialPixel.h:166
const char VALID_MAXS1
Definition SpecialPixel.h:195
const float HIGH_REPR_SAT4
Definition SpecialPixel.h:146
const short LOW_REPR_SAT2
Definition SpecialPixel.h:155
const DBL_UNION IHIGH_INSTR_SAT8
Definition SpecialPixel.h:109
const int ILOW_INSTR_SAT4
Definition SpecialPixel.h:139
const short NULL2
Definition SpecialPixel.h:154
const float NULL4
Definition SpecialPixel.h:134
const unsigned char LOW_REPR_SAT1
Definition SpecialPixel.h:200
const unsigned char LOW_INSTR_SAT1
Definition SpecialPixel.h:201
const unsigned char VALID_MAX1
Definition SpecialPixel.h:204
const int IHIGH_INSTR_SAT4
Definition SpecialPixel.h:142
const float HIGH_INSTR_SAT4
Definition SpecialPixel.h:143
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
Definition SpecialPixel.h:240
const unsigned int HIGH_REPR_SATUI4
Definition SpecialPixel.h:185
const int IVALID_MIN4
Definition SpecialPixel.h:129
const double Null
Value for an Isis Null pixel.
Definition SpecialPixel.h:95
const int VALID_MINI4
Definition SpecialPixel.h:171
const unsigned short LOW_INSTR_SATU2
Definition SpecialPixel.h:165
const float VALID_MAX4
Definition SpecialPixel.h:149
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
Definition SpecialPixel.h:300
const double ValidMinimum
The minimum valid double value for Isis pixels.
Definition SpecialPixel.h:87
double TestPixel(const float t)
Converts float pixels to double pixels with special pixel translations.
Definition SpecialPixel.h:336
const double Lrs
Value for an Isis Low Representation Saturation pixel.
Definition SpecialPixel.h:99
const int VALID_MAXI4
Definition SpecialPixel.h:177
const double Lis
Value for an Isis Low Instrument Saturation pixel.
Definition SpecialPixel.h:105
const short LOW_INSTR_SAT2
Definition SpecialPixel.h:156
const unsigned char NULL1
Definition SpecialPixel.h:199
const int ILOW_REPR_SAT4
Definition SpecialPixel.h:136
bool IsSpecial(const double d)
Returns if the input pixel is special.
Definition SpecialPixel.h:214
const double LOW_INSTR_SAT8
Definition SpecialPixel.h:104
const unsigned char VALID_MIN1
Definition SpecialPixel.h:198
const unsigned int NULLUI4
Definition SpecialPixel.h:181
const int HIGH_INSTR_SATI4
Definition SpecialPixel.h:175
const short HIGH_REPR_SAT2
Definition SpecialPixel.h:158
const double HIGH_INSTR_SAT8
Definition SpecialPixel.h:110
const double NULL8
Definition SpecialPixel.h:94
const double LOW_REPR_SAT8
Definition SpecialPixel.h:98
const char LOW_REPR_SATS1
Definition SpecialPixel.h:191
const unsigned int VALID_MINUI4
Definition SpecialPixel.h:180
QString PixelToString(double d, double precision=8)
Takes a double pixel value and returns the name of the pixel type as a string.
Definition SpecialPixel.h:388
bool IsHighPixel(const double d)
Returns if the input pixel is one of the high saturation types.
Definition SpecialPixel.h:264
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition IString.cpp:149
const int LOW_REPR_SATI4
Definition SpecialPixel.h:173
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
Definition SpecialPixel.h:312
const unsigned int HIGH_INSTR_SATUI4
Definition SpecialPixel.h:184
const DBL_UNION INULL8
Definition SpecialPixel.h:93
const unsigned short VALID_MINU2
Definition SpecialPixel.h:162
const DBL_UNION ILOW_REPR_SAT8
Definition SpecialPixel.h:97
const float LOW_INSTR_SAT4
Definition SpecialPixel.h:140
bool IsLowPixel(const double d)
Returns if the input pixel is one of the low saturation types.
Definition SpecialPixel.h:276
const unsigned int VALID_MAXUI4
Definition SpecialPixel.h:186
const double VALID_MIN8
Definition SpecialPixel.h:86
const float VALID_MIN4
Definition SpecialPixel.h:130
const unsigned char HIGH_INSTR_SAT1
Definition SpecialPixel.h:202