• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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               I n c l u d e s
27 ----------------------------------------------------------------------*/
28 #include "plotseg.h"
29 #include "callcpp.h"
30 #include "scrollview.h"
31 #include "tessclas.h"
32 #include "blobs.h"
33 #include "const.h"
34 #include <math.h>
35 
36 #ifndef GRAPHICS_DISABLED
37 
38 /*----------------------------------------------------------------------
39               V a r i a b l e s
40 ----------------------------------------------------------------------*/
41 ScrollView *segm_window = NULL;
42 
43 INT_VAR(wordrec_display_segmentations, 0, "Display Segmentations");
44 
45 /*----------------------------------------------------------------------
46               F u n c t i o n s
47 ----------------------------------------------------------------------*/
48 /**********************************************************************
49  * display_segmentation
50  *
51  * Display all the words on the page into a window.
52  **********************************************************************/
display_segmentation(TBLOB * chunks,SEARCH_STATE segmentation)53 void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation) {
54   /* If no window create it */
55   if (segm_window == NULL) {
56     segm_window = c_create_window ("Segmentation", 5, 10,
57       500, 256, -1000.0, 1000.0, 0.0, 256.0);
58   }
59   else {
60     c_clear_window(segm_window);
61   }
62 
63   render_segmentation(segm_window, chunks, segmentation);
64   /* Put data in the window */
65   c_make_current(segm_window);
66 }
67 
68 /**********************************************************************
69  * render_segmentation
70  *
71  * Create a list of line segments that represent the list of chunks
72  * using the correct segmentation that was supplied as input.
73  **********************************************************************/
render_segmentation(ScrollView * window,TBLOB * chunks,SEARCH_STATE segmentation)74 void render_segmentation(ScrollView *window,
75                          TBLOB *chunks,
76                          SEARCH_STATE segmentation) {
77   TBLOB *blob;
78   C_COL color = Black;
79   int char_num = -1;
80   int chunks_left = 0;
81 
82   TPOINT topleft;
83   TPOINT botright;
84 
85   // Find bounding box.
86   blobs_bounding_box(chunks, &topleft, &botright);
87 
88   iterate_blobs(blob, chunks) {
89 
90     if (chunks_left-- == 0) {
91       color = color_list[++char_num % NUM_COLORS];
92 
93       if (char_num < segmentation[0])
94         chunks_left = segmentation[char_num + 1];
95       else
96         chunks_left = MAX_INT32;
97     }
98     render_outline(window, blob->outlines, color);
99   }
100   window->ZoomToRectangle(topleft.x, topleft.y, botright.x, botright.y);
101 }
102 
103 #endif  // GRPAHICS_DISABLED
104