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 | /*!
|
---|
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
|
---|
21 | template <class T>
|
---|
22 | Image<T>::Image()
|
---|
23 | // Constructeur par defaut.
|
---|
24 | : TMatrix<T>()
|
---|
25 | {
|
---|
26 | SetOrg();
|
---|
27 | SetPixelSize();
|
---|
28 | }
|
---|
29 |
|
---|
30 | //! Constructor, with specification of the image size, pixel size and offsets
|
---|
31 | template <class T>
|
---|
32 | Image<T>::Image(sa_size_t sizx, sa_size_t sizy, r_8 szpx, r_8 szpy, r_8 orgx, r_8 orgy)
|
---|
33 | // Constructeur par defaut.
|
---|
34 | : TMatrix<T>(sizy, sizx)
|
---|
35 | {
|
---|
36 | SetOrg(orgx, orgy);
|
---|
37 | SetPixelSize(szpx, szpy);
|
---|
38 | }
|
---|
39 |
|
---|
40 | //! Copy constructor
|
---|
41 | template <class T>
|
---|
42 | Image<T>::Image(const Image<T>& a)
|
---|
43 | : TMatrix<T>(a)
|
---|
44 | {
|
---|
45 | SetOrg(a.XOrg(), a.YOrg() );
|
---|
46 | SetPixelSize(a.XPixSize(), a.YPixSize());
|
---|
47 | }
|
---|
48 |
|
---|
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 | */
|
---|
54 | template <class T>
|
---|
55 | Image<T>::Image(const Image<T>& a, bool share)
|
---|
56 | : TMatrix<T>(a, share)
|
---|
57 | {
|
---|
58 | SetOrg(a.XOrg(), a.YOrg() );
|
---|
59 | SetPixelSize(a.XPixSize(), a.YPixSize());
|
---|
60 | }
|
---|
61 |
|
---|
62 | //! Destructor
|
---|
63 | template <class T>
|
---|
64 | Image<T>::~Image()
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
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 |
|
---|
168 | ///////////////////////////////////////////////////////////////
|
---|
169 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
170 | #pragma define_template Image<uint_2>
|
---|
171 | #pragma define_template Image<int_4>
|
---|
172 | #pragma define_template Image<int_8>
|
---|
173 | #pragma define_template Image<r_4>
|
---|
174 | #pragma define_template Image<r_8>
|
---|
175 | //#pragma define_template Image< complex<r_4> >
|
---|
176 | //#pragma define_template Image< complex<r_8> >
|
---|
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>
|
---|
183 | #endif
|
---|
184 |
|
---|
185 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
186 | template class Image<uint_2>;
|
---|
187 | template class Image<int_4>;
|
---|
188 | template class Image<int_8>;
|
---|
189 | template class Image<r_4>;
|
---|
190 | template class Image<r_8>;
|
---|
191 | //template class Image< complex<r_4> >;
|
---|
192 | //template class Image< complex<r_8> >;
|
---|
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 |
|
---|
200 | #endif
|
---|