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