Tesseract  3.02
QLSQ Class Reference

#include <quadlsq.h>

List of all members.

Public Member Functions

 QLSQ ()
void clear ()
void add (double x, double y)
void remove (double x, double y)
inT32 count ()
void fit (int degree)
double get_a ()
double get_b ()
double get_c ()

Detailed Description

Definition at line 25 of file quadlsq.h.


Constructor & Destructor Documentation

QLSQ::QLSQ ( ) [inline]

Definition at line 28 of file quadlsq.h.

           {  //constructor
      clear();  //set to zeros
    }

Member Function Documentation

void QLSQ::add ( double  x,
double  y 
)

Definition at line 58 of file quadlsq.cpp.

                {
  n++;                           //count elements
  sigx += x;                     //update accumulators
  sigy += y;
  sigxx += x * x;
  sigxy += x * y;
  sigyy += y * y;
  sigxxx += (long double) x *x * x;
  sigxxy += (long double) x *x * y;
  sigxxxx += (long double) x *x * x * x;
}
void QLSQ::clear ( )

Definition at line 36 of file quadlsq.cpp.

                 {  //initialize
  a = 0;
  b = 0;
  c = 0;
  n = 0;                         //no elements
  sigx = 0;                      //update accumulators
  sigy = 0;
  sigxx = 0;
  sigxy = 0;
  sigyy = 0;
  sigxxx = 0;
  sigxxy = 0;
  sigxxxx = 0;
}
inT32 QLSQ::count ( ) [inline]

Definition at line 39 of file quadlsq.h.

                  {  //no of elements
      return n;
    }
void QLSQ::fit ( int  degree)

Definition at line 105 of file quadlsq.cpp.

                {
  long double cubetemp;          //intermediates
  long double squaretemp;
  long double top96, bottom96;   /*accurate top & bottom */

  if (n >= 4 && degree >= 2) {
    cubetemp = sigxxx * n - (long double) sigxx *sigx;

    top96 =
      cubetemp * ((long double) sigxy * n - (long double) sigx * sigy);

    squaretemp = (long double) sigxx *n - (long double) sigx *sigx;

    top96 += squaretemp * ((long double) sigxx * sigy - sigxxy * n);

    bottom96 = cubetemp * cubetemp;

    bottom96 -= squaretemp * (sigxxxx * n - (long double) sigxx * sigxx);

    a = top96 / bottom96;

    top96 = ((long double) sigxx * sigx - sigxxx * n) * a
      + (long double) sigxy *n - (long double) sigx *sigy;
    bottom96 = (long double) sigxx *n - (long double) sigx *sigx;
    b = top96 / bottom96;

    c = (sigy - a * sigxx - b * sigx) / n;
  }
  else if (n == 0 || degree < 0) {
    a = b = c = 0;
  }
  else {
    a = 0;
    if (n > 1 && degree > 0) {
      b = (sigxy * n - sigx * sigy) / (sigxx * n - sigx * sigx);
    }
    else
      b = 0;
    c = (sigy - b * sigx) / n;
  }
}
double QLSQ::get_a ( ) [inline]

Definition at line 45 of file quadlsq.h.

                   {  //get x squard
      return a;
    }
double QLSQ::get_b ( ) [inline]

Definition at line 48 of file quadlsq.h.

                   {  //get x squard
      return b;
    }
double QLSQ::get_c ( ) [inline]

Definition at line 51 of file quadlsq.h.

                   {  //get x squard
      return c;
    }
void QLSQ::remove ( double  x,
double  y 
)

Definition at line 80 of file quadlsq.cpp.

                   {
  if (n <= 0)
                                 //illegal
    EMPTY_QLSQ.error ("QLSQ::remove", ABORT, NULL);
  n--;                           //count elements
  sigx -= x;                     //update accumulators
  sigy -= y;
  sigxx -= x * x;
  sigxy -= x * y;
  sigyy -= y * y;
  sigxxx -= (long double) x *x * x;
  sigxxy -= (long double) x *x * y;
  sigxxxx -= (long double) x *x * x * x;
}

The documentation for this class was generated from the following files: