aboutsummaryrefslogtreecommitdiff
path: root/classify/float2int.cpp
blob: b52237c740375efab6902d32e95f071631df3a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/******************************************************************************
 **	Filename:    float2int.c
 **	Purpose:     Routines for converting float features to int features
 **	Author:      Dan Johnson
 **	History:     Wed Mar 13 07:47:48 1991, DSJ, Created.
 **
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** 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.
 ******************************************************************************/
/**----------------------------------------------------------------------------
          Include Files and Type Defines
----------------------------------------------------------------------------**/
#include "float2int.h"
#include "normmatch.h"
#include "mfoutline.h"
#include "picofeat.h"

#define MAX_INT_CHAR_NORM (INT_CHAR_NORM_RANGE - 1)

/**----------------------------------------------------------------------------
              Public Code
----------------------------------------------------------------------------**/
/*---------------------------------------------------------------------------*/
void ClearCharNormArray(INT_TEMPLATES Templates,
                        CLASS_NORMALIZATION_ARRAY CharNormArray) {
/*
 **	Parameters:
 **		Templates	specifies classes currently defined
 **		CharNormArray	array to be cleared
 **	Globals: none
 **	Operation: For each class in Templates, clear the corresponding
 **		entry in CharNormArray.  CharNormArray is indexed by class
 **		indicies (as obtained from Templates) rather than class id's.
 **	Return: none
 **	Exceptions: none
 **	History: Wed Feb 20 11:20:54 1991, DSJ, Created.
 */
  int i;

  for (i = 0; i < NumClassesIn (Templates); i++) {
    CharNormArray[i] = 0;
  }

}                                /* ClearCharNormArray */


/*---------------------------------------------------------------------------*/
void ComputeIntCharNormArray(FEATURE NormFeature,
                             INT_TEMPLATES Templates,
                             CLASS_NORMALIZATION_ARRAY CharNormArray) {
/*
 **	Parameters:
 **		NormFeature	character normalization feature
 **		Templates	specifies classes currently defined
 **		CharNormArray	place to put results
 **	Globals: none
 **	Operation: For each class in Templates, compute the match between
 **		NormFeature and the normalization protos for that class.
 **		Convert this number to the range from 0 - 255 and store it
 **		into CharNormArray.  CharNormArray is indexed by class
 **		indicies (as obtained from Templates) rather than class id's.
 **	Return: none (results are returned in CharNormArray)
 **	Exceptions: none
 **	History: Wed Feb 20 11:20:54 1991, DSJ, Created.
 */
  int i;
  int NormAdjust;

  for (i = 0; i < NumClassesIn (Templates); i++) {
    NormAdjust = (int) (INT_CHAR_NORM_RANGE *
      ComputeNormMatch (i, NormFeature, FALSE));
    if (NormAdjust < 0)
      NormAdjust = 0;
    else if (NormAdjust > MAX_INT_CHAR_NORM)
      NormAdjust = MAX_INT_CHAR_NORM;

    CharNormArray[i] = NormAdjust;
  }

}                                /* ComputeIntCharNormArray */


/*---------------------------------------------------------------------------*/
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures) {
/*
 **	Parameters:
 **		Features	floating point pico-features to be converted
 **		IntFeatures	array to put converted features into
 **	Globals: none
 **	Operation: This routine converts each floating point pico-feature
 **		in Features into integer format and saves it into
 **		IntFeatures.
 **	Return: none (results are returned in IntFeatures)
 **	Exceptions: none
 **	History: Wed Feb 20 10:58:45 1991, DSJ, Created.
 */
  int Fid;
  FEATURE Feature;
  FLOAT32 YShift;

  if (NormMethod == baseline)
    YShift = BASELINE_Y_SHIFT;
  else
    YShift = Y_SHIFT;

  for (Fid = 0; Fid < NumFeaturesIn (Features); Fid++) {
    Feature = FeatureIn (Features, Fid);

    IntFeatures[Fid].X = BucketFor (ParamOf (Feature, PicoFeatX),
      X_SHIFT, INT_FEAT_RANGE);
    IntFeatures[Fid].Y = BucketFor (ParamOf (Feature, PicoFeatY),
      YShift, INT_FEAT_RANGE);
    IntFeatures[Fid].Theta = CircBucketFor (ParamOf (Feature, PicoFeatDir),
      ANGLE_SHIFT, INT_FEAT_RANGE);
    IntFeatures[Fid].CP_misses = 0;
  }
}                                /* ComputeIntFeatures */