tesseract  3.04.00
intproto.cpp File Reference
#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "classify.h"
#include "const.h"
#include "emalloc.h"
#include "fontinfo.h"
#include "genericvector.h"
#include "globals.h"
#include "helpers.h"
#include "intproto.h"
#include "mfoutline.h"
#include "ndminx.h"
#include "picofeat.h"
#include "points.h"
#include "shapetable.h"
#include "svmnode.h"

Go to the source code of this file.

Classes

struct  FILL_SWITCH
 
struct  TABLE_FILLER
 
struct  FILL_SPEC
 

Namespaces

 tesseract
 

Macros

#define PROTO_PRUNER_SCALE   (4.0)
 
#define INT_DESCENDER   (0.0 * INT_CHAR_NORM_RANGE)
 
#define INT_BASELINE   (0.25 * INT_CHAR_NORM_RANGE)
 
#define INT_XHEIGHT   (0.75 * INT_CHAR_NORM_RANGE)
 
#define INT_CAPHEIGHT   (1.0 * INT_CHAR_NORM_RANGE)
 
#define INT_XCENTER   (0.5 * INT_CHAR_NORM_RANGE)
 
#define INT_YCENTER   (0.5 * INT_CHAR_NORM_RANGE)
 
#define INT_XRADIUS   (0.2 * INT_CHAR_NORM_RANGE)
 
#define INT_YRADIUS   (0.2 * INT_CHAR_NORM_RANGE)
 
#define INT_MIN_X   0
 
#define INT_MIN_Y   0
 
#define INT_MAX_X   INT_CHAR_NORM_RANGE
 
#define INT_MAX_Y   INT_CHAR_NORM_RANGE
 
#define HV_TOLERANCE   (0.0025) /* approx 0.9 degrees */
 
#define MAX_NUM_SWITCHES   3
 
#define OLD_MAX_NUM_CONFIGS   32
 
#define OLD_WERDS_PER_CONFIG_VEC
 
#define CircularIncrement(i, r)   (((i) < (r) - 1)?((i)++):((i) = 0))
 
#define MapParam(P, O, N)    (floor (((P) + (O)) * (N)))
 
#define MAX_LEVEL   2
 
#define XS   X_SHIFT
 
#define YS   Y_SHIFT
 
#define AS   ANGLE_SHIFT
 
#define NB   NUM_CP_BUCKETS
 

Enumerations

enum  SWITCH_TYPE { StartSwitch, EndSwitch, LastSwitch }
 

Functions

FLOAT32 BucketStart (int Bucket, FLOAT32 Offset, int NumBuckets)
 
FLOAT32 BucketEnd (int Bucket, FLOAT32 Offset, int NumBuckets)
 
void DoFill (FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, register uinT32 ClassMask, register uinT32 ClassCount, register uinT32 WordIndex)
 
BOOL8 FillerDone (TABLE_FILLER *Filler)
 
void FillPPCircularBits (uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
 
void FillPPLinearBits (uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
 
void GetCPPadsForLevel (int Level, FLOAT32 *EndPad, FLOAT32 *SidePad, FLOAT32 *AnglePad)
 
ScrollView::Color GetMatchColorFor (FLOAT32 Evidence)
 
void GetNextFill (TABLE_FILLER *Filler, FILL_SPEC *Fill)
 
void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad, FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER *Filler)
 
void RenderIntFeature (ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
 
void RenderIntProto (ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
 
int TruncateParam (FLOAT32 Param, int Min, int Max, char *Id)
 
void AddIntClass (INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
 
int AddIntConfig (INT_CLASS Class)
 
int AddIntProto (INT_CLASS Class)
 
void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
 
void AddProtoToProtoPruner (PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
 
uinT8 Bucket8For (FLOAT32 param, FLOAT32 offset, int num_buckets)
 
uinT16 Bucket16For (FLOAT32 param, FLOAT32 offset, int num_buckets)
 
uinT8 CircBucketFor (FLOAT32 param, FLOAT32 offset, int num_buckets)
 
void UpdateMatchDisplay ()
 
void ConvertConfig (BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
 
void DisplayIntFeature (const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence)
 
void DisplayIntProto (INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence)
 
INT_CLASS NewIntClass (int MaxNumProtos, int MaxNumConfigs)
 
void free_int_class (INT_CLASS int_class)
 
INT_TEMPLATES NewIntTemplates ()
 
void free_int_templates (INT_TEMPLATES templates)
 
void tesseract::ClearFeatureSpaceWindow (NORM_METHOD norm_method, ScrollView *window)
 
void InitIntMatchWindowIfReqd ()
 
void InitProtoDisplayWindowIfReqd ()
 
void InitFeatureDisplayWindowIfReqd ()
 
ScrollViewCreateFeatureSpaceWindow (const char *name, int xpos, int ypos)
 

Variables

ScrollViewIntMatchWindow = NULL
 
ScrollViewFeatureDisplayWindow = NULL
 
ScrollViewProtoDisplayWindow = NULL
 
int classify_num_cp_levels = 3
 
double classify_cp_angle_pad_loose = 45.0
 
double classify_cp_angle_pad_medium = 20.0
 
double classify_cp_angle_pad_tight = 10.0
 
double classify_cp_end_pad_loose = 0.5
 
double classify_cp_end_pad_medium = 0.5
 
double classify_cp_end_pad_tight = 0.5
 
double classify_cp_side_pad_loose = 2.5
 
double classify_cp_side_pad_medium = 1.2
 
double classify_cp_side_pad_tight = 0.6
 
double classify_pp_angle_pad = 45.0
 
double classify_pp_end_pad = 0.5
 
double classify_pp_side_pad = 2.5
 

Macro Definition Documentation

#define AS   ANGLE_SHIFT
#define CircularIncrement (   i,
 
)    (((i) < (r) - 1)?((i)++):((i) = 0))

macro for performing circular increments of bucket indices

Definition at line 122 of file intproto.cpp.

#define HV_TOLERANCE   (0.0025) /* approx 0.9 degrees */

define pad used to snap near horiz/vertical protos to horiz/vertical

Definition at line 71 of file intproto.cpp.

#define INT_BASELINE   (0.25 * INT_CHAR_NORM_RANGE)

Definition at line 57 of file intproto.cpp.

#define INT_CAPHEIGHT   (1.0 * INT_CHAR_NORM_RANGE)

Definition at line 59 of file intproto.cpp.

#define INT_DESCENDER   (0.0 * INT_CHAR_NORM_RANGE)

Definition at line 56 of file intproto.cpp.

#define INT_MAX_X   INT_CHAR_NORM_RANGE

Definition at line 67 of file intproto.cpp.

#define INT_MAX_Y   INT_CHAR_NORM_RANGE

Definition at line 68 of file intproto.cpp.

#define INT_MIN_X   0

Definition at line 65 of file intproto.cpp.

#define INT_MIN_Y   0

Definition at line 66 of file intproto.cpp.

#define INT_XCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 61 of file intproto.cpp.

#define INT_XHEIGHT   (0.75 * INT_CHAR_NORM_RANGE)

Definition at line 58 of file intproto.cpp.

#define INT_XRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 63 of file intproto.cpp.

#define INT_YCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 62 of file intproto.cpp.

#define INT_YRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 64 of file intproto.cpp.

#define MapParam (   P,
  O,
 
)    (floor (((P) + (O)) * (N)))

macro for mapping floats to ints without bounds checking

Definition at line 125 of file intproto.cpp.

#define MAX_LEVEL   2
#define MAX_NUM_SWITCHES   3

Definition at line 76 of file intproto.cpp.

#define NB   NUM_CP_BUCKETS
#define OLD_MAX_NUM_CONFIGS   32

Definition at line 114 of file intproto.cpp.

#define OLD_WERDS_PER_CONFIG_VEC
Value:
#define BITS_PER_WERD
Definition: intproto.h:44
#define OLD_MAX_NUM_CONFIGS
Definition: intproto.cpp:114

Definition at line 115 of file intproto.cpp.

#define PROTO_PRUNER_SCALE   (4.0)

Definition at line 54 of file intproto.cpp.

#define XS   X_SHIFT
#define YS   Y_SHIFT

Enumeration Type Documentation

Enumerator
StartSwitch 
EndSwitch 
LastSwitch 

Definition at line 73 of file intproto.cpp.

Function Documentation

void AddIntClass ( INT_TEMPLATES  Templates,
CLASS_ID  ClassId,
INT_CLASS  Class 
)

This routine adds a new class structure to a set of templates. Classes have to be added to Templates in the order of increasing ClassIds.

Parameters
Templatestemplates to add new class to
ClassIdclass id to associate new class with
Classclass data structure to add to templates

Globals: none

Note
Exceptions: none
History: Mon Feb 11 11:52:08 1991, DSJ, Created.

Definition at line 241 of file intproto.cpp.

241  {
242  int Pruner;
243 
244  assert (LegalClassId (ClassId));
245  if (ClassId != Templates->NumClasses) {
246  fprintf(stderr, "Please make sure that classes are added to templates");
247  fprintf(stderr, " in increasing order of ClassIds\n");
248  exit(1);
249  }
250  ClassForClassId (Templates, ClassId) = Class;
251  Templates->NumClasses++;
252 
253  if (Templates->NumClasses > MaxNumClassesIn (Templates)) {
254  Pruner = Templates->NumClassPruners++;
255  Templates->ClassPruners[Pruner] = new CLASS_PRUNER_STRUCT;
256  memset(Templates->ClassPruners[Pruner], 0, sizeof(CLASS_PRUNER_STRUCT));
257  }
258 } /* AddIntClass */
#define LegalClassId(c)
Definition: intproto.h:179
#define MaxNumClassesIn(T)
Definition: intproto.h:178
#define ClassForClassId(T, c)
Definition: intproto.h:181
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:125
int AddIntConfig ( INT_CLASS  Class)

This routine returns the index of the next free config in Class.

Parameters
Classclass to add new configuration to

Globals: none

Returns
Index of next free config.
Note
Exceptions: none
History: Mon Feb 11 14:44:40 1991, DSJ, Created.

Definition at line 274 of file intproto.cpp.

274  {
275  int Index;
276 
277  assert(Class->NumConfigs < MAX_NUM_CONFIGS);
278 
279  Index = Class->NumConfigs++;
280  Class->ConfigLengths[Index] = 0;
281  return Index;
282 } /* AddIntConfig */
#define MAX_NUM_CONFIGS
Definition: intproto.h:46
uinT16 ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:113
uinT8 NumConfigs
Definition: intproto.h:110
int AddIntProto ( INT_CLASS  Class)

This routine allocates the next free proto in Class and returns its index.

Parameters
Classclass to add new proto to

Globals: none

Returns
Proto index of new proto.
Note
Exceptions: none
History: Mon Feb 11 13:26:41 1991, DSJ, Created.

Definition at line 298 of file intproto.cpp.

298  {
299  int Index;
300  int ProtoSetId;
301  PROTO_SET ProtoSet;
302  INT_PROTO Proto;
303  register uinT32 *Word;
304 
305  if (Class->NumProtos >= MAX_NUM_PROTOS)
306  return (NO_PROTO);
307 
308  Index = Class->NumProtos++;
309 
310  if (Class->NumProtos > MaxNumIntProtosIn(Class)) {
311  ProtoSetId = Class->NumProtoSets++;
312 
313  ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
314  Class->ProtoSets[ProtoSetId] = ProtoSet;
315  memset(ProtoSet, 0, sizeof(*ProtoSet));
316 
317  /* reallocate space for the proto lengths and install in class */
318  Class->ProtoLengths =
319  (uinT8 *)Erealloc(Class->ProtoLengths,
320  MaxNumIntProtosIn(Class) * sizeof(uinT8));
321  memset(&Class->ProtoLengths[Index], 0,
322  sizeof(*Class->ProtoLengths) * (MaxNumIntProtosIn(Class) - Index));
323  }
324 
325  /* initialize proto so its length is zero and it isn't in any configs */
326  Class->ProtoLengths[Index] = 0;
327  Proto = ProtoForProtoId (Class, Index);
328  for (Word = Proto->Configs;
329  Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);
330 
331  return (Index);
332 
333 } /* AddIntProto */
uinT32 Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:86
uinT8 NumProtoSets
Definition: intproto.h:109
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68
unsigned int uinT32
Definition: host.h:103
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:70
#define MaxNumIntProtosIn(C)
Definition: intproto.h:168
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:111
#define ProtoForProtoId(C, P)
Definition: intproto.h:171
uinT16 NumProtos
Definition: intproto.h:108
struct PROTO_SET_STRUCT * PROTO_SET
void * Emalloc(int Size)
Definition: emalloc.cpp:35
#define NO_PROTO
Definition: matchdefs.h:42
unsigned char uinT8
Definition: host.h:99
#define MAX_NUM_PROTOS
Definition: intproto.h:47
uinT8 * ProtoLengths
Definition: intproto.h:112
void AddProtoToClassPruner ( PROTO  Proto,
CLASS_ID  ClassId,
INT_TEMPLATES  Templates 
)

Definition at line 337 of file intproto.cpp.

353 {
354  CLASS_PRUNER_STRUCT* Pruner;
355  uinT32 ClassMask;
356  uinT32 ClassCount;
357  uinT32 WordIndex;
358  int Level;
359  FLOAT32 EndPad, SidePad, AnglePad;
360  TABLE_FILLER TableFiller;
361  FILL_SPEC FillSpec;
362 
363  Pruner = CPrunerFor (Templates, ClassId);
364  WordIndex = CPrunerWordIndexFor (ClassId);
365  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassId);
366 
367  for (Level = classify_num_cp_levels - 1; Level >= 0; Level--) {
368  GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);
369  ClassCount = CPrunerMaskFor (Level, ClassId);
370  InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);
371 
372  while (!FillerDone (&TableFiller)) {
373  GetNextFill(&TableFiller, &FillSpec);
374  DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
375  }
376  }
377 } /* AddProtoToClassPruner */
BOOL8 FillerDone(TABLE_FILLER *Filler)
Definition: intproto.cpp:1314
void GetCPPadsForLevel(int Level, FLOAT32 *EndPad, FLOAT32 *SidePad, FLOAT32 *AnglePad)
Definition: intproto.cpp:1498
#define MAX_LEVEL
unsigned int uinT32
Definition: host.h:103
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
Definition: intproto.cpp:1576
#define CPrunerWordIndexFor(c)
Definition: intproto.h:185
#define CPrunerFor(T, c)
Definition: intproto.h:184
int classify_num_cp_levels
Definition: intproto.cpp:190
void InitTableFiller(FLOAT32 EndPad, FLOAT32 SidePad, FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER *Filler)
Definition: intproto.cpp:1644
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, register uinT32 ClassMask, register uinT32 ClassCount, register uinT32 WordIndex)
Definition: intproto.cpp:1264
#define CPrunerMaskFor(L, c)
Definition: intproto.h:187
float FLOAT32
Definition: host.h:111
void AddProtoToProtoPruner ( PROTO  Proto,
int  ProtoId,
INT_CLASS  Class,
bool  debug 
)

Definition at line 381 of file intproto.cpp.

382  {
383 /*
384  ** Parameters:
385  ** Proto floating-pt proto to be added to proto pruner
386  ** ProtoId id of proto
387  ** Class integer class that contains desired proto pruner
388  ** Globals: none
389  ** Operation: This routine updates the proto pruner lookup tables
390  ** for Class to include a new proto identified by ProtoId
391  ** and described by Proto.
392  ** Return: none
393  ** Exceptions: none
394  ** History: Fri Feb 8 13:07:19 1991, DSJ, Created.
395  */
396  FLOAT32 Angle, X, Y, Length;
397  FLOAT32 Pad;
398  int Index;
399  PROTO_SET ProtoSet;
400 
401  if (ProtoId >= Class->NumProtos)
402  cprintf("AddProtoToProtoPruner:assert failed: %d < %d",
403  ProtoId, Class->NumProtos);
404  assert(ProtoId < Class->NumProtos);
405 
406  Index = IndexForProto (ProtoId);
407  ProtoSet = Class->ProtoSets[SetForProto (ProtoId)];
408 
409  Angle = Proto->Angle;
410 #ifndef _WIN32
411  assert(!isnan(Angle));
412 #endif
413 
414  FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index,
415  Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
416  debug);
417 
418  Angle *= 2.0 * PI;
419  Length = Proto->Length;
420 
421  X = Proto->X + X_SHIFT;
422  Pad = MAX (fabs (cos (Angle)) * (Length / 2.0 +
425  fabs (sin (Angle)) * (classify_pp_side_pad *
427 
428  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);
429 
430  Y = Proto->Y + Y_SHIFT;
431  Pad = MAX (fabs (sin (Angle)) * (Length / 2.0 +
434  fabs (cos (Angle)) * (classify_pp_side_pad *
436 
437  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);
438 } /* AddProtoToProtoPruner */
#define X_SHIFT
Definition: intproto.h:40
#define Y_SHIFT
Definition: intproto.h:41
double classify_pp_end_pad
Definition: intproto.cpp:204
double classify_pp_angle_pad
Definition: intproto.cpp:203
void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
Definition: intproto.cpp:1382
FLOAT32 Y
Definition: protos.h:48
#define MAX(x, y)
Definition: ndminx.h:24
#define PRUNER_Y
Definition: intproto.h:35
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
#define isnan(x)
Definition: mathfix.h:31
#define PRUNER_ANGLE
Definition: intproto.h:36
#define IndexForProto(P)
Definition: intproto.h:170
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:111
FLOAT32 X
Definition: protos.h:47
#define PI
Definition: const.h:19
#define SetForProto(P)
Definition: intproto.h:169
FLOAT32 Length
Definition: protos.h:50
FLOAT32 Angle
Definition: protos.h:49
#define PRUNER_X
Definition: intproto.h:34
#define GetPicoFeatureLength()
Definition: picofeat.h:59
double classify_pp_side_pad
Definition: intproto.cpp:205
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
uinT16 NumProtos
Definition: intproto.h:108
void FillPPCircularBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
Definition: intproto.cpp:1338
#define ANGLE_SHIFT
Definition: intproto.h:39
float FLOAT32
Definition: host.h:111
uinT16 Bucket16For ( FLOAT32  param,
FLOAT32  offset,
int  num_buckets 
)

Definition at line 449 of file intproto.cpp.

449  {
450  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
451  return static_cast<uinT16>(ClipToRange(bucket, 0, num_buckets - 1));
452 }
int IntCastRounded(double x)
Definition: helpers.h:172
#define MapParam(P, O, N)
Definition: intproto.cpp:125
unsigned short uinT16
Definition: host.h:101
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
uinT8 Bucket8For ( FLOAT32  param,
FLOAT32  offset,
int  num_buckets 
)

Definition at line 445 of file intproto.cpp.

445  {
446  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
447  return static_cast<uinT8>(ClipToRange(bucket, 0, num_buckets - 1));
448 }
int IntCastRounded(double x)
Definition: helpers.h:172
#define MapParam(P, O, N)
Definition: intproto.cpp:125
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
unsigned char uinT8
Definition: host.h:99
FLOAT32 BucketEnd ( int  Bucket,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 1244 of file intproto.cpp.

1244  {
1245 /*
1246  ** Parameters:
1247  ** Bucket bucket whose end is to be computed
1248  ** Offset offset used to map params to buckets
1249  ** NumBuckets total number of buckets
1250  ** Globals: none
1251  ** Operation: This routine returns the parameter value which
1252  ** corresponds to the end of the specified bucket.
1253  ** The bucket number should have been generated using the
1254  ** BucketFor() function with parameters Offset and NumBuckets.
1255  ** Return: Param value corresponding to end position of Bucket.
1256  ** Exceptions: none
1257  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
1258  */
1259  return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
1260 } /* BucketEnd */
USHORT Offset
Definition: GlyphLessFont.h:26
float FLOAT32
Definition: host.h:111
FLOAT32 BucketStart ( int  Bucket,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 1223 of file intproto.cpp.

1223  {
1224 /*
1225  ** Parameters:
1226  ** Bucket bucket whose start is to be computed
1227  ** Offset offset used to map params to buckets
1228  ** NumBuckets total number of buckets
1229  ** Globals: none
1230  ** Operation: This routine returns the parameter value which
1231  ** corresponds to the beginning of the specified bucket.
1232  ** The bucket number should have been generated using the
1233  ** BucketFor() function with parameters Offset and NumBuckets.
1234  ** Return: Param value corresponding to start position of Bucket.
1235  ** Exceptions: none
1236  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
1237  */
1238  return (((FLOAT32) Bucket / NumBuckets) - Offset);
1239 
1240 } /* BucketStart */
USHORT Offset
Definition: GlyphLessFont.h:26
float FLOAT32
Definition: host.h:111
uinT8 CircBucketFor ( FLOAT32  param,
FLOAT32  offset,
int  num_buckets 
)

Definition at line 458 of file intproto.cpp.

458  {
459  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
460  return static_cast<uinT8>(Modulo(bucket, num_buckets));
461 } /* CircBucketFor */
int IntCastRounded(double x)
Definition: helpers.h:172
#define MapParam(P, O, N)
Definition: intproto.cpp:125
int Modulo(int a, int b)
Definition: helpers.h:157
unsigned char uinT8
Definition: host.h:99
void ConvertConfig ( BIT_VECTOR  Config,
int  ConfigId,
INT_CLASS  Class 
)

Definition at line 484 of file intproto.cpp.

484  {
485 /*
486  ** Parameters:
487  ** Config config to be added to class
488  ** ConfigId id to be used for new config
489  ** Class class to add new config to
490  ** Globals: none
491  ** Operation: This operation updates the config vectors of all protos
492  ** in Class to indicate that the protos with 1's in Config
493  ** belong to a new configuration identified by ConfigId.
494  ** It is assumed that the length of the Config bit vector is
495  ** equal to the number of protos in Class.
496  ** Return: none
497  ** Exceptions: none
498  ** History: Mon Feb 11 14:57:31 1991, DSJ, Created.
499  */
500  int ProtoId;
501  INT_PROTO Proto;
502  int TotalLength;
503 
504  for (ProtoId = 0, TotalLength = 0;
505  ProtoId < Class->NumProtos; ProtoId++) {
506  if (test_bit(Config, ProtoId)) {
507  Proto = ProtoForProtoId(Class, ProtoId);
508  SET_BIT(Proto->Configs, ConfigId);
509  TotalLength += Class->ProtoLengths[ProtoId];
510  }
511  }
512  Class->ConfigLengths[ConfigId] = TotalLength;
513 } /* ConvertConfig */
uinT32 Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:86
#define SET_BIT(array, bit)
Definition: bitvec.h:57
CLUSTERCONFIG Config
#define ProtoForProtoId(C, P)
Definition: intproto.h:171
uinT16 ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:113
uinT16 NumProtos
Definition: intproto.h:108
#define test_bit(array, bit)
Definition: bitvec.h:61
uinT8 * ProtoLengths
Definition: intproto.h:112
ScrollView* CreateFeatureSpaceWindow ( const char *  name,
int  xpos,
int  ypos 
)

Definition at line 1976 of file intproto.cpp.

1976  {
1977  return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
1978 }
name_table name
void DisplayIntFeature ( const INT_FEATURE_STRUCT Feature,
FLOAT32  Evidence 
)

Definition at line 628 of file intproto.cpp.

628  {
629 /*
630  ** Parameters:
631  ** Feature pico-feature to be displayed
632  ** Evidence best evidence for this feature (0-1)
633  ** Globals:
634  ** FeatureShapes global display list for features
635  ** Operation: This routine renders the specified feature into a
636  ** global display list.
637  ** Return: none
638  ** Exceptions: none
639  ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
640  */
641  ScrollView::Color color = GetMatchColorFor(Evidence);
642  RenderIntFeature(IntMatchWindow, Feature, color);
643  if (FeatureDisplayWindow) {
644  RenderIntFeature(FeatureDisplayWindow, Feature, color);
645  }
646 } /* DisplayIntFeature */
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence)
Definition: intproto.cpp:1550
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:182
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1808
ScrollView * IntMatchWindow
Definition: intproto.cpp:181
void DisplayIntProto ( INT_CLASS  Class,
PROTO_ID  ProtoId,
FLOAT32  Evidence 
)

Definition at line 650 of file intproto.cpp.

650  {
651 /*
652  ** Parameters:
653  ** Class class to take proto from
654  ** ProtoId id of proto in Class to be displayed
655  ** Evidence total evidence for proto (0-1)
656  ** Globals:
657  ** ProtoShapes global display list for protos
658  ** Operation: This routine renders the specified proto into a
659  ** global display list.
660  ** Return: none
661  ** Exceptions: none
662  ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
663  */
664  ScrollView::Color color = GetMatchColorFor(Evidence);
665  RenderIntProto(IntMatchWindow, Class, ProtoId, color);
666  if (ProtoDisplayWindow) {
667  RenderIntProto(ProtoDisplayWindow, Class, ProtoId, color);
668  }
669 } /* DisplayIntProto */
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence)
Definition: intproto.cpp:1550
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
Definition: intproto.cpp:1845
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:183
ScrollView * IntMatchWindow
Definition: intproto.cpp:181
void DoFill ( FILL_SPEC FillSpec,
CLASS_PRUNER_STRUCT Pruner,
register uinT32  ClassMask,
register uinT32  ClassCount,
register uinT32  WordIndex 
)

Definition at line 1264 of file intproto.cpp.

1268  {
1269 /*
1270  ** Parameters:
1271  ** FillSpec specifies which bits to fill in pruner
1272  ** Pruner class pruner to be filled
1273  ** ClassMask indicates which bits to change in each word
1274  ** ClassCount indicates what to change bits to
1275  ** WordIndex indicates which word to change
1276  ** Globals: none
1277  ** Operation: This routine fills in the section of a class pruner
1278  ** corresponding to a single x value for a single proto of
1279  ** a class.
1280  ** Return: none
1281  ** Exceptions: none
1282  ** History: Tue Feb 19 11:11:29 1991, DSJ, Created.
1283  */
1284  register int X, Y, Angle;
1285  register uinT32 OldWord;
1286 
1287  X = FillSpec->X;
1288  if (X < 0)
1289  X = 0;
1290  if (X >= NUM_CP_BUCKETS)
1291  X = NUM_CP_BUCKETS - 1;
1292 
1293  if (FillSpec->YStart < 0)
1294  FillSpec->YStart = 0;
1295  if (FillSpec->YEnd >= NUM_CP_BUCKETS)
1296  FillSpec->YEnd = NUM_CP_BUCKETS - 1;
1297 
1298  for (Y = FillSpec->YStart; Y <= FillSpec->YEnd; Y++)
1299  for (Angle = FillSpec->AngleStart;
1301  OldWord = Pruner->p[X][Y][Angle][WordIndex];
1302  if (ClassCount > (OldWord & ClassMask)) {
1303  OldWord &= ~ClassMask;
1304  OldWord |= ClassCount;
1305  Pruner->p[X][Y][Angle][WordIndex] = OldWord;
1306  }
1307  if (Angle == FillSpec->AngleEnd)
1308  break;
1309  }
1310 } /* DoFill */
inT8 YEnd
Definition: intproto.cpp:105
uinT32 p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:77
uinT8 AngleStart
Definition: intproto.cpp:106
unsigned int uinT32
Definition: host.h:103
#define NUM_CP_BUCKETS
Definition: intproto.h:52
uinT8 AngleEnd
Definition: intproto.cpp:106
inT8 YStart
Definition: intproto.cpp:105
#define TRUE
Definition: capi.h:28
#define CircularIncrement(i, r)
Definition: intproto.cpp:122
BOOL8 FillerDone ( TABLE_FILLER Filler)

Definition at line 1314 of file intproto.cpp.

1314  {
1315 /*
1316  ** Parameters:
1317  ** Filler table filler to check if done
1318  ** Globals: none
1319  ** Operation: Return TRUE if the specified table filler is done, i.e.
1320  ** if it has no more lines to fill.
1321  ** Return: TRUE if no more lines to fill, FALSE otherwise.
1322  ** Exceptions: none
1323  ** History: Tue Feb 19 10:08:05 1991, DSJ, Created.
1324  */
1325  FILL_SWITCH *Next;
1326 
1327  Next = &(Filler->Switch[Filler->NextSwitch]);
1328 
1329  if (Filler->X > Next->X && Next->Type == LastSwitch)
1330  return (TRUE);
1331  else
1332  return (FALSE);
1333 
1334 } /* FillerDone */
uinT8 NextSwitch
Definition: intproto.cpp:91
#define FALSE
Definition: capi.h:29
SWITCH_TYPE Type
Definition: intproto.cpp:80
#define TRUE
Definition: capi.h:28
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:96
void FillPPCircularBits ( uinT32  ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int  Bit,
FLOAT32  Center,
FLOAT32  Spread,
bool  debug 
)

Definition at line 1338 of file intproto.cpp.

1339  {
1340 /*
1341  ** Parameters:
1342  ** ParamTable table of bit vectors, one per param bucket
1343  ** Bit bit position in vectors to be filled
1344  ** Center center of filled area
1345  ** Spread spread of filled area
1346  ** Globals: none
1347  ** Operation: This routine sets Bit in each bit vector whose
1348  ** bucket lies within the range Center +- Spread. The fill
1349  ** is done for a circular dimension, i.e. bucket 0 is adjacent
1350  ** to the last bucket. It is assumed that Center and Spread
1351  ** are expressed in a circular coordinate system whose range
1352  ** is 0 to 1.
1353  ** Return: none
1354  ** Exceptions: none
1355  ** History: Tue Oct 16 09:26:54 1990, DSJ, Created.
1356  */
1357  int i, FirstBucket, LastBucket;
1358 
1359  if (Spread > 0.5)
1360  Spread = 0.5;
1361 
1362  FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS);
1363  if (FirstBucket < 0)
1364  FirstBucket += NUM_PP_BUCKETS;
1365 
1366  LastBucket = (int) floor ((Center + Spread) * NUM_PP_BUCKETS);
1367  if (LastBucket >= NUM_PP_BUCKETS)
1368  LastBucket -= NUM_PP_BUCKETS;
1369  if (debug) tprintf("Circular fill from %d to %d", FirstBucket, LastBucket);
1370  for (i = FirstBucket; TRUE; CircularIncrement (i, NUM_PP_BUCKETS)) {
1371  SET_BIT (ParamTable[i], Bit);
1372 
1373  /* exit loop after we have set the bit for the last bucket */
1374  if (i == LastBucket)
1375  break;
1376  }
1377 
1378 } /* FillPPCircularBits */
#define SET_BIT(array, bit)
Definition: bitvec.h:57
#define tprintf(...)
Definition: tprintf.h:31
#define NUM_PP_BUCKETS
Definition: intproto.h:51
#define TRUE
Definition: capi.h:28
#define CircularIncrement(i, r)
Definition: intproto.cpp:122
void FillPPLinearBits ( uinT32  ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int  Bit,
FLOAT32  Center,
FLOAT32  Spread,
bool  debug 
)

Definition at line 1382 of file intproto.cpp.

1383  {
1384 /*
1385  ** Parameters:
1386  ** ParamTable table of bit vectors, one per param bucket
1387  ** Bit bit number being filled
1388  ** Center center of filled area
1389  ** Spread spread of filled area
1390  ** Globals: none
1391  ** Operation: This routine sets Bit in each bit vector whose
1392  ** bucket lies within the range Center +- Spread. The fill
1393  ** is done for a linear dimension, i.e. there is no wrap-around
1394  ** for this dimension. It is assumed that Center and Spread
1395  ** are expressed in a linear coordinate system whose range
1396  ** is approximately 0 to 1. Values outside this range will
1397  ** be clipped.
1398  ** Return: none
1399  ** Exceptions: none
1400  ** History: Tue Oct 16 09:26:54 1990, DSJ, Created.
1401  */
1402  int i, FirstBucket, LastBucket;
1403 
1404  FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS);
1405  if (FirstBucket < 0)
1406  FirstBucket = 0;
1407 
1408  LastBucket = (int) floor ((Center + Spread) * NUM_PP_BUCKETS);
1409  if (LastBucket >= NUM_PP_BUCKETS)
1410  LastBucket = NUM_PP_BUCKETS - 1;
1411 
1412  if (debug) tprintf("Linear fill from %d to %d", FirstBucket, LastBucket);
1413  for (i = FirstBucket; i <= LastBucket; i++)
1414  SET_BIT (ParamTable[i], Bit);
1415 
1416 } /* FillPPLinearBits */
#define SET_BIT(array, bit)
Definition: bitvec.h:57
#define tprintf(...)
Definition: tprintf.h:31
#define NUM_PP_BUCKETS
Definition: intproto.h:51
void free_int_class ( INT_CLASS  int_class)

Definition at line 725 of file intproto.cpp.

725  {
726  int i;
727 
728  for (i = 0; i < int_class->NumProtoSets; i++) {
729  Efree (int_class->ProtoSets[i]);
730  }
731  if (int_class->ProtoLengths != NULL) {
732  Efree (int_class->ProtoLengths);
733  }
734  Efree(int_class);
735 }
uinT8 NumProtoSets
Definition: intproto.h:109
#define NULL
Definition: host.h:144
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:111
void Efree(void *ptr)
Definition: emalloc.cpp:85
uinT8 * ProtoLengths
Definition: intproto.h:112
void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 764 of file intproto.cpp.

764  {
765  int i;
766 
767  for (i = 0; i < templates->NumClasses; i++)
768  free_int_class(templates->Class[i]);
769  for (i = 0; i < templates->NumClassPruners; i++)
770  delete templates->ClassPruners[i];
771  Efree(templates);
772 }
void free_int_class(INT_CLASS int_class)
Definition: intproto.cpp:725
INT_CLASS Class[MAX_NUM_CLASSES]
Definition: intproto.h:124
void Efree(void *ptr)
Definition: emalloc.cpp:85
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:125
void GetCPPadsForLevel ( int  Level,
FLOAT32 EndPad,
FLOAT32 SidePad,
FLOAT32 AnglePad 
)

Definition at line 1498 of file intproto.cpp.

1501  {
1502 /*
1503  ** Parameters:
1504  ** Level "tightness" level to return pads for
1505  ** EndPad place to put end pad for Level
1506  ** SidePad place to put side pad for Level
1507  ** AnglePad place to put angle pad for Level
1508  ** Globals: none
1509  ** Operation: This routine copies the appropriate global pad variables
1510  ** into EndPad, SidePad, and AnglePad. This is a kludge used
1511  ** to get around the fact that global control variables cannot
1512  ** be arrays. If the specified level is illegal, the tightest
1513  ** possible pads are returned.
1514  ** Return: none (results are returned in EndPad, SidePad, and AnglePad.
1515  ** Exceptions: none
1516  ** History: Thu Feb 14 08:26:49 1991, DSJ, Created.
1517  */
1518  switch (Level) {
1519  case 0:
1522  *AnglePad = classify_cp_angle_pad_loose / 360.0;
1523  break;
1524 
1525  case 1:
1528  *AnglePad = classify_cp_angle_pad_medium / 360.0;
1529  break;
1530 
1531  case 2:
1534  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1535  break;
1536 
1537  default:
1540  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1541  break;
1542  }
1543  if (*AnglePad > 0.5)
1544  *AnglePad = 0.5;
1545 
1546 } /* GetCPPadsForLevel */
double classify_cp_end_pad_loose
Definition: intproto.cpp:197
double classify_cp_angle_pad_medium
Definition: intproto.cpp:194
double classify_cp_angle_pad_tight
Definition: intproto.cpp:196
double classify_cp_angle_pad_loose
Definition: intproto.cpp:192
double classify_cp_end_pad_medium
Definition: intproto.cpp:198
#define GetPicoFeatureLength()
Definition: picofeat.h:59
double classify_cp_side_pad_tight
Definition: intproto.cpp:202
double classify_cp_side_pad_loose
Definition: intproto.cpp:200
double classify_cp_end_pad_tight
Definition: intproto.cpp:199
double classify_cp_side_pad_medium
Definition: intproto.cpp:201
ScrollView::Color GetMatchColorFor ( FLOAT32  Evidence)

Definition at line 1550 of file intproto.cpp.

1550  {
1551 /*
1552  ** Parameters:
1553  ** Evidence evidence value to return color for
1554  ** Globals: none
1555  ** Operation:
1556  ** Return: Color which corresponds to specified Evidence value.
1557  ** Exceptions: none
1558  ** History: Thu Mar 21 15:24:52 1991, DSJ, Created.
1559  */
1560 
1561  assert (Evidence >= 0.0);
1562  assert (Evidence <= 1.0);
1563 
1564  if (Evidence >= 0.90)
1565  return ScrollView::WHITE;
1566  else if (Evidence >= 0.75)
1567  return ScrollView::GREEN;
1568  else if (Evidence >= 0.50)
1569  return ScrollView::RED;
1570  else
1571  return ScrollView::BLUE;
1572 } /* GetMatchColorFor */
void GetNextFill ( TABLE_FILLER Filler,
FILL_SPEC Fill 
)

Definition at line 1576 of file intproto.cpp.

1576  {
1577 /*
1578  ** Parameters:
1579  ** Filler filler to get next fill spec from
1580  ** Fill place to put spec for next fill
1581  ** Globals: none
1582  ** Operation: This routine returns (in Fill) the specification of
1583  ** the next line to be filled from Filler. FillerDone() should
1584  ** always be called before GetNextFill() to ensure that we
1585  ** do not run past the end of the fill table.
1586  ** Return: none (results are returned in Fill)
1587  ** Exceptions: none
1588  ** History: Tue Feb 19 10:17:42 1991, DSJ, Created.
1589  */
1590  FILL_SWITCH *Next;
1591 
1592  /* compute the fill assuming no switches will be encountered */
1593  Fill->AngleStart = Filler->AngleStart;
1594  Fill->AngleEnd = Filler->AngleEnd;
1595  Fill->X = Filler->X;
1596  Fill->YStart = Filler->YStart >> 8;
1597  Fill->YEnd = Filler->YEnd >> 8;
1598 
1599  /* update the fill info and the filler for ALL switches at this X value */
1600  Next = &(Filler->Switch[Filler->NextSwitch]);
1601  while (Filler->X >= Next->X) {
1602  Fill->X = Filler->X = Next->X;
1603  if (Next->Type == StartSwitch) {
1604  Fill->YStart = Next->Y;
1605  Filler->StartDelta = Next->Delta;
1606  Filler->YStart = Next->YInit;
1607  }
1608  else if (Next->Type == EndSwitch) {
1609  Fill->YEnd = Next->Y;
1610  Filler->EndDelta = Next->Delta;
1611  Filler->YEnd = Next->YInit;
1612  }
1613  else { /* Type must be LastSwitch */
1614  break;
1615  }
1616  Filler->NextSwitch++;
1617  Next = &(Filler->Switch[Filler->NextSwitch]);
1618  }
1619 
1620  /* prepare the filler for the next call to this routine */
1621  Filler->X++;
1622  Filler->YStart += Filler->StartDelta;
1623  Filler->YEnd += Filler->EndDelta;
1624 
1625 } /* GetNextFill */
inT8 YEnd
Definition: intproto.cpp:105
inT16 StartDelta
Definition: intproto.cpp:95
inT16 YEnd
Definition: intproto.cpp:94
uinT8 NextSwitch
Definition: intproto.cpp:91
uinT8 AngleStart
Definition: intproto.cpp:106
inT16 YStart
Definition: intproto.cpp:94
inT16 EndDelta
Definition: intproto.cpp:95
uinT8 AngleEnd
Definition: intproto.cpp:106
inT16 YInit
Definition: intproto.cpp:82
SWITCH_TYPE Type
Definition: intproto.cpp:80
inT8 YStart
Definition: intproto.cpp:105
uinT8 AngleEnd
Definition: intproto.cpp:92
inT16 Delta
Definition: intproto.cpp:83
uinT8 AngleStart
Definition: intproto.cpp:92
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:96
void InitFeatureDisplayWindowIfReqd ( )

Initializes the feature display window if it is not already initialized.

Definition at line 1967 of file intproto.cpp.

1967  {
1968  if (FeatureDisplayWindow == NULL) {
1969  FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
1970  50, 700);
1971  }
1972 }
#define NULL
Definition: host.h:144
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:182
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1976
void InitIntMatchWindowIfReqd ( )

Initializes the int matcher window if it is not already initialized.

Definition at line 1935 of file intproto.cpp.

1935  {
1936  if (IntMatchWindow == NULL) {
1937  IntMatchWindow = CreateFeatureSpaceWindow("IntMatchWindow", 50, 200);
1938  SVMenuNode* popup_menu = new SVMenuNode();
1939 
1940  popup_menu->AddChild("Debug Adapted classes", IDA_ADAPTIVE,
1941  "x", "Class to debug");
1942  popup_menu->AddChild("Debug Static classes", IDA_STATIC,
1943  "x", "Class to debug");
1944  popup_menu->AddChild("Debug Both", IDA_BOTH,
1945  "x", "Class to debug");
1946  popup_menu->AddChild("Debug Shape Index", IDA_SHAPE_INDEX,
1947  "0", "Index to debug");
1948  popup_menu->BuildMenu(IntMatchWindow, false);
1949  }
1950 }
void BuildMenu(ScrollView *sv, bool menu_bar=true)
Definition: svmnode.cpp:121
#define NULL
Definition: host.h:144
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1976
ScrollView * IntMatchWindow
Definition: intproto.cpp:181
SVMenuNode * AddChild(const char *txt)
Definition: svmnode.cpp:59
void InitProtoDisplayWindowIfReqd ( )

Initializes the proto display window if it is not already initialized.

Definition at line 1956 of file intproto.cpp.

1956  {
1957  if (ProtoDisplayWindow == NULL) {
1958  ProtoDisplayWindow = CreateFeatureSpaceWindow("ProtoDisplayWindow",
1959  550, 200);
1960  }
1961 }
#define NULL
Definition: host.h:144
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1976
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:183
void InitTableFiller ( FLOAT32  EndPad,
FLOAT32  SidePad,
FLOAT32  AnglePad,
PROTO  Proto,
TABLE_FILLER Filler 
)

This routine computes a data structure (Filler) which can be used to fill in a rectangle surrounding the specified Proto.

Parameters
EndPad,SidePad,AnglePadpadding to add to proto
Protoproto to create a filler for
Fillerplace to put table filler

Globals: none

Returns
none (results are returned in Filler)
Note
Exceptions: none
History: Thu Feb 14 09:27:05 1991, DSJ, Created.

Definition at line 1644 of file intproto.cpp.

1650 {
1651  FLOAT32 Angle;
1652  FLOAT32 X, Y, HalfLength;
1653  FLOAT32 Cos, Sin;
1654  FLOAT32 XAdjust, YAdjust;
1655  FPOINT Start, Switch1, Switch2, End;
1656  int S1 = 0;
1657  int S2 = 1;
1658 
1659  Angle = Proto->Angle;
1660  X = Proto->X;
1661  Y = Proto->Y;
1662  HalfLength = Proto->Length / 2.0;
1663 
1664  Filler->AngleStart = CircBucketFor(Angle - AnglePad, AS, NB);
1665  Filler->AngleEnd = CircBucketFor(Angle + AnglePad, AS, NB);
1666  Filler->NextSwitch = 0;
1667 
1668  if (fabs (Angle - 0.0) < HV_TOLERANCE || fabs (Angle - 0.5) < HV_TOLERANCE) {
1669  /* horizontal proto - handle as special case */
1670  Filler->X = Bucket8For(X - HalfLength - EndPad, XS, NB);
1671  Filler->YStart = Bucket16For(Y - SidePad, YS, NB * 256);
1672  Filler->YEnd = Bucket16For(Y + SidePad, YS, NB * 256);
1673  Filler->StartDelta = 0;
1674  Filler->EndDelta = 0;
1675  Filler->Switch[0].Type = LastSwitch;
1676  Filler->Switch[0].X = Bucket8For(X + HalfLength + EndPad, XS, NB);
1677  } else if (fabs(Angle - 0.25) < HV_TOLERANCE ||
1678  fabs(Angle - 0.75) < HV_TOLERANCE) {
1679  /* vertical proto - handle as special case */
1680  Filler->X = Bucket8For(X - SidePad, XS, NB);
1681  Filler->YStart = Bucket16For(Y - HalfLength - EndPad, YS, NB * 256);
1682  Filler->YEnd = Bucket16For(Y + HalfLength + EndPad, YS, NB * 256);
1683  Filler->StartDelta = 0;
1684  Filler->EndDelta = 0;
1685  Filler->Switch[0].Type = LastSwitch;
1686  Filler->Switch[0].X = Bucket8For(X + SidePad, XS, NB);
1687  } else {
1688  /* diagonal proto */
1689 
1690  if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) {
1691  /* rising diagonal proto */
1692  Angle *= 2.0 * PI;
1693  Cos = fabs(cos(Angle));
1694  Sin = fabs(sin(Angle));
1695 
1696  /* compute the positions of the corners of the acceptance region */
1697  Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1698  Start.y = Y - (HalfLength + EndPad) * Sin + SidePad * Cos;
1699  End.x = 2.0 * X - Start.x;
1700  End.y = 2.0 * Y - Start.y;
1701  Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1702  Switch1.y = Y - (HalfLength + EndPad) * Sin - SidePad * Cos;
1703  Switch2.x = 2.0 * X - Switch1.x;
1704  Switch2.y = 2.0 * Y - Switch1.y;
1705 
1706  if (Switch1.x > Switch2.x) {
1707  S1 = 1;
1708  S2 = 0;
1709  }
1710 
1711  /* translate into bucket positions and deltas */
1712  Filler->X = Bucket8For(Start.x, XS, NB);
1713  Filler->StartDelta = -(inT16) ((Cos / Sin) * 256);
1714  Filler->EndDelta = (inT16) ((Sin / Cos) * 256);
1715 
1716  XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1717  YAdjust = XAdjust * Cos / Sin;
1718  Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1719  YAdjust = XAdjust * Sin / Cos;
1720  Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1721 
1722  Filler->Switch[S1].Type = StartSwitch;
1723  Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1724  Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1725  XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1726  YAdjust = XAdjust * Sin / Cos;
1727  Filler->Switch[S1].YInit = Bucket16For(Switch1.y - YAdjust, YS, NB * 256);
1728  Filler->Switch[S1].Delta = Filler->EndDelta;
1729 
1730  Filler->Switch[S2].Type = EndSwitch;
1731  Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1732  Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1733  XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1734  YAdjust = XAdjust * Cos / Sin;
1735  Filler->Switch[S2].YInit = Bucket16For(Switch2.y + YAdjust, YS, NB * 256);
1736  Filler->Switch[S2].Delta = Filler->StartDelta;
1737 
1738  Filler->Switch[2].Type = LastSwitch;
1739  Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1740  } else {
1741  /* falling diagonal proto */
1742  Angle *= 2.0 * PI;
1743  Cos = fabs(cos(Angle));
1744  Sin = fabs(sin(Angle));
1745 
1746  /* compute the positions of the corners of the acceptance region */
1747  Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1748  Start.y = Y + (HalfLength + EndPad) * Sin - SidePad * Cos;
1749  End.x = 2.0 * X - Start.x;
1750  End.y = 2.0 * Y - Start.y;
1751  Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1752  Switch1.y = Y + (HalfLength + EndPad) * Sin + SidePad * Cos;
1753  Switch2.x = 2.0 * X - Switch1.x;
1754  Switch2.y = 2.0 * Y - Switch1.y;
1755 
1756  if (Switch1.x > Switch2.x) {
1757  S1 = 1;
1758  S2 = 0;
1759  }
1760 
1761  /* translate into bucket positions and deltas */
1762  Filler->X = Bucket8For(Start.x, XS, NB);
1763  Filler->StartDelta = -(inT16) ((Sin / Cos) * 256);
1764  Filler->EndDelta = (inT16) ((Cos / Sin) * 256);
1765 
1766  XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1767  YAdjust = XAdjust * Sin / Cos;
1768  Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1769  YAdjust = XAdjust * Cos / Sin;
1770  Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1771 
1772  Filler->Switch[S1].Type = EndSwitch;
1773  Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1774  Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1775  XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1776  YAdjust = XAdjust * Sin / Cos;
1777  Filler->Switch[S1].YInit = Bucket16For(Switch1.y + YAdjust, YS, NB * 256);
1778  Filler->Switch[S1].Delta = Filler->StartDelta;
1779 
1780  Filler->Switch[S2].Type = StartSwitch;
1781  Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1782  Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1783  XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1784  YAdjust = XAdjust * Cos / Sin;
1785  Filler->Switch[S2].YInit = Bucket16For(Switch2.y - YAdjust, YS, NB * 256);
1786  Filler->Switch[S2].Delta = Filler->EndDelta;
1787 
1788  Filler->Switch[2].Type = LastSwitch;
1789  Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1790  }
1791  }
1792 } /* InitTableFiller */
inT16 StartDelta
Definition: intproto.cpp:95
Definition: fpoint.h:29
FLOAT32 y
Definition: fpoint.h:31
inT16 YEnd
Definition: intproto.cpp:94
#define NB
#define AS
uinT8 NextSwitch
Definition: intproto.cpp:91
FLOAT32 Y
Definition: protos.h:48
uinT16 Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:449
inT16 YStart
Definition: intproto.cpp:94
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets)
Definition: intproto.cpp:1244
inT16 EndDelta
Definition: intproto.cpp:95
uinT8 Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:445
FLOAT32 X
Definition: protos.h:47
#define PI
Definition: const.h:19
inT16 YInit
Definition: intproto.cpp:82
SWITCH_TYPE Type
Definition: intproto.cpp:80
FLOAT32 Length
Definition: protos.h:50
FLOAT32 Angle
Definition: protos.h:49
short inT16
Definition: host.h:100
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets)
Definition: intproto.cpp:1223
#define XS
uinT8 AngleEnd
Definition: intproto.cpp:92
inT16 Delta
Definition: intproto.cpp:83
#define YS
FLOAT32 x
Definition: fpoint.h:31
#define HV_TOLERANCE
Definition: intproto.cpp:71
uinT8 CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:458
uinT8 AngleStart
Definition: intproto.cpp:92
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:96
float FLOAT32
Definition: host.h:111
INT_CLASS NewIntClass ( int  MaxNumProtos,
int  MaxNumConfigs 
)

Definition at line 673 of file intproto.cpp.

673  {
674 /*
675  ** Parameters:
676  ** MaxNumProtos number of protos to allocate space for
677  ** MaxNumConfigs number of configs to allocate space for
678  ** Globals: none
679  ** Operation: This routine creates a new integer class data structure
680  ** and returns it. Sufficient space is allocated
681  ** to handle the specified number of protos and configs.
682  ** Return: New class created.
683  ** Exceptions: none
684  ** History: Fri Feb 8 10:51:23 1991, DSJ, Created.
685  */
686  INT_CLASS Class;
687  PROTO_SET ProtoSet;
688  int i;
689 
690  assert(MaxNumConfigs <= MAX_NUM_CONFIGS);
691 
692  Class = (INT_CLASS) Emalloc(sizeof(INT_CLASS_STRUCT));
693  Class->NumProtoSets = ((MaxNumProtos + PROTOS_PER_PROTO_SET - 1) /
695 
696  assert(Class->NumProtoSets <= MAX_NUM_PROTO_SETS);
697 
698  Class->NumProtos = 0;
699  Class->NumConfigs = 0;
700 
701  for (i = 0; i < Class->NumProtoSets; i++) {
702  /* allocate space for a proto set, install in class, and initialize */
703  ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
704  memset(ProtoSet, 0, sizeof(*ProtoSet));
705  Class->ProtoSets[i] = ProtoSet;
706 
707  /* allocate space for the proto lengths and install in class */
708  }
709  if (MaxNumIntProtosIn (Class) > 0) {
710  Class->ProtoLengths =
711  (uinT8 *)Emalloc(MaxNumIntProtosIn (Class) * sizeof (uinT8));
712  memset(Class->ProtoLengths, 0,
713  MaxNumIntProtosIn(Class) * sizeof(*Class->ProtoLengths));
714  } else {
715  Class->ProtoLengths = NULL;
716  }
717  memset(Class->ConfigLengths, 0, sizeof(Class->ConfigLengths));
718 
719  return (Class);
720 
721 } /* NewIntClass */
uinT8 NumProtoSets
Definition: intproto.h:109
#define NULL
Definition: host.h:144
#define MaxNumIntProtosIn(C)
Definition: intproto.h:168
#define MAX_NUM_CONFIGS
Definition: intproto.h:46
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:111
struct INT_CLASS_STRUCT * INT_CLASS
uinT16 ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:113
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:49
uinT16 NumProtos
Definition: intproto.h:108
struct PROTO_SET_STRUCT * PROTO_SET
void * Emalloc(int Size)
Definition: emalloc.cpp:35
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:48
unsigned char uinT8
Definition: host.h:99
uinT8 NumConfigs
Definition: intproto.h:110
uinT8 * ProtoLengths
Definition: intproto.h:112
INT_TEMPLATES NewIntTemplates ( )

Definition at line 739 of file intproto.cpp.

739  {
740 /*
741  ** Parameters: none
742  ** Globals: none
743  ** Operation: This routine allocates a new set of integer templates
744  ** initialized to hold 0 classes.
745  ** Return: The integer templates created.
746  ** Exceptions: none
747  ** History: Fri Feb 8 08:38:51 1991, DSJ, Created.
748  */
749  INT_TEMPLATES T;
750  int i;
751 
752  T = (INT_TEMPLATES) Emalloc (sizeof (INT_TEMPLATES_STRUCT));
753  T->NumClasses = 0;
754  T->NumClassPruners = 0;
755 
756  for (i = 0; i < MAX_NUM_CLASSES; i++)
757  ClassForClassId (T, i) = NULL;
758 
759  return (T);
760 } /* NewIntTemplates */
#define NULL
Definition: host.h:144
#define ClassForClassId(T, c)
Definition: intproto.h:181
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
void * Emalloc(int Size)
Definition: emalloc.cpp:35
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
void RenderIntFeature ( ScrollView window,
const INT_FEATURE_STRUCT Feature,
ScrollView::Color  color 
)

Definition at line 1808 of file intproto.cpp.

1809  {
1810  FLOAT32 X, Y, Dx, Dy, Length;
1811 
1812  window->Pen(color);
1813  assert(Feature != NULL);
1814  assert(color != 0);
1815 
1816  X = Feature->X;
1817  Y = Feature->Y;
1818  Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
1819  // The -PI has no significant effect here, but the value of Theta is computed
1820  // using BinaryAnglePlusPi in intfx.cpp.
1821  Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * PI - PI);
1822  Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * PI - PI);
1823 
1824  window->SetCursor(X, Y);
1825  window->DrawTo(X + Dx, Y + Dy);
1826 } /* RenderIntFeature */
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:133
#define NULL
Definition: host.h:144
#define PI
Definition: const.h:19
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
void Pen(Color color)
Definition: scrollview.cpp:726
#define GetPicoFeatureLength()
Definition: picofeat.h:59
float FLOAT32
Definition: host.h:111
void RenderIntProto ( ScrollView window,
INT_CLASS  Class,
PROTO_ID  ProtoId,
ScrollView::Color  color 
)

Definition at line 1845 of file intproto.cpp.

1848  {
1849  PROTO_SET ProtoSet;
1850  INT_PROTO Proto;
1851  int ProtoSetIndex;
1852  int ProtoWordIndex;
1853  FLOAT32 Length;
1854  int Xmin, Xmax, Ymin, Ymax;
1855  FLOAT32 X, Y, Dx, Dy;
1856  uinT32 ProtoMask;
1857  int Bucket;
1858 
1859  assert(ProtoId >= 0);
1860  assert(Class != NULL);
1861  assert(ProtoId < Class->NumProtos);
1862  assert(color != 0);
1863  window->Pen(color);
1864 
1865  ProtoSet = Class->ProtoSets[SetForProto(ProtoId)];
1866  ProtoSetIndex = IndexForProto(ProtoId);
1867  Proto = &(ProtoSet->Protos[ProtoSetIndex]);
1868  Length = (Class->ProtoLengths[ProtoId] *
1870  ProtoMask = PPrunerMaskFor(ProtoId);
1871  ProtoWordIndex = PPrunerWordIndexFor(ProtoId);
1872 
1873  // find the x and y extent of the proto from the proto pruning table
1874  Xmin = Ymin = NUM_PP_BUCKETS;
1875  Xmax = Ymax = 0;
1876  for (Bucket = 0; Bucket < NUM_PP_BUCKETS; Bucket++) {
1877  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_X][Bucket][ProtoWordIndex]) {
1878  UpdateRange(Bucket, &Xmin, &Xmax);
1879  }
1880 
1881  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_Y][Bucket][ProtoWordIndex]) {
1882  UpdateRange(Bucket, &Ymin, &Ymax);
1883  }
1884  }
1885  X = (Xmin + Xmax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1886  Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1887  // The -PI has no significant effect here, but the value of Theta is computed
1888  // using BinaryAnglePlusPi in intfx.cpp.
1889  Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * PI - PI);
1890  Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * PI - PI);
1891 
1892  window->SetCursor(X - Dx, Y - Dy);
1893  window->DrawTo(X + Dx, Y + Dy);
1894 } /* RenderIntProto */
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:125
#define PROTO_PRUNER_SCALE
Definition: intproto.cpp:54
#define PPrunerMaskFor(I)
Definition: intproto.h:176
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
Definition: intproto.h:97
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:133
#define NULL
Definition: host.h:144
unsigned int uinT32
Definition: host.h:103
#define PRUNER_Y
Definition: intproto.h:35
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
#define IndexForProto(P)
Definition: intproto.h:170
#define PPrunerWordIndexFor(I)
Definition: intproto.h:173
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:111
#define PI
Definition: const.h:19
#define SetForProto(P)
Definition: intproto.h:169
#define PRUNER_X
Definition: intproto.h:34
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
#define NUM_PP_BUCKETS
Definition: intproto.h:51
void Pen(Color color)
Definition: scrollview.cpp:726
#define GetPicoFeatureLength()
Definition: picofeat.h:59
float FLOAT32
Definition: host.h:111
uinT8 * ProtoLengths
Definition: intproto.h:112
int TruncateParam ( FLOAT32  Param,
int  Min,
int  Max,
char *  Id 
)

This routine truncates Param to lie within the range of Min-Max inclusive. If a truncation is performed, and Id is not null, an warning message is printed.

Parameters
Paramparameter value to be truncated
Min,Maxparameter limits (inclusive)
Idstring id of parameter for error messages

Globals: none

Returns
Truncated parameter.
Note
Exceptions: none
History: Fri Feb 8 11:54:28 1991, DSJ, Created.

Definition at line 1913 of file intproto.cpp.

1913  {
1914  if (Param < Min) {
1915  if (Id)
1916  cprintf("Warning: Param %s truncated from %f to %d!\n",
1917  Id, Param, Min);
1918  Param = Min;
1919  } else if (Param > Max) {
1920  if (Id)
1921  cprintf("Warning: Param %s truncated from %f to %d!\n",
1922  Id, Param, Max);
1923  Param = Max;
1924  }
1925  return static_cast<int>(floor(Param));
1926 } /* TruncateParam */
void cprintf(const char *format,...)
Definition: callcpp.cpp:40
void UpdateMatchDisplay ( )

Definition at line 466 of file intproto.cpp.

466  {
467 /*
468  ** Parameters: none
469  ** Globals:
470  ** FeatureShapes display list for features
471  ** ProtoShapes display list for protos
472  ** Operation: This routine clears the global feature and proto
473  ** display lists.
474  ** Return: none
475  ** Exceptions: none
476  ** History: Thu Mar 21 15:40:19 1991, DSJ, Created.
477  */
478  if (IntMatchWindow != NULL)
480 } /* ClearMatchDisplay */
#define NULL
Definition: host.h:144
ScrollView * IntMatchWindow
Definition: intproto.cpp:181
static void Update()
Definition: scrollview.cpp:715

Variable Documentation

double classify_cp_angle_pad_loose = 45.0

"Class Pruner Angle Pad Loose"

Definition at line 192 of file intproto.cpp.

double classify_cp_angle_pad_medium = 20.0

"Class Pruner Angle Pad Medium"

Definition at line 194 of file intproto.cpp.

double classify_cp_angle_pad_tight = 10.0

"CLass Pruner Angle Pad Tight"

Definition at line 196 of file intproto.cpp.

double classify_cp_end_pad_loose = 0.5

"Class Pruner End Pad Loose"

Definition at line 197 of file intproto.cpp.

double classify_cp_end_pad_medium = 0.5

"Class Pruner End Pad Medium"

Definition at line 198 of file intproto.cpp.

double classify_cp_end_pad_tight = 0.5

"Class Pruner End Pad Tight"

Definition at line 199 of file intproto.cpp.

double classify_cp_side_pad_loose = 2.5

"Class Pruner Side Pad Loose"

Definition at line 200 of file intproto.cpp.

double classify_cp_side_pad_medium = 1.2

"Class Pruner Side Pad Medium"

Definition at line 201 of file intproto.cpp.

double classify_cp_side_pad_tight = 0.6

"Class Pruner Side Pad Tight"

Definition at line 202 of file intproto.cpp.

int classify_num_cp_levels = 3

"Number of Class Pruner Levels"

Definition at line 190 of file intproto.cpp.

double classify_pp_angle_pad = 45.0

"Proto Pruner Angle Pad"

Definition at line 203 of file intproto.cpp.

double classify_pp_end_pad = 0.5

"Proto Prune End Pad"

Definition at line 204 of file intproto.cpp.

double classify_pp_side_pad = 2.5

"Proto Pruner Side Pad"

Definition at line 205 of file intproto.cpp.

ScrollView* FeatureDisplayWindow = NULL

Definition at line 182 of file intproto.cpp.

ScrollView* IntMatchWindow = NULL

Definition at line 181 of file intproto.cpp.

ScrollView* ProtoDisplayWindow = NULL

Definition at line 183 of file intproto.cpp.