| 1 | // This may look like C code, but it is really -*- C++ -*- | 
|---|
| 2 | #ifndef LOCALMAP_SEEN | 
|---|
| 3 | #define LOCALMAP_SEEN | 
|---|
| 4 |  | 
|---|
| 5 | #include "pixelmap.h" | 
|---|
| 6 | #include "sphericalmap.h" | 
|---|
| 7 | #include "ndatablock.h" | 
|---|
| 8 |  | 
|---|
| 9 | #include "anydataobj.h" | 
|---|
| 10 | #include "ppersist.h" | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | // ***************** Class LocalMap ***************************** | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | namespace SOPHYA { | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | template <class T> | 
|---|
| 22 | class FIO_LocalMap; | 
|---|
| 23 |  | 
|---|
| 24 | template<class T> | 
|---|
| 25 | class FITS_LocalMap; | 
|---|
| 26 |  | 
|---|
| 27 | /* Class LocalMap */ | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | template<class T> | 
|---|
| 31 | class LocalMap : public PixelMap<T> | 
|---|
| 32 | { | 
|---|
| 33 |  | 
|---|
| 34 | // friend declaration for classes which handle persistence and FITS IO | 
|---|
| 35 | friend class FIO_LocalMap<T>; | 
|---|
| 36 | friend class FITS_LocalMap<T>; | 
|---|
| 37 |  | 
|---|
| 38 | public: | 
|---|
| 39 |  | 
|---|
| 40 | LocalMap(); | 
|---|
| 41 | LocalMap(int_4 nx, int_4 ny); | 
|---|
| 42 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle=0.); | 
|---|
| 43 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle=0.); | 
|---|
| 44 | LocalMap(const LocalMap<T>& lm, bool share); | 
|---|
| 45 | LocalMap(const LocalMap<T>& lm); | 
|---|
| 46 | virtual ~LocalMap(); | 
|---|
| 47 |  | 
|---|
| 48 | inline virtual bool IsTemp(void) const { return pixels_.IsTemp();} | 
|---|
| 49 |  | 
|---|
| 50 | /*! Setting blockdata to temporary (see ndatablock documentation) */ | 
|---|
| 51 | inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);}; | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | // ---------- Overloading of () to access pixel number k ---- | 
|---|
| 55 |  | 
|---|
| 56 | inline T& operator()(int_4 k) {return(this->PixVal(k));} | 
|---|
| 57 | inline T const& operator()(int_4 k) const {return(this->PixVal(k));} | 
|---|
| 58 | inline T& operator()(int_4 ix, int_4 iy) {return this->PixVal(iy*nSzX_+ix);}; | 
|---|
| 59 | inline T const& operator()(int_4 ix, int_4 iy) const {return this->PixVal(iy*nSzX_+ix);}; | 
|---|
| 60 |  | 
|---|
| 61 | // Acces a un pixel | 
|---|
| 62 | inline T& operator()(double theta,double phi) {return(this->PixValSph(theta,phi));}; | 
|---|
| 63 | inline T  const& operator()(double theta,double phi) const {return(this->PixValSph(theta,phi));}; | 
|---|
| 64 |  | 
|---|
| 65 | // ---------- Definition of PixelMap abstract methods ------- | 
|---|
| 66 |  | 
|---|
| 67 | virtual int_4 NbPixels() const;   // D.Y. int change en int_4 rationalisation Mac | 
|---|
| 68 |  | 
|---|
| 69 | virtual T& PixVal(int_4 k); | 
|---|
| 70 | virtual T const& PixVal(int_4 k) const; | 
|---|
| 71 | //! if fg = true, will generate  exceptions , when theta-phi out of range | 
|---|
| 72 | inline  void SetThrowExceptionWhenOutofMapFlag(bool fg = false) { exc_outofmap_ = fg; } | 
|---|
| 73 |  | 
|---|
| 74 | //! true --> exceptions wil be active when theta-phi out of range | 
|---|
| 75 | inline  bool GetThrowExceptionWhenOutofMapFlag() { return exc_outofmap_; } | 
|---|
| 76 |  | 
|---|
| 77 | virtual bool ContainsSph(double theta, double phi) const; | 
|---|
| 78 | //! return pixel number correspoinding to (theta,phi) | 
|---|
| 79 | virtual int_4 PixIndexSph(double theta,double phi) const; | 
|---|
| 80 |  | 
|---|
| 81 | //! return (theta,phi) correspoinding to pixel number k | 
|---|
| 82 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const; | 
|---|
| 83 |  | 
|---|
| 84 | //! set all pixel values equal to v | 
|---|
| 85 | virtual T SetPixels(T v); | 
|---|
| 86 |  | 
|---|
| 87 | // return the solid angle covered by pixel k (steradians) | 
|---|
| 88 | virtual double PixSolAngle(int_4 k) const; | 
|---|
| 89 |  | 
|---|
| 90 | // ---------- Specific methods ------------------------------ | 
|---|
| 91 |  | 
|---|
| 92 | void ReSize(int_4 nx, int_4 ny); | 
|---|
| 93 |  | 
|---|
| 94 | void SetOrigin(double theta=90.,double phi=0.,double angle=0.); | 
|---|
| 95 | void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.); | 
|---|
| 96 | void SetSize(double angleX,double angleY); | 
|---|
| 97 |  | 
|---|
| 98 | /*! \fn TypeOfMap() | 
|---|
| 99 | return the string "LOCAL" | 
|---|
| 100 | */ | 
|---|
| 101 | inline virtual string TypeOfMap() const {return string("LOCAL");}; | 
|---|
| 102 |  | 
|---|
| 103 |  | 
|---|
| 104 | /*! Check to see if the local mapping is done */ | 
|---|
| 105 | inline bool LocalMap_isDone() const {return( originSet_ && angleSized_ && pixelSized_);}; | 
|---|
| 106 |  | 
|---|
| 107 | void PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const; | 
|---|
| 108 |  | 
|---|
| 109 |  | 
|---|
| 110 | void ProjectionToSphere(SphericalMap<T>&) const; | 
|---|
| 111 |  | 
|---|
| 112 | /* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere. | 
|---|
| 113 | -> static method, or separate class */ | 
|---|
| 114 |  | 
|---|
| 115 | /*! provides a integer characterizing the pixelization refinement  (here : number of pixels) */ | 
|---|
| 116 | inline virtual int_4 SizeIndex() const {return(nPix_);} | 
|---|
| 117 | inline int_4 Size_x() const {return nSzX_;} | 
|---|
| 118 | inline int_4 Size_y() const {return nSzY_;} | 
|---|
| 119 |  | 
|---|
| 120 | /* Je rajoute ces 2 fonctions inlines pour compatibilite d'interface | 
|---|
| 121 | avec TArray  -   Reza 30/8/2000                                   */ | 
|---|
| 122 | inline int_4 SizeX() const {return nSzX_;} | 
|---|
| 123 | inline int_4 SizeY() const {return nSzY_;} | 
|---|
| 124 |  | 
|---|
| 125 | inline void Origin(double& theta,double& phi,int_4& x0,int_4& y0,double& angle) const {theta= thetaDegresC_; phi= phiDegresC_; x0= x0_; y0= y0_;angle= angleDegres_;} | 
|---|
| 126 |  | 
|---|
| 127 | /*! total aperture in theta and phi, in degrees ( from SetSize() ) */ | 
|---|
| 128 | inline void Aperture(double& anglex,double& angley) const {anglex= angleDegresX_; angley= angleDegresY_;} | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | /*  Acces to the DataBlock  */ | 
|---|
| 132 | inline       NDataBlock<T>& DataBlock()       {return pixels_.DataBlock();} | 
|---|
| 133 | inline const NDataBlock<T>& DataBlock() const {return pixels_.DataBlock();} | 
|---|
| 134 |  | 
|---|
| 135 | /*  Acces to the matrix  */ | 
|---|
| 136 | //! access to matrix | 
|---|
| 137 | /*! | 
|---|
| 138 | \warning : a pixel is defined by the pair of a phi-like index | 
|---|
| 139 | (x-axis) and a theta-like index (y-axis). The phi-like index denotes | 
|---|
| 140 | the column number in the matrix ; the theta-like index denotes the | 
|---|
| 141 | row number. | 
|---|
| 142 | */ | 
|---|
| 143 | inline       TMatrix<T>& Matrix()       {return pixels_;} | 
|---|
| 144 | inline const TMatrix<T>& Matrix() const {return pixels_;} | 
|---|
| 145 |  | 
|---|
| 146 | /* impression */ | 
|---|
| 147 | void print(ostream& os) const; | 
|---|
| 148 |  | 
|---|
| 149 | // Operations diverses  = , +=, ... | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 | virtual LocalMap<T>& Set(const LocalMap<T>& a); | 
|---|
| 153 | inline  LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);} | 
|---|
| 154 |  | 
|---|
| 155 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements) | 
|---|
| 156 |  | 
|---|
| 157 | //! Fill LocalMap with all elements equal to \b x | 
|---|
| 158 | virtual LocalMap<T>& SetT(T a); | 
|---|
| 159 | inline  LocalMap<T>& operator = (T a) {return SetT(a);} | 
|---|
| 160 |  | 
|---|
| 161 | // Add \b x to all elements | 
|---|
| 162 | virtual LocalMap<T>& Add(T a); | 
|---|
| 163 | inline  LocalMap<T>&  operator += (T x)  { return Add(x); } | 
|---|
| 164 | // Substract \b x to all elements | 
|---|
| 165 | virtual LocalMap<T>& Sub(T a,bool fginv=false); | 
|---|
| 166 | inline   LocalMap<T>&  operator -= (T x)  { return Sub(x); } | 
|---|
| 167 | // Multiply all elements by \b x | 
|---|
| 168 | virtual LocalMap<T>& Mul(T a); | 
|---|
| 169 | inline  LocalMap<T>&  operator *= (T x)  { return Mul(x); } | 
|---|
| 170 | // Divide all elements by \b x | 
|---|
| 171 | virtual LocalMap<T>& Div(T a); | 
|---|
| 172 | inline  LocalMap<T>&  operator /= (T x)  { return Div(x); } | 
|---|
| 173 |  | 
|---|
| 174 | // A += -=  (ajoute, soustrait element par element les deux spheres ) | 
|---|
| 175 | //! Operator LocalMap += LocalMap | 
|---|
| 176 | virtual LocalMap<T>&  AddElt(const LocalMap<T>& a); | 
|---|
| 177 | inline  LocalMap<T>&  operator += (const LocalMap<T>& a)  { return AddElt(a); } | 
|---|
| 178 |  | 
|---|
| 179 |  | 
|---|
| 180 |  | 
|---|
| 181 | virtual LocalMap<T>&  SubElt(const LocalMap<T>& a); | 
|---|
| 182 | //! Operator LocalMap -= LocalMap | 
|---|
| 183 | inline  LocalMap<T>&  operator -= (const LocalMap<T>& a)  { return SubElt(a); } | 
|---|
| 184 | // Multiplication, division element par element les deux LocalMap | 
|---|
| 185 | virtual LocalMap<T>&  MulElt(const LocalMap<T>& a); | 
|---|
| 186 | inline  LocalMap<T>&  operator *= (const LocalMap<T>& a)  { return MulElt(a); } | 
|---|
| 187 | virtual LocalMap<T>&  DivElt(const LocalMap<T>& a); | 
|---|
| 188 | inline  LocalMap<T>&  operator /= (const LocalMap<T>& a)  { return DivElt(a); } | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|
| 191 | void CloneOrShare(const LocalMap<T>& a); | 
|---|
| 192 | void Share(const LocalMap<T>& a); | 
|---|
| 193 | LocalMap<T>& CopyElt(const LocalMap<T>& a); | 
|---|
| 194 |  | 
|---|
| 195 | //! assign a new object Id (or DataRef Id) - useful for PPF write operations | 
|---|
| 196 | inline void RenewObjId() { pixels_.RenewObjId(); } | 
|---|
| 197 |  | 
|---|
| 198 | // ---------- Méthodes internes ----------------------------- | 
|---|
| 199 |  | 
|---|
| 200 | private : | 
|---|
| 201 |  | 
|---|
| 202 | void InitNul(); | 
|---|
| 203 | void SetCoorC(double theta0, double phi0); | 
|---|
| 204 | TMatrix<double> CalculMatricePassage(); | 
|---|
| 205 | void Getij(int_4 k,int_4& i,int_4& j) const; | 
|---|
| 206 | void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const; | 
|---|
| 207 |  | 
|---|
| 208 | void recopierVariablesSimples(const LocalMap<T>& lm); | 
|---|
| 209 |  | 
|---|
| 210 | void initializationError() const; | 
|---|
| 211 |  | 
|---|
| 212 |  | 
|---|
| 213 | // ---------- Variables internes ---------------------------- | 
|---|
| 214 | // variables suffisantes pour reconstruire l'objet | 
|---|
| 215 |  | 
|---|
| 216 | bool pixelSized_; | 
|---|
| 217 | bool angleSized_; | 
|---|
| 218 | bool originSet_; | 
|---|
| 219 |  | 
|---|
| 220 | int_4 nSzX_; | 
|---|
| 221 | int_4 nSzY_; | 
|---|
| 222 | double angleDegresX_; | 
|---|
| 223 | double angleDegresY_; | 
|---|
| 224 | double thetaDegresC_; | 
|---|
| 225 | double phiDegresC_; | 
|---|
| 226 | int_4 x0_; | 
|---|
| 227 | int_4 y0_; | 
|---|
| 228 | double angleDegres_; | 
|---|
| 229 |  | 
|---|
| 230 |  | 
|---|
| 231 | //  NDataBlock<T> pixels_; | 
|---|
| 232 | TMatrix<T> pixels_; | 
|---|
| 233 |  | 
|---|
| 234 |  | 
|---|
| 235 | // variables derivees (redondantes, precalculees pour ameliorer | 
|---|
| 236 | // les performances) | 
|---|
| 237 |  | 
|---|
| 238 | int_4 nPix_; | 
|---|
| 239 |  | 
|---|
| 240 |  | 
|---|
| 241 | double thetaC_; | 
|---|
| 242 | double phiC_; | 
|---|
| 243 | double csthC_; | 
|---|
| 244 | double snthC_; | 
|---|
| 245 | double csphC_; | 
|---|
| 246 | double snphC_; | 
|---|
| 247 | double XC_; | 
|---|
| 248 | double YC_; | 
|---|
| 249 | double ZC_; | 
|---|
| 250 |  | 
|---|
| 251 |  | 
|---|
| 252 | double angle_; | 
|---|
| 253 | double cosAngle_; | 
|---|
| 254 | double sinAngle_; | 
|---|
| 255 | double deltaPhi_; | 
|---|
| 256 | double deltaTheta_; | 
|---|
| 257 |  | 
|---|
| 258 | bool exc_outofmap_; | 
|---|
| 259 |  | 
|---|
| 260 |  | 
|---|
| 261 | }; | 
|---|
| 262 |  | 
|---|
| 263 | //////////////////////////////////////////////////////////////// | 
|---|
| 264 | // Surcharge d'operateurs A (+,-,*,/) (T) x | 
|---|
| 265 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,T) | 
|---|
| 266 | \brief Operator LocalMap = LocalMap + constant */ | 
|---|
| 267 | template <class T> inline LocalMap<T> operator + (const LocalMap<T>& a, T b) | 
|---|
| 268 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 269 | result.Add(b); return result;} | 
|---|
| 270 | /*! \ingroup SkyMap \fn operator+(T,const LocalMap<T>&) | 
|---|
| 271 | \brief Operator LocalMap = constant + LocalMap */ | 
|---|
| 272 | template <class T> inline LocalMap<T> operator + (T b,const LocalMap<T>& a) | 
|---|
| 273 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 274 | result.Add(b); return result;} | 
|---|
| 275 |  | 
|---|
| 276 |  | 
|---|
| 277 | /*! \ingroup SkyMap\fn operator-(const LocalMap<T>&,T) | 
|---|
| 278 | \brief Operator LocalMap = LocalMap - constant */ | 
|---|
| 279 | template <class T> inline LocalMap<T> operator - (const LocalMap<T>& a, T b) | 
|---|
| 280 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 281 | result.Sub(b); return result;} | 
|---|
| 282 |  | 
|---|
| 283 | /*! \ingroup  \fn operator-(T,const LocalMap<T>&) | 
|---|
| 284 | \brief Operator LocalMap = constant - LocalMap */ | 
|---|
| 285 | template <class T> inline LocalMap<T> operator - (T b,const LocalMap<T>& a) | 
|---|
| 286 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 287 | result.Sub(b,true); return result;} | 
|---|
| 288 |  | 
|---|
| 289 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,T) | 
|---|
| 290 | \brief Operator LocalMap = LocalMap * constant */ | 
|---|
| 291 | template <class T> inline LocalMap<T> operator * (const LocalMap<T>& a, T b) | 
|---|
| 292 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 293 | result.Mul(b); return result;} | 
|---|
| 294 |  | 
|---|
| 295 | /*! \ingroup SkyMap \fn operator*(T,const LocalMap<T>&) | 
|---|
| 296 | \brief Operator LocalMap = constant * LocalMap */ | 
|---|
| 297 | template <class T> inline LocalMap<T> operator * (T b,const LocalMap<T>& a) | 
|---|
| 298 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 299 | result.Mul(b); return result;} | 
|---|
| 300 |  | 
|---|
| 301 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,T) | 
|---|
| 302 | \brief Operator LocalMap = LocalMap / constant */ | 
|---|
| 303 | template <class T> inline LocalMap<T> operator / (const LocalMap<T>& a, T b) | 
|---|
| 304 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 305 | result.Div(b); return result;} | 
|---|
| 306 |  | 
|---|
| 307 | /*! \ingroup SkyMap \fn operator/(T,const LocalMap<T>&) | 
|---|
| 308 | \brief Operator LocalMap = constant / LocalMap  */ | 
|---|
| 309 | template <class T> inline LocalMap<T> operator / (T b, const LocalMap<T>& a) | 
|---|
| 310 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true); | 
|---|
| 311 | result.Div(b, true); return result;} | 
|---|
| 312 |  | 
|---|
| 313 | //////////////////////////////////////////////////////////////// | 
|---|
| 314 | // Surcharge d'operateurs C = A (+,-) B | 
|---|
| 315 |  | 
|---|
| 316 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&) | 
|---|
| 317 | \brief Operator LocalMap = LocalMap + LocalMap */ | 
|---|
| 318 | template <class T> | 
|---|
| 319 | inline LocalMap<T> operator + (const LocalMap<T>& a,const LocalMap<T>& b) | 
|---|
| 320 | { LocalMap<T> result; result.SetTemp(true); | 
|---|
| 321 | if (b.IsTemp())  { result.Share(b); result.AddElt(a); } | 
|---|
| 322 | else { result.CloneOrShare(a); result.AddElt(b); } | 
|---|
| 323 | return result; } | 
|---|
| 324 |  | 
|---|
| 325 | /*! \ingroup SkyMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&) | 
|---|
| 326 | \brief Operator LocalMap = LocalMap - LocalMap */ | 
|---|
| 327 | template <class T> | 
|---|
| 328 | inline LocalMap<T> operator - (const LocalMap<T>& a,const LocalMap<T>& b) | 
|---|
| 329 | { LocalMap<T> result; result.SetTemp(true); | 
|---|
| 330 | if (b.IsTemp())  { result.Share(b); result.SubElt(a); } | 
|---|
| 331 | else { result.CloneOrShare(a); result.SubElt(b); } | 
|---|
| 332 | return result; } | 
|---|
| 333 |  | 
|---|
| 334 | //////////////////////////////////////////////////////////////// | 
|---|
| 335 | // Surcharge d'operateurs C = A (*,/) B | 
|---|
| 336 |  | 
|---|
| 337 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,const LocalMap<T>&) | 
|---|
| 338 | \brief Operator LocalMap = LocalMap * LocalMap (pixel by pixel multiply)*/ | 
|---|
| 339 | template <class T> | 
|---|
| 340 | inline LocalMap<T> operator * (const LocalMap<T>& a,const LocalMap<T>& b) | 
|---|
| 341 | { LocalMap<T> result; result.SetTemp(true); | 
|---|
| 342 | if (b.IsTemp())  { result.Share(b); result.MulElt(a); } | 
|---|
| 343 | else { result.CloneOrShare(a); result.MulElt(b); } | 
|---|
| 344 | return result; } | 
|---|
| 345 |  | 
|---|
| 346 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,const LocalMap<T>&) | 
|---|
| 347 | \brief Operator LocalMap = LocalMap / LocalMap (pixel by pixel divide)*/ | 
|---|
| 348 | template <class T> | 
|---|
| 349 | inline LocalMap<T> operator / (const LocalMap<T>& a,const LocalMap<T>& b) | 
|---|
| 350 | { LocalMap<T> result; result.SetTemp(true); | 
|---|
| 351 | result.CloneOrShare(a); result.DivElt(b); | 
|---|
| 352 | return result; } | 
|---|
| 353 |  | 
|---|
| 354 |  | 
|---|
| 355 |  | 
|---|
| 356 | } // Fin du namespace | 
|---|
| 357 |  | 
|---|
| 358 | #endif | 
|---|