| [3573] | 1 | #include "machdefs.h" | 
|---|
|  | 2 | #include <iostream> | 
|---|
|  | 3 | #include <stdlib.h> | 
|---|
|  | 4 | #include <stdio.h> | 
|---|
|  | 5 | #include <math.h> | 
|---|
|  | 6 | #include <algorithm> | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "pexceptions.h" | 
|---|
|  | 9 |  | 
|---|
|  | 10 | #include "slinparbuff.h" | 
|---|
|  | 11 |  | 
|---|
|  | 12 | namespace SOPHYA { | 
|---|
|  | 13 |  | 
|---|
|  | 14 | //================================================================ | 
|---|
|  | 15 | // SLinParBuff | 
|---|
|  | 16 | //================================================================ | 
|---|
|  | 17 |  | 
|---|
|  | 18 | // ---- Createur | 
|---|
|  | 19 | SLinParBuff::SLinParBuff(uint_4 lenbuf,uint_4 nresynch,r_8 x0,r_8 y0,bool autoxy0) | 
|---|
|  | 20 | { | 
|---|
|  | 21 | if(lenbuf==0) throw RangeCheckError("SLinParBuff: lenbuf==0 !"); | 
|---|
|  | 22 | mLenBuf = lenbuf; | 
|---|
|  | 23 | mNResynch = nresynch; | 
|---|
|  | 24 | mX = new r_8[mLenBuf]; mY = new r_8[mLenBuf]; | 
|---|
|  | 25 | mX0 = x0; mY0 = y0; mAutoXY0 = autoxy0; | 
|---|
|  | 26 | Reset(); | 
|---|
|  | 27 | } | 
|---|
|  | 28 |  | 
|---|
|  | 29 | // ---- Createur par copie | 
|---|
|  | 30 | SLinParBuff::SLinParBuff(SLinParBuff& slp) | 
|---|
|  | 31 | { | 
|---|
|  | 32 | mLenBuf = slp.mLenBuf; | 
|---|
|  | 33 | mNResynch = slp.mNResynch; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | mX = mY = NULL; | 
|---|
|  | 36 | if(mLenBuf) { | 
|---|
|  | 37 | mX = new r_8[mLenBuf]; mY = new r_8[mLenBuf]; | 
|---|
|  | 38 | for(uint_4 i=0;i<mLenBuf;i++) {mX[i]=slp.mX[i]; mY[i]=slp.mY[i];} | 
|---|
|  | 39 | } | 
|---|
|  | 40 |  | 
|---|
|  | 41 | mX0 = slp.mX0; mY0 = slp.mY0; mAutoXY0 = slp.mAutoXY0; | 
|---|
|  | 42 | mNCur = slp.mNCur; mIDeb = slp.mIDeb; mIResynch = slp.mIResynch; | 
|---|
|  | 43 | mNResynchEff = slp.mNResynchEff; mNPush = slp.mNPush; mNPop = slp.mNPop; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | mSx = slp.mSx; mSy = slp.mSy; | 
|---|
|  | 46 | mSx2 = slp.mSx2; mSy2 = slp.mSy2; mSxy = slp.mSxy; | 
|---|
|  | 47 | mSx3 = slp.mSx3; mSx2y = slp.mSx2y; | 
|---|
|  | 48 | mSx4 = slp.mSx4; | 
|---|
|  | 49 | } | 
|---|
|  | 50 |  | 
|---|
|  | 51 | // ---- Createur par defaut | 
|---|
|  | 52 | SLinParBuff::SLinParBuff(void) | 
|---|
|  | 53 | { | 
|---|
|  | 54 | mLenBuf = 0; mNResynch = 0; | 
|---|
|  | 55 | mX = mY = NULL; | 
|---|
|  | 56 | mX0 = mY0 = 0.; mAutoXY0 = false; | 
|---|
|  | 57 | Reset(); | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
|  | 60 | // ---- Destructeur | 
|---|
|  | 61 | SLinParBuff::~SLinParBuff() | 
|---|
|  | 62 | { | 
|---|
|  | 63 | if(mX) delete [] mX; if(mY) delete [] mY; | 
|---|
|  | 64 | } | 
|---|
|  | 65 |  | 
|---|
|  | 66 | void SLinParBuff::GetX0Y0(r_8& x0,r_8& y0) | 
|---|
|  | 67 | { | 
|---|
|  | 68 | x0 = mX0; | 
|---|
|  | 69 | y0 = mY0; | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
|  | 72 | bool SLinParBuff::GetAutoX0Y0() | 
|---|
|  | 73 | { | 
|---|
|  | 74 | return mAutoXY0; | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
|  | 77 | // ---- Stabilite numerique, centrage des x,y en mX0,mY0 | 
|---|
|  | 78 | void SLinParBuff::SetX0Y0(r_8 x0,r_8 y0) | 
|---|
|  | 79 | { | 
|---|
|  | 80 | mX0 = x0; mY0 = y0; mAutoXY0 = false; | 
|---|
|  | 81 | ReComputeSum(); | 
|---|
|  | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // ---- Stabilite numerique, centrage automatique a <x> et <y> | 
|---|
|  | 85 | //      a chaque ReComputeSum | 
|---|
|  | 86 | void SLinParBuff::SetAutoX0Y0(bool autoxy0) | 
|---|
|  | 87 | { | 
|---|
|  | 88 | mAutoXY0 = autoxy0; | 
|---|
|  | 89 | ReComputeSum(); | 
|---|
|  | 90 | } | 
|---|
|  | 91 |  | 
|---|
|  | 92 | // ---- Reset des sommes et des compteurs | 
|---|
|  | 93 | void SLinParBuff::Reset(void) | 
|---|
|  | 94 | { | 
|---|
|  | 95 | mSx=mSy=mSx2=mSy2=mSxy=mSx3=mSx2y=mSx4=0.; | 
|---|
|  | 96 | mNCur = mIDeb = mIResynch = mNResynchEff = mNPush = mNPop = 0; | 
|---|
|  | 97 | //if(mX) for(uint_4 i=0;i<mLenBuf;i++) mX[i] = 0.; | 
|---|
|  | 98 | //if(mY) for(uint_4 i=0;i<mLenBuf;i++) mY[i] = 0.; | 
|---|
|  | 99 | } | 
|---|
|  | 100 |  | 
|---|
|  | 101 | // ---- Pour enlever la donnee la plus ancienne | 
|---|
|  | 102 | uint_4 SLinParBuff::Pop(void) | 
|---|
|  | 103 | { | 
|---|
|  | 104 | if(mNCur==0) return mNCur; | 
|---|
|  | 105 | r_8 x=mX[mIDeb]-mX0, y=mY[mIDeb]-mY0; r_8 x2 = x*x; | 
|---|
|  | 106 | mSx  -= x;     mSy   -= y; | 
|---|
|  | 107 | mSx2 -= x2;    mSy2  -= y*y;   mSxy -= x*y; | 
|---|
|  | 108 | mSx3 -= x2*x;  mSx2y -= x2*y; | 
|---|
|  | 109 | mSx4 -= x2*x2; | 
|---|
|  | 110 | mNCur--; mNPop++; | 
|---|
|  | 111 | if(mNCur==0) {Reset(); return mNCur;} | 
|---|
|  | 112 | mIDeb++; if(mIDeb==mLenBuf) mIDeb=0; | 
|---|
|  | 113 | return mNCur; | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | // ---- Pour ajouter une donnee, la donnee la plus ancienne | 
|---|
|  | 117 | //      est enlevee si le buffer est deja plein. | 
|---|
|  | 118 | uint_4 SLinParBuff::Push(r_8 x,r_8 y) | 
|---|
|  | 119 | { | 
|---|
|  | 120 | uint_4 ifill; | 
|---|
|  | 121 | if(mNCur==mLenBuf) { | 
|---|
|  | 122 | r_8 X=mX[mIDeb]-mX0, Y=mY[mIDeb]-mY0; r_8 X2 = X*X; | 
|---|
|  | 123 | mSx  -= X;     mSy   -=Y; | 
|---|
|  | 124 | mSx2 -= X2;    mSy2  -=Y*Y;   mSxy -= X*Y; | 
|---|
|  | 125 | mSx3 -= X2*X;  mSx2y -=X*X*Y; | 
|---|
|  | 126 | mSx4 -= X2*X2; | 
|---|
|  | 127 | ifill = mIDeb; | 
|---|
|  | 128 | mIDeb++; if(mIDeb==mLenBuf) mIDeb=0; | 
|---|
|  | 129 | } else { | 
|---|
|  | 130 | ifill = (mIDeb+mNCur)%mLenBuf; | 
|---|
|  | 131 | mNCur++; | 
|---|
|  | 132 | } | 
|---|
|  | 133 | mX[ifill] = x; mY[ifill] = y; | 
|---|
|  | 134 | x -= mX0; y -= mY0; r_8 x2 = x*x; | 
|---|
|  | 135 | mSx += x; mSy += y; | 
|---|
|  | 136 | mSx2 += x2; mSy2 += y*y; mSxy += x*y; | 
|---|
|  | 137 | mSx3 += x2*x; mSx2y += x2*y; | 
|---|
|  | 138 | mSx4 += x2*x2; | 
|---|
|  | 139 | mNPush++; | 
|---|
|  | 140 | // Il faut re-synchroniser pour eviter les derives numeriques | 
|---|
|  | 141 | mIResynch++; if(mIResynch == mNResynch) ReComputeSum(); | 
|---|
|  | 142 | return mNCur; | 
|---|
|  | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 | // ---- Pour re-synchroniser (eviter les derives numeriques). | 
|---|
|  | 146 | uint_4 SLinParBuff::ReComputeSum(void) | 
|---|
|  | 147 | { | 
|---|
|  | 148 | if(mNCur==0) return 0; | 
|---|
|  | 149 | // Re-centrage automatique a la moyenne demande: | 
|---|
|  | 150 | // Attention, mSx = sum(x-mX0) ==> nouvel mX0 = mSx/N + mX0(ancien) | 
|---|
|  | 151 | if(mAutoXY0) {mX0 = mSx/(r_8)mNCur + mX0; mY0 = mSy/(r_8)mNCur + mY0;} | 
|---|
|  | 152 | mSx=mSy=mSx2=mSy2=mSxy=mSx3=mSx2y=mSx4=0.; | 
|---|
|  | 153 | for(uint_4 i=mIDeb;i<mIDeb+mNCur;i++) { | 
|---|
|  | 154 | uint_4 ii = i%mLenBuf; | 
|---|
|  | 155 | r_8 x=mX[ii]-mX0, y=mY[ii]-mY0; r_8 x2 = x*x; | 
|---|
|  | 156 | mSx  += x;     mSy   += y; | 
|---|
|  | 157 | mSx2 += x2;    mSy2  += y*y;   mSxy += x*y; | 
|---|
|  | 158 | mSx3 += x2*x;  mSx2y += x2*y; | 
|---|
|  | 159 | mSx4 += x2*x2; | 
|---|
|  | 160 | } | 
|---|
|  | 161 | mIResynch=0; | 
|---|
|  | 162 | mNResynchEff++; | 
|---|
|  | 163 | return mNCur; | 
|---|
|  | 164 | } | 
|---|
|  | 165 |  | 
|---|
|  | 166 | // ---- Calcul <y>, Var(y) | 
|---|
|  | 167 | //   recomputeXi2=true : recalcule le xi2 (sigma) avec la courbe et les points | 
|---|
|  | 168 | r_8 SLinParBuff::Compute(r_8& mean,bool recomputeXi2) | 
|---|
|  | 169 | { | 
|---|
|  | 170 | mean=0.; | 
|---|
|  | 171 | if(mNCur==0) return -1.; | 
|---|
|  | 172 | // Moyenne | 
|---|
|  | 173 | mean  = mSy/(r_8) mNCur; | 
|---|
|  | 174 | // Sigma | 
|---|
|  | 175 | r_8 sigma; | 
|---|
|  | 176 | if(recomputeXi2) { | 
|---|
|  | 177 | sigma=0.; | 
|---|
|  | 178 | for(uint_4 i=mIDeb;i<mIDeb+mNCur;i++) { | 
|---|
|  | 179 | uint_4 ii = i%mLenBuf; | 
|---|
|  | 180 | r_8 s = mean - (mY[ii]-mY0); | 
|---|
|  | 181 | sigma += s*s; | 
|---|
|  | 182 | } | 
|---|
|  | 183 | sigma /= (r_8) mNCur; | 
|---|
|  | 184 | } else { | 
|---|
|  | 185 | sigma = mSy2/(r_8) mNCur - mean*mean; | 
|---|
|  | 186 | } | 
|---|
|  | 187 | // gestion du decalage | 
|---|
|  | 188 | mean += mY0; | 
|---|
|  | 189 |  | 
|---|
|  | 190 | if(sigma>0.) return sqrt(sigma); | 
|---|
|  | 191 | if(sigma<0.) return -sqrt(-sigma); | 
|---|
|  | 192 | return sigma; | 
|---|
|  | 193 | } | 
|---|
|  | 194 |  | 
|---|
|  | 195 | // ---- Calcul y=a0+a1*x et slin=Var(y-(a0+a1*x))=sqrt(<dy^2>) | 
|---|
|  | 196 | //   recomputeXi2=true : recalcule le xi2 avec la courbe et les points | 
|---|
|  | 197 | r_8 SLinParBuff::Compute(r_8& a0,r_8 &a1,bool recomputeXi2) | 
|---|
|  | 198 | { | 
|---|
|  | 199 | a0=a1=0.; | 
|---|
|  | 200 | if(mNCur==0) return -1.; | 
|---|
|  | 201 | // Fit lineaire | 
|---|
|  | 202 | r_8 w = mNCur*mSx2 - mSx*mSx; | 
|---|
|  | 203 | if(w==0. || mNCur==1) return -2.; | 
|---|
|  | 204 | a0 = (mSx2*mSy - mSx*mSxy)/w; | 
|---|
|  | 205 | a1 = (mNCur*mSxy - mSx*mSy )/w; | 
|---|
|  | 206 | // Sigma par rapport Fit lineaire | 
|---|
|  | 207 | // (On a XI2=mNCur*slin**2 dans notre cas ou les erreurs=1) | 
|---|
|  | 208 | r_8 slin; | 
|---|
|  | 209 | if(recomputeXi2) { | 
|---|
|  | 210 | slin=0.; | 
|---|
|  | 211 | for(uint_4 i=mIDeb;i<mIDeb+mNCur;i++) { | 
|---|
|  | 212 | uint_4 ii = i%mLenBuf; | 
|---|
|  | 213 | r_8 s = a0+a1*(mX[ii]-mX0) - (mY[ii]-mY0); | 
|---|
|  | 214 | slin += s*s; | 
|---|
|  | 215 | } | 
|---|
|  | 216 | slin /= (r_8) mNCur; | 
|---|
|  | 217 | } else { | 
|---|
|  | 218 | slin = (mSy2 +a0*a0*mNCur +a1*a1*mSx2 -2.*a0*mSy -2.*a1*mSxy +2.*a0*a1*mSx) | 
|---|
|  | 219 | / (r_8)mNCur; | 
|---|
|  | 220 | } | 
|---|
|  | 221 | // gestion du decalage y-y0 = a0 + a1*(x-x0) | 
|---|
|  | 222 | a0 = mY0 + a0 - a1*mX0; | 
|---|
|  | 223 |  | 
|---|
|  | 224 | if(slin>0.) return sqrt(slin); | 
|---|
|  | 225 | if(slin<0.) return -sqrt(-slin); | 
|---|
|  | 226 | return slin; | 
|---|
|  | 227 | } | 
|---|
|  | 228 |  | 
|---|
|  | 229 | // ---- Calcul y=a0+a1*x+a2*x^2 et spar=Var(y-(a0+a1*x+a2*x^2))=sqrt(<dy^2>) | 
|---|
|  | 230 | //   recomputeXi2=true : recalcule le xi2 avec la courbe et les points | 
|---|
|  | 231 | r_8 SLinParBuff::Compute(r_8& a0,r_8 &a1,r_8 &a2,bool recomputeXi2) | 
|---|
|  | 232 | { | 
|---|
|  | 233 | a0=a1=a2=0.; | 
|---|
|  | 234 | if(mNCur==0) return -1.; | 
|---|
|  | 235 | // Fit parabolique | 
|---|
|  | 236 | r_8 w = mSx2*(mSx2*mSx2-mSx3*mSx) -mSx*(mSx3*mSx2-mSx4*mSx) +mNCur*(mSx3*mSx3-mSx4*mSx2); | 
|---|
|  | 237 | if(w==0. || mNCur<=2) return -2.; | 
|---|
|  | 238 | a2 =  (mSy*(mSx2*mSx2-mSx3*mSx)  - mSxy*(mSx*mSx2-mSx3*mNCur)  + mSx2y*(mSx*mSx-mSx2*mNCur) )/w; | 
|---|
|  | 239 | a1 = -(mSy*(mSx3*mSx2-mSx4*mSx)  - mSxy*(mSx2*mSx2-mSx4*mNCur) + mSx2y*(mSx2*mSx-mSx3*mNCur))/w; | 
|---|
|  | 240 | a0 =  (mSy*(mSx3*mSx3-mSx4*mSx2) - mSxy*(mSx2*mSx3-mSx4*mSx)   + mSx2y*(mSx2*mSx2-mSx3*mSx) )/w; | 
|---|
|  | 241 | // Sigma par rapport Fit parabolique | 
|---|
|  | 242 | // (On a XI2=mNCur*spar**2 dans notre cas ou les erreurs=1) | 
|---|
|  | 243 | // Le calcul direct du Xi2 n'est pas precis | 
|---|
|  | 244 | r_8 spar; | 
|---|
|  | 245 | if(recomputeXi2) { | 
|---|
|  | 246 | spar=0.; | 
|---|
|  | 247 | for(uint_4 i=mIDeb;i<mIDeb+mNCur;i++) { | 
|---|
|  | 248 | uint_4 ii = i%mLenBuf; | 
|---|
|  | 249 | r_8 s = a0+(a1+a2*(mX[ii]-mX0))*(mX[ii]-mX0) - (mY[ii]-mY0); | 
|---|
|  | 250 | spar += s*s; | 
|---|
|  | 251 | } | 
|---|
|  | 252 | spar /= (r_8) mNCur; | 
|---|
|  | 253 | } else { | 
|---|
|  | 254 | spar = (mSy2 +a0*a0*mNCur +a1*a1*mSx2 +a2*a2*mSx4 -2.*mSy*a0 -2.*a1*mSxy | 
|---|
|  | 255 | -2.*a2*mSx2y +2.*a0*a1*mSx +2.*a0*a2*mSx2 +2.*a1*a2*mSx3) | 
|---|
|  | 256 | / (r_8) mNCur; | 
|---|
|  | 257 | } | 
|---|
|  | 258 | // gestion du decalage y-y0 = a0 + a1*(x-x0) + a2*(x-x0)^2 | 
|---|
|  | 259 | a0 = mY0 + a0 - a1*mX0 + a2*mX0*mX0; | 
|---|
|  | 260 | a1 = a1 - 2.*a2*mX0; | 
|---|
|  | 261 |  | 
|---|
|  | 262 | if(spar>0.) return sqrt(spar); | 
|---|
|  | 263 | if(spar<0.) return -sqrt(-spar); | 
|---|
|  | 264 | return spar; | 
|---|
|  | 265 | } | 
|---|
|  | 266 |  | 
|---|
|  | 267 | // ---- Print de l'etat de la classe | 
|---|
|  | 268 | //      lp = 0 : parametres | 
|---|
|  | 269 | //           1 :            + sommes | 
|---|
|  | 270 | //           2 :                     + tableaux | 
|---|
|  | 271 | void SLinParBuff::Print(int lp) | 
|---|
|  | 272 | { | 
|---|
|  | 273 | cout<<"SLinParBuff(LenBuf="<<mLenBuf<<",NResynch="<<mNResynch | 
|---|
|  | 274 | <<",auto_xy0="<<mAutoXY0 | 
|---|
|  | 275 | <<"): mX0="<<mX0<<" mY0="<<mY0<<" mNCur="<<mNCur<<endl | 
|---|
|  | 276 | <<"           NPush="<<mNPush<<" NPop="<<mNPop | 
|---|
|  | 277 | <<" NSynchro="<<mNResynchEff<<endl; | 
|---|
|  | 278 | if(mNCur==0) return; | 
|---|
|  | 279 | if(lp>=2) { | 
|---|
|  | 280 | cout<<"X:"; | 
|---|
|  | 281 | if(mX) for(uint_4 i=0;i<mNCur;i++) { | 
|---|
|  | 282 | uint_4 ii = (mIDeb+i)%mLenBuf; | 
|---|
|  | 283 | cout<<" "<<mX[ii]; if(i%10==9 || i==mNCur-1) cout<<endl; | 
|---|
|  | 284 | } | 
|---|
|  | 285 | if(mY) cout<<"Y:"; | 
|---|
|  | 286 | for(uint_4 i=0;i<mNCur;i++) { | 
|---|
|  | 287 | uint_4 ii = (mIDeb+i)%mLenBuf; | 
|---|
|  | 288 | cout<<" "<<mY[ii]; if(i%10==9 || i==mNCur-1) cout<<endl; | 
|---|
|  | 289 | } | 
|---|
|  | 290 | } | 
|---|
|  | 291 | if(lp>=1) { | 
|---|
|  | 292 | cout<<"...IDeb="<<mIDeb<<" IResynch="<<mIResynch<<endl; | 
|---|
|  | 293 | cout<<"   Sx="<<mSx<<" Sx2="<<mSx2<<" Sx3="<<mSx3<<" Sx4="<<mSx4<<endl | 
|---|
|  | 294 | <<"   Sy="<<mSy<<" Sy2="<<mSy2<<" Sxy="<<mSxy<<" Sx2y="<<mSx2y<<endl; | 
|---|
|  | 295 | } | 
|---|
|  | 296 | } | 
|---|
|  | 297 |  | 
|---|
|  | 298 | // ---- Print des valeurs numeriques calculees | 
|---|
|  | 299 | //      lp = 0 : valeurs calculees | 
|---|
|  | 300 | //           1 :             + sommes | 
|---|
|  | 301 | void SLinParBuff::PrintCompute(int lp) | 
|---|
|  | 302 | { | 
|---|
|  | 303 | bool recompute = (mX==NULL || mY==NULL) ? false: true; | 
|---|
|  | 304 | r_8 mean; | 
|---|
|  | 305 | r_8 sigma = Compute(mean,recompute), sigmar = Compute(mean,false); | 
|---|
|  | 306 | cout<<"SLinParBuff: n="<<NPoints()<<" mean="<<mean | 
|---|
|  | 307 | <<" sigma="<<sigma<<" (raw="<<sigmar<<")"<<endl; | 
|---|
|  | 308 | r_8 a0,a1,a2; | 
|---|
|  | 309 | r_8 slin  = Compute(a0,a1,recompute), slinr  = Compute(a0,a1,false); | 
|---|
|  | 310 | cout<<"             a0="<<a0<<" a1="<<a1 | 
|---|
|  | 311 | <<" slin="<<slin<<" (raw="<<slinr<<")"<<endl; | 
|---|
|  | 312 | r_8 spar = Compute(a0,a1,a2,recompute), sparr = Compute(a0,a1,a2,false); | 
|---|
|  | 313 | cout<<"             a0="<<a0<<" a1="<<a1<<" a2="<<a2 | 
|---|
|  | 314 | <<" spar="<<spar<<" (raw="<<sparr<<")"<<endl; | 
|---|
|  | 315 | if(lp<1) return; | 
|---|
|  | 316 | cout<<"...Sx="<<mSx<<" Sx2="<<mSx2<<" Sx3="<<mSx3<<" Sx4="<<mSx4<<endl | 
|---|
|  | 317 | <<"   Sy="<<mSy<<" Sy2="<<mSy2<<" Sxy="<<mSxy<<" Sx2y="<<mSx2y<<endl; | 
|---|
|  | 318 | } | 
|---|
|  | 319 |  | 
|---|
|  | 320 |  | 
|---|
|  | 321 |  | 
|---|
|  | 322 |  | 
|---|
|  | 323 | //================================================================ | 
|---|
|  | 324 | // SLinParBuffMerger | 
|---|
|  | 325 | //================================================================ | 
|---|
|  | 326 |  | 
|---|
|  | 327 | /////////////////////////////////////////////////////////////////// | 
|---|
|  | 328 | // That Class allows merging of SLinParBuff Class for computing  // | 
|---|
|  | 329 | // parameters. | 
|---|
|  | 330 | // ex: | 
|---|
|  | 331 | // SLinParBuff s1;  -> Fill s1 | 
|---|
|  | 332 | // SLinParBuff s2;  -> Fill s2 | 
|---|
|  | 333 | // SLinParBuff s3;  -> Fill s3 | 
|---|
|  | 334 | // SLinParBuffMerger smerge(s1); | 
|---|
|  | 335 | //   sig = smerge.Compute(mean); -> same as sig = s1.Compute(mean); | 
|---|
|  | 336 | // smerge.Add(s2); | 
|---|
|  | 337 | //   sig = smerge.Compute(mean); -> sig and mean are those for | 
|---|
|  | 338 |  | 
|---|
|  | 339 |  | 
|---|
|  | 340 | SLinParBuffMerger::SLinParBuffMerger(void) | 
|---|
|  | 341 | { | 
|---|
|  | 342 | mFirst=true; | 
|---|
|  | 343 | mSlp.Reset(); | 
|---|
|  | 344 | } | 
|---|
|  | 345 |  | 
|---|
|  | 346 | SLinParBuffMerger::SLinParBuffMerger(SLinParBuff& s,bool recompute) | 
|---|
|  | 347 | { | 
|---|
|  | 348 | mFirst=true; | 
|---|
|  | 349 | mSlp.Reset(); | 
|---|
|  | 350 | Add(s,recompute); | 
|---|
|  | 351 | } | 
|---|
|  | 352 |  | 
|---|
|  | 353 | SLinParBuffMerger::~SLinParBuffMerger(void) | 
|---|
|  | 354 | { | 
|---|
|  | 355 | } | 
|---|
|  | 356 |  | 
|---|
|  | 357 | void SLinParBuffMerger::Add(SLinParBuff& s,bool recompute) | 
|---|
|  | 358 | { | 
|---|
|  | 359 | bool changex0y0=false, AutoXY0_Save; r_8 X0_Save,Y0_Save; | 
|---|
|  | 360 | if(mFirst) { | 
|---|
|  | 361 | // Cas ou c'est le premier SLinParBuff additionne. | 
|---|
|  | 362 | mSlp.mX0=s.mX0; mSlp.mY0=s.mY0; mFirst=false; | 
|---|
|  | 363 | } else if(mSlp.mX0!=s.mX0 || mSlp.mY0!=s.mY0) { | 
|---|
|  | 364 | // Attention: pour merger il faut avoir les memes mX0,mY0 | 
|---|
|  | 365 | changex0y0=true; | 
|---|
|  | 366 | X0_Save=s.mX0; Y0_Save=s.mY0; AutoXY0_Save=s.mAutoXY0; | 
|---|
|  | 367 | s.mX0=mSlp.mX0; s.mY0=mSlp.mY0; s.mAutoXY0=false; | 
|---|
|  | 368 | recompute=true; | 
|---|
|  | 369 | } | 
|---|
|  | 370 | if(recompute) s.ReComputeSum(); | 
|---|
|  | 371 | mSlp.mNCur += s.mNCur; | 
|---|
|  | 372 | mSlp.mSx   += s.mSx; | 
|---|
|  | 373 | mSlp.mSy   += s.mSy; | 
|---|
|  | 374 | mSlp.mSx2  += s.mSx2; | 
|---|
|  | 375 | mSlp.mSy2  += s.mSy2; | 
|---|
|  | 376 | mSlp.mSxy  += s.mSxy; | 
|---|
|  | 377 | mSlp.mSx3  += s.mSx3; | 
|---|
|  | 378 | mSlp.mSx2y += s.mSx2y; | 
|---|
|  | 379 | mSlp.mSx4  += s.mSx4; | 
|---|
|  | 380 | // Dans le cas ou on a change les X0,Y0, on remet en etat | 
|---|
|  | 381 | if(changex0y0) { | 
|---|
|  | 382 | s.mX0=X0_Save; s.mY0=Y0_Save; | 
|---|
|  | 383 | s.ReComputeSum(); | 
|---|
|  | 384 | s.mAutoXY0=AutoXY0_Save; | 
|---|
|  | 385 | } | 
|---|
|  | 386 | } | 
|---|
|  | 387 |  | 
|---|
|  | 388 |  | 
|---|
|  | 389 | } // Fin du namespace | 
|---|
|  | 390 |  | 
|---|