| [1104] | 1 | //  Classes image heritant de TMatrix<T> | 
|---|
|  | 2 | //                       R.Ansari, C.Magneville 07/2000 | 
|---|
| [220] | 3 | // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA | 
|---|
|  | 4 |  | 
|---|
| [244] | 5 | #include "machdefs.h" | 
|---|
| [220] | 6 | #include <stdio.h> | 
|---|
| [1104] | 7 | #include <stdlib.h> | 
|---|
|  | 8 | #include "pexceptions.h" | 
|---|
| [220] | 9 | #include "cimage.h" | 
|---|
|  | 10 |  | 
|---|
| [1390] | 11 | /*! | 
|---|
|  | 12 | \class SOPHYA::Image | 
|---|
|  | 13 | \ingroup NTools | 
|---|
|  | 14 | This class specializes the Matrix class, for representing intensity | 
|---|
|  | 15 | (or grey-level) images. It adds the possibility of defining pixel | 
|---|
|  | 16 | size and offset. The convention for the acces operator is also | 
|---|
|  | 17 | changed, compared to the matrix class. | 
|---|
|  | 18 | */ | 
|---|
|  | 19 |  | 
|---|
|  | 20 | //! Default constructor - Pixel array not allocated | 
|---|
| [220] | 21 | template <class T> | 
|---|
| [1104] | 22 | Image<T>::Image() | 
|---|
|  | 23 | // Constructeur par defaut. | 
|---|
|  | 24 | : TMatrix<T>() | 
|---|
| [220] | 25 | { | 
|---|
| [1104] | 26 | SetOrg(); | 
|---|
|  | 27 | SetPixelSize(); | 
|---|
| [220] | 28 | } | 
|---|
|  | 29 |  | 
|---|
| [1390] | 30 | //! Constructor, with specification of the image size, pixel size and offsets | 
|---|
| [220] | 31 | template <class T> | 
|---|
| [1390] | 32 | Image<T>::Image(sa_size_t sizx, sa_size_t sizy, r_8 szpx, r_8 szpy, r_8 orgx, r_8 orgy) | 
|---|
| [1104] | 33 | // Constructeur par defaut. | 
|---|
|  | 34 | : TMatrix<T>(sizy, sizx) | 
|---|
| [220] | 35 | { | 
|---|
| [1104] | 36 | SetOrg(orgx, orgy); | 
|---|
|  | 37 | SetPixelSize(szpx, szpy); | 
|---|
| [220] | 38 | } | 
|---|
|  | 39 |  | 
|---|
| [1390] | 40 | //! Copy constructor | 
|---|
| [220] | 41 | template <class T> | 
|---|
| [1104] | 42 | Image<T>::Image(const Image<T>& a) | 
|---|
|  | 43 | : TMatrix<T>(a) | 
|---|
| [220] | 44 | { | 
|---|
| [1104] | 45 | SetOrg(a.XOrg(), a.YOrg() ); | 
|---|
|  | 46 | SetPixelSize(a.XPixSize(), a.YPixSize()); | 
|---|
| [220] | 47 | } | 
|---|
|  | 48 |  | 
|---|
| [1390] | 49 |  | 
|---|
|  | 50 | //! Copy constructor with possibility of duplicating the pixel array | 
|---|
|  | 51 | /*! | 
|---|
|  | 52 | \param share : if true, the data is shared, duplicated if false. | 
|---|
|  | 53 | */ | 
|---|
| [220] | 54 | template <class T> | 
|---|
| [1104] | 55 | Image<T>::Image(const Image<T>& a, bool share) | 
|---|
|  | 56 | : TMatrix<T>(a, share) | 
|---|
| [220] | 57 | { | 
|---|
| [1104] | 58 | SetOrg(a.XOrg(), a.YOrg() ); | 
|---|
|  | 59 | SetPixelSize(a.XPixSize(), a.YPixSize()); | 
|---|
| [220] | 60 | } | 
|---|
| [1390] | 61 |  | 
|---|
|  | 62 | //! Destructor | 
|---|
| [220] | 63 | template <class T> | 
|---|
|  | 64 | Image<T>::~Image() | 
|---|
|  | 65 | { | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
| [1159] | 68 |  | 
|---|
|  | 69 | // -------------------------------------------------------- | 
|---|
|  | 70 | //   Les objets delegues pour la gestion de persistance | 
|---|
|  | 71 | // -------------------------------------------------------- | 
|---|
|  | 72 | /*! | 
|---|
|  | 73 | \class SOPHYA::FIO_Image | 
|---|
|  | 74 | \ingroup Image | 
|---|
|  | 75 | Class for persistent management of Image | 
|---|
|  | 76 |  | 
|---|
|  | 77 | */ | 
|---|
|  | 78 | /////////////////////////////////////////////////////////// | 
|---|
|  | 79 |  | 
|---|
|  | 80 | //! Default constructor | 
|---|
|  | 81 | template <class T> | 
|---|
|  | 82 | FIO_Image<T>::FIO_Image() | 
|---|
|  | 83 | : FIO_TArray<T>() | 
|---|
|  | 84 | { | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 |  | 
|---|
|  | 88 | //! Constructor from the file \b filename | 
|---|
|  | 89 | template <class T> | 
|---|
|  | 90 | FIO_Image<T>::FIO_Image(string const & filename) | 
|---|
|  | 91 | : FIO_TArray<T>(filename) | 
|---|
|  | 92 | { | 
|---|
|  | 93 | } | 
|---|
|  | 94 |  | 
|---|
|  | 95 | //! Constructor from the Image \b obj | 
|---|
|  | 96 | template <class T> | 
|---|
|  | 97 | FIO_Image<T>::FIO_Image(const Image<T> & obj) | 
|---|
|  | 98 | : FIO_TArray<T>() | 
|---|
|  | 99 | { | 
|---|
|  | 100 | dobj = new Image<T>(obj, true); | 
|---|
|  | 101 | ownobj=true; | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | //! Connect with a Image \b obj | 
|---|
|  | 105 | template <class T> | 
|---|
|  | 106 | FIO_Image<T>::FIO_Image(Image<T> * obj) | 
|---|
|  | 107 | : FIO_TArray<T>(obj) | 
|---|
|  | 108 | { | 
|---|
|  | 109 | } | 
|---|
|  | 110 |  | 
|---|
|  | 111 |  | 
|---|
|  | 112 | //! Connect Image \b o | 
|---|
|  | 113 | template <class T> | 
|---|
|  | 114 | void FIO_Image<T>::SetDataObj(AnyDataObj & o) | 
|---|
|  | 115 | { | 
|---|
|  | 116 | Image<T> * po = dynamic_cast< Image<T> * >(&o); | 
|---|
|  | 117 | if (po == NULL) return; | 
|---|
|  | 118 | if (ownobj && dobj) delete dobj; | 
|---|
|  | 119 | dobj = po; ownobj = false; | 
|---|
|  | 120 | } | 
|---|
|  | 121 |  | 
|---|
|  | 122 | template <class T> | 
|---|
|  | 123 | void FIO_Image<T>::ReadSelf(PInPersist& is) | 
|---|
|  | 124 | { | 
|---|
|  | 125 | if (dobj == NULL) dobj = new Image<T>; | 
|---|
|  | 126 | Image<T> * img = dynamic_cast<Image<T> * > (dobj); | 
|---|
|  | 127 | // On lit les 3 premiers uint_4 | 
|---|
|  | 128 | //  0: Numero de version,  1 : reserve | 
|---|
|  | 129 | uint_4 itab[3]; | 
|---|
|  | 130 | is.Get(itab,3); | 
|---|
|  | 131 |  | 
|---|
|  | 132 | // Image<T> part data | 
|---|
|  | 133 | r_8 orgx, orgy; | 
|---|
|  | 134 | is.Get(orgx); | 
|---|
|  | 135 | is.Get(orgy); | 
|---|
|  | 136 | img->SetOrg(orgx, orgy); | 
|---|
|  | 137 | r_8 szx, szy; | 
|---|
|  | 138 | is.Get(szx); | 
|---|
|  | 139 | is.Get(szy); | 
|---|
|  | 140 | img->SetPixelSize(szx, szy); | 
|---|
|  | 141 |  | 
|---|
|  | 142 | // Reading the TArray part | 
|---|
|  | 143 | FIO_TArray<T>::ReadSelf(is); | 
|---|
|  | 144 | } | 
|---|
|  | 145 |  | 
|---|
|  | 146 | template <class T> | 
|---|
|  | 147 | void FIO_Image<T>::WriteSelf(POutPersist& os) const | 
|---|
|  | 148 | { | 
|---|
|  | 149 | if (dobj == NULL)   return; | 
|---|
|  | 150 | Image<T> * img = dynamic_cast<Image<T> * > (dobj); | 
|---|
|  | 151 | //  On ecrit 3 uint_4 .... | 
|---|
|  | 152 | uint_4 itab[3]; | 
|---|
|  | 153 | itab[0] = 1;  // Numero de version a 1 | 
|---|
|  | 154 | itab[1] = 0; | 
|---|
|  | 155 | itab[2] = 0; | 
|---|
|  | 156 | os.Put(itab,3); | 
|---|
|  | 157 |  | 
|---|
|  | 158 | // Image<T> part data | 
|---|
|  | 159 | os.Put(img->XOrg()); | 
|---|
|  | 160 | os.Put(img->XOrg()); | 
|---|
|  | 161 | os.Put(img->XPixSize()); | 
|---|
|  | 162 | os.Put(img->YPixSize()); | 
|---|
|  | 163 |  | 
|---|
|  | 164 | // Writing the TArray part | 
|---|
|  | 165 | FIO_TArray<T>::WriteSelf(os); | 
|---|
|  | 166 | } | 
|---|
|  | 167 |  | 
|---|
| [1104] | 168 | /////////////////////////////////////////////////////////////// | 
|---|
| [220] | 169 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 170 | #pragma define_template Image<uint_2> | 
|---|
|  | 171 | #pragma define_template Image<int_4> | 
|---|
| [1104] | 172 | #pragma define_template Image<int_8> | 
|---|
| [220] | 173 | #pragma define_template Image<r_4> | 
|---|
| [1104] | 174 | #pragma define_template Image<r_8> | 
|---|
|  | 175 | //#pragma define_template Image< complex<r_4> > | 
|---|
|  | 176 | //#pragma define_template Image< complex<r_8> > | 
|---|
| [1159] | 177 |  | 
|---|
|  | 178 | #pragma define_template FIO_Image<uint_2> | 
|---|
|  | 179 | #pragma define_template FIO_Image<int_4> | 
|---|
|  | 180 | #pragma define_template FIO_Image<int_8> | 
|---|
|  | 181 | #pragma define_template FIO_Image<r_4> | 
|---|
|  | 182 | #pragma define_template FIO_Image<r_8> | 
|---|
| [220] | 183 | #endif | 
|---|
|  | 184 |  | 
|---|
| [1104] | 185 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
| [220] | 186 | template class Image<uint_2>; | 
|---|
|  | 187 | template class Image<int_4>; | 
|---|
| [1104] | 188 | template class Image<int_8>; | 
|---|
| [220] | 189 | template class Image<r_4>; | 
|---|
| [1104] | 190 | template class Image<r_8>; | 
|---|
|  | 191 | //template class Image< complex<r_4> >; | 
|---|
|  | 192 | //template class Image< complex<r_8> >; | 
|---|
| [1159] | 193 |  | 
|---|
|  | 194 | template class FIO_Image<uint_2>; | 
|---|
|  | 195 | template class FIO_Image<int_4>; | 
|---|
|  | 196 | template class FIO_Image<int_8>; | 
|---|
|  | 197 | template class FIO_Image<r_4>; | 
|---|
|  | 198 | template class FIO_Image<r_8>; | 
|---|
|  | 199 |  | 
|---|
| [220] | 200 | #endif | 
|---|