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