Tesseract  3.02
tesseract-ocr/ccstruct/quspline.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        quspline.h  (Formerly qspline.h)
00003  * Description: Code for the QSPLINE class.
00004  * Author:              Ray Smith
00005  * Created:             Tue Oct 08 17:16:12 BST 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef           QUSPLINE_H
00021 #define           QUSPLINE_H
00022 
00023 #include          "quadratc.h"
00024 #include          "serialis.h"
00025 #include          "memry.h"
00026 #include          "rect.h"
00027 
00028 class ROW;
00029 
00030 class QSPLINE
00031 {
00032   friend void make_first_baseline(TBOX *,
00033                                   int,
00034                                   int *,
00035                                   int *,
00036                                   QSPLINE *,
00037                                   QSPLINE *,
00038                                   float);
00039   friend void make_holed_baseline(TBOX *, int, QSPLINE *, QSPLINE *, float);
00040   friend void tweak_row_baseline(ROW *, double, double);
00041   public:
00042     QSPLINE() {  //empty constructor
00043       segments = 0;
00044       xcoords = NULL;            //everything empty
00045       quadratics = NULL;
00046     }
00047     QSPLINE(  //copy constructor
00048             const QSPLINE &src);
00049     QSPLINE(                  //constructor
00050             inT32 count,      //number of segments
00051             inT32 *xstarts,   //segment starts
00052             double *coeffs);  //coefficients
00053     ~QSPLINE ();                 //destructor
00054     QSPLINE (                    //least squares fit
00055       int xstarts[],             //spline boundaries
00056       int segcount,              //no of segments
00057       int xcoords[],             //points to fit
00058       int ycoords[], int blobcount,//no of coords
00059       int degree);               //function
00060 
00061     double step(            //step change
00062                 double x1,  //between coords
00063                 double x2);
00064     double y(                  //evaluate
00065              double x) const;  //at x
00066 
00067     void move(              // reposition spline
00068               ICOORD vec);  // by vector
00069     BOOL8 overlap(                   //test overlap
00070                   QSPLINE *spline2,  //2 cannot be smaller
00071                   double fraction);  //by more than this
00072     void extrapolate(                  //linear extrapolation
00073                      double gradient,  //gradient to use
00074                      int left,         //new left edge
00075                      int right);       //new right edge
00076 
00077 #ifndef GRAPHICS_DISABLED
00078     void plot(                       //draw it
00079               ScrollView* window,         //in window
00080               ScrollView::Color colour) const;  //in colour
00081 #endif
00082 
00083     QSPLINE & operator= (
00084       const QSPLINE & source);   //from this
00085 
00086   private:
00087 
00088     inT32 spline_index(                  //binary search
00089                        double x) const;  //for x
00090     inT32 segments;              //no of segments
00091     inT32 *xcoords;              //no of coords
00092     QUAD_COEFFS *quadratics;     //spline pieces
00093 };
00094 #endif