tesseract 3.04.01

ccstruct/split.h

Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        split.h  (Formerly split.h)
00005  * Description:
00006  * Author:       Mark Seaman, SW Productivity
00007  * Created:      Fri Oct 16 14:37:00 1987
00008  * Modified:     Mon May 13 10:49:23 1991 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Reusable Software Component
00012  *
00013  * (c) Copyright 1987, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  *****************************************************************************/
00025 #ifndef SPLIT_H
00026 #define SPLIT_H
00027 
00028 /*----------------------------------------------------------------------
00029               I n c l u d e s
00030 ----------------------------------------------------------------------*/
00031 #include "blobs.h"
00032 #include "scrollview.h"
00033 
00034 /*----------------------------------------------------------------------
00035               T y p e s
00036 ----------------------------------------------------------------------*/
00037 struct SPLIT {
00038   SPLIT() : point1(NULL), point2(NULL) {}
00039   SPLIT(EDGEPT* pt1, EDGEPT* pt2) : point1(pt1), point2(pt2) {}
00040 
00041   // Returns the bounding box of all the points in the split.
00042   TBOX bounding_box() const;
00043   // Returns the bounding box of the outline from point1 to point2.
00044   TBOX Box12() const { return point1->SegmentBox(point2); }
00045   // Returns the bounding box of the outline from point1 to point1.
00046   TBOX Box21() const { return point2->SegmentBox(point1); }
00047   // Returns the bounding box of the out
00048 
00049   // Hides the SPLIT so the outlines appear not to be cut by it.
00050   void Hide() const;
00051   // Undoes hide, so the outlines are cut by the SPLIT.
00052   void Reveal() const;
00053 
00054   // Returns true if the given EDGEPT is used by this SPLIT, checking only
00055   // the EDGEPT pointer, not the coordinates.
00056   bool UsesPoint(const EDGEPT* point) const {
00057     return point1 == point || point2 == point;
00058   }
00059   // Returns true if the other SPLIT has any position shared with *this.
00060   bool SharesPosition(const SPLIT& other) const {
00061     return point1->EqualPos(*other.point1) || point1->EqualPos(*other.point2) ||
00062            point2->EqualPos(*other.point1) || point2->EqualPos(*other.point2);
00063   }
00064   // Returns true if both points are contained within the blob.
00065   bool ContainedByBlob(const TBLOB& blob) const {
00066     return blob.Contains(point1->pos) && blob.Contains(point2->pos);
00067   }
00068   // Returns true if both points are contained within the outline.
00069   bool ContainedByOutline(const TESSLINE& outline) const {
00070     return outline.Contains(point1->pos) && outline.Contains(point2->pos);
00071   }
00072   // Compute a split priority based on the bounding boxes of the parts.
00073   // The arguments here are config parameters defined in Wordrec. Add chop_
00074   // to the beginning of the name.
00075   float FullPriority(int xmin, int xmax, double overlap_knob,
00076                      int centered_maxwidth, double center_knob,
00077                      double width_change_knob) const;
00078   // Returns true if *this SPLIT appears OK in the sense that it does not cross
00079   // any outlines and does not chop off any ridiculously small pieces.
00080   bool IsHealthy(const TBLOB& blob, int min_points, int min_area) const;
00081   // Returns true if the split generates a small chunk in terms of either area
00082   // or number of points.
00083   bool IsLittleChunk(int min_points, int min_area) const;
00084 
00085   void Print() const;
00086 #ifndef GRAPHICS_DISABLED
00087   // Draws the split in the given window.
00088   void Mark(ScrollView* window) const;
00089 #endif
00090 
00091   // Creates two outlines out of one by splitting the original one in half.
00092   // Inserts the resulting outlines into the given list.
00093   void SplitOutlineList(TESSLINE* outlines) const;
00094   // Makes a split between these two edge points, but does not affect the
00095   // outlines to which they belong.
00096   void SplitOutline() const;
00097   // Undoes the effect of SplitOutlineList, correcting the outlines for undoing
00098   // the split, but possibly leaving some duplicate outlines.
00099   void UnsplitOutlineList(TBLOB* blob) const;
00100   // Removes the split that was put between these two points.
00101   void UnsplitOutlines() const;
00102 
00103   EDGEPT *point1;
00104   EDGEPT *point2;
00105 };
00106 
00107 /*----------------------------------------------------------------------
00108               V a r i a b l e s
00109 ----------------------------------------------------------------------*/
00110 
00111 extern BOOL_VAR_H(wordrec_display_splits, 0, "Display splits");
00112 
00113 /*----------------------------------------------------------------------
00114               F u n c t i o n s
00115 ----------------------------------------------------------------------*/
00116 EDGEPT *make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev);
00117 
00118 void remove_edgept(EDGEPT *point);
00119 
00120 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines