tesseract  5.0.0
render.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * File: render.cpp (Formerly render.c)
4  * Description: Convert the various data type into line lists
5  * Author: Mark Seaman, OCR Technology
6  *
7  * (c) Copyright 1989, Hewlett-Packard Company.
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 // Include automatically generated configuration file if running autoconf.
21 #ifdef HAVE_CONFIG_H
22 # include "config_auto.h"
23 #endif
24 
25 #include "render.h"
26 
27 #include "blobs.h"
28 
29 #include <cmath>
30 
31 namespace tesseract {
32 
33 /*----------------------------------------------------------------------
34  V a r i a b l e s
35 ----------------------------------------------------------------------*/
37 
40 
41 BOOL_VAR(wordrec_display_all_blobs, 0, "Display Blobs");
42 
43 BOOL_VAR(wordrec_blob_pause, 0, "Blob pause");
44 
45 /*----------------------------------------------------------------------
46  F u n c t i o n s
47 ----------------------------------------------------------------------*/
48 #ifndef GRAPHICS_DISABLED
49 /**********************************************************************
50  * display_blob
51  *
52  * Macro to display blob in a window.
53  **********************************************************************/
54 void display_blob(TBLOB *blob, ScrollView::Color color) {
55  /* Size of drawable */
56  if (blob_window == nullptr) {
57  blob_window = new ScrollView("Blobs", 520, 10, 500, 256, 2000, 256, true);
58  } else {
59  blob_window->Clear();
60  }
61 
62  render_blob(blob_window, blob, color);
63 }
64 
65 /**********************************************************************
66  * render_blob
67  *
68  * Create a list of line segments that represent the expanded outline
69  * that was supplied as input.
70  **********************************************************************/
71 void render_blob(ScrollView *window, TBLOB *blob, ScrollView::Color color) {
72  /* No outline */
73  if (!blob) {
74  return;
75  }
76 
77  render_outline(window, blob->outlines, color);
78 }
79 
80 /**********************************************************************
81  * render_edgepts
82  *
83  * Create a list of line segments that represent the expanded outline
84  * that was supplied as input.
85  **********************************************************************/
86 void render_edgepts(ScrollView *window, EDGEPT *edgept, ScrollView::Color color) {
87  if (!edgept) {
88  return;
89  }
90 
91  float x = edgept->pos.x;
92  float y = edgept->pos.y;
93  EDGEPT *this_edge = edgept;
94 
95  window->Pen(color);
96  window->SetCursor(x, y);
97  do {
98  this_edge = this_edge->next;
99  x = this_edge->pos.x;
100  y = this_edge->pos.y;
101  window->DrawTo(x, y);
102  } while (edgept != this_edge);
103 }
104 
105 /**********************************************************************
106  * render_outline
107  *
108  * Create a list of line segments that represent the expanded outline
109  * that was supplied as input.
110  **********************************************************************/
111 void render_outline(ScrollView *window, TESSLINE *outline, ScrollView::Color color) {
112  /* No outline */
113  if (!outline) {
114  return;
115  }
116  /* Draw Compact outline */
117  if (outline->loop) {
118  render_edgepts(window, outline->loop, color);
119  }
120  /* Add on next outlines */
121  render_outline(window, outline->next, color);
122 }
123 
124 #endif // !GRAPHICS_DISABLED
125 
126 } // namespace tesseract
#define BOOL_VAR(name, val, comment)
Definition: params.h:359
ScrollView * blob_window
Definition: render.cpp:36
void render_edgepts(ScrollView *window, EDGEPT *edgept, ScrollView::Color color)
Definition: render.cpp:86
ScrollView::Color color_list[]
Definition: render.cpp:38
void render_outline(ScrollView *window, TESSLINE *outline, ScrollView::Color color)
Definition: render.cpp:111
bool wordrec_display_all_blobs
Definition: render.cpp:41
void render_blob(ScrollView *window, TBLOB *blob, ScrollView::Color color)
Definition: render.cpp:71
bool wordrec_blob_pause
Definition: render.cpp:43
void display_blob(TBLOB *blob, ScrollView::Color color)
Definition: render.cpp:54
TDimension x
Definition: blobs.h:89
TDimension y
Definition: blobs.h:90
EDGEPT * next
Definition: blobs.h:200
TPOINT pos
Definition: blobs.h:194
EDGEPT * loop
Definition: blobs.h:287
TESSLINE * next
Definition: blobs.h:288
TESSLINE * outlines
Definition: blobs.h:404
void Pen(Color color)
Definition: scrollview.cpp:723
void SetCursor(int x, int y)
Definition: scrollview.cpp:498
void DrawTo(int x, int y)
Definition: scrollview.cpp:504