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