Tesseract  3.02
tesseract-ocr/ccstruct/polyblk.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        polyblk.h  (Formerly poly_block.h)
00003  * Description: Polygonal blocks
00004  * Author:                                      Sheelagh Lloyd?
00005  * Created:
00006  *
00007  * (C) Copyright 1993, 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 #ifndef           POLYBLK_H
00020 #define           POLYBLK_H
00021 
00022 #include "publictypes.h"
00023 #include "elst.h"
00024 #include "points.h"
00025 #include "rect.h"
00026 #include "scrollview.h"
00027 
00028 #include          "hpddef.h"     // must be last (handpd.dll)
00029 
00030 class DLLSYM POLY_BLOCK {
00031  public:
00032   POLY_BLOCK() {
00033   }
00034   // Initialize from box coordinates.
00035   POLY_BLOCK(const TBOX& box, PolyBlockType type);
00036   POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type);
00037   ~POLY_BLOCK () {
00038   }
00039 
00040   TBOX *bounding_box() {  // access function
00041     return &box;
00042   }
00043 
00044   ICOORDELT_LIST *points() {  // access function
00045     return &vertices;
00046   }
00047 
00048   void compute_bb();
00049 
00050   PolyBlockType isA() const {
00051     return type;
00052   }
00053 
00054   bool IsText() const {
00055     return PTIsTextType(type);
00056   }
00057 
00058   // Rotate about the origin by the given rotation. (Analogous to
00059   // multiplying by a complex number.
00060   void rotate(FCOORD rotation);
00061   // Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)
00062   void reflect_in_y_axis();
00063   // Move by adding shift to all coordinates.
00064   void move(ICOORD shift);
00065 
00066   void plot(ScrollView* window, inT32 num);
00067 
00068   void fill(ScrollView* window, ScrollView::Color colour);
00069 
00070   // Returns true if other is inside this.
00071   bool contains(POLY_BLOCK *other);
00072 
00073   // Returns true if the polygons of other and this overlap.
00074   bool overlap(POLY_BLOCK *other);
00075 
00076   // Returns the winding number of this around the test_pt.
00077   // Positive for anticlockwise, negative for clockwise, and zero for
00078   // test_pt outside this.
00079   inT16 winding_number(const ICOORD &test_pt);
00080 
00081   // Static utility functions to handle the PolyBlockType.
00082 
00083   // Returns a color to draw the given type.
00084   static ScrollView::Color ColorForPolyBlockType(PolyBlockType type);
00085 
00086  private:
00087   ICOORDELT_LIST vertices;     // vertices
00088   TBOX box;                     // bounding box
00089   PolyBlockType type;              // Type of this region.
00090 };
00091 
00092 // Class to iterate the scanlines of a polygon.
00093 class DLLSYM PB_LINE_IT {
00094  public:
00095   PB_LINE_IT(POLY_BLOCK *blkptr) {
00096     block = blkptr;
00097   }
00098 
00099   void set_to_block(POLY_BLOCK * blkptr) {
00100     block = blkptr;
00101   }
00102 
00103   // Returns a list of runs of pixels for the given y coord.
00104   // Each element of the returned list is the start (x) and extent(y) of
00105   // a run inside the region.
00106   // Delete the returned list after use.
00107   ICOORDELT_LIST *get_line(inT16 y);
00108 
00109  private:
00110   POLY_BLOCK * block;
00111 };
00112 #endif