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