[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 |
|
---|
[3174] | 195 | //! assign a new object Id (or DataRef Id) - useful for PPF write operations
|
---|
| 196 | inline void RenewObjId() { pixels_.RenewObjId(); }
|
---|
[1419] | 197 |
|
---|
[764] | 198 | // ---------- Méthodes internes -----------------------------
|
---|
| 199 |
|
---|
| 200 | private :
|
---|
| 201 |
|
---|
| 202 | void InitNul();
|
---|
[2013] | 203 | void SetCoorC(double theta0, double phi0);
|
---|
| 204 | TMatrix<double> CalculMatricePassage();
|
---|
[764] | 205 | void Getij(int_4 k,int_4& i,int_4& j) const;
|
---|
[2013] | 206 | void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const;
|
---|
[764] | 207 |
|
---|
[908] | 208 | void recopierVariablesSimples(const LocalMap<T>& lm);
|
---|
| 209 |
|
---|
[2198] | 210 | void initializationError() const;
|
---|
[908] | 211 |
|
---|
[3174] | 212 |
|
---|
[764] | 213 | // ---------- Variables internes ----------------------------
|
---|
[2013] | 214 | // variables suffisantes pour reconstruire l'objet
|
---|
| 215 |
|
---|
[2198] | 216 | bool pixelSized_;
|
---|
| 217 | bool angleSized_;
|
---|
| 218 | bool originSet_;
|
---|
| 219 |
|
---|
[2013] | 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 |
|
---|
[2198] | 230 |
|
---|
[2013] | 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 |
|
---|
[2052] | 258 | bool exc_outofmap_;
|
---|
[2013] | 259 |
|
---|
| 260 |
|
---|
[764] | 261 | };
|
---|
| 262 |
|
---|
[1419] | 263 | ////////////////////////////////////////////////////////////////
|
---|
| 264 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 265 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,T)
|
---|
[1419] | 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;}
|
---|
[1423] | 270 | /*! \ingroup SkyMap \fn operator+(T,const LocalMap<T>&)
|
---|
[1419] | 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;}
|
---|
[764] | 275 |
|
---|
| 276 |
|
---|
[1423] | 277 | /*! \ingroup SkyMap\fn operator-(const LocalMap<T>&,T)
|
---|
[1419] | 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 |
|
---|
[1423] | 289 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,T)
|
---|
[1419] | 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 |
|
---|
[1423] | 295 | /*! \ingroup SkyMap \fn operator*(T,const LocalMap<T>&)
|
---|
[1419] | 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 |
|
---|
[1423] | 301 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,T)
|
---|
[1419] | 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 |
|
---|
[1423] | 307 | /*! \ingroup SkyMap \fn operator/(T,const LocalMap<T>&)
|
---|
[1419] | 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 |
|
---|
[1423] | 316 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 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 |
|
---|
[1423] | 325 | /*! \ingroup SkyMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 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);
|
---|
[1429] | 330 | if (b.IsTemp()) { result.Share(b); result.SubElt(a); }
|
---|
[1419] | 331 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
| 332 | return result; }
|
---|
| 333 |
|
---|
[1551] | 334 | ////////////////////////////////////////////////////////////////
|
---|
| 335 | // Surcharge d'operateurs C = A (*,/) B
|
---|
[1419] | 336 |
|
---|
[1551] | 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);
|
---|
[2433] | 351 | result.CloneOrShare(a); result.DivElt(b);
|
---|
[1551] | 352 | return result; }
|
---|
| 353 |
|
---|
| 354 |
|
---|
| 355 |
|
---|
[841] | 356 | } // Fin du namespace
|
---|
[764] | 357 |
|
---|
| 358 | #endif
|
---|