[228] | 1 | #include "localmap.h"
|
---|
[470] | 2 | #include "nbmath.h"
|
---|
| 3 | #include <complex>
|
---|
| 4 | #include "piocmplx.h"
|
---|
| 5 |
|
---|
| 6 | #include <string.h>
|
---|
[228] | 7 | #include <iostream.h>
|
---|
[470] | 8 |
|
---|
| 9 |
|
---|
[228] | 10 | //*****************************************************************************
|
---|
| 11 | //++
|
---|
| 12 | // Class LocalMap
|
---|
| 13 | //
|
---|
| 14 | // include localmap.h nbmath.h
|
---|
| 15 | //
|
---|
| 16 | // A local map of a region of the sky, in cartesian coordinates.
|
---|
| 17 | // It has an origin in (theta0, phi0), mapped to pixel(x0, y0)
|
---|
| 18 | // (x0, y0 might be outside of this local map)
|
---|
| 19 | // default value of (x0, y0) is middle of the map, center of
|
---|
| 20 | // pixel(nx/2, ny/2)
|
---|
| 21 | //
|
---|
[568] | 22 | // A local map is a 2 dimensional array, with i as column index and j
|
---|
| 23 | // as row index. The map is supposed to lie on a plan tangent to the
|
---|
| 24 | // celestial sphere in a point whose coordinates are (x0,y0) on the local
|
---|
| 25 | // map and (theta0, phi0) on the sphere. The range of the map is defined
|
---|
| 26 | // by two values of angles covered respectively by all the pixels in
|
---|
| 27 | // x direction and all the pixels in y direction (SetSize()).
|
---|
| 28 | //
|
---|
| 29 | // A "reference plane" is considered : this plane is tangent to the
|
---|
| 30 | // celestial sphere in a point with angles theta=Pi/2 and phi=0. This
|
---|
| 31 | // point is the origine of coordinates is of the reference plane. The
|
---|
| 32 | // x-axis is the tangent parallel to the equatorial line and oriented
|
---|
| 33 | // toward the increasing phi's ; the y-axis is parallel to the meridian
|
---|
| 34 | // line and oriented toward the north pole.
|
---|
| 35 | //
|
---|
| 36 | // Internally, a map is first defined within this reference plane and
|
---|
| 37 | // tranported until the point (theta0, phi0) in such a way that both
|
---|
| 38 | // axes are kept parallel to meridian and parallel lines of the sphere.
|
---|
| 39 | // The user can define its own map with axes rotated with respect to
|
---|
| 40 | // reference axes (this rotation is characterized by angle between
|
---|
| 41 | // the local parallel line and the wanted x-axis-- see method
|
---|
| 42 | // SetOrigin(...))
|
---|
| 43 | //
|
---|
| 44 | //
|
---|
[228] | 45 |
|
---|
| 46 | //
|
---|
| 47 | //--
|
---|
| 48 | //++
|
---|
| 49 | //
|
---|
| 50 | // Links Parents
|
---|
| 51 | //
|
---|
| 52 | // PixelMap
|
---|
| 53 | //
|
---|
| 54 | //--
|
---|
| 55 | //++
|
---|
| 56 | //
|
---|
[568] | 57 | // Links Childs
|
---|
[228] | 58 | //
|
---|
| 59 | //
|
---|
| 60 | //--
|
---|
| 61 | //++
|
---|
[568] | 62 | // Titre Constructors
|
---|
[228] | 63 | //--
|
---|
| 64 | //++
|
---|
[470] | 65 | template<class T>
|
---|
| 66 | LocalMap<T>::LocalMap()
|
---|
| 67 | //
|
---|
[568] | 68 | //
|
---|
[228] | 69 | //--
|
---|
[470] | 70 | {
|
---|
| 71 | InitNul();
|
---|
[604] | 72 | pixels_.Reset();
|
---|
[470] | 73 | }
|
---|
[228] | 74 |
|
---|
| 75 | //++
|
---|
[470] | 76 | template<class T>
|
---|
[682] | 77 | LocalMap<T>::LocalMap(int_4 nx, int_4 ny) : nSzX_(nx), nSzY_(ny)
|
---|
[470] | 78 | //
|
---|
[568] | 79 | //
|
---|
[228] | 80 | //--
|
---|
| 81 | {
|
---|
| 82 | InitNul();
|
---|
[470] | 83 | nPix_= nx*ny;
|
---|
| 84 | pixels_.ReSize(nPix_);
|
---|
| 85 | pixels_.Reset();
|
---|
[228] | 86 | }
|
---|
| 87 |
|
---|
| 88 | //++
|
---|
[470] | 89 | template<class T>
|
---|
[574] | 90 | LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
|
---|
| 91 | : pixels_(lm.pixels_, share)
|
---|
| 92 |
|
---|
[470] | 93 | //
|
---|
[568] | 94 | // copy constructor
|
---|
[228] | 95 | //--
|
---|
[470] | 96 | {
|
---|
| 97 | cout<<" LocalMap:: Appel du constructeur de recopie " << endl;
|
---|
| 98 |
|
---|
| 99 | if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
|
---|
| 100 | nSzX_= lm.nSzX_;
|
---|
| 101 | nSzY_= lm.nSzY_;
|
---|
| 102 | nPix_= lm.nPix_;
|
---|
| 103 | originFlag_= lm.originFlag_;
|
---|
| 104 | extensFlag_= lm.extensFlag_;
|
---|
| 105 | x0_= lm.x0_;
|
---|
| 106 | y0_= lm.y0_;
|
---|
| 107 | theta0_= lm.theta0_;
|
---|
| 108 | phi0_= lm.phi0_;
|
---|
| 109 | angle_= lm.angle_;
|
---|
| 110 | cos_angle_= lm.cos_angle_;
|
---|
| 111 | sin_angle_= lm.sin_angle_;
|
---|
| 112 | angleX_= lm.angleX_;
|
---|
| 113 | angleY_= lm.angleY_;
|
---|
| 114 | tgAngleX_= lm.tgAngleX_;
|
---|
| 115 | tgAngleY_= lm.tgAngleY_;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[228] | 118 | //++
|
---|
[568] | 119 | // Titre Destructor
|
---|
| 120 | //--
|
---|
| 121 | //++
|
---|
[470] | 122 | template<class T>
|
---|
| 123 | LocalMap<T>::~LocalMap()
|
---|
| 124 | //
|
---|
[228] | 125 | //--
|
---|
| 126 | {
|
---|
[470] | 127 | InitNul();
|
---|
[228] | 128 | }
|
---|
| 129 |
|
---|
[568] | 130 |
|
---|
| 131 |
|
---|
[470] | 132 | //++
|
---|
[568] | 133 | // Titre Public Methods
|
---|
[470] | 134 | //--
|
---|
[228] | 135 |
|
---|
[470] | 136 | //++
|
---|
| 137 | template<class T>
|
---|
[682] | 138 | void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
|
---|
[470] | 139 | //
|
---|
[568] | 140 | // Resize storage area for pixels
|
---|
[470] | 141 | //--
|
---|
[228] | 142 | {
|
---|
[470] | 143 | InitNul();
|
---|
| 144 | nSzX_ = nx;
|
---|
| 145 | nSzY_ = ny;
|
---|
| 146 | nPix_= nx*ny;
|
---|
| 147 | pixels_.ReSize(nPix_);
|
---|
| 148 | pixels_.Reset();
|
---|
[228] | 149 | }
|
---|
| 150 |
|
---|
| 151 | //++
|
---|
[470] | 152 | template<class T>
|
---|
[682] | 153 | int_4 LocalMap<T>::NbPixels() const
|
---|
[470] | 154 | //
|
---|
[568] | 155 | // Return number of pixels
|
---|
[228] | 156 | //--
|
---|
| 157 | {
|
---|
[470] | 158 | return(nPix_);
|
---|
[228] | 159 | }
|
---|
| 160 |
|
---|
| 161 | //++
|
---|
[470] | 162 | template<class T>
|
---|
[682] | 163 | T& LocalMap<T>::PixVal(int_4 k)
|
---|
[470] | 164 | //
|
---|
[568] | 165 | // Return value of pixel with index k
|
---|
[228] | 166 | //--
|
---|
| 167 | {
|
---|
[470] | 168 | if((k < 0) || (k >= nPix_))
|
---|
| 169 | {
|
---|
| 170 | cout << " LocalMap::PIxVal : exceptions a mettre en place" <<endl;
|
---|
| 171 | // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
|
---|
| 172 | THROW(rangeCheckErr);
|
---|
| 173 | //throw "LocalMap::PIxVal Pixel index out of range";
|
---|
| 174 | }
|
---|
| 175 | return(pixels_(k));
|
---|
[228] | 176 | }
|
---|
| 177 |
|
---|
| 178 | //++
|
---|
| 179 |
|
---|
[470] | 180 | template<class T>
|
---|
[682] | 181 | T const& LocalMap<T>::PixVal(int_4 k) const
|
---|
[470] | 182 | //
|
---|
[568] | 183 | // const version of previous method
|
---|
[228] | 184 | //--
|
---|
| 185 | {
|
---|
[470] | 186 | if((k < 0) || (k >= nPix_))
|
---|
| 187 | {
|
---|
| 188 | cout << " LocalMap::PIxVal : exceptions a mettre en place" <<endl;
|
---|
| 189 | // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
|
---|
| 190 |
|
---|
| 191 | throw "LocalMap::PIxVal Pixel index out of range";
|
---|
| 192 | }
|
---|
| 193 | return *(pixels_.Data()+k);
|
---|
[228] | 194 | }
|
---|
| 195 |
|
---|
[574] | 196 | template<class T>
|
---|
| 197 | bool LocalMap<T>::ContainsSph(double theta, double phi) const
|
---|
| 198 | {
|
---|
| 199 | // $CHECK$ Reza 11/11/99 - A modifier
|
---|
| 200 | return(true);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[228] | 203 | //++
|
---|
[470] | 204 | template<class T>
|
---|
[682] | 205 | int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
|
---|
[470] | 206 | //
|
---|
[568] | 207 | // Return index of the pixel with spherical coordinates (theta,phi)
|
---|
[228] | 208 | //--
|
---|
| 209 | {
|
---|
[682] | 210 | int_4 i,j;
|
---|
[470] | 211 | if(!(originFlag_) || !(extensFlag_))
|
---|
| 212 | {
|
---|
| 213 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
|
---|
| 214 | exit(0);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference)
|
---|
[473] | 218 | double theta_aux= theta;
|
---|
| 219 | double phi_aux = phi;
|
---|
[228] | 220 | UserToReference(theta_aux, phi_aux);
|
---|
[470] | 221 |
|
---|
[228] | 222 | // coordonnees dans le plan local en unites de pixels
|
---|
[473] | 223 | double x,y;
|
---|
| 224 | AngleProjToPix(theta_aux,phi_aux, x, y);
|
---|
[228] | 225 |
|
---|
[473] | 226 | double xmin= -x0_-0.5;
|
---|
| 227 | double xmax= xmin+nSzX_;
|
---|
| 228 | if((x > xmax) || (x < xmin)) return(-1);
|
---|
| 229 | double xcurrent= xmin;
|
---|
[470] | 230 | for(i = 0; i < nSzX_; i++ )
|
---|
| 231 | {
|
---|
| 232 | xcurrent += 1.;
|
---|
| 233 | if( x < xcurrent ) break;
|
---|
| 234 | }
|
---|
[473] | 235 | double ymin= -y0_-0.5;
|
---|
| 236 | double ymax= ymin+nSzY_;
|
---|
[470] | 237 | if((y > ymax) || (y < ymin)) return(-1);
|
---|
[473] | 238 | double ycurrent= ymin;
|
---|
[470] | 239 | for(j = 0; j < nSzY_; j++ )
|
---|
| 240 | {
|
---|
| 241 | ycurrent += 1.;
|
---|
| 242 | if( y < ycurrent ) break;
|
---|
| 243 | }
|
---|
| 244 | return (j*nSzX_+i);
|
---|
[228] | 245 | }
|
---|
| 246 |
|
---|
| 247 | //++
|
---|
[470] | 248 | template<class T>
|
---|
[682] | 249 | void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
|
---|
[470] | 250 | //
|
---|
[568] | 251 | // Return (theta, phi) coordinates of pixel with index k
|
---|
[228] | 252 | //--
|
---|
| 253 | {
|
---|
[470] | 254 | if(!(originFlag_) || !(extensFlag_))
|
---|
| 255 | {
|
---|
| 256 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl;
|
---|
| 257 | exit(0);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[682] | 260 | int_4 i,j;
|
---|
[228] | 261 | Getij(k,i,j);
|
---|
[470] | 262 |
|
---|
[473] | 263 | double X= double(i-x0_);
|
---|
| 264 | double Y= double(j-y0_);
|
---|
[228] | 265 | // situation de ce pixel dans le plan de reference
|
---|
[473] | 266 | double x= X*cos_angle_-Y*sin_angle_;
|
---|
| 267 | double y= X*sin_angle_+Y* cos_angle_;
|
---|
[228] | 268 | // projection sur la sphere
|
---|
[470] | 269 | PixProjToAngle(x, y, theta, phi);
|
---|
[228] | 270 | // retour au plan utilisateur
|
---|
| 271 | ReferenceToUser(theta, phi);
|
---|
| 272 | }
|
---|
[574] | 273 |
|
---|
| 274 | template <class T>
|
---|
| 275 | T LocalMap<T>::SetPixels(T v)
|
---|
| 276 | {
|
---|
| 277 | pixels_.Reset(v);
|
---|
| 278 | return(v);
|
---|
| 279 | }
|
---|
[228] | 280 |
|
---|
| 281 | //++
|
---|
[470] | 282 | template<class T>
|
---|
[682] | 283 | double LocalMap<T>::PixSolAngle(int_4 k) const
|
---|
[470] | 284 | //
|
---|
[568] | 285 | // Pixel Solid angle (steradians)
|
---|
| 286 | // All the pixels have not necessarly the same size in (theta, phi)
|
---|
| 287 | // because of the projection scheme which is not yet fixed.
|
---|
[228] | 288 | //--
|
---|
| 289 | {
|
---|
[682] | 290 | int_4 i,j;
|
---|
[228] | 291 | Getij(k,i,j);
|
---|
[473] | 292 | double X= double(i-x0_);
|
---|
| 293 | double Y= double(j-y0_);
|
---|
| 294 | double XR= X+double(i)*0.5;
|
---|
| 295 | double XL= X-double(i)*0.5;
|
---|
| 296 | double YU= Y+double(j)*0.5;
|
---|
| 297 | double YL= Y-double(j)*0.5;
|
---|
| 298 |
|
---|
[228] | 299 | // situation dans le plan de reference
|
---|
[473] | 300 | double x0= XL*cos_angle_-YL*sin_angle_;
|
---|
| 301 | double y0= XL*sin_angle_+YL*cos_angle_;
|
---|
| 302 | double xa= XR*cos_angle_-YL*sin_angle_;
|
---|
| 303 | double ya= XR*sin_angle_+YL*cos_angle_;
|
---|
| 304 | double xb= XL*cos_angle_-YU*sin_angle_;
|
---|
| 305 | double yb= XL*sin_angle_+YU*cos_angle_;
|
---|
| 306 |
|
---|
[228] | 307 | // projection sur la sphere
|
---|
[473] | 308 | double thet0,phi0,theta,phia,thetb,phib;
|
---|
| 309 | PixProjToAngle(x0, y0, thet0, phi0);
|
---|
| 310 | PixProjToAngle(xa, ya, theta, phia);
|
---|
| 311 | PixProjToAngle(xb, yb, thetb, phib);
|
---|
| 312 |
|
---|
[228] | 313 | // angle solide
|
---|
[473] | 314 | double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0));
|
---|
| 315 | return sol;
|
---|
[228] | 316 | }
|
---|
| 317 |
|
---|
| 318 | //++
|
---|
[470] | 319 | template<class T>
|
---|
[473] | 320 | void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
|
---|
[470] | 321 | //
|
---|
[568] | 322 | // set the referential of the map (angles in degrees)
|
---|
| 323 | // (default x0=siz_x/2, y0=siz_y/2)
|
---|
[228] | 324 | //--
|
---|
| 325 | {
|
---|
[473] | 326 | theta0_= theta0;
|
---|
| 327 | phi0_ = phi0;
|
---|
| 328 | angle_ = angle;
|
---|
[470] | 329 | x0_= nSzX_/2;
|
---|
| 330 | y0_= nSzY_/2;
|
---|
[473] | 331 | cos_angle_= cos(angle*Pi/180.);
|
---|
| 332 | sin_angle_= sin(angle*Pi/180.);
|
---|
[470] | 333 | originFlag_= true;
|
---|
| 334 | cout << " LocalMap:: set origin 1 done" << endl;
|
---|
[228] | 335 | }
|
---|
| 336 |
|
---|
| 337 | //++
|
---|
[470] | 338 | template<class T>
|
---|
[682] | 339 | void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
|
---|
[470] | 340 | //
|
---|
[568] | 341 | // set the referential of the map (angles in degrees)
|
---|
[228] | 342 | //--
|
---|
| 343 | {
|
---|
[473] | 344 | theta0_= theta0;
|
---|
| 345 | phi0_ = phi0;
|
---|
| 346 | angle_ = angle;
|
---|
[470] | 347 | x0_= x0;
|
---|
| 348 | y0_= y0;
|
---|
[473] | 349 | cos_angle_= cos(angle*Pi/180.);
|
---|
| 350 | sin_angle_= sin(angle*Pi/180.);
|
---|
[470] | 351 | originFlag_= true;
|
---|
| 352 | cout << " LocalMap:: set origin 2 done" << endl;
|
---|
[228] | 353 | }
|
---|
| 354 |
|
---|
| 355 | //++
|
---|
[470] | 356 | template<class T>
|
---|
[473] | 357 | void LocalMap<T>::SetSize(double angleX,double angleY)
|
---|
[470] | 358 | //
|
---|
[568] | 359 | // angle range of tthe map (angles in degrees)
|
---|
[470] | 360 | //--
|
---|
| 361 | {
|
---|
[473] | 362 | angleX_= angleX;
|
---|
| 363 | angleY_= angleY;
|
---|
[228] | 364 |
|
---|
[470] | 365 | // tangente de la moitie de l'ouverture angulaire totale
|
---|
[473] | 366 | tgAngleX_= tan(0.5*angleX_*Pi/180.);
|
---|
| 367 | tgAngleY_= tan(0.5*angleY_*Pi/180.);
|
---|
[470] | 368 |
|
---|
| 369 | extensFlag_= true;
|
---|
| 370 | cout << " LocalMap:: set extension done" << endl;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | //++
|
---|
| 374 | template<class T>
|
---|
| 375 | void LocalMap<T>::Project(SphericalMap<T>& sphere) const
|
---|
| 376 | //
|
---|
[568] | 377 | // Projection to a spherical map
|
---|
[228] | 378 | //--
|
---|
| 379 | {
|
---|
[470] | 380 | for(int m = 0; m < nPix_; m++)
|
---|
| 381 | {
|
---|
[473] | 382 | double theta,phi;
|
---|
[470] | 383 | PixThetaPhi(m,theta,phi);
|
---|
| 384 | sphere(theta,phi)= pixels_(m);
|
---|
| 385 | // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl;
|
---|
| 386 | }
|
---|
[228] | 387 | }
|
---|
[568] | 388 | // Titre Private Methods
|
---|
| 389 | //++
|
---|
| 390 | template<class T>
|
---|
| 391 | void LocalMap<T>::InitNul()
|
---|
| 392 | //
|
---|
| 393 | // set some attributes to zero
|
---|
| 394 | //--
|
---|
| 395 | {
|
---|
| 396 | originFlag_= false;
|
---|
| 397 | extensFlag_= false;
|
---|
| 398 | cos_angle_= 1.0;
|
---|
| 399 | sin_angle_= 0.0;
|
---|
[604] | 400 | // pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$
|
---|
[568] | 401 | }
|
---|
[470] | 402 |
|
---|
[228] | 403 | //++
|
---|
[470] | 404 | template<class T>
|
---|
[682] | 405 | void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
|
---|
[470] | 406 | //
|
---|
[568] | 407 | // Return 2 indices corresponding to the pixel number k
|
---|
[228] | 408 | //--
|
---|
| 409 | {
|
---|
[470] | 410 | i= (k+1)%nSzX_-1;
|
---|
| 411 | if(i == -1) i= nSzX_-1;
|
---|
| 412 | j= (k-i+2)/nSzX_;
|
---|
[228] | 413 | }
|
---|
| 414 |
|
---|
[470] | 415 | //++
|
---|
| 416 | template<class T>
|
---|
[473] | 417 | void LocalMap<T>::ReferenceToUser(double& theta,double& phi) const
|
---|
[228] | 418 | //
|
---|
[568] | 419 | // Transform a pair of coordinates (theta, phi) given in
|
---|
| 420 | // reference coordinates into map coordinates
|
---|
| 421 | //--
|
---|
[470] | 422 | {
|
---|
[473] | 423 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
|
---|
[470] | 424 | {
|
---|
| 425 | throw "LocalMap::ReferenceToUser (theta,phi) out of range";
|
---|
| 426 | }
|
---|
| 427 |
|
---|
[473] | 428 | theta= theta0_*Pi/180.+theta-Pi*0.5;
|
---|
[470] | 429 | if(theta < 0.)
|
---|
| 430 | {
|
---|
| 431 | theta= -theta;
|
---|
[473] | 432 | phi += Pi;
|
---|
[470] | 433 | }
|
---|
| 434 | else
|
---|
| 435 | {
|
---|
[473] | 436 | if(theta > Pi)
|
---|
[470] | 437 | {
|
---|
[473] | 438 | theta= 2.*Pi-theta;
|
---|
| 439 | phi += Pi;
|
---|
[470] | 440 | }
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[473] | 443 | phi= phi0_*Pi/180.+phi;
|
---|
| 444 | while(phi >= 2.*Pi) phi-= 2.*Pi;
|
---|
[470] | 445 |
|
---|
[473] | 446 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
|
---|
[470] | 447 | {
|
---|
| 448 | cout << " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl;
|
---|
| 449 | cout << " theta= " << theta << " phi= " << phi << endl;
|
---|
| 450 | exit(0);
|
---|
| 451 | }
|
---|
[228] | 452 | }
|
---|
| 453 |
|
---|
[470] | 454 | //++
|
---|
| 455 | template<class T>
|
---|
[473] | 456 | void LocalMap<T>::UserToReference(double& theta,double& phi) const
|
---|
[228] | 457 | //
|
---|
[568] | 458 | // Transform a pair of coordinates (theta, phi) given in
|
---|
| 459 | // map coordinates into reference coordinates
|
---|
| 460 | //--
|
---|
[470] | 461 | {
|
---|
[473] | 462 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
|
---|
[470] | 463 | {
|
---|
[473] | 464 | cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl;
|
---|
| 465 | // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range"));
|
---|
[470] | 466 | throw "LocalMap::UserToReference (theta,phi) out of range";
|
---|
| 467 | }
|
---|
| 468 |
|
---|
[473] | 469 | double phi1= phi-phi0_*Pi/180.;
|
---|
| 470 | if(phi1 < 0.) phi1+= 2.*Pi;
|
---|
[470] | 471 |
|
---|
[473] | 472 | double theta1= theta-theta0_*Pi/180.+Pi*0.5;
|
---|
[470] | 473 | if(theta1 < 0.)
|
---|
| 474 | {
|
---|
| 475 | theta= -theta1;
|
---|
[473] | 476 | phi1+= Pi;
|
---|
[470] | 477 | }
|
---|
| 478 | else
|
---|
| 479 | {
|
---|
[473] | 480 | if(theta1 > Pi)
|
---|
[470] | 481 | {
|
---|
[473] | 482 | theta= 2.*Pi-theta1;
|
---|
| 483 | phi1+= Pi;
|
---|
[470] | 484 | }
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[473] | 487 | while(phi1 >= 2.*Pi) phi1-= 2.*Pi;
|
---|
[470] | 488 | phi= phi1;
|
---|
[473] | 489 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi)
|
---|
[470] | 490 | {
|
---|
| 491 | cout << " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl;
|
---|
| 492 | cout << " theta= " << theta << " phi= " << phi << endl;
|
---|
| 493 | exit(0);
|
---|
| 494 | }
|
---|
[228] | 495 | }
|
---|
| 496 |
|
---|
[470] | 497 | //++
|
---|
| 498 | template<class T>
|
---|
[473] | 499 | void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const
|
---|
[470] | 500 | //
|
---|
[568] | 501 | //
|
---|
| 502 | // Given coordinates in pixel units in the REFERENCE PLANE, return
|
---|
| 503 | // (theta, phi) in "absolute" referential theta=pi/2 ,phi=0.
|
---|
[470] | 504 | //--
|
---|
[228] | 505 | {
|
---|
[473] | 506 | theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_);
|
---|
| 507 | phi= atan2(2.*x*tgAngleX_,(double)nSzX_);
|
---|
[470] | 508 | if(phi < 0.) phi += DeuxPi;
|
---|
[228] | 509 | }
|
---|
| 510 |
|
---|
[470] | 511 | //++
|
---|
| 512 | template<class T>
|
---|
[473] | 513 | void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const
|
---|
[470] | 514 | //
|
---|
[568] | 515 | // Given coordinates (theta, phi) in "absolute" referential
|
---|
| 516 | // theta=pi/2 ,phi=0 return pixel indices (i,j) in the REFERENCE PLANE.
|
---|
[470] | 517 | //--
|
---|
| 518 | {
|
---|
[473] | 519 | if(phi >= Pi) phi-= DeuxPi;
|
---|
[470] | 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 | }
|
---|
[228] | 524 |
|
---|
[470] | 525 | template<class T>
|
---|
| 526 | void LocalMap<T>::print(ostream& os) const
|
---|
[228] | 527 | {
|
---|
[470] | 528 | os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
|
---|
| 529 | if(LocalMap_isDone())
|
---|
| 530 | {
|
---|
| 531 | os<<" theta0= "<<theta0_<<", phi0= "<<phi0_<<", angle= "<<angle_<<endl;
|
---|
| 532 | 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 | }
|
---|
[228] | 537 |
|
---|
[470] | 538 | os << " contenu de pixels : ";
|
---|
| 539 | for(int i=0; i < nPix_; i++)
|
---|
| 540 | {
|
---|
| 541 | if(i%5 == 0) os << endl;
|
---|
| 542 | os << pixels_(i) <<", ";
|
---|
| 543 | }
|
---|
| 544 | os << endl;
|
---|
[228] | 545 | }
|
---|
[568] | 546 | //++
|
---|
| 547 | // Titre class FIO_LocalMap
|
---|
| 548 | // Delegated objects for persitance management
|
---|
| 549 | //--
|
---|
[228] | 550 |
|
---|
[470] | 551 | //*******************************************************************
|
---|
| 552 | // class FIO_LocalMap<T>
|
---|
| 553 | // Les objets delegues pour la gestion de persistance
|
---|
| 554 | //*******************************************************************
|
---|
[228] | 555 |
|
---|
[568] | 556 | //++
|
---|
[470] | 557 | template <class T>
|
---|
| 558 | FIO_LocalMap<T>::FIO_LocalMap()
|
---|
[568] | 559 | //
|
---|
| 560 | //--
|
---|
[228] | 561 | {
|
---|
[470] | 562 | dobj= new LocalMap<T>;
|
---|
| 563 | ownobj= true;
|
---|
| 564 | }
|
---|
[568] | 565 | //++
|
---|
[470] | 566 | template <class T>
|
---|
| 567 | FIO_LocalMap<T>::FIO_LocalMap(string const& filename)
|
---|
[568] | 568 | //
|
---|
| 569 | //--
|
---|
[470] | 570 | {
|
---|
| 571 | dobj= new LocalMap<T>;
|
---|
[604] | 572 | dobj->DataBlock().SetTemp(true);
|
---|
[470] | 573 | ownobj= true;
|
---|
| 574 | Read(filename);
|
---|
| 575 | }
|
---|
[228] | 576 |
|
---|
[568] | 577 | //++
|
---|
[470] | 578 | template <class T>
|
---|
| 579 | FIO_LocalMap<T>::FIO_LocalMap(const LocalMap<T>& obj)
|
---|
[568] | 580 | //
|
---|
| 581 | //--
|
---|
[470] | 582 | {
|
---|
[574] | 583 | dobj= new LocalMap<T>(obj, true);
|
---|
[604] | 584 | dobj->DataBlock().SetTemp(true);
|
---|
[470] | 585 | ownobj= true;
|
---|
[228] | 586 | }
|
---|
| 587 |
|
---|
[470] | 588 | template <class T>
|
---|
| 589 | FIO_LocalMap<T>::FIO_LocalMap(LocalMap<T>* obj)
|
---|
| 590 | {
|
---|
| 591 | dobj= obj;
|
---|
| 592 | ownobj= false;
|
---|
| 593 | }
|
---|
[228] | 594 |
|
---|
[568] | 595 | //++
|
---|
[470] | 596 | template <class T>
|
---|
| 597 | FIO_LocalMap<T>::~FIO_LocalMap()
|
---|
[568] | 598 | //
|
---|
| 599 | //--
|
---|
[470] | 600 | {
|
---|
| 601 | if (ownobj && dobj) delete dobj;
|
---|
| 602 | }
|
---|
[568] | 603 | //++
|
---|
[470] | 604 | template <class T>
|
---|
| 605 | AnyDataObj* FIO_LocalMap<T>::DataObj()
|
---|
[568] | 606 | //
|
---|
| 607 | //--
|
---|
[470] | 608 | {
|
---|
| 609 | return(dobj);
|
---|
[228] | 610 | }
|
---|
| 611 |
|
---|
[568] | 612 | //++
|
---|
[470] | 613 | template <class T>
|
---|
| 614 | void FIO_LocalMap<T>::ReadSelf(PInPersist& is)
|
---|
[568] | 615 | //
|
---|
| 616 | //--
|
---|
[470] | 617 | {
|
---|
[228] | 618 |
|
---|
[470] | 619 | if(dobj == NULL)
|
---|
| 620 | {
|
---|
| 621 | dobj= new LocalMap<T>;
|
---|
[604] | 622 | dobj->DataBlock().SetTemp(true);
|
---|
| 623 | ownobj= true;
|
---|
[470] | 624 | }
|
---|
| 625 |
|
---|
| 626 | // Pour savoir s'il y avait un DVList Info associe
|
---|
| 627 | char strg[256];
|
---|
| 628 | is.GetLine(strg, 255);
|
---|
| 629 | bool hadinfo= false;
|
---|
| 630 | if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
|
---|
| 631 | if(hadinfo)
|
---|
| 632 | { // Lecture eventuelle du DVList Info
|
---|
| 633 | is >> dobj->Info();
|
---|
| 634 | }
|
---|
| 635 |
|
---|
[682] | 636 | int_4 nSzX;
|
---|
[470] | 637 | is.GetI4(nSzX);
|
---|
| 638 | dobj->setSize_x(nSzX);
|
---|
| 639 |
|
---|
[682] | 640 | int_4 nSzY;
|
---|
[470] | 641 | is.GetI4(nSzY);
|
---|
| 642 | dobj->setSize_y(nSzY);
|
---|
| 643 |
|
---|
[682] | 644 | int_4 nPix;
|
---|
[470] | 645 | is.GetI4(nPix);
|
---|
| 646 | dobj->setNbPixels(nPix);
|
---|
| 647 |
|
---|
| 648 | string ss("local mapping is done");
|
---|
| 649 | string sso;
|
---|
| 650 | is.GetStr(sso);
|
---|
| 651 | if(sso == ss)
|
---|
| 652 | {
|
---|
| 653 | cout<<" ReadSelf:: local mapping"<<endl;
|
---|
[682] | 654 | int_4 x0, y0;
|
---|
[473] | 655 | double theta, phi, angle;
|
---|
[470] | 656 | is.GetI4(x0);
|
---|
| 657 | is.GetI4(y0);
|
---|
[473] | 658 | is.GetR8(theta);
|
---|
| 659 | is.GetR8(phi);
|
---|
| 660 | is.GetR8(angle);
|
---|
[470] | 661 | dobj->SetOrigin(theta, phi, x0, y0, angle);
|
---|
| 662 |
|
---|
[473] | 663 | double angleX, angleY;
|
---|
| 664 | is.GetR8(angleX);
|
---|
| 665 | is.GetR8(angleY);
|
---|
[470] | 666 | dobj->SetSize(angleX, angleY);
|
---|
| 667 | }
|
---|
| 668 |
|
---|
[604] | 669 | // On lit le DataBlock;
|
---|
| 670 | is >> dobj->DataBlock();
|
---|
[228] | 671 | }
|
---|
| 672 |
|
---|
[568] | 673 | //++
|
---|
[470] | 674 | template <class T>
|
---|
| 675 | void FIO_LocalMap<T>::WriteSelf(POutPersist& os) const
|
---|
[568] | 676 | //
|
---|
| 677 | //--
|
---|
[470] | 678 | {
|
---|
| 679 | if(dobj == NULL)
|
---|
| 680 | {
|
---|
[568] | 681 | cout << " FIO_LocalMap::WriteSelf:: dobj= null " << endl;
|
---|
[470] | 682 | return;
|
---|
| 683 | }
|
---|
[228] | 684 |
|
---|
[470] | 685 | char strg[256];
|
---|
[682] | 686 | int_4 nSzX= dobj->Size_x();
|
---|
| 687 | int_4 nSzY= dobj->Size_y();
|
---|
| 688 | int_4 nPix= dobj->NbPixels();
|
---|
[470] | 689 |
|
---|
| 690 | if(dobj->ptrInfo())
|
---|
| 691 | {
|
---|
| 692 | sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d HasInfo",nSzX,nSzY);
|
---|
| 693 | os.PutLine(strg);
|
---|
| 694 | os << dobj->Info();
|
---|
| 695 | }
|
---|
| 696 | else
|
---|
| 697 | {
|
---|
| 698 | sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d ",nSzX,nSzY);
|
---|
| 699 | os.PutLine(strg);
|
---|
| 700 | }
|
---|
[228] | 701 |
|
---|
[470] | 702 | os.PutI4(nSzX);
|
---|
| 703 | os.PutI4(nSzY);
|
---|
| 704 | os.PutI4(nPix);
|
---|
[228] | 705 |
|
---|
[470] | 706 | if(dobj->LocalMap_isDone())
|
---|
| 707 | {
|
---|
| 708 | string ss("local mapping is done");
|
---|
| 709 | os.PutStr(ss);
|
---|
[682] | 710 | int_4 x0, y0;
|
---|
[473] | 711 | double theta, phi, angle;
|
---|
[470] | 712 | dobj->Origin(theta, phi, x0, y0, angle);
|
---|
| 713 | os.PutI4(x0);
|
---|
| 714 | os.PutI4(y0);
|
---|
[473] | 715 | os.PutR8(theta);
|
---|
| 716 | os.PutR8(phi);
|
---|
| 717 | os.PutR8(angle);
|
---|
[470] | 718 |
|
---|
[473] | 719 | double angleX, angleY;
|
---|
[470] | 720 | dobj->Aperture(angleX, angleY);
|
---|
[473] | 721 | os.PutR8(angleX);
|
---|
| 722 | os.PutR8(angleY);
|
---|
[470] | 723 | }
|
---|
| 724 | else
|
---|
| 725 | {
|
---|
| 726 | string ss("no local mapping");
|
---|
| 727 | os.PutStr(ss);
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[604] | 730 | // On ecrit le dataBlock
|
---|
| 731 | os << dobj->DataBlock();
|
---|
[470] | 732 | }
|
---|
| 733 |
|
---|
[682] | 734 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 735 | #pragma define_template LocalMap<double>
|
---|
| 736 | #pragma define_template LocalMap<float>
|
---|
| 737 | #pragma define_template LocalMap< complex<double> >
|
---|
| 738 | #pragma define_template LocalMap< complex<float> >
|
---|
| 739 | #pragma define_template FIO_LocalMap<double>
|
---|
| 740 | #pragma define_template FIO_LocalMap<float>
|
---|
| 741 | #pragma define_template FIO_LocalMap< complex<float> >
|
---|
| 742 | #pragma define_template FIO_LocalMap< complex<double> >
|
---|
| 743 | #endif
|
---|
| 744 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 745 | template class LocalMap<double>;
|
---|
| 746 | template class LocalMap<float>;
|
---|
| 747 | template class LocalMap< complex<double> >;
|
---|
| 748 | template class LocalMap< complex<float> >;
|
---|
| 749 | template class FIO_LocalMap<double>;
|
---|
| 750 | template class FIO_LocalMap<float>;
|
---|
| 751 | template class FIO_LocalMap< complex<float> >;
|
---|
| 752 | template class FIO_LocalMap< complex<double> >;
|
---|
| 753 | #endif
|
---|