source: Sophya/trunk/SophyaPI/PIext/nomskymapadapter.cc@ 594

Last change on this file since 594 was 594, checked in by ercodmgr, 26 years ago

finalisation interfacage TMatrix, PixelMap - Reza 17/11/99

File size: 7.9 KB
RevLine 
[585]1#include "machdefs.h"
2#include <stdlib.h>
[594]3#include <math.h>
[585]4#include <typeinfo>
5#include <iostream.h>
6#include <string>
7#include <complex>
8
9#include "nomskymapadapter.h"
10#include "spherethetaphi.h"
11#include "spheregorski.h"
12#include "localmap.h"
[594]13#include "pitvmaad.h"
14#include "complexios.h"
[585]15
[594]16// Classe array adapter pour localMap
17template <class T>
18class LocalMapArrAdapter : public P2DArrayAdapter {
19public:
20 LocalMapArrAdapter(LocalMap<T>* lm, bool d=false) :
21 P2DArrayAdapter(lm->XSize(), lm->YSize())
22 { ad = d; map = lm; }
[585]23
[594]24 virtual ~LocalMapArrAdapter() { if (ad) delete map; }
25 virtual double Value(int ix, int iy) { return((*map)(ix, iy)); }
26
27protected :
28 bool ad;
29 LocalMap<T>* map;
30};
31
32/* --Methode-- */
33double LocalMapArrAdapter< complex<float> >::Value(int ix, int iy)
34{
35double re,im;
36re = (*map)(iy, ix).real();
37im = (*map)(iy, ix).imag();
38return(sqrt(re*re+im*im));
39}
40/* --Methode-- */
41double LocalMapArrAdapter< complex<double> >::Value(int ix, int iy)
42{
43double re,im;
44re = (*map)(iy, ix).real();
45im = (*map)(iy, ix).imag();
46return(sqrt(re*re+im*im));
47}
48
[585]49//----------------------------------------------------------------
50// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet PixelMap<T>
51//----------------------------------------------------------------
52
53
54/* --Methode-- */
55template <class T>
56NOMAdapter_PixelMap<T>::NOMAdapter_PixelMap(PixelMap<T> * o)
[594]57 : NObjMgrAdapter(o)
[585]58{
59mMap = o;
60}
61
62/* --Methode-- */
63template <class T>
64NOMAdapter_PixelMap<T>::~NOMAdapter_PixelMap()
65{
66}
67
68/* --Methode-- */
69template <class T>
70NObjMgrAdapter* NOMAdapter_PixelMap<T>::Clone(AnyDataObj* o)
71{
72PixelMap<T>* m = dynamic_cast<PixelMap<T> *>(o);
73if (m) return ( new NOMAdapter_PixelMap<T>(m) );
74return ( new NObjMgrAdapter(o) );
75}
76
77/* --Methode-- */
78template <class T>
79AnyDataObj* NOMAdapter_PixelMap<T>::GetCopyObj()
80{
81LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
82if (lm != NULL) return( new LocalMap<T>(*lm) );
83SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
84if (st != NULL) return( new SphereThetaPhi<T>(*st) );
85SphereGorski<T>* sg = dynamic_cast< SphereGorski<T> * >(mMap);
86if (sg != NULL) return( new SphereGorski<T>(*sg) );
87return(NULL);
88}
89
90/* --Methode-- */
91template <class T>
92void NOMAdapter_PixelMap<T>::SavePPF(POutPersist& pos, string const & nom)
93{
94LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
95if (lm != NULL) {
96 FIO_LocalMap<T> fio(lm);
97 fio.Write(pos, nom);
98 return;
99 }
100SphereThetaPhi<T>* st = dynamic_cast< SphereThetaPhi<T> * >(mMap);
101if (st != NULL) {
102 FIO_SphereThetaPhi<T> fio(st);
103 fio.Write(pos, nom);
104 return;
105 }
106SphereGorski<T>* sg = dynamic_cast< SphereGorski<T> * >(mMap);
107if (sg != NULL) {
108 FIO_SphereGorski<T> fio(sg);
109 fio.Write(pos, nom);
110 return;
111 }
112string s = typeid(*mMap).name();
113cout << "NOMAdapter_PixelMap<T>::SavePPF() - Error : Not supported for " << s << endl;
114}
115
116/* --Methode-- */
117template <class T>
118void NOMAdapter_PixelMap<T>::Print(ostream& os)
119{
120string s = typeid(*mMap).name();
[594]121T moy, sig;
122MeanSig(moy, sig);
[585]123cout << "SkyMap Type: " << s << " NbPixels= " << mMap->NbPixels() << endl;
[594]124cout << " Mean= " << moy << " Sig2= " << sig << endl;
[585]125}
126
127
128/* --Methode-- */
129template <class T>
130P2DArrayAdapter* NOMAdapter_PixelMap<T>::Get2DArray(string &)
131{
[594]132LocalMap<T>* lm = dynamic_cast< LocalMap<T> * >(mMap);
133if (lm != NULL) return(new LocalMapArrAdapter<T>(lm, false));
134int nr = 250;
135int nc = 500;
136SphericalMap<T>* sm = dynamic_cast< SphericalMap<T> *>(mMap);
137if (sm != NULL) { nr = sqrt(0.75*mMap->NbPixels()); nc = 2*nr; }
138TMatrix<T> * mtx = new TMatrix<T>(nr, nc);
139Project_Mol(*mtx);
140return (new POTMatrixAdapter<T>(mtx, true) );
[585]141}
142
143/* --Methode-- */
144template <class T>
145NTupleInterface* NOMAdapter_PixelMap<T>::GetNTupleInterface(bool& adel)
146{
147adel = true;
148return( new NTupInt_PixelMap<T>(mMap) );
149}
150
[594]151/* --Methode-- */
152template <class T>
153void NOMAdapter_PixelMap<T>::MeanSig(T& gmoy, T& gsig)
154{
155 gmoy=0.;
156 gsig = 0.;
157 T valok;
158 for(int k=0; k<mMap->NbPixels(); k++) {
159 valok = (*mMap)(k);
160 gmoy += valok; gsig += valok*valok;
161 }
162 gmoy /= (T)mMap->NbPixels();
163 gsig = gsig/(T)mMap->NbPixels() - gmoy*gmoy;
[585]164
[594]165}
[585]166
[594]167/* --Methode-- */
168template <class T>
169void NOMAdapter_PixelMap<T>::Project_Mol(TMatrix<T> & mtx, T defval)
170{
171 r_8 xa, yd, teta,phi, facteur;
172 int_4 l,c,k;
173 int_4 nl = mtx.NRows();
174 int_4 nc = mtx.NCols();
175 mtx.Reset(defval); // On met tout a defval
176// cout << " NRows= " << nl << " NCols= " << nc << endl;
177 for(l=0; l<nl; l++) {
178 yd = (r_8)(l+0.5)/(r_8)nl-0.5;
179 facteur=2.*M_PI/sin(acos((double)yd*2));
180 teta = (yd+0.5)*Pi;
181 // teta = (0.5-yd)*M_PI;
182 for(c=0; c<nc; c++) {
183 xa = (r_8)(c+0.5)/(r_8)nc-0.5;
184 phi = xa*facteur+M_PI;
185 if ( (phi <= 2*M_PI) && (phi >= 0.) ) {
186 k = mMap->PixIndexSph(teta, phi);
187 mtx(l,c) = (*mMap)(k);
188 }
189 }
190 }
191}
192
[585]193// -------------------------------------------------------------
194
195/* --Methode-- */
196template <class T>
197NTupInt_PixelMap<T>::NTupInt_PixelMap(PixelMap<T>* m)
198{
199mMap = m;
200}
201
202/* --Methode-- */
203template <class T>
204NTupInt_PixelMap<T>::~NTupInt_PixelMap()
205{
206}
207
208/* --Methode-- */
209template <class T>
210uint_4 NTupInt_PixelMap<T>::NbLines() const
211{
212return( mMap->NbPixels() );
213}
214
215/* --Methode-- */
216template <class T>
217uint_4 NTupInt_PixelMap<T>::NbColumns() const
218{
219return(8);
220}
221
222/* --Methode-- */
223template <class T>
224r_8* NTupInt_PixelMap<T>::GetLineD(int n) const
225{
226int i;
227if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
228 for(i=0; i<8; i++) mRet[i] = 0.;
229else {
230 double teta,phi;
231 mMap->PixThetaPhi(n, teta, phi);
232 mRet[0] = n; mRet[1] = mMap->PixVal(n);
233 mRet[2] = mRet[1]; mRet[3] = 0.;
234 mRet[4] = mRet[1]; mRet[5] = 0.;
235 mRet[6] = teta; mRet[7] = phi;
236 }
237return(mRet);
238}
239
240/* --Methode-- */
241template <class T>
242string NTupInt_PixelMap<T>::VarList_C(const char* nx) const
243{
244string nomx;
245if (nx) nomx = nx;
246else nomx = "_xh_";
247string vardec = "double i,k,val,real,imag,mod,phas,teta,phi; \n";
248vardec += "i = " + nomx + "[0]; k = " + nomx + "[0]; val = " + nomx + "[1]; \n";
249vardec += "real = " + nomx + "[2]; imag = " + nomx + "[3]; \n";
250vardec += "mod = " + nomx + "[4]; phas = " + nomx + "[5]; \n";
251vardec += "teta = " + nomx + "[6]; phi = " + nomx + "[7]; \n";
252return(vardec);
253}
254
255r_8* NTupInt_PixelMap< complex<float> >::GetLineD(int n) const
256{
257int i;
258if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
259 for(i=0; i<8; i++) mRet[i] = 0.;
260else {
261 double teta,phi;
262 mMap->PixThetaPhi(n, teta, phi);
263 mRet[0] = n;
264 mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
265 mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
266 mRet[5] = atan2(mRet[3], mRet[2]);
267 mRet[6] = teta; mRet[7] = phi;
268 }
269return(mRet);
270}
271
272r_8* NTupInt_PixelMap< complex<double> >::GetLineD(int n) const
273{
274int i;
275if ((n < 0) || (n >= (int)(mMap->NbPixels()) ))
276 for(i=0; i<8; i++) mRet[i] = 0.;
277else {
278 double teta,phi;
279 mMap->PixThetaPhi(n, teta, phi);
280 mRet[0] = n;
281 mRet[2] = mMap->PixVal(n).real(); mRet[3] = mMap->PixVal(n).imag();
282 mRet[1] = mRet[4] = sqrt(mRet[2]*mRet[2]+mRet[3]*mRet[3]);
283 mRet[5] = atan2(mRet[3], mRet[2]);
284 mRet[6] = teta; mRet[7] = phi;
285 }
286return(mRet);
287}
288
289
290#ifdef __CXX_PRAGMA_TEMPLATES__
291#pragma define_template NOMAdapter_PixelMap<r_4>
292#pragma define_template NOMAdapter_PixelMap<r_8>
293#pragma define_template NOMAdapter_PixelMap< complex<float> >
294#pragma define_template NOMAdapter_PixelMap< complex<double> >
295#pragma define_template NTupInt_PixelMap<r_4>
296#pragma define_template NTupInt_PixelMap<r_8>
297#pragma define_template NTupInt_PixelMap< complex<float> >
298#pragma define_template NTupInt_PixelMap< complex<double> >
299#endif
300
301#if defined(ANSI_TEMPLATES)
302template class NOMAdapter_PixelMap<r_4>;
303template class NOMAdapter_PixelMap<r_8>;
304template class NOMAdapter_PixelMap< complex<float> >;
305template class NOMAdapter_PixelMap< complex<double> >;
306template class NTupInt_PixelMap<r_4>;
307template class NTupInt_PixelMap<r_8>;
308template class NTupInt_PixelMap< complex<float> >;
309template class NTupInt_PixelMap< complex<double> >;
310#endif
Note: See TracBrowser for help on using the repository browser.