14 #ifndef SI_PIXEL_TEMPLATE_STANDALONE
24 #include<boost/bind.hpp>
27 namespace VVIObjDetails {
28 void sincosint(
double x,
double & sint,
double & cint);
33 inline double f1(
double x,
double const * h_) {
return h_[0]+h_[1]*
std::log(h_[2]*x)-h_[3]*
x;}
36 int dzero(
double a,
double b,
double& x0,
37 double& rv,
double eps,
int mxf,
F func);
52 const double xp[9] = { 9.29,2.47,.89,.36,.15,.07,.03,.02,0.0 };
53 const double xq[7] = { .012,.03,.08,.26,.87,3.83,11.0 };
55 double q, u,
x,
c1, c2, c3, c4, d1, h4, h5, h6,
q2, x1, d, ll, ul, xf1, xf2, rv;
60 if(kappa < 0.01) kappa = 0.01;
61 if(kappa > 10.) kappa = 10.;
62 if(beta2 < 0.) beta2 = 0.;
63 if(beta2 > 1.) beta2 = 1.;
65 h_[4] = 1. - beta2*0.42278433999999998 + 7.6/kappa;
68 h4 = -7.6/kappa - (beta2 * .57721566 + 1);
75 for (lp = 0; lp < 9; ++lp) {
76 if (kappa >= xp[lp])
break;
79 for (lq = 0; lq < 7; ++lq) {
80 if (kappa <= xq[lq])
break;
88 omega_ = 6.2831853000000004/t_;
89 h_[0] = kappa * (beta2 * .57721566 + 2.) + 9.9166128600000008;
90 if (kappa >= .07) {h_[0] += 6.90775527;}
91 h_[1] = beta2 * kappa;
93 h_[3] = omega_ * 1.5707963250000001;
97 d =
exp(kappa * (beta2 * (.57721566 - h5) + 1.)) * .31830988654751274;
100 a_[n - 1] = omega_ * .31830988654751274;
104 for (k = 1; k <
n; ++
k) {
112 xf1 = kappa * (beta2 * c1 - c4) - x * c2;
113 xf2 = x * c1 + kappa * (c3 + beta2 * c2) + t0_ * x;
115 d1 = q * d * omega_ *
exp(xf1);
116 a_[l - 1] = d1 *
cos(xf2);
117 b_[l - 1] = -d1 *
sin(xf2);
119 d1 = q * d *
exp(xf1)/
k;
120 a_[l - 1] = d1 *
sin(xf2);
121 b_[l - 1] = d1 *
cos(xf2);
122 a_[n - 1] += q2 * a_[l - 1];
141 double f, u,
y, a0, a1;
143 double b1, b0, b2, cof;
149 }
else if (x <=
t1_) {
151 u = omega_ * y - 3.141592653589793;
156 for (k = 2; k <= n1; ++
k) {
159 a0 =
a_[k - 1] + cof * a1 - a2;
163 for (k = 2; k <=
n; ++
k) {
166 b0 =
b_[k - 1] + cof * b1 - b2;
168 f = (a0 - a2) * .5 + b0 *
sin(u);
172 if (
mode_ != 0) {f = 1.;}
194 namespace VVIObjDetails {
198 const double zero = 0.;
199 const double one = 1.;
200 const double two = 2.;
201 const double eight = 8.;
202 const double ce = .57721566490153;
203 const double c__[14] = { 1.9405491464836,.9413409132865,
204 -.579845034293,.3091572011159,-.0916101792208,.0164437407515,
205 -.0019713091952,1.692538851e-4,-1.09393296e-5,5.522386e-7,
206 -2.23995e-8,7.465e-10,-2.08e-11,5
e-13 };
207 const double p[23] = { .96074783975204,-.0371138962124,
208 .00194143988899,-1.7165988425e-4,2.112637753e-5,-3.27163257e-6,
209 6.0069212e-7,-1.2586794e-7,2.932563e-8,-7.45696e-9,2.04105e-9,
210 -5.9502e-10,1.8323e-10,-5.921e-11,1.997e-11,-7
e-12,2.54e-12,
211 -9.5e-13,3.7e-13,-1.4e-13,6
e-14,-2
e-14,1e-14 };
212 const double q[20] = { .98604065696238,-.0134717382083,
213 4.5329284117e-4,-3.067288652e-5,3.13199198e-6,-4.2110196e-7,
214 6.907245e-8,-1.318321e-8,2.83697e-9,-6.7329e-10,1.734e-10,
215 -4.787e-11,1.403e-11,-4.33e-12,1.4e-12,-4.7e-13,1.7e-13,-6
e-14,
224 double r__,
y, b0, b1, b2,
pp, qq, alfa;
231 if (fabs(x) <= eight) {
235 h__ = two * (d__1 * d__1) - one;
239 for (i__ = 13; i__ >= 0; --i__) {
240 b0 = c__[i__] - alfa * b1 - b2;
244 b1 = ce +
log((fabs(x))) - b0 + h__ * b2;
250 h__ = two * (d__1 * d__1) - one;
254 for (i__ = 22; i__ >= 0; --i__) {
255 b0 = p[i__] - alfa * b1 - b2;
262 for (i__ = 19; i__ >= 0; --i__) {
263 b0 = q[i__] - alfa * b1 - b2;
268 b1 = r__ * (qq *
sin(x) - r__ * pp *
cos(x));
276 const double zero = 0.;
277 const double one = 1.;
278 const double two = 2.;
279 const double eight = 8.;
280 const double pih = 1.5707963267949;
281 const double s[14] = { 1.9522209759531,-.6884042321257,
282 .4551855132256,-.1804571236838,.0410422133759,-.0059586169556,
283 6.001427414e-4,-4.44708329e-5,2.5300782e-6,-1.141308e-7,4.1858e-9,
284 -1.273e-10,3.3e-12,-1
e-13 };
285 const double p[23] = { .96074783975204,-.0371138962124,
286 .00194143988899,-1.7165988425e-4,2.112637753e-5,-3.27163257e-6,
287 6.0069212e-7,-1.2586794e-7,2.932563e-8,-7.45696e-9,2.04105e-9,
288 -5.9502e-10,1.8323e-10,-5.921e-11,1.997e-11,-7
e-12,2.54e-12,
289 -9.5e-13,3.7e-13,-1.4e-13,6
e-14,-2
e-14,1e-14 };
290 const double q[20] = { .98604065696238,-.0134717382083,
291 4.5329284117e-4,-3.067288652e-5,3.13199198e-6,-4.2110196e-7,
292 6.907245e-8,-1.318321e-8,2.83697e-9,-6.7329e-10,1.734e-10,
293 -4.787e-11,1.403e-11,-4.33e-12,1.4e-12,-4.7e-13,1.7e-13,-6
e-14,
302 double r__,
y, b0, b1, b2,
pp, qq, alfa;
304 if (fabs(x) <= eight) {
307 h__ = two * (d__1 * d__1) - one;
311 for (i__ = 13; i__ >= 0; --i__) {
312 b0 = s[i__] - alfa * b1 - b2;
321 h__ = two * (d__1 * d__1) - one;
325 for (i__ = 22; i__ >= 0; --i__) {
326 b0 = p[i__] - alfa * b1 - b2;
333 for (i__ = 19; i__ >= 0; --i__) {
334 b0 = q[i__] - alfa * b1 - b2;
340 if(x < 0.) d__1 = -d__1;
341 b1 = d__1 - r__ * (r__ * pp *
sin(x) + qq *
cos(x));
347 void sincosint(
double x,
double & sint,
double & cint) {
350 const double zero = 0.;
351 const double one = 1.;
352 const double two = 2.;
353 const double eight = 8.;
354 const double ce = .57721566490153;
355 const double pih = 1.5707963267949;
356 const double s__[14] = { 1.9522209759531,-.6884042321257,
357 .4551855132256,-.1804571236838,.0410422133759,-.0059586169556,
358 6.001427414e-4,-4.44708329e-5,2.5300782e-6,-1.141308e-7,4.1858e-9,
359 -1.273e-10,3.3e-12,-1
e-13 };
361 const double c__[14] = { 1.9405491464836,.9413409132865,
362 -.579845034293,.3091572011159,-.0916101792208,.0164437407515,
363 -.0019713091952,1.692538851e-4,-1.09393296e-5,5.522386e-7,
364 -2.23995e-8,7.465e-10,-2.08e-11,5
e-13 };
366 const double p[23] = { .96074783975204,-.0371138962124,
367 .00194143988899,-1.7165988425e-4,2.112637753e-5,-3.27163257e-6,
368 6.0069212e-7,-1.2586794e-7,2.932563e-8,-7.45696e-9,2.04105e-9,
369 -5.9502e-10,1.8323e-10,-5.921e-11,1.997e-11,-7
e-12,2.54e-12,
370 -9.5e-13,3.7e-13,-1.4e-13,6
e-14,-2
e-14,1e-14 };
371 const double q[20] = { .98604065696238,-.0134717382083,
372 4.5329284117e-4,-3.067288652e-5,3.13199198e-6,-4.2110196e-7,
373 6.907245e-8,-1.318321e-8,2.83697e-9,-6.7329e-10,1.734e-10,
374 -4.787e-11,1.403e-11,-4.33e-12,1.4e-12,-4.7e-13,1.7e-13,-6
e-14,
383 double r__,
y, b0, b1, b2,
pp, qq, alfa;
389 if (fabs(x) <= eight) {
393 h__ = two * (d__1 * d__1) - one;
400 for (i__ = 13; i__ >= 0; --i__) {
401 b0 = c__[i__] - alfa * b1 - b2;
405 cint = ce +
log((fabs(x))) - b0 + h__ * b2;
410 for (i__ = 13; i__ >= 0; --i__) {
411 b0 = s__[i__] - alfa * b1 - b2;
415 sint = y * (b0 - b2);
422 h__ = two * (d__1 * d__1) - one;
426 for (i__ = 22; i__ >= 0; --i__) {
427 b0 = p[i__] - alfa * b1 - b2;
434 for (i__ = 19; i__ >= 0; --i__) {
435 b0 = q[i__] - alfa * b1 - b2;
441 cint = r__ * (qq *
sin(x) - r__ * pp *
cos(x));
444 if(x < 0.) d__1 = -d__1;
445 sint = d__1 - r__ * (r__ * pp *
sin(x) + qq *
cos(x));
454 const double zero = 0.;
455 const double q2[7] = { .10340013040487,3.319092135933,
456 20.449478501379,41.280784189142,32.426421069514,10.041164382905,
458 const double p3[6] = { -2.3909964453136,-147.98219500504,
459 -254.3763397689,-119.55761038372,-19.630408535939,-.9999999999036
461 const double q3[6] = { 177.60070940351,530.68509610812,
462 462.23027156148,156.81843364539,21.630408494238,1. };
463 const double p4[8] = { -8.6693733995107,-549.14226552109,
464 -4210.0161535707,-249301.39345865,-119623.66934925,
465 -22174462.775885,3892804.213112,-391546073.8091 };
466 const double q4[8] = { 34.171875,-1607.0892658722,35730.029805851,
467 -483547.43616216,4285596.2461175,-24903337.574054,89192576.757561,
469 const double a1[8] = { -2.1808638152072,-21.901023385488,
470 9.3081638566217,25.076281129356,-33.184253199722,60.121799083008,
471 -43.253113287813,1.0044310922808 };
472 const double b1[8] = { 0.,3.9370770185272,300.89264837292,
473 -6.2504116167188,1003.6743951673,14.325673812194,2736.2411988933,
475 const double a2[8] = { -3.4833465360285,-18.65454548834,
476 -8.2856199414064,-32.34673303054,17.960168876925,1.7565631546961,
477 -1.9502232128966,.99999429607471 };
478 const double b2[8] = { 0.,69.500065588743,57.283719383732,
479 25.777638423844,760.76114800773,28.951672792514,-3.4394226689987,
481 const double a3[6] = { -27.780928934438,-10.10479081576,
482 -9.1483008216736,-5.0223317461851,-3.0000077799358,
484 const double one = 1.;
485 const double b3[6] = { 0.,122.39993926823,2.7276100778779,
486 -7.1897518395045,-2.9990118065262,1.999999942826 };
487 const double two = 2.;
488 const double three = 3.;
489 const double x0 = .37250741078137;
490 const double xl[6] = { -24.,-12.,-6.,0.,1.,4. };
491 const double p1[5] = { 4.293125234321,39.894153870321,
492 292.52518866921,425.69682638592,-434.98143832952 };
493 const double q1[5] = { 1.,18.899288395003,150.95038744251,
494 568.05252718987,753.58564359843 };
495 const double p2[7] = { .43096783946939,6.9052252278444,
496 23.019255939133,24.378408879132,9.0416155694633,.99997957705159,
500 double v,
y, ap, bp, aq, dp, bq, dq;
504 for (
int i__ = 2; i__ <= 5; ++i__) {
506 ap = a3[i__ - 1] - x + b3[i__ - 1] / ap;
508 y =
exp(-x) / x * (one - (a3[5] + b3[5] / ap) / x);
509 }
else if (x <= xl[1]) {
511 for (
int i__ = 2; i__ <= 7; ++i__) {
512 ap = a2[i__ - 1] - x + b2[i__ - 1] / ap;
514 y =
exp(-x) / x * (a2[7] + b2[7] / ap);
515 }
else if (x <= xl[2]) {
517 for (
int i__ = 2; i__ <= 7; ++i__) {
518 ap = a1[i__ - 1] - x + b1[i__ - 1] / ap;
520 y =
exp(-x) / x * (a1[7] + b1[7] / ap);
521 }
else if (x < xl[3]) {
522 v = -two * (x / three + one);
525 for (
int i__ = 2; i__ <= 8; ++i__) {
528 dp = p4[i__ - 1] - ap + v * bp;
532 for (
int i__ = 2; i__ <= 8; ++i__) {
535 dq = q4[i__ - 1] - aq + v * bq;
537 y = -
log(-x / x0) + (x + x0) * (dp - ap) / (dq - aq);
538 }
else if (x == xl[3]) {
540 }
else if (x < xl[4]) {
543 for (
int i__ = 2; i__ <= 5; ++i__) {
544 ap = p1[i__ - 1] + x * ap;
545 aq = q1[i__ - 1] + x * aq;
547 y = -
log(x) + ap / aq;
548 }
else if (x <= xl[5]) {
552 for (
int i__ = 2; i__ <= 7; ++i__) {
553 ap = p2[i__ - 1] + y * ap;
554 aq = q2[i__ - 1] + y * aq;
556 y =
exp(-x) * ap / aq;
561 for (
int i__ = 2; i__ <= 6; ++i__) {
562 ap = p3[i__ - 1] + y * ap;
563 aq = q3[i__ - 1] + y * aq;
565 y =
exp(-x) * y * (one + y * ap / aq);
572 int dzero(
double a,
double b,
double& x0,
573 double& rv,
double eps,
int mxf,
F func) {
575 double d__1, d__2, d__3, d__4;
578 double f1,
f2,
f3, u1, u2, x1, x2, u3, u4, x3, ca, cb, cc,
fa,
fb, ee,
ff;
580 double xa, xb, fx, xx, su4;
595 ee = eps * (fabs(x0) + 1);
609 rv = (d__1 = xb - xa, fabs(d__1)) * -.5;
625 if (u2 == 0. || u4 == 0.) {
goto L1;}
631 cb = (x1 + x2) * u2 - (x2 + x0) * u1;
632 cc = (x1 - x0) * f1 - x1 * (ca * x1 + cb);
634 if (cb == 0.) {
goto L1;}
638 u4 = u3 * u3 - cc / ca;
639 if (u4 < 0.) {
goto L1;}
641 if (x0 + u3 < 0.f) {su4 = -su4;}
644 if (x0 < xa || x0 > xb) {
goto L1;}
646 d__3 = (d__1 = x0 - x3, fabs(d__1)), d__4 = (d__2 = x0 - x2, fabs(d__2));
648 ee = eps * (fabs(x0) + 1);
686 rv = (d__1 = xb - xa, fabs(d__1)) * -.5;
void limits(double &xl, double &xu) const
density (mode=0) or distribution (mode=1) function
Sin< T >::type sin(const T &t)
double sinint(double x)
Private version of the cosine integral.
int dzero(double a, double b, double &x0, double &rv, double eps, int mxf, F func)
double cosint(double x)
Private version of the cosine and sine integral.
const T & max(const T &a, const T &b)
Cos< T >::type cos(const T &t)
double f2(double x, double const *h_)
VVIObj(double kappa=0.01, double beta2=1., int mode=0)
Constructor.
double fcn(double x) const
void sincosint(double x, double &sint, double &cint)
double f1(double x, double const *h_)
Private version of the exponential integral.
const int mode_
returns the limits on the non-zero (mode=0) or normalized region (mode=1)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
double expint(double x)
Private version of the sine integral.