tesseract
3.03
|
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 class DLLSYM POLY_BLOCK { 00029 public: 00030 POLY_BLOCK() { 00031 } 00032 // Initialize from box coordinates. 00033 POLY_BLOCK(const TBOX& box, PolyBlockType type); 00034 POLY_BLOCK(ICOORDELT_LIST *points, PolyBlockType type); 00035 ~POLY_BLOCK () { 00036 } 00037 00038 TBOX *bounding_box() { // access function 00039 return &box; 00040 } 00041 00042 ICOORDELT_LIST *points() { // access function 00043 return &vertices; 00044 } 00045 00046 void compute_bb(); 00047 00048 PolyBlockType isA() const { 00049 return type; 00050 } 00051 00052 bool IsText() const { 00053 return PTIsTextType(type); 00054 } 00055 00056 // Rotate about the origin by the given rotation. (Analogous to 00057 // multiplying by a complex number. 00058 void rotate(FCOORD rotation); 00059 // Reflect the coords of the polygon in the y-axis. (Flip the sign of x.) 00060 void reflect_in_y_axis(); 00061 // Move by adding shift to all coordinates. 00062 void move(ICOORD shift); 00063 00064 void plot(ScrollView* window, inT32 num); 00065 00066 #ifndef GRAPHICS_DISABLED 00067 void fill(ScrollView* window, ScrollView::Color colour); 00068 #endif // GRAPHICS_DISABLED 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 #ifndef GRAPHICS_DISABLED 00082 // Static utility functions to handle the PolyBlockType. 00083 // Returns a color to draw the given type. 00084 static ScrollView::Color ColorForPolyBlockType(PolyBlockType type); 00085 #endif // GRAPHICS_DISABLED 00086 00087 private: 00088 ICOORDELT_LIST vertices; // vertices 00089 TBOX box; // bounding box 00090 PolyBlockType type; // Type of this region. 00091 }; 00092 00093 // Class to iterate the scanlines of a polygon. 00094 class DLLSYM PB_LINE_IT { 00095 public: 00096 PB_LINE_IT(POLY_BLOCK *blkptr) { 00097 block = blkptr; 00098 } 00099 00100 void set_to_block(POLY_BLOCK * blkptr) { 00101 block = blkptr; 00102 } 00103 00104 // Returns a list of runs of pixels for the given y coord. 00105 // Each element of the returned list is the start (x) and extent(y) of 00106 // a run inside the region. 00107 // Delete the returned list after use. 00108 ICOORDELT_LIST *get_line(inT16 y); 00109 00110 private: 00111 POLY_BLOCK * block; 00112 }; 00113 #endif