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