Tesseract  3.02
 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 ----------------------------------------------------------------------*/
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  **********************************************************************/
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
C_COL color_list[]
Definition: render.cpp:45
#define NUM_COLORS
Definition: render.h:44
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
void render_segmentation(ScrollView *window, TBLOB *chunks, SEARCH_STATE segmentation)
Definition: plotseg.cpp:79
void ZoomToRectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:760
Definition: rect.h:29
int wordrec_display_segmentations
Definition: plotseg.cpp:48
TESSLINE * outlines
Definition: blobs.h:227
inT16 right() const
Definition: rect.h:74
ScrollView * c_create_window(const char *name, inT16 xpos, inT16 ypos, inT16 xsize, inT16 ysize, double xmin, double xmax, double ymin, double ymax)
Definition: callcpp.cpp:56
void render_outline(void *window, TESSLINE *outline, C_COL color)
Definition: render.cpp:124
C_COL
Definition: callcpp.h:32
#define MAX_INT32
Definition: host.h:120
void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation)
Definition: plotseg.cpp:58
#define INT_VAR(name, val, comment)
Definition: params.h:248
ScrollView * segm_window
Definition: plotseg.cpp:46
Definition: blobs.h:174
inT16 top() const
Definition: rect.h:53
Definition: callcpp.h:33
TBOX bounding_box() const
Definition: blobs.cpp:384
void c_clear_window(void *win)
Definition: callcpp.cpp:105
void c_make_current(void *win)
Definition: callcpp.cpp:98
TBLOB * next
Definition: blobs.h:228
int * SEARCH_STATE
Definition: states.h:46
inT16 bottom() const
Definition: rect.h:60