[220] | 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 |
|
---|
[896] | 17 | namespace SOPHYA {
|
---|
| 18 | class GeneralFit;
|
---|
| 19 | }
|
---|
[220] | 20 |
|
---|
| 21 | // Flags de verifications sur les indices
|
---|
| 22 |
|
---|
| 23 | //#define IMGRGCHECK
|
---|
| 24 | //#define IMGVOIDCHECK
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | // ------------- Classe RzImage ------------------
|
---|
| 28 |
|
---|
| 29 | typedef union { // il faut acceder le bon en fonction de datatype
|
---|
| 30 | RzVect<uint_1>* u1;
|
---|
| 31 | RzVect<uint_2>* u2;
|
---|
| 32 | RzVect<int_2>* i2;
|
---|
| 33 | RzVect<int_4>* i4;
|
---|
| 34 | RzVect<r_4>* r4;
|
---|
| 35 | RzVect<r_8>* r8;
|
---|
| 36 | } ImgVectP ;
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
[494] | 40 | class RzImage : public PPersist , public AnyDataObj {
|
---|
[220] | 41 | //class RzImage EXC_AWARE {
|
---|
| 42 | public:
|
---|
| 43 |
|
---|
| 44 | RzImage(PBaseDataTypes dType, int sizx, int sizy,
|
---|
| 45 | int imgId = 0, char const * imgName = 0);
|
---|
| 46 | RzImage(PBaseDataTypes dType=kpbdt_unknown);
|
---|
| 47 | RzImage(const RzImage&, int sharePixels=0);
|
---|
| 48 |
|
---|
| 49 | RzImage(char *flnm); // Creation/Lecture fichier de obtenu par Write()
|
---|
| 50 |
|
---|
| 51 | virtual ~RzImage();
|
---|
| 52 |
|
---|
| 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&);
|
---|
[756] | 105 | virtual AnyDataObj* DataObj() { return(this); }
|
---|
| 106 | virtual void SetDataObj(AnyDataObj &)
|
---|
| 107 | { throw ForbiddenError("RzImage::SetDataObj() not allowed ! "); }
|
---|
[220] | 108 |
|
---|
| 109 | // Fonctions d'acces aux pixels avec conversion
|
---|
| 110 | // ATTENTION LENT ! EVITER AUX ENDROITS CRITIQUES.
|
---|
| 111 |
|
---|
| 112 | int IValue(int i, int j) const ;
|
---|
| 113 | int IValue(int k) const ;
|
---|
| 114 | float FValue(int i, int j) const ;
|
---|
| 115 | float FValue(int k) const ;
|
---|
| 116 | double DValue(int i, int j) const ;
|
---|
| 117 | double DValue(int k) const ;
|
---|
| 118 |
|
---|
| 119 | // Quelques variables caracterisant la distribution des pixels
|
---|
| 120 | r_4 fond; // Fond de l'image
|
---|
| 121 | r_4 sigmaFond; // Fluctuation du fond
|
---|
| 122 | int_4 nbNul; // Nb de pixels < min
|
---|
| 123 | int_4 nbSat; // Nb de pixels > max
|
---|
| 124 | r_4 minPix; // Valeur mini des pixels >= min <= max
|
---|
| 125 | r_4 maxPix; // Valeur maxi des pixels >= min <= max
|
---|
| 126 | r_4 moyPix; // Valeur moyenne des pixels
|
---|
| 127 | r_4 sigPix; // Sigma distribution des pixels
|
---|
| 128 |
|
---|
| 129 | protected:
|
---|
| 130 | PBaseDataTypes dataType;
|
---|
| 131 | int_4 siz_x,siz_y; // Taille x,y
|
---|
| 132 | int_4 org_x,org_y; // Origines si image lu ds un fichier
|
---|
| 133 | r_4 pxsz_x, pxsz_y; // Taille des pixels
|
---|
| 134 | int_4 isFits; // Beurk. Ah que Reza ne me fait-il pas faire!
|
---|
| 135 | char name[32]; // Nom de l'image (Gestion des objets)
|
---|
| 136 | int_4 id; // Identificateur (Gestion des objets)
|
---|
| 137 |
|
---|
| 138 | void* voidP; // un pointeur sans type -
|
---|
| 139 | // Vivement le RTTI qu'on puisse eliminer ces choses
|
---|
| 140 | ImgVectP vect; // il faut acceder le bon en fonction de datatype
|
---|
| 141 |
|
---|
| 142 | DVList* mInfo; // Infos (variables) attachees a l'image
|
---|
| 143 |
|
---|
| 144 | private:
|
---|
| 145 | int (RzImage::* IVal_p)(int) const;
|
---|
| 146 | float (RzImage::* FVal_p)(int) const;
|
---|
| 147 | double (RzImage::* DVal_p)(int) const;
|
---|
| 148 |
|
---|
| 149 | int IVal_u1(int k) const;
|
---|
| 150 | int IVal_u2(int k) const;
|
---|
| 151 | int IVal_i2(int k) const;
|
---|
| 152 | int IVal_r4(int k) const;
|
---|
| 153 | int IVal_i4(int k) const;
|
---|
| 154 | int IVal_r8(int k) const;
|
---|
| 155 |
|
---|
| 156 | float FVal_u1(int k) const;
|
---|
| 157 | float FVal_u2(int k) const;
|
---|
| 158 | float FVal_i2(int k) const;
|
---|
| 159 | float FVal_r4(int k) const;
|
---|
| 160 | float FVal_i4(int k) const;
|
---|
| 161 | float FVal_r8(int k) const;
|
---|
| 162 |
|
---|
| 163 | double DVal_u1(int k) const;
|
---|
| 164 | double DVal_u2(int k) const;
|
---|
| 165 | double DVal_i2(int k) const;
|
---|
| 166 | double DVal_r4(int k) const;
|
---|
| 167 | double DVal_i4(int k) const;
|
---|
| 168 | double DVal_r8(int k) const;
|
---|
| 169 | };
|
---|
| 170 |
|
---|
| 171 | // Definition de l'operateur <<
|
---|
| 172 | inline ostream& operator << (ostream& s, RzImage const & img)
|
---|
| 173 | { img.Print(s); return(s); }
|
---|
| 174 |
|
---|
| 175 | // Implementation des methodes d'acces pixels inline
|
---|
| 176 |
|
---|
| 177 | #ifdef IMGRGCHECK
|
---|
| 178 | #define RZCHECKIMG2(_x_,_y_) \
|
---|
| 179 | if ((_x_ >= siz_x) || (_y_ >= siz_y) || \
|
---|
| 180 | (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr); \
|
---|
| 181 | if (!voidP) THROW(nullPtrErr)
|
---|
| 182 | #define RZCHECKIMG1(_x_) \
|
---|
| 183 | if ((_x_ >= siz_x*siz_y) || (_x_ < 0)) THROW(rangeCheckErr); \
|
---|
| 184 | if (!voidP) THROW(nullPtrErr)
|
---|
| 185 | #else
|
---|
| 186 | #if defined(IMGVOIDCHECK)
|
---|
| 187 | #define RZCHECKIMG2(_x_,_y_) \
|
---|
| 188 | if (!voidP) THROW(NullPtrErr)
|
---|
| 189 | #define RZCHECKIMG1(_x_,_y_) \
|
---|
| 190 | if (!voidP) THROW(NullPtrErr)
|
---|
| 191 | #else
|
---|
| 192 | #define RZCHECKIMG2(_x_,_y_)
|
---|
| 193 | #define RZCHECKIMG1(_x_)
|
---|
| 194 | #endif
|
---|
| 195 | #endif /* IMGRGCHECK */
|
---|
| 196 |
|
---|
| 197 | // Methodes d'acces pixels inline
|
---|
| 198 |
|
---|
| 199 | inline int RzImage::IValue(int k) const
|
---|
| 200 | {
|
---|
| 201 | RZCHECKIMG1(k);
|
---|
| 202 | return (this->*IVal_p)(k);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | inline int RzImage::IValue(int i, int j) const
|
---|
| 206 | {
|
---|
| 207 | RZCHECKIMG2(i,j);
|
---|
| 208 | return IValue(i+j*siz_x);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | inline float RzImage::FValue(int k) const
|
---|
| 212 | {
|
---|
| 213 | RZCHECKIMG1(k);
|
---|
| 214 | return (this->*FVal_p)(k);
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | inline float RzImage::FValue(int i, int j) const
|
---|
| 218 | {
|
---|
| 219 | RZCHECKIMG2(i,j);
|
---|
| 220 | return FValue(i+j*siz_x);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | inline double RzImage::DValue(int k) const
|
---|
| 224 | {
|
---|
| 225 | RZCHECKIMG1(k);
|
---|
| 226 | return (this->*DVal_p)(k);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | inline double RzImage::DValue(int i, int j) const
|
---|
| 230 | {
|
---|
| 231 | RZCHECKIMG2(i,j);
|
---|
| 232 | return DValue(i+j*siz_x);
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[896] | 235 |
|
---|
[220] | 236 | #endif
|
---|