00001 /* ============================================================================ 00002 'pixel.cpp' defines the pixel class methods. The classes are defined in 00003 'pixel.h'. 00004 00005 Written by Nicholas Phillips, December 2006 00006 Broken out of 'skymap.h'. MRG, ADNET, 23 January 2007. 00007 ============================================================================ */ 00008 #include <math.h> 00009 #include "pixel.h" 00010 /* ============================================================================ 00011 The BasePixel class provides a common denominator for the various types of 00012 supported maps. Up to six data elements per pixel are supported: 00013 Stokes I, Q, U, NObs, and the polarization magnitude and angle wrt meridian. 00014 00015 The default data access functions are defined here. They all throw exceptions 00016 indicating that the data requested is not defined. Child classes should 00017 overload the relevant functions to provide support for that data. 00018 ============================================================================ */ 00019 double BasePixel::ddummy = 0.0; 00020 /* ------------------------------------------------------------------------- */ 00021 double BasePixel::T() const 00022 { 00023 throw MapException(MapException::Undefined); 00024 return 0; 00025 } 00026 /* ------------------------------------------------------------------------- */ 00027 double & BasePixel::T() 00028 { 00029 throw MapException(MapException::Undefined); 00030 return ddummy; 00031 } 00032 /* ------------------------------------------------------------------------- */ 00033 double BasePixel::I() const 00034 { 00035 throw MapException(MapException::Undefined); 00036 return 0; 00037 } 00038 /* ------------------------------------------------------------------------- */ 00039 double & BasePixel::I() 00040 { 00041 throw MapException(MapException::Undefined); 00042 return ddummy; // not that we will ever get here 00043 } 00044 /* ------------------------------------------------------------------------- */ 00045 double BasePixel::Q() const 00046 { 00047 throw MapException(MapException::Undefined); 00048 return 0; 00049 } 00050 /* ------------------------------------------------------------------------- */ 00051 double & BasePixel::Q() 00052 { 00053 throw MapException(MapException::Undefined); 00054 return ddummy; 00055 } 00056 /* ------------------------------------------------------------------------- */ 00057 double BasePixel::U() const 00058 { 00059 throw MapException(MapException::Undefined); 00060 return 0; 00061 } 00062 /* ------------------------------------------------------------------------- */ 00063 double & BasePixel::U() 00064 { 00065 throw MapException(MapException::Undefined); 00066 return ddummy; 00067 } 00068 /* ------------------------------------------------------------------------- */ 00069 double BasePixel::Nobs() const 00070 { 00071 throw MapException(MapException::Undefined); 00072 return 0; 00073 } 00074 /* ------------------------------------------------------------------------- */ 00075 double & BasePixel::Nobs() 00076 { 00077 throw MapException(MapException::Undefined); 00078 return ddummy; // not that we will ever get here 00079 } 00080 /* ------------------------------------------------------------------------- */ 00081 double BasePixel::Pmag() const 00082 { 00083 throw MapException(MapException::Undefined); 00084 return 0; 00085 } 00086 /* ------------------------------------------------------------------------- */ 00087 double & BasePixel::Pmag() 00088 { 00089 throw MapException(MapException::Undefined); 00090 return ddummy; // not that we will ever get here 00091 } 00092 /* ------------------------------------------------------------------------- */ 00093 double BasePixel::Pang() const 00094 { 00095 throw MapException(MapException::Undefined); 00096 return 0; 00097 } 00098 /* ------------------------------------------------------------------------- */ 00099 double & BasePixel::Pang() 00100 { 00101 throw MapException(MapException::Undefined); 00102 return ddummy; // not that we will ever get here 00103 } 00104 /* ---------------------------------------------------------------------------- 00105 'copy' copies another pixel into this one. This function captures and ignores 00106 MapException exceptions; it does NOT rethrow them. 00107 00108 Arguments: 00109 &src - The pixel to copy. 00110 00111 Returned: 00112 Nothing. 00113 00114 Written by Michael R. Greason, ADNET, 27 March 2007. 00115 ---------------------------------------------------------------------------- */ 00116 void BasePixel::copy (BasePixel& src) 00117 { 00118 try { this->T() = src.T(); } catch (MapException &exc) { ; } 00119 try { this->Q() = src.Q(); } catch (MapException &exc) { ; } 00120 try { this->U() = src.U(); } catch (MapException &exc) { ; } 00121 try { this->Nobs() = src.Nobs(); } catch (MapException &exc) { ; } 00122 try { this->Pmag() = src.Pmag(); } catch (MapException &exc) { ; } 00123 try { this->Pang() = src.Pang(); } catch (MapException &exc) { ; } 00124 } 00125 /* ---------------------------------------------------------------------------- 00126 'clear' zeros the pixel out. This function captures and ignores MapException 00127 exceptions; it does NOT rethrow them. 00128 00129 Arguments: 00130 None. 00131 00132 Returned: 00133 Nothing. 00134 00135 Written by Michael R. Greason, ADNET, 27 March 2007. 00136 ---------------------------------------------------------------------------- */ 00137 void BasePixel::clear (void) 00138 { 00139 try { this->T() = 0.0; } catch (MapException &exc) { ; } 00140 try { this->Q() = 0.0; } catch (MapException &exc) { ; } 00141 try { this->U() = 0.0; } catch (MapException &exc) { ; } 00142 try { this->Nobs() = 0.0; } catch (MapException &exc) { ; } 00143 try { this->Pmag() = 0.0; } catch (MapException &exc) { ; } 00144 try { this->Pang() = 0.0; } catch (MapException &exc) { ; } 00145 } 00146 /* ============================================================================ 00147 The TPPixel class defines a Stokes I, Q, U pixel. The polarization magnitude 00148 and angle will be computed whenever Q and U are set. 00149 ============================================================================ */ 00150 /* ---------------------------------------------------------------------------- 00151 'computePolar' computes the polarization magnitude and angle. 00152 00153 Arguments: 00154 None. 00155 00156 Returned: 00157 Nothing. 00158 00159 Written by Michael R. Greason, ADNET, 30 August 2007. 00160 ---------------------------------------------------------------------------- */ 00161 void TPPixel::computePolar (void) 00162 { 00163 Pmag_ = sqrt( (Q_ * Q_) + (U_ * U_) ); 00164 Pang_ = atan2(U_, Q_) / 2.; 00165 }