Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plotseg.cpp
Go to the documentation of this file.
1 /* -*-C-*-
2 ********************************************************************************
3 *
4 * File: plotseg.c (Formerly plotseg.c)
5 * Description:
6 * Author: Mark Seaman, OCR Technology
7 * Created: Fri Oct 16 14:37:00 1987
8 * Modified: Fri Apr 26 10:03:05 1991 (Mark Seaman) marks@hpgrlt
9 * Language: C
10 * Package: N/A
11 * Status: Reusable Software Component
12 *
13 * (c) Copyright 1987, Hewlett-Packard Company.
14 ** Licensed under the Apache License, Version 2.0 (the "License");
15 ** you may not use this file except in compliance with the License.
16 ** You may obtain a copy of the License at
17 ** http://www.apache.org/licenses/LICENSE-2.0
18 ** Unless required by applicable law or agreed to in writing, software
19 ** distributed under the License is distributed on an "AS IS" BASIS,
20 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 ** See the License for the specific language governing permissions and
22 ** limitations under the License.
23 *
24 *********************************************************************************/
25
26 // Include automatically generated configuration file if running autoconf.
27 #ifdef HAVE_CONFIG_H
28 #include "config_auto.h"
29 #endif
30
31 #ifndef GRAPHICS_DISABLED
32
33 /*----------------------------------------------------------------------
34 I n c l u d e s
35 ----------------------------------------------------------------------*/
36 #include "plotseg.h"
37 #include "callcpp.h"
38 #include "scrollview.h"
39 #include "blobs.h"
40 #include "const.h"
41 #include <math.h>
42
43 /*----------------------------------------------------------------------
44 V a r i a b l e s
45 ----------------------------------------------------------------------*/
46 ScrollView *segm_window = NULL;
47
48 INT_VAR(wordrec_display_segmentations, 0, "Display Segmentations");
49
50 /*----------------------------------------------------------------------
51 F u n c t i o n s
52 ----------------------------------------------------------------------*/
53 /**********************************************************************
54 * display_segmentation
55 *
56 * Display all the words on the page into a window.
57 **********************************************************************/
58 void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation) {
59 /* If no window create it */
60 if (segm_window == NULL) {
61 segm_window = c_create_window ("Segmentation", 5, 10,
62 500, 256, -1000.0, 1000.0, 0.0, 256.0);
63 }
64 else {
65 c_clear_window(segm_window);
66 }
67
68 render_segmentation(segm_window, chunks, segmentation);
69 /* Put data in the window */
70 c_make_current(segm_window);
71 }
72
73 /**********************************************************************
74 * render_segmentation
75 *
76 * Create a list of line segments that represent the list of chunks
77 * using the correct segmentation that was supplied as input.
78 **********************************************************************/
79 void render_segmentation(ScrollView *window,
80 TBLOB *chunks,
81 SEARCH_STATE segmentation) {
82 TBLOB *blob;
83 C_COL color = Black;
84 int char_num = -1;
85 int chunks_left = 0;
86
87 TBOX bbox;
88 if (chunks) bbox = chunks->bounding_box();
89
90 for (blob = chunks; blob != NULL; blob = blob->next) {
91 bbox += blob->bounding_box();
92 if (chunks_left-- == 0) {
93 color = color_list[++char_num % NUM_COLORS];
94
95 if (char_num < segmentation[0])
96 chunks_left = segmentation[char_num + 1];
97 else
98 chunks_left = MAX_INT32;
99 }
100 render_outline(window, blob->outlines, color);
101 }
102 window->ZoomToRectangle(bbox.left(), bbox.top(),
103 bbox.right(), bbox.bottom());
104 }
105
106 #endif // GRPAHICS_DISABLED