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