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