source: Sophya/trunk/SophyaLib/NTools/cimage.h@ 3986

Last change on this file since 3986 was 3836, checked in by ansari, 15 years ago

Declaration extern des classes templ des classes template avec instantiation explicite (avec flag NEED_EXT_DECL_TEMP) pour regler le pb de dynamic_cast sur Mac OS X 10.6, Reza 05/08/2010

File size: 5.2 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// Classes image heritant de TMatrix<T>
3// R.Ansari, C.Magneville 07/2000
4// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
5
6#ifndef CIMAGE_SEEN
7#define CIMAGE_SEEN
8
9#include "tmatrix.h"
10#include "fioarr.h"
11
12
13// **********************************************************
14// Classe Image
15
16namespace SOPHYA {
17
18//! Class for handling images
19template <class T>
20class Image : public TMatrix<T> {
21
22public:
23 Image();
24 Image(sa_size_t sizx, sa_size_t sizy, r_8 szpx=1., r_8 szpy=1., r_8 orgx=0., r_8 orgy=0.);
25 Image(const Image<T>& a);
26 Image(const Image<T>& a, bool share);
27
28 virtual ~Image();
29
30 // Inline element acces methods
31 inline T const& operator()(sa_size_t ix, sa_size_t jy) const;
32 inline T& operator()(sa_size_t ix, sa_size_t jy);
33
34 //! Returns the image size along X (corresponding to the number of columns)
35 inline sa_size_t XSize() const {return this->NCols();}
36 //! Returns the image size along Y (corresponding to the number of lines)
37 inline sa_size_t YSize() const {return this->NRows();}
38
39 //! Returns the X position, for pixel(0,0)
40 inline r_8 XOrg() const {return org_x;}
41 //! Returns the Y position, for pixel(0,0)
42 inline r_8 YOrg() const {return org_y;}
43
44 //! Returns pixel size along X
45 inline r_8 XPixSize() const {return pxsz_x;}
46 //! Returns pixel size along Y
47 inline r_8 YPixSize() const {return pxsz_y;}
48
49 //! Returns the pixel position along X, for pixels with X index \b i
50 inline r_8 XPos(sa_size_t i) const {return org_x + i*pxsz_x;}
51 //! Returns the pixel position along Y, for pixels with Y index \b j
52 inline r_8 YPos(sa_size_t j) const {return org_y + j*pxsz_y;}
53
54 //! Set the position for pixel(0,0)
55 inline void SetOrg(r_8 orgx=0., r_8 orgy=0.)
56 { org_x = orgx; org_y = orgy; }
57 //! Set the pixel size
58 inline void SetPixelSize(r_8 szx=1., r_8 szy=1.)
59 { pxsz_x = szx; pxsz_y = szy; }
60
61 //! = : fill image with constant value \b x
62 inline Image<T>& operator = (T x) {SetT(x); return(*this);}
63
64protected:
65 r_8 org_x,org_y; // Coordonnees pixel(0,0)
66 r_8 pxsz_x, pxsz_y; // Taille des pixels
67};
68
69//! () : Return the pixel value (element) for pixel \b ix (column index) and \b jy (line index)
70template <class T>
71inline T const& Image<T>::operator()(sa_size_t ix, sa_size_t jy) const
72{
73 return (TMatrix<T>::operator() (jy, ix));
74}
75
76//! () : Return the pixel value (element) for pixel \b ix (column index) and \b jy (line index)
77template <class T>
78inline T & Image<T>::operator()(sa_size_t ix, sa_size_t jy)
79{
80 return (TMatrix<T>::operator() (jy, ix));
81}
82
83/////////////////////////////////////////////////////////////////////////
84//! Class for persistent management of Image
85template <class T>
86class FIO_Image : public FIO_TArray<T> {
87public:
88 FIO_Image();
89 FIO_Image(string const & filename);
90 FIO_Image(const Image<T> & obj);
91 FIO_Image(Image<T> * obj);
92 // virtual ~FIO_Image();
93 virtual void SetDataObj(AnyDataObj & o);
94 inline operator Image<T>() { return(*(dynamic_cast<Image<T> * >(this->dobj))); }
95protected :
96 virtual void ReadSelf(PInPersist&);
97 virtual void WriteSelf(POutPersist&) const;
98};
99
100/*! \ingroup NTools \fn operator<<(POutPersist&,Image<T>&)
101 \brief Write Image \b obj into POutPersist stream \b os */
102template <class T>
103inline POutPersist& operator << (POutPersist& os, Image<T> & obj)
104{ FIO_Image<T> fio(&obj); fio.Write(os); return(os); }
105
106/*! \ingroup NTools \fn operator>>(PInPersist&,Image<T>&)
107 \brief Read Image \b obj from PInPersist stream \b os */
108template <class T>
109inline PInPersist& operator >> (PInPersist& is, Image<T> & obj)
110{ FIO_Image<T> fio(&obj); fio.Read(is); return(is); }
111
112
113
114typedef Image<uint_2> ImageU2;
115typedef Image<int_4> ImageI4;
116typedef Image<r_4> ImageR4;
117typedef Image<r_8> ImageR8;
118
119class GeneralFit;
120//! OBSOLETE - Should not be used - for compatibility with peida in (s)piapp
121class RzImage {
122public:
123 RzImage() { }
124 ~RzImage() { }
125 inline uint_4 XSize() const {return 0;}
126 inline uint_4 YSize() const {return 0;}
127
128 inline r_8 XOrg() const {return 0;}
129 inline r_8 YOrg() const {return 0;}
130
131 inline r_8 XPixSize() const {return 1.;}
132 inline r_8 YPixSize() const {return 1.;}
133 inline r_8 DValue(int i, int j) const { return 0.; }
134 // Resultats d'un GeneralFit
135 inline RzImage* FitResidus(GeneralFit& gfit) { return NULL; }
136 inline RzImage* FitFunction(GeneralFit& gfit) { return NULL; }
137
138};
139
140
141//--------- extern template declarations (if needed) -----------
142#if defined ( NEED_EXT_DECL_TEMP ) && !defined( CIMAGE_CC_BFILE )
143extern template class Image<uint_1>;
144extern template class Image<uint_2>;
145extern template class Image<uint_4>;
146extern template class Image<uint_8>;
147extern template class Image<int_1>;
148extern template class Image<int_2>;
149extern template class Image<int_4>;
150extern template class Image<int_8>;
151extern template class Image<r_4>;
152extern template class Image<r_8>;
153extern template class Image< complex<r_4> >;
154extern template class Image< complex<r_8> >;
155#endif // Fin de if defined ( NEED_EXT_DECL_TEMP )
156
157} // End of namespace SOPHYA
158
159#endif
160
161
Note: See TracBrowser for help on using the repository browser.