tesseract
3.03
|
00001 /********************************************************************** 00002 * File: stepblob.h (Formerly cblob.h) 00003 * Description: Code for C_BLOB class. 00004 * Author: Ray Smith 00005 * Created: Tue Oct 08 10:41:13 BST 1991 00006 * 00007 * (C) Copyright 1991, 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 00020 #ifndef STEPBLOB_H 00021 #define STEPBLOB_H 00022 00023 #include "coutln.h" 00024 #include "rect.h" 00025 00026 class C_BLOB; 00027 struct Pix; 00028 ELISTIZEH(C_BLOB) 00029 00030 class C_BLOB:public ELIST_LINK 00031 { 00032 public: 00033 C_BLOB() { 00034 } 00035 explicit C_BLOB(C_OUTLINE_LIST *outline_list); 00036 // Simpler constructor to build a blob from a single outline that has 00037 // already been fully initialized. 00038 explicit C_BLOB(C_OUTLINE* outline); 00039 00040 // Builds a set of one or more blobs from a list of outlines. 00041 // Input: one outline on outline_list contains all the others, but the 00042 // nesting and order are undefined. 00043 // If good_blob is true, the blob is added to good_blobs_it, unless 00044 // an illegal (generation-skipping) parent-child relationship is found. 00045 // If so, the parent blob goes to bad_blobs_it, and the immediate children 00046 // are promoted to the top level, recursively being sent to good_blobs_it. 00047 // If good_blob is false, all created blobs will go to the bad_blobs_it. 00048 // Output: outline_list is empty. One or more blobs are added to 00049 // good_blobs_it and/or bad_blobs_it. 00050 static void ConstructBlobsFromOutlines(bool good_blob, 00051 C_OUTLINE_LIST* outline_list, 00052 C_BLOB_IT* good_blobs_it, 00053 C_BLOB_IT* bad_blobs_it); 00054 00055 // Sets the COUT_INVERSE flag appropriately on the outlines and their 00056 // children recursively, reversing the outlines if needed so that 00057 // everything has an anticlockwise top-level. 00058 void CheckInverseFlagAndDirection(); 00059 00060 // Build and return a fake blob containing a single fake outline with no 00061 // steps. 00062 static C_BLOB* FakeBlob(const TBOX& box); 00063 00064 C_OUTLINE_LIST *out_list() { //get outline list 00065 return &outlines; 00066 } 00067 00068 TBOX bounding_box(); //compute bounding box 00069 inT32 area(); //compute area 00070 inT32 perimeter(); // Total perimeter of outlines and 1st level children. 00071 inT32 outer_area(); //compute area 00072 inT32 count_transitions( //count maxima 00073 inT32 threshold); //size threshold 00074 00075 void move(const ICOORD vec); // repostion blob by vector 00076 void rotate(const FCOORD& rotation); // Rotate by given vector. 00077 00078 // Adds sub-pixel resolution EdgeOffsets for the outlines using greyscale 00079 // if the supplied pix is 8-bit or the binary edges if NULL. 00080 void ComputeEdgeOffsets(int threshold, Pix* pix); 00081 00082 // Estimates and returns the baseline position based on the shape of the 00083 // outlines. 00084 inT16 EstimateBaselinePosition(); 00085 00086 // Returns a Pix rendering of the blob. pixDestroy after use. 00087 Pix* render(); 00088 // Returns a Pix rendering of the outline of the blob. (no fill). 00089 // pixDestroy after use. 00090 Pix* render_outline(); 00091 00092 #ifndef GRAPHICS_DISABLED 00093 void plot( //draw one 00094 ScrollView* window, //window to draw in 00095 ScrollView::Color blob_colour, //for outer bits 00096 ScrollView::Color child_colour); //for holes 00097 // Draws the blob in the given colour, and child_colour, normalized 00098 // using the given denorm, making use of sub-pixel accurate information 00099 // if available. 00100 void plot_normed(const DENORM& denorm, 00101 ScrollView::Color blob_colour, 00102 ScrollView::Color child_colour, 00103 ScrollView* window); 00104 #endif // GRAPHICS_DISABLED 00105 00106 C_BLOB& operator= (const C_BLOB & source) { 00107 if (!outlines.empty ()) 00108 outlines.clear(); 00109 outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy); 00110 return *this; 00111 } 00112 00113 static C_BLOB* deep_copy(const C_BLOB* src) { 00114 C_BLOB* blob = new C_BLOB; 00115 *blob = *src; 00116 return blob; 00117 } 00118 00119 private: 00120 C_OUTLINE_LIST outlines; //master elements 00121 }; 00122 00123 #endif