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