Changeset 2013 in Sophya for trunk/SophyaLib/SkyMap/localmap.cc
- Timestamp:
- May 24, 2002, 4:54:53 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SkyMap/localmap.cc
r1624 r2013 7 7 #include <string.h> 8 8 #include <iostream.h> 9 #include "timing.h" 9 10 10 11 11 12 /*! 12 13 \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) 14 A local map is a 2 dimensional matrix, with ny rows and nx columns. 15 The local map has an origin in (theta0, phi0), mapped to pixel(x0, y0) 16 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. 17 Each pixel(ip, it) is defined by its "phi-like" index ip (column 18 index in the matrix) and its "theta-like" index it (row index in 19 the matrix). Index ip is associated with x-axis in a map-coordinate 20 system ; index it is associated with y-axis in the same map-coordinate system. 21 22 The map is supposed to lie on a plan tangent to the celestial sphere 23 at a point, with spherical coordinates (theta0, phi0), whose pixel 24 numbers are (x0,y0) in the local map. The aperture of the map is defined 25 by two values of angles, angleX and angleY, covered respectively by all 26 the pixels in x direction and all the pixels in y direction. 27 28 Each pixel has angleX/nx and angleY/ny, as angle extensions. So, in 29 map-coordinate system the pixel (i,j) has following coordinates : 30 31 x = (i-x0)*angleX/nx 32 33 y = (j-y0)*angleY/ny 30 34 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(...)) 35 (angles in radians) 36 37 The projection (method : ProjectionToSphere() )of the map onto a 38 sphere is made by the following procedure : 39 40 the sphere is supposed to have radius=1. The map is 41 considered to be tangent to the sphere, on a point with (theta0, phi0) 42 spherical coodinates. A reference coordinate system (plane-coordinate 43 system) , is chosen in the plane of the map with reference axes : 44 45 x-axis : vector tengent to a parallel in (theta0, phi0) on the sphere 46 (components in "3-dim cartesian system : -sin(phi0) ; cos(phi0) ; 0) 47 48 z-axis : vector-radius with 3-dim cartesian cordinates : 49 sin(theta0)*cos(phi0) ; sin(theta0*sin(phi0) ; cos(theta0) 50 51 y-axis = z-axis^x-axis : tangent to the meridian at (theta0, phi0) 52 53 note that the map-coordinate system may be rotated with respect to 54 plane-coordinate system (parameter "angle" below). 55 56 the projection of a map pixel is defined as the intersection of 57 the vector-radius, from sphere center to the pixel defined by 58 his coordinates in the plane-coordinate system (computed from x,y 59 above, with eventual rotation), with the sphere. 38 60 */ 39 61 template<class T> … … 43 65 } 44 66 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) 67 //! full constructor of the local map 68 /*! 69 \param nx : number of pixels in x direction 70 \param ny : number of pixels in y direction 71 \param angleX : total angle aperture in x direction (degrees) 72 \param angleY : total angle aperture in y direction (degrees) 73 \param theta0,phi0 : spherical coordinates of reference point at which 74 the map is considered to be tangent to the sphere 75 \param x0, y0 : coodinates (in pixels) of the reference point just defined 76 \param angle : angle (degrees) of the rotation between x-axis of 77 map-coordinate system) and the tangent to parallel on 78 the sphere (default : 0.). 79 */ 80 template<class T> 81 LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle) 87 82 { 88 83 InitNul(); … … 90 85 nSzY_ = ny; 91 86 nPix_= nx*ny; 92 pixels_.ReSize(nPix_); 93 pixels_.Reset(); 87 pixels_.ReSize(ny,nx); 88 SetSize(angleX, angleY); 89 SetOrigin(theta0, phi0, x0, y0, angle); 90 } 91 92 93 //! standard constructor of the local map 94 /*! 95 \param nx : number of pixels in x direction 96 \param ny : number of pixels in y direction 97 \param angleX : total angle aperture in x direction (degrees) 98 \param angleY : total angle aperture in y direction (degrees) 99 \param theta0,phi0 : spherical coordinates of reference point at which 100 the map is considered to be tangent to the sphere 101 \param angle : angle (degrees) of the rotation between x-axis of 102 map-coordinate system) and the tangent to parallel on 103 the sphere (default : 0.). 104 */ 105 template<class T> 106 LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle) 107 { 108 InitNul(); 109 nSzX_ = nx; 110 nSzY_ = ny; 111 nPix_= nx*ny; 112 pixels_.ReSize(ny,nx); 113 cout << " tableau pixels initialise " << endl; 114 SetSize(angleX, angleY); 115 cout << " fin du setsize " << endl; 116 SetOrigin(theta0, phi0, angle); 117 cout << " fin du set oorigine " << endl; 118 } 119 120 //! copy constructor 121 /*! 122 \param share : if true, share data. If false copy data 123 */ 124 template<class T> 125 LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share) 126 : pixels_(lm.pixels_, share) 127 { 128 129 if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_); 130 recopierVariablesSimples(lm); 131 } 132 133 //! copy constructor 134 /*! 135 \warning datas are \b SHARED with \b lm. 136 \sa TMatrix::TMatrix(const TMatrix<T>&) 137 */ 138 template<class T> 139 LocalMap<T>::LocalMap(const LocalMap<T>& lm) 140 : pixels_(lm.pixels_) 141 142 { 143 144 if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_); 145 recopierVariablesSimples(lm); 146 } 147 148 template<class T> 149 LocalMap<T>::~LocalMap() {;} 150 151 152 153 /*! \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny) 154 155 Resize storage area for pixels 156 */ 157 template<class T> 158 void LocalMap<T>::ReSize(int_4 nx, int_4 ny) 159 { 160 // angles par pixel, en radians 161 deltaPhi_ *= nSzX_/nx; 162 deltaTheta_ *= nSzY_/ny; 163 164 nSzX_ = nx; 165 nSzY_ = ny; 166 nPix_= nx*ny; 167 pixels_.ReSize(ny,nx); 94 168 } 95 169 … … 122 196 recopierVariablesSimples(a); 123 197 int k; 124 for (k=0; k< nPix_; k++) pixels_(k) = a.pixels_(k);198 pixels_ = a.pixels_; 125 199 return(*this); 126 200 … … 163 237 if((k < 0) || (k >= nPix_)) 164 238 { 165 cout << " LocalMap::PIxVal : exceptions a mettre en place" <<endl; 166 THROW(rangeCheckErr); 167 } 168 return(pixels_(k)); 239 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range "); 240 } 241 // 242 int_4 i,j; 243 Getij(k,i,j); 244 return(pixels_(j,i)); 245 246 // 169 247 } 170 248 … … 177 255 if((k < 0) || (k >= nPix_)) 178 256 { 179 cout << " LocalMap::PIxVal : exceptions a mettre en place" <<endl; 180 throw "LocalMap::PIxVal Pixel index out of range"; 257 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range "); 181 258 } 182 return *(pixels_.Data()+k); 259 // 260 int_4 i,j; 261 Getij(k,i,j); 262 return(pixels_(j,i)); 183 263 } 184 264 … … 197 277 /*! \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const 198 278 279 angles in radians 199 280 \return index of the pixel with spherical coordinates (theta,phi) 200 281 */ … … 203 284 { 204 285 int_4 i,j; 205 if(!(originFlag_) || !(extensFlag_)) 206 { 207 cout << " LocalMap: correspondance carte-sphere non etablie" << endl; 208 exit(0); 209 } 210 211 // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference) 212 double theta_aux= theta; 213 double phi_aux = phi; 214 UserToReference(theta_aux, phi_aux); 215 216 // coordonnees dans le plan local en unites de pixels 217 double x,y; 218 AngleProjToPix(theta_aux,phi_aux, x, y); 286 287 double csTheta = cos(theta); 288 double snTheta = sin(theta); 289 double csPhi = cos(phi); 290 double snPhi = sin(phi); 291 double csPhiMPhiC = cos (phi - phiC_); 292 double snPhiMPhiC = sin (phi - phiC_); 293 // le point sur la sphere est note M. 294 // intersection P de OM avec le plan de la carte (tangent en C) 295 double denom = snTheta*snthC_*csPhiMPhiC + csTheta*csthC_; 296 if ( denom == 0.) 297 { 298 throw PException("LocalMap::PixIndexSph : vector radius parallel to map plane "); 299 } 300 double lambda = 1./denom; 301 // coordonnes du point d'intersection P dans le repere lie au plan 302 303 double XP = lambda*snTheta*snPhiMPhiC; 304 double YP = lambda*snTheta*csthC_*csPhiMPhiC; 305 306 // coordonnees dans le repere lie a la carte (eventuellement tourne par 307 // rapport au precedent. 308 309 double X = XP*cosAngle_ + YP*sinAngle_; 310 double Y = -XP*sinAngle_ + YP*cosAngle_; 311 312 // en unites de pixels 313 314 X /= deltaPhi_; 315 Y /= deltaTheta_; 316 219 317 220 318 double xmin= -x0_-0.5; 221 319 double xmax= xmin+nSzX_; 222 if(( x > xmax) || (x< xmin)) return(-1);320 if((X > xmax) || (X < xmin)) return(-1); 223 321 double xcurrent= xmin; 224 322 for(i = 0; i < nSzX_; i++ ) 225 323 { 226 324 xcurrent += 1.; 227 if( x< xcurrent ) break;325 if( X < xcurrent ) break; 228 326 } 229 327 double ymin= -y0_-0.5; 230 328 double ymax= ymin+nSzY_; 231 if(( y > ymax) || (y< ymin)) return(-1);329 if((Y > ymax) || (Y < ymin)) return(-1); 232 330 double ycurrent= ymin; 233 331 for(j = 0; j < nSzY_; j++ ) 234 332 { 235 333 ycurrent += 1.; 236 if( y< ycurrent ) break;334 if( Y < ycurrent ) break; 237 335 } 238 336 return (j*nSzX_+i); … … 243 341 \return (theta, phi) coordinates of pixel with index k 244 342 */ 343 344 245 345 template<class T> 246 346 void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const 247 347 { 248 if(!(originFlag_) || !(extensFlag_))249 {250 cout << " LocalMap: correspondance carte-sphere non etablie" << endl;251 exit(0);252 }253 348 254 349 int_4 i,j; 255 350 Getij(k,i,j); 256 351 257 double X= double(i-x0_); 258 double Y= double(j-y0_); 259 // situation de ce pixel dans le plan de reference 260 double x= X*cos_angle_-Y*sin_angle_; 261 double y= X*sin_angle_+Y* cos_angle_; 262 // projection sur la sphere 263 PixProjToAngle(x, y, theta, phi); 264 // retour au plan utilisateur 265 ReferenceToUser(theta, phi); 266 } 352 PixThetaPhi(i,j, theta, phi); 353 354 } 355 356 /*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const 357 358 359 \return (theta, phi) coordinates of pixel of map with indices (ip,it) corresponding to x and y directions 360 361 \param ip : phi-like index 362 \param it : theta-like index 363 */ 364 365 template<class T> 366 void LocalMap<T>::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const 367 { 368 double XP, YP, ZP; 369 PixToSphereC(ip,it,XP,YP,ZP); 370 371 theta = acos(ZP); 372 phi = atan2(YP, XP); 373 while (phi < 0.) phi += 2.*Pi; 374 375 } 376 377 378 267 379 268 380 /*! \fn T SOPHYA::LocalMap::SetPixels(T v) … … 273 385 T LocalMap<T>::SetPixels(T v) 274 386 { 275 pixels_ .Reset(v);387 pixels_ = v; 276 388 return(v); 277 389 } … … 281 393 Pixel Solid angle (steradians) 282 394 283 All the pixels have not necessarly the same size in (theta, phi)284 because of the projection scheme which is not yet fixed.395 All the pixels are considered to have the same size in (theta, phi). 396 285 397 */ 286 398 template<class T> 287 399 double LocalMap<T>::PixSolAngle(int_4 k) const 288 400 { 401 double XP, YP, ZP; 289 402 int_4 i,j; 290 403 Getij(k,i,j); 291 double X= double(i-x0_); 292 double Y= double(j-y0_); 293 double XR= X+double(i)*0.5; 294 double XL= X-double(i)*0.5; 295 double YU= Y+double(j)*0.5; 296 double YL= Y-double(j)*0.5; 297 298 // situation dans le plan de reference 299 double x0= XL*cos_angle_-YL*sin_angle_; 300 double y0= XL*sin_angle_+YL*cos_angle_; 301 double xa= XR*cos_angle_-YL*sin_angle_; 302 double ya= XR*sin_angle_+YL*cos_angle_; 303 double xb= XL*cos_angle_-YU*sin_angle_; 304 double yb= XL*sin_angle_+YU*cos_angle_; 305 306 // projection sur la sphere 307 double thet0,phi0,theta,phia,thetb,phib; 308 PixProjToAngle(x0, y0, thet0, phi0); 309 PixProjToAngle(xa, ya, theta, phia); 310 PixProjToAngle(xb, yb, thetb, phib); 404 PixToSphereC(i,j,XP,YP,ZP); 405 406 double theta = acos(ZP); 407 408 311 409 312 410 // angle solide 313 double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0)); 411 412 double sol= 2.* deltaPhi_*sin(theta)*sin(0.5*deltaTheta_); 314 413 return sol; 315 414 } 316 415 416 /*! \fn void SOPHYA::LocalMap::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) 417 418 projection of a pixel of map, onto the unity sphere ; result in cartesian coordinates. 419 */ 420 421 template<class T> 422 void LocalMap<T>::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const 423 { 424 double X= double(ip-x0_)* deltaPhi_; 425 double Y= double(it-y0_)*deltaTheta_; 426 427 // situation dans le plan de reference tangent 428 double dx= X*cosAngle_-Y*sinAngle_; 429 double dy= X*sinAngle_+Y*cosAngle_; 430 431 XP = XC_ - dx*snphC_ - dy*csthC_*csphC_; 432 YP = YC_ + dx*csphC_ - dy*csthC_*snphC_; 433 ZP = ZC_ + dy*snthC_; 434 435 // on renormalise pour eviter les probleme de precision lors 436 // de la prise ulterieure de lignes trigonometriques 437 double norme = sqrt(XP*XP + YP*YP + ZP*ZP); 438 XP /= norme; 439 YP /= norme; 440 ZP /= norme; 441 } 442 317 443 /*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle) 318 444 … … 324 450 void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle) 325 451 { 326 theta0_= theta0; 327 phi0_ = phi0; 328 angle_ = angle; 329 x0_= nSzX_/2; 330 y0_= nSzY_/2; 331 cos_angle_= cos(angle*Pi/180.); 332 sin_angle_= sin(angle*Pi/180.); 333 originFlag_= true; 334 cout << " LocalMap:: set origin 1 done" << endl; 452 SetOrigin(theta0, phi0, nSzX_/2, nSzY_/2, angle); 335 453 } 336 454 … … 342 460 void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle) 343 461 { 344 theta0_= theta0; 345 phi0_ = phi0; 346 angle_ = angle; 462 // if (originFlag_) 463 // { 464 // throw PException("LocalMap::SetOrigin : redefining origin is not allowed at the moment "); 465 // } 466 467 if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.) 468 { 469 throw "LocalMap::SetOrigin angle out of range"; 470 } 471 SetCoorC(theta0,phi0); 472 angleDegres_ = angle; 473 // en radians 474 angle_ = angle*Pi/180.; 347 475 x0_= x0; 348 476 y0_= y0; 349 cos_angle_= cos(angle*Pi/180.); 350 sin_angle_= sin(angle*Pi/180.); 351 originFlag_= true; 352 cout << " LocalMap:: set origin 2 done" << endl; 477 cosAngle_= cos(angle_); 478 sinAngle_= sin(angle_); 353 479 } 354 480 481 template<class T> 482 void LocalMap<T>::SetCoorC(double theta0, double phi0) 483 { 484 485 thetaDegresC_ = theta0; 486 phiDegresC_ = phi0; 487 488 // passage en radians 489 thetaC_= theta0*Pi/180.; 490 phiC_ = phi0*Pi/180.; 491 csthC_ = cos(thetaC_); 492 snthC_ = sin(thetaC_); 493 csphC_ = cos(phiC_); 494 snphC_ = sin(phiC_); 495 XC_ = snthC_*csphC_; 496 YC_ = snthC_*snphC_; 497 ZC_ = csthC_; 498 } 499 500 501 // angles en RADIANS 502 template<class T> 503 TMatrix<double> LocalMap<T>::CalculMatricePassage() 504 { 505 cout << " calcul matrice de passage " << endl; 506 TMatrix<double> passage(3,3); 507 double cos_th_axeZ; 508 double sin_th_axeZ; 509 double cos_phi_axeZ; 510 double sin_phi_axeZ; 511 512 double cth,sth, cdeltaPhi, phi, cphi, sphi; 513 514 if ( snthC_ <= 0.) // carte centree au pole 515 { 516 cos_th_axeZ = 1.; 517 sin_th_axeZ = 0.; 518 cos_phi_axeZ = 1.; 519 sin_phi_axeZ = 0.; 520 521 } 522 else 523 { 524 cth = cosAngle_*snthC_; 525 double arg = 1.-cth*cth; 526 if (arg <= 0. ) // carte centree sur l'equateur, sans rotation 527 { 528 cos_th_axeZ = 1.; 529 sin_th_axeZ = 0.; 530 cos_phi_axeZ = csphC_; 531 sin_phi_axeZ = snphC_; 532 } 533 else 534 { 535 sth = sqrt(arg); 536 cdeltaPhi = -csthC_*cth/(snthC_*sth); 537 if (cdeltaPhi < -1. ) cdeltaPhi = -1.; 538 if (cdeltaPhi > 1. ) cdeltaPhi = 1.; 539 phi = phiC_ + acos( cdeltaPhi ); 540 541 cos_th_axeZ = cth; 542 sin_th_axeZ = sth; 543 cos_phi_axeZ = cos(phi); 544 sin_phi_axeZ = sin(phi); 545 } 546 } 547 passage(0,0) = snthC_*csphC_; 548 passage(1,0) = snthC_*snphC_; 549 passage(2,0) = csthC_; 550 551 passage(0,2) = sin_th_axeZ*cos_phi_axeZ; 552 passage(1,2) = sin_th_axeZ*sin_phi_axeZ; 553 passage(2,2) = cos_th_axeZ; 554 555 passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0); 556 passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0); 557 passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0); 558 559 // passage.Print(cout); 560 // cout << " fin calcul passage " << endl; 561 562 return passage; 563 564 565 } 566 355 567 /*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY) 356 568 … … 360 572 void LocalMap<T>::SetSize(double angleX,double angleY) 361 573 { 362 angleX_= angleX; 363 angleY_= angleY; 364 365 // tangente de la moitie de l'ouverture angulaire totale 366 tgAngleX_= tan(0.5*angleX_*Pi/180.); 367 tgAngleY_= tan(0.5*angleY_*Pi/180.); 368 369 extensFlag_= true; 370 cout << " LocalMap:: set extension done" << endl; 371 } 372 373 /*! \fn void SOPHYA::LocalMap::Project(SphericalMap<T>& sphere) const 574 if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.) 575 { 576 throw "LocalMap::SetSize extension angle out of range"; 577 } 578 579 angleDegresX_ = angleX; 580 angleDegresY_ = angleY; 581 // angles par pixel, en radians 582 cout << " taille x " << nSzX_ <<" taille y " << nSzY_ << endl; 583 deltaPhi_ = angleX*Pi/(180.*nSzX_); 584 deltaTheta_ = angleY*Pi/(180.*nSzY_); 585 586 587 } 588 589 590 591 /*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const 374 592 375 593 Projection to a spherical map 376 594 */ 377 595 template<class T> 378 void LocalMap<T>::Project(SphericalMap<T>& sphere) const 379 { 380 for(int m = 0; m < nPix_; m++) 381 { 382 double theta,phi; 383 PixThetaPhi(m,theta,phi); 384 sphere(theta,phi)= pixels_(m); 385 // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl; 386 } 387 } 596 void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const 597 { 598 double theta, phi; 599 int it, ip; 600 for (it = 0; it < nSzY_; it++) 601 { 602 for (ip = 0; ip < nSzX_; ip++) 603 { 604 PixThetaPhi(ip,it, theta, phi); 605 sphere(theta,phi)= pixels_(it, ip); 606 } 607 } 608 } 609 610 611 388 612 // Titre Private Methods 389 613 //++ … … 391 615 void LocalMap<T>::InitNul() 392 616 // 393 // set someattributes to zero617 // set attributes to zero 394 618 //-- 395 619 { 396 originFlag_= false; 397 extensFlag_= false; 398 cos_angle_= 1.0; 399 sin_angle_= 0.0; 400 // pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$ 620 nSzX_ = 0; 621 nSzY_ = 0; 622 angleDegresX_ = 0.; 623 angleDegresY_ = 0.; 624 thetaDegresC_ = 0.; 625 phiDegresC_ = 0.; 626 x0_ = 0; 627 y0_ = 0; 628 angleDegres_ = 0.; 629 630 631 nPix_ = 0; 632 633 thetaC_ = 0.; 634 phiC_ = 0.; 635 csthC_ = 1.; 636 snthC_ = 0.; 637 csphC_ = 1.; 638 snphC_ = 0.; 639 XC_ = 0.; 640 YC_ = 0.; 641 ZC_ = 1.; 642 643 angle_ = 0.; 644 cosAngle_ = 1.; 645 sinAngle_ = 0.; 646 deltaPhi_ = 0.; 647 deltaTheta_ =0.; 401 648 } 402 649 … … 414 661 } 415 662 416 /*! \fn void SOPHYA::LocalMap::ReferenceToUser(double& theta,double& phi) const 417 418 Transform a pair of coordinates (theta, phi) given in 419 reference coordinates into map coordinates 420 */ 421 template<class T> 422 void LocalMap<T>::ReferenceToUser(double& theta,double& phi) const 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 /*! \fn void SOPHYA::LocalMap::UserToReference(double& theta,double& phi) const 456 457 Transform a pair of coordinates (theta, phi) given in 458 map coordinates into reference coordinates 459 */ 460 template<class T> 461 void LocalMap<T>::UserToReference(double& theta,double& phi) const 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 /*! \fn void SOPHYA::LocalMap::PixProjToAngle(double x,double y,double& theta,double& phi) const 499 500 Given coordinates in pixel units in the REFERENCE PLANE, return 501 (theta, phi) in "absolute" referential theta=pi/2 ,phi=0. 502 */ 503 template<class T> 504 void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const 505 { 506 theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_); 507 phi= atan2(2.*x*tgAngleX_,(double)nSzX_); 508 if(phi < 0.) phi += DeuxPi; 509 } 510 511 /*! \fn void SOPHYA::LocalMap::AngleProjToPix(double theta,double phi,double& x,double& y) const 512 513 Given coordinates (theta, phi) in "absolute" referential 514 theta=pi/2 ,phi=0 return pixel indices (i,j) in the REFERENCE PLANE. 515 */ 516 template<class T> 517 void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const 518 { 519 if(phi >= Pi) phi-= DeuxPi; 520 // y=0.5*mSzY_*cot(theta)/tgAngleY_; $CHECK-REZA-04/99$ 521 y= 0.5*nSzY_/tan(theta)/tgAngleY_; // ? cot = 1/tan ? 522 x= 0.5*nSzX_*tan(phi)/tgAngleX_; 523 } 663 664 665 666 524 667 525 668 template<class T> … … 527 670 { 528 671 os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl; 529 if(LocalMap_isDone()) 530 { 531 os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl; 672 os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl; 532 673 os<<" x0= "<<x0_<<", y0= "<<y0_<<endl; 533 os<<" cos= "<<cos_angle_<<", & sin= "<<sin_angle_<<endl; 534 os<<" angleX= "<<angleX_<<", angleY= "<<angleY_<<endl; 535 os<<" tg(angleX)= "<<tgAngleX_<<", tg(angleY)= "<<tgAngleY_<<endl; 536 } 674 os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl; 675 os<<" deltaPhi_= "<< deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl; 676 os <<endl; 537 677 538 678 os << " contenu de pixels : "; … … 540 680 { 541 681 if(i%5 == 0) os << endl; 542 os << pixels_(i) <<", "; 682 int_4 ik,jk; 683 Getij(i,ik,jk); 684 os << pixels_(jk,ik) <<", "; 543 685 } 544 686 os << endl; … … 549 691 void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm) 550 692 { 551 nSzX_= lm.nSzX_; 552 nSzY_= lm.nSzY_; 553 nPix_= lm.nPix_; 554 originFlag_= lm.originFlag_; 555 extensFlag_= lm.extensFlag_; 556 x0_= lm.x0_; 557 y0_= lm.y0_; 558 theta0_= lm.theta0_; 559 phi0_= lm.phi0_; 693 694 nSzX_ = lm.nSzX_; 695 nSzY_ = lm.nSzY_; 696 nPix_ = lm.nPix_; 697 x0_ = lm.x0_; 698 y0_ = lm.y0_; 699 700 thetaC_ = lm.thetaC_; 701 phiC_ = lm.phiC_; 702 csthC_ = lm.csthC_; 703 snthC_ = lm.snthC_; 704 csphC_ = lm.csphC_; 705 snphC_ = lm.snphC_; 706 XC_ = lm.XC_; 707 YC_ = lm.YC_; 708 ZC_ = lm.ZC_; 709 560 710 angle_= lm.angle_; 561 cos_angle_= lm.cos_angle_; 562 sin_angle_= lm.sin_angle_; 563 angleX_= lm.angleX_; 564 angleY_= lm.angleY_; 565 tgAngleX_= lm.tgAngleX_; 566 tgAngleY_= lm.tgAngleY_; 711 cosAngle_ = lm.cosAngle_; 712 sinAngle_ = lm.sinAngle_; 713 deltaPhi_ = lm. deltaPhi_; 714 deltaTheta_ = lm.deltaTheta_; 567 715 } 568 716 … … 654 802 throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ; 655 803 } 656 pixels_ *= a.pixels_; 804 // pixels_ *= a.pixels_; 805 pixels_.DataBlock() *= a.pixels_.DataBlock(); 657 806 return (*this); 658 807 } … … 666 815 throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ; 667 816 } 668 pixels_ /= a.pixels_; 817 // pixels_ /= a.pixels_; 818 pixels_.DataBlock() /= a.pixels_.DataBlock(); 669 819 return (*this); 670 820 } … … 673 823 674 824 675 676 //++677 // Titre class FIO_LocalMap678 // Delegated objects for persitance management679 //--680 825 681 826
Note:
See TracChangeset
for help on using the changeset viewer.