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