391 std::vector<unsigned int> indstart_low(width);
392 std::vector<unsigned int> indstart_up(width);
393 unsigned int j_low = 0, j_up = 0, jseg = 0, indjseg = 0, i = 1, indjseg2, ind;
394 double output_low_first = input[0] -
lambda;
395 double output_low_curr = output_low_first;
396 double output_up_first = input[0] +
lambda;
397 double output_up_curr = output_up_first;
398 const double twolambda = 2.0 *
lambda;
400 output[0] = input[0];
406 for (; i < width; i++) {
407 if (input[i] >= output_low_curr) {
408 if (input[i] <= output_up_curr) {
409 output_up_curr += (input[i] - output_up_curr) / (i - indstart_up[j_up] + 1);
410 output[indjseg] = output_up_first;
411 while ((j_up > jseg) && (output_up_curr <= output[ind = indstart_up[j_up - 1]]))
412 output_up_curr += (output[ind] - output_up_curr) *
413 ((
double)(indstart_up[j_up--] - ind) / (i - ind + 1));
415 while ((output_up_curr <= output_low_first) && (jseg < j_low)) {
416 indjseg2 = indstart_low[++jseg];
417 output_up_curr += (output_up_curr - output_low_first) *
418 ((
double)(indjseg2 - indjseg) / (i - indjseg2 + 1));
419 while (indjseg < indjseg2) output[indjseg++] = output_low_first;
420 output_low_first = output[indjseg];
422 output_up_first = output_up_curr;
423 indstart_up[j_up = jseg] = indjseg;
425 else output[indstart_up[j_up]] = output_up_curr;
428 output_up_curr = output[i] = input[indstart_up[++j_up] = i];
429 output_low_curr += (input[i] - output_low_curr) / (i - indstart_low[j_low] + 1);
430 output[indjseg] = output_low_first;
431 while ((j_low > jseg) && (output_low_curr >= output[ind = indstart_low[j_low - 1]]))
432 output_low_curr += (output[ind] - output_low_curr) *
433 ((
double)(indstart_low[j_low--] - ind) / (i - ind + 1));
435 while ((output_low_curr >= output_up_first) && (jseg < j_up)) {
436 indjseg2 = indstart_up[++jseg];
437 output_low_curr += (output_low_curr - output_up_first) *
438 ((
double)(indjseg2 - indjseg) / (i - indjseg2 + 1));
439 while (indjseg < indjseg2) output[indjseg++] = output_up_first;
440 output_up_first = output[indjseg];
442 if ((indstart_low[j_low = jseg] = indjseg) == i) output_low_first = output_up_first - twolambda;
443 else output_low_first = output_low_curr;
445 else output[indstart_low[j_low]] = output_low_curr;
448 output_up_curr += ((output_low_curr = output[i] = input[indstart_low[++j_low] = i]) -
449 output_up_curr) / (i - indstart_up[j_up] + 1);
450 output[indjseg] = output_up_first;
451 while ((j_up > jseg) && (output_up_curr <= output[ind = indstart_up[j_up - 1]]))
452 output_up_curr += (output[ind] - output_up_curr) *
453 ((
double)(indstart_up[j_up--] - ind) / (i - ind + 1));
455 while ((output_up_curr <= output_low_first) && (jseg < j_low)) {
456 indjseg2 = indstart_low[++jseg];
457 output_up_curr += (output_up_curr - output_low_first) *
458 ((
double)(indjseg2 - indjseg) / (i - indjseg2 + 1));
459 while (indjseg < indjseg2) output[indjseg++] = output_low_first;
460 output_low_first = output[indjseg];
462 if ((indstart_up[j_up = jseg] = indjseg) == i) output_up_first = output_low_first + twolambda;
463 else output_up_first = output_up_curr;
465 else output[indstart_up[j_up]] = output_up_curr;
469 if (input[i] + lambda <= output_low_curr) {
470 while (jseg < j_low) {
471 indjseg2 = indstart_low[++jseg];
472 while (indjseg < indjseg2) output[indjseg++] = output_low_first;
473 output_low_first = output[indjseg];
475 while (indjseg < i) output[indjseg++] = output_low_first;
476 output[indjseg] = input[i] +
lambda;
478 else if (input[i] - lambda >= output_up_curr) {
479 while (jseg < j_up) {
480 indjseg2 = indstart_up[++jseg];
481 while (indjseg < indjseg2) output[indjseg++] = output_up_first;
482 output_up_first = output[indjseg];
484 while (indjseg < i) output[indjseg++] = output_up_first;
485 output[indjseg] = input[i] -
lambda;
488 output_low_curr += (input[i] + lambda - output_low_curr) / (i - indstart_low[j_low] + 1);
489 output[indjseg] = output_low_first;
490 while ((j_low > jseg) && (output_low_curr >= output[ind = indstart_low[j_low - 1]]))
491 output_low_curr += (output[ind] - output_low_curr) *
492 ((
double)(indstart_low[j_low--] - ind) / (i - ind + 1));
494 if (output_up_first >= output_low_curr)
495 while (indjseg <= i) output[indjseg++] = output_low_curr;
497 output_up_curr += (input[i] - lambda - output_up_curr) / (i - indstart_up[j_up] + 1);
498 output[indjseg] = output_up_first;
499 while ((j_up > jseg) && (output_up_curr <= output[ind = indstart_up[j_up - 1]]))
500 output_up_curr += (output[ind] - output_up_curr) *
501 ((
double)(indstart_up[j_up--] - ind) / (i - ind + 1));
502 while (jseg < j_up) {
503 indjseg2 = indstart_up[++jseg];
504 while (indjseg < indjseg2) output[indjseg++] = output_up_first;
505 output_up_first = output[indjseg];
507 indjseg = indstart_up[j_up];
508 while (indjseg <= i) output[indjseg++] = output_up_curr;
512 while (jseg < j_low) {
513 indjseg2 = indstart_low[++jseg];
514 while (indjseg < indjseg2) output[indjseg++] = output_low_first;
515 output_low_first = output[indjseg];
517 indjseg = indstart_low[j_low];
518 while (indjseg <= i) output[indjseg++] = output_low_curr;
double lambda(double a, double b, double c)