Changeset 1104 in Sophya for trunk/SophyaLib/NTools/cimage.h


Ignore:
Timestamp:
Jul 27, 2000, 7:30:57 PM (25 years ago)
Author:
ansari
Message:

Heritage classe Image<T> de TMatrix<T> Reza+CMV 27/7/2000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/cimage.h

    r896 r1104  
    11// This may look like C code, but it is really -*- C++ -*-
    2 //  Classes image typee      E.Aubourg , E. Lesquoy     
    3 //                           Modifs R. Ansari   04/95
    4 
     2//  Classes image heritant de TMatrix<T>
     3//                       R.Ansari, C.Magneville 07/2000   
    54// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
    65
     
    87#define CIMAGE_SEEN
    98
    10 #include <iostream.h>
    11 #include <iomanip.h>
    12 #include "rzimage.h"
    13 
    14 // Flags de verifications sur les indices  dans rzimage.h
    15 
    16 //#define IMGRGCHECK
    17 //#define IMGVOIDCHECK
     9#include "tmatrix.h"
    1810
    1911
     
    2113// Classe Image
    2214
     15namespace SOPHYA {
    2316
    2417template <class T>
    25 class Image : public RzImage {
     18class Image : public TMatrix<T> {
    2619
    2720public:
    28   Image(int sizx, int sizy, int zero=1);
    2921  Image();
    30   Image(const Image<T>&, int sharePixels=0);
    31   Image(const Image<T>&, int orgx, int orgy, int sizx=-1, int sizy=-1);
    32   EXPLICIT Image(const RzImage&); // Pour Reza. Partage les pixels
    33   Image(char *flnm);
     22  Image(uint_4 sizx, uint_4 sizy, r_8 szpx=1., r_8 szpy=1., r_8 orgx=0., r_8 orgy=0.);
     23  Image(const Image<T>& a);
     24  Image(const Image<T>& a, bool share);
     25
    3426  virtual ~Image();
    3527
    36   static PPersist*      Create()              { return new Image<T>;}
     28  // Inline element acces methods
     29  inline T const& operator()(uint_4 ix,uint_4 jy) const;
     30  inline T&       operator()(uint_4 ix,uint_4 jy);
    3731
    38   virtual void    ReadSelf(PInPersist&);
     32  inline uint_4  XSize() const {return NCols();}
     33  inline uint_4  YSize() const {return NRows();}
    3934
    40   Image<T>&       operator= (const Image<T> &);
    41   Image<T>&       operator= (T);
     35  inline r_8     XOrg() const {return org_x;}
     36  inline r_8     YOrg() const {return org_y;}
    4237
    43   Image<T>&       operator+= (Image<T> const&);
    44   Image<T>&       operator-= (Image<T> const&);
    45   Image<T>&       operator*= (Image<T> const&);
    46   Image<T>&       operator/= (Image<T> const&);
     38  inline r_8     XPixSize() const {return pxsz_x;}
     39  inline r_8     YPixSize() const {return pxsz_y;}
    4740
    48   Image<T>&       operator+= (double);
    49   Image<T>&       operator-= (double);
    50   Image<T>&       operator*= (double);
    51   Image<T>&       operator/= (double);
    52 
    53   Image<T>        WhereNonZero();
    54 
    55 
    56 //   Impression de tout le contenu de l'image
    57   virtual void    PrintImage(ostream& os) const;
    58   inline void     PrintImage() const  { PrintImage(cout); }
    59 
    60   void            Zero();
    61   void            Allocate(int sizx, int sizy, int zero=1, ImgVectP* pvpsh=NULL);
    62 
    63   inline T&       operator() (int x, int y);
    64   inline T        operator() (int x, int y) const;
    65   inline T&       operator[] (int i);
    66   inline T        operator[] (int i) const;
    67   T*              ImagePtr()         {return imagePtr;}
    68   const T*        ImagePtr() const   {return imagePtr;}
    69                                            
    70   int             CheckDyn(double min=-9.e19, double max=9.e19);
    71 
    72   void            SeuilBas(double seuil, double val);
    73   void            SeuilHaut(double seuil, double val);
    74   void            SeuilBas(double seuil);
    75   void            SeuilHaut(double seuil);
    76   void            SetPixels(int szx, int szy, T* pim);
    77 
    78   int EstimeFdSg(float& xbmax,float& sgbmax,float nbsig=3.5,float frac=0.33
    79                 ,float lowbad=1.,float highbad=-1.,int deb=0);
    80   float FondCiel(int nbin,float bin_low,float bin_high
    81                 ,int degre=2,float frac=0.5f,int modu=1,int deb=0);
    82   float SigmaCiel(int nbin,float bin_low,float bin_high,float& means
    83                  ,float lowbad=1.,float highbad=-1.
    84                  ,float nsig=4.f,int modu=1,int deb=0);
    85   int   MoySigma(float& mean,float& sigma
    86                 ,float lowbad=1.,float highbad=-1.,int modu=1);
    87   int   MoySigmaIter(float& mean,float& sigma,float lowbad=1.,float highbad=-1.
    88                     ,int modu=1,int nitermx=10
    89                     ,float perdiff=0.1f,float scut=3.5f, int deb=0);
    90   int   FondSigmaCiel(float lowbad,float highbad,int pvsz=100
    91               ,float nbsig1=3.5f,float nbsig2=7.f,float nbsig3=5.f
    92               ,float binsg=0.5f,float frac=0.33f,int modu=1,int deb=0);
    93 
     41  inline void    SetOrg(r_8 orgx=0., r_8 orgy=0.)
     42                       { org_x = orgx;  org_y = orgy; } 
     43  inline void    SetPixelSize(r_8 szx=1., r_8 szy=1.)
     44                       { pxsz_x = szx;   pxsz_y = szy; }
    9445
    9546protected:
    96 
    97   void HBinInt(int& nbin,float& xmin,float& xmax);
    98 
    99   T*              imagePtr;
     47  r_8   org_x,org_y;        //  Coordonnees pixel(0,0)
     48  r_8   pxsz_x, pxsz_y;     //  Taille des pixels
    10049};
    10150
    102 // Definition de l'operateur <<
    103 //template <class T>
    104 //ostream& operator << (ostream& s, Image<T> const& img)
    105 //  {  img.Print(s);  return(s);  }
    106 
    107 
    108 /*  .......................................................  */
    109 /*          Implementation inline des acces pixels           */
    110 /*  .......................................................  */
    111 
    112 // ----- Macro de verification des indices  ------
    113 
    114 #ifdef IMGRGCHECK
    115 #define CHECKIMG(_x_,_y_)                                  \
    116       if ((_x_ >= siz_x) || (_y_ >= siz_y) ||              \
    117           (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr);  \
    118       if (!imagePtr) THROW(nullPtrErr)
    119 #else
    120 #if defined(IMGVOIDCHECK)
    121 #define CHECKIMG(_x_,_y_) \
    122       if (!imagePtr) THROW(NullPtrErr)
    123 #else
    124 #define CHECKIMG(_x_,_y_)
    125 #endif
    126 #endif /* IMGRGCHECK */
    127 
    128 #define INRANGE(_x_,_y_) ((_x_ < siz_x) && (_y_ < siz_y) && \
    129                           (_x_ >= 0) && (_y_ >= 0))
    130 
    131 
    132 // Fin des macros  ------
    133 
    134 
    13551template <class T>
    136 inline T & Image<T>::operator() (int x, int y)
     52inline T const& Image<T>::operator()(uint_4 ix, uint_4 jy) const
    13753{
    138   CHECKIMG(x,y);
    139   return imagePtr[x+y*siz_x];
     54  return (TMatrix<T>::operator() (jy, ix));
    14055}
    14156
    14257template <class T>
    143 inline T Image<T>::operator() (int x, int y) const
     58inline T & Image<T>::operator()(uint_4 ix, uint_4 jy)
    14459{
    145   CHECKIMG(x,y);
    146   return imagePtr[x+y*siz_x];
    147 }
    148 
    149 template <class T>
    150 inline T & Image<T>::operator[] (int i)
    151 {
    152   CHECKIMG(0,0);
    153   return imagePtr[i];
    154 }
    155 
    156 template <class T>
    157 inline T Image<T>::operator[] (int i) const
    158 {
    159   CHECKIMG(0,0);
    160   return imagePtr[i];
    161 }
    162 
    163 // Operateurs addition, multiplication, ... (+ - * / ) avec des doubles
    164 
    165 template <class T>
    166 Image<T> operator+ (Image<T> const& a, double b)
    167 {
    168   Image<T> c(a);
    169   c += b;
    170   return c;
    171 }
    172 
    173 template <class T>
    174 Image<T> operator- (Image<T> const& a, double b)
    175 {
    176   Image<T> c(a);
    177   c -= b;
    178   return c;
    179 }
    180 
    181 template <class T>
    182 Image<T> operator* (Image<T> const& a, double b)
    183 {
    184   Image<T> c(a);
    185   c *= b;
    186   return c;
    187 }
    188 
    189 template <class T>
    190 Image<T> operator/ (Image<T> const& a, double b)
    191 {
    192   Image<T> c(a);
    193   c /= b;
    194   return c;
    195 }
    196 
    197 // Operateurs addition, multiplication, ... (+ - * / ) entre images
    198 template <class T>
    199 Image<T> operator+ (Image<T> const& a, Image<T> const& b)
    200 {
    201   Image<T> c(a);
    202   c += b;
    203   return c;
    204 }
    205 
    206 template <class T>
    207 Image<T> operator- (Image<T> const& a, Image<T> const& b)
    208 {
    209   Image<T> c(a);
    210   c -= b;
    211   return c;
    212 }
    213 
    214 template <class T>
    215 Image<T> operator* (Image<T> const& a, Image<T> const& b)
    216 {
    217   Image<T> c(a);
    218   c *= b;
    219   return c;
    220 }
    221 
    222 template <class T>
    223 Image<T> operator/ (Image<T> const& a, Image<T> const& b)
    224 {
    225   Image<T> c(a);
    226   c /= b;
    227   return c;
     60  return (TMatrix<T>::operator() (jy, ix));
    22861}
    22962
    23063
    231 /*  .......................................................  */
    232 /*         Fonctions de copie d'images et de paves           */
    233 /*  .......................................................  */
    234 
    235 template <class T2, class T1>
    236 void CopieImageF(Image<T2>& copie, Image<T1> const& pim,
    237                  int org_pim_x=0, int org_pim_y=0,
    238                  int pim_lpav_x=0, int pim_lpav_y=0,
    239                  int org_copie_x=0, int org_copie_y=0,
    240                  double cutmin=0., double cutmax=0.);
    241                
    242 template <class T2, class T1>
    243 void CopieImage(Image<T2>& copie, Image<T1> const& pim);
    244 
    245 template <class T2, class T1>
    246 void CopieImage(Image<T2>& copie, Image<T1> const& pim,
    247                 int org_pim_x, int org_pim_y,
    248                 int pim_lpav_x=0, int pim_lpav_y=0,
    249                 int org_copie_x=0, int org_copie_y=0,
    250                 double cutmin=0, double cutmax=0);
    251 
    252 
    253 template <class T2, class T1>
    254 void
    255 CopiePave(Image<T2>& pave, Image<T1> const& pim,
    256           float xc, float yc,
    257           double cutmin=0, double cutmax=0);
    258 
    259 
    260 template <class T>
    261 void
    262 RzCopieImage(Image<T>& copie, RzImage const& pim,
    263              int org_pim_x, int org_pim_y,
    264              int pim_lpav_x=0, int pim_lpav_y=0,
    265              int org_copie_x=0, int org_copie_y=0,
    266              double cutmin=0, double cutmax=0);
    267 
    268 template <class T>
    269 void
    270 RzCopieImage(Image<T>& copie, RzImage const& pim);
    271 
    272 template <class T>
    273 void
    274 RzCopiePave(Image<T> & pave, RzImage const & pim,
    275             float xc, float yc,
    276             double cutmin=0, double cutmax=0);
    277 /*  .......................................................  */
    278 /*         Autres fonctions utilitaires pour RzImage         */
    279 /*  .......................................................  */
    280 
    281 void RzPrintImage(RzImage & img);
    282 
    283 /*  Images de types usuels   */
    284 
    285 typedef Image<uint_1> ImageU1;
    28664typedef Image<uint_2> ImageU2;
    287 typedef Image<int_2>  ImageI2;
    28865typedef Image<int_4>  ImageI4;
    28966typedef Image<r_4>    ImageR4;
     67typedef Image<r_8>    ImageR8;
    29068
     69class GeneralFit;
     70class RzImage {
     71public:
     72  RzImage() { }
     73  ~RzImage() { }
     74  inline uint_4  XSize() const {return 0;}
     75  inline uint_4  YSize() const {return 0;}
    29176
    292 #ifdef __MWERKS__
    293 template <class T>
    294 ostream& operator << (ostream& s, Image<T> const& pim);
    295 #endif
     77  inline r_8     XOrg() const {return 0;}
     78  inline r_8     YOrg() const {return 0;}
    29679
     80  inline r_8     XPixSize() const {return 1.;}
     81  inline r_8     YPixSize() const {return 1.;}
     82  inline r_8     DValue(int i, int j) const { return 0.; }
     83  // Resultats d'un GeneralFit
     84  inline RzImage*      FitResidus(GeneralFit& gfit) { return NULL; }
     85  inline RzImage*      FitFunction(GeneralFit& gfit) { return NULL; }
     86
     87};
     88
     89}  // End of namespace SOPHYA
    29790
    29891#endif
Note: See TracChangeset for help on using the changeset viewer.