tesseract  4.00.00dev
stepblob.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: stepblob.h (Formerly cblob.h)
3  * Description: Code for C_BLOB class.
4  * Author: Ray Smith
5  * Created: Tue Oct 08 10:41:13 BST 1991
6  *
7  * (C) Copyright 1991, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #ifndef STEPBLOB_H
21 #define STEPBLOB_H
22 
23 #include "coutln.h"
24 #include "rect.h"
25 
26 class C_BLOB;
27 struct Pix;
29 
30 class C_BLOB:public ELIST_LINK
31 {
32  public:
33  C_BLOB() {
34  }
35  explicit C_BLOB(C_OUTLINE_LIST *outline_list);
36  // Simpler constructor to build a blob from a single outline that has
37  // already been fully initialized.
38  explicit C_BLOB(C_OUTLINE* outline);
39 
40  // Builds a set of one or more blobs from a list of outlines.
41  // Input: one outline on outline_list contains all the others, but the
42  // nesting and order are undefined.
43  // If good_blob is true, the blob is added to good_blobs_it, unless
44  // an illegal (generation-skipping) parent-child relationship is found.
45  // If so, the parent blob goes to bad_blobs_it, and the immediate children
46  // are promoted to the top level, recursively being sent to good_blobs_it.
47  // If good_blob is false, all created blobs will go to the bad_blobs_it.
48  // Output: outline_list is empty. One or more blobs are added to
49  // good_blobs_it and/or bad_blobs_it.
50  static void ConstructBlobsFromOutlines(bool good_blob,
51  C_OUTLINE_LIST* outline_list,
52  C_BLOB_IT* good_blobs_it,
53  C_BLOB_IT* bad_blobs_it);
54 
55  // Sets the COUT_INVERSE flag appropriately on the outlines and their
56  // children recursively, reversing the outlines if needed so that
57  // everything has an anticlockwise top-level.
58  void CheckInverseFlagAndDirection();
59 
60  // Build and return a fake blob containing a single fake outline with no
61  // steps.
62  static C_BLOB* FakeBlob(const TBOX& box);
63 
64  C_OUTLINE_LIST *out_list() { //get outline list
65  return &outlines;
66  }
67 
68  TBOX bounding_box() const; // compute bounding box
69  inT32 area(); //compute area
70  inT32 perimeter(); // Total perimeter of outlines and 1st level children.
71  inT32 outer_area(); //compute area
72  inT32 count_transitions( //count maxima
73  inT32 threshold); //size threshold
74 
75  void move(const ICOORD vec); // repostion blob by vector
76  void rotate(const FCOORD& rotation); // Rotate by given vector.
77 
78  // Adds sub-pixel resolution EdgeOffsets for the outlines using greyscale
79  // if the supplied pix is 8-bit or the binary edges if NULL.
80  void ComputeEdgeOffsets(int threshold, Pix* pix);
81 
82  // Estimates and returns the baseline position based on the shape of the
83  // outlines.
84  inT16 EstimateBaselinePosition();
85 
86  // Returns a Pix rendering of the blob. pixDestroy after use.
87  Pix* render();
88  // Returns a Pix rendering of the outline of the blob. (no fill).
89  // pixDestroy after use.
90  Pix* render_outline();
91 
92  #ifndef GRAPHICS_DISABLED
93  void plot( //draw one
94  ScrollView* window, //window to draw in
95  ScrollView::Color blob_colour, //for outer bits
96  ScrollView::Color child_colour); //for holes
97  // Draws the blob in the given colour, and child_colour, normalized
98  // using the given denorm, making use of sub-pixel accurate information
99  // if available.
100  void plot_normed(const DENORM& denorm,
101  ScrollView::Color blob_colour,
102  ScrollView::Color child_colour,
103  ScrollView* window);
104  #endif // GRAPHICS_DISABLED
105 
106  C_BLOB& operator= (const C_BLOB & source) {
107  if (!outlines.empty ())
108  outlines.clear();
109  outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
110  return *this;
111  }
112 
113  static C_BLOB* deep_copy(const C_BLOB* src) {
114  C_BLOB* blob = new C_BLOB;
115  *blob = *src;
116  return blob;
117  }
118 
119  static int SortByXMiddle(const void *v1, const void *v2) {
120  const C_BLOB* blob1 = *static_cast<const C_BLOB* const *>(v1);
121  const C_BLOB* blob2 = *static_cast<const C_BLOB* const *>(v2);
122  return blob1->bounding_box().x_middle() -
123  blob2->bounding_box().x_middle();
124  }
125 
126 
127  private:
128  C_OUTLINE_LIST outlines; //master elements
129 };
130 
131 #endif
C_OUTLINE_LIST * out_list()
Definition: stepblob.h:64
Definition: points.h:189
int32_t inT32
Definition: host.h:38
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:948
void render_outline(void *window, TESSLINE *outline, C_COL color)
Definition: render.cpp:124
int16_t inT16
Definition: host.h:36
static int SortByXMiddle(const void *v1, const void *v2)
Definition: stepblob.h:119
static C_BLOB * deep_copy(const C_BLOB *src)
Definition: stepblob.h:113
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:259
Definition: rect.h:30
TBOX bounding_box() const
Definition: stepblob.cpp:250
C_BLOB()
Definition: stepblob.h:33
int x_middle() const
Definition: rect.h:81
integer coordinate
Definition: points.h:30