ccstruct/quspline.h

Go to the documentation of this file.
00001 
00020 #ifndef           QUSPLINE_H
00021 #define           QUSPLINE_H
00022 
00023 #include          "grphics.h"
00024 #include          "quadratc.h"
00025 #include          "serialis.h"
00026 #include          "memry.h"
00027 #include          "rect.h"
00028 
00029 class ROW;
00030 
00035 class QSPLINE
00036 {
00037   friend void make_first_baseline(BOX *,
00038                                   int,
00039                                   int *,
00040                                   int *,
00041                                   QSPLINE *,
00042                                   QSPLINE *,
00043                                   float);
00044   friend void make_holed_baseline(BOX *, int, QSPLINE *, QSPLINE *, float); 
00045   friend void tweak_row_baseline(ROW *); 
00046   public:
00047     QSPLINE() {  //empty constructor
00048       segments = 0;
00049       xcoords = NULL;            //everything empty
00050       quadratics = NULL;
00051     }
00052     QSPLINE(  //copy constructor
00053             const QSPLINE &src);
00054     QSPLINE(                  //constructor
00055             INT32 count,      //number of segments
00056             INT32 *xstarts,   //segment starts
00057             double *coeffs);  //coefficients
00058     ~QSPLINE ();                 //destructor
00059     QSPLINE (                    //least squares fit
00060       int xstarts[],             //spline boundaries
00061       int segcount,              //no of segments
00062       int xcoords[],             //points to fit
00063       int ycoords[], int blobcount,//no of coords
00064       int degree);               //function
00065 
00066     double step(            //step change
00067                 double x1,  //between coords
00068                 double x2);
00069     double y(                  //evaluate
00070              double x) const;  //at x
00071 
00072     void move(              // reposition spline
00073               ICOORD vec);  // by vector
00074     BOOL8 overlap(                   //test overlap
00075                   QSPLINE *spline2,  //2 cannot be smaller
00076                   double fraction);  //by more than this
00077     void extrapolate(                  //linear extrapolation
00078                      double gradient,  //gradient to use
00079                      int left,         //new left edge
00080                      int right);       //new right edge
00081 
00082 #ifndef GRAPHICS_DISABLED
00083     void plot(                       //draw it
00084               WINDOW window,         //in window
00085               COLOUR colour) const;  //in colour
00086 #endif
00087 
00088     void prep_serialise() {  //set ptrs to counts
00089     }                            //not required
00090 
00091     void dump(  //write external bits
00092               FILE *f) {
00093       serialise_bytes (f, (void *) xcoords, (segments + 1) * sizeof (INT32));
00094       serialise_bytes (f, (void *) quadratics, segments * sizeof (QUAD_COEFFS));
00095     }
00096 
00097     void de_dump(  //read external bits
00098                  FILE *f) {
00099       xcoords = (INT32 *) de_serialise_bytes (f,
00100         (segments + 1) * sizeof (INT32));
00101       quadratics = (QUAD_COEFFS *) de_serialise_bytes (f,
00102         segments *
00103         sizeof (QUAD_COEFFS));
00104     }
00105 
00106                                  //assign copy
00107     make_serialise (QSPLINE) QSPLINE & operator= (
00108       const QSPLINE & source);   //from this
00109 
00110   private:
00111 
00112     INT32 spline_index(                  //binary search
00113                        double x) const;  //for x
00114     INT32 segments;              //no of segments
00115     INT32 *xcoords;              //no of coords
00116     QUAD_COEFFS *quadratics;     //spline pieces
00117 };
00118 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1