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