tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
quspline.h
1 /**********************************************************************
2  * File: quspline.h (Formerly qspline.h)
3  * Description: Code for the QSPLINE class.
4  * Author: Ray Smith
5  * Created: Tue Oct 08 17:16:12 BST 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef QUSPLINE_H
21 #define QUSPLINE_H
22 
23 #include <cstdint> // for int32_t
24 #include "scrollview.h" // for ScrollView, ScrollView::Color
25 
26 class ICOORD;
27 class QUAD_COEFFS;
28 class ROW;
29 class TBOX;
30 struct Pix;
31 
32 class QSPLINE
33 {
34  friend void make_first_baseline(TBOX *,
35  int,
36  int *,
37  int *,
38  QSPLINE *,
39  QSPLINE *,
40  float);
41  friend void make_holed_baseline(TBOX *, int, QSPLINE *, QSPLINE *, float);
42  friend void tweak_row_baseline(ROW *, double, double);
43  public:
44  QSPLINE() { //empty constructor
45  segments = 0;
46  xcoords = nullptr; //everything empty
47  quadratics = nullptr;
48  }
49  QSPLINE( //copy constructor
50  const QSPLINE &src);
51  QSPLINE( //constructor
52  int32_t count, //number of segments
53  int32_t *xstarts, //segment starts
54  double *coeffs); //coefficients
55  ~QSPLINE (); //destructor
56  QSPLINE ( //least squares fit
57  int xstarts[], //spline boundaries
58  int segcount, //no of segments
59  int xcoords[], //points to fit
60  int ycoords[], int blobcount,//no of coords
61  int degree); //function
62 
63  double step( //step change
64  double x1, //between coords
65  double x2);
66  double y( //evaluate
67  double x) const; //at x
68 
69  void move( // reposition spline
70  ICOORD vec); // by vector
71  bool overlap( //test overlap
72  QSPLINE* spline2, //2 cannot be smaller
73  double fraction); //by more than this
74  void extrapolate( //linear extrapolation
75  double gradient, //gradient to use
76  int left, //new left edge
77  int right); //new right edge
78 
79 #ifndef GRAPHICS_DISABLED
80  void plot( //draw it
81  ScrollView* window, //in window
82  ScrollView::Color colour) const; //in colour
83 #endif
84 
85  // Paint the baseline over pix. If pix has depth of 32, then the line will
86  // be painted in red. Otherwise it will be painted in black.
87  void plot(Pix* pix) const;
88 
90  const QSPLINE & source); //from this
91 
92  private:
93 
94  int32_t spline_index( //binary search
95  double x) const; //for x
96  int32_t segments; //no of segments
97  int32_t *xcoords; //no of coords
98  QUAD_COEFFS *quadratics; //spline pieces
99 };
100 #endif
~QSPLINE()
Definition: quspline.cpp:152
QSPLINE & operator=(const QSPLINE &source)
Definition: quspline.cpp:164
Color
Definition: scrollview.h:105
Definition: rect.h:34
int32_t * xcoords
Definition: quspline.h:97
Definition: quspline.h:32
void extrapolate(double gradient, int left, int right)
Definition: quspline.cpp:291
Definition: scrollview.h:102
void move(ICOORD vec)
Definition: quspline.cpp:251
friend void make_first_baseline(TBOX *, int, int *, int *, QSPLINE *, QSPLINE *, float)
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:347
int32_t spline_index(double x) const
Definition: quspline.cpp:225
integer coordinate
Definition: points.h:32
Definition: ocrrow.h:36
QSPLINE()
Definition: quspline.h:44
Definition: quadratc.h:25
double y(double x) const
Definition: quspline.cpp:209
friend void make_holed_baseline(TBOX *, int, QSPLINE *, QSPLINE *, float)
double step(double x1, double x2)
Definition: quspline.cpp:184
int32_t segments
Definition: quspline.h:96
bool overlap(QSPLINE *spline2, double fraction)
Definition: quspline.cpp:272
QUAD_COEFFS * quadratics
Definition: quspline.h:98
friend void tweak_row_baseline(ROW *, double, double)
Definition: tordmain.cpp:895