wordrec/matchtab.cpp File Reference

#include "matchtab.h"
#include "freelist.h"
#include "callcpp.h"
#include "blobs.h"

Go to the source code of this file.

Classes

Defines

Typedefs

Functions

Variables


Define Documentation

#define blank_entry ( match_table,
 )     (! (match_table[x].topleft | match_table[x].botright))

Test an element in the blob match table to see if it is blank.

Return a non-zero value if it is blank.

Definition at line 66 of file matchtab.cpp.

Referenced by get_match_by_bounds(), init_match_table(), and put_match().

#define NUM_MATCH_ENTRIES   500

Entries in match_table.

Definition at line 58 of file matchtab.cpp.

Referenced by get_match_by_bounds(), init_match_table(), and put_match().


Typedef Documentation

typedef struct _MATCH_ MATCH


Function Documentation

void end_match_table (  ) 

Definition at line 100 of file matchtab.cpp.

References been_initialized, init_match_table(), match_table, memfree(), and NULL.

Referenced by program_editdown().

00100                        {
00101   if (been_initialized) {
00102     init_match_table();
00103     memfree(match_table);
00104     match_table = NULL;
00105     been_initialized = 0;
00106   }
00107 }

CHOICES get_match ( TBLOB blob  ) 

Look up this blob in the match table to see if it needs to be matched.

If it is not present then NULL is returned.

Definition at line 153 of file matchtab.cpp.

References blob_bounding_box(), and get_match_by_bounds().

00153                                {
00154   unsigned int topleft;
00155   unsigned int botright;
00156   TPOINT tp_topleft;
00157   TPOINT tp_botright;
00158   /* Do starting hash */
00159   blob_bounding_box(blob, &tp_topleft, &tp_botright);
00160   topleft = *(unsigned int *) &tp_topleft;
00161   botright = *(unsigned int *) &tp_botright;
00162   return (get_match_by_bounds (topleft, botright));
00163 }

CHOICES get_match_by_bounds ( unsigned int  topleft,
unsigned int  botright 
)

Look up this blob in the match table to see if it needs to be matched.

If it is not present then NULL is returned.

Definition at line 173 of file matchtab.cpp.

References blank_entry, copy_choices(), match_table, NIL, and NUM_MATCH_ENTRIES.

Referenced by get_match(), and record_piece_ratings().

00173                                                                          { 
00174   unsigned int start;
00175   int x;
00176   /* Do starting hash */
00177   start = (topleft * botright) % NUM_MATCH_ENTRIES;
00178   /* Search for match */
00179   x = start;
00180   do {
00181     /* Not found when blank */
00182     if (blank_entry (match_table, x))
00183       break;
00184     /* Is this the match ? */
00185     if (match_table[x].topleft == topleft &&
00186     match_table[x].botright == botright) {
00187       return (copy_choices (match_table[x].rating));
00188     }
00189     if (++x >= NUM_MATCH_ENTRIES)
00190       x = 0;
00191   }
00192   while (x != start);
00193 
00194   return (NIL);
00195 }

void init_match_table (  ) 

Note:
File: matchtab.h (Formerly matchtab.h)
Match table to retain blobs that were matched.
Author:
Mark Seaman, OCR Technology
Date:
Mon Jan 29 09:00:56 1990 Tue Mar 19 15:38:19 1991 (Mark Seaman) marks
 * (c) Copyright 1990, 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.

Definition at line 77 of file matchtab.cpp.

References been_initialized, blank_entry, _MATCH_::botright, destroy_nodes(), free_choice(), match_table, memalloc(), NULL, NUM_MATCH_ENTRIES, and _MATCH_::rating.

Referenced by cc_recog(), and end_match_table().

00077                         {
00078   int x;
00079 
00080   if (been_initialized) {
00081     /* Reclaim old choices */
00082     for (x = 0; x < NUM_MATCH_ENTRIES; x++) {
00083       if ((!blank_entry (match_table, x)) && match_table[x].rating)
00084         destroy_nodes (match_table[x].rating, free_choice);
00085     }
00086   }
00087   else {
00088     /* Allocate memory once */
00089     been_initialized = 1;
00090     match_table = (MATCH *) memalloc (sizeof (MATCH) * NUM_MATCH_ENTRIES);
00091   }
00092   /* Initialize the table */
00093   for (x = 0; x < NUM_MATCH_ENTRIES; x++) {
00094     match_table[x].topleft = 0;
00095     match_table[x].botright = 0;
00096     match_table[x].rating = NULL;
00097   }
00098 }

void put_match ( TBLOB blob,
CHOICES  ratings 
)

Put a new blob and its corresponding match ratings into the match table.

Definition at line 114 of file matchtab.cpp.

References blank_entry, blob_bounding_box(), copy_choices(), cprintf(), match_table, NUM_MATCH_ENTRIES, and ratings.

00114                                              {
00115   unsigned int topleft;
00116   unsigned int botright;
00117   unsigned int start;
00118   TPOINT tp_topleft;
00119   TPOINT tp_botright;
00120   int x;
00121   /* Hash into table */
00122   blob_bounding_box(blob, &tp_topleft, &tp_botright);
00123   topleft = *(unsigned int *) &tp_topleft;
00124   botright = *(unsigned int *) &tp_botright;
00125   start = (topleft * botright) % NUM_MATCH_ENTRIES;
00126 
00127   /* Look for empty */
00128   x = start;
00129   do {
00130     if (blank_entry (match_table, x)) {
00131       /* Add this entry */
00132       match_table[x].topleft = topleft;
00133       match_table[x].botright = botright;
00134       match_table[x].rating = copy_choices (ratings);
00135       return;
00136     }
00137     if (++x >= NUM_MATCH_ENTRIES)
00138       x = 0;
00139   }
00140   while (x != start);
00141 
00142   cprintf ("error: Match table is full\n");
00143 }


Variable Documentation

int been_initialized = 0 [static]

Create and clear a match table to be used to speed up the splitter.

Definition at line 76 of file matchtab.cpp.

Referenced by end_match_table(), and init_match_table().

MATCH* match_table

Holds many ratings on blobs.

Definition at line 49 of file matchtab.cpp.

Referenced by end_match_table(), get_match_by_bounds(), init_match_table(), and put_match().


Generated on Wed Feb 28 19:49:28 2007 for Tesseract by  doxygen 1.5.1