-
Notifications
You must be signed in to change notification settings - Fork 4
/
pixel.cpp
165 lines (154 loc) · 5.74 KB
/
pixel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* ============================================================================
'pixel.cpp' defines the pixel class methods. The classes are defined in
'pixel.h'.
Written by Nicholas Phillips, December 2006
Broken out of 'skymap.h'. MRG, ADNET, 23 January 2007.
============================================================================ */
#include <math.h>
#include "pixel.h"
/* ============================================================================
The BasePixel class provides a common denominator for the various types of
supported maps. Up to six data elements per pixel are supported:
Stokes I, Q, U, NObs, and the polarization magnitude and angle wrt meridian.
The default data access functions are defined here. They all throw exceptions
indicating that the data requested is not defined. Child classes should
overload the relevant functions to provide support for that data.
============================================================================ */
double BasePixel::ddummy = 0.0;
/* ------------------------------------------------------------------------- */
double BasePixel::T() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::T()
{
throw MapException(MapException::Undefined);
return ddummy;
}
/* ------------------------------------------------------------------------- */
double BasePixel::I() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::I()
{
throw MapException(MapException::Undefined);
return ddummy; // not that we will ever get here
}
/* ------------------------------------------------------------------------- */
double BasePixel::Q() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::Q()
{
throw MapException(MapException::Undefined);
return ddummy;
}
/* ------------------------------------------------------------------------- */
double BasePixel::U() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::U()
{
throw MapException(MapException::Undefined);
return ddummy;
}
/* ------------------------------------------------------------------------- */
double BasePixel::Nobs() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::Nobs()
{
throw MapException(MapException::Undefined);
return ddummy; // not that we will ever get here
}
/* ------------------------------------------------------------------------- */
double BasePixel::Pmag() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::Pmag()
{
throw MapException(MapException::Undefined);
return ddummy; // not that we will ever get here
}
/* ------------------------------------------------------------------------- */
double BasePixel::Pang() const
{
throw MapException(MapException::Undefined);
return 0;
}
/* ------------------------------------------------------------------------- */
double & BasePixel::Pang()
{
throw MapException(MapException::Undefined);
return ddummy; // not that we will ever get here
}
/* ----------------------------------------------------------------------------
'copy' copies another pixel into this one. This function captures and ignores
MapException exceptions; it does NOT rethrow them.
Arguments:
&src - The pixel to copy.
Returned:
Nothing.
Written by Michael R. Greason, ADNET, 27 March 2007.
---------------------------------------------------------------------------- */
void BasePixel::copy (BasePixel& src)
{
try { this->T() = src.T(); } catch (MapException &exc) { ; }
try { this->Q() = src.Q(); } catch (MapException &exc) { ; }
try { this->U() = src.U(); } catch (MapException &exc) { ; }
try { this->Nobs() = src.Nobs(); } catch (MapException &exc) { ; }
try { this->Pmag() = src.Pmag(); } catch (MapException &exc) { ; }
try { this->Pang() = src.Pang(); } catch (MapException &exc) { ; }
}
/* ----------------------------------------------------------------------------
'clear' zeros the pixel out. This function captures and ignores MapException
exceptions; it does NOT rethrow them.
Arguments:
None.
Returned:
Nothing.
Written by Michael R. Greason, ADNET, 27 March 2007.
---------------------------------------------------------------------------- */
void BasePixel::clear (void)
{
try { this->T() = 0.0; } catch (MapException &exc) { ; }
try { this->Q() = 0.0; } catch (MapException &exc) { ; }
try { this->U() = 0.0; } catch (MapException &exc) { ; }
try { this->Nobs() = 0.0; } catch (MapException &exc) { ; }
try { this->Pmag() = 0.0; } catch (MapException &exc) { ; }
try { this->Pang() = 0.0; } catch (MapException &exc) { ; }
}
/* ============================================================================
The TPPixel class defines a Stokes I, Q, U pixel. The polarization magnitude
and angle will be computed whenever Q and U are set.
============================================================================ */
/* ----------------------------------------------------------------------------
'computePolar' computes the polarization magnitude and angle.
Arguments:
None.
Returned:
Nothing.
Written by Michael R. Greason, ADNET, 30 August 2007.
---------------------------------------------------------------------------- */
void TPPixel::computePolar (void)
{
Pmag_ = sqrt( (Q_ * Q_) + (U_ * U_) );
Pang_ = atan2(U_, Q_) / 2.;
}