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

Last change on this file since 4078 was 4066, checked in by ansari, 13 years ago

Ajout gestion de niveau d'impression globale pour les cartes du module SkyMap ds pixelmap.h et prise en compte du niveau pour les prints ds Resize des SphericalMaps (fait en janv 2012 ?), Reza 27/04/2012

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