2007-03-08 04:03:40 +08:00
|
|
|
/* -*-C-*-
|
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File: plotseg.c (Formerly plotseg.c)
|
|
|
|
* Description:
|
|
|
|
* Author: Mark Seaman, OCR Technology
|
|
|
|
* Created: Fri Oct 16 14:37:00 1987
|
|
|
|
* Modified: Fri Apr 26 10:03:05 1991 (Mark Seaman) marks@hpgrlt
|
|
|
|
* Language: C
|
|
|
|
* Package: N/A
|
|
|
|
* Status: Reusable Software Component
|
|
|
|
*
|
|
|
|
* (c) Copyright 1987, Hewlett-Packard Company.
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
I n c l u d e s
|
|
|
|
----------------------------------------------------------------------*/
|
|
|
|
#include "plotseg.h"
|
|
|
|
#include "callcpp.h"
|
2008-04-22 08:35:16 +08:00
|
|
|
#include "scrollview.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "blobs.h"
|
|
|
|
#include "const.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
2010-09-30 23:53:40 +08:00
|
|
|
// Include automatically generated configuration file if running autoconf.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config_auto.h"
|
|
|
|
#endif
|
|
|
|
|
2009-06-04 01:24:08 +08:00
|
|
|
#ifndef GRAPHICS_DISABLED
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
V a r i a b l e s
|
|
|
|
----------------------------------------------------------------------*/
|
2008-04-22 08:35:16 +08:00
|
|
|
ScrollView *segm_window = NULL;
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:46:01 +08:00
|
|
|
INT_VAR(wordrec_display_segmentations, 0, "Display Segmentations");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
F u n c t i o n s
|
|
|
|
----------------------------------------------------------------------*/
|
|
|
|
/**********************************************************************
|
|
|
|
* display_segmentation
|
|
|
|
*
|
|
|
|
* Display all the words on the page into a window.
|
|
|
|
**********************************************************************/
|
2008-04-22 08:35:16 +08:00
|
|
|
void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation) {
|
2007-03-08 04:03:40 +08:00
|
|
|
/* If no window create it */
|
|
|
|
if (segm_window == NULL) {
|
|
|
|
segm_window = c_create_window ("Segmentation", 5, 10,
|
2008-04-22 08:35:16 +08:00
|
|
|
500, 256, -1000.0, 1000.0, 0.0, 256.0);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
else {
|
2008-04-22 08:35:16 +08:00
|
|
|
c_clear_window(segm_window);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
2008-04-22 08:35:16 +08:00
|
|
|
render_segmentation(segm_window, chunks, segmentation);
|
2007-03-08 04:03:40 +08:00
|
|
|
/* Put data in the window */
|
2008-04-22 08:35:16 +08:00
|
|
|
c_make_current(segm_window);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* render_segmentation
|
|
|
|
*
|
|
|
|
* Create a list of line segments that represent the list of chunks
|
|
|
|
* using the correct segmentation that was supplied as input.
|
|
|
|
**********************************************************************/
|
2008-04-22 08:35:16 +08:00
|
|
|
void render_segmentation(ScrollView *window,
|
2007-03-08 04:03:40 +08:00
|
|
|
TBLOB *chunks,
|
|
|
|
SEARCH_STATE segmentation) {
|
|
|
|
TBLOB *blob;
|
|
|
|
C_COL color = Black;
|
|
|
|
int char_num = -1;
|
|
|
|
int chunks_left = 0;
|
|
|
|
|
2012-02-02 11:01:38 +08:00
|
|
|
TBOX bbox;
|
|
|
|
if (chunks) bbox = chunks->bounding_box();
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
for (blob = chunks; blob != NULL; blob = blob->next) {
|
2012-02-02 11:01:38 +08:00
|
|
|
bbox += blob->bounding_box();
|
2007-03-08 04:03:40 +08:00
|
|
|
if (chunks_left-- == 0) {
|
|
|
|
color = color_list[++char_num % NUM_COLORS];
|
|
|
|
|
|
|
|
if (char_num < segmentation[0])
|
|
|
|
chunks_left = segmentation[char_num + 1];
|
|
|
|
else
|
2009-06-04 01:24:08 +08:00
|
|
|
chunks_left = MAX_INT32;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2008-04-22 08:35:16 +08:00
|
|
|
render_outline(window, blob->outlines, color);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2012-02-02 11:01:38 +08:00
|
|
|
window->ZoomToRectangle(bbox.left(), bbox.top(),
|
|
|
|
bbox.right(), bbox.bottom());
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2009-06-04 01:24:08 +08:00
|
|
|
|
2009-07-11 10:46:01 +08:00
|
|
|
#endif // GRPAHICS_DISABLED
|