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