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

Last change on this file since 2763 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 25.0 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_) 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_) 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 (mInfo_) {delete mInfo_; mInfo_ = NULL;}
239 if (a.mInfo_) 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 (mInfo_) {delete mInfo_; mInfo_ = NULL;}
247 if (a.mInfo_) 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 (mInfo_) delete mInfo_;
274 mInfo_ = NULL;
275 if (a.mInfo_) 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 XP = XC_ - dx*snphC_ - dy*csthC_*csphC_;
498 YP = YC_ + dx*csphC_ - dy*csthC_*snphC_;
499 ZP = ZC_ + dy*snthC_;
500
501 // on renormalise pour eviter les probleme de precision lors
502 // de la prise ulterieure de lignes trigonometriques
503 double norme = sqrt(XP*XP + YP*YP + ZP*ZP);
504 XP /= norme;
505 YP /= norme;
506 ZP /= norme;
507}
508
509/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,double angle)
510 set the referential of the map (angles in degrees)
511
512 \param theta0
513 \param phi0 celestial coordinates attributed to center pixel: x0=siz_x/2, y0=siz_y/2
514\param angle angle between map referential and plane-coordinate system (see class description)
515*/
516template<class T>
517void LocalMap<T>::SetOrigin(double theta0,double phi0,double angle)
518{
519 SetOrigin(theta0, phi0, nSzX_/2, nSzY_/2, angle);
520}
521
522/*! \fn void SOPHYA::LocalMap::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
523 set the referential of the map (angles in degrees)
524
525 \param theta0
526 \param phi0 celestial coordinates attributed to center pixel: (x0,y0)
527\param angle angle between map referential and plane-coordinate system (see class description)
528
529*/
530template<class T>
531void LocalMap<T>::SetOrigin(double theta0,double phi0,int_4 x0,int_4 y0,double angle)
532{
533
534 if ( theta0 < 0. || theta0 > 180. || phi0 < 0. || phi0 > 360. || angle < -90. || angle > 90.)
535 {
536 throw ParmError("LocalMap::SetOrigin angle out of range");
537 }
538 SetCoorC(theta0,phi0);
539 angleDegres_ = angle;
540 // en radians
541 angle_ = angle*Pi/180.;
542 x0_= x0;
543 y0_= y0;
544 cosAngle_= cos(angle_);
545 sinAngle_= sin(angle_);
546
547 if (originSet_)
548 {
549 cout << " WARNING: LocalMap<T>::SetOrigin() : reset origine of a local map which had already an origin " << endl;
550 }
551 originSet_ = true;
552}
553
554template<class T>
555void LocalMap<T>::SetCoorC(double theta0, double phi0)
556{
557
558 thetaDegresC_ = theta0;
559 phiDegresC_ = phi0;
560
561 // passage en radians
562 thetaC_= theta0*Pi/180.;
563 phiC_ = phi0*Pi/180.;
564 csthC_ = cos(thetaC_);
565 snthC_ = sin(thetaC_);
566 csphC_ = cos(phiC_);
567 snphC_ = sin(phiC_);
568 XC_ = snthC_*csphC_;
569 YC_ = snthC_*snphC_;
570 ZC_ = csthC_;
571}
572
573
574// angles en RADIANS
575template<class T>
576TMatrix<double> LocalMap<T>::CalculMatricePassage()
577{
578 cout << " calcul matrice de passage " << endl;
579 if (! LocalMap_isDone()) initializationError();
580 TMatrix<double> passage(3,3);
581 double cos_th_axeZ;
582 double sin_th_axeZ;
583 double cos_phi_axeZ;
584 double sin_phi_axeZ;
585
586 double cth,sth, cdeltaPhi, phi, cphi, sphi;
587
588 if ( snthC_ <= 0.) // carte centree au pole
589 {
590 cos_th_axeZ = 1.;
591 sin_th_axeZ = 0.;
592 cos_phi_axeZ = 1.;
593 sin_phi_axeZ = 0.;
594
595 }
596 else
597 {
598 cth = cosAngle_*snthC_;
599 double arg = 1.-cth*cth;
600 if (arg <= 0. ) // carte centree sur l'equateur, sans rotation
601 {
602 cos_th_axeZ = 1.;
603 sin_th_axeZ = 0.;
604 cos_phi_axeZ = csphC_;
605 sin_phi_axeZ = snphC_;
606 }
607 else
608 {
609 sth = sqrt(arg);
610 cdeltaPhi = -csthC_*cth/(snthC_*sth);
611 if (cdeltaPhi < -1. ) cdeltaPhi = -1.;
612 if (cdeltaPhi > 1. ) cdeltaPhi = 1.;
613 phi = phiC_ + acos( cdeltaPhi );
614
615 cos_th_axeZ = cth;
616 sin_th_axeZ = sth;
617 cos_phi_axeZ = cos(phi);
618 sin_phi_axeZ = sin(phi);
619 }
620 }
621 passage(0,0) = snthC_*csphC_;
622 passage(1,0) = snthC_*snphC_;
623 passage(2,0) = csthC_;
624
625 passage(0,2) = sin_th_axeZ*cos_phi_axeZ;
626 passage(1,2) = sin_th_axeZ*sin_phi_axeZ;
627 passage(2,2) = cos_th_axeZ;
628
629 passage(0,1) = passage(1,2)*passage(2,0) - passage(2,2)*passage(1,0);
630 passage(1,1) = passage(2,2)*passage(0,0) - passage(0,2)*passage(2,0);
631 passage(2,1) = passage(0,2)*passage(1,0) - passage(1,2)*passage(0,0);
632
633 // passage.Print(cout);
634 // cout << " fin calcul passage " << endl;
635
636 return passage;
637
638
639}
640
641/*! \fn void SOPHYA::LocalMap::SetSize(double angleX,double angleY)
642
643 angle range of tthe map (angles in degrees)
644\param angleX phi-like angle
645\param angleX theta-like angle
646*/
647template<class T>
648void LocalMap<T>::SetSize(double angleX,double angleY)
649{
650 if (!pixelSized_) initializationError();
651
652 if ( angleX <= 0. || angleX > 180. || angleY <= 0. || angleY > 180.)
653 {
654 throw ParmError("LocalMap::SetSize extension angle out of range");
655 }
656
657 angleDegresX_ = angleX;
658 angleDegresY_ = angleY;
659 // angles par pixel, en radians
660 cout << " taille x " << nSzX_ <<" taille y " << nSzY_ << endl;
661 deltaPhi_ = angleX*Pi/(180.*nSzX_);
662 deltaTheta_ = angleY*Pi/(180.*nSzY_);
663
664 if (angleSized_)
665 {
666 cout << " WARNING LocalMap::SetSize ; angle resizing of an already sized local map " << endl;
667 }
668 angleSized_ = true;
669
670}
671
672
673
674/*! \fn void SOPHYA::LocalMap::ProjectionToSphere(SphericalMap<T>& sphere) const
675
676Projection to a spherical map
677*/
678template<class T>
679void LocalMap<T>::ProjectionToSphere(SphericalMap<T>& sphere) const
680{
681 double theta, phi;
682 int it, ip;
683 for (it = 0; it < nSzY_; it++)
684 {
685 for (ip = 0; ip < nSzX_; ip++)
686 {
687 PixThetaPhi(ip,it, theta, phi);
688 sphere(theta,phi)= pixels_(it, ip);
689 }
690 }
691}
692
693
694
695// Titre Private Methods
696//++
697template<class T>
698void LocalMap<T>::InitNul()
699//
700// set attributes to zero
701//--
702{
703
704 pixelSized_ = false;
705 angleSized_ = false;
706 originSet_ = false;
707
708 nSzX_ = 0;
709 nSzY_ = 0;
710 angleDegresX_ = 0.;
711 angleDegresY_ = 0.;
712 thetaDegresC_ = 0.;
713 phiDegresC_ = 0.;
714 x0_ = 0;
715 y0_ = 0;
716 angleDegres_ = 0.;
717
718
719
720 nPix_ = 0;
721
722 thetaC_ = 0.;
723 phiC_ = 0.;
724 csthC_ = 1.;
725 snthC_ = 0.;
726 csphC_ = 1.;
727 snphC_ = 0.;
728 XC_ = 0.;
729 YC_ = 0.;
730 ZC_ = 1.;
731
732 angle_ = 0.;
733 cosAngle_ = 1.;
734 sinAngle_ = 0.;
735 deltaPhi_ = 0.;
736 deltaTheta_ =0.;
737 SetThrowExceptionWhenOutofMapFlag(false); // Genere des exceptions si theta-phi out of range
738}
739
740
741/*! \fn void SOPHYA::LocalMap::Getij(int_4 k,int_4& i,int_4& j) const
742
743 \return 2 indices corresponding to the pixel number k
744*/
745template<class T>
746void LocalMap<T>::Getij(int_4 k,int_4& i,int_4& j) const
747{
748 i= (k+1)%nSzX_-1;
749 if(i == -1) i= nSzX_-1;
750 j= (k-i+2)/nSzX_;
751}
752
753
754
755
756
757
758template<class T>
759void LocalMap<T>::print(ostream& os) const
760{
761 os<<" SzX= "<<nSzX_<<", SzY= "<<nSzY_<<", NPix= "<<nPix_<<endl;
762 os<<" theta0= "<<thetaC_*180./Pi <<", phi0= "<<phiC_*180./Pi <<", angle= "<<angle_*180./Pi<<endl;
763 os<<" x0= "<<x0_<<", y0= "<<y0_<<endl;
764 os<<" cos= "<< cosAngle_ <<", & sin= "<<sinAngle_<<endl;
765 os<<" deltaPhi_= "<< deltaPhi_ <<", deltaTheta = "<< deltaTheta_ <<endl;
766 os <<endl;
767
768 os << " contenu de pixels : ";
769 for(int i=0; i < nPix_; i++)
770 {
771 if(i%5 == 0) os << endl;
772 int_4 ik,jk;
773 Getij(i,ik,jk);
774 os << pixels_(jk,ik) <<", ";
775 }
776 os << endl;
777}
778
779
780template<class T>
781void LocalMap<T>::recopierVariablesSimples(const LocalMap<T>& lm)
782{
783
784 pixelSized_ = lm.pixelSized_;
785 angleSized_ = lm.angleSized_;
786 originSet_ = lm.originSet_ ;
787
788
789 nSzX_ = lm.nSzX_;
790 nSzY_ = lm.nSzY_;
791 nPix_ = lm.nPix_;
792 x0_ = lm.x0_;
793 y0_ = lm.y0_;
794
795 thetaC_ = lm.thetaC_;
796 phiC_ = lm.phiC_;
797 csthC_ = lm.csthC_;
798 snthC_ = lm.snthC_;
799 csphC_ = lm.csphC_;
800 snphC_ = lm.snphC_;
801 XC_ = lm.XC_;
802 YC_ = lm.YC_;
803 ZC_ = lm.ZC_;
804
805 angle_= lm.angle_;
806 cosAngle_ = lm.cosAngle_;
807 sinAngle_ = lm.sinAngle_;
808 deltaPhi_ = lm. deltaPhi_;
809 deltaTheta_ = lm.deltaTheta_;
810}
811
812template<class T>
813void LocalMap<T>::initializationError() const
814{
815 cout << endl;
816 if (!pixelSized_) cout << " LocalMap::initializationError() ; pixel sizing is missing " << endl;
817 if (!angleSized_ ) cout << " LocalMap::initializationError() ; angle sizing is missing " << endl;
818 if (!originSet_ ) cout << " LocalMap::initializationError() ; origin of map is not set " << endl;
819 throw PException("LocalMap::initializationError() : bad initialization of the local map ");
820
821
822}
823
824
825// ...... Operations de calcul ......
826
827
828/*! \fn void SOPHYA::LocalMap::SetT(T a)
829 Fill a LocalMap with a constant value \b a
830 */
831template <class T>
832LocalMap<T>& LocalMap<T>::SetT(T a)
833{
834 if (NbPixels() < 1)
835 throw RangeCheckError("LocalMap<T>::SetT(T ) - LocalMap not dimensionned ! ");
836 pixels_ = a;
837 return (*this);
838}
839
840/*! \fn void SOPHYA::LocalMap::Add(T a)
841Add a constant value \b x to a LocalMap
842 */
843template <class T>
844LocalMap<T>& LocalMap<T>::Add(T a)
845 {
846 if (NbPixels()< 1)
847 throw RangeCheckError("LocalMap<T>::Add(T ) - LocalMap not dimensionned ! ");
848 pixels_ += a;
849 return (*this);
850}
851
852/*! \fn void SOPHYA::LocalMap::Sub(T a,bool fginv)
853
854Substract a constant value \b a to a LocalMap
855
856*/
857template <class T>
858LocalMap<T>& LocalMap<T>::Sub(T a,bool fginv)
859{
860 if (NbPixels()< 1)
861 throw RangeCheckError("LocalMap<T>::Sub(T ) - LocalMap not dimensionned ! ");
862 pixels_.Sub(a,fginv);
863 return (*this);
864}
865
866/*! \fn void SOPHYA::LocalMap::Mul(T a)
867mutiply a LocalMap by a constant value \b a
868*/
869template <class T>
870LocalMap<T>& LocalMap<T>::Mul(T a)
871{
872 if (NbPixels()< 1)
873 throw RangeCheckError("LocalMap<T>::Mul(T ) - LocalMap not dimensionned ! ");
874 pixels_ *= a;
875 return (*this);
876}
877
878/*! \fn void SOPHYA::LocalMap::Div(T a)
879divide a LocalMap by a constant value \b a
880*/
881template <class T>
882LocalMap<T>& LocalMap<T>::Div(T a)
883{
884 if (NbPixels()< 1)
885 throw RangeCheckError("LocalMap<T>::Div(T ) - LocalMap not dimensionned ! ");
886 pixels_ /= a;
887 return (*this);
888}
889
890// >>>> Operations avec 2nd membre de type LocalMap
891/*! \fn void SOPHYA::LocalMap::AddElt(const LocalMap<T>& a)
892Add two LocalMap
893 */
894template <class T>
895LocalMap<T>& LocalMap<T>::AddElt(const LocalMap<T>& a)
896{
897 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
898 {
899 throw(SzMismatchError("LocalMap<T>::AddElt(const LocalMap<T>&) SizeMismatch")) ;
900 }
901 pixels_ += a.pixels_;
902 return (*this);
903}
904
905/*! \fn void SOPHYA::LocalMap::SubElt(const LocalMap<T>& a)
906Substract two LocalMap
907 */
908template <class T>
909LocalMap<T>& LocalMap<T>::SubElt(const LocalMap<T>& a)
910{
911 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
912 {
913 throw(SzMismatchError("LocalMap<T>::SubElt(const LocalMap<T>&) SizeMismatch")) ;
914 }
915 pixels_ -= a.pixels_;
916 return (*this);
917}
918
919/*! \fn void SOPHYA::LocalMap::MulElt(const LocalMap<T>& a)
920Multiply two LocalMap (elements by elements)
921 */
922template <class T>
923LocalMap<T>& LocalMap<T>::MulElt(const LocalMap<T>& a)
924{
925 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
926 {
927 throw(SzMismatchError("LocalMap<T>::MulElt(const LocalMap<T>&) SizeMismatch")) ;
928 }
929 // pixels_ *= a.pixels_;
930 pixels_.DataBlock() *= a.pixels_.DataBlock();
931 return (*this);
932}
933
934/*! \fn void SOPHYA::LocalMap::DivElt(const LocalMap<T>& a)
935Divide two LocalMaps (elements by elements) - No protection for divide by 0
936*/
937template <class T>
938LocalMap<T>& LocalMap<T>::DivElt(const LocalMap<T>& a)
939{
940 if (nSzX_ != a.nSzX_ || nSzY_ != a.nSzY_)
941 {
942 throw(SzMismatchError("LocalMap<T>::DivElt(const LocalMap<T>&) SizeMismatch")) ;
943 }
944 // pixels_ /= a.pixels_;
945 pixels_.DataBlock() /= a.pixels_.DataBlock();
946 return (*this);
947}
948
949
950
951
952
953
954#ifdef __CXX_PRAGMA_TEMPLATES__
955#pragma define_template LocalMap<int_4>
956#pragma define_template LocalMap<r_8>
957#pragma define_template LocalMap<r_4>
958#pragma define_template LocalMap< complex<r_8> >
959#pragma define_template LocalMap< complex<r_4> >
960#endif
961#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
962template class LocalMap<int_4>;
963template class LocalMap<r_8>;
964template class LocalMap<r_4>;
965template class LocalMap< complex<r_8> >;
966template class LocalMap< complex<r_4> >;
967#endif
Note: See TracBrowser for help on using the repository browser.