Tesseract 3.01
|
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 // Move by adding shift to all coordinates. 00062 void move(ICOORD shift); 00063 00064 void plot(ScrollView* window, inT32 num); 00065 00066 void fill(ScrollView* window, ScrollView::Color colour); 00067 00068 // Returns true if other is inside this. 00069 bool contains(POLY_BLOCK *other); 00070 00071 // Returns true if the polygons of other and this overlap. 00072 bool overlap(POLY_BLOCK *other); 00073 00074 // Returns the winding number of this around the test_pt. 00075 // Positive for anticlockwise, negative for clockwise, and zero for 00076 // test_pt outside this. 00077 inT16 winding_number(const ICOORD &test_pt); 00078 00079 // Static utility functions to handle the PolyBlockType. 00080 00081 // Returns a color to draw the given type. 00082 static ScrollView::Color ColorForPolyBlockType(PolyBlockType type); 00083 00084 private: 00085 ICOORDELT_LIST vertices; // vertices 00086 TBOX box; // bounding box 00087 PolyBlockType type; // Type of this region. 00088 }; 00089 00090 // Class to iterate the scanlines of a polygon. 00091 class DLLSYM PB_LINE_IT { 00092 public: 00093 PB_LINE_IT(POLY_BLOCK *blkptr) { 00094 block = blkptr; 00095 } 00096 00097 void set_to_block(POLY_BLOCK * blkptr) { 00098 block = blkptr; 00099 } 00100 00101 // Returns a list of runs of pixels for the given y coord. 00102 // Each element of the returned list is the start (x) and extent(y) of 00103 // a run inside the region. 00104 // Delete the returned list after use. 00105 ICOORDELT_LIST *get_line(inT16 y); 00106 00107 private: 00108 POLY_BLOCK * block; 00109 }; 00110 #endif