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