| [764] | 1 | #include "localmap.h" | 
|---|
|  | 2 | #include "smathconst.h" | 
|---|
|  | 3 | #include <complex> | 
|---|
|  | 4 | #include "piocmplx.h" | 
|---|
| [809] | 5 | #include "fiondblock.h" | 
|---|
| [764] | 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 |  | 
|---|
|  | 99 | if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_); | 
|---|
| [908] | 100 | recopierVariablesSimples(lm); | 
|---|
| [764] | 101 | } | 
|---|
|  | 102 |  | 
|---|
|  | 103 | //++ | 
|---|
| [908] | 104 | template<class T> | 
|---|
|  | 105 | LocalMap<T>::LocalMap(const LocalMap<T>& lm) | 
|---|
|  | 106 | : pixels_(lm.pixels_) | 
|---|
|  | 107 |  | 
|---|
|  | 108 | // | 
|---|
|  | 109 | //    copy constructor | 
|---|
|  | 110 | //-- | 
|---|
|  | 111 | { | 
|---|
|  | 112 |  | 
|---|
|  | 113 | if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_); | 
|---|
|  | 114 | recopierVariablesSimples(lm); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 | //++ | 
|---|
| [764] | 118 | // Titre        Destructor | 
|---|
|  | 119 | //-- | 
|---|
|  | 120 | //++ | 
|---|
|  | 121 | template<class T> | 
|---|
|  | 122 | LocalMap<T>::~LocalMap() | 
|---|
|  | 123 | // | 
|---|
|  | 124 | //-- | 
|---|
|  | 125 | { | 
|---|
|  | 126 | InitNul(); | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|
|  | 129 |  | 
|---|
|  | 130 |  | 
|---|
|  | 131 | //++ | 
|---|
|  | 132 | // Titre        Public Methods | 
|---|
|  | 133 | //-- | 
|---|
|  | 134 |  | 
|---|
|  | 135 | //++ | 
|---|
|  | 136 | template<class T> | 
|---|
|  | 137 | void LocalMap<T>::ReSize(int_4 nx, int_4 ny) | 
|---|
|  | 138 | // | 
|---|
|  | 139 | //    Resize storage area for pixels | 
|---|
|  | 140 | //-- | 
|---|
|  | 141 | { | 
|---|
|  | 142 | InitNul(); | 
|---|
|  | 143 | nSzX_ = nx; | 
|---|
|  | 144 | nSzY_ = ny; | 
|---|
|  | 145 | nPix_= nx*ny; | 
|---|
|  | 146 | pixels_.ReSize(nPix_); | 
|---|
|  | 147 | pixels_.Reset(); | 
|---|
|  | 148 | } | 
|---|
|  | 149 |  | 
|---|
| [908] | 150 | template<class T> | 
|---|
|  | 151 | LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a) | 
|---|
|  | 152 | { | 
|---|
|  | 153 | if (this != &a) | 
|---|
|  | 154 | { | 
|---|
|  | 155 | recopierVariablesSimples(a); | 
|---|
|  | 156 | pixels_.CloneOrShare(a.pixels_); | 
|---|
|  | 157 | if (mInfo_) delete mInfo_; | 
|---|
|  | 158 | mInfo_ = NULL; | 
|---|
|  | 159 | if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_)); | 
|---|
|  | 160 | } | 
|---|
|  | 161 | return(*this); | 
|---|
|  | 162 | } | 
|---|
|  | 163 |  | 
|---|
|  | 164 |  | 
|---|
| [764] | 165 | //++ | 
|---|
|  | 166 | template<class T> | 
|---|
|  | 167 | int_4 LocalMap<T>::NbPixels() const | 
|---|
|  | 168 | // | 
|---|
|  | 169 | //    Return number of pixels | 
|---|
|  | 170 | //-- | 
|---|
|  | 171 | { | 
|---|
|  | 172 | return(nPix_); | 
|---|
|  | 173 | } | 
|---|
|  | 174 |  | 
|---|
|  | 175 | //++ | 
|---|
|  | 176 | template<class T> | 
|---|
|  | 177 | T& LocalMap<T>::PixVal(int_4 k) | 
|---|
|  | 178 | // | 
|---|
|  | 179 | //    Return value of pixel with index k | 
|---|
|  | 180 | //-- | 
|---|
|  | 181 | { | 
|---|
|  | 182 | if((k < 0) || (k >= nPix_)) | 
|---|
|  | 183 | { | 
|---|
|  | 184 | cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl; | 
|---|
|  | 185 | //  THROW(out_of_range("LocalMap::PIxVal Pixel index out of range")); | 
|---|
|  | 186 | THROW(rangeCheckErr); | 
|---|
|  | 187 | //throw "LocalMap::PIxVal Pixel index out of range"; | 
|---|
|  | 188 | } | 
|---|
|  | 189 | return(pixels_(k)); | 
|---|
|  | 190 | } | 
|---|
|  | 191 |  | 
|---|
|  | 192 | //++ | 
|---|
|  | 193 |  | 
|---|
|  | 194 | template<class T> | 
|---|
|  | 195 | T const& LocalMap<T>::PixVal(int_4 k) const | 
|---|
|  | 196 | // | 
|---|
|  | 197 | //   const version of previous method | 
|---|
|  | 198 | //-- | 
|---|
|  | 199 | { | 
|---|
|  | 200 | if((k < 0) || (k >= nPix_)) | 
|---|
|  | 201 | { | 
|---|
|  | 202 | cout << " LocalMap::PIxVal : exceptions  a mettre en place" <<endl; | 
|---|
|  | 203 | //    THROW(out_of_range("LocalMap::PIxVal Pixel index out of range")); | 
|---|
|  | 204 |  | 
|---|
|  | 205 | throw "LocalMap::PIxVal Pixel index out of range"; | 
|---|
|  | 206 | } | 
|---|
|  | 207 | return *(pixels_.Data()+k); | 
|---|
|  | 208 | } | 
|---|
|  | 209 |  | 
|---|
|  | 210 | template<class T> | 
|---|
|  | 211 | bool LocalMap<T>::ContainsSph(double theta, double phi) const | 
|---|
|  | 212 | { | 
|---|
|  | 213 | // $CHECK$  Reza 11/11/99 - A modifier | 
|---|
|  | 214 | return(true); | 
|---|
|  | 215 | } | 
|---|
|  | 216 |  | 
|---|
|  | 217 | //++ | 
|---|
|  | 218 | template<class T> | 
|---|
|  | 219 | int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const | 
|---|
|  | 220 | // | 
|---|
|  | 221 | //    Return index of the pixel with spherical coordinates (theta,phi) | 
|---|
|  | 222 | //-- | 
|---|
|  | 223 | { | 
|---|
|  | 224 | int_4 i,j; | 
|---|
|  | 225 | if(!(originFlag_) || !(extensFlag_)) | 
|---|
|  | 226 | { | 
|---|
|  | 227 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl; | 
|---|
|  | 228 | exit(0); | 
|---|
|  | 229 | } | 
|---|
|  | 230 |  | 
|---|
|  | 231 | // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference) | 
|---|
|  | 232 | double theta_aux= theta; | 
|---|
|  | 233 | double phi_aux  = phi; | 
|---|
|  | 234 | UserToReference(theta_aux, phi_aux); | 
|---|
|  | 235 |  | 
|---|
|  | 236 | // coordonnees dans le plan local en unites de pixels | 
|---|
|  | 237 | double x,y; | 
|---|
|  | 238 | AngleProjToPix(theta_aux,phi_aux, x, y); | 
|---|
|  | 239 |  | 
|---|
|  | 240 | double xmin= -x0_-0.5; | 
|---|
|  | 241 | double xmax= xmin+nSzX_; | 
|---|
|  | 242 | if((x > xmax) || (x < xmin)) return(-1); | 
|---|
|  | 243 | double xcurrent= xmin; | 
|---|
|  | 244 | for(i = 0; i < nSzX_; i++ ) | 
|---|
|  | 245 | { | 
|---|
|  | 246 | xcurrent += 1.; | 
|---|
|  | 247 | if( x < xcurrent ) break; | 
|---|
|  | 248 | } | 
|---|
|  | 249 | double ymin= -y0_-0.5; | 
|---|
|  | 250 | double ymax= ymin+nSzY_; | 
|---|
|  | 251 | if((y >  ymax) || (y < ymin)) return(-1); | 
|---|
|  | 252 | double ycurrent= ymin; | 
|---|
|  | 253 | for(j = 0; j < nSzY_; j++ ) | 
|---|
|  | 254 | { | 
|---|
|  | 255 | ycurrent += 1.; | 
|---|
|  | 256 | if( y < ycurrent ) break; | 
|---|
|  | 257 | } | 
|---|
|  | 258 | return (j*nSzX_+i); | 
|---|
|  | 259 | } | 
|---|
|  | 260 |  | 
|---|
|  | 261 | //++ | 
|---|
|  | 262 | template<class T> | 
|---|
|  | 263 | void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const | 
|---|
|  | 264 | // | 
|---|
|  | 265 | //    Return (theta, phi) coordinates of pixel with index k | 
|---|
|  | 266 | //-- | 
|---|
|  | 267 | { | 
|---|
|  | 268 | if(!(originFlag_) || !(extensFlag_)) | 
|---|
|  | 269 | { | 
|---|
|  | 270 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl; | 
|---|
|  | 271 | exit(0); | 
|---|
|  | 272 | } | 
|---|
|  | 273 |  | 
|---|
|  | 274 | int_4 i,j; | 
|---|
|  | 275 | Getij(k,i,j); | 
|---|
|  | 276 |  | 
|---|
|  | 277 | double X= double(i-x0_); | 
|---|
|  | 278 | double Y= double(j-y0_); | 
|---|
|  | 279 | // situation de ce pixel dans le plan de reference | 
|---|
|  | 280 | double x= X*cos_angle_-Y*sin_angle_; | 
|---|
|  | 281 | double y= X*sin_angle_+Y* cos_angle_; | 
|---|
|  | 282 | // projection sur la sphere | 
|---|
|  | 283 | PixProjToAngle(x, y, theta, phi); | 
|---|
|  | 284 | // retour au plan utilisateur | 
|---|
|  | 285 | ReferenceToUser(theta, phi); | 
|---|
|  | 286 | } | 
|---|
|  | 287 |  | 
|---|
|  | 288 | template <class T> | 
|---|
|  | 289 | T LocalMap<T>::SetPixels(T v) | 
|---|
|  | 290 | { | 
|---|
|  | 291 | pixels_.Reset(v); | 
|---|
|  | 292 | return(v); | 
|---|
|  | 293 | } | 
|---|
|  | 294 |  | 
|---|
|  | 295 | //++ | 
|---|
|  | 296 | template<class T> | 
|---|
|  | 297 | double LocalMap<T>::PixSolAngle(int_4 k) const | 
|---|
|  | 298 | // | 
|---|
|  | 299 | //    Pixel Solid angle  (steradians) | 
|---|
|  | 300 | //    All the pixels have not necessarly the same size in (theta, phi) | 
|---|
|  | 301 | //    because of the projection scheme which is not yet fixed. | 
|---|
|  | 302 | //-- | 
|---|
|  | 303 | { | 
|---|
|  | 304 | int_4 i,j; | 
|---|
|  | 305 | Getij(k,i,j); | 
|---|
|  | 306 | double X= double(i-x0_); | 
|---|
|  | 307 | double Y= double(j-y0_); | 
|---|
|  | 308 | double XR= X+double(i)*0.5; | 
|---|
|  | 309 | double XL= X-double(i)*0.5; | 
|---|
|  | 310 | double YU= Y+double(j)*0.5; | 
|---|
|  | 311 | double YL= Y-double(j)*0.5; | 
|---|
|  | 312 |  | 
|---|
|  | 313 | // situation  dans le plan de reference | 
|---|
|  | 314 | double x0= XL*cos_angle_-YL*sin_angle_; | 
|---|
|  | 315 | double y0= XL*sin_angle_+YL*cos_angle_; | 
|---|
|  | 316 | double xa= XR*cos_angle_-YL*sin_angle_; | 
|---|
|  | 317 | double ya= XR*sin_angle_+YL*cos_angle_; | 
|---|
|  | 318 | double xb= XL*cos_angle_-YU*sin_angle_; | 
|---|
|  | 319 | double yb= XL*sin_angle_+YU*cos_angle_; | 
|---|
|  | 320 |  | 
|---|
|  | 321 | // projection sur la sphere | 
|---|
|  | 322 | double thet0,phi0,theta,phia,thetb,phib; | 
|---|
|  | 323 | PixProjToAngle(x0, y0, thet0, phi0); | 
|---|
|  | 324 | PixProjToAngle(xa, ya, theta, phia); | 
|---|
|  | 325 | PixProjToAngle(xb, yb, thetb, phib); | 
|---|
|  | 326 |  | 
|---|
|  | 327 | // angle solide | 
|---|
|  | 328 | double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0)); | 
|---|
|  | 329 | return sol; | 
|---|
|  | 330 | } | 
|---|
|  | 331 |  | 
|---|
|  | 332 | //++ | 
|---|
|  | 333 | template<class T> | 
|---|
|  | 334 | void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle) | 
|---|
|  | 335 | // | 
|---|
|  | 336 | //    set the referential of the map (angles in degrees) | 
|---|
|  | 337 | //    (default x0=siz_x/2,  y0=siz_y/2) | 
|---|
|  | 338 | //-- | 
|---|
|  | 339 | { | 
|---|
|  | 340 | theta0_= theta0; | 
|---|
|  | 341 | phi0_  = phi0; | 
|---|
|  | 342 | angle_ = angle; | 
|---|
|  | 343 | x0_= nSzX_/2; | 
|---|
|  | 344 | y0_= nSzY_/2; | 
|---|
|  | 345 | cos_angle_= cos(angle*Pi/180.); | 
|---|
|  | 346 | sin_angle_= sin(angle*Pi/180.); | 
|---|
|  | 347 | originFlag_= true; | 
|---|
|  | 348 | cout << " LocalMap:: set origin 1 done" << endl; | 
|---|
|  | 349 | } | 
|---|
|  | 350 |  | 
|---|
|  | 351 | //++ | 
|---|
|  | 352 | template<class T> | 
|---|
|  | 353 | void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle) | 
|---|
|  | 354 | // | 
|---|
|  | 355 | //    set the referential of the map (angles in degrees) | 
|---|
|  | 356 | //-- | 
|---|
|  | 357 | { | 
|---|
|  | 358 | theta0_= theta0; | 
|---|
|  | 359 | phi0_  = phi0; | 
|---|
|  | 360 | angle_ = angle; | 
|---|
|  | 361 | x0_= x0; | 
|---|
|  | 362 | y0_= y0; | 
|---|
|  | 363 | cos_angle_= cos(angle*Pi/180.); | 
|---|
|  | 364 | sin_angle_= sin(angle*Pi/180.); | 
|---|
|  | 365 | originFlag_= true; | 
|---|
|  | 366 | cout << " LocalMap:: set origin 2 done" << endl; | 
|---|
|  | 367 | } | 
|---|
|  | 368 |  | 
|---|
|  | 369 | //++ | 
|---|
|  | 370 | template<class T> | 
|---|
|  | 371 | void LocalMap<T>::SetSize(double angleX,double angleY) | 
|---|
|  | 372 | // | 
|---|
|  | 373 | //    angle range of tthe map (angles in degrees) | 
|---|
|  | 374 | //-- | 
|---|
|  | 375 | { | 
|---|
|  | 376 | angleX_= angleX; | 
|---|
|  | 377 | angleY_= angleY; | 
|---|
|  | 378 |  | 
|---|
|  | 379 | // tangente de la moitie de l'ouverture angulaire totale | 
|---|
|  | 380 | tgAngleX_= tan(0.5*angleX_*Pi/180.); | 
|---|
|  | 381 | tgAngleY_= tan(0.5*angleY_*Pi/180.); | 
|---|
|  | 382 |  | 
|---|
|  | 383 | extensFlag_= true; | 
|---|
|  | 384 | cout << " LocalMap:: set extension done" << endl; | 
|---|
|  | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | //++ | 
|---|
|  | 388 | template<class T> | 
|---|
|  | 389 | void LocalMap<T>::Project(SphericalMap<T>& sphere) const | 
|---|
|  | 390 | // | 
|---|
|  | 391 | //    Projection to a spherical map | 
|---|
|  | 392 | //-- | 
|---|
|  | 393 | { | 
|---|
|  | 394 | for(int m = 0; m < nPix_; m++) | 
|---|
|  | 395 | { | 
|---|
|  | 396 | double theta,phi; | 
|---|
|  | 397 | PixThetaPhi(m,theta,phi); | 
|---|
|  | 398 | sphere(theta,phi)= pixels_(m); | 
|---|
|  | 399 | // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl; | 
|---|
|  | 400 | } | 
|---|
|  | 401 | } | 
|---|
|  | 402 | // Titre        Private Methods | 
|---|
|  | 403 | //++ | 
|---|
|  | 404 | template<class T> | 
|---|
|  | 405 | void LocalMap<T>::InitNul() | 
|---|
|  | 406 | // | 
|---|
|  | 407 | //    set some attributes to zero | 
|---|
|  | 408 | //-- | 
|---|
|  | 409 | { | 
|---|
|  | 410 | originFlag_= false; | 
|---|
|  | 411 | extensFlag_= false; | 
|---|
|  | 412 | cos_angle_= 1.0; | 
|---|
|  | 413 | sin_angle_= 0.0; | 
|---|
|  | 414 | //  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$ | 
|---|
|  | 415 | } | 
|---|
|  | 416 |  | 
|---|
|  | 417 | //++ | 
|---|
|  | 418 | template<class T> | 
|---|
|  | 419 | void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const | 
|---|
|  | 420 | // | 
|---|
|  | 421 | //    Return 2 indices corresponding to the pixel number k | 
|---|
|  | 422 | //-- | 
|---|
|  | 423 | { | 
|---|
|  | 424 | i= (k+1)%nSzX_-1; | 
|---|
|  | 425 | if(i == -1) i= nSzX_-1; | 
|---|
|  | 426 | j= (k-i+2)/nSzX_; | 
|---|
|  | 427 | } | 
|---|
|  | 428 |  | 
|---|
|  | 429 | //++ | 
|---|
|  | 430 | template<class T> | 
|---|
|  | 431 | void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const | 
|---|
|  | 432 | // | 
|---|
|  | 433 | //    Transform a pair of coordinates (theta, phi) given in | 
|---|
|  | 434 | //    reference coordinates into map coordinates | 
|---|
|  | 435 | //-- | 
|---|
|  | 436 | { | 
|---|
|  | 437 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 438 | { | 
|---|
|  | 439 | throw "LocalMap::ReferenceToUser (theta,phi) out of range"; | 
|---|
|  | 440 | } | 
|---|
|  | 441 |  | 
|---|
|  | 442 | theta= theta0_*Pi/180.+theta-Pi*0.5; | 
|---|
|  | 443 | if(theta < 0.) | 
|---|
|  | 444 | { | 
|---|
|  | 445 | theta= -theta; | 
|---|
|  | 446 | phi += Pi; | 
|---|
|  | 447 | } | 
|---|
|  | 448 | else | 
|---|
|  | 449 | { | 
|---|
|  | 450 | if(theta > Pi) | 
|---|
|  | 451 | { | 
|---|
|  | 452 | theta= 2.*Pi-theta; | 
|---|
|  | 453 | phi += Pi; | 
|---|
|  | 454 | } | 
|---|
|  | 455 | } | 
|---|
|  | 456 |  | 
|---|
|  | 457 | phi= phi0_*Pi/180.+phi; | 
|---|
|  | 458 | while(phi >= 2.*Pi) phi-= 2.*Pi; | 
|---|
|  | 459 |  | 
|---|
|  | 460 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 461 | { | 
|---|
|  | 462 | cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl; | 
|---|
|  | 463 | cout << " theta= " << theta << " phi= " << phi << endl; | 
|---|
|  | 464 | exit(0); | 
|---|
|  | 465 | } | 
|---|
|  | 466 | } | 
|---|
|  | 467 |  | 
|---|
|  | 468 | //++ | 
|---|
|  | 469 | template<class T> | 
|---|
|  | 470 | void  LocalMap<T>::UserToReference(double& theta,double& phi) const | 
|---|
|  | 471 | // | 
|---|
|  | 472 | //    Transform a pair of coordinates (theta, phi) given in | 
|---|
|  | 473 | //    map coordinates into reference coordinates | 
|---|
|  | 474 | //-- | 
|---|
|  | 475 | { | 
|---|
|  | 476 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 477 | { | 
|---|
|  | 478 | cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl; | 
|---|
|  | 479 | // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range")); | 
|---|
|  | 480 | throw "LocalMap::UserToReference (theta,phi) out of range"; | 
|---|
|  | 481 | } | 
|---|
|  | 482 |  | 
|---|
|  | 483 | double phi1= phi-phi0_*Pi/180.; | 
|---|
|  | 484 | if(phi1 < 0.) phi1+= 2.*Pi; | 
|---|
|  | 485 |  | 
|---|
|  | 486 | double theta1= theta-theta0_*Pi/180.+Pi*0.5; | 
|---|
|  | 487 | if(theta1 < 0.) | 
|---|
|  | 488 | { | 
|---|
|  | 489 | theta= -theta1; | 
|---|
|  | 490 | phi1+= Pi; | 
|---|
|  | 491 | } | 
|---|
|  | 492 | else | 
|---|
|  | 493 | { | 
|---|
|  | 494 | if(theta1 > Pi) | 
|---|
|  | 495 | { | 
|---|
|  | 496 | theta= 2.*Pi-theta1; | 
|---|
|  | 497 | phi1+= Pi; | 
|---|
|  | 498 | } | 
|---|
|  | 499 | } | 
|---|
|  | 500 |  | 
|---|
|  | 501 | while(phi1 >= 2.*Pi) phi1-= 2.*Pi; | 
|---|
|  | 502 | phi= phi1; | 
|---|
|  | 503 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 504 | { | 
|---|
|  | 505 | cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl; | 
|---|
|  | 506 | cout << " theta= " << theta << " phi= " << phi << endl; | 
|---|
|  | 507 | exit(0); | 
|---|
|  | 508 | } | 
|---|
|  | 509 | } | 
|---|
|  | 510 |  | 
|---|
|  | 511 | //++ | 
|---|
|  | 512 | template<class T> | 
|---|
|  | 513 | void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const | 
|---|
|  | 514 | // | 
|---|
|  | 515 | // | 
|---|
|  | 516 | //    Given coordinates in pixel units in the REFERENCE PLANE, return | 
|---|
|  | 517 | //    (theta, phi) in "absolute" referential theta=pi/2 ,phi=0. | 
|---|
|  | 518 | //-- | 
|---|
|  | 519 | { | 
|---|
|  | 520 | theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_); | 
|---|
|  | 521 | phi= atan2(2.*x*tgAngleX_,(double)nSzX_); | 
|---|
|  | 522 | if(phi < 0.) phi += DeuxPi; | 
|---|
|  | 523 | } | 
|---|
|  | 524 |  | 
|---|
|  | 525 | //++ | 
|---|
|  | 526 | template<class T> | 
|---|
|  | 527 | void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const | 
|---|
|  | 528 | // | 
|---|
|  | 529 | //    Given coordinates  (theta, phi) in "absolute" referential | 
|---|
|  | 530 | //    theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE. | 
|---|
|  | 531 | //-- | 
|---|
|  | 532 | { | 
|---|
|  | 533 | if(phi >= Pi) phi-= DeuxPi; | 
|---|
|  | 534 | //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$ | 
|---|
|  | 535 | y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ? | 
|---|
|  | 536 | x= 0.5*nSzX_*tan(phi)/tgAngleX_; | 
|---|
|  | 537 | } | 
|---|
|  | 538 |  | 
|---|
|  | 539 | template<class T> | 
|---|
|  | 540 | void LocalMap<T>::print(ostream& os) const | 
|---|
|  | 541 | { | 
|---|
|  | 542 | os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl; | 
|---|
|  | 543 | if(LocalMap_isDone()) | 
|---|
|  | 544 | { | 
|---|
|  | 545 | os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl; | 
|---|
|  | 546 | os<<" x0= "<<x0_<<", y0= "<<y0_<<endl; | 
|---|
|  | 547 | os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl; | 
|---|
|  | 548 | os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl; | 
|---|
|  | 549 | os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl; | 
|---|
|  | 550 | } | 
|---|
|  | 551 |  | 
|---|
|  | 552 | os << " contenu de pixels : "; | 
|---|
|  | 553 | for(int i=0; i < nPix_; i++) | 
|---|
|  | 554 | { | 
|---|
|  | 555 | if(i%5 == 0) os << endl; | 
|---|
|  | 556 | os <<  pixels_(i) <<", "; | 
|---|
|  | 557 | } | 
|---|
|  | 558 | os << endl; | 
|---|
|  | 559 | } | 
|---|
| [908] | 560 |  | 
|---|
|  | 561 |  | 
|---|
|  | 562 | template<class T> | 
|---|
|  | 563 | void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm) | 
|---|
|  | 564 | { | 
|---|
|  | 565 | nSzX_= lm.nSzX_; | 
|---|
|  | 566 | nSzY_= lm.nSzY_; | 
|---|
|  | 567 | nPix_= lm.nPix_; | 
|---|
|  | 568 | originFlag_= lm.originFlag_; | 
|---|
|  | 569 | extensFlag_= lm.extensFlag_; | 
|---|
|  | 570 | x0_= lm.x0_; | 
|---|
|  | 571 | y0_= lm.y0_; | 
|---|
|  | 572 | theta0_= lm.theta0_; | 
|---|
|  | 573 | phi0_= lm.phi0_; | 
|---|
|  | 574 | angle_= lm.angle_; | 
|---|
|  | 575 | cos_angle_= lm.cos_angle_; | 
|---|
|  | 576 | sin_angle_= lm.sin_angle_; | 
|---|
|  | 577 | angleX_= lm.angleX_; | 
|---|
|  | 578 | angleY_= lm.angleY_; | 
|---|
|  | 579 | tgAngleX_= lm.tgAngleX_; | 
|---|
|  | 580 | tgAngleY_= lm.tgAngleY_; | 
|---|
|  | 581 | } | 
|---|
|  | 582 |  | 
|---|
|  | 583 |  | 
|---|
| [764] | 584 | //++ | 
|---|
|  | 585 | // Titre        class FIO_LocalMap | 
|---|
|  | 586 | //    Delegated objects for persitance management | 
|---|
|  | 587 | //-- | 
|---|
|  | 588 |  | 
|---|
|  | 589 |  | 
|---|
|  | 590 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 591 | #pragma define_template LocalMap<r_8> | 
|---|
|  | 592 | #pragma define_template LocalMap<r_4> | 
|---|
|  | 593 | #pragma define_template LocalMap< complex<r_8> > | 
|---|
|  | 594 | #pragma define_template LocalMap< complex<r_4> > | 
|---|
|  | 595 | #endif | 
|---|
|  | 596 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
|  | 597 | template class LocalMap<r_8>; | 
|---|
|  | 598 | template class LocalMap<r_4>; | 
|---|
|  | 599 | template class LocalMap< complex<r_8> >; | 
|---|
|  | 600 | template class LocalMap< complex<r_4> >; | 
|---|
|  | 601 | #endif | 
|---|