[764] | 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 |
|
---|
[841] | 16 |
|
---|
| 17 |
|
---|
| 18 | namespace SOPHYA {
|
---|
| 19 |
|
---|
| 20 |
|
---|
[2013] | 21 | template <class T>
|
---|
| 22 | class FIO_LocalMap;
|
---|
| 23 |
|
---|
| 24 | template<class T>
|
---|
| 25 | class FITS_LocalMap;
|
---|
| 26 |
|
---|
[1217] | 27 | /* Class LocalMap */
|
---|
| 28 |
|
---|
| 29 |
|
---|
[764] | 30 | template<class T>
|
---|
| 31 | class LocalMap : public PixelMap<T>
|
---|
| 32 | {
|
---|
| 33 |
|
---|
[2013] | 34 | // friend declaration for classes which handle persistence and FITS IO
|
---|
| 35 | friend class FIO_LocalMap<T>;
|
---|
| 36 | friend class FITS_LocalMap<T>;
|
---|
| 37 |
|
---|
[764] | 38 | public:
|
---|
| 39 |
|
---|
| 40 | LocalMap();
|
---|
[2198] | 41 | LocalMap(int_4 nx, int_4 ny);
|
---|
[2013] | 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.);
|
---|
[917] | 44 | LocalMap(const LocalMap<T>& lm, bool share);
|
---|
[908] | 45 | LocalMap(const LocalMap<T>& lm);
|
---|
[764] | 46 | virtual ~LocalMap();
|
---|
| 47 |
|
---|
[908] | 48 | inline virtual bool IsTemp(void) const { return pixels_.IsTemp();}
|
---|
[1217] | 49 |
|
---|
[764] | 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 |
|
---|
[2885] | 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);};
|
---|
[2052] | 60 |
|
---|
| 61 | // Acces a un pixel
|
---|
[2885] | 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));};
|
---|
[764] | 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;
|
---|
[2290] | 71 | //! if fg = true, will generate exceptions , when theta-phi out of range
|
---|
| 72 | inline void SetThrowExceptionWhenOutofMapFlag(bool fg = false) { exc_outofmap_ = fg; }
|
---|
[764] | 73 |
|
---|
[2290] | 74 | //! true --> exceptions wil be active when theta-phi out of range
|
---|
[2056] | 75 | inline bool GetThrowExceptionWhenOutofMapFlag() { return exc_outofmap_; }
|
---|
[2052] | 76 |
|
---|
[764] | 77 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
[2290] | 78 | //! return pixel number correspoinding to (theta,phi)
|
---|
[764] | 79 | virtual int_4 PixIndexSph(double theta,double phi) const;
|
---|
| 80 |
|
---|
[2290] | 81 | //! return (theta,phi) correspoinding to pixel number k
|
---|
[764] | 82 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const;
|
---|
| 83 |
|
---|
[2290] | 84 | //! set all pixel values equal to v
|
---|
[764] | 85 | virtual T SetPixels(T v);
|
---|
| 86 |
|
---|
[2290] | 87 | // return the solid angle covered by pixel k (steradians)
|
---|
[764] | 88 | virtual double PixSolAngle(int_4 k) const;
|
---|
| 89 |
|
---|
| 90 | // ---------- Specific methods ------------------------------
|
---|
| 91 |
|
---|
| 92 | void ReSize(int_4 nx, int_4 ny);
|
---|
| 93 |
|
---|
[2198] | 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 |
|
---|
[2290] | 98 | /*! \fn TypeOfMap()
|
---|
| 99 | return the string "LOCAL"
|
---|
| 100 | */
|
---|
| 101 | inline virtual string TypeOfMap() const {return string("LOCAL");};
|
---|
[764] | 102 |
|
---|
| 103 |
|
---|
[1217] | 104 | /*! Check to see if the local mapping is done */
|
---|
[2198] | 105 | inline bool LocalMap_isDone() const {return( originSet_ && angleSized_ && pixelSized_);};
|
---|
[764] | 106 |
|
---|
[2013] | 107 | void PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const;
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | void ProjectionToSphere(SphericalMap<T>&) const;
|
---|
[764] | 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 |
|
---|
[1217] | 115 | /*! provides a integer characterizing the pixelization refinement (here : number of pixels) */
|
---|
[764] | 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 |
|
---|
[1163] | 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 |
|
---|
[2013] | 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_;}
|
---|
[764] | 126 |
|
---|
[2013] | 127 | /*! total aperture in theta and phi, in degrees ( from SetSize() ) */
|
---|
| 128 | inline void Aperture(double& anglex,double& angley) const {anglex= angleDegresX_; angley= angleDegresY_;}
|
---|
[764] | 129 |
|
---|
| 130 |
|
---|
| 131 | /* Acces to the DataBlock */
|
---|
[2013] | 132 | inline NDataBlock<T>& DataBlock() {return pixels_.DataBlock();}
|
---|
| 133 | inline const NDataBlock<T>& DataBlock() const {return pixels_.DataBlock();}
|
---|
[764] | 134 |
|
---|
[2013] | 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 |
|
---|
[764] | 146 | /* impression */
|
---|
| 147 | void print(ostream& os) const;
|
---|
| 148 |
|
---|
[1419] | 149 | // Operations diverses = , +=, ...
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | virtual LocalMap<T>& Set(const LocalMap<T>& a);
|
---|
[908] | 153 | inline LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);}
|
---|
| 154 |
|
---|
[1419] | 155 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
[908] | 156 |
|
---|
[1419] | 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);}
|
---|
[908] | 160 |
|
---|
[2290] | 161 | // Add \b x to all elements
|
---|
[1419] | 162 | virtual LocalMap<T>& Add(T a);
|
---|
| 163 | inline LocalMap<T>& operator += (T x) { return Add(x); }
|
---|
[2290] | 164 | // Substract \b x to all elements
|
---|
[1624] | 165 | virtual LocalMap<T>& Sub(T a,bool fginv=false);
|
---|
[1419] | 166 | inline LocalMap<T>& operator -= (T x) { return Sub(x); }
|
---|
[2290] | 167 | // Multiply all elements by \b x
|
---|
[1419] | 168 | virtual LocalMap<T>& Mul(T a);
|
---|
| 169 | inline LocalMap<T>& operator *= (T x) { return Mul(x); }
|
---|
[2290] | 170 | // Divide all elements by \b x
|
---|
[1419] | 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); }
|
---|
[1551] | 187 | virtual LocalMap<T>& DivElt(const LocalMap<T>& a);
|
---|
| 188 | inline LocalMap<T>& operator /= (const LocalMap<T>& a) { return DivElt(a); }
|
---|
[1419] | 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 |
|
---|
[764] | 196 | // ---------- Méthodes internes -----------------------------
|
---|
| 197 |
|
---|
| 198 | private :
|
---|
| 199 |
|
---|
| 200 | void InitNul();
|
---|
[2013] | 201 | void SetCoorC(double theta0, double phi0);
|
---|
| 202 | TMatrix<double> CalculMatricePassage();
|
---|
[764] | 203 | void Getij(int_4 k,int_4& i,int_4& j) const;
|
---|
[2013] | 204 | void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const;
|
---|
[764] | 205 |
|
---|
[908] | 206 | void recopierVariablesSimples(const LocalMap<T>& lm);
|
---|
| 207 |
|
---|
[2198] | 208 | void initializationError() const;
|
---|
[908] | 209 |
|
---|
[764] | 210 | // ---------- Variables internes ----------------------------
|
---|
| 211 |
|
---|
[2013] | 212 |
|
---|
| 213 | // variables suffisantes pour reconstruire l'objet
|
---|
| 214 |
|
---|
[2198] | 215 | bool pixelSized_;
|
---|
| 216 | bool angleSized_;
|
---|
| 217 | bool originSet_;
|
---|
| 218 |
|
---|
[2013] | 219 | int_4 nSzX_;
|
---|
| 220 | int_4 nSzY_;
|
---|
| 221 | double angleDegresX_;
|
---|
| 222 | double angleDegresY_;
|
---|
| 223 | double thetaDegresC_;
|
---|
| 224 | double phiDegresC_;
|
---|
| 225 | int_4 x0_;
|
---|
| 226 | int_4 y0_;
|
---|
| 227 | double angleDegres_;
|
---|
| 228 |
|
---|
[2198] | 229 |
|
---|
[2013] | 230 | // NDataBlock<T> pixels_;
|
---|
| 231 | TMatrix<T> pixels_;
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 | // variables derivees (redondantes, precalculees pour ameliorer
|
---|
| 235 | // les performances)
|
---|
| 236 |
|
---|
| 237 | int_4 nPix_;
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | double thetaC_;
|
---|
| 241 | double phiC_;
|
---|
| 242 | double csthC_;
|
---|
| 243 | double snthC_;
|
---|
| 244 | double csphC_;
|
---|
| 245 | double snphC_;
|
---|
| 246 | double XC_;
|
---|
| 247 | double YC_;
|
---|
| 248 | double ZC_;
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 | double angle_;
|
---|
| 252 | double cosAngle_;
|
---|
| 253 | double sinAngle_;
|
---|
| 254 | double deltaPhi_;
|
---|
| 255 | double deltaTheta_;
|
---|
| 256 |
|
---|
[2052] | 257 | bool exc_outofmap_;
|
---|
[2013] | 258 |
|
---|
| 259 |
|
---|
[764] | 260 | };
|
---|
| 261 |
|
---|
[1419] | 262 | ////////////////////////////////////////////////////////////////
|
---|
| 263 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 264 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,T)
|
---|
[1419] | 265 | \brief Operator LocalMap = LocalMap + constant */
|
---|
| 266 | template <class T> inline LocalMap<T> operator + (const LocalMap<T>& a, T b)
|
---|
| 267 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 268 | result.Add(b); return result;}
|
---|
[1423] | 269 | /*! \ingroup SkyMap \fn operator+(T,const LocalMap<T>&)
|
---|
[1419] | 270 | \brief Operator LocalMap = constant + LocalMap */
|
---|
| 271 | template <class T> inline LocalMap<T> operator + (T b,const LocalMap<T>& a)
|
---|
| 272 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 273 | result.Add(b); return result;}
|
---|
[764] | 274 |
|
---|
| 275 |
|
---|
[1423] | 276 | /*! \ingroup SkyMap\fn operator-(const LocalMap<T>&,T)
|
---|
[1419] | 277 | \brief Operator LocalMap = LocalMap - constant */
|
---|
| 278 | template <class T> inline LocalMap<T> operator - (const LocalMap<T>& a, T b)
|
---|
| 279 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 280 | result.Sub(b); return result;}
|
---|
| 281 |
|
---|
| 282 | /*! \ingroup \fn operator-(T,const LocalMap<T>&)
|
---|
| 283 | \brief Operator LocalMap = constant - LocalMap */
|
---|
| 284 | template <class T> inline LocalMap<T> operator - (T b,const LocalMap<T>& a)
|
---|
| 285 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 286 | result.Sub(b,true); return result;}
|
---|
| 287 |
|
---|
[1423] | 288 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,T)
|
---|
[1419] | 289 | \brief Operator LocalMap = LocalMap * constant */
|
---|
| 290 | template <class T> inline LocalMap<T> operator * (const LocalMap<T>& a, T b)
|
---|
| 291 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 292 | result.Mul(b); return result;}
|
---|
| 293 |
|
---|
[1423] | 294 | /*! \ingroup SkyMap \fn operator*(T,const LocalMap<T>&)
|
---|
[1419] | 295 | \brief Operator LocalMap = constant * LocalMap */
|
---|
| 296 | template <class T> inline LocalMap<T> operator * (T b,const LocalMap<T>& a)
|
---|
| 297 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 298 | result.Mul(b); return result;}
|
---|
| 299 |
|
---|
[1423] | 300 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,T)
|
---|
[1419] | 301 | \brief Operator LocalMap = LocalMap / constant */
|
---|
| 302 | template <class T> inline LocalMap<T> operator / (const LocalMap<T>& a, T b)
|
---|
| 303 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 304 | result.Div(b); return result;}
|
---|
| 305 |
|
---|
[1423] | 306 | /*! \ingroup SkyMap \fn operator/(T,const LocalMap<T>&)
|
---|
[1419] | 307 | \brief Operator LocalMap = constant / LocalMap */
|
---|
| 308 | template <class T> inline LocalMap<T> operator / (T b, const LocalMap<T>& a)
|
---|
| 309 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 310 | result.Div(b, true); return result;}
|
---|
| 311 |
|
---|
| 312 | ////////////////////////////////////////////////////////////////
|
---|
| 313 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 314 |
|
---|
[1423] | 315 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 316 | \brief Operator LocalMap = LocalMap + LocalMap */
|
---|
| 317 | template <class T>
|
---|
| 318 | inline LocalMap<T> operator + (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 319 | { LocalMap<T> result; result.SetTemp(true);
|
---|
| 320 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 321 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 322 | return result; }
|
---|
| 323 |
|
---|
[1423] | 324 | /*! \ingroup SkyMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 325 | \brief Operator LocalMap = LocalMap - LocalMap */
|
---|
| 326 | template <class T>
|
---|
| 327 | inline LocalMap<T> operator - (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 328 | { LocalMap<T> result; result.SetTemp(true);
|
---|
[1429] | 329 | if (b.IsTemp()) { result.Share(b); result.SubElt(a); }
|
---|
[1419] | 330 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
| 331 | return result; }
|
---|
| 332 |
|
---|
[1551] | 333 | ////////////////////////////////////////////////////////////////
|
---|
| 334 | // Surcharge d'operateurs C = A (*,/) B
|
---|
[1419] | 335 |
|
---|
[1551] | 336 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,const LocalMap<T>&)
|
---|
| 337 | \brief Operator LocalMap = LocalMap * LocalMap (pixel by pixel multiply)*/
|
---|
| 338 | template <class T>
|
---|
| 339 | inline LocalMap<T> operator * (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 340 | { LocalMap<T> result; result.SetTemp(true);
|
---|
| 341 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
| 342 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
| 343 | return result; }
|
---|
| 344 |
|
---|
| 345 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,const LocalMap<T>&)
|
---|
| 346 | \brief Operator LocalMap = LocalMap / LocalMap (pixel by pixel divide)*/
|
---|
| 347 | template <class T>
|
---|
| 348 | inline LocalMap<T> operator / (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 349 | { LocalMap<T> result; result.SetTemp(true);
|
---|
[2433] | 350 | result.CloneOrShare(a); result.DivElt(b);
|
---|
[1551] | 351 | return result; }
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 |
|
---|
[841] | 355 | } // Fin du namespace
|
---|
[764] | 356 |
|
---|
| 357 | #endif
|
---|