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