Isis 3 Programmer Reference
Pixel.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Pixel.h"
8
9using namespace std;
10
11namespace Isis {
12
19 m_line = 0;
20 m_sample = 0;
21 m_band = 0;
23 }
24
25
36 Pixel::Pixel(int sample, int line, int band, double DN) {
38 m_line = line;
39 m_band = band;
40 m_DN = DN;
41 }
42
43
51 Pixel::Pixel(const Pixel& pixel) {
52 m_sample = pixel.sample();
53 m_line = pixel.line();
54 m_band = pixel.band();
55 m_DN = pixel.DN();
56 }
57
58
66 Pixel &Pixel::operator=(const Pixel& other) {
67 m_line = other.line();
68 m_sample = other.sample();
69 m_band = other.band();
70 m_DN = other.DN();
71 return *this;
72 }
73
74
77
78
80 int Pixel::line() const {
81 return m_line;
82 }
83
84
86 int Pixel::sample() const {
87 return m_sample;
88 }
89
90
92 int Pixel::band() const {
93 return m_band;
94 }
95
96
98 double Pixel::DN() const {
99 return m_DN;
100 }
101
102
111 unsigned char Pixel::To8Bit(const double d) {
112 if(d < VALID_MIN8) {
113 if(d == NULL8) return NULL1;
114 else if(d == LOW_INSTR_SAT8) return LOW_INSTR_SAT1;
115 else if(d == LOW_REPR_SAT8) return LOW_REPR_SAT1;
116 else if(d == HIGH_INSTR_SAT8) return HIGH_INSTR_SAT1;
117 else if(d == HIGH_REPR_SAT8) return HIGH_REPR_SAT1;
118 else return LOW_REPR_SAT1;
119 }
120 else {
121 if(d < VALID_MIN1 - 0.5) return LOW_REPR_SAT1;
122 else if(d > VALID_MAX1 + 0.5) return HIGH_REPR_SAT1;
123
124 else {
125 int itemp = (int)(d + 0.5);
126 if(itemp < VALID_MIN1) return LOW_REPR_SAT1;
127 else if(itemp > VALID_MAX1) return HIGH_REPR_SAT1;
128 else return (unsigned char)(d + 0.5);
129 }
130 }
131 }
132
133
140 unsigned char Pixel::To8Bit() {
141 return To8Bit(m_DN);
142 }
143
144
152 short int Pixel::To16Bit(const double d) {
153 if(d < VALID_MIN8) {
154 if(d == NULL8) return NULL2;
155 else if(d == LOW_INSTR_SAT8) return LOW_INSTR_SAT2;
156 else if(d == LOW_REPR_SAT8) return LOW_REPR_SAT2;
157 else if(d == HIGH_INSTR_SAT8) return HIGH_INSTR_SAT2;
158 else if(d == HIGH_REPR_SAT8) return HIGH_REPR_SAT2;
159 else return LOW_REPR_SAT2;
160 }
161 else {
162 if(d < VALID_MIN2 - 0.5) return LOW_REPR_SAT2;
163 else if(d > VALID_MAX2 + 0.5) return HIGH_REPR_SAT2;
164
165 else {
166 int itemp;
167 if(d < 0.0) {
168 itemp = (int)(d - 0.5);
169 }
170 else {
171 itemp = (int)(d + 0.5);
172 }
173
174 if(itemp < VALID_MIN2) return LOW_REPR_SAT2;
175 else if(itemp > VALID_MAX2) return HIGH_REPR_SAT2;
176 else if(d < 0.0) return (short)(d - 0.5);
177 else return (short)(d + 0.5);
178 }
179 }
180 }
181
182
189 short int Pixel::To16Bit() {
190 return To16Bit(m_DN);
191 }
192
200 short unsigned int Pixel::To16UBit(const double d) {
201 if(d < VALID_MIN8) {
202 if(d == NULL8) return NULLU2;
203 else if(d == LOW_INSTR_SAT8) return LOW_INSTR_SATU2;
204 else if(d == LOW_REPR_SAT8) return LOW_REPR_SATU2;
205 else if(d == HIGH_INSTR_SAT8) return HIGH_INSTR_SATU2;
206 else if(d == HIGH_REPR_SAT8) return HIGH_REPR_SATU2;
207 else return LOW_REPR_SATU2;
208 }
209 else {
210 if(d < VALID_MIN2 - 0.5) return LOW_REPR_SATU2;
211 else if(d > VALID_MAX2 + 0.5) return HIGH_REPR_SATU2;
212
213 else {
214 int itemp;
215 if(d < 0.0) {
216 itemp = (int)(d - 0.5);
217 }
218 else {
219 itemp = (int)(d + 0.5);
220 }
221
222 if(itemp < VALID_MIN2) return LOW_REPR_SATU2;
223 else if(itemp > VALID_MAX2) return HIGH_REPR_SATU2;
224 else if(d < 0.0) return (short)(d - 0.5);
225 else return (short)(d + 0.5);
226 }
227 }
228 }
229
230
237 short unsigned int Pixel::To16Ubit() {
238 return To16UBit(m_DN);
239 }
240
248 float Pixel::To32Bit(const double d) {
249 if(d < (double) VALID_MIN8) {
250 if(d == NULL8) return(NULL4);
251 else if(d == LOW_REPR_SAT8) return(LOW_REPR_SAT4);
252 else if(d == LOW_INSTR_SAT8) return(LOW_INSTR_SAT4);
253 else if(d == HIGH_INSTR_SAT8) return(HIGH_INSTR_SAT4);
254 else if(d == HIGH_REPR_SAT8) return(HIGH_REPR_SAT4);
255 else return(LOW_REPR_SAT4);
256 }
257 else if(d > (double) VALID_MAX8) return(HIGH_REPR_SAT8);
258 else return((float) d);
259 }
260
268 return To32Bit(m_DN);
269 }
270
271
280 double Pixel::ToDouble(const unsigned char d) {
281 if(d < VALID_MIN1) {
282 if(d == NULL1) return(NULL8);
283 else if(d == LOW_REPR_SAT1) return(LOW_REPR_SAT8);
284 else if(d == LOW_INSTR_SAT1) return(LOW_INSTR_SAT8);
285 else if(d == HIGH_REPR_SAT1) return(HIGH_REPR_SAT8);
286 else if(d == HIGH_INSTR_SAT1) return(HIGH_INSTR_SAT8);
287 else return(LOW_REPR_SAT8);
288 }
289 else if(d > VALID_MAX1) return(HIGH_REPR_SAT8);
290 else return((double) d);
291 }
292
293
301 double Pixel::ToDouble(const short int d) {
302 if(d < VALID_MIN2) {
303 if(d == NULL2) return(NULL8);
304 else if(d == LOW_REPR_SAT2) return(LOW_REPR_SAT8);
305 else if(d == LOW_INSTR_SAT2) return(LOW_INSTR_SAT8);
306 else if(d == HIGH_REPR_SAT2) return(HIGH_REPR_SAT8);
307 else if(d == HIGH_INSTR_SAT2) return(HIGH_INSTR_SAT8);
308 else return(LOW_REPR_SAT8);
309 }
310 else return((double) d);
311 }
312
320 double Pixel::ToDouble(const short unsigned int d) {
321 if(d < VALID_MINU2) {
322 if(d == NULLU2) return(NULL8);
323 else if(d == LOW_REPR_SATU2) return(LOW_REPR_SAT8);
324 else if(d == LOW_INSTR_SATU2) return(LOW_INSTR_SAT8);
325 else if(d == HIGH_REPR_SATU2) return(HIGH_REPR_SAT8);
326 else if(d == HIGH_INSTR_SATU2) return(HIGH_INSTR_SAT8);
327 else return(LOW_REPR_SAT8);
328 }
329 else return((double) d);
330 }
331
332
340 double Pixel::ToDouble(const float d) {
341 if(d < VALID_MIN4) {
342 if(d == NULL4) return(NULL8);
343 else if(d == LOW_REPR_SAT4) return(LOW_REPR_SAT8);
344 else if(d == LOW_INSTR_SAT4) return(LOW_INSTR_SAT8);
345 else if(d == HIGH_REPR_SAT4) return(HIGH_REPR_SAT8);
346 else if(d == HIGH_INSTR_SAT4) return(HIGH_INSTR_SAT8);
347 else return(LOW_REPR_SAT8);
348 }
349 else if(d > VALID_MAX4) return(HIGH_REPR_SAT8);
350 else return((double) d);
351 }
352
353
360 return m_DN;
361 }
362
363
374 float Pixel::ToFloat(const unsigned char t) {
375 if(t < (double) VALID_MIN1) {
376 if(t == NULL1) return(NULL4);
377 else if(t == LOW_REPR_SAT1) return(LOW_REPR_SAT4);
378 else if(t == LOW_INSTR_SAT1) return(LOW_INSTR_SAT4);
379 else if(t == HIGH_INSTR_SAT1) return(HIGH_INSTR_SAT4);
380 else if(t == HIGH_REPR_SAT1) return(HIGH_REPR_SAT4);
381 else return(LOW_REPR_SAT4);
382 }
383 else if(t > (double) VALID_MAX1) return(HIGH_REPR_SAT8);
384 else return((float) t);
385 }
386
395 float Pixel::ToFloat(const short int t) {
396 if(t < (double) VALID_MIN2) {
397 if(t == NULL2) return(NULL4);
398 else if(t == LOW_REPR_SAT2) return(LOW_REPR_SAT4);
399 else if(t == LOW_INSTR_SAT2) return(LOW_INSTR_SAT4);
400 else if(t == HIGH_INSTR_SAT2) return(HIGH_INSTR_SAT4);
401 else if(t == HIGH_REPR_SAT2) return(HIGH_REPR_SAT4);
402 else return(LOW_REPR_SAT4);
403 }
404 else if(t > (double) VALID_MAX2) return(HIGH_REPR_SAT8);
405 else return((float) t);
406 }
407
416 float Pixel::ToFloat(const short unsigned int t) {
417 if(t < (double) VALID_MINU2) {
418 if(t == NULLU2) return(NULL4);
419 else if(t == LOW_REPR_SATU2) return(LOW_REPR_SAT4);
420 else if(t == LOW_INSTR_SATU2) return(LOW_INSTR_SAT4);
421 else if(t == HIGH_INSTR_SATU2) return(HIGH_INSTR_SAT4);
422 else if(t == HIGH_REPR_SATU2) return(HIGH_REPR_SAT4);
423 else return(LOW_REPR_SAT4);
424 }
425 else if(t > (double) VALID_MAXU2) return(HIGH_REPR_SAT8);
426 else return((float) t);
427 }
428
437 float Pixel::ToFloat(const double t) {
438 if(t < (double) VALID_MIN8) {
439 if(t == NULL8) return(NULL4);
440 else if(t == LOW_REPR_SAT8) return(LOW_REPR_SAT4);
441 else if(t == LOW_INSTR_SAT8) return(LOW_INSTR_SAT4);
442 else if(t == HIGH_INSTR_SAT8) return(HIGH_INSTR_SAT4);
443 else if(t == HIGH_REPR_SAT8) return(HIGH_REPR_SAT4);
444 else return(LOW_REPR_SAT4);
445 }
446 else if(t > (double) VALID_MAX8) return(HIGH_REPR_SAT8);
447 else return((float) t);
448 }
449
458 return ToFloat(m_DN);
459 }
460
469 string Pixel::ToString(double d) {
470 if(IsSpecial(d)) {
471 if(IsNull(d)) return string("Null");
472 else if(IsLrs(d)) return string("Lrs");
473 else if(IsHrs(d)) return string("Hrs");
474 else if(IsHis(d)) return string("His");
475 else if(IsLis(d)) return string("Lis");
476 else return string("Invalid");
477 }
478
479 QString result;
480 return result.setNum(d).toStdString();
481 }
482
489 return ToString(m_DN);
490 }
491}
Store and/or manipulate pixel values.
Definition Pixel.h:48
virtual ~Pixel()
Default destructor.
Definition Pixel.cpp:76
int m_sample
sample coordinate of pixel
Definition Pixel.h:289
short unsigned int To16Ubit()
Converts internal pixel value to a short int pixel with special pixel translations.
Definition Pixel.cpp:237
Pixel & operator=(const Pixel &other)
Copy assignment operator.
Definition Pixel.cpp:66
unsigned char To8Bit()
Converts internal pixel value to an unsigned char pixel with special pixel translations.
Definition Pixel.cpp:140
int line() const
Definition Pixel.cpp:80
std::string ToString()
Returns the name of the pixel type as a string.
Definition Pixel.cpp:488
bool IsLis()
Returns true if the input pixel is low instrument saturation.
Definition Pixel.h:260
float To32Bit()
Converts internal pixel value to float with special pixel translations.
Definition Pixel.cpp:267
short int To16Bit()
Converts internal pixel value to a short int pixel with special pixel translations.
Definition Pixel.cpp:189
bool IsHis()
Returns true if the input pixel is high instrument saturation.
Definition Pixel.h:240
bool IsSpecial()
Returns true if the input pixel is special.
Definition Pixel.h:105
int m_band
band coordinate of pixel
Definition Pixel.h:292
Pixel()
Constructs an empty Pixel.
Definition Pixel.cpp:18
int sample() const
Definition Pixel.cpp:86
bool IsNull()
Returns true if the input pixel is null.
Definition Pixel.h:160
double m_DN
DN of pixel.
Definition Pixel.h:295
bool IsLrs()
Returns true if the input pixel is low representation saturation.
Definition Pixel.h:280
int m_line
line coordinate of pixel
Definition Pixel.h:286
double ToDouble()
Converts stored pixel value to a double.
Definition Pixel.cpp:359
bool IsHrs()
Returns true if the input pixel is high representation saturation.
Definition Pixel.h:220
int band() const
Definition Pixel.cpp:92
static short unsigned int To16UBit(const double d)
Converts double pixels to short unsigned int pixels with special pixel translations.
Definition Pixel.cpp:200
float ToFloat()
Converts internal pixel value to float with pixel translations and care for overflows (underflows are...
Definition Pixel.cpp:457
double DN() const
Definition Pixel.cpp:98
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double Null
Value for an Isis Null pixel.
Namespace for the standard library.