1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <typeinfo>
|
---|
4 | #include <iostream>
|
---|
5 | #include <string>
|
---|
6 |
|
---|
7 | #include "datatype.h"
|
---|
8 |
|
---|
9 | #include "nomimagadapter.h"
|
---|
10 | #include "pimgadapter.h"
|
---|
11 |
|
---|
12 | #ifdef SANS_EVOLPLANCK
|
---|
13 | #include "fitsimage.h"
|
---|
14 | #else
|
---|
15 | #include "objfitter.h"
|
---|
16 | #include "fitstarray.h"
|
---|
17 | #endif
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | //---------------------------------------------------------------
|
---|
22 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet Image<T>
|
---|
23 | //---------------------------------------------------------------
|
---|
24 |
|
---|
25 |
|
---|
26 | /* --Methode-- */
|
---|
27 | template <class T>
|
---|
28 | NOMAdapter_Image<T>::NOMAdapter_Image(Image<T> * o)
|
---|
29 | : NObjMgrAdapter(o)
|
---|
30 | {
|
---|
31 | mImg = o;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /* --Methode-- */
|
---|
35 | template <class T>
|
---|
36 | NOMAdapter_Image<T>::~NOMAdapter_Image()
|
---|
37 | {
|
---|
38 | }
|
---|
39 |
|
---|
40 | /* --Methode-- */
|
---|
41 | template <class T>
|
---|
42 | NObjMgrAdapter* NOMAdapter_Image<T>::Clone(AnyDataObj* o)
|
---|
43 | {
|
---|
44 | Image<T>* im = dynamic_cast<Image<T> *>(o);
|
---|
45 | if (im) return ( new NOMAdapter_Image<T>(im) );
|
---|
46 | return ( new NObjMgrAdapter(o) );
|
---|
47 | }
|
---|
48 |
|
---|
49 | /* --Methode-- */
|
---|
50 | template <class T>
|
---|
51 | string NOMAdapter_Image<T>::GetDataObjType()
|
---|
52 | {
|
---|
53 | string type = "Image< ";
|
---|
54 | // type += DecodeTypeIdName(typeid(T).name());
|
---|
55 | type += DataTypeInfo<T>::getTypeName();
|
---|
56 | type += " > ";
|
---|
57 | return(type);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /* --Methode-- */
|
---|
61 | template <class T>
|
---|
62 | AnyDataObj* NOMAdapter_Image<T>::CloneDataObj(bool share)
|
---|
63 | {
|
---|
64 | #ifdef SANS_EVOLPLANCK
|
---|
65 | FitsImage<T> * fima = dynamic_cast<FitsImage<T> *>(mImg);
|
---|
66 | if (fima == NULL) return( new Image<T>(*mImg ) );
|
---|
67 | else return ( new FitsImage<T>(*fima) );
|
---|
68 | #else
|
---|
69 | return( new Image<T>(*mImg, share) );
|
---|
70 | #endif
|
---|
71 | }
|
---|
72 |
|
---|
73 | /* --Methode-- */
|
---|
74 | template <class T>
|
---|
75 | void NOMAdapter_Image<T>::ReadFits(string const & flnm)
|
---|
76 | {
|
---|
77 | #ifdef SANS_EVOLPLANCK
|
---|
78 | cerr << " NOMAdapter_Image<T>::ReadFits() Non disponible !! " << endl;
|
---|
79 | #else
|
---|
80 | FitsInFile fis(flnm);
|
---|
81 | fis >> (*mImg);
|
---|
82 | #endif
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* --Methode-- */
|
---|
86 | template <class T>
|
---|
87 | void NOMAdapter_Image<T>::SaveFits(string const & flnm)
|
---|
88 | {
|
---|
89 | #ifdef SANS_EVOLPLANCK
|
---|
90 | FitsImage<T> fim(*mImg, 1);
|
---|
91 | fim.Save(flnm);
|
---|
92 | #else
|
---|
93 | FitsOutFile fos(flnm);
|
---|
94 | fos << (*mImg);
|
---|
95 | #endif
|
---|
96 | }
|
---|
97 |
|
---|
98 | #ifndef SANS_EVOLPLANCK
|
---|
99 | #if defined(__SGICC__)
|
---|
100 | template <>
|
---|
101 | #endif
|
---|
102 | void NOMAdapter_Image< uint_2 >::SaveFits(string const & flnm)
|
---|
103 | {
|
---|
104 | cout << " NOMAdapter_Image< uint_2 >::SaveFits() - Error "
|
---|
105 | << " Not supported uint_2 data type ! " << endl;
|
---|
106 | }
|
---|
107 |
|
---|
108 | #if defined(__SGICC__)
|
---|
109 | template <>
|
---|
110 | #endif
|
---|
111 | void NOMAdapter_Image< uint_2 >::ReadFits(string const & flnm)
|
---|
112 | {
|
---|
113 | cout << " NOMAdapter_Image< uint_2 >::ReadFits() - Error "
|
---|
114 | << " Not supported uint_2 data type ! " << endl;
|
---|
115 | }
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | /* --Methode-- */
|
---|
119 | template <class T>
|
---|
120 | void NOMAdapter_Image<T>::SavePPF(POutPersist& pos, string const & nom)
|
---|
121 | {
|
---|
122 | #ifdef SANS_EVOLPLANCK
|
---|
123 | // PEIDA-EROS L'histo est lui-meme PPersist
|
---|
124 | string tag = nom; // A cause de const
|
---|
125 | mImg->Write(pos,0,tag);
|
---|
126 | #else
|
---|
127 | string s = typeid(*mObj).name();
|
---|
128 | cout << "NOMAdapter_Image<T>::SavePPF() - Error : Not supported for " << s << endl;
|
---|
129 | #endif
|
---|
130 | }
|
---|
131 |
|
---|
132 | /* --Methode-- */
|
---|
133 | template <class T>
|
---|
134 | void NOMAdapter_Image<T>::Print(ostream& os)
|
---|
135 | {
|
---|
136 | mImg->Print(os);
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | /* --Methode-- */
|
---|
141 | template <class T>
|
---|
142 | P2DArrayAdapter* NOMAdapter_Image<T>::Get2DArray(string &)
|
---|
143 | {
|
---|
144 | return ( new ImageAdapter<T>(mImg, false) );
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* --Methode-- */
|
---|
148 | template <class T>
|
---|
149 | NTupleInterface* NOMAdapter_Image<T>::GetNTupleInterface(bool& adel)
|
---|
150 | {
|
---|
151 | adel = true;
|
---|
152 | return( new NTupInt_Image<T>(mImg) );
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* --Methode-- */
|
---|
156 | template <class T>
|
---|
157 | GeneralFitData* NOMAdapter_Image<T>::GetGeneralFitData(bool& adel
|
---|
158 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin
|
---|
159 | ,int i1,int i2,int j1,int j2)
|
---|
160 | {
|
---|
161 | adel = false;
|
---|
162 | if(!mImg) return(NULL);
|
---|
163 |
|
---|
164 | int nx = mImg->XSize();
|
---|
165 | int ny = mImg->YSize();
|
---|
166 | if(nx<=0 || ny<=0) return(NULL);
|
---|
167 |
|
---|
168 | i1 = (i1<0||i1>=nx)? 0: i1;
|
---|
169 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
|
---|
170 | j1 = (j1<0||j1>=ny)? 0: j1;
|
---|
171 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
|
---|
172 |
|
---|
173 | GeneralFitData* mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
|
---|
174 | adel = true;
|
---|
175 |
|
---|
176 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
|
---|
177 | double x = mImg->XPos(i);
|
---|
178 | double y = mImg->YPos(j);
|
---|
179 | double f = (*mImg)(i,j);
|
---|
180 | double e = 1.;
|
---|
181 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
|
---|
182 | mGData->AddData2(x,y,f,e);
|
---|
183 | }
|
---|
184 |
|
---|
185 | return mGData;
|
---|
186 | }
|
---|
187 |
|
---|
188 | template <class T>
|
---|
189 | AnyDataObj* NOMAdapter_Image<T>::FitResidusObj(GeneralFit& mfit)
|
---|
190 | {
|
---|
191 | #ifdef SANS_EVOLPLANCK
|
---|
192 | RzImage* rzim = mImg->FitResidus(mfit);
|
---|
193 | ImageR4* im = new ImageR4(*rzim);
|
---|
194 | return im;
|
---|
195 | #else
|
---|
196 | Image<T>* im = new Image<T>(ObjectFitter::FitResidus(*mImg,mfit));
|
---|
197 | return im;
|
---|
198 | #endif
|
---|
199 | }
|
---|
200 |
|
---|
201 | template <class T>
|
---|
202 | AnyDataObj* NOMAdapter_Image<T>::FitFunctionObj(GeneralFit& mfit)
|
---|
203 | {
|
---|
204 | #ifdef SANS_EVOLPLANCK
|
---|
205 | RzImage* rzim = mImg->FitFunction(mfit);
|
---|
206 | ImageR4* im = new ImageR4(*rzim);
|
---|
207 | return im;
|
---|
208 | #else
|
---|
209 | Image<T>* im = NULL;
|
---|
210 | //im = new Image<T>(ObjectFitter::FitFunction(*mImg,mfit));
|
---|
211 | return im;
|
---|
212 | #endif
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 | // -------------------------------------------------------------
|
---|
217 |
|
---|
218 | /* --Methode-- */
|
---|
219 | template <class T>
|
---|
220 | NTupInt_Image<T>::NTupInt_Image(Image<T>* m)
|
---|
221 | {
|
---|
222 | mImg = m;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /* --Methode-- */
|
---|
226 | template <class T>
|
---|
227 | NTupInt_Image<T>::~NTupInt_Image()
|
---|
228 | {
|
---|
229 | }
|
---|
230 |
|
---|
231 | /* --Methode-- */
|
---|
232 | template <class T>
|
---|
233 | uint_4 NTupInt_Image<T>::NbLines() const
|
---|
234 | {
|
---|
235 | return( mImg->XSize() * mImg->YSize() );
|
---|
236 | }
|
---|
237 |
|
---|
238 | /* --Methode-- */
|
---|
239 | template <class T>
|
---|
240 | uint_4 NTupInt_Image<T>::NbColumns() const
|
---|
241 | {
|
---|
242 | return(3);
|
---|
243 | }
|
---|
244 |
|
---|
245 | /* --Methode-- */
|
---|
246 | template <class T>
|
---|
247 | r_8* NTupInt_Image<T>::GetLineD(int n) const
|
---|
248 | {
|
---|
249 | int i,j;
|
---|
250 | if ((n < 0) || (n >= mImg->XSize() * mImg->YSize() ))
|
---|
251 | for(i=0; i<3; i++) mRet[i] = 0.;
|
---|
252 | else {
|
---|
253 | i = n%mImg->XSize(); j = n/mImg->XSize();
|
---|
254 | mRet[0] = i; mRet[1] = j; mRet[2] = (*mImg)(i,j);
|
---|
255 | }
|
---|
256 | return(mRet);
|
---|
257 | }
|
---|
258 |
|
---|
259 | /* --Methode-- */
|
---|
260 | template <class T>
|
---|
261 | string NTupInt_Image<T>::VarList_C(const char* nx) const
|
---|
262 | {
|
---|
263 | string nomx;
|
---|
264 | if (nx) nomx = nx;
|
---|
265 | else nomx = "_xh_";
|
---|
266 | string vardec = "double x,y,pix,i,j,val; \n";
|
---|
267 | vardec += "x = i = " + nomx + "[0]; y = j = " + nomx + "[1]; pix = val = " + nomx + "[2]; \n";
|
---|
268 | return(vardec);
|
---|
269 | }
|
---|
270 |
|
---|
271 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
272 | #pragma define_template NOMAdapter_Image<uint_2>
|
---|
273 | #pragma define_template NOMAdapter_Image<int_4>
|
---|
274 | #pragma define_template NOMAdapter_Image<r_4>
|
---|
275 | #pragma define_template NTupInt_Image<uint_2>
|
---|
276 | #pragma define_template NTupInt_Image<int_4>
|
---|
277 | #pragma define_template NTupInt_Image<r_4>
|
---|
278 | #ifdef SANS_EVOLPLANCK
|
---|
279 | #pragma define_template NOMAdapter_Image<int_2>
|
---|
280 | #pragma define_template NTupInt_Image<int_2>
|
---|
281 | #endif
|
---|
282 | #endif
|
---|
283 | #if defined(ANSI_TEMPLATES) || defined(__ANSI_TEMPLATES__) || defined(__GNU_TEMPLATES__)
|
---|
284 | template class NOMAdapter_Image<uint_2>;
|
---|
285 | template class NOMAdapter_Image<int_4>;
|
---|
286 | template class NOMAdapter_Image<r_4>;
|
---|
287 | template class NTupInt_Image<uint_2>;
|
---|
288 | template class NTupInt_Image<int_4>;
|
---|
289 | template class NTupInt_Image<r_4>;
|
---|
290 | #ifdef SANS_EVOLPLANCK
|
---|
291 | template class NOMAdapter_Image<int_2>;
|
---|
292 | template class NTupInt_Image<int_2>;
|
---|
293 | #endif
|
---|
294 | #endif
|
---|
295 |
|
---|
296 |
|
---|