| 1 | #include "sopnamsp.h" | 
|---|
| 2 | #include "machdefs.h" | 
|---|
| 3 | #include <stdlib.h> | 
|---|
| 4 | #include <typeinfo> | 
|---|
| 5 | #include <iostream> | 
|---|
| 6 | #include <string> | 
|---|
| 7 |  | 
|---|
| 8 | #include "datatype.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include "nomimagadapter.h" | 
|---|
| 11 | #include "pimgadapter.h" | 
|---|
| 12 |  | 
|---|
| 13 | #ifdef SANS_EVOLPLANCK | 
|---|
| 14 | #include "fitsimage.h" | 
|---|
| 15 | #else | 
|---|
| 16 | #include "objfitter.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 |  | 
|---|
| 74 | /* --Methode-- */ | 
|---|
| 75 | template <class T> | 
|---|
| 76 | void NOMAdapter_Image<T>::SavePPF(POutPersist& pos, string const & nom) | 
|---|
| 77 | { | 
|---|
| 78 | #ifdef SANS_EVOLPLANCK | 
|---|
| 79 | // PEIDA-EROS L'histo est lui-meme PPersist | 
|---|
| 80 | string tag = nom;  // A cause de const | 
|---|
| 81 | mImg->Write(pos,0,tag); | 
|---|
| 82 | #else | 
|---|
| 83 | string s = typeid(*mObj).name(); | 
|---|
| 84 | cout << "NOMAdapter_Image<T>::SavePPF() - Error : Not supported for " << s << endl; | 
|---|
| 85 | #endif | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | /* --Methode-- */ | 
|---|
| 89 | template <class T> | 
|---|
| 90 | void NOMAdapter_Image<T>::Print(ostream& os, int lev) | 
|---|
| 91 | { | 
|---|
| 92 | if (lev < 3) mImg->Show(os, false); | 
|---|
| 93 | else  mImg->Show(os, true); | 
|---|
| 94 | if (lev > 0) mImg->Print(os, 10*lev); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | /* --Methode-- */ | 
|---|
| 99 | template <class T> | 
|---|
| 100 | P2DArrayAdapter* NOMAdapter_Image<T>::Get2DArray(string &) | 
|---|
| 101 | { | 
|---|
| 102 | return ( new ImageAdapter<T>(mImg, false) ); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | /* --Methode-- */ | 
|---|
| 106 | template <class T> | 
|---|
| 107 | NTupleInterface* NOMAdapter_Image<T>::GetNTupleInterface(bool& adel) | 
|---|
| 108 | { | 
|---|
| 109 | adel = true; | 
|---|
| 110 | return( new NTupInt_Image<T>(mImg) ); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | /* --Methode-- */ | 
|---|
| 114 | template <class T> | 
|---|
| 115 | GeneralFitData* NOMAdapter_Image<T>::GetGeneralFitData(bool& adel | 
|---|
| 116 | ,GeneralFitData::FitErrType errtype,double errscale,double errmin | 
|---|
| 117 | ,int i1,int i2,int j1,int j2) | 
|---|
| 118 | { | 
|---|
| 119 | adel = false; | 
|---|
| 120 | if(!mImg) return(NULL); | 
|---|
| 121 |  | 
|---|
| 122 | int nx = mImg->XSize(); | 
|---|
| 123 | int ny = mImg->YSize(); | 
|---|
| 124 | if(nx<=0 || ny<=0) return(NULL); | 
|---|
| 125 |  | 
|---|
| 126 | i1 = (i1<0||i1>=nx)? 0: i1; | 
|---|
| 127 | i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2; | 
|---|
| 128 | j1 = (j1<0||j1>=ny)? 0: j1; | 
|---|
| 129 | j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2; | 
|---|
| 130 |  | 
|---|
| 131 | GeneralFitData* mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0); | 
|---|
| 132 | adel = true; | 
|---|
| 133 |  | 
|---|
| 134 | for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) { | 
|---|
| 135 | double x = mImg->XPos(i); | 
|---|
| 136 | double y = mImg->YPos(j); | 
|---|
| 137 | double f = (*mImg)(i,j); | 
|---|
| 138 | double e = 1.; | 
|---|
| 139 | e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin); | 
|---|
| 140 | mGData->AddData2(x,y,f,e); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | return mGData; | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | template <class T> | 
|---|
| 147 | AnyDataObj* NOMAdapter_Image<T>::FitResidusObj(GeneralFit& mfit) | 
|---|
| 148 | { | 
|---|
| 149 | #ifdef SANS_EVOLPLANCK | 
|---|
| 150 | RzImage* rzim = mImg->FitResidus(mfit); | 
|---|
| 151 | ImageR4* im   = new ImageR4(*rzim); | 
|---|
| 152 | return im; | 
|---|
| 153 | #else | 
|---|
| 154 | Image<T>* im = new Image<T>(ObjectFitter::FitResidus(*mImg,mfit)); | 
|---|
| 155 | return im; | 
|---|
| 156 | #endif | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|
| 159 | template <class T> | 
|---|
| 160 | AnyDataObj* NOMAdapter_Image<T>::FitFunctionObj(GeneralFit& mfit) | 
|---|
| 161 | { | 
|---|
| 162 | #ifdef SANS_EVOLPLANCK | 
|---|
| 163 | RzImage* rzim = mImg->FitFunction(mfit); | 
|---|
| 164 | ImageR4* im   = new ImageR4(*rzim); | 
|---|
| 165 | return im; | 
|---|
| 166 | #else | 
|---|
| 167 | Image<T>* im = NULL; | 
|---|
| 168 | //im = new Image<T>(ObjectFitter::FitFunction(*mImg,mfit)); | 
|---|
| 169 | return im; | 
|---|
| 170 | #endif | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 |  | 
|---|
| 174 | // ------------------------------------------------------------- | 
|---|
| 175 |  | 
|---|
| 176 | /* --Methode-- */ | 
|---|
| 177 | template <class T> | 
|---|
| 178 | NTupInt_Image<T>::NTupInt_Image(Image<T>* m) | 
|---|
| 179 | { | 
|---|
| 180 | mImg = m; | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|
| 183 | /* --Methode-- */ | 
|---|
| 184 | template <class T> | 
|---|
| 185 | NTupInt_Image<T>::~NTupInt_Image() | 
|---|
| 186 | { | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | /* --Methode-- */ | 
|---|
| 190 | template <class T> | 
|---|
| 191 | sa_size_t NTupInt_Image<T>::NbLines() const | 
|---|
| 192 | { | 
|---|
| 193 | return( mImg->XSize() * mImg->YSize() ); | 
|---|
| 194 | } | 
|---|
| 195 |  | 
|---|
| 196 | /* --Methode-- */ | 
|---|
| 197 | template <class T> | 
|---|
| 198 | sa_size_t NTupInt_Image<T>::NbColumns() const | 
|---|
| 199 | { | 
|---|
| 200 | return(3); | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 | /* --Methode-- */ | 
|---|
| 204 | template <class T> | 
|---|
| 205 | r_8* NTupInt_Image<T>::GetLineD(sa_size_t n) const | 
|---|
| 206 | { | 
|---|
| 207 | int i,j; | 
|---|
| 208 | if ((n < 0) || (n >= mImg->XSize() * mImg->YSize() )) | 
|---|
| 209 | for(i=0; i<3; i++)  mRet[i] = 0.; | 
|---|
| 210 | else { | 
|---|
| 211 | i = n%mImg->XSize();  j = n/mImg->XSize(); | 
|---|
| 212 | mRet[0] = i;  mRet[1] = j;  mRet[2] = (*mImg)(i,j); | 
|---|
| 213 | } | 
|---|
| 214 | return(mRet); | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | /* --Methode-- */ | 
|---|
| 218 | template <class T> | 
|---|
| 219 | string NTupInt_Image<T>::VarList_C(const char* nx) const | 
|---|
| 220 | { | 
|---|
| 221 | string nomx; | 
|---|
| 222 | if (nx) nomx = nx; | 
|---|
| 223 | else nomx = "_xh_"; | 
|---|
| 224 | string vardec = "double x,y,pix,i,j,val; \n"; | 
|---|
| 225 | vardec += "x = i = " + nomx + "[0]; y = j = " + nomx + "[1];  pix = val = " + nomx + "[2]; \n"; | 
|---|
| 226 | return(vardec); | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
| 230 | #pragma define_template NOMAdapter_Image<uint_2> | 
|---|
| 231 | #pragma define_template NOMAdapter_Image<int_4> | 
|---|
| 232 | #pragma define_template NOMAdapter_Image<r_4> | 
|---|
| 233 | #pragma define_template NOMAdapter_Image<r_8> | 
|---|
| 234 | #pragma define_template NTupInt_Image<uint_2> | 
|---|
| 235 | #pragma define_template NTupInt_Image<int_4> | 
|---|
| 236 | #pragma define_template NTupInt_Image<r_4> | 
|---|
| 237 | #pragma define_template NTupInt_Image<r_8> | 
|---|
| 238 | #ifdef SANS_EVOLPLANCK | 
|---|
| 239 | #pragma define_template NOMAdapter_Image<int_2> | 
|---|
| 240 | #pragma define_template NTupInt_Image<int_2> | 
|---|
| 241 | #endif | 
|---|
| 242 | #endif | 
|---|
| 243 | #if defined(ANSI_TEMPLATES) || defined(__ANSI_TEMPLATES__) || defined(__GNU_TEMPLATES__) | 
|---|
| 244 | template class NOMAdapter_Image<uint_2>; | 
|---|
| 245 | template class NOMAdapter_Image<int_4>; | 
|---|
| 246 | template class NOMAdapter_Image<r_4>; | 
|---|
| 247 | template class NOMAdapter_Image<r_8>; | 
|---|
| 248 | template class NTupInt_Image<uint_2>; | 
|---|
| 249 | template class NTupInt_Image<int_4>; | 
|---|
| 250 | template class NTupInt_Image<r_4>; | 
|---|
| 251 | template class NTupInt_Image<r_8>; | 
|---|
| 252 | #ifdef SANS_EVOLPLANCK | 
|---|
| 253 | template class NOMAdapter_Image<int_2>; | 
|---|
| 254 | template class NTupInt_Image<int_2>; | 
|---|
| 255 | #endif | 
|---|
| 256 | #endif | 
|---|
| 257 |  | 
|---|
| 258 |  | 
|---|