tesseract  5.0.0-alpha-619-ge9db
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 <cstdint> // for int32_t, int16_t
24 #include "coutln.h" // for C_OUTLINE_LIST, C_OUTLINE
25 #include "elst.h" // for ELIST_ITERATOR, ELISTIZEH, ELIST_LINK
26 #include "points.h" // for FCOORD, ICOORD (ptr only)
27 #include "rect.h" // for TBOX
28 #include "scrollview.h" // for ScrollView, ScrollView::Color
29 
30 class C_BLOB;
31 class DENORM;
32 
33 struct Pix;
34 
36 
37 class C_BLOB:public ELIST_LINK
38 {
39  public:
40  C_BLOB() = default;
41  explicit C_BLOB(C_OUTLINE_LIST *outline_list);
42  // Simpler constructor to build a blob from a single outline that has
43  // already been fully initialized.
44  explicit C_BLOB(C_OUTLINE* outline);
45 
46  // Builds a set of one or more blobs from a list of outlines.
47  // Input: one outline on outline_list contains all the others, but the
48  // nesting and order are undefined.
49  // If good_blob is true, the blob is added to good_blobs_it, unless
50  // an illegal (generation-skipping) parent-child relationship is found.
51  // If so, the parent blob goes to bad_blobs_it, and the immediate children
52  // are promoted to the top level, recursively being sent to good_blobs_it.
53  // If good_blob is false, all created blobs will go to the bad_blobs_it.
54  // Output: outline_list is empty. One or more blobs are added to
55  // good_blobs_it and/or bad_blobs_it.
56  static void ConstructBlobsFromOutlines(bool good_blob,
57  C_OUTLINE_LIST* outline_list,
58  C_BLOB_IT* good_blobs_it,
59  C_BLOB_IT* bad_blobs_it);
60 
61  // Sets the COUT_INVERSE flag appropriately on the outlines and their
62  // children recursively, reversing the outlines if needed so that
63  // everything has an anticlockwise top-level.
64  void CheckInverseFlagAndDirection();
65 
66  // Build and return a fake blob containing a single fake outline with no
67  // steps.
68  static C_BLOB* FakeBlob(const TBOX& box);
69 
70  C_OUTLINE_LIST *out_list() { //get outline list
71  return &outlines;
72  }
73 
74  TBOX bounding_box() const; // compute bounding box
75  int32_t area(); //compute area
76  int32_t perimeter(); // Total perimeter of outlines and 1st level children.
77  int32_t outer_area(); //compute area
78  int32_t count_transitions( //count maxima
79  int32_t threshold); //size threshold
80 
81  void move(const ICOORD vec); // repostion blob by vector
82  void rotate(const FCOORD& rotation); // Rotate by given vector.
83 
84  // Adds sub-pixel resolution EdgeOffsets for the outlines using greyscale
85  // if the supplied pix is 8-bit or the binary edges if nullptr.
86  void ComputeEdgeOffsets(int threshold, Pix* pix);
87 
88  // Estimates and returns the baseline position based on the shape of the
89  // outlines.
90  int16_t EstimateBaselinePosition();
91 
92  // Returns a Pix rendering of the blob. pixDestroy after use.
93  Pix* render();
94  // Returns a Pix rendering of the outline of the blob. (no fill).
95  // pixDestroy after use.
96  Pix* render_outline();
97 
98  #ifndef GRAPHICS_DISABLED
99  void plot( //draw one
100  ScrollView* window, //window to draw in
101  ScrollView::Color blob_colour, //for outer bits
102  ScrollView::Color child_colour); //for holes
103  // Draws the blob in the given colour, and child_colour, normalized
104  // using the given denorm, making use of sub-pixel accurate information
105  // if available.
106  void plot_normed(const DENORM& denorm,
107  ScrollView::Color blob_colour,
108  ScrollView::Color child_colour,
109  ScrollView* window);
110  #endif // GRAPHICS_DISABLED
111 
112  C_BLOB& operator= (const C_BLOB & source) {
113  if (!outlines.empty ())
114  outlines.clear();
115  outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
116  return *this;
117  }
118 
119  static C_BLOB* deep_copy(const C_BLOB* src) {
120  auto* blob = new C_BLOB;
121  *blob = *src;
122  return blob;
123  }
124 
125  static int SortByXMiddle(const void *v1, const void *v2) {
126  const C_BLOB* blob1 = *static_cast<const C_BLOB* const*>(v1);
127  const C_BLOB* blob2 = *static_cast<const C_BLOB* const*>(v2);
128  return blob1->bounding_box().x_middle() -
129  blob2->bounding_box().x_middle();
130  }
131 
132 
133  private:
134  C_OUTLINE_LIST outlines; //master elements
135 };
136 
137 #endif
ScrollView
Definition: scrollview.h:97
elst.h
C_BLOB::bounding_box
TBOX bounding_box() const
Definition: stepblob.cpp:247
ICOORD
integer coordinate
Definition: points.h:30
rect.h
FCOORD
Definition: points.h:187
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
C_BLOB
Definition: stepblob.h:36
C_OUTLINE
Definition: coutln.h:71
C_BLOB::deep_copy
static C_BLOB * deep_copy(const C_BLOB *src)
Definition: stepblob.h:118
render_outline
void render_outline(void *window, TESSLINE *outline, C_COL color)
Definition: render.cpp:106
TBOX::x_middle
int x_middle() const
Definition: rect.h:84
coutln.h
C_OUTLINE::deep_copy
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:260
ELIST_LINK
Definition: elst.h:74
ScrollView::Color
Color
Definition: scrollview.h:100
scrollview.h
points.h
TBOX
Definition: rect.h:33
DENORM
Definition: normalis.h:49