source: Sophya/trunk/SophyaLib/SkyMap/localmap.cc@ 2442

Last change on this file since 2442 was 2442, checked in by ansari, 22 years ago

Suppression include piocmplx.h ds .cc , Reza 03/10/2003

File size: 24.9 KB
Line 
1#include "localmap.h"
2#include "smathconst.h"
3#include <complex>
4#include "fiondblock.h"
5
6#include <string.h>
7#include <iostream>
8#include "timing.h"
9
10
11/*!
12 \class SOPHYA::LocalMap
13 \ingroup SkyMap
14 A local map is a 2 dimensional matrix, with ny rows and nx columns.
15 The local map has a spatial origin with spherical coordinates (theta0, phi0), mapped to pixel(x0, y0). Default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2).
16
17 Each pixel(ip, it) is defined by its "phi-like" index ip (column
18 index in the matrix) and its "theta-like" index it (row index in
19 the matrix). Index ip is associated with x-axis in a map-coordinate
20 system ; index it is associated with y-axis in the same map-coordinate system.
21
22 The map is supposed to lie in a plan tangent to the celestial sphere
23 at its origin, with spherical coordinates (theta0, phi0), whose pixel
24 numbers are (x0,y0) in the local map as indicated above. The aperture of the map is defined by two values of angles, angleX and angleY, covered respectively by all the pixels in x direction and all the pixels in y direction.
25
26 Each pixel has angleX/nx and angleY/ny, as angle extensions. So, in
27 map-coordinate system the pixel (i,j) has following coordinates :
28
29 x = (i-x0)*angleX/nx
30
31 y = (j-y0)*angleY/ny
32
33 (angles in radians)
34
35 The projection (method : ProjectionToSphere() ) of the map onto a
36 sphere is made by the following procedure :
37
38 the sphere is supposed to have radius=1. The map is
39 considered to be tangent to the sphere, at a point with (theta0, phi0)
40 spherical coodinates. A reference coordinate system (plane-coordinate
41 system) , is chosen with respect to the plane of the map with reference axes :
42
43 x-axis : vector tangent to a parallel at (theta0, phi0) on the sphere
44 (components in "3-dim cartesian system : -sin(phi0) ; cos(phi0) ; 0)
45
46 z-axis : vector-radius with 3-dim cartesian cordinates :
47 sin(theta0)*cos(phi0) ; sin(theta0*sin(phi0) ; cos(theta0)
48
49 y-axis : z-axis^x-axis : tangent to the meridian at (theta0, phi0)
50
51
52 note that the map-coordinate system may be rotated with respect to
53 plane-coordinate system (parameter "angle" below).
54
55 the projection of a map pixel is defined as the intersection of
56 the vector-radius, from sphere center to the pixel defined by
57 his coordinates in the plane-coordinate system (computed from x,y
58 above, with eventual rotation), with the sphere.
59
60 In order to make an instance of this class available, the user must either use the standard constructor LocalMap() (as well as the "full" constructor LocalMap() ) or use the "partial" constructor LocalMap() followed by call to SetSize() and SetOrigin() (for fixing links between the map and the celestial sphere.
61
62Example :
63
64\verbatim
65 LocalMap<r_4> lcm(300, 600, 10.,20., 90.,0.); // full cstr.
66\endverbatim
67
68defining a local map 300X600 pixels, representing a sphere portion of angular apertures 10 degres x 20 degres, with map center located on the equator, is equivalent to :
69
70\verbatim
71 LocalMap<r_4> lcm(300, 600); // partial cstr.
72 lcm.SetSize(10., 20.);
73 lcm.SetOrigin(90., 0.);
74\endverbatim
75
76as well as :
77
78
79\verbatim
80 LocalMap<r_4> lcm(300, 600, 10.,20., 90.,0., 0, 0); // full cstr.
81\endverbatim
82
83(same map, but with origin of coordinates at pixel (0,0) instead of (150, 300) as it was implicit above)
84
85is equivalent to :
86
87\verbatim
88 LocalMap<r_4> lcm(300, 600);
89 lcm.SetSize(10., 20.);
90lcm.SetOrigin(90., 0., 0,0);
91\endverbatim
92
93
94*/
95template<class T>
96LocalMap<T>::LocalMap() : pixels_()
97{
98 InitNul();
99}
100
101//! partial constructor of the local map
102/*! \fn void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny)
103 \param nx : number of pixels in x direction
104 \param ny : number of pixels in y direction
105
106must be followed by calls to the methods SetSize() and SetOrigin() in order the object become usable
107
108 */
109template<class T>
110LocalMap<T>::LocalMap(int_4 nx, int_4 ny)
111{
112 InitNul();
113 ReSize(nx, ny);
114 // nSzX_ = nx;
115 // nSzY_ = ny;
116 // nPix_= nx*ny;
117 // pixels_.ReSize(ny,nx);
118}
119
120//! full constructor of the local map
121/*! \fn void SOPHYA::LocalMap:::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle)
122 \param nx : number of pixels in x direction
123 \param ny : number of pixels in y direction
124 \param angleX : total angle aperture in x direction (degrees)
125 \param angleY : total angle aperture in y direction (degrees)
126 \param theta0,phi0 : spherical coordinates of reference point at which
127 the map is considered to be tangent to the sphere
128 \param x0, y0 : coordinates (in pixels) of the reference point just defined
129 \param angle : angle (degrees) of the rotation between x-axis of
130 map-coordinate system) and the tangent to parallel on
131 the sphere (default : 0.).
132 */
133template<class T>
134LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle)
135{
136 InitNul();
137 // nSzX_ = nx;
138 // nSzY_ = ny;
139 // nPix_= nx*ny;
140 // pixels_.ReSize(ny,nx);
141 ReSize(nx, ny);
142 SetSize(angleX, angleY);
143 SetOrigin(theta0, phi0, x0, y0, angle);
144}
145
146// void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
147
148//! standard constructor of the local map
149/*! \fn void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
150 \param nx : number of pixels in x direction
151 \param ny : number of pixels in y direction
152 \param angleX : total angle aperture in x direction (degrees)
153 \param angleY : total angle aperture in y direction (degrees)
154 \param theta0,phi0 : spherical coordinates of reference point at which
155 the map is considered to be tangent to the sphere
156 \param angle : angle (degrees) of the rotation between x-axis of
157 map-coordinate system) and the tangent to parallel on
158 the sphere (default : 0.).
159 */
160template<class T>
161LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
162{
163 InitNul();
164 // nSzX_ = nx;
165 // nSzY_ = ny;
166 // nPix_= nx*ny;
167 // pixels_.ReSize(ny,nx);
168 ReSize(nx, ny);
169 SetSize(angleX, angleY);
170 SetOrigin(theta0, phi0, angle);
171}
172
173//! copy constructor
174/*! \fn void SOPHYA::LocalMap::LocalMap(const LocalMap<T>& lm, bool share)
175 \param share : if true, share data. If false copy data
176 */
177template<class T>
178LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
179 : pixels_(lm.pixels_, share)
180{
181
182 if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
183 recopierVariablesSimples(lm);
184}
185
186//! copy constructor
187/*! \fn void SOPHYA::LocalMap::LocalMap(const LocalMap<T>& lm)
188 \warning datas are \b SHARED with \b lm.
189 \sa TMatrix::TMatrix(const TMatrix<T>&)
190*/
191template<class T>
192LocalMap<T>::LocalMap(const LocalMap<T>& lm)
193 : pixels_(lm.pixels_)
194
195{
196
197 if(lm.mInfo_) mInfo_= new DVList(*lm.mInfo_);
198 recopierVariablesSimples(lm);
199}
200
201//! destructor
202/*! \fn void SOPHYA::LocalMap::~LocalMap()
203
204 */
205template<class T>
206LocalMap<T>::~LocalMap() {;}
207
208
209
210/*! \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny)
211
212 Resize storage area for pixels
213\param nx
214\param ny new pixel numbers
215*/
216template<class T>
217void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
218{
219 // angles par pixel, en radians
220 deltaPhi_ *= nSzX_/nx;
221 deltaTheta_ *= nSzY_/ny;
222
223 nSzX_ = nx;
224 nSzY_ = ny;
225 nPix_= nx*ny;
226 pixels_.ReSize(ny,nx);
227 pixelSized_ = true;
228}
229
230////////////////////////// methodes de copie/share
231
232template<class T>
233void LocalMap<T>::CloneOrShare(const LocalMap<T>& a)
234{
235 recopierVariablesSimples(a);
236 pixels_.CloneOrShare(a.pixels_);
237 if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
238 if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
239}
240template<class T>
241void LocalMap<T>::Share(const LocalMap<T>& a)
242{
243 recopierVariablesSimples(a);
244 pixels_.Share(a.pixels_);
245 if (mInfo_) {delete mInfo_; mInfo_ = NULL;}
246 if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
247}
248
249template<class T>
250LocalMap<T>& LocalMap<T>::CopyElt(const LocalMap<T>& a)
251{
252 if (NbPixels() < 1)
253 throw RangeCheckError("LocalMap<T>::CopyElt(const LocalMap<T>& ) - Not Allocated Array ! ");
254 if (NbPixels() != a.NbPixels())
255 throw(SzMismatchError("LocalMap<T>::CopyElt(const LocalMap<T>&) SizeMismatch")) ;
256 recopierVariablesSimples(a);
257 int k;
258 pixels_ = a.pixels_;
259 return(*this);
260
261}
262
263template<class T>
264LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a)
265 {
266 if (this != &a)
267 {
268 if (a.NbPixels() < 1)
269 throw RangeCheckError("LocalMap<T>::Set(a ) - Array a not allocated ! ");
270 if (NbPixels() < 1) CloneOrShare(a);
271 else CopyElt(a);
272 if (mInfo_) delete mInfo_;
273 mInfo_ = NULL;
274 if (a.mInfo_) mInfo_ = new DVList(*(a.mInfo_));
275 }
276 return(*this);
277 }
278
279
280/*! \fn int_4 SOPHYA::LocalMap::NbPixels() const
281
282 \return number of pixels
283*/
284template<class T>
285int_4 LocalMap<T>::NbPixels() const
286{
287 return(nPix_);
288}
289
290/*! \fn T& SOPHYA::LocalMap::PixVal(int_4 k)
291
292 \return value of pixel with index k
293*/
294template<class T>
295T& LocalMap<T>::PixVal(int_4 k)
296{
297 if((k < 0) || (k >= nPix_))
298 {
299 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
300 }
301 //
302 int_4 i,j;
303 Getij(k,i,j);
304 return(pixels_(j,i));
305
306 //
307}
308
309/*! \fn T const& SOPHYA::LocalMap::PixVal(int_4 k) const
310 const version of previous method
311*/
312template<class T>
313T const& LocalMap<T>::PixVal(int_4 k) const
314{
315 if((k < 0) || (k >= nPix_))
316 {
317 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
318 }
319 //
320 int_4 i,j;
321 Getij(k,i,j);
322 return(pixels_(j,i));
323}
324
325/*! \fn bool SOPHYA::LocalMap::ContainsSph(double theta, double phi) const
326 \return true if teta,phi in map
327 <b> Not yet implemented </b>
328*/
329template<class T>
330bool LocalMap<T>::ContainsSph(double theta, double phi) const
331{
332// $CHECK$ Reza 11/11/99 - A modifier
333 throw NotAvailableOperation("LocalMap<T>::ContainsSph() - Not yet implemented !");
334 return(true);
335}
336
337/*! \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const
338
339 angles in radians
340 \return index of the pixel with spherical coordinates (theta,phi)
341*/
342template<class T>
343int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
344{
345 int_4 i,j;
346
347 if (! LocalMap_isDone()) initializationError();
348 double csTheta = cos(theta);
349 double snTheta = sin(theta);
350 double csPhi = cos(phi);
351 double snPhi = sin(phi);
352 double csPhiMPhiC = cos (phi - phiC_);
353 double snPhiMPhiC = sin (phi - phiC_);
354 // le point sur la sphere est note M.
355 // intersection P de OM avec le plan de la carte (tangent en C)
356 double denom = snTheta*snthC_*csPhiMPhiC + csTheta*csthC_;
357 if ( denom == 0.)
358 {
359 }
360 double lambda = 1./denom;
361 // coordonnes du point d'intersection P dans le repere lie au plan
362
363 double XP = lambda*snTheta*snPhiMPhiC;
364 double YP = lambda*snTheta*csthC_*csPhiMPhiC;
365
366 // coordonnees dans le repere lie a la carte (eventuellement tourne par
367 // rapport au precedent.
368
369 double X = XP*cosAngle_ + YP*sinAngle_;
370 double Y = -XP*sinAngle_ + YP*cosAngle_;
371
372 // en unites de pixels
373
374 X /= deltaPhi_;
375 Y /= deltaTheta_;
376
377
378 double xmin= -x0_-0.5;
379 double xmax= xmin+nSzX_;
380 if((X > xmax) || (X < xmin)) {
381 if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (X) ");
382 else return(-1);
383 }
384 double xcurrent= xmin;
385 for(i = 0; i < nSzX_; i++ )
386 {
387 xcurrent += 1.;
388 if( X < xcurrent ) break;
389 }
390 double ymin= -y0_-0.5;
391 double ymax= ymin+nSzY_;
392 if((Y > ymax) || (Y < ymin)) {
393 if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (Y) ");
394 else return(-1);
395 }
396 double ycurrent= ymin;
397 for(j = 0; j < nSzY_; j++ )
398 {
399 ycurrent += 1.;
400 if( Y < ycurrent ) break;
401 }
402 return (j*nSzX_+i);
403}
404
405/*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 k,double& theta,double& phi) const
406
407 \return (theta, phi) coordinates of pixel with index k
408*/
409
410
411template<class T>
412void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
413{
414
415 int_4 i,j;
416 Getij(k,i,j);
417
418 PixThetaPhi(i,j, theta, phi);
419
420}
421
422/*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
423
424
425 \return (theta, phi) coordinates of pixel of map with indices (ip,it) corresponding to x and y directions
426
427 \param ip phi-like index
428 \param it theta-like index
429*/
430
431template<class T>
432void LocalMap<T>::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
433{
434 double XP, YP, ZP;
435 PixToSphereC(ip,it,XP,YP,ZP);
436
437 theta = acos(ZP);
438 phi = atan2(YP, XP);
439 while (phi < 0.) phi += 2.*Pi;
440
441}
442
443
444
445
446/*! \fn T SOPHYA::LocalMap::SetPixels(T v)
447
448Set all pixels to value v
449*/
450template <class T>
451T LocalMap<T>::SetPixels(T v)
452{
453pixels_ = v;
454return(v);
455}
456
457/*! \fn double SOPHYA::LocalMap::PixSolAngle(int_4 k) const
458 Pixel Solid angle of pixel k (steradians).
459 For the moment, all the pixels are considered to have the same size in (theta, phi). So the parameter k is dummy.
460
461*/
462template<class T>
463double LocalMap<T>::PixSolAngle(int_4 k) const
464{
465 double XP, YP, ZP;
466 int_4 i,j;
467 Getij(k,i,j);
468 PixToSphereC(i,j,XP,YP,ZP);
469
470 double theta = acos(ZP);
471
472
473
474 // angle solide
475
476 double sol= 2.* deltaPhi_*sin(theta)*sin(0.5*deltaTheta_);
477 return sol;
478}
479
480/*! \fn void SOPHYA::LocalMap::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
481
482projection of a pixel of map, onto the unity sphere ; result in cartesian coordinates.
483*/
484
485template<class T>
486void LocalMap<T>::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
487{
488 if (! LocalMap_isDone()) initializationError();
489 double X= double(ip-x0_)* deltaPhi_;
490 double Y= double(it-y0_)*deltaTheta_;
491
492 // situation dans le plan de reference tangent
493 double dx= X*cosAngle_-Y*sinAngle_;
494 double dy= X*sinAngle_+Y*cosAngle_;
495
496 XP = XC_ - dx*snphC_ - dy*csthC_*csphC_;
497 YP = YC_ + dx*csphC_ - dy*csthC_*snphC_;
498 ZP = ZC_ + dy*snthC_;
499
500 // on renormalise pour eviter les probleme de precision lors
501 // de la prise ulterieure de lignes trigonometriques
502 double norme = sqrt(XP*XP + YP*YP + ZP*ZP);
503 XP /= norme;
504 YP /= norme;
505 ZP /= norme;
506}
507
508/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle)
509 set the referential of the map (angles in degrees)
510
511 \param theta0
512 \param phi0 celestial coordinates attributed to center pixel: x0=siz_x/2, y0=siz_y/2
513\param angle angle between map referential and plane-coordinate system (see class description)
514*/
515template<class T>
516void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
517{
518 SetOrigin(theta0, phi0, nSzX_/2, nSzY_/2, angle);
519}
520
521/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
522 set the referential of the map (angles in degrees)
523
524 \param theta0
525 \param phi0 celestial coordinates attributed to center pixel: (x0,y0)
526\param angle angle between map referential and plane-coordinate system (see class description)
527
528*/
529template<class T>
530void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
531{
532
533 if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.)
534 {
535 throw ParmError("LocalMap::SetOrigin angle out of range");
536 }
537 SetCoorC(theta0,phi0);
538 angleDegres_ = angle;
539 // en radians
540 angle_ = angle*Pi/180.;
541 x0_= x0;
542 y0_= y0;
543 cosAngle_= cos(angle_);
544 sinAngle_= sin(angle_);
545
546 if (originSet_)
547 {
548 cout << " WARNING: LocalMap<T>::SetOrigin() : reset origine of a local map which had already an origin " << endl;
549 }
550 originSet_ = true;
551}
552
553template<class T>
554void LocalMap<T>::SetCoorC(double theta0, double phi0)
555{
556
557 thetaDegresC_ = theta0;
558 phiDegresC_ = phi0;
559
560 // passage en radians
561 thetaC_= theta0*Pi/180.;
562 phiC_ = phi0*Pi/180.;
563 csthC_ = cos(thetaC_);
564 snthC_ = sin(thetaC_);
565 csphC_ = cos(phiC_);
566 snphC_ = sin(phiC_);
567 XC_ = snthC_*csphC_;
568 YC_ = snthC_*snphC_;
569 ZC_ = csthC_;
570}
571
572
573// angles en RADIANS
574template<class T>
575TMatrix<double> LocalMap<T>::CalculMatricePassage()
576{
577 cout << " calcul matrice de passage " << endl;
578 if (! LocalMap_isDone()) initializationError();
579 TMatrix<double> passage(3,3);
580 double cos_th_axeZ;
581 double sin_th_axeZ;
582 double cos_phi_axeZ;
583 double sin_phi_axeZ;
584
585 double cth,sth, cdeltaPhi, phi, cphi, sphi;
586
587 if ( snthC_ <= 0.) // carte centree au pole
588 {
589 cos_th_axeZ = 1.;
590 sin_th_axeZ = 0.;
591 cos_phi_axeZ = 1.;
592 sin_phi_axeZ = 0.;
593
594 }
595 else
596 {
597 cth = cosAngle_*snthC_;
598 double arg = 1.-cth*cth;
599 if (arg <= 0. ) // carte centree sur l'equateur, sans rotation
600 {
601 cos_th_axeZ = 1.;
602 sin_th_axeZ = 0.;
603 cos_phi_axeZ = csphC_;
604 sin_phi_axeZ = snphC_;
605 }
606 else
607 {
608 sth = sqrt(arg);
609 cdeltaPhi = -csthC_*cth/(snthC_*sth);
610 if (cdeltaPhi < -1. ) cdeltaPhi = -1.;
611 if (cdeltaPhi > 1. ) cdeltaPhi = 1.;
612 phi = phiC_ + acos( cdeltaPhi );
613
614 cos_th_axeZ = cth;
615 sin_th_axeZ = sth;
616 cos_phi_axeZ = cos(phi);
617 sin_phi_axeZ = sin(phi);
618 }
619 }
620 passage(0,0) = snthC_*csphC_;
621 passage(1,0) = snthC_*snphC_;
622 passage(2,0) = csthC_;
623
624 passage(0,2) = sin_th_axeZ*cos_phi_axeZ;
625 passage(1,2) = sin_th_axeZ*sin_phi_axeZ;
626 passage(2,2) = cos_th_axeZ;
627
628 passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0);
629 passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0);
630 passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0);
631
632 // passage.Print(cout);
633 // cout << " fin calcul passage " << endl;
634
635 return passage;
636
637
638}
639
640/*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY)
641
642 angle range of tthe map (angles in degrees)
643\param angleX phi-like angle
644\param angleX theta-like angle
645*/
646template<class T>
647void LocalMap<T>::SetSize(double angleX,double angleY)
648{
649 if (!pixelSized_) initializationError();
650
651 if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.)
652 {
653 throw ParmError("LocalMap::SetSize extension angle out of range");
654 }
655
656 angleDegresX_ = angleX;
657 angleDegresY_ = angleY;
658 // angles par pixel, en radians
659 cout << " taille x " << nSzX_ <<" taille y " << nSzY_ << endl;
660 deltaPhi_ = angleX*Pi/(180.*nSzX_);
661 deltaTheta_ = angleY*Pi/(180.*nSzY_);
662
663 if (angleSized_)
664 {
665 cout << " WARNING LocalMap::SetSize ; angle resizing of an already sized local map " << endl;
666 }
667 angleSized_ = true;
668
669}
670
671
672
673/*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const
674
675Projection to a spherical map
676*/
677template<class T>
678void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const
679{
680 double theta, phi;
681 int it, ip;
682 for (it = 0; it < nSzY_; it++)
683 {
684 for (ip = 0; ip < nSzX_; ip++)
685 {
686 PixThetaPhi(ip,it, theta, phi);
687 sphere(theta,phi)= pixels_(it, ip);
688 }
689 }
690}
691
692
693
694// Titre Private Methods
695//++
696template<class T>
697void LocalMap<T>::InitNul()
698//
699// set attributes to zero
700//--
701{
702
703 pixelSized_ = false;
704 angleSized_ = false;
705 originSet_ = false;
706
707 nSzX_ = 0;
708 nSzY_ = 0;
709 angleDegresX_ = 0.;
710 angleDegresY_ = 0.;
711 thetaDegresC_ = 0.;
712 phiDegresC_ = 0.;
713 x0_ = 0;
714 y0_ = 0;
715 angleDegres_ = 0.;
716
717
718
719 nPix_ = 0;
720
721 thetaC_ = 0.;
722 phiC_ = 0.;
723 csthC_ = 1.;
724 snthC_ = 0.;
725 csphC_ = 1.;
726 snphC_ = 0.;
727 XC_ = 0.;
728 YC_ = 0.;
729 ZC_ = 1.;
730
731 angle_ = 0.;
732 cosAngle_ = 1.;
733 sinAngle_ = 0.;
734 deltaPhi_ = 0.;
735 deltaTheta_ =0.;
736 SetThrowExceptionWhenOutofMapFlag(false); // Genere des exceptions si theta-phi out of range
737}
738
739
740/*! \fn void SOPHYA::LocalMap::Getij(int_4 k,int_4& i,int_4& j) const
741
742 \return 2 indices corresponding to the pixel number k
743*/
744template<class T>
745void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
746{
747 i= (k+1)%nSzX_-1;
748 if(i == -1) i= nSzX_-1;
749 j= (k-i+2)/nSzX_;
750}
751
752
753
754
755
756
757template<class T>
758void LocalMap<T>::print(ostream& os) const
759{
760 os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
761 os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl;
762 os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
763 os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl;
764 os<<" deltaPhi_= "<< deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl;
765 os <<endl;
766
767 os << " contenu de pixels : ";
768 for(int i=0; i < nPix_; i++)
769 {
770 if(i%5 == 0) os << endl;
771 int_4 ik,jk;
772 Getij(i,ik,jk);
773 os << pixels_(jk,ik) <<", ";
774 }
775 os << endl;
776}
777
778
779template<class T>
780void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
781{
782
783 pixelSized_ = lm.pixelSized_;
784 angleSized_ = lm.angleSized_;
785 originSet_ = lm.originSet_ ;
786
787
788 nSzX_ = lm.nSzX_;
789 nSzY_ = lm.nSzY_;
790 nPix_ = lm.nPix_;
791 x0_ = lm.x0_;
792 y0_ = lm.y0_;
793
794 thetaC_ = lm.thetaC_;
795 phiC_ = lm.phiC_;
796 csthC_ = lm.csthC_;
797 snthC_ = lm.snthC_;
798 csphC_ = lm.csphC_;
799 snphC_ = lm.snphC_;
800 XC_ = lm.XC_;
801 YC_ = lm.YC_;
802 ZC_ = lm.ZC_;
803
804 angle_= lm.angle_;
805 cosAngle_ = lm.cosAngle_;
806 sinAngle_ = lm.sinAngle_;
807 deltaPhi_ = lm. deltaPhi_;
808 deltaTheta_ = lm.deltaTheta_;
809}
810
811template<class T>
812void LocalMap<T>::initializationError() const
813{
814 cout << endl;
815 if (!pixelSized_) cout << " LocalMap::initializationError() ; pixel sizing is missing " << endl;
816 if (!angleSized_ ) cout << " LocalMap::initializationError() ; angle sizing is missing " << endl;
817 if (!originSet_ ) cout << " LocalMap::initializationError() ; origin of map is not set " << endl;
818 throw PException("LocalMap::initializationError() : bad initialization of the local map ");
819
820
821}
822
823
824// ...... Operations de calcul ......
825
826
827/*! \fn void SOPHYA::LocalMap::SetT(T a)
828 Fill a LocalMap with a constant value \b a
829 */
830template <class T>
831LocalMap<T>& LocalMap<T>::SetT(T a)
832{
833 if (NbPixels() < 1)
834 throw RangeCheckError("LocalMap<T>::SetT(T ) - LocalMap not dimensionned ! ");
835 pixels_ = a;
836 return (*this);
837}
838
839/*! \fn void SOPHYA::LocalMap::Add(T a)
840Add a constant value \b x to a LocalMap
841 */
842template <class T>
843LocalMap<T>& LocalMap<T>::Add(T a)
844 {
845 if (NbPixels()< 1)
846 throw RangeCheckError("LocalMap<T>::Add(T ) - LocalMap not dimensionned ! ");
847 pixels_ += a;
848 return (*this);
849}
850
851/*! \fn void SOPHYA::LocalMap::Sub(T a,bool fginv)
852
853Substract a constant value \b a to a LocalMap
854
855*/
856template <class T>
857LocalMap<T>& LocalMap<T>::Sub(T a,bool fginv)
858{
859 if (NbPixels()< 1)
860 throw RangeCheckError("LocalMap<T>::Sub(T ) - LocalMap not dimensionned ! ");
861 pixels_.Sub(a,fginv);
862 return (*this);
863}
864
865/*! \fn void SOPHYA::LocalMap::Mul(T a)
866mutiply a LocalMap by a constant value \b a
867*/
868template <class T>
869LocalMap<T>& LocalMap<T>::Mul(T a)
870{
871 if (NbPixels()< 1)
872 throw RangeCheckError("LocalMap<T>::Mul(T ) - LocalMap not dimensionned ! ");
873 pixels_ *= a;
874 return (*this);
875}
876
877/*! \fn void SOPHYA::LocalMap::Div(T a)
878divide a LocalMap by a constant value \b a
879*/
880template <class T>
881LocalMap<T>& LocalMap<T>::Div(T a)
882{
883 if (NbPixels()< 1)
884 throw RangeCheckError("LocalMap<T>::Div(T ) - LocalMap not dimensionned ! ");
885 pixels_ /= a;
886 return (*this);
887}
888
889// >>>> Operations avec 2nd membre de type LocalMap
890/*! \fn void SOPHYA::LocalMap::AddElt(const LocalMap<T>& a)
891Add two LocalMap
892 */
893template <class T>
894LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a)
895{
896 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
897 {
898 throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
899 }
900 pixels_ += a.pixels_;
901 return (*this);
902}
903
904/*! \fn void SOPHYA::LocalMap::SubElt(const LocalMap<T>& a)
905Substract two LocalMap
906 */
907template <class T>
908LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a)
909{
910 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
911 {
912 throw(SzMismatchError("LocalMap<T>::SubElt(const LocalMap<T>&) SizeMismatch")) ;
913 }
914 pixels_ -= a.pixels_;
915 return (*this);
916}
917
918/*! \fn void SOPHYA::LocalMap::MulElt(const LocalMap<T>& a)
919Multiply two LocalMap (elements by elements)
920 */
921template <class T>
922LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a)
923{
924 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
925 {
926 throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ;
927 }
928 // pixels_ *= a.pixels_;
929 pixels_.DataBlock() *= a.pixels_.DataBlock();
930 return (*this);
931}
932
933/*! \fn void SOPHYA::LocalMap::DivElt(const LocalMap<T>& a)
934Divide two LocalMaps (elements by elements) - No protection for divide by 0
935*/
936template <class T>
937LocalMap<T>& LocalMap<T>::DivElt(const LocalMap<T>& a)
938{
939 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
940 {
941 throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ;
942 }
943 // pixels_ /= a.pixels_;
944 pixels_.DataBlock() /= a.pixels_.DataBlock();
945 return (*this);
946}
947
948
949
950
951
952
953#ifdef __CXX_PRAGMA_TEMPLATES__
954#pragma define_template LocalMap<int_4>
955#pragma define_template LocalMap<r_8>
956#pragma define_template LocalMap<r_4>
957#pragma define_template LocalMap< complex<r_8> >
958#pragma define_template LocalMap< complex<r_4> >
959#endif
960#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
961template class LocalMap<int_4>;
962template class LocalMap<r_8>;
963template class LocalMap<r_4>;
964template class LocalMap< complex<r_8> >;
965template class LocalMap< complex<r_4> >;
966#endif
Note: See TracBrowser for help on using the repository browser.