pixel.h

Go to the documentation of this file.
00001 #ifndef PIXEL_HPP
00002 #define PIXEL_HPP
00003 /* ============================================================================
00004 'pixel.h' defines the pixel classes.  Non-inline methods and space
00005 for static class members are defined in 'pixel.cpp'.
00006 
00007 Written by Nicholas Phillips, December 2006
00008 Adapted for WMAP.  FITS and copy operator added.  Michael R. Greason, ADNET,
00009         27 December 2006.
00010 Broken out of 'skymap.h'.  MRG, ADNET, 23 January 2007.
00011 Polarization magnitude and angle support.  MRG, ADNET, 30 August 2007.
00012 ============================================================================ */
00013 #include "map_exception.h"
00014 /* ============================================================================
00015 The BasePixel class provides a common denominator for the various types of
00016 supported maps.  Up to six data elements per pixel are supported:
00017 Stokes I, Q, and U, NObs, Pmag and Pang.
00018 
00019 The contents may be accessed through the T/I, Q, U, Nobs, Pmag, and Pang
00020 functions; these functions may be used on either side of the equals sign.
00021 An exception is thrown if an undefined value is accessed.
00022 ============================================================================ */
00023 class BasePixel
00024 {
00025         protected:
00026                 static double ddummy;
00027         public:
00028                 BasePixel(){};
00029                 virtual ~BasePixel() {};
00030                 virtual double   T()    const;
00031                 virtual double & T()         ;
00032                 virtual double   I()    const;
00033                 virtual double & I()         ;
00034                 virtual double   Q()    const;
00035                 virtual double & Q()         ;
00036                 virtual double   U()    const;
00037                 virtual double & U()         ;
00038                 virtual double   Nobs() const;
00039                 virtual double & Nobs()      ;
00040                 virtual double   Pmag() const;
00041                 virtual double & Pmag()      ;
00042                 virtual double   Pang() const;
00043                 virtual double & Pang()      ;
00044                 
00045                 virtual void copy (BasePixel& src);
00046                 virtual void clear (void);
00047                 
00048                 BasePixel& operator= (BasePixel& src);
00049                 double operator[](unsigned int i) const;
00050                 double & operator[](unsigned int i);
00051                 virtual unsigned int maxIndex (void) const;
00052                 virtual void computePolar (void) { return; }
00053 };
00054 /* ----------------------------------------------------------------------------
00055 'operator=' copies another pixel into this one.
00056 
00057 Arguments:
00058         &src  - The pixel to copy.
00059 
00060 Returned:
00061         *this - A reference to this pixel.
00062 ---------------------------------------------------------------------------- */
00063 inline BasePixel& BasePixel::operator= (BasePixel& src)
00064 {
00065         copy(src);
00066         return *this;
00067 }
00068 /* ----------------------------------------------------------------------------
00069 'operator[]' allows the pixel to be indexed as an array.
00070 
00071 Arguments:
00072         i  -  The index into the array:
00073                         0 - Stokes I
00074                         1 - Stokes Q
00075                         2 - Stokes U
00076                         3 - Nobs
00077                         4 - Polarization magnitude
00078                         5 - Polarization angle wrt the meridian
00079 
00080 Returned:
00081         The associated value.  0 is returned if the pixel doesn't support the
00082         requested information; an exception is also thrown.  An exception is also
00083         thrown if the index is out of bounds.
00084 ---------------------------------------------------------------------------- */
00085 inline double BasePixel::operator[](unsigned int i) const
00086 {
00087         double rv = 0;
00088         switch( i ){
00089                 case 0:
00090                         rv = T();
00091                         break;
00092                 case 1:
00093                         rv = Q();
00094                         break;
00095                 case 2: 
00096                         rv = U();
00097                         break;
00098                 case 3: 
00099                         rv = Nobs();
00100                         break;
00101                 case 4: 
00102                         rv = Pmag();
00103                         break;
00104                 case 5: 
00105                         rv = Pang();
00106                         break;
00107                 default:
00108                         throw MapException(MapException::Undefined);
00109         }
00110         return rv;
00111 }
00112 inline double & BasePixel::operator[](unsigned int i)
00113 {
00114         switch( i ){
00115                 case 0:
00116                         return T();
00117                         break;
00118                 case 1:
00119                         return Q();
00120                         break;
00121                 case 2: 
00122                         return U();
00123                         break;
00124                 case 3: 
00125                         return Nobs();
00126                         break;
00127                 case 4: 
00128                         return Pmag();
00129                         break;
00130                 case 5: 
00131                         return Pang();
00132                         break;
00133                 default:
00134                         throw MapException(MapException::Undefined);
00135         }
00136         return ddummy;
00137 }
00138 /* ----------------------------------------------------------------------------
00139 'maxIndex' returns the maximum index number allowed by the pixel class when
00140 indexing into it as an array.
00141 
00142 Arguments:
00143         None.
00144 
00145 Returned:
00146         The maximum index allowed by the pixel class.
00147 ---------------------------------------------------------------------------- */
00148 inline unsigned int BasePixel::maxIndex(void) const
00149 {
00150         throw MapException(MapException::Undefined);
00151         return 0;
00152 }
00153 /* ============================================================================
00154 The TPixel class defines a temperature/Stokes I-only pixel.
00155 ============================================================================ */
00156 class TPixel : public BasePixel
00157 {
00158         protected:
00159                 double T_;
00160         public:
00161                 TPixel() : T_(0) {};            
00162                 virtual ~TPixel() {};
00163                 virtual double   T() const { return T_; };
00164                 virtual double & T()       { return T_; };
00165                 virtual double   I() const { return T_; };
00166                 virtual double & I()       { return T_; };
00167                 virtual unsigned int maxIndex (void) const { return 0; }
00168 };
00169 /* ============================================================================
00170 The TPPixel class defines a Stokes I, Q, U pixel.  The polarization magnitude
00171 and angle will be computed whenever Q and U are set.
00172 ============================================================================ */
00173 class TPPixel : public TPixel
00174 {
00175         protected:
00176                 double Q_;
00177                 double U_;
00178                 double Pmag_;
00179                 double Pang_;
00180         public:
00181                 TPPixel() : TPixel(), Q_(0), U_(0), Pmag_(0), Pang_(0) {};
00182                 virtual ~TPPixel() {};
00183                 virtual double   Q()    const { return Q_;    };
00184                 virtual double & Q()          { return Q_;    };
00185                 virtual double   U()    const { return U_;    };
00186                 virtual double & U()          { return U_;    };
00187                 virtual double   Pmag() const { return Pmag_; };
00188                 virtual double & Pmag()       { return Pmag_; };
00189                 virtual double   Pang() const { return Pang_; };
00190                 virtual double & Pang()       { return Pang_; };
00191                 virtual unsigned int maxIndex (void) const { return 5; }
00192                 virtual void computePolar (void);
00193 };
00194 /* ============================================================================
00195 The TnobsPixel class defines a temperature/Stokes I-only pixel with an nobs 
00196 component.
00197 ============================================================================ */
00198 class TnobsPixel : public TPixel
00199 {
00200         protected:
00201                 double nobs_;
00202         public:
00203                 TnobsPixel() : TPixel(), nobs_(0) {};           
00204                 virtual ~TnobsPixel() {};
00205                 virtual double    Nobs() const { return nobs_; };
00206                 virtual double  & Nobs()       { return nobs_; };
00207                 virtual unsigned int maxIndex (void) const { return 2; }
00208 };
00209 /* ============================================================================
00210 The TPnobsPixel class defines a Stokes I, Q, U pixel with an nobs component.
00211 ============================================================================ */
00212 class TPnobsPixel : public TPPixel
00213 {
00214         protected:
00215                 double nobs_;
00216         public:
00217                 TPnobsPixel() : TPPixel(), nobs_(0) {}; 
00218                 virtual ~TPnobsPixel() {};
00219                 virtual double    Nobs() const { return nobs_; };
00220                 virtual double  & Nobs()       { return nobs_; };
00221                 virtual unsigned int maxIndex (void) const { return 6; }
00222 };
00223 #endif

Generated on Fri Feb 6 15:32:42 2009 for Skyviewer by  doxygen 1.4.7