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