[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();
|
---|
[2013] | 41 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle=0.);
|
---|
| 42 | LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle=0.);
|
---|
[917] | 43 | LocalMap(const LocalMap<T>& lm, bool share);
|
---|
[908] | 44 | LocalMap(const LocalMap<T>& lm);
|
---|
[764] | 45 | virtual ~LocalMap();
|
---|
| 46 |
|
---|
[908] | 47 | inline virtual bool IsTemp(void) const { return pixels_.IsTemp();}
|
---|
[1217] | 48 |
|
---|
[764] | 49 | /*! Setting blockdata to temporary (see ndatablock documentation) */
|
---|
| 50 | inline virtual void SetTemp(bool temp=false) const {pixels_.SetTemp(temp);};
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | // ---------- Overloading of () to access pixel number k ----
|
---|
| 54 |
|
---|
| 55 | inline T& operator()(int_4 k) {return(PixVal(k));}
|
---|
| 56 | inline T const& operator()(int_4 k) const {return(PixVal(k));}
|
---|
| 57 | inline T& operator()(int_4 ix, int_4 iy) {return PixVal(iy*nSzX_+ix);};
|
---|
| 58 | inline T const& operator()(int_4 ix, int_4 iy) const {return PixVal(iy*nSzX_+ix);};
|
---|
| 59 |
|
---|
| 60 | // ---------- Definition of PixelMap abstract methods -------
|
---|
| 61 |
|
---|
| 62 | virtual int_4 NbPixels() const; // D.Y. int change en int_4 rationalisation Mac
|
---|
| 63 |
|
---|
| 64 | virtual T& PixVal(int_4 k);
|
---|
| 65 | virtual T const& PixVal(int_4 k) const;
|
---|
| 66 |
|
---|
| 67 | virtual bool ContainsSph(double theta, double phi) const;
|
---|
| 68 | virtual int_4 PixIndexSph(double theta,double phi) const;
|
---|
| 69 |
|
---|
| 70 | virtual void PixThetaPhi(int_4 k,double& theta,double& phi) const;
|
---|
| 71 |
|
---|
| 72 | virtual T SetPixels(T v);
|
---|
| 73 |
|
---|
| 74 | virtual double PixSolAngle(int_4 k) const;
|
---|
| 75 |
|
---|
| 76 | // ---------- Specific methods ------------------------------
|
---|
| 77 |
|
---|
| 78 | void ReSize(int_4 nx, int_4 ny);
|
---|
| 79 |
|
---|
| 80 | inline virtual char* TypeOfMap() const {return "LOCAL";};
|
---|
| 81 |
|
---|
| 82 |
|
---|
[1217] | 83 | /*! Check to see if the local mapping is done */
|
---|
[2013] | 84 | //inline bool LocalMap_isDone() const {return(originFlag_ && extensFlag_);};
|
---|
[764] | 85 |
|
---|
[2013] | 86 | void PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const;
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | void ProjectionToSphere(SphericalMap<T>&) const;
|
---|
[764] | 90 |
|
---|
| 91 | /* There should be a more complex algorithm somewhere to combine *several* local maps to a full sphere.
|
---|
| 92 | -> static method, or separate class */
|
---|
| 93 |
|
---|
[1217] | 94 | /*! provides a integer characterizing the pixelization refinement (here : number of pixels) */
|
---|
[764] | 95 | inline virtual int_4 SizeIndex() const {return(nPix_);}
|
---|
| 96 | inline int_4 Size_x() const {return nSzX_;}
|
---|
| 97 | inline int_4 Size_y() const {return nSzY_;}
|
---|
| 98 |
|
---|
[1163] | 99 | /* Je rajoute ces 2 fonctions inlines pour compatibilite d'interface
|
---|
| 100 | avec TArray - Reza 30/8/2000 */
|
---|
| 101 | inline int_4 SizeX() const {return nSzX_;}
|
---|
| 102 | inline int_4 SizeY() const {return nSzY_;}
|
---|
| 103 |
|
---|
[2013] | 104 | 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] | 105 |
|
---|
[2013] | 106 | /*! total aperture in theta and phi, in degrees ( from SetSize() ) */
|
---|
| 107 | inline void Aperture(double& anglex,double& angley) const {anglex= angleDegresX_; angley= angleDegresY_;}
|
---|
[764] | 108 |
|
---|
| 109 |
|
---|
| 110 | /* Acces to the DataBlock */
|
---|
[2013] | 111 | inline NDataBlock<T>& DataBlock() {return pixels_.DataBlock();}
|
---|
| 112 | inline const NDataBlock<T>& DataBlock() const {return pixels_.DataBlock();}
|
---|
[764] | 113 |
|
---|
[2013] | 114 | /* Acces to the matrix */
|
---|
| 115 | //! access to matrix
|
---|
| 116 | /*!
|
---|
| 117 | \warning : a pixel is defined by the pair of a phi-like index
|
---|
| 118 | (x-axis) and a theta-like index (y-axis). The phi-like index denotes
|
---|
| 119 | the column number in the matrix ; the theta-like index denotes the
|
---|
| 120 | row number.
|
---|
| 121 | */
|
---|
| 122 | inline TMatrix<T>& Matrix() {return pixels_;}
|
---|
| 123 | inline const TMatrix<T>& Matrix() const {return pixels_;}
|
---|
| 124 |
|
---|
[764] | 125 | /* impression */
|
---|
| 126 | void print(ostream& os) const;
|
---|
| 127 |
|
---|
[1419] | 128 | // Operations diverses = , +=, ...
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | virtual LocalMap<T>& Set(const LocalMap<T>& a);
|
---|
[908] | 132 | inline LocalMap<T>& operator = (const LocalMap<T>& a) {return Set(a);}
|
---|
| 133 |
|
---|
[1419] | 134 | // A += -= *= /= x (ajoute, soustrait, ... x a tous les elements)
|
---|
[908] | 135 |
|
---|
[1419] | 136 | //! Fill LocalMap with all elements equal to \b x
|
---|
| 137 | virtual LocalMap<T>& SetT(T a);
|
---|
| 138 | inline LocalMap<T>& operator = (T a) {return SetT(a);}
|
---|
[908] | 139 |
|
---|
[1419] | 140 | //! Add \b x to all elements
|
---|
| 141 | virtual LocalMap<T>& Add(T a);
|
---|
| 142 | inline LocalMap<T>& operator += (T x) { return Add(x); }
|
---|
| 143 | //! Substract \b x to all elements
|
---|
[1624] | 144 | virtual LocalMap<T>& Sub(T a,bool fginv=false);
|
---|
[1419] | 145 | inline LocalMap<T>& operator -= (T x) { return Sub(x); }
|
---|
| 146 | //! Multiply all elements by \b x
|
---|
| 147 | virtual LocalMap<T>& Mul(T a);
|
---|
| 148 | inline LocalMap<T>& operator *= (T x) { return Mul(x); }
|
---|
| 149 | //! Divide all elements by \b x
|
---|
| 150 | virtual LocalMap<T>& Div(T a);
|
---|
| 151 | inline LocalMap<T>& operator /= (T x) { return Div(x); }
|
---|
| 152 |
|
---|
| 153 | // A += -= (ajoute, soustrait element par element les deux spheres )
|
---|
| 154 | //! Operator LocalMap += LocalMap
|
---|
| 155 | virtual LocalMap<T>& AddElt(const LocalMap<T>& a);
|
---|
| 156 | inline LocalMap<T>& operator += (const LocalMap<T>& a) { return AddElt(a); }
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | virtual LocalMap<T>& SubElt(const LocalMap<T>& a);
|
---|
| 161 | //! Operator LocalMap -= LocalMap
|
---|
| 162 | inline LocalMap<T>& operator -= (const LocalMap<T>& a) { return SubElt(a); }
|
---|
| 163 | // Multiplication, division element par element les deux LocalMap
|
---|
| 164 | virtual LocalMap<T>& MulElt(const LocalMap<T>& a);
|
---|
| 165 | inline LocalMap<T>& operator *= (const LocalMap<T>& a) { return MulElt(a); }
|
---|
[1551] | 166 | virtual LocalMap<T>& DivElt(const LocalMap<T>& a);
|
---|
| 167 | inline LocalMap<T>& operator /= (const LocalMap<T>& a) { return DivElt(a); }
|
---|
[1419] | 168 |
|
---|
| 169 |
|
---|
| 170 | void CloneOrShare(const LocalMap<T>& a);
|
---|
| 171 | void Share(const LocalMap<T>& a);
|
---|
| 172 | LocalMap<T>& CopyElt(const LocalMap<T>& a);
|
---|
| 173 |
|
---|
| 174 |
|
---|
[764] | 175 | // ---------- Méthodes internes -----------------------------
|
---|
| 176 |
|
---|
| 177 | private :
|
---|
| 178 |
|
---|
| 179 | void InitNul();
|
---|
[2013] | 180 | void SetOrigin(double theta=90.,double phi=0.,double angle=0.);
|
---|
| 181 | void SetOrigin(double theta,double phi,int_4 x0,int_4 y0,double angle=0.);
|
---|
| 182 | void SetSize(double angleX,double angleY);
|
---|
| 183 | void SetCoorC(double theta0, double phi0);
|
---|
| 184 | TMatrix<double> CalculMatricePassage();
|
---|
[764] | 185 | void Getij(int_4 k,int_4& i,int_4& j) const;
|
---|
[2013] | 186 | void PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const;
|
---|
[764] | 187 |
|
---|
[908] | 188 | void recopierVariablesSimples(const LocalMap<T>& lm);
|
---|
| 189 |
|
---|
| 190 |
|
---|
[764] | 191 | // ---------- Variables internes ----------------------------
|
---|
| 192 |
|
---|
[2013] | 193 |
|
---|
| 194 | // variables suffisantes pour reconstruire l'objet
|
---|
| 195 |
|
---|
| 196 | int_4 nSzX_;
|
---|
| 197 | int_4 nSzY_;
|
---|
| 198 | double angleDegresX_;
|
---|
| 199 | double angleDegresY_;
|
---|
| 200 | double thetaDegresC_;
|
---|
| 201 | double phiDegresC_;
|
---|
| 202 | int_4 x0_;
|
---|
| 203 | int_4 y0_;
|
---|
| 204 | double angleDegres_;
|
---|
| 205 |
|
---|
| 206 | // NDataBlock<T> pixels_;
|
---|
| 207 | TMatrix<T> pixels_;
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | // variables derivees (redondantes, precalculees pour ameliorer
|
---|
| 211 | // les performances)
|
---|
| 212 |
|
---|
| 213 | int_4 nPix_;
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 | double thetaC_;
|
---|
| 217 | double phiC_;
|
---|
| 218 | double csthC_;
|
---|
| 219 | double snthC_;
|
---|
| 220 | double csphC_;
|
---|
| 221 | double snphC_;
|
---|
| 222 | double XC_;
|
---|
| 223 | double YC_;
|
---|
| 224 | double ZC_;
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | double angle_;
|
---|
| 228 | double cosAngle_;
|
---|
| 229 | double sinAngle_;
|
---|
| 230 | double deltaPhi_;
|
---|
| 231 | double deltaTheta_;
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
[764] | 235 | };
|
---|
| 236 |
|
---|
[1419] | 237 | ////////////////////////////////////////////////////////////////
|
---|
| 238 | // Surcharge d'operateurs A (+,-,*,/) (T) x
|
---|
[1423] | 239 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,T)
|
---|
[1419] | 240 | \brief Operator LocalMap = LocalMap + constant */
|
---|
| 241 | template <class T> inline LocalMap<T> operator + (const LocalMap<T>& a, T b)
|
---|
| 242 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 243 | result.Add(b); return result;}
|
---|
[1423] | 244 | /*! \ingroup SkyMap \fn operator+(T,const LocalMap<T>&)
|
---|
[1419] | 245 | \brief Operator LocalMap = constant + LocalMap */
|
---|
| 246 | template <class T> inline LocalMap<T> operator + (T b,const LocalMap<T>& a)
|
---|
| 247 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 248 | result.Add(b); return result;}
|
---|
[764] | 249 |
|
---|
| 250 |
|
---|
[1423] | 251 | /*! \ingroup SkyMap\fn operator-(const LocalMap<T>&,T)
|
---|
[1419] | 252 | \brief Operator LocalMap = LocalMap - constant */
|
---|
| 253 | template <class T> inline LocalMap<T> operator - (const LocalMap<T>& a, T b)
|
---|
| 254 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 255 | result.Sub(b); return result;}
|
---|
| 256 |
|
---|
| 257 | /*! \ingroup \fn operator-(T,const LocalMap<T>&)
|
---|
| 258 | \brief Operator LocalMap = constant - LocalMap */
|
---|
| 259 | template <class T> inline LocalMap<T> operator - (T b,const LocalMap<T>& a)
|
---|
| 260 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 261 | result.Sub(b,true); return result;}
|
---|
| 262 |
|
---|
[1423] | 263 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,T)
|
---|
[1419] | 264 | \brief Operator LocalMap = LocalMap * constant */
|
---|
| 265 | template <class T> inline LocalMap<T> operator * (const LocalMap<T>& a, T b)
|
---|
| 266 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 267 | result.Mul(b); return result;}
|
---|
| 268 |
|
---|
[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.Mul(b); return result;}
|
---|
| 274 |
|
---|
[1423] | 275 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,T)
|
---|
[1419] | 276 | \brief Operator LocalMap = LocalMap / constant */
|
---|
| 277 | template <class T> inline LocalMap<T> operator / (const LocalMap<T>& a, T b)
|
---|
| 278 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 279 | result.Div(b); return result;}
|
---|
| 280 |
|
---|
[1423] | 281 | /*! \ingroup SkyMap \fn operator/(T,const LocalMap<T>&)
|
---|
[1419] | 282 | \brief Operator LocalMap = constant / LocalMap */
|
---|
| 283 | template <class T> inline LocalMap<T> operator / (T b, const LocalMap<T>& a)
|
---|
| 284 | {LocalMap<T> result; result.CloneOrShare(a); result.SetTemp(true);
|
---|
| 285 | result.Div(b, true); return result;}
|
---|
| 286 |
|
---|
| 287 | ////////////////////////////////////////////////////////////////
|
---|
| 288 | // Surcharge d'operateurs C = A (+,-) B
|
---|
| 289 |
|
---|
[1423] | 290 | /*! \ingroup SkyMap \fn operator+(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 291 | \brief Operator LocalMap = LocalMap + LocalMap */
|
---|
| 292 | template <class T>
|
---|
| 293 | inline LocalMap<T> operator + (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 294 | { LocalMap<T> result; result.SetTemp(true);
|
---|
| 295 | if (b.IsTemp()) { result.Share(b); result.AddElt(a); }
|
---|
| 296 | else { result.CloneOrShare(a); result.AddElt(b); }
|
---|
| 297 | return result; }
|
---|
| 298 |
|
---|
[1423] | 299 | /*! \ingroup SkyMap \fn operator-(const LocalMap<T>&,const LocalMap<T>&)
|
---|
[1419] | 300 | \brief Operator LocalMap = LocalMap - LocalMap */
|
---|
| 301 | template <class T>
|
---|
| 302 | inline LocalMap<T> operator - (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 303 | { LocalMap<T> result; result.SetTemp(true);
|
---|
[1429] | 304 | if (b.IsTemp()) { result.Share(b); result.SubElt(a); }
|
---|
[1419] | 305 | else { result.CloneOrShare(a); result.SubElt(b); }
|
---|
| 306 | return result; }
|
---|
| 307 |
|
---|
[1551] | 308 | ////////////////////////////////////////////////////////////////
|
---|
| 309 | // Surcharge d'operateurs C = A (*,/) B
|
---|
[1419] | 310 |
|
---|
[1551] | 311 | /*! \ingroup SkyMap \fn operator*(const LocalMap<T>&,const LocalMap<T>&)
|
---|
| 312 | \brief Operator LocalMap = LocalMap * LocalMap (pixel by pixel multiply)*/
|
---|
| 313 | template <class T>
|
---|
| 314 | inline LocalMap<T> operator * (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 315 | { LocalMap<T> result; result.SetTemp(true);
|
---|
| 316 | if (b.IsTemp()) { result.Share(b); result.MulElt(a); }
|
---|
| 317 | else { result.CloneOrShare(a); result.MulElt(b); }
|
---|
| 318 | return result; }
|
---|
| 319 |
|
---|
| 320 | /*! \ingroup SkyMap \fn operator/(const LocalMap<T>&,const LocalMap<T>&)
|
---|
| 321 | \brief Operator LocalMap = LocalMap / LocalMap (pixel by pixel divide)*/
|
---|
| 322 | template <class T>
|
---|
| 323 | inline LocalMap<T> operator / (const LocalMap<T>& a,const LocalMap<T>& b)
|
---|
| 324 | { LocalMap<T> result; result.SetTemp(true);
|
---|
| 325 | if (b.IsTemp()) { result.Share(b); result.DivElt(a); }
|
---|
| 326 | else { result.CloneOrShare(a); result.DivElt(b); }
|
---|
| 327 | return result; }
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 |
|
---|
[841] | 331 | } // Fin du namespace
|
---|
[764] | 332 |
|
---|
| 333 | #endif
|
---|