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

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

amelioration de la projection de localmap

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