Tesseract  3.02
tesseract-ocr/wordrec/render.cpp
Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        render.c  (Formerly render.c)
00005  * Description:  Convert the various data type into line lists
00006  * Author:       Mark Seaman, OCR Technology
00007  * Created:      Fri Jul 28 13:14:48 1989
00008  * Modified:     Mon Jul 15 10:23:37 1991 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Experimental (Do Not Distribute)
00012  *
00013  * (c) Copyright 1989, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  *********************************************************************************/
00025 #include "render.h"
00026 #include "blobs.h"
00027 
00028 #ifdef __UNIX__
00029 #include <assert.h>
00030 #endif
00031 #include <math.h>
00032 
00033 #include "vecfuncs.h"
00034 
00035 // Include automatically generated configuration file if running autoconf.
00036 #ifdef HAVE_CONFIG_H
00037 #include "config_auto.h"
00038 #endif
00039 
00040 /*----------------------------------------------------------------------
00041               V a r i a b l e s
00042 ----------------------------------------------------------------------*/
00043 ScrollView *blob_window = NULL;
00044 
00045 C_COL color_list[] = {
00046   Red, Cyan, Yellow, Blue, Green, White
00047 };
00048 
00049 BOOL_VAR(wordrec_display_all_blobs, 0, "Display Blobs");
00050 
00051 BOOL_VAR(wordrec_display_all_words, 0, "Display Words");
00052 
00053 BOOL_VAR(wordrec_blob_pause, 0, "Blob pause");
00054 
00055 /*----------------------------------------------------------------------
00056               F u n c t i o n s
00057 ----------------------------------------------------------------------*/
00058 #ifndef GRAPHICS_DISABLED
00059 /**********************************************************************
00060  * display_blob
00061  *
00062  * Macro to display blob in a window.
00063  **********************************************************************/
00064 void display_blob(TBLOB *blob, C_COL color) {
00065   /* Size of drawable */
00066   if (blob_window == NULL) {
00067     blob_window = c_create_window ("Blobs", 520, 10,
00068       500, 256, -1000.0, 1000.0, 0.0, 256.0);
00069   }
00070   else {
00071     c_clear_window(blob_window);
00072   }
00073 
00074   render_blob(blob_window, blob, color);
00075 }
00076 
00077 /**********************************************************************
00078  * render_blob
00079  *
00080  * Create a list of line segments that represent the expanded outline
00081  * that was supplied as input.
00082  **********************************************************************/
00083 void render_blob(void *window, TBLOB *blob, C_COL color) {
00084   /* No outline */
00085   if (!blob)
00086     return;
00087 
00088   render_outline (window, blob->outlines, color);
00089 }
00090 
00091 
00092 /**********************************************************************
00093  * render_edgepts
00094  *
00095  * Create a list of line segments that represent the expanded outline
00096  * that was supplied as input.
00097  **********************************************************************/
00098 void render_edgepts(void *window, EDGEPT *edgept, C_COL color) {
00099   float x = edgept->pos.x;
00100   float y = edgept->pos.y;
00101   EDGEPT *this_edge = edgept;
00102 
00103   if (!edgept)
00104     return;
00105 
00106   c_line_color_index(window, color);
00107   c_move(window, x, y);
00108   do {
00109     this_edge = this_edge->next;
00110     x = this_edge->pos.x;
00111     y = this_edge->pos.y;
00112     c_draw(window, x, y);
00113   }
00114   while (edgept != this_edge);
00115 }
00116 
00117 
00118 /**********************************************************************
00119  * render_outline
00120  *
00121  * Create a list of line segments that represent the expanded outline
00122  * that was supplied as input.
00123  **********************************************************************/
00124 void render_outline(void *window,
00125                     TESSLINE *outline,
00126                     C_COL color) {
00127   /* No outline */
00128   if (!outline)
00129     return;
00130   /* Draw Compact outline */
00131   if (outline->loop)
00132     render_edgepts (window, outline->loop, color);
00133   /* Add on next outlines */
00134   render_outline (window, outline->next, color);
00135 }
00136 
00137 #endif  // GRAPHICS_DISABLED