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

Last change on this file since 3751 was 3572, checked in by cmv, 17 years ago

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

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