Index: trunk/SophyaLib/NTools/cimage.h
===================================================================
--- trunk/SophyaLib/NTools/cimage.h	(revision 896)
+++ trunk/SophyaLib/NTools/cimage.h	(revision 1104)
@@ -1,6 +1,5 @@
 // This may look like C code, but it is really -*- C++ -*-
-//  Classes image typee      E.Aubourg , E. Lesquoy     
-//                           Modifs R. Ansari   04/95
-
+//  Classes image heritant de TMatrix<T>
+//                       R.Ansari, C.Magneville 07/2000    
 // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
 
@@ -8,12 +7,5 @@
 #define CIMAGE_SEEN
 
-#include <iostream.h>
-#include <iomanip.h>
-#include "rzimage.h"
-
-// Flags de verifications sur les indices  dans rzimage.h 
-
-//#define IMGRGCHECK
-//#define IMGVOIDCHECK
+#include "tmatrix.h"
 
 
@@ -21,278 +13,79 @@
 // Classe Image
 
+namespace SOPHYA {
 
 template <class T>
-class Image : public RzImage {
+class Image : public TMatrix<T> {
 
 public:
-  Image(int sizx, int sizy, int zero=1);
   Image();
-  Image(const Image<T>&, int sharePixels=0);
-  Image(const Image<T>&, int orgx, int orgy, int sizx=-1, int sizy=-1);
-  EXPLICIT Image(const RzImage&); // Pour Reza. Partage les pixels
-  Image(char *flnm);
+  Image(uint_4 sizx, uint_4 sizy, r_8 szpx=1., r_8 szpy=1., r_8 orgx=0., r_8 orgy=0.);
+  Image(const Image<T>& a);
+  Image(const Image<T>& a, bool share);
+
   virtual ~Image();
 
-  static PPersist*      Create()              { return new Image<T>;}
+  // Inline element acces methods 
+  inline T const& operator()(uint_4 ix,uint_4 jy) const;
+  inline T&       operator()(uint_4 ix,uint_4 jy);
 
-  virtual void    ReadSelf(PInPersist&);
+  inline uint_4  XSize() const {return NCols();}
+  inline uint_4  YSize() const {return NRows();}
 
-  Image<T>&       operator= (const Image<T> &);
-  Image<T>&       operator= (T);
+  inline r_8     XOrg() const {return org_x;}
+  inline r_8     YOrg() const {return org_y;}
 
-  Image<T>&       operator+= (Image<T> const&);
-  Image<T>&       operator-= (Image<T> const&);
-  Image<T>&       operator*= (Image<T> const&);
-  Image<T>&       operator/= (Image<T> const&);
+  inline r_8     XPixSize() const {return pxsz_x;}
+  inline r_8     YPixSize() const {return pxsz_y;}
 
-  Image<T>&       operator+= (double);
-  Image<T>&       operator-= (double);
-  Image<T>&       operator*= (double);
-  Image<T>&       operator/= (double);
-
-  Image<T>        WhereNonZero();
-
-
-//   Impression de tout le contenu de l'image 
-  virtual void    PrintImage(ostream& os) const;
-  inline void     PrintImage() const  { PrintImage(cout); }
-
-  void            Zero();
-  void            Allocate(int sizx, int sizy, int zero=1, ImgVectP* pvpsh=NULL);
-
-  inline T&       operator() (int x, int y);
-  inline T        operator() (int x, int y) const;
-  inline T&       operator[] (int i);
-  inline T        operator[] (int i) const;
-  T*              ImagePtr()         {return imagePtr;}
-  const T*        ImagePtr() const   {return imagePtr;}
-                                            
-  int             CheckDyn(double min=-9.e19, double max=9.e19);
-
-  void            SeuilBas(double seuil, double val);
-  void            SeuilHaut(double seuil, double val);
-  void            SeuilBas(double seuil);
-  void            SeuilHaut(double seuil);
-  void            SetPixels(int szx, int szy, T* pim);
-
-  int EstimeFdSg(float& xbmax,float& sgbmax,float nbsig=3.5,float frac=0.33
-                ,float lowbad=1.,float highbad=-1.,int deb=0);
-  float FondCiel(int nbin,float bin_low,float bin_high
-                ,int degre=2,float frac=0.5f,int modu=1,int deb=0);
-  float SigmaCiel(int nbin,float bin_low,float bin_high,float& means
-                 ,float lowbad=1.,float highbad=-1.
-                 ,float nsig=4.f,int modu=1,int deb=0);
-  int   MoySigma(float& mean,float& sigma
-                ,float lowbad=1.,float highbad=-1.,int modu=1);
-  int   MoySigmaIter(float& mean,float& sigma,float lowbad=1.,float highbad=-1.
-                    ,int modu=1,int nitermx=10
-                    ,float perdiff=0.1f,float scut=3.5f, int deb=0);
-  int   FondSigmaCiel(float lowbad,float highbad,int pvsz=100
-              ,float nbsig1=3.5f,float nbsig2=7.f,float nbsig3=5.f
-              ,float binsg=0.5f,float frac=0.33f,int modu=1,int deb=0);
-
+  inline void    SetOrg(r_8 orgx=0., r_8 orgy=0.)
+                       { org_x = orgx;  org_y = orgy; }  
+  inline void    SetPixelSize(r_8 szx=1., r_8 szy=1.)
+                       { pxsz_x = szx;   pxsz_y = szy; }
 
 protected:
-
-  void HBinInt(int& nbin,float& xmin,float& xmax);
-
-  T*              imagePtr;
+  r_8   org_x,org_y;        //  Coordonnees pixel(0,0)
+  r_8   pxsz_x, pxsz_y;     //  Taille des pixels
 };
 
-// Definition de l'operateur << 
-//template <class T> 
-//ostream& operator << (ostream& s, Image<T> const& img)
-//  {  img.Print(s);  return(s);  }
-
-
-/*  .......................................................  */
-/*          Implementation inline des acces pixels           */
-/*  .......................................................  */
-
-// ----- Macro de verification des indices  ------ 
-
-#ifdef IMGRGCHECK
-#define CHECKIMG(_x_,_y_)                                  \
-      if ((_x_ >= siz_x) || (_y_ >= siz_y) ||              \
-          (_x_ < 0) || (_y_ < 0)) THROW(rangeCheckErr);  \
-      if (!imagePtr) THROW(nullPtrErr)
-#else
-#if defined(IMGVOIDCHECK)
-#define CHECKIMG(_x_,_y_) \
-      if (!imagePtr) THROW(NullPtrErr)
-#else
-#define CHECKIMG(_x_,_y_)
-#endif
-#endif /* IMGRGCHECK */
-
-#define INRANGE(_x_,_y_) ((_x_ < siz_x) && (_y_ < siz_y) && \
-                          (_x_ >= 0) && (_y_ >= 0))
-
-
-// Fin des macros  ------ 
-
-
 template <class T>
-inline T & Image<T>::operator() (int x, int y)
+inline T const& Image<T>::operator()(uint_4 ix, uint_4 jy) const
 {
-  CHECKIMG(x,y);
-  return imagePtr[x+y*siz_x];
+  return (TMatrix<T>::operator() (jy, ix));
 }
 
 template <class T>
-inline T Image<T>::operator() (int x, int y) const
+inline T & Image<T>::operator()(uint_4 ix, uint_4 jy) 
 {
-  CHECKIMG(x,y);
-  return imagePtr[x+y*siz_x];
-}
-
-template <class T>
-inline T & Image<T>::operator[] (int i)
-{
-  CHECKIMG(0,0);
-  return imagePtr[i];
-}
-
-template <class T>
-inline T Image<T>::operator[] (int i) const
-{
-  CHECKIMG(0,0);
-  return imagePtr[i];
-}
-
-// Operateurs addition, multiplication, ... (+ - * / ) avec des doubles 
-
-template <class T> 
-Image<T> operator+ (Image<T> const& a, double b) 
-{
-  Image<T> c(a);
-  c += b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator- (Image<T> const& a, double b) 
-{
-  Image<T> c(a);
-  c -= b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator* (Image<T> const& a, double b) 
-{
-  Image<T> c(a);
-  c *= b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator/ (Image<T> const& a, double b) 
-{
-  Image<T> c(a);
-  c /= b;
-  return c;
-}
-
-// Operateurs addition, multiplication, ... (+ - * / ) entre images
-template <class T> 
-Image<T> operator+ (Image<T> const& a, Image<T> const& b)
-{
-  Image<T> c(a);
-  c += b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator- (Image<T> const& a, Image<T> const& b) 
-{
-  Image<T> c(a);
-  c -= b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator* (Image<T> const& a, Image<T> const& b) 
-{
-  Image<T> c(a);
-  c *= b;
-  return c;
-}
-
-template <class T> 
-Image<T> operator/ (Image<T> const& a, Image<T> const& b) 
-{
-  Image<T> c(a);
-  c /= b;
-  return c;
+  return (TMatrix<T>::operator() (jy, ix));
 }
 
 
-/*  .......................................................  */
-/*         Fonctions de copie d'images et de paves           */
-/*  .......................................................  */
-
-template <class T2, class T1>
-void CopieImageF(Image<T2>& copie, Image<T1> const& pim,
-                 int org_pim_x=0, int org_pim_y=0,
-                 int pim_lpav_x=0, int pim_lpav_y=0,
-                 int org_copie_x=0, int org_copie_y=0,
-                 double cutmin=0., double cutmax=0.);
-                
-template <class T2, class T1>
-void CopieImage(Image<T2>& copie, Image<T1> const& pim);
-
-template <class T2, class T1>
-void CopieImage(Image<T2>& copie, Image<T1> const& pim,
-                int org_pim_x, int org_pim_y,
-                int pim_lpav_x=0, int pim_lpav_y=0,
-                int org_copie_x=0, int org_copie_y=0,
-                double cutmin=0, double cutmax=0);
-
-
-template <class T2, class T1>
-void 
-CopiePave(Image<T2>& pave, Image<T1> const& pim,
-	  float xc, float yc, 
-	  double cutmin=0, double cutmax=0);
-
-
-template <class T>
-void 
-RzCopieImage(Image<T>& copie, RzImage const& pim,
-	     int org_pim_x, int org_pim_y,
-	     int pim_lpav_x=0, int pim_lpav_y=0,
-	     int org_copie_x=0, int org_copie_y=0,
-	     double cutmin=0, double cutmax=0);
-
-template <class T>
-void 
-RzCopieImage(Image<T>& copie, RzImage const& pim);
-
-template <class T>
-void 
-RzCopiePave(Image<T> & pave, RzImage const & pim,
-	    float xc, float yc,
-	    double cutmin=0, double cutmax=0);
-/*  .......................................................  */
-/*         Autres fonctions utilitaires pour RzImage         */
-/*  .......................................................  */
-
-void RzPrintImage(RzImage & img);
-
-/*  Images de types usuels   */
-
-typedef Image<uint_1> ImageU1;
 typedef Image<uint_2> ImageU2;
-typedef Image<int_2>  ImageI2;
 typedef Image<int_4>  ImageI4;
 typedef Image<r_4>    ImageR4;
+typedef Image<r_8>    ImageR8;
 
+class GeneralFit;
+class RzImage {
+public:
+  RzImage() { }
+  ~RzImage() { }
+  inline uint_4  XSize() const {return 0;}
+  inline uint_4  YSize() const {return 0;}
 
-#ifdef __MWERKS__
-template <class T>
-ostream& operator << (ostream& s, Image<T> const& pim);
-#endif
+  inline r_8     XOrg() const {return 0;}
+  inline r_8     YOrg() const {return 0;}
 
+  inline r_8     XPixSize() const {return 1.;}
+  inline r_8     YPixSize() const {return 1.;}
+  inline r_8     DValue(int i, int j) const { return 0.; }
+  // Resultats d'un GeneralFit
+  inline RzImage*      FitResidus(GeneralFit& gfit) { return NULL; }
+  inline RzImage*      FitFunction(GeneralFit& gfit) { return NULL; }
+
+};
+
+}  // End of namespace SOPHYA
 
 #endif
