Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cutoffs.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: cutoffs.c
3  ** Purpose: Routines to manipulate an array of class cutoffs.
4  ** Author: Dan Johnson
5  ** History: Wed Feb 20 09:28:51 1991, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
21 #include "cutoffs.h"
22 
23 #include <stdio.h>
24 
25 #include "classify.h"
26 #include "efio.h"
27 #include "globals.h"
28 #include "helpers.h"
29 #include "scanutils.h"
30 #include "serialis.h"
31 #include "unichar.h"
32 
33 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
34 
35 #define MAX_CUTOFF 1000
36 
40 /*---------------------------------------------------------------------------*/
41 namespace tesseract {
42 void Classify::ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset,
43  CLASS_CUTOFF_ARRAY Cutoffs) {
44 /*
45  ** Parameters:
46  ** Filename name of file containing cutoff definitions
47  ** Cutoffs array to put cutoffs into
48  ** Globals: none
49  ** Operation: Open Filename, read in all of the class-id/cutoff pairs
50  ** and insert them into the Cutoffs array. Cutoffs are
51  ** indexed in the array by class id. Unused entries in the
52  ** array are set to an arbitrarily high cutoff value.
53  ** Return: none
54  ** Exceptions: none
55  ** History: Wed Feb 20 09:38:26 1991, DSJ, Created.
56  */
57  char Class[UNICHAR_LEN + 1];
58  CLASS_ID ClassId;
59  int Cutoff;
60  int i;
61 
62  if (shape_table_ != NULL) {
63  if (!shapetable_cutoffs_.DeSerialize(swap, CutoffFile)) {
64  tprintf("Error during read of shapetable pffmtable!\n");
65  }
66  }
67  for (i = 0; i < MAX_NUM_CLASSES; i++)
68  Cutoffs[i] = MAX_CUTOFF;
69 
70  while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
71  fscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d",
72  Class, &Cutoff) == 2) {
73  if (strcmp(Class, "NULL") == 0) {
74  ClassId = unicharset.unichar_to_id(" ");
75  } else {
76  ClassId = unicharset.unichar_to_id(Class);
77  }
78  Cutoffs[ClassId] = Cutoff;
79  SkipNewline(CutoffFile);
80  }
81 } /* ReadNewCutoffs */
82 
83 } // namespace tesseract