tesseract  5.0.0-alpha-619-ge9db
quspline.h
Go to the documentation of this file.
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
ScrollView
Definition: scrollview.h:97
QSPLINE::tweak_row_baseline
friend void tweak_row_baseline(ROW *, double, double)
Definition: tordmain.cpp:893
QSPLINE::make_holed_baseline
friend void make_holed_baseline(TBOX *, int, QSPLINE *, QSPLINE *, float)
ICOORD
integer coordinate
Definition: points.h:30
QSPLINE
Definition: quspline.h:31
QSPLINE::make_first_baseline
friend void make_first_baseline(TBOX *, int, int *, int *, QSPLINE *, QSPLINE *, float)
QSPLINE::extrapolate
void extrapolate(double gradient, int left, int right)
Definition: quspline.cpp:280
QSPLINE::plot
void plot(ScrollView *window, ScrollView::Color colour) const
Definition: quspline.cpp:335
QSPLINE::move
void move(ICOORD vec)
Definition: quspline.cpp:242
QSPLINE::operator=
QSPLINE & operator=(const QSPLINE &source)
Definition: quspline.cpp:159
QSPLINE::step
double step(double x1, double x2)
Definition: quspline.cpp:178
QSPLINE::y
double y(double x) const
Definition: quspline.cpp:202
count
int count(LIST var_list)
Definition: oldlist.cpp:79
ROW
Definition: ocrrow.h:35
QUAD_COEFFS
Definition: quadratc.h:24
QSPLINE::~QSPLINE
~QSPLINE()
Definition: quspline.cpp:148
QSPLINE::QSPLINE
QSPLINE()
Definition: quspline.h:43
QSPLINE::overlap
bool overlap(QSPLINE *spline2, double fraction)
Definition: quspline.cpp:262
ScrollView::Color
Color
Definition: scrollview.h:100
scrollview.h
TBOX
Definition: rect.h:33