source: Sophya/trunk/SophyaLib/SkyMap/pixelmap.h@ 3174

Last change on this file since 3174 was 2978, checked in by ansari, 19 years ago

1/ Mise en place de la prise en charge du schema de pixelisation NESTED dans
SphereHEALPix<T>
2/ petites corrections sur PixelMap<T> et cartes speheriques

Reza 21/06/2006

File size: 4.8 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2#ifndef PIXELMAP_SEEN
3#define PIXELMAP_SEEN
4
5#include "ppersist.h"
6#include "dvlist.h"
7#include "spherepos.h"
8#include "datatype.h"
9#include <iostream>
10#include <typeinfo>
11
12namespace SOPHYA {
13
14/*!
15 \class PixelMap
16 \ingroup SkyMap
17 General map of pixels on part of sphere or whole sphere.
18
19 Class hierarchy :
20\verbatim
21 PixelMap
22 SphericalMap
23 SphereThetaPhi
24 SphereHEALPix
25 SphereIco
26 LocalMap
27\endverbatim
28*/
29
30template<class T>
31class PixelMap : public AnyDataObj
32{
33public:
34
35 PixelMap(SphereCoordSys* cs = NULL) : mInfo_(NULL)
36 { if (cs) cs_ = cs; else cs_ = new SphereCoordSys; }
37virtual ~PixelMap()
38 { if (mInfo_) delete mInfo_; if (cs_) delete cs_; }
39
40// Set/Change/Get the coordinate system
41virtual void SetCoordSys(SphereCoordSys* cs)
42 { if (cs) { delete cs_; cs_ = cs; } }
43inline SphereCoordSys* GetCoordSys() const { return(cs_); }
44
45/*! Number of pixels */
46virtual int_4 NbPixels() const=0;
47
48/*! Value of pixel number k */
49virtual T& PixVal(int_4 k)=0;
50virtual T const& PixVal(int_4 k) const=0;
51
52// Map s coverage
53virtual bool ContainsSph(double theta, double phi) const=0;
54virtual bool Contains(const SpherePosition& spos) const;
55
56/*! Index of pixel at (theta,phi) */
57virtual int_4 PixIndexSph(double theta, double phi) const=0;
58// Index of pixel at a sky-position
59virtual int_4 PixIndex(const SpherePosition& spos);
60
61/*! Value of pixel number at (theta,phi) */
62virtual T& PixValSph(double theta, double phi)
63 {return PixVal(PixIndexSph(theta,phi));}
64virtual T const& PixValSph(double theta, double phi) const
65 {return PixVal(PixIndexSph(theta,phi));}
66
67/*! Spherical coordinates of center of pixel number k */
68virtual void PixThetaPhi(int_4 k, double& theta, double& phi) const=0;
69
70/*! provides a integer characterizing the pixelization refinement
71 (depending of the type of the map)
72*/
73virtual int_4 SizeIndex() const=0;
74virtual string TypeOfMap() const =0;
75
76/*! Pixel (steradians) */
77virtual double PixSolAngle(int_4 k) const =0;
78
79/*! Setting blockdata to temporary (see ndatablock documentation) */
80virtual void SetTemp(bool temp=false) const =0;
81
82
83/*! Overloading of () to access pixel number k. */
84inline T& operator()(int_4 k) {return(PixVal(k));}
85inline T const& operator()(int_4 k) const {return(PixVal(k));}
86
87// Overloading of () to access pixel at a sky position .
88inline T& operator()(const SpherePosition& spos)
89 { return(PixVal(PixIndex(spos))); }
90inline T const& operator()(const SpherePosition& spos) const
91 { return(PixVal(PixIndex(spos))); }
92
93
94// Note : no overloading of (double,double) to access pixel (theta,phi).
95// overloading of (double,double) in SphericalMap
96// overloading of (int,int) in CartesianMap
97
98/*! Setting pixel values to a constant */
99virtual T SetPixels(T v);
100PixelMap<T>& SetT(T v);
101 //inline T operator = (T v) { return(SetPixels(v)); }
102inline PixelMap<T>& operator = (T v) { return(SetT(v)); }
103
104//! Ascii print of synthetic information about the pixelmap on stream os
105virtual void Show(ostream& os) const;
106//! Show information on \b cout
107inline void Show() const { Show(cout); }
108
109
110//! Return a reference to the associated DVList object
111DVList& Info()
112 {
113 if (mInfo_ == NULL) mInfo_ = new DVList;
114 return(*mInfo_);
115 }
116
117const DVList* ptrInfo() const
118 {
119 return mInfo_;
120 }
121
122protected :
123 SphereCoordSys *cs_; // Coordinate system used in the map
124 DVList* mInfo_; // Infos (variables) attachees
125};
126
127template <class T>
128inline ostream& operator << (ostream& s, const PixelMap<T> & a)
129{ a.Show(s); return(s); }
130
131template <class T>
132int_4 PixelMap<T>::PixIndex(const SpherePosition& spos)
133{
134UnitVector v = spos.Transform(*cs_);
135return(PixIndexSph(v.Theta(), v.Phi()));
136}
137
138template <class T>
139bool PixelMap<T>::Contains(const SpherePosition& spos) const
140{
141UnitVector v = spos.Transform(*cs_);
142return(ContainsSph(v.Theta(), v.Phi()));
143}
144template <class T>
145T PixelMap<T>::SetPixels(T v)
146{
147int k;
148for(k=0; k<NbPixels(); k++) PixVal(k) = v;
149return(v);
150}
151template <class T>
152PixelMap<T>& PixelMap<T>::SetT(T v)
153{
154int k;
155for(k=0; k<NbPixels(); k++) PixVal(k) = v;
156return(*this);
157}
158
159template <class T>
160void PixelMap<T>::Show(ostream& os) const
161{
162os << "PixelMap<T>::Show() class: " << typeid(*this).name()
163 << " T= " << DataTypeInfo<T>::getTypeName()
164 << " TypeOfMap= " << TypeOfMap() << endl;
165double solang = 0.;
166if (NbPixels() > 0) solang = PixSolAngle(NbPixels()/2);
167 double frac = NbPixels()*solang*100/(4.*M_PI);
168if (frac > 100.) frac = 100.;
169os << " NbPixels()= " << NbPixels() << " ResolArcMin ~="
170 << Angle(sqrt(solang)).ToArcMin() << " SphereFrac ~= "
171 << frac << " % of 4Pi" << endl;
172}
173
174
175} // Fin du namespace
176
177#endif
Note: See TracBrowser for help on using the repository browser.