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

Last change on this file since 3300 was 3300, checked in by ansari, 18 years ago

Correction ds LocalMap::PixToSphereC() suite message S.Plascczynski du 12/07/07 - Reza 17/08/2007

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 int k;
259 pixels_ = a.pixels_;
260 return(*this);
261
262}
263
264template<class T>
265LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a)
266 {
267 if (this != &a)
268 {
269 if (a.NbPixels() < 1)
270 throw RangeCheckError("LocalMap<T>::Set(a ) - Array a not allocated ! ");
271 if (NbPixels() < 1) CloneOrShare(a);
272 else CopyElt(a);
273 if (this->mInfo_) delete this->mInfo_;
274 this->mInfo_ = NULL;
275 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
276 }
277 return(*this);
278 }
279
280
281/*! \fn int_4 SOPHYA::LocalMap::NbPixels() const
282
283 \return number of pixels
284*/
285template<class T>
286int_4 LocalMap<T>::NbPixels() const
287{
288 return(nPix_);
289}
290
291/*! \fn T& SOPHYA::LocalMap::PixVal(int_4 k)
292
293 \return value of pixel with index k
294*/
295template<class T>
296T& LocalMap<T>::PixVal(int_4 k)
297{
298 if((k < 0) || (k >= nPix_))
299 {
300 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
301 }
302 //
303 int_4 i,j;
304 Getij(k,i,j);
305 return(pixels_(j,i));
306
307 //
308}
309
310/*! \fn T const& SOPHYA::LocalMap::PixVal(int_4 k) const
311 const version of previous method
312*/
313template<class T>
314T const& LocalMap<T>::PixVal(int_4 k) const
315{
316 if((k < 0) || (k >= nPix_))
317 {
318 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
319 }
320 //
321 int_4 i,j;
322 Getij(k,i,j);
323 return(pixels_(j,i));
324}
325
326/*! \fn bool SOPHYA::LocalMap::ContainsSph(double theta, double phi) const
327 \return true if teta,phi in map
328 <b> Not yet implemented </b>
329*/
330template<class T>
331bool LocalMap<T>::ContainsSph(double theta, double phi) const
332{
333// $CHECK$ Reza 11/11/99 - A modifier
334 throw NotAvailableOperation("LocalMap<T>::ContainsSph() - Not yet implemented !");
335 return(true);
336}
337
338/*! \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const
339
340 angles in radians
341 \return index of the pixel with spherical coordinates (theta,phi)
342*/
343template<class T>
344int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
345{
346 int_4 i,j;
347
348 if (! LocalMap_isDone()) initializationError();
349 double csTheta = cos(theta);
350 double snTheta = sin(theta);
351 double csPhi = cos(phi);
352 double snPhi = sin(phi);
353 double csPhiMPhiC = cos (phi - phiC_);
354 double snPhiMPhiC = sin (phi - phiC_);
355 // le point sur la sphere est note M.
356 // intersection P de OM avec le plan de la carte (tangent en C)
357 double denom = snTheta*snthC_*csPhiMPhiC + csTheta*csthC_;
358 if ( denom == 0.)
359 {
360 }
361 double lambda = 1./denom;
362 // coordonnes du point d'intersection P dans le repere lie au plan
363
364 double XP = lambda*snTheta*snPhiMPhiC;
365 double YP = lambda*snTheta*csthC_*csPhiMPhiC;
366
367 // coordonnees dans le repere lie a la carte (eventuellement tourne par
368 // rapport au precedent.
369
370 double X = XP*cosAngle_ + YP*sinAngle_;
371 double Y = -XP*sinAngle_ + YP*cosAngle_;
372
373 // en unites de pixels
374
375 X /= deltaPhi_;
376 Y /= deltaTheta_;
377
378
379 double xmin= -x0_-0.5;
380 double xmax= xmin+nSzX_;
381 if((X > xmax) || (X < xmin)) {
382 if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (X) ");
383 else return(-1);
384 }
385 double xcurrent= xmin;
386 for(i = 0; i < nSzX_; i++ )
387 {
388 xcurrent += 1.;
389 if( X < xcurrent ) break;
390 }
391 double ymin= -y0_-0.5;
392 double ymax= ymin+nSzY_;
393 if((Y > ymax) || (Y < ymin)) {
394 if (exc_outofmap_) throw RangeCheckError("LocalMap<T>::PixIndexSph() - Out of Map Theta/Phi (Y) ");
395 else return(-1);
396 }
397 double ycurrent= ymin;
398 for(j = 0; j < nSzY_; j++ )
399 {
400 ycurrent += 1.;
401 if( Y < ycurrent ) break;
402 }
403 return (j*nSzX_+i);
404}
405
406/*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 k,double& theta,double& phi) const
407
408 \return (theta, phi) coordinates of pixel with index k
409*/
410
411
412template<class T>
413void LocalMap<T>::PixThetaPhi(int_4 k,double& theta,double& phi) const
414{
415
416 int_4 i,j;
417 Getij(k,i,j);
418
419 PixThetaPhi(i,j, theta, phi);
420
421}
422
423/*! \fn void SOPHYA::LocalMap::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
424
425
426 \return (theta, phi) coordinates of pixel of map with indices (ip,it) corresponding to x and y directions
427
428 \param ip phi-like index
429 \param it theta-like index
430*/
431
432template<class T>
433void LocalMap<T>::PixThetaPhi(int_4 ip,int_4 it, double& theta,double& phi) const
434{
435 double XP, YP, ZP;
436 PixToSphereC(ip,it,XP,YP,ZP);
437
438 theta = acos(ZP);
439 phi = atan2(YP, XP);
440 while (phi < 0.) phi += 2.*Pi;
441
442}
443
444
445
446
447/*! \fn T SOPHYA::LocalMap::SetPixels(T v)
448
449Set all pixels to value v
450*/
451template <class T>
452T LocalMap<T>::SetPixels(T v)
453{
454pixels_ = v;
455return(v);
456}
457
458/*! \fn double SOPHYA::LocalMap::PixSolAngle(int_4 k) const
459 Pixel Solid angle of pixel k (steradians).
460 For the moment, all the pixels are considered to have the same size in (theta, phi). So the parameter k is dummy.
461
462*/
463template<class T>
464double LocalMap<T>::PixSolAngle(int_4 k) const
465{
466 double XP, YP, ZP;
467 int_4 i,j;
468 Getij(k,i,j);
469 PixToSphereC(i,j,XP,YP,ZP);
470
471 double theta = acos(ZP);
472
473
474
475 // angle solide
476
477 double sol= 2.* deltaPhi_*sin(theta)*sin(0.5*deltaTheta_);
478 return sol;
479}
480
481/*! \fn void SOPHYA::LocalMap::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
482
483projection of a pixel of map, onto the unity sphere ; result in cartesian coordinates.
484*/
485
486template<class T>
487void LocalMap<T>::PixToSphereC(int_4 ip, int_4 it, double& XP, double& YP, double& ZP) const
488{
489 if (! LocalMap_isDone()) initializationError();
490 double X= double(ip-x0_)* deltaPhi_;
491 double Y= double(it-y0_)*deltaTheta_;
492
493 // situation dans le plan de reference tangent
494 double dx= X*cosAngle_-Y*sinAngle_;
495 double dy= X*sinAngle_+Y*cosAngle_;
496
497 // Aout07 : Correction -dy change en +dy suite message S.Plaszczynski du 12/07/07 pour XP et YP (Reza)
498 XP = XC_ - dx*snphC_ + dy*csthC_*csphC_; // Aout07: -dy change en +dy (Rz/SP)
499 YP = YC_ + dx*csphC_ + dy*csthC_*snphC_; // Aout07: -dy change en +dy (Rz/SP)
500 ZP = ZC_ + dy*snthC_;
501
502 // on renormalise pour eviter les probleme de precision lors
503 // de la prise ulterieure de lignes trigonometriques
504 double norme = sqrt(XP*XP + YP*YP + ZP*ZP);
505 XP /= norme;
506 YP /= norme;
507 ZP /= norme;
508}
509
510/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle)
511 set the referential of the map (angles in degrees)
512
513 \param theta0
514 \param phi0 celestial coordinates attributed to center pixel: x0=siz_x/2, y0=siz_y/2
515\param angle angle between map referential and plane-coordinate system (see class description)
516*/
517template<class T>
518void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
519{
520 SetOrigin(theta0, phi0, nSzX_/2, nSzY_/2, angle);
521}
522
523/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
524 set the referential of the map (angles in degrees)
525
526 \param theta0
527 \param phi0 celestial coordinates attributed to center pixel: (x0,y0)
528\param angle angle between map referential and plane-coordinate system (see class description)
529
530*/
531template<class T>
532void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
533{
534
535 if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.)
536 {
537 throw ParmError("LocalMap::SetOrigin angle out of range");
538 }
539 SetCoorC(theta0,phi0);
540 angleDegres_ = angle;
541 // en radians
542 angle_ = angle*Pi/180.;
543 x0_= x0;
544 y0_= y0;
545 cosAngle_= cos(angle_);
546 sinAngle_= sin(angle_);
547
548 if (originSet_)
549 {
550 cout << " WARNING: LocalMap<T>::SetOrigin() : reset origine of a local map which had already an origin " << endl;
551 }
552 originSet_ = true;
553}
554
555template<class T>
556void LocalMap<T>::SetCoorC(double theta0, double phi0)
557{
558
559 thetaDegresC_ = theta0;
560 phiDegresC_ = phi0;
561
562 // passage en radians
563 thetaC_= theta0*Pi/180.;
564 phiC_ = phi0*Pi/180.;
565 csthC_ = cos(thetaC_);
566 snthC_ = sin(thetaC_);
567 csphC_ = cos(phiC_);
568 snphC_ = sin(phiC_);
569 XC_ = snthC_*csphC_;
570 YC_ = snthC_*snphC_;
571 ZC_ = csthC_;
572}
573
574
575// angles en RADIANS
576template<class T>
577TMatrix<double> LocalMap<T>::CalculMatricePassage()
578{
579 cout << " calcul matrice de passage " << endl;
580 if (! LocalMap_isDone()) initializationError();
581 TMatrix<double> passage(3,3);
582 double cos_th_axeZ;
583 double sin_th_axeZ;
584 double cos_phi_axeZ;
585 double sin_phi_axeZ;
586
587 double cth,sth, cdeltaPhi, phi, cphi, sphi;
588
589 if ( snthC_ <= 0.) // carte centree au pole
590 {
591 cos_th_axeZ = 1.;
592 sin_th_axeZ = 0.;
593 cos_phi_axeZ = 1.;
594 sin_phi_axeZ = 0.;
595
596 }
597 else
598 {
599 cth = cosAngle_*snthC_;
600 double arg = 1.-cth*cth;
601 if (arg <= 0. ) // carte centree sur l'equateur, sans rotation
602 {
603 cos_th_axeZ = 1.;
604 sin_th_axeZ = 0.;
605 cos_phi_axeZ = csphC_;
606 sin_phi_axeZ = snphC_;
607 }
608 else
609 {
610 sth = sqrt(arg);
611 cdeltaPhi = -csthC_*cth/(snthC_*sth);
612 if (cdeltaPhi < -1. ) cdeltaPhi = -1.;
613 if (cdeltaPhi > 1. ) cdeltaPhi = 1.;
614 phi = phiC_ + acos( cdeltaPhi );
615
616 cos_th_axeZ = cth;
617 sin_th_axeZ = sth;
618 cos_phi_axeZ = cos(phi);
619 sin_phi_axeZ = sin(phi);
620 }
621 }
622 passage(0,0) = snthC_*csphC_;
623 passage(1,0) = snthC_*snphC_;
624 passage(2,0) = csthC_;
625
626 passage(0,2) = sin_th_axeZ*cos_phi_axeZ;
627 passage(1,2) = sin_th_axeZ*sin_phi_axeZ;
628 passage(2,2) = cos_th_axeZ;
629
630 passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0);
631 passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0);
632 passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0);
633
634 // passage.Print(cout);
635 // cout << " fin calcul passage " << endl;
636
637 return passage;
638
639
640}
641
642/*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY)
643
644 angle range of tthe map (angles in degrees)
645\param angleX phi-like angle
646\param angleX theta-like angle
647*/
648template<class T>
649void LocalMap<T>::SetSize(double angleX,double angleY)
650{
651 if (!pixelSized_) initializationError();
652
653 if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.)
654 {
655 throw ParmError("LocalMap::SetSize extension angle out of range");
656 }
657
658 angleDegresX_ = angleX;
659 angleDegresY_ = angleY;
660 // angles par pixel, en radians
661 cout << " taille x " << nSzX_ <<" taille y " << nSzY_ << endl;
662 deltaPhi_ = angleX*Pi/(180.*nSzX_);
663 deltaTheta_ = angleY*Pi/(180.*nSzY_);
664
665 if (angleSized_)
666 {
667 cout << " WARNING LocalMap::SetSize ; angle resizing of an already sized local map " << endl;
668 }
669 angleSized_ = true;
670
671}
672
673
674
675/*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const
676
677Projection to a spherical map
678*/
679template<class T>
680void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const
681{
682 double theta, phi;
683 int it, ip;
684 for (it = 0; it < nSzY_; it++)
685 {
686 for (ip = 0; ip < nSzX_; ip++)
687 {
688 PixThetaPhi(ip,it, theta, phi);
689 sphere(theta,phi)= pixels_(it, ip);
690 }
691 }
692}
693
694
695
696// Titre Private Methods
697//++
698template<class T>
699void LocalMap<T>::InitNul()
700//
701// set attributes to zero
702//--
703{
704
705 pixelSized_ = false;
706 angleSized_ = false;
707 originSet_ = false;
708
709 nSzX_ = 0;
710 nSzY_ = 0;
711 angleDegresX_ = 0.;
712 angleDegresY_ = 0.;
713 thetaDegresC_ = 0.;
714 phiDegresC_ = 0.;
715 x0_ = 0;
716 y0_ = 0;
717 angleDegres_ = 0.;
718
719
720
721 nPix_ = 0;
722
723 thetaC_ = 0.;
724 phiC_ = 0.;
725 csthC_ = 1.;
726 snthC_ = 0.;
727 csphC_ = 1.;
728 snphC_ = 0.;
729 XC_ = 0.;
730 YC_ = 0.;
731 ZC_ = 1.;
732
733 angle_ = 0.;
734 cosAngle_ = 1.;
735 sinAngle_ = 0.;
736 deltaPhi_ = 0.;
737 deltaTheta_ =0.;
738 SetThrowExceptionWhenOutofMapFlag(false); // Genere des exceptions si theta-phi out of range
739}
740
741
742/*! \fn void SOPHYA::LocalMap::Getij(int_4 k,int_4& i,int_4& j) const
743
744 \return 2 indices corresponding to the pixel number k
745*/
746template<class T>
747void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
748{
749 i= (k+1)%nSzX_-1;
750 if(i == -1) i= nSzX_-1;
751 j= (k-i+2)/nSzX_;
752}
753
754
755
756
757
758
759template<class T>
760void LocalMap<T>::print(ostream& os) const
761{
762 os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
763 os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl;
764 os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
765 os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl;
766 os<<" deltaPhi_= "<< deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl;
767 os <<endl;
768
769 os << " contenu de pixels : ";
770 for(int i=0; i < nPix_; i++)
771 {
772 if(i%5 == 0) os << endl;
773 int_4 ik,jk;
774 Getij(i,ik,jk);
775 os << pixels_(jk,ik) <<", ";
776 }
777 os << endl;
778}
779
780
781template<class T>
782void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
783{
784
785 pixelSized_ = lm.pixelSized_;
786 angleSized_ = lm.angleSized_;
787 originSet_ = lm.originSet_ ;
788
789
790 nSzX_ = lm.nSzX_;
791 nSzY_ = lm.nSzY_;
792 nPix_ = lm.nPix_;
793 x0_ = lm.x0_;
794 y0_ = lm.y0_;
795
796 thetaC_ = lm.thetaC_;
797 phiC_ = lm.phiC_;
798 csthC_ = lm.csthC_;
799 snthC_ = lm.snthC_;
800 csphC_ = lm.csphC_;
801 snphC_ = lm.snphC_;
802 XC_ = lm.XC_;
803 YC_ = lm.YC_;
804 ZC_ = lm.ZC_;
805
806 angle_= lm.angle_;
807 cosAngle_ = lm.cosAngle_;
808 sinAngle_ = lm.sinAngle_;
809 deltaPhi_ = lm. deltaPhi_;
810 deltaTheta_ = lm.deltaTheta_;
811}
812
813template<class T>
814void LocalMap<T>::initializationError() const
815{
816 cout << endl;
817 if (!pixelSized_) cout << " LocalMap::initializationError() ; pixel sizing is missing " << endl;
818 if (!angleSized_ ) cout << " LocalMap::initializationError() ; angle sizing is missing " << endl;
819 if (!originSet_ ) cout << " LocalMap::initializationError() ; origin of map is not set " << endl;
820 throw PException("LocalMap::initializationError() : bad initialization of the local map ");
821
822
823}
824
825
826// ...... Operations de calcul ......
827
828
829/*! \fn void SOPHYA::LocalMap::SetT(T a)
830 Fill a LocalMap with a constant value \b a
831 */
832template <class T>
833LocalMap<T>& LocalMap<T>::SetT(T a)
834{
835 if (NbPixels() < 1)
836 throw RangeCheckError("LocalMap<T>::SetT(T ) - LocalMap not dimensionned ! ");
837 pixels_ = a;
838 return (*this);
839}
840
841/*! \fn void SOPHYA::LocalMap::Add(T a)
842Add a constant value \b x to a LocalMap
843 */
844template <class T>
845LocalMap<T>& LocalMap<T>::Add(T a)
846 {
847 if (NbPixels()< 1)
848 throw RangeCheckError("LocalMap<T>::Add(T ) - LocalMap not dimensionned ! ");
849 pixels_ += a;
850 return (*this);
851}
852
853/*! \fn void SOPHYA::LocalMap::Sub(T a,bool fginv)
854
855Substract a constant value \b a to a LocalMap
856
857*/
858template <class T>
859LocalMap<T>& LocalMap<T>::Sub(T a,bool fginv)
860{
861 if (NbPixels()< 1)
862 throw RangeCheckError("LocalMap<T>::Sub(T ) - LocalMap not dimensionned ! ");
863 pixels_.Sub(a,fginv);
864 return (*this);
865}
866
867/*! \fn void SOPHYA::LocalMap::Mul(T a)
868mutiply a LocalMap by a constant value \b a
869*/
870template <class T>
871LocalMap<T>& LocalMap<T>::Mul(T a)
872{
873 if (NbPixels()< 1)
874 throw RangeCheckError("LocalMap<T>::Mul(T ) - LocalMap not dimensionned ! ");
875 pixels_ *= a;
876 return (*this);
877}
878
879/*! \fn void SOPHYA::LocalMap::Div(T a)
880divide a LocalMap by a constant value \b a
881*/
882template <class T>
883LocalMap<T>& LocalMap<T>::Div(T a)
884{
885 if (NbPixels()< 1)
886 throw RangeCheckError("LocalMap<T>::Div(T ) - LocalMap not dimensionned ! ");
887 pixels_ /= a;
888 return (*this);
889}
890
891// >>>> Operations avec 2nd membre de type LocalMap
892/*! \fn void SOPHYA::LocalMap::AddElt(const LocalMap<T>& a)
893Add two LocalMap
894 */
895template <class T>
896LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a)
897{
898 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
899 {
900 throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
901 }
902 pixels_ += a.pixels_;
903 return (*this);
904}
905
906/*! \fn void SOPHYA::LocalMap::SubElt(const LocalMap<T>& a)
907Substract two LocalMap
908 */
909template <class T>
910LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a)
911{
912 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
913 {
914 throw(SzMismatchError("LocalMap<T>::SubElt(const LocalMap<T>&) SizeMismatch")) ;
915 }
916 pixels_ -= a.pixels_;
917 return (*this);
918}
919
920/*! \fn void SOPHYA::LocalMap::MulElt(const LocalMap<T>& a)
921Multiply two LocalMap (elements by elements)
922 */
923template <class T>
924LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a)
925{
926 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
927 {
928 throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ;
929 }
930 // pixels_ *= a.pixels_;
931 pixels_.DataBlock() *= a.pixels_.DataBlock();
932 return (*this);
933}
934
935/*! \fn void SOPHYA::LocalMap::DivElt(const LocalMap<T>& a)
936Divide two LocalMaps (elements by elements) - No protection for divide by 0
937*/
938template <class T>
939LocalMap<T>& LocalMap<T>::DivElt(const LocalMap<T>& a)
940{
941 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
942 {
943 throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ;
944 }
945 // pixels_ /= a.pixels_;
946 pixels_.DataBlock() /= a.pixels_.DataBlock();
947 return (*this);
948}
949
950
951
952
953
954
955#ifdef __CXX_PRAGMA_TEMPLATES__
956#pragma define_template LocalMap<int_4>
957#pragma define_template LocalMap<r_8>
958#pragma define_template LocalMap<r_4>
959#pragma define_template LocalMap< complex<r_8> >
960#pragma define_template LocalMap< complex<r_4> >
961#endif
962#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
963namespace SOPHYA {
964template class LocalMap<int_4>;
965template class LocalMap<r_8>;
966template class LocalMap<r_4>;
967template class LocalMap< complex<r_8> >;
968template class LocalMap< complex<r_4> >;
969}
970#endif
Note: See TracBrowser for help on using the repository browser.