[2615] | 1 | #include "sopnamsp.h"
|
---|
[295] | 2 | #include "machdefs.h"
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <typeinfo>
|
---|
[2322] | 5 | #include <iostream>
|
---|
[295] | 6 | #include <string>
|
---|
| 7 |
|
---|
[1224] | 8 | #include "datatype.h"
|
---|
| 9 |
|
---|
[295] | 10 | #include "nomimagadapter.h"
|
---|
[1207] | 11 | #include "pimgadapter.h"
|
---|
| 12 |
|
---|
[495] | 13 | #ifdef SANS_EVOLPLANCK
|
---|
[295] | 14 | #include "fitsimage.h"
|
---|
[1207] | 15 | #else
|
---|
| 16 | #include "objfitter.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 |
|
---|
[1321] | 73 |
|
---|
| 74 | /* --Methode-- */
|
---|
| 75 | template <class T>
|
---|
[295] | 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>
|
---|
[2975] | 90 | void NOMAdapter_Image<T>::Print(ostream& os, int lev)
|
---|
[295] | 91 | {
|
---|
[2975] | 92 | if (lev < 3) mImg->Show(os, false);
|
---|
| 93 | else mImg->Show(os, true);
|
---|
| 94 | if (lev > 0) mImg->Print(os, 10*lev);
|
---|
[295] | 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>
|
---|
[344] | 107 | NTupleInterface* NOMAdapter_Image<T>::GetNTupleInterface(bool& adel)
|
---|
[295] | 108 | {
|
---|
[344] | 109 | adel = true;
|
---|
[295] | 110 | return( new NTupInt_Image<T>(mImg) );
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[1207] | 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);
|
---|
[295] | 121 |
|
---|
[1207] | 122 | int nx = mImg->XSize();
|
---|
| 123 | int ny = mImg->YSize();
|
---|
| 124 | if(nx<=0 || ny<=0) return(NULL);
|
---|
[295] | 125 |
|
---|
[1207] | 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 |
|
---|
[295] | 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>
|
---|
[2683] | 191 | sa_size_t NTupInt_Image<T>::NbLines() const
|
---|
[295] | 192 | {
|
---|
| 193 | return( mImg->XSize() * mImg->YSize() );
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /* --Methode-- */
|
---|
| 197 | template <class T>
|
---|
[2683] | 198 | sa_size_t NTupInt_Image<T>::NbColumns() const
|
---|
[295] | 199 | {
|
---|
| 200 | return(3);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /* --Methode-- */
|
---|
| 204 | template <class T>
|
---|
[2683] | 205 | r_8* NTupInt_Image<T>::GetLineD(sa_size_t n) const
|
---|
[295] | 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>
|
---|
[326] | 219 | string NTupInt_Image<T>::VarList_C(const char* nx) const
|
---|
[295] | 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 NTupInt_Image<uint_2>
|
---|
| 234 | #pragma define_template NTupInt_Image<int_4>
|
---|
| 235 | #pragma define_template NTupInt_Image<r_4>
|
---|
[1105] | 236 | #ifdef SANS_EVOLPLANCK
|
---|
| 237 | #pragma define_template NOMAdapter_Image<int_2>
|
---|
| 238 | #pragma define_template NTupInt_Image<int_2>
|
---|
[295] | 239 | #endif
|
---|
[1105] | 240 | #endif
|
---|
[506] | 241 | #if defined(ANSI_TEMPLATES) || defined(__ANSI_TEMPLATES__) || defined(__GNU_TEMPLATES__)
|
---|
[295] | 242 | template class NOMAdapter_Image<uint_2>;
|
---|
| 243 | template class NOMAdapter_Image<int_4>;
|
---|
| 244 | template class NOMAdapter_Image<r_4>;
|
---|
| 245 | template class NTupInt_Image<uint_2>;
|
---|
| 246 | template class NTupInt_Image<int_4>;
|
---|
| 247 | template class NTupInt_Image<r_4>;
|
---|
[1105] | 248 | #ifdef SANS_EVOLPLANCK
|
---|
| 249 | template class NOMAdapter_Image<int_2>;
|
---|
| 250 | template class NTupInt_Image<int_2>;
|
---|
[295] | 251 | #endif
|
---|
[1105] | 252 | #endif
|
---|
[295] | 253 |
|
---|
| 254 |
|
---|