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