1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // Classe image generique E.Aubourg , E. Lesquoy
|
---|
3 | // Modifs R. Ansari 04/95
|
---|
4 |
|
---|
5 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
6 |
|
---|
7 | #ifndef RZIMAGE_SEEN
|
---|
8 | #define RZIMAGE_SEEN
|
---|
9 |
|
---|
10 | #include <iostream.h>
|
---|
11 |
|
---|
12 | #include "rzvect.h"
|
---|
13 | #include "datatypes.h"
|
---|
14 | #include "ppersist.h"
|
---|
15 | #include "dvlist.h"
|
---|
16 |
|
---|
17 | class GeneralFit;
|
---|
18 |
|
---|
19 | // Flags de verifications sur les indices
|
---|
20 |
|
---|
21 | //#define IMGRGCHECK
|
---|
22 | //#define IMGVOIDCHECK
|
---|
23 |
|
---|
24 |
|
---|
25 | // ------------- Classe RzImage ------------------
|
---|
26 |
|
---|
27 | typedef union { // il faut acceder le bon en fonction de datatype
|
---|
28 | RzVect<uint_1>* u1;
|
---|
29 | RzVect<uint_2>* u2;
|
---|
30 | RzVect<int_2>* i2;
|
---|
31 | RzVect<int_4>* i4;
|
---|
32 | RzVect<r_4>* r4;
|
---|
33 | RzVect<r_8>* r8;
|
---|
34 | } ImgVectP ;
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | class RzImage : public PPersist {
|
---|
39 | //class RzImage EXC_AWARE {
|
---|
40 | public:
|
---|
41 | enum {classId = ClassId_Image };
|
---|
42 |
|
---|
43 | RzImage(PBaseDataTypes dType, int sizx, int sizy,
|
---|
44 | int imgId = 0, char const * imgName = 0);
|
---|
45 | RzImage(PBaseDataTypes dType=kpbdt_unknown);
|
---|
46 | RzImage(const RzImage&, int sharePixels=0);
|
---|
47 |
|
---|
48 | RzImage(char *flnm); // Creation/Lecture fichier de obtenu par Write()
|
---|
49 |
|
---|
50 | virtual ~RzImage();
|
---|
51 |
|
---|
52 | int_4 ClassId() const { return classId; }
|
---|
53 | static PPersist* Create() { return new RzImage;}
|
---|
54 |
|
---|
55 | RzImage& operator= (RzImage const &);
|
---|
56 |
|
---|
57 | inline int_4 XSize() const {return siz_x;}
|
---|
58 | inline int_4 YSize() const {return siz_y;}
|
---|
59 |
|
---|
60 | inline int_4 XOrg() const {return org_x;}
|
---|
61 | inline int_4 YOrg() const {return org_y;}
|
---|
62 |
|
---|
63 | inline float XPxSize() const {return pxsz_x;}
|
---|
64 | inline float YPxSize() const {return pxsz_y;}
|
---|
65 |
|
---|
66 | inline ImgVectP Vect() const {return vect;}
|
---|
67 | inline void * VoidP() const {return voidP;}
|
---|
68 | inline int IsFits() const {return isFits;}
|
---|
69 |
|
---|
70 | inline PBaseDataTypes PixelType() const { return dataType; }
|
---|
71 | inline char * PixelNomType() const { return DataName(dataType); }
|
---|
72 |
|
---|
73 | inline char * Nom() { return name; }
|
---|
74 | inline const char * Nom() const { return name; }
|
---|
75 | inline int_4 Ident() const { return id; }
|
---|
76 |
|
---|
77 | DVList& Info();
|
---|
78 |
|
---|
79 | void Allocate(PBaseDataTypes dType, int sizx, int sizy, ImgVectP* pvpsh=NULL);
|
---|
80 | void DeAllocPixels();
|
---|
81 | void SetPixels(PBaseDataTypes dType, int sizx, int sizy, void* data);
|
---|
82 |
|
---|
83 | void SetOrg(int_4 orgx, int_4 orgy);
|
---|
84 | void SetPxSize(float szx=1, float szy=1);
|
---|
85 | void SetAtt(int nbnul = -1, int nbsat = -1,
|
---|
86 | float minpix = 0, float maxpix = -1.,
|
---|
87 | float moypix = 0, float sigpix = -1.,
|
---|
88 | float fnd = -1., float sigfnd = -1.);
|
---|
89 |
|
---|
90 | void SetNameId(int imgid = 0, char const * nom = NULL);
|
---|
91 |
|
---|
92 | // Fonctions d'impressions
|
---|
93 | virtual void Print(ostream& os) const;
|
---|
94 | inline void Print() const { Print(cout); }
|
---|
95 |
|
---|
96 | virtual int CheckDyn(double min=-9.e19, double max=9.e19);
|
---|
97 |
|
---|
98 | // Resultats d'un GeneralFit
|
---|
99 | RzImage* FitResidus(GeneralFit& gfit);
|
---|
100 | RzImage* FitFunction(GeneralFit& gfit);
|
---|
101 |
|
---|
102 | void Save(char *flnm);
|
---|
103 | virtual void WriteSelf(POutPersist&) const;
|
---|
104 | virtual void ReadSelf(PInPersist&);
|
---|
105 |
|
---|
106 | // Fonctions d'acces aux pixels avec conversion
|
---|
107 | // ATTENTION LENT ! EVITER AUX ENDROITS CRITIQUES.
|
---|
108 |
|
---|
109 | int IValue(int i, int j) const ;
|
---|
110 | int IValue(int k) const ;
|
---|
111 | float FValue(int i, int j) const ;
|
---|
112 | float FValue(int k) const ;
|
---|
113 | double DValue(int i, int j) const ;
|
---|
114 | double DValue(int k) const ;
|
---|
115 |
|
---|
116 | // Quelques variables caracterisant la distribution des pixels
|
---|
117 | r_4 fond; // Fond de l'image
|
---|
118 | r_4 sigmaFond; // Fluctuation du fond
|
---|
119 | int_4 nbNul; // Nb de pixels < min
|
---|
120 | int_4 nbSat; // Nb de pixels > max
|
---|
121 | r_4 minPix; // Valeur mini des pixels >= min <= max
|
---|
122 | r_4 maxPix; // Valeur maxi des pixels >= min <= max
|
---|
123 | r_4 moyPix; // Valeur moyenne des pixels
|
---|
124 | r_4 sigPix; // Sigma distribution des pixels
|
---|
125 |
|
---|
126 | protected:
|
---|
127 | PBaseDataTypes dataType;
|
---|
128 | int_4 siz_x,siz_y; // Taille x,y
|
---|
129 | int_4 org_x,org_y; // Origines si image lu ds un fichier
|
---|
130 | r_4 pxsz_x, pxsz_y; // Taille des pixels
|
---|
131 | int_4 isFits; // Beurk. Ah que Reza ne me fait-il pas faire!
|
---|
132 | char name[32]; // Nom de l'image (Gestion des objets)
|
---|
133 | int_4 id; // Identificateur (Gestion des objets)
|
---|
134 |
|
---|
135 | void* voidP; // un pointeur sans type -
|
---|
136 | // Vivement le RTTI qu'on puisse eliminer ces choses
|
---|
137 | ImgVectP vect; // il faut acceder le bon en fonction de datatype
|
---|
138 |
|
---|
139 | DVList* mInfo; // Infos (variables) attachees a l'image
|
---|
140 |
|
---|
141 | private:
|
---|
142 | int (RzImage::* IVal_p)(int) const;
|
---|
143 | float (RzImage::* FVal_p)(int) const;
|
---|
144 | double (RzImage::* DVal_p)(int) const;
|
---|
145 |
|
---|
146 | int IVal_u1(int k) const;
|
---|
147 | int IVal_u2(int k) const;
|
---|
148 | int IVal_i2(int k) const;
|
---|
149 | int IVal_r4(int k) const;
|
---|
150 | int IVal_i4(int k) const;
|
---|
151 | int IVal_r8(int k) const;
|
---|
152 |
|
---|
153 | float FVal_u1(int k) const;
|
---|
154 | float FVal_u2(int k) const;
|
---|
155 | float FVal_i2(int k) const;
|
---|
156 | float FVal_r4(int k) const;
|
---|
157 | float FVal_i4(int k) const;
|
---|
158 | float FVal_r8(int k) const;
|
---|
159 |
|
---|
160 | double DVal_u1(int k) const;
|
---|
161 | double DVal_u2(int k) const;
|
---|
162 | double DVal_i2(int k) const;
|
---|
163 | double DVal_r4(int k) const;
|
---|
164 | double DVal_i4(int k) const;
|
---|
165 | double DVal_r8(int k) const;
|
---|
166 | };
|
---|
167 |
|
---|
168 | // Definition de l'operateur <<
|
---|
169 | inline ostream& operator << (ostream& s, RzImage const & img)
|
---|
170 | { img.Print(s); return(s); }
|
---|
171 |
|
---|
172 | // Implementation des methodes d'acces pixels inline
|
---|
173 |
|
---|
174 | #ifdef IMGRGCHECK
|
---|
175 | #define RZCHECKIMG2(_x_,_y_) \
|
---|
176 | if ((_x_ >= siz_x) || (_y_ >= siz_y) || \
|
---|
177 | (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr); \
|
---|
178 | if (!voidP) THROW(nullPtrErr)
|
---|
179 | #define RZCHECKIMG1(_x_) \
|
---|
180 | if ((_x_ >= siz_x*siz_y) || (_x_ < 0)) THROW(rangeCheckErr); \
|
---|
181 | if (!voidP) THROW(nullPtrErr)
|
---|
182 | #else
|
---|
183 | #if defined(IMGVOIDCHECK)
|
---|
184 | #define RZCHECKIMG2(_x_,_y_) \
|
---|
185 | if (!voidP) THROW(NullPtrErr)
|
---|
186 | #define RZCHECKIMG1(_x_,_y_) \
|
---|
187 | if (!voidP) THROW(NullPtrErr)
|
---|
188 | #else
|
---|
189 | #define RZCHECKIMG2(_x_,_y_)
|
---|
190 | #define RZCHECKIMG1(_x_)
|
---|
191 | #endif
|
---|
192 | #endif /* IMGRGCHECK */
|
---|
193 |
|
---|
194 | // Methodes d'acces pixels inline
|
---|
195 |
|
---|
196 | inline int RzImage::IValue(int k) const
|
---|
197 | {
|
---|
198 | RZCHECKIMG1(k);
|
---|
199 | return (this->*IVal_p)(k);
|
---|
200 | }
|
---|
201 |
|
---|
202 | inline int RzImage::IValue(int i, int j) const
|
---|
203 | {
|
---|
204 | RZCHECKIMG2(i,j);
|
---|
205 | return IValue(i+j*siz_x);
|
---|
206 | }
|
---|
207 |
|
---|
208 | inline float RzImage::FValue(int k) const
|
---|
209 | {
|
---|
210 | RZCHECKIMG1(k);
|
---|
211 | return (this->*FVal_p)(k);
|
---|
212 | }
|
---|
213 |
|
---|
214 | inline float RzImage::FValue(int i, int j) const
|
---|
215 | {
|
---|
216 | RZCHECKIMG2(i,j);
|
---|
217 | return FValue(i+j*siz_x);
|
---|
218 | }
|
---|
219 |
|
---|
220 | inline double RzImage::DValue(int k) const
|
---|
221 | {
|
---|
222 | RZCHECKIMG1(k);
|
---|
223 | return (this->*DVal_p)(k);
|
---|
224 | }
|
---|
225 |
|
---|
226 | inline double RzImage::DValue(int i, int j) const
|
---|
227 | {
|
---|
228 | RZCHECKIMG2(i,j);
|
---|
229 | return DValue(i+j*siz_x);
|
---|
230 | }
|
---|
231 |
|
---|
232 | #endif
|
---|