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