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 "quadratc.h" 24 #include "serialis.h" 25 #include "memry.h" 26 #include "rect.h" 27 28 class ROW; 29 30 class QSPLINE 31 { 32 friend void make_first_baseline(TBOX *, 33 int, 34 int *, 35 int *, 36 QSPLINE *, 37 QSPLINE *, 38 float); 39 friend void make_holed_baseline(TBOX *, int, QSPLINE *, QSPLINE *, float); 40 friend void tweak_row_baseline(ROW *); 41 public: QSPLINE()42 QSPLINE() { //empty constructor 43 segments = 0; 44 xcoords = NULL; //everything empty 45 quadratics = NULL; 46 } 47 QSPLINE( //copy constructor 48 const QSPLINE &src); 49 QSPLINE( //constructor 50 inT32 count, //number of segments 51 inT32 *xstarts, //segment starts 52 double *coeffs); //coefficients 53 ~QSPLINE (); //destructor 54 QSPLINE ( //least squares fit 55 int xstarts[], //spline boundaries 56 int segcount, //no of segments 57 int xcoords[], //points to fit 58 int ycoords[], int blobcount,//no of coords 59 int degree); //function 60 61 double step( //step change 62 double x1, //between coords 63 double x2); 64 double y( //evaluate 65 double x) const; //at x 66 67 void move( // reposition spline 68 ICOORD vec); // by vector 69 BOOL8 overlap( //test overlap 70 QSPLINE *spline2, //2 cannot be smaller 71 double fraction); //by more than this 72 void extrapolate( //linear extrapolation 73 double gradient, //gradient to use 74 int left, //new left edge 75 int right); //new right edge 76 77 #ifndef GRAPHICS_DISABLED 78 void plot( //draw it 79 ScrollView* window, //in window 80 ScrollView::Color colour) const; //in colour 81 #endif 82 prep_serialise()83 void prep_serialise() { //set ptrs to counts 84 } //not required 85 dump(FILE * f)86 void dump( //write external bits 87 FILE *f) { 88 serialise_bytes (f, (void *) xcoords, (segments + 1) * sizeof (inT32)); 89 serialise_bytes (f, (void *) quadratics, segments * sizeof (QUAD_COEFFS)); 90 } 91 de_dump(FILE * f)92 void de_dump( //read external bits 93 FILE *f) { 94 xcoords = (inT32 *) de_serialise_bytes (f, 95 (segments + 1) * sizeof (inT32)); 96 quadratics = (QUAD_COEFFS *) de_serialise_bytes (f, 97 segments * 98 sizeof (QUAD_COEFFS)); 99 } 100 101 //assign copy 102 make_serialise (QSPLINE) QSPLINE & operator= ( 103 const QSPLINE & source); //from this 104 105 private: 106 107 inT32 spline_index( //binary search 108 double x) const; //for x 109 inT32 segments; //no of segments 110 inT32 *xcoords; //no of coords 111 QUAD_COEFFS *quadratics; //spline pieces 112 }; 113 #endif 114