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

Last change on this file since 2213 was 2198, checked in by lemeur, 23 years ago

toilette d'ete

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