| [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 | \return true if teta,phi in map | 
|---|
| [1431] | 187 | <b> Not yet implemented </b> | 
|---|
| [1217] | 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 | 
|---|
| [1431] | 193 | throw NotAvailableOperation("LocalMap<T>::ContainsSph() - Not yet implemented !"); | 
|---|
|  | 194 | return(true); | 
|---|
| [764] | 195 | } | 
|---|
|  | 196 |  | 
|---|
| [1217] | 197 | /*!  \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const | 
|---|
|  | 198 |  | 
|---|
|  | 199 | \return index of the pixel with spherical coordinates (theta,phi) | 
|---|
|  | 200 | */ | 
|---|
| [764] | 201 | template<class T> | 
|---|
|  | 202 | int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const | 
|---|
|  | 203 | { | 
|---|
|  | 204 | int_4 i,j; | 
|---|
|  | 205 | if(!(originFlag_) || !(extensFlag_)) | 
|---|
|  | 206 | { | 
|---|
|  | 207 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl; | 
|---|
|  | 208 | exit(0); | 
|---|
|  | 209 | } | 
|---|
|  | 210 |  | 
|---|
|  | 211 | // theta et phi en coordonnees relatives (on se ramene a une situation par rapport au plan de reference) | 
|---|
|  | 212 | double theta_aux= theta; | 
|---|
|  | 213 | double phi_aux  = phi; | 
|---|
|  | 214 | UserToReference(theta_aux, phi_aux); | 
|---|
|  | 215 |  | 
|---|
|  | 216 | // coordonnees dans le plan local en unites de pixels | 
|---|
|  | 217 | double x,y; | 
|---|
|  | 218 | AngleProjToPix(theta_aux,phi_aux, x, y); | 
|---|
|  | 219 |  | 
|---|
|  | 220 | double xmin= -x0_-0.5; | 
|---|
|  | 221 | double xmax= xmin+nSzX_; | 
|---|
|  | 222 | if((x > xmax) || (x < xmin)) return(-1); | 
|---|
|  | 223 | double xcurrent= xmin; | 
|---|
|  | 224 | for(i = 0; i < nSzX_; i++ ) | 
|---|
|  | 225 | { | 
|---|
|  | 226 | xcurrent += 1.; | 
|---|
|  | 227 | if( x < xcurrent ) break; | 
|---|
|  | 228 | } | 
|---|
|  | 229 | double ymin= -y0_-0.5; | 
|---|
|  | 230 | double ymax= ymin+nSzY_; | 
|---|
|  | 231 | if((y >  ymax) || (y < ymin)) return(-1); | 
|---|
|  | 232 | double ycurrent= ymin; | 
|---|
|  | 233 | for(j = 0; j < nSzY_; j++ ) | 
|---|
|  | 234 | { | 
|---|
|  | 235 | ycurrent += 1.; | 
|---|
|  | 236 | if( y < ycurrent ) break; | 
|---|
|  | 237 | } | 
|---|
|  | 238 | return (j*nSzX_+i); | 
|---|
|  | 239 | } | 
|---|
|  | 240 |  | 
|---|
| [1217] | 241 | /*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 k,double& theta,double& phi) const | 
|---|
|  | 242 |  | 
|---|
|  | 243 | \return (theta, phi) coordinates of pixel with index k | 
|---|
|  | 244 | */ | 
|---|
| [764] | 245 | template<class T> | 
|---|
|  | 246 | void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const | 
|---|
|  | 247 | { | 
|---|
|  | 248 | if(!(originFlag_) || !(extensFlag_)) | 
|---|
|  | 249 | { | 
|---|
|  | 250 | cout << " LocalMap: correspondance carte-sphere non etablie" << endl; | 
|---|
|  | 251 | exit(0); | 
|---|
|  | 252 | } | 
|---|
|  | 253 |  | 
|---|
|  | 254 | int_4 i,j; | 
|---|
|  | 255 | Getij(k,i,j); | 
|---|
|  | 256 |  | 
|---|
|  | 257 | double X= double(i-x0_); | 
|---|
|  | 258 | double Y= double(j-y0_); | 
|---|
|  | 259 | // situation de ce pixel dans le plan de reference | 
|---|
|  | 260 | double x= X*cos_angle_-Y*sin_angle_; | 
|---|
|  | 261 | double y= X*sin_angle_+Y* cos_angle_; | 
|---|
|  | 262 | // projection sur la sphere | 
|---|
|  | 263 | PixProjToAngle(x, y, theta, phi); | 
|---|
|  | 264 | // retour au plan utilisateur | 
|---|
|  | 265 | ReferenceToUser(theta, phi); | 
|---|
|  | 266 | } | 
|---|
|  | 267 |  | 
|---|
| [1217] | 268 | /*! \fn T SOPHYA::LocalMap::SetPixels(T v) | 
|---|
|  | 269 |  | 
|---|
|  | 270 | Set all pixels to value v | 
|---|
|  | 271 | */ | 
|---|
| [764] | 272 | template <class T> | 
|---|
|  | 273 | T LocalMap<T>::SetPixels(T v) | 
|---|
|  | 274 | { | 
|---|
|  | 275 | pixels_.Reset(v); | 
|---|
|  | 276 | return(v); | 
|---|
|  | 277 | } | 
|---|
|  | 278 |  | 
|---|
| [1217] | 279 | /*! \fn double SOPHYA::LocalMap::PixSolAngle(int_4 k) const | 
|---|
|  | 280 |  | 
|---|
|  | 281 | Pixel Solid angle  (steradians) | 
|---|
|  | 282 |  | 
|---|
|  | 283 | All the pixels have not necessarly the same size in (theta, phi) | 
|---|
|  | 284 | because of the projection scheme which is not yet fixed. | 
|---|
|  | 285 | */ | 
|---|
| [764] | 286 | template<class T> | 
|---|
|  | 287 | double LocalMap<T>::PixSolAngle(int_4 k) const | 
|---|
|  | 288 | { | 
|---|
|  | 289 | int_4 i,j; | 
|---|
|  | 290 | Getij(k,i,j); | 
|---|
|  | 291 | double X= double(i-x0_); | 
|---|
|  | 292 | double Y= double(j-y0_); | 
|---|
|  | 293 | double XR= X+double(i)*0.5; | 
|---|
|  | 294 | double XL= X-double(i)*0.5; | 
|---|
|  | 295 | double YU= Y+double(j)*0.5; | 
|---|
|  | 296 | double YL= Y-double(j)*0.5; | 
|---|
|  | 297 |  | 
|---|
|  | 298 | // situation  dans le plan de reference | 
|---|
|  | 299 | double x0= XL*cos_angle_-YL*sin_angle_; | 
|---|
|  | 300 | double y0= XL*sin_angle_+YL*cos_angle_; | 
|---|
|  | 301 | double xa= XR*cos_angle_-YL*sin_angle_; | 
|---|
|  | 302 | double ya= XR*sin_angle_+YL*cos_angle_; | 
|---|
|  | 303 | double xb= XL*cos_angle_-YU*sin_angle_; | 
|---|
|  | 304 | double yb= XL*sin_angle_+YU*cos_angle_; | 
|---|
|  | 305 |  | 
|---|
|  | 306 | // projection sur la sphere | 
|---|
|  | 307 | double thet0,phi0,theta,phia,thetb,phib; | 
|---|
|  | 308 | PixProjToAngle(x0, y0, thet0, phi0); | 
|---|
|  | 309 | PixProjToAngle(xa, ya, theta, phia); | 
|---|
|  | 310 | PixProjToAngle(xb, yb, thetb, phib); | 
|---|
|  | 311 |  | 
|---|
|  | 312 | // angle solide | 
|---|
|  | 313 | double sol= fabs((xa-x0)*(yb-y0)-(xb-x0)*(ya-y0)); | 
|---|
|  | 314 | return sol; | 
|---|
|  | 315 | } | 
|---|
|  | 316 |  | 
|---|
| [1217] | 317 | /*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle) | 
|---|
|  | 318 |  | 
|---|
|  | 319 | set the referential of the map (angles in degrees) | 
|---|
|  | 320 |  | 
|---|
|  | 321 | (default x0=siz_x/2,  y0=siz_y/2) | 
|---|
|  | 322 | */ | 
|---|
| [764] | 323 | template<class T> | 
|---|
|  | 324 | void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle) | 
|---|
|  | 325 | { | 
|---|
|  | 326 | theta0_= theta0; | 
|---|
|  | 327 | phi0_  = phi0; | 
|---|
|  | 328 | angle_ = angle; | 
|---|
|  | 329 | x0_= nSzX_/2; | 
|---|
|  | 330 | y0_= nSzY_/2; | 
|---|
|  | 331 | cos_angle_= cos(angle*Pi/180.); | 
|---|
|  | 332 | sin_angle_= sin(angle*Pi/180.); | 
|---|
|  | 333 | originFlag_= true; | 
|---|
|  | 334 | cout << " LocalMap:: set origin 1 done" << endl; | 
|---|
|  | 335 | } | 
|---|
|  | 336 |  | 
|---|
| [1217] | 337 | /*!  \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle) | 
|---|
|  | 338 |  | 
|---|
|  | 339 | set the referential of the map (angles in degrees) | 
|---|
|  | 340 | */ | 
|---|
| [764] | 341 | template<class T> | 
|---|
|  | 342 | void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle) | 
|---|
|  | 343 | { | 
|---|
|  | 344 | theta0_= theta0; | 
|---|
|  | 345 | phi0_  = phi0; | 
|---|
|  | 346 | angle_ = angle; | 
|---|
|  | 347 | x0_= x0; | 
|---|
|  | 348 | y0_= y0; | 
|---|
|  | 349 | cos_angle_= cos(angle*Pi/180.); | 
|---|
|  | 350 | sin_angle_= sin(angle*Pi/180.); | 
|---|
|  | 351 | originFlag_= true; | 
|---|
|  | 352 | cout << " LocalMap:: set origin 2 done" << endl; | 
|---|
|  | 353 | } | 
|---|
|  | 354 |  | 
|---|
| [1217] | 355 | /*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY) | 
|---|
|  | 356 |  | 
|---|
|  | 357 | angle range of tthe map (angles in degrees) | 
|---|
|  | 358 | */ | 
|---|
| [764] | 359 | template<class T> | 
|---|
|  | 360 | void LocalMap<T>::SetSize(double angleX,double angleY) | 
|---|
|  | 361 | { | 
|---|
|  | 362 | angleX_= angleX; | 
|---|
|  | 363 | angleY_= angleY; | 
|---|
|  | 364 |  | 
|---|
|  | 365 | // tangente de la moitie de l'ouverture angulaire totale | 
|---|
|  | 366 | tgAngleX_= tan(0.5*angleX_*Pi/180.); | 
|---|
|  | 367 | tgAngleY_= tan(0.5*angleY_*Pi/180.); | 
|---|
|  | 368 |  | 
|---|
|  | 369 | extensFlag_= true; | 
|---|
|  | 370 | cout << " LocalMap:: set extension done" << endl; | 
|---|
|  | 371 | } | 
|---|
|  | 372 |  | 
|---|
| [1217] | 373 | /*! \fn void SOPHYA::LocalMap::Project(SphericalMap<T>& sphere) const | 
|---|
|  | 374 |  | 
|---|
|  | 375 | Projection to a spherical map | 
|---|
|  | 376 | */ | 
|---|
| [764] | 377 | template<class T> | 
|---|
|  | 378 | void LocalMap<T>::Project(SphericalMap<T>& sphere) const | 
|---|
|  | 379 | { | 
|---|
|  | 380 | for(int m = 0; m < nPix_; m++) | 
|---|
|  | 381 | { | 
|---|
|  | 382 | double theta,phi; | 
|---|
|  | 383 | PixThetaPhi(m,theta,phi); | 
|---|
|  | 384 | sphere(theta,phi)= pixels_(m); | 
|---|
|  | 385 | // cout << "theta " << theta << " phi " << phi << " valeur " << sphere(theta,phi)<< endl; | 
|---|
|  | 386 | } | 
|---|
|  | 387 | } | 
|---|
|  | 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; | 
|---|
|  | 400 | //  pixels_.Reset(); Pas de reset par InitNul (en cas de share) - Reza 20/11/99 $CHECK$ | 
|---|
|  | 401 | } | 
|---|
|  | 402 |  | 
|---|
| [1217] | 403 |  | 
|---|
|  | 404 | /*!   \fn void SOPHYA::LocalMap::Getij(int_4 k,int_4& i,int_4& j) const | 
|---|
|  | 405 |  | 
|---|
|  | 406 | \return 2 indices corresponding to the pixel number k | 
|---|
|  | 407 | */ | 
|---|
| [764] | 408 | template<class T> | 
|---|
|  | 409 | void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const | 
|---|
|  | 410 | { | 
|---|
|  | 411 | i= (k+1)%nSzX_-1; | 
|---|
|  | 412 | if(i == -1) i= nSzX_-1; | 
|---|
|  | 413 | j= (k-i+2)/nSzX_; | 
|---|
|  | 414 | } | 
|---|
|  | 415 |  | 
|---|
| [1217] | 416 | /*! \fn void  SOPHYA::LocalMap::ReferenceToUser(double& theta,double& phi) const | 
|---|
|  | 417 |  | 
|---|
|  | 418 | Transform a pair of coordinates (theta, phi) given in | 
|---|
|  | 419 | reference coordinates into map coordinates | 
|---|
|  | 420 | */ | 
|---|
| [764] | 421 | template<class T> | 
|---|
|  | 422 | void  LocalMap<T>::ReferenceToUser(double& theta,double& phi) const | 
|---|
|  | 423 | { | 
|---|
|  | 424 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 425 | { | 
|---|
|  | 426 | throw "LocalMap::ReferenceToUser (theta,phi) out of range"; | 
|---|
|  | 427 | } | 
|---|
|  | 428 |  | 
|---|
|  | 429 | theta= theta0_*Pi/180.+theta-Pi*0.5; | 
|---|
|  | 430 | if(theta < 0.) | 
|---|
|  | 431 | { | 
|---|
|  | 432 | theta= -theta; | 
|---|
|  | 433 | phi += Pi; | 
|---|
|  | 434 | } | 
|---|
|  | 435 | else | 
|---|
|  | 436 | { | 
|---|
|  | 437 | if(theta > Pi) | 
|---|
|  | 438 | { | 
|---|
|  | 439 | theta= 2.*Pi-theta; | 
|---|
|  | 440 | phi += Pi; | 
|---|
|  | 441 | } | 
|---|
|  | 442 | } | 
|---|
|  | 443 |  | 
|---|
|  | 444 | phi= phi0_*Pi/180.+phi; | 
|---|
|  | 445 | while(phi >= 2.*Pi) phi-= 2.*Pi; | 
|---|
|  | 446 |  | 
|---|
|  | 447 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 448 | { | 
|---|
|  | 449 | cout <<  " LocalMap::ReferenceToUser : erreur bizarre dans le transfert a la carte utilisateur " << endl; | 
|---|
|  | 450 | cout << " theta= " << theta << " phi= " << phi << endl; | 
|---|
|  | 451 | exit(0); | 
|---|
|  | 452 | } | 
|---|
|  | 453 | } | 
|---|
|  | 454 |  | 
|---|
| [1217] | 455 | /*!  \fn void  SOPHYA::LocalMap::UserToReference(double& theta,double& phi) const | 
|---|
|  | 456 |  | 
|---|
|  | 457 | Transform a pair of coordinates (theta, phi) given in | 
|---|
|  | 458 | map coordinates into reference coordinates | 
|---|
|  | 459 | */ | 
|---|
| [764] | 460 | template<class T> | 
|---|
|  | 461 | void  LocalMap<T>::UserToReference(double& theta,double& phi) const | 
|---|
|  | 462 | { | 
|---|
|  | 463 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 464 | { | 
|---|
|  | 465 | cout<<" LocalMap::UserToReference: exceptions a mettre en place" <<endl; | 
|---|
|  | 466 | // THROW(out_of_range("LocalMap::PIxVal Pixel index out of range")); | 
|---|
|  | 467 | throw "LocalMap::UserToReference (theta,phi) out of range"; | 
|---|
|  | 468 | } | 
|---|
|  | 469 |  | 
|---|
|  | 470 | double phi1= phi-phi0_*Pi/180.; | 
|---|
|  | 471 | if(phi1 < 0.) phi1+= 2.*Pi; | 
|---|
|  | 472 |  | 
|---|
|  | 473 | double theta1= theta-theta0_*Pi/180.+Pi*0.5; | 
|---|
|  | 474 | if(theta1 < 0.) | 
|---|
|  | 475 | { | 
|---|
|  | 476 | theta= -theta1; | 
|---|
|  | 477 | phi1+= Pi; | 
|---|
|  | 478 | } | 
|---|
|  | 479 | else | 
|---|
|  | 480 | { | 
|---|
|  | 481 | if(theta1 > Pi) | 
|---|
|  | 482 | { | 
|---|
|  | 483 | theta= 2.*Pi-theta1; | 
|---|
|  | 484 | phi1+= Pi; | 
|---|
|  | 485 | } | 
|---|
|  | 486 | } | 
|---|
|  | 487 |  | 
|---|
|  | 488 | while(phi1 >= 2.*Pi) phi1-= 2.*Pi; | 
|---|
|  | 489 | phi= phi1; | 
|---|
|  | 490 | if(theta > Pi || theta < 0. || phi < 0. || phi >= 2*Pi) | 
|---|
|  | 491 | { | 
|---|
|  | 492 | cout <<  " LocalMap::UserToReference : erreur bizarre dans le transfert a la carte de reference " << endl; | 
|---|
|  | 493 | cout << " theta= " << theta << " phi= " << phi << endl; | 
|---|
|  | 494 | exit(0); | 
|---|
|  | 495 | } | 
|---|
|  | 496 | } | 
|---|
|  | 497 |  | 
|---|
| [1217] | 498 | /*! \fn void SOPHYA::LocalMap::PixProjToAngle(double x,double y,double& theta,double& phi) const | 
|---|
|  | 499 |  | 
|---|
|  | 500 | Given coordinates in pixel units in the REFERENCE PLANE, return | 
|---|
|  | 501 | (theta, phi) in "absolute" referential theta=pi/2 ,phi=0. | 
|---|
|  | 502 | */ | 
|---|
| [764] | 503 | template<class T> | 
|---|
|  | 504 | void LocalMap<T>::PixProjToAngle(double x,double y,double& theta,double& phi) const | 
|---|
|  | 505 | { | 
|---|
|  | 506 | theta= Pi*0.5-atan(2.*y*tgAngleY_/(double)nSzY_); | 
|---|
|  | 507 | phi= atan2(2.*x*tgAngleX_,(double)nSzX_); | 
|---|
|  | 508 | if(phi < 0.) phi += DeuxPi; | 
|---|
|  | 509 | } | 
|---|
|  | 510 |  | 
|---|
| [1217] | 511 | /*! \fn void SOPHYA::LocalMap::AngleProjToPix(double theta,double phi,double& x,double& y) const | 
|---|
|  | 512 |  | 
|---|
|  | 513 | Given coordinates  (theta, phi) in "absolute" referential | 
|---|
|  | 514 | theta=pi/2 ,phi=0  return pixel indices  (i,j) in the REFERENCE PLANE. | 
|---|
|  | 515 | */ | 
|---|
| [764] | 516 | template<class T> | 
|---|
|  | 517 | void LocalMap<T>::AngleProjToPix(double theta,double phi,double& x,double& y) const | 
|---|
|  | 518 | { | 
|---|
|  | 519 | if(phi >= Pi) phi-= DeuxPi; | 
|---|
|  | 520 | //  y=0.5*mSzY_*cot(theta)/tgAngleY_;  $CHECK-REZA-04/99$ | 
|---|
|  | 521 | y= 0.5*nSzY_/tan(theta)/tgAngleY_;  // ? cot = 1/tan ? | 
|---|
|  | 522 | x= 0.5*nSzX_*tan(phi)/tgAngleX_; | 
|---|
|  | 523 | } | 
|---|
|  | 524 |  | 
|---|
|  | 525 | template<class T> | 
|---|
|  | 526 | void LocalMap<T>::print(ostream& os) const | 
|---|
|  | 527 | { | 
|---|
|  | 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 | } | 
|---|
|  | 537 |  | 
|---|
|  | 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; | 
|---|
|  | 545 | } | 
|---|
| [908] | 546 |  | 
|---|
|  | 547 |  | 
|---|
|  | 548 | template<class T> | 
|---|
|  | 549 | void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm) | 
|---|
|  | 550 | { | 
|---|
|  | 551 | nSzX_= lm.nSzX_; | 
|---|
|  | 552 | nSzY_= lm.nSzY_; | 
|---|
|  | 553 | nPix_= lm.nPix_; | 
|---|
|  | 554 | originFlag_= lm.originFlag_; | 
|---|
|  | 555 | extensFlag_= lm.extensFlag_; | 
|---|
|  | 556 | x0_= lm.x0_; | 
|---|
|  | 557 | y0_= lm.y0_; | 
|---|
|  | 558 | theta0_= lm.theta0_; | 
|---|
|  | 559 | phi0_= lm.phi0_; | 
|---|
|  | 560 | angle_= lm.angle_; | 
|---|
|  | 561 | cos_angle_= lm.cos_angle_; | 
|---|
|  | 562 | sin_angle_= lm.sin_angle_; | 
|---|
|  | 563 | angleX_= lm.angleX_; | 
|---|
|  | 564 | angleY_= lm.angleY_; | 
|---|
|  | 565 | tgAngleX_= lm.tgAngleX_; | 
|---|
|  | 566 | tgAngleY_= lm.tgAngleY_; | 
|---|
|  | 567 | } | 
|---|
|  | 568 |  | 
|---|
| [1419] | 569 | //   ...... Operations de calcul  ...... | 
|---|
| [908] | 570 |  | 
|---|
| [1419] | 571 |  | 
|---|
|  | 572 | //! Fill a LocalMap with a constant value \b a | 
|---|
|  | 573 | template <class T> | 
|---|
|  | 574 | LocalMap<T>& LocalMap<T>::SetT(T a) | 
|---|
|  | 575 | { | 
|---|
|  | 576 | if (NbPixels() < 1) | 
|---|
|  | 577 | throw RangeCheckError("LocalMap<T>::SetT(T )  - LocalMap not dimensionned ! "); | 
|---|
|  | 578 | pixels_ = a; | 
|---|
|  | 579 | return (*this); | 
|---|
|  | 580 | } | 
|---|
|  | 581 |  | 
|---|
|  | 582 | /*! Add a constant value \b x to a LocalMap */ | 
|---|
|  | 583 | template <class T> | 
|---|
|  | 584 | LocalMap<T>& LocalMap<T>::Add(T a) | 
|---|
|  | 585 | { | 
|---|
|  | 586 | if (NbPixels()< 1) | 
|---|
|  | 587 | throw RangeCheckError("LocalMap<T>::Add(T )  - LocalMap not dimensionned ! "); | 
|---|
|  | 588 | pixels_ += a; | 
|---|
|  | 589 | return (*this); | 
|---|
|  | 590 | } | 
|---|
|  | 591 |  | 
|---|
|  | 592 | /*! Substract a constant value \b a to a LocalMap */ | 
|---|
|  | 593 | template <class T> | 
|---|
| [1624] | 594 | LocalMap<T>& LocalMap<T>::Sub(T a,bool fginv) | 
|---|
| [1419] | 595 | { | 
|---|
|  | 596 | if (NbPixels()< 1) | 
|---|
|  | 597 | throw RangeCheckError("LocalMap<T>::Sub(T )  - LocalMap not dimensionned ! "); | 
|---|
| [1624] | 598 | pixels_.Sub(a,fginv); | 
|---|
| [1419] | 599 | return (*this); | 
|---|
|  | 600 | } | 
|---|
|  | 601 |  | 
|---|
|  | 602 | /*! multiply a LocalMap by a constant value \b a */ | 
|---|
|  | 603 | template <class T> | 
|---|
|  | 604 | LocalMap<T>& LocalMap<T>::Mul(T a) | 
|---|
|  | 605 | { | 
|---|
|  | 606 | if (NbPixels()< 1) | 
|---|
|  | 607 | throw RangeCheckError("LocalMap<T>::Mul(T )  - LocalMap not dimensionned ! "); | 
|---|
|  | 608 | pixels_ *= a; | 
|---|
|  | 609 | return (*this); | 
|---|
|  | 610 | } | 
|---|
|  | 611 |  | 
|---|
|  | 612 | /*! divide a LocalMap by a constant value \b a */ | 
|---|
|  | 613 | template <class T> | 
|---|
|  | 614 | LocalMap<T>& LocalMap<T>::Div(T a) | 
|---|
|  | 615 | { | 
|---|
|  | 616 | if (NbPixels()< 1) | 
|---|
|  | 617 | throw RangeCheckError("LocalMap<T>::Div(T )  - LocalMap not dimensionned ! "); | 
|---|
|  | 618 | pixels_ /= a; | 
|---|
|  | 619 | return (*this); | 
|---|
|  | 620 | } | 
|---|
|  | 621 |  | 
|---|
|  | 622 | //  >>>> Operations avec 2nd membre de type LocalMap | 
|---|
|  | 623 | //! Add two LocalMap | 
|---|
|  | 624 |  | 
|---|
|  | 625 | template <class T> | 
|---|
|  | 626 | LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a) | 
|---|
|  | 627 | { | 
|---|
|  | 628 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_) | 
|---|
|  | 629 | { | 
|---|
|  | 630 | throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ; | 
|---|
|  | 631 | } | 
|---|
|  | 632 | pixels_ += a.pixels_; | 
|---|
|  | 633 | return (*this); | 
|---|
|  | 634 | } | 
|---|
|  | 635 |  | 
|---|
|  | 636 | //! Substract two LocalMap | 
|---|
|  | 637 | template <class T> | 
|---|
|  | 638 | LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a) | 
|---|
|  | 639 | { | 
|---|
|  | 640 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_) | 
|---|
|  | 641 | { | 
|---|
| [1551] | 642 | throw(SzMismatchError("LocalMap<T>::SubElt(const LocalMap<T>&) SizeMismatch")) ; | 
|---|
| [1419] | 643 | } | 
|---|
|  | 644 | pixels_ -= a.pixels_; | 
|---|
|  | 645 | return (*this); | 
|---|
|  | 646 | } | 
|---|
|  | 647 |  | 
|---|
|  | 648 | //! Multiply two LocalMap (elements by elements) | 
|---|
|  | 649 | template <class T> | 
|---|
|  | 650 | LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a) | 
|---|
|  | 651 | { | 
|---|
|  | 652 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_) | 
|---|
|  | 653 | { | 
|---|
| [1551] | 654 | throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ; | 
|---|
| [1419] | 655 | } | 
|---|
|  | 656 | pixels_ *= a.pixels_; | 
|---|
|  | 657 | return (*this); | 
|---|
|  | 658 | } | 
|---|
|  | 659 |  | 
|---|
| [1551] | 660 | //! Divide two LocalMaps (elements by elements) - No protection for divide by 0 | 
|---|
|  | 661 | template <class T> | 
|---|
|  | 662 | LocalMap<T>& LocalMap<T>::DivElt(const LocalMap<T>& a) | 
|---|
|  | 663 | { | 
|---|
|  | 664 | if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_) | 
|---|
|  | 665 | { | 
|---|
|  | 666 | throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ; | 
|---|
|  | 667 | } | 
|---|
|  | 668 | pixels_ /= a.pixels_; | 
|---|
|  | 669 | return (*this); | 
|---|
|  | 670 | } | 
|---|
| [1419] | 671 |  | 
|---|
|  | 672 |  | 
|---|
|  | 673 |  | 
|---|
|  | 674 |  | 
|---|
| [1551] | 675 |  | 
|---|
| [764] | 676 | //++ | 
|---|
|  | 677 | // Titre        class FIO_LocalMap | 
|---|
|  | 678 | //    Delegated objects for persitance management | 
|---|
|  | 679 | //-- | 
|---|
|  | 680 |  | 
|---|
|  | 681 |  | 
|---|
|  | 682 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| [1308] | 683 | #pragma define_template LocalMap<int_4> | 
|---|
| [764] | 684 | #pragma define_template LocalMap<r_8> | 
|---|
|  | 685 | #pragma define_template LocalMap<r_4> | 
|---|
|  | 686 | #pragma define_template LocalMap< complex<r_8> > | 
|---|
|  | 687 | #pragma define_template LocalMap< complex<r_4> > | 
|---|
|  | 688 | #endif | 
|---|
|  | 689 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| [1308] | 690 | template class LocalMap<int_4>; | 
|---|
| [764] | 691 | template class LocalMap<r_8>; | 
|---|
|  | 692 | template class LocalMap<r_4>; | 
|---|
|  | 693 | template class LocalMap< complex<r_8> >; | 
|---|
|  | 694 | template class LocalMap< complex<r_4> >; | 
|---|
|  | 695 | #endif | 
|---|