| 1 | #include "localmap.h"
 | 
|---|
| 2 | #include "smathconst.h"
 | 
|---|
| 3 | #include <complex>
 | 
|---|
| 4 | #include "piocmplx.h"
 | 
|---|
| 5 | #include "fiondblock.h"
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #include <string.h>
 | 
|---|
| 8 | #include <iostream.h>
 | 
|---|
| 9 | 
 | 
|---|
| 10 | 
 | 
|---|
| 11 | //*****************************************************************************
 | 
|---|
| 12 | //++ 
 | 
|---|
| 13 | // Class        LocalMap
 | 
|---|
| 14 | //
 | 
|---|
| 15 | // include      localmap.h 
 | 
|---|
| 16 | //
 | 
|---|
| 17 | //    A local map of a region of the sky, in cartesian coordinates.
 | 
|---|
| 18 | //    It has an origin in (theta0, phi0), mapped to pixel(x0, y0)
 | 
|---|
| 19 | //    (x0, y0 might be outside of this local map)
 | 
|---|
| 20 | //    default value of (x0, y0) is middle of the map, center of 
 | 
|---|
| 21 | //    pixel(nx/2, ny/2)
 | 
|---|
| 22 | //
 | 
|---|
| 23 | //    A local map is a 2 dimensional array, with i as column index and j
 | 
|---|
| 24 | //    as row index. The map is supposed to lie on a plan tangent to the 
 | 
|---|
| 25 | //    celestial sphere in a point whose coordinates are (x0,y0) on the local
 | 
|---|
| 26 | //    map and (theta0, phi0) on the sphere. The range of the map is defined
 | 
|---|
| 27 | //    by two values of angles covered respectively by all the pixels in 
 | 
|---|
| 28 | //    x direction and all the pixels in y direction (SetSize()).
 | 
|---|
| 29 | //
 | 
|---|
| 30 | //    A "reference plane" is considered : this plane is tangent to the 
 | 
|---|
| 31 | //    celestial sphere in a point with angles theta=Pi/2 and phi=0. This 
 | 
|---|
| 32 | //    point is the origine of coordinates is of the reference plane. The 
 | 
|---|
| 33 | //    x-axis is the tangent parallel to the equatorial line and oriented 
 | 
|---|
| 34 | //    toward the increasing phi's ; the y-axis is parallel to the meridian 
 | 
|---|
| 35 | //    line and oriented toward the north pole.
 | 
|---|
| 36 | //    
 | 
|---|
| 37 | //    Internally, a map is first defined within this reference plane and
 | 
|---|
| 38 | //    tranported until the point (theta0, phi0) in such a way that both 
 | 
|---|
| 39 | //    axes are kept parallel to meridian and parallel lines of the sphere.
 | 
|---|
| 40 | //    The user can define its own map with axes rotated with respect to
 | 
|---|
| 41 | //    reference axes (this rotation is characterized by angle between 
 | 
|---|
| 42 | //    the local parallel line and the wanted x-axis-- see method 
 | 
|---|
| 43 | //    SetOrigin(...))
 | 
|---|
| 44 | //    
 | 
|---|
| 45 | //
 | 
|---|
| 46 | 
 | 
|---|
| 47 | //
 | 
|---|
| 48 | //-- 
 | 
|---|
| 49 | //++
 | 
|---|
| 50 | //
 | 
|---|
| 51 | // Links        Parents
 | 
|---|
| 52 | //
 | 
|---|
| 53 | //    PixelMap
 | 
|---|
| 54 | //    
 | 
|---|
| 55 | //-- 
 | 
|---|
| 56 | //++
 | 
|---|
| 57 | //
 | 
|---|
| 58 | // Links        Childs
 | 
|---|
| 59 | //
 | 
|---|
| 60 | //     
 | 
|---|
| 61 | //-- 
 | 
|---|
| 62 | //++
 | 
|---|
| 63 | // Titre        Constructors
 | 
|---|
| 64 | //--
 | 
|---|
| 65 | //++
 | 
|---|
| 66 | template<class T>
 | 
|---|
| 67 | LocalMap<T>::LocalMap()
 | 
|---|
| 68 | //
 | 
|---|
| 69 | //     
 | 
|---|
| 70 | //--
 | 
|---|
| 71 | {
 | 
|---|
| 72 |   InitNul();
 | 
|---|
| 73 |   pixels_.Reset();
 | 
|---|
| 74 | }
 | 
|---|
| 75 | 
 | 
|---|
| 76 | //++
 | 
|---|
| 77 | template<class T>
 | 
|---|
| 78 | LocalMap<T>::LocalMap(int_4 nx, int_4 ny) : nSzX_(nx), nSzY_(ny)
 | 
|---|
| 79 | //
 | 
|---|
| 80 | //    
 | 
|---|
| 81 | //--
 | 
|---|
| 82 | {
 | 
|---|
| 83 |   InitNul();
 | 
|---|
| 84 |   nPix_= nx*ny;
 | 
|---|
| 85 |   pixels_.ReSize(nPix_);
 | 
|---|
| 86 |   pixels_.Reset();
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | //++
 | 
|---|
| 90 | template<class T>
 | 
|---|
| 91 | LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
 | 
|---|
| 92 |   : pixels_(lm.pixels_, share)
 | 
|---|
| 93 | 
 | 
|---|
| 94 | //
 | 
|---|
| 95 | //    copy constructor
 | 
|---|
| 96 | //--
 | 
|---|
| 97 | {
 | 
|---|
| 98 |   cout<<" LocalMap:: Appel du constructeur de recopie " << endl;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
 | 
|---|
| 101 |   nSzX_= lm.nSzX_;
 | 
|---|
| 102 |   nSzY_= lm.nSzY_;
 | 
|---|
| 103 |   nPix_= lm.nPix_;
 | 
|---|
| 104 |   originFlag_= lm.originFlag_;
 | 
|---|
| 105 |   extensFlag_= lm.extensFlag_;
 | 
|---|
| 106 |   x0_= lm.x0_;
 | 
|---|
| 107 |   y0_= lm.y0_;
 | 
|---|
| 108 |   theta0_= lm.theta0_;
 | 
|---|
| 109 |   phi0_= lm.phi0_;
 | 
|---|
| 110 |   angle_= lm.angle_;
 | 
|---|
| 111 |   cos_angle_= lm.cos_angle_;
 | 
|---|
| 112 |   sin_angle_= lm.sin_angle_;
 | 
|---|
| 113 |   angleX_= lm.angleX_;
 | 
|---|
| 114 |   angleY_= lm.angleY_;
 | 
|---|
| 115 |   tgAngleX_= lm.tgAngleX_;
 | 
|---|
| 116 |   tgAngleY_= lm.tgAngleY_;
 | 
|---|
| 117 | }
 | 
|---|
| 118 | 
 | 
|---|
| 119 | //++
 | 
|---|
| 120 | // Titre        Destructor
 | 
|---|
| 121 | //--
 | 
|---|
| 122 | //++
 | 
|---|
| 123 | template<class T>
 | 
|---|
| 124 | LocalMap<T>::~LocalMap()
 | 
|---|
| 125 | //
 | 
|---|
| 126 | //--
 | 
|---|
| 127 | {
 | 
|---|
| 128 |   InitNul();
 | 
|---|
| 129 | }
 | 
|---|
| 130 | 
 | 
|---|
| 131 | 
 | 
|---|
| 132 | 
 | 
|---|
| 133 | //++
 | 
|---|
| 134 | // Titre        Public Methods
 | 
|---|
| 135 | //--
 | 
|---|
| 136 | 
 | 
|---|
| 137 | //++
 | 
|---|
| 138 | template<class T>
 | 
|---|
| 139 | void LocalMap<T>::ReSize(int_4 nx, int_4 ny) 
 | 
|---|
| 140 | //
 | 
|---|
| 141 | //    Resize storage area for pixels 
 | 
|---|
| 142 | //--
 | 
|---|
| 143 | {
 | 
|---|
| 144 |   InitNul();
 | 
|---|
| 145 |   nSzX_ = nx;
 | 
|---|
| 146 |   nSzY_ = ny;
 | 
|---|
| 147 |   nPix_= nx*ny;
 | 
|---|
| 148 |   pixels_.ReSize(nPix_);
 | 
|---|
| 149 |   pixels_.Reset();
 | 
|---|
| 150 | }
 | 
|---|
| 151 | 
 | 
|---|
| 152 | //++
 | 
|---|
| 153 | template<class T>
 | 
|---|
| 154 | int_4 LocalMap<T>::NbPixels() const
 | 
|---|
| 155 | //
 | 
|---|
| 156 | //    Return number of pixels
 | 
|---|
| 157 | //--
 | 
|---|
| 158 | {
 | 
|---|
| 159 |   return(nPix_);
 | 
|---|
| 160 | }
 | 
|---|
| 161 | 
 | 
|---|
| 162 | //++
 | 
|---|
| 163 | template<class T>
 | 
|---|
| 164 | T& LocalMap<T>::PixVal(int_4 k)
 | 
|---|
| 165 | //
 | 
|---|
| 166 | //    Return value of pixel with index k
 | 
|---|
| 167 | //--
 | 
|---|
| 168 | {
 | 
|---|
| 169 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 170 |     {
 | 
|---|
| 171 |       cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
 | 
|---|
| 172 |       //  THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
 | 
|---|
| 173 |       THROW(rangeCheckErr);
 | 
|---|
| 174 |       //throw "LocalMap::PIxVal Pixel index out of range";
 | 
|---|
| 175 |     }
 | 
|---|
| 176 |   return(pixels_(k));
 | 
|---|
| 177 | }
 | 
|---|
| 178 | 
 | 
|---|
| 179 | //++
 | 
|---|
| 180 | 
 | 
|---|
| 181 | template<class T>
 | 
|---|
| 182 | T const& LocalMap<T>::PixVal(int_4 k) const
 | 
|---|
| 183 | //
 | 
|---|
| 184 | //   const version of previous method
 | 
|---|
| 185 | //--
 | 
|---|
| 186 | {
 | 
|---|
| 187 |   if((k < 0) || (k >= nPix_)) 
 | 
|---|
| 188 |     {
 | 
|---|
| 189 |       cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl;
 | 
|---|
| 190 |       //    THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
 | 
|---|
| 191 |       
 | 
|---|
| 192 |       throw "LocalMap::PIxVal Pixel index out of range"; 
 | 
|---|
| 193 |     } 
 | 
|---|
| 194 |   return *(pixels_.Data()+k);
 | 
|---|
| 195 | }
 | 
|---|
| 196 | 
 | 
|---|
| 197 | template<class T>
 | 
|---|
| 198 | bool LocalMap<T>::ContainsSph(double theta, double phi) const
 | 
|---|
| 199 | {
 | 
|---|
| 200 | // $CHECK$  Reza 11/11/99 - A modifier
 | 
|---|
| 201 | return(true);
 | 
|---|
| 202 | }
 | 
|---|
| 203 | 
 | 
|---|
| 204 | //++
 | 
|---|
| 205 | template<class T>
 | 
|---|
| 206 | int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
 | 
|---|
| 207 | //
 | 
|---|
| 208 | //    Return index of the pixel with spherical coordinates (theta,phi)
 | 
|---|
| 209 | //--
 | 
|---|
| 210 | {
 | 
|---|
| 211 |   int_4 i,j;
 | 
|---|
| 212 |   if(!(originFlag_) || !(extensFlag_)) 
 | 
|---|
| 213 |     {
 | 
|---|
| 214 |       cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
 | 
|---|
| 215 |       exit(0);
 | 
|---|
| 216 |     }
 | 
|---|
| 217 | 
 | 
|---|
| 218 |   // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference)
 | 
|---|
| 219 |   double theta_aux= theta;
 | 
|---|
| 220 |   double phi_aux  = phi;
 | 
|---|
| 221 |   UserToReference(theta_aux, phi_aux);
 | 
|---|
| 222 | 
 | 
|---|
| 223 |   // coordonnees dans le plan local en unites de pixels
 | 
|---|
| 224 |   double x,y;
 | 
|---|
| 225 |   AngleProjToPix(theta_aux,phi_aux, x, y);
 | 
|---|
| 226 | 
 | 
|---|
| 227 |   double xmin= -x0_-0.5;
 | 
|---|
| 228 |   double xmax= xmin+nSzX_;
 | 
|---|
| 229 |   if((x > xmax) || (x < xmin)) return(-1);
 | 
|---|
| 230 |   double xcurrent= xmin;
 | 
|---|
| 231 |   for(i = 0; i < nSzX_; i++ ) 
 | 
|---|
| 232 |     {
 | 
|---|
| 233 |       xcurrent += 1.;
 | 
|---|
| 234 |       if( x < xcurrent ) break;
 | 
|---|
| 235 |     }
 | 
|---|
| 236 |   double ymin= -y0_-0.5;
 | 
|---|
| 237 |   double ymax= ymin+nSzY_;
 | 
|---|
| 238 |   if((y >  ymax) || (y < ymin)) return(-1);
 | 
|---|
| 239 |   double ycurrent= ymin;
 | 
|---|
| 240 |   for(j = 0; j < nSzY_; j++ ) 
 | 
|---|
| 241 |     {
 | 
|---|
| 242 |       ycurrent += 1.;
 | 
|---|
| 243 |       if( y < ycurrent ) break;
 | 
|---|
| 244 |     }
 | 
|---|
| 245 |   return (j*nSzX_+i);
 | 
|---|
| 246 | }
 | 
|---|
| 247 | 
 | 
|---|
| 248 | //++
 | 
|---|
| 249 | template<class T>
 | 
|---|
| 250 | void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
 | 
|---|
| 251 | //
 | 
|---|
| 252 | //    Return (theta, phi) coordinates of pixel with index k
 | 
|---|
| 253 | //--
 | 
|---|
| 254 | {
 | 
|---|
| 255 |   if(!(originFlag_) || !(extensFlag_)) 
 | 
|---|
| 256 |     {
 | 
|---|
| 257 |       cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
 | 
|---|
| 258 |       exit(0);
 | 
|---|
| 259 |     }
 | 
|---|
| 260 | 
 | 
|---|
| 261 |   int_4 i,j;
 | 
|---|
| 262 |   Getij(k,i,j);
 | 
|---|
| 263 | 
 | 
|---|
| 264 |   double X= double(i-x0_);
 | 
|---|
| 265 |   double Y= double(j-y0_);
 | 
|---|
| 266 |   // situation de ce pixel dans le plan de reference
 | 
|---|
| 267 |   double x= X*cos_angle_-Y*sin_angle_;
 | 
|---|
| 268 |   double y= X*sin_angle_+Y* cos_angle_;
 | 
|---|
| 269 |   // projection sur la sphere
 | 
|---|
| 270 |   PixProjToAngle(x, y, theta, phi);
 | 
|---|
| 271 |   // retour au plan utilisateur
 | 
|---|
| 272 |   ReferenceToUser(theta, phi);
 | 
|---|
| 273 | }
 | 
|---|
| 274 | 
 | 
|---|
| 275 | template <class T>
 | 
|---|
| 276 | T LocalMap<T>::SetPixels(T v)
 | 
|---|
| 277 | {
 | 
|---|
| 278 | pixels_.Reset(v);
 | 
|---|
| 279 | return(v);
 | 
|---|
| 280 | }
 | 
|---|
| 281 |  
 | 
|---|
| 282 | //++
 | 
|---|
| 283 | template<class T>
 | 
|---|
| 284 | double LocalMap<T>::PixSolAngle(int_4 k) const
 | 
|---|
| 285 | //
 | 
|---|
| 286 | //    Pixel Solid angle  (steradians)
 | 
|---|
| 287 | //    All the pixels have not necessarly the same size in (theta, phi)
 | 
|---|
| 288 | //    because of the projection scheme which is not yet fixed.   
 | 
|---|
| 289 | //--
 | 
|---|
| 290 | {
 | 
|---|
| 291 |   int_4 i,j;
 | 
|---|
| 292 |   Getij(k,i,j);
 | 
|---|
| 293 |   double X= double(i-x0_);
 | 
|---|
| 294 |   double Y= double(j-y0_);
 | 
|---|
| 295 |   double XR= X+double(i)*0.5;
 | 
|---|
| 296 |   double XL= X-double(i)*0.5;
 | 
|---|
| 297 |   double YU= Y+double(j)*0.5;
 | 
|---|
| 298 |   double YL= Y-double(j)*0.5;
 | 
|---|
| 299 | 
 | 
|---|
| 300 |   // situation  dans le plan de reference
 | 
|---|
| 301 |   double x0= XL*cos_angle_-YL*sin_angle_;
 | 
|---|
| 302 |   double y0= XL*sin_angle_+YL*cos_angle_;
 | 
|---|
| 303 |   double xa= XR*cos_angle_-YL*sin_angle_;
 | 
|---|
| 304 |   double ya= XR*sin_angle_+YL*cos_angle_;
 | 
|---|
| 305 |   double xb= XL*cos_angle_-YU*sin_angle_;
 | 
|---|
| 306 |   double yb= XL*sin_angle_+YU*cos_angle_;
 | 
|---|
| 307 | 
 | 
|---|
| 308 |   // projection sur la sphere
 | 
|---|
| 309 |   double thet0,phi0,theta,phia,thetb,phib;
 | 
|---|
| 310 |   PixProjToAngle(x0, y0, thet0, phi0);
 | 
|---|
| 311 |   PixProjToAngle(xa, ya, theta, phia);
 | 
|---|
| 312 |   PixProjToAngle(xb, yb, thetb, phib);
 | 
|---|
| 313 | 
 | 
|---|
| 314 |   // angle solide
 | 
|---|
| 315 |   double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0));
 | 
|---|
| 316 |   return sol;
 | 
|---|
| 317 | }
 | 
|---|
| 318 | 
 | 
|---|
| 319 | //++
 | 
|---|
| 320 | template<class T>
 | 
|---|
| 321 | void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
 | 
|---|
| 322 | //
 | 
|---|
| 323 | //    set the referential of the map (angles in degrees)
 | 
|---|
| 324 | //    (default x0=siz_x/2,  y0=siz_y/2) 
 | 
|---|
| 325 | //--
 | 
|---|
| 326 | {
 | 
|---|
| 327 |   theta0_= theta0;
 | 
|---|
| 328 |   phi0_  = phi0;
 | 
|---|
| 329 |   angle_ = angle;
 | 
|---|
| 330 |   x0_= nSzX_/2;
 | 
|---|
| 331 |   y0_= nSzY_/2;
 | 
|---|
| 332 |   cos_angle_= cos(angle*Pi/180.);
 | 
|---|
| 333 |   sin_angle_= sin(angle*Pi/180.);
 | 
|---|
| 334 |   originFlag_= true; 
 | 
|---|
| 335 |   cout << " LocalMap:: set origin 1 done" << endl;
 | 
|---|
| 336 | }
 | 
|---|
| 337 |  
 | 
|---|
| 338 | //++
 | 
|---|
| 339 | template<class T>
 | 
|---|
| 340 | void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
 | 
|---|
| 341 | //
 | 
|---|
| 342 | //    set the referential of the map (angles in degrees)
 | 
|---|
| 343 | //--
 | 
|---|
| 344 | {
 | 
|---|
| 345 |   theta0_= theta0;
 | 
|---|
| 346 |   phi0_  = phi0;
 | 
|---|
| 347 |   angle_ = angle;
 | 
|---|
| 348 |   x0_= x0;
 | 
|---|
| 349 |   y0_= y0;
 | 
|---|
| 350 |   cos_angle_= cos(angle*Pi/180.);
 | 
|---|
| 351 |   sin_angle_= sin(angle*Pi/180.);
 | 
|---|
| 352 |   originFlag_= true;
 | 
|---|
| 353 |   cout << " LocalMap:: set origin 2 done" << endl;
 | 
|---|
| 354 | } 
 | 
|---|
| 355 | 
 | 
|---|
| 356 | //++
 | 
|---|
| 357 | template<class T>
 | 
|---|
| 358 | void LocalMap<T>::SetSize(double angleX,double angleY)
 | 
|---|
| 359 | //
 | 
|---|
| 360 | //    angle range of tthe map (angles in degrees)
 | 
|---|
| 361 | //--
 | 
|---|
| 362 | {
 | 
|---|
| 363 |   angleX_= angleX;
 | 
|---|
| 364 |   angleY_= angleY;
 | 
|---|
| 365 | 
 | 
|---|
| 366 |   // tangente de la moitie de l'ouverture angulaire totale
 | 
|---|
| 367 |   tgAngleX_= tan(0.5*angleX_*Pi/180.);
 | 
|---|
| 368 |   tgAngleY_= tan(0.5*angleY_*Pi/180.);
 | 
|---|
| 369 | 
 | 
|---|
| 370 |   extensFlag_= true;
 | 
|---|
| 371 |   cout << " LocalMap:: set extension done" << endl;
 | 
|---|
| 372 | }
 | 
|---|
| 373 | 
 | 
|---|
| 374 | //++
 | 
|---|
| 375 | template<class T>
 | 
|---|
| 376 | void LocalMap<T>::Project(SphericalMap<T>& sphere) const
 | 
|---|
| 377 | //
 | 
|---|
| 378 | //    Projection to a spherical map   
 | 
|---|
| 379 | //--
 | 
|---|
| 380 | {
 | 
|---|
| 381 |   for(int m = 0; m < nPix_; m++) 
 | 
|---|
| 382 |     {
 | 
|---|
| 383 |       double theta,phi;
 | 
|---|
| 384 |       PixThetaPhi(m,theta,phi);
 | 
|---|
| 385 |       sphere(theta,phi)= pixels_(m);
 | 
|---|
| 386 |       // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl;
 | 
|---|
| 387 |     }
 | 
|---|
| 388 | }
 | 
|---|
| 389 | // Titre        Private Methods
 | 
|---|
| 390 | //++
 | 
|---|
| 391 | template<class T>
 | 
|---|
| 392 | void LocalMap<T>::InitNul()
 | 
|---|
| 393 | //
 | 
|---|
| 394 | //    set some attributes to zero
 | 
|---|
| 395 | //--
 | 
|---|
| 396 | { 
 | 
|---|
| 397 |   originFlag_= false;
 | 
|---|
| 398 |   extensFlag_= false;
 | 
|---|
| 399 |   cos_angle_= 1.0;
 | 
|---|
| 400 |   sin_angle_= 0.0;
 | 
|---|
| 401 | //  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
 | 
|---|
| 402 | }
 | 
|---|
| 403 | 
 | 
|---|
| 404 | //++
 | 
|---|
| 405 | template<class T>
 | 
|---|
| 406 | void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
 | 
|---|
| 407 | //
 | 
|---|
| 408 | //    Return 2 indices corresponding to the pixel number k
 | 
|---|
| 409 | //--
 | 
|---|
| 410 | {
 | 
|---|
| 411 |   i= (k+1)%nSzX_-1;
 | 
|---|
| 412 |   if(i == -1) i= nSzX_-1;
 | 
|---|
| 413 |   j= (k-i+2)/nSzX_;
 | 
|---|
| 414 | }
 | 
|---|
| 415 | 
 | 
|---|
| 416 | //++
 | 
|---|
| 417 | template<class T>
 | 
|---|
| 418 | void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const
 | 
|---|
| 419 | //
 | 
|---|
| 420 | //    Transform a pair of coordinates (theta, phi) given in 
 | 
|---|
| 421 | //    reference coordinates into map coordinates
 | 
|---|
| 422 | //--     
 | 
|---|
| 423 | {
 | 
|---|
| 424 |   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
 | 
|---|
| 425 |     {
 | 
|---|
| 426 |       throw "LocalMap::ReferenceToUser (theta,phi) out of range"; 
 | 
|---|
| 427 |     } 
 | 
|---|
| 428 | 
 | 
|---|
| 429 |   theta= theta0_*Pi/180.+theta-Pi*0.5;
 | 
|---|
| 430 |   if(theta < 0.) 
 | 
|---|
| 431 |     {
 | 
|---|
| 432 |       theta= -theta;
 | 
|---|
| 433 |       phi += Pi;
 | 
|---|
| 434 |     } 
 | 
|---|
| 435 |   else 
 | 
|---|
| 436 |     {
 | 
|---|
| 437 |       if(theta > Pi) 
 | 
|---|
| 438 |         {
 | 
|---|
| 439 |           theta= 2.*Pi-theta;
 | 
|---|
| 440 |           phi += Pi;
 | 
|---|
| 441 |         } 
 | 
|---|
| 442 |     }
 | 
|---|
| 443 | 
 | 
|---|
| 444 |   phi= phi0_*Pi/180.+phi;
 | 
|---|
| 445 |   while(phi >= 2.*Pi) phi-= 2.*Pi;
 | 
|---|
| 446 | 
 | 
|---|
| 447 |   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
 | 
|---|
| 448 |     {
 | 
|---|
| 449 |       cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl;
 | 
|---|
| 450 |       cout << " theta= " << theta << " phi= " << phi << endl;
 | 
|---|
| 451 |       exit(0);
 | 
|---|
| 452 |     }
 | 
|---|
| 453 | }
 | 
|---|
| 454 | 
 | 
|---|
| 455 | //++
 | 
|---|
| 456 | template<class T>
 | 
|---|
| 457 | void  LocalMap<T>::UserToReference(double& theta,double& phi) const
 | 
|---|
| 458 | //
 | 
|---|
| 459 | //    Transform a pair of coordinates (theta, phi) given in 
 | 
|---|
| 460 | //    map coordinates into reference coordinates
 | 
|---|
| 461 | //--     
 | 
|---|
| 462 | {
 | 
|---|
| 463 |   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
 | 
|---|
| 464 |     {
 | 
|---|
| 465 |       cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl;
 | 
|---|
| 466 |       // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
 | 
|---|
| 467 |       throw "LocalMap::UserToReference (theta,phi) out of range"; 
 | 
|---|
| 468 |     }
 | 
|---|
| 469 | 
 | 
|---|
| 470 |   double phi1= phi-phi0_*Pi/180.;
 | 
|---|
| 471 |   if(phi1 < 0.) phi1+= 2.*Pi;
 | 
|---|
| 472 | 
 | 
|---|
| 473 |   double theta1= theta-theta0_*Pi/180.+Pi*0.5;
 | 
|---|
| 474 |   if(theta1 < 0.) 
 | 
|---|
| 475 |     {
 | 
|---|
| 476 |       theta= -theta1;
 | 
|---|
| 477 |       phi1+= Pi;
 | 
|---|
| 478 |     } 
 | 
|---|
| 479 |   else
 | 
|---|
| 480 |     { 
 | 
|---|
| 481 |       if(theta1 > Pi) 
 | 
|---|
| 482 |         {
 | 
|---|
| 483 |           theta= 2.*Pi-theta1;
 | 
|---|
| 484 |           phi1+= Pi;
 | 
|---|
| 485 |         }
 | 
|---|
| 486 |     }
 | 
|---|
| 487 | 
 | 
|---|
| 488 |   while(phi1 >= 2.*Pi) phi1-= 2.*Pi;
 | 
|---|
| 489 |   phi= phi1;
 | 
|---|
| 490 |   if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) 
 | 
|---|
| 491 |     {
 | 
|---|
| 492 |       cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl;
 | 
|---|
| 493 |       cout << " theta= " << theta << " phi= " << phi << endl;
 | 
|---|
| 494 |       exit(0);
 | 
|---|
| 495 |     }
 | 
|---|
| 496 | }
 | 
|---|
| 497 | 
 | 
|---|
| 498 | //++
 | 
|---|
| 499 | template<class T>
 | 
|---|
| 500 | void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const
 | 
|---|
| 501 | //
 | 
|---|
| 502 | //  
 | 
|---|
| 503 | //    Given coordinates in pixel units in the REFERENCE PLANE, return
 | 
|---|
| 504 | //    (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.   
 | 
|---|
| 505 | //--
 | 
|---|
| 506 | {
 | 
|---|
| 507 |   theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_);
 | 
|---|
| 508 |   phi= atan2(2.*x*tgAngleX_,(double)nSzX_);
 | 
|---|
| 509 |   if(phi < 0.) phi += DeuxPi;
 | 
|---|
| 510 | }
 | 
|---|
| 511 | 
 | 
|---|
| 512 | //++
 | 
|---|
| 513 | template<class T>
 | 
|---|
| 514 | void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const
 | 
|---|
| 515 | //
 | 
|---|
| 516 | //    Given coordinates  (theta, phi) in "absolute" referential 
 | 
|---|
| 517 | //    theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE.
 | 
|---|
| 518 | //--
 | 
|---|
| 519 | {
 | 
|---|
| 520 |   if(phi >= Pi) phi-= DeuxPi;
 | 
|---|
| 521 |   //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$
 | 
|---|
| 522 |   y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ?  
 | 
|---|
| 523 |   x= 0.5*nSzX_*tan(phi)/tgAngleX_;
 | 
|---|
| 524 | }
 | 
|---|
| 525 | 
 | 
|---|
| 526 | template<class T>
 | 
|---|
| 527 | void LocalMap<T>::print(ostream& os) const
 | 
|---|
| 528 | {
 | 
|---|
| 529 |   os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
 | 
|---|
| 530 |   if(LocalMap_isDone())
 | 
|---|
| 531 |     {
 | 
|---|
| 532 |       os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl;
 | 
|---|
| 533 |       os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
 | 
|---|
| 534 |       os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl;
 | 
|---|
| 535 |       os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl;
 | 
|---|
| 536 |       os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl;
 | 
|---|
| 537 |     }
 | 
|---|
| 538 | 
 | 
|---|
| 539 |   os << " contenu de pixels : ";
 | 
|---|
| 540 |   for(int i=0; i < nPix_; i++)
 | 
|---|
| 541 |     {
 | 
|---|
| 542 |       if(i%5 == 0) os << endl;
 | 
|---|
| 543 |       os <<  pixels_(i) <<", ";
 | 
|---|
| 544 |     }
 | 
|---|
| 545 |   os << endl;
 | 
|---|
| 546 | }
 | 
|---|
| 547 | //++
 | 
|---|
| 548 | // Titre        class FIO_LocalMap
 | 
|---|
| 549 | //    Delegated objects for persitance management
 | 
|---|
| 550 | //--
 | 
|---|
| 551 | 
 | 
|---|
| 552 | 
 | 
|---|
| 553 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 554 | #pragma define_template LocalMap<r_8>
 | 
|---|
| 555 | #pragma define_template LocalMap<r_4>
 | 
|---|
| 556 | #pragma define_template LocalMap< complex<r_8> >
 | 
|---|
| 557 | #pragma define_template LocalMap< complex<r_4> >
 | 
|---|
| 558 | #endif
 | 
|---|
| 559 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| 560 | template class LocalMap<r_8>;
 | 
|---|
| 561 | template class LocalMap<r_4>;
 | 
|---|
| 562 | template class LocalMap< complex<r_8> >;
 | 
|---|
| 563 | template class LocalMap< complex<r_4> >;
 | 
|---|
| 564 | #endif
 | 
|---|