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

Last change on this file since 3856 was 3836, checked in by ansari, 15 years ago

Declaration extern des classes templ des classes template avec instantiation explicite (avec flag NEED_EXT_DECL_TEMP) pour regler le pb de dynamic_cast sur Mac OS X 10.6, Reza 05/08/2010

File size: 25.2 KB
Line 
1#include "sopnamsp.h"
2#include "smathconst.h"
3#include <complex>
4#include "fiondblock.h"
5
6#define LOCALMAP_CC_BFILE // avoid extern template declarations
7#include "localmap.h"
8
9#include <string.h>
10#include <iostream>
11#include "timing.h"
12
13
14/*!
15 \class SOPHYA::LocalMap
16 \ingroup SkyMap
17 A local map is a 2 dimensional matrix, with ny rows and nx columns.
18 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).
19
20 Each pixel(ip, it) is defined by its "phi-like" index ip (column
21 index in the matrix) and its "theta-like" index it (row index in
22 the matrix). Index ip is associated with x-axis in a map-coordinate
23 system ; index it is associated with y-axis in the same map-coordinate system.
24
25 The map is supposed to lie in a plan tangent to the celestial sphere
26 at its origin, with spherical coordinates (theta0, phi0), whose pixel
27 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.
28
29 Each pixel has angleX/nx and angleY/ny, as angle extensions. So, in
30 map-coordinate system the pixel (i,j) has following coordinates :
31
32 x = (i-x0)*angleX/nx
33
34 y = (j-y0)*angleY/ny
35
36 (angles in radians)
37
38 The projection (method : ProjectionToSphere() ) of the map onto a
39 sphere is made by the following procedure :
40
41 the sphere is supposed to have radius=1. The map is
42 considered to be tangent to the sphere, at a point with (theta0, phi0)
43 spherical coodinates. A reference coordinate system (plane-coordinate
44 system) , is chosen with respect to the plane of the map with reference axes :
45
46 x-axis : vector tangent to a parallel at (theta0, phi0) on the sphere
47 (components in "3-dim cartesian system : -sin(phi0) ; cos(phi0) ; 0)
48
49 z-axis : vector-radius with 3-dim cartesian cordinates :
50 sin(theta0)*cos(phi0) ; sin(theta0*sin(phi0) ; cos(theta0)
51
52 y-axis : z-axis^x-axis : tangent to the meridian at (theta0, phi0)
53
54
55 note that the map-coordinate system may be rotated with respect to
56 plane-coordinate system (parameter "angle" below).
57
58 the projection of a map pixel is defined as the intersection of
59 the vector-radius, from sphere center to the pixel defined by
60 his coordinates in the plane-coordinate system (computed from x,y
61 above, with eventual rotation), with the sphere.
62
63 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.
64
65Example :
66
67\verbatim
68 LocalMap<r_4> lcm(300, 600, 10.,20., 90.,0.); // full cstr.
69\endverbatim
70
71defining 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 :
72
73\verbatim
74 LocalMap<r_4> lcm(300, 600); // partial cstr.
75 lcm.SetSize(10., 20.);
76 lcm.SetOrigin(90., 0.);
77\endverbatim
78
79as well as :
80
81
82\verbatim
83 LocalMap<r_4> lcm(300, 600, 10.,20., 90.,0., 0, 0); // full cstr.
84\endverbatim
85
86(same map, but with origin of coordinates at pixel (0,0) instead of (150, 300) as it was implicit above)
87
88is equivalent to :
89
90\verbatim
91 LocalMap<r_4> lcm(300, 600);
92 lcm.SetSize(10., 20.);
93lcm.SetOrigin(90., 0., 0,0);
94\endverbatim
95
96
97*/
98template<class T>
99LocalMap<T>::LocalMap() : pixels_()
100{
101 InitNul();
102}
103
104//! partial constructor of the local map
105/*! \fn void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny)
106 \param nx : number of pixels in x direction
107 \param ny : number of pixels in y direction
108
109must be followed by calls to the methods SetSize() and SetOrigin() in order the object become usable
110
111 */
112template<class T>
113LocalMap<T>::LocalMap(int_4 nx, int_4 ny)
114{
115 InitNul();
116 ReSize(nx, ny);
117 // nSzX_ = nx;
118 // nSzY_ = ny;
119 // nPix_= nx*ny;
120 // pixels_.ReSize(ny,nx);
121}
122
123//! full constructor of the local map
124/*! \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)
125 \param nx : number of pixels in x direction
126 \param ny : number of pixels in y direction
127 \param angleX : total angle aperture in x direction (degrees)
128 \param angleY : total angle aperture in y direction (degrees)
129 \param theta0,phi0 : spherical coordinates of reference point at which
130 the map is considered to be tangent to the sphere
131 \param x0, y0 : coordinates (in pixels) of the reference point just defined
132 \param angle : angle (degrees) of the rotation between x-axis of
133 map-coordinate system) and the tangent to parallel on
134 the sphere (default : 0.).
135 */
136template<class T>
137LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0,int_4 x0,int_4 y0,double angle)
138{
139 InitNul();
140 // nSzX_ = nx;
141 // nSzY_ = ny;
142 // nPix_= nx*ny;
143 // pixels_.ReSize(ny,nx);
144 ReSize(nx, ny);
145 SetSize(angleX, angleY);
146 SetOrigin(theta0, phi0, x0, y0, angle);
147}
148
149// void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
150
151//! standard constructor of the local map
152/*! \fn void SOPHYA::LocalMap::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
153 \param nx : number of pixels in x direction
154 \param ny : number of pixels in y direction
155 \param angleX : total angle aperture in x direction (degrees)
156 \param angleY : total angle aperture in y direction (degrees)
157 \param theta0,phi0 : spherical coordinates of reference point at which
158 the map is considered to be tangent to the sphere
159 \param angle : angle (degrees) of the rotation between x-axis of
160 map-coordinate system) and the tangent to parallel on
161 the sphere (default : 0.).
162 */
163template<class T>
164LocalMap<T>::LocalMap(int_4 nx, int_4 ny, double angleX,double angleY, double theta0,double phi0, double angle)
165{
166 InitNul();
167 // nSzX_ = nx;
168 // nSzY_ = ny;
169 // nPix_= nx*ny;
170 // pixels_.ReSize(ny,nx);
171 ReSize(nx, ny);
172 SetSize(angleX, angleY);
173 SetOrigin(theta0, phi0, angle);
174}
175
176//! copy constructor
177/*! \fn void SOPHYA::LocalMap::LocalMap(const LocalMap<T>& lm, bool share)
178 \param share : if true, share data. If false copy data
179 */
180template<class T>
181LocalMap<T>::LocalMap(const LocalMap<T>& lm, bool share)
182 : pixels_(lm.pixels_, share)
183{
184
185 if(lm.mInfo_) this->mInfo_= new DVList(*lm.mInfo_);
186 recopierVariablesSimples(lm);
187}
188
189//! copy constructor
190/*! \fn void SOPHYA::LocalMap::LocalMap(const LocalMap<T>& lm)
191 \warning datas are \b SHARED with \b lm.
192 \sa TMatrix::TMatrix(const TMatrix<T>&)
193*/
194template<class T>
195LocalMap<T>::LocalMap(const LocalMap<T>& lm)
196 : pixels_(lm.pixels_)
197
198{
199
200 if(lm.mInfo_) this->mInfo_= new DVList(*lm.mInfo_);
201 recopierVariablesSimples(lm);
202}
203
204//! destructor
205/*! \fn void SOPHYA::LocalMap::~LocalMap()
206
207 */
208template<class T>
209LocalMap<T>::~LocalMap() {;}
210
211
212
213/*! \fn void SOPHYA::LocalMap::ReSize(int_4 nx, int_4 ny)
214
215 Resize storage area for pixels
216\param nx
217\param ny new pixel numbers
218*/
219template<class T>
220void LocalMap<T>::ReSize(int_4 nx, int_4 ny)
221{
222 // angles par pixel, en radians
223 deltaPhi_ *= nSzX_/nx;
224 deltaTheta_ *= nSzY_/ny;
225
226 nSzX_ = nx;
227 nSzY_ = ny;
228 nPix_= nx*ny;
229 pixels_.ReSize(ny,nx);
230 pixelSized_ = true;
231}
232
233////////////////////////// methodes de copie/share
234
235template<class T>
236void LocalMap<T>::CloneOrShare(const LocalMap<T>& a)
237{
238 recopierVariablesSimples(a);
239 pixels_.CloneOrShare(a.pixels_);
240 if (this->mInfo_) {delete this->mInfo_; this->mInfo_ = NULL;}
241 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
242}
243template<class T>
244void LocalMap<T>::Share(const LocalMap<T>& a)
245{
246 recopierVariablesSimples(a);
247 pixels_.Share(a.pixels_);
248 if (this->mInfo_) {delete this->mInfo_; this->mInfo_ = NULL;}
249 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
250}
251
252template<class T>
253LocalMap<T>& LocalMap<T>::CopyElt(const LocalMap<T>& a)
254{
255 if (NbPixels() < 1)
256 throw RangeCheckError("LocalMap<T>::CopyElt(const LocalMap<T>& ) - Not Allocated Array ! ");
257 if (NbPixels() != a.NbPixels())
258 throw(SzMismatchError("LocalMap<T>::CopyElt(const LocalMap<T>&) SizeMismatch")) ;
259 recopierVariablesSimples(a);
260 pixels_ = a.pixels_;
261 return(*this);
262
263}
264
265template<class T>
266LocalMap<T>& LocalMap<T>::Set(const LocalMap<T>& a)
267 {
268 if (this != &a)
269 {
270 if (a.NbPixels() < 1)
271 throw RangeCheckError("LocalMap<T>::Set(a ) - Array a not allocated ! ");
272 if (NbPixels() < 1) CloneOrShare(a);
273 else CopyElt(a);
274 if (this->mInfo_) delete this->mInfo_;
275 this->mInfo_ = NULL;
276 if (a.mInfo_) this->mInfo_ = new DVList(*(a.mInfo_));
277 }
278 return(*this);
279 }
280
281
282/*! \fn int_4 SOPHYA::LocalMap::NbPixels() const
283
284 \return number of pixels
285*/
286template<class T>
287int_4 LocalMap<T>::NbPixels() const
288{
289 return(nPix_);
290}
291
292/*! \fn T& SOPHYA::LocalMap::PixVal(int_4 k)
293
294 \return value of pixel with index k
295*/
296template<class T>
297T& LocalMap<T>::PixVal(int_4 k)
298{
299 if((k < 0) || (k >= nPix_))
300 {
301 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
302 }
303 //
304 int_4 i,j;
305 Getij(k,i,j);
306 return(pixels_(j,i));
307
308 //
309}
310
311/*! \fn T const& SOPHYA::LocalMap::PixVal(int_4 k) const
312 const version of previous method
313*/
314template<class T>
315T const& LocalMap<T>::PixVal(int_4 k) const
316{
317 if((k < 0) || (k >= nPix_))
318 {
319 throw RangeCheckError("LocalMap::PIxVal Pixel index out of range ");
320 }
321 //
322 int_4 i,j;
323 Getij(k,i,j);
324 return(pixels_(j,i));
325}
326
327/*! \fn bool SOPHYA::LocalMap::ContainsSph(double theta, double phi) const
328 \return true if teta,phi in map
329 <b> Not yet implemented </b>
330*/
331template<class T>
332bool LocalMap<T>::ContainsSph(double theta, double phi) const
333{
334// $CHECK$ Reza 11/11/99 - A modifier
335 throw NotAvailableOperation("LocalMap<T>::ContainsSph() - Not yet implemented !");
336 return(true);
337}
338
339/*! \fn int_4 SOPHYA::LocalMap::PixIndexSph(double theta,double phi) const
340
341 angles in radians
342 \return index of the pixel with spherical coordinates (theta,phi)
343*/
344template<class T>
345int_4 LocalMap<T>::PixIndexSph(double theta,double phi) const
346{
347 int_4 i,j;
348
349 if (! LocalMap_isDone()) initializationError();
350 double csTheta = cos(theta);
351 double snTheta = sin(theta);
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 // Aout07 : Correction -dy change en +dy suite message S.Plaszczynski du 12/07/07 pour XP et YP (Reza)
497 XP = XC_ - dx*snphC_ + dy*csthC_*csphC_; // Aout07: -dy change en +dy (Rz/SP)
498 YP = YC_ + dx*csphC_ + dy*csthC_*snphC_; // Aout07: -dy change en +dy (Rz/SP)
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;
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)
962namespace SOPHYA {
963template class LocalMap<int_4>;
964template class LocalMap<r_8>;
965template class LocalMap<r_4>;
966template class LocalMap< complex<r_8> >;
967template class LocalMap< complex<r_4> >;
968}
969#endif
Note: See TracBrowser for help on using the repository browser.