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