Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 "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)
 
int BucketFor (FLOAT32 Param, FLOAT32 Offset, int NumBuckets)
 
int CircBucketFor (FLOAT32 Param, FLOAT32 Offset, int NumBuckets)
 
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 121 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 70 of file intproto.cpp.

#define INT_BASELINE   (0.25 * INT_CHAR_NORM_RANGE)

Definition at line 56 of file intproto.cpp.

#define INT_CAPHEIGHT   (1.0 * INT_CHAR_NORM_RANGE)

Definition at line 58 of file intproto.cpp.

#define INT_DESCENDER   (0.0 * INT_CHAR_NORM_RANGE)

Definition at line 55 of file intproto.cpp.

#define INT_MAX_X   INT_CHAR_NORM_RANGE

Definition at line 66 of file intproto.cpp.

#define INT_MAX_Y   INT_CHAR_NORM_RANGE

Definition at line 67 of file intproto.cpp.

#define INT_MIN_X   0

Definition at line 64 of file intproto.cpp.

#define INT_MIN_Y   0

Definition at line 65 of file intproto.cpp.

#define INT_XCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 60 of file intproto.cpp.

#define INT_XHEIGHT   (0.75 * INT_CHAR_NORM_RANGE)

Definition at line 57 of file intproto.cpp.

#define INT_XRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 62 of file intproto.cpp.

#define INT_YCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 61 of file intproto.cpp.

#define INT_YRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 63 of file intproto.cpp.

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

macro for mapping floats to ints without bounds checking

Definition at line 124 of file intproto.cpp.

#define MAX_LEVEL   2
#define MAX_NUM_SWITCHES   3

Definition at line 75 of file intproto.cpp.

#define NB   NUM_CP_BUCKETS
#define OLD_MAX_NUM_CONFIGS   32

Definition at line 113 of file intproto.cpp.

#define OLD_WERDS_PER_CONFIG_VEC
Value:
#define OLD_MAX_NUM_CONFIGS
Definition: intproto.cpp:113
#define BITS_PER_WERD
Definition: intproto.h:42

Definition at line 114 of file intproto.cpp.

#define PROTO_PRUNER_SCALE   (4.0)

Definition at line 53 of file intproto.cpp.

#define XS   X_SHIFT
#define YS   Y_SHIFT

Enumeration Type Documentation

Enumerator
StartSwitch 
EndSwitch 
LastSwitch 

Definition at line 72 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 224 of file intproto.cpp.

224  {
225  int Pruner;
226 
227  assert (LegalClassId (ClassId));
228  if (ClassId != Templates->NumClasses) {
229  fprintf(stderr, "Please make sure that classes are added to templates");
230  fprintf(stderr, " in increasing order of ClassIds\n");
231  exit(1);
232  }
233  ClassForClassId (Templates, ClassId) = Class;
234  Templates->NumClasses++;
235 
236  if (Templates->NumClasses > MaxNumClassesIn (Templates)) {
237  Pruner = Templates->NumClassPruners++;
238  Templates->ClassPruners[Pruner] = new CLASS_PRUNER_STRUCT;
239  memset(Templates->ClassPruners[Pruner], 0, sizeof(CLASS_PRUNER_STRUCT));
240  }
241 } /* AddIntClass */
#define ClassForClassId(T, c)
Definition: intproto.h:173
#define MaxNumClassesIn(T)
Definition: intproto.h:170
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:123
#define LegalClassId(c)
Definition: intproto.h:171
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 257 of file intproto.cpp.

257  {
258  int Index;
259 
260  assert(Class->NumConfigs < MAX_NUM_CONFIGS);
261 
262  Index = Class->NumConfigs++;
263  Class->ConfigLengths[Index] = 0;
264  return Index;
265 } /* AddIntConfig */
#define MAX_NUM_CONFIGS
Definition: intproto.h:44
uinT8 NumConfigs
Definition: intproto.h:108
uinT16 ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:111
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 281 of file intproto.cpp.

281  {
282  int Index;
283  int ProtoSetId;
284  PROTO_SET ProtoSet;
285  INT_PROTO Proto;
286  register uinT32 *Word;
287 
288  if (Class->NumProtos >= MAX_NUM_PROTOS)
289  return (NO_PROTO);
290 
291  Index = Class->NumProtos++;
292 
293  if (Class->NumProtos > MaxNumIntProtosIn(Class)) {
294  ProtoSetId = Class->NumProtoSets++;
295 
296  ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
297  Class->ProtoSets[ProtoSetId] = ProtoSet;
298  memset(ProtoSet, 0, sizeof(*ProtoSet));
299 
300  /* reallocate space for the proto lengths and install in class */
301  Class->ProtoLengths =
302  (uinT8 *)Erealloc(Class->ProtoLengths,
303  MaxNumIntProtosIn(Class) * sizeof(uinT8));
304  memset(&Class->ProtoLengths[Index], 0,
305  sizeof(*Class->ProtoLengths) * (MaxNumIntProtosIn(Class) - Index));
306  }
307 
308  /* initialize proto so its length is zero and it isn't in any configs */
309  Class->ProtoLengths[Index] = 0;
310  Proto = ProtoForProtoId (Class, Index);
311  for (Word = Proto->Configs;
312  Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);
313 
314  return (Index);
315 
316 } /* AddIntProto */
uinT32 Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:84
void * Erealloc(void *ptr, size_t size)
Definition: emalloc.cpp:70
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
#define MAX_NUM_PROTOS
Definition: intproto.h:45
struct PROTO_SET_STRUCT * PROTO_SET
uinT8 * ProtoLengths
Definition: intproto.h:110
void * Emalloc(size_t Size)
Definition: emalloc.cpp:35
#define NO_PROTO
Definition: matchdefs.h:42
#define MaxNumIntProtosIn(C)
Definition: intproto.h:160
unsigned char uinT8
Definition: host.h:99
uinT16 NumProtos
Definition: intproto.h:106
unsigned int uinT32
Definition: host.h:103
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:66
uinT8 NumProtoSets
Definition: intproto.h:107
#define ProtoForProtoId(C, P)
Definition: intproto.h:163
void AddProtoToClassPruner ( PROTO  Proto,
CLASS_ID  ClassId,
INT_TEMPLATES  Templates 
)

Definition at line 320 of file intproto.cpp.

336 {
337  CLASS_PRUNER_STRUCT* Pruner;
338  uinT32 ClassMask;
339  uinT32 ClassCount;
340  uinT32 WordIndex;
341  int Level;
342  FLOAT32 EndPad, SidePad, AnglePad;
343  TABLE_FILLER TableFiller;
344  FILL_SPEC FillSpec;
345 
346  Pruner = CPrunerFor (Templates, ClassId);
347  WordIndex = CPrunerWordIndexFor (ClassId);
348  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassId);
349 
350  for (Level = classify_num_cp_levels - 1; Level >= 0; Level--) {
351  GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);
352  ClassCount = CPrunerMaskFor (Level, ClassId);
353  InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);
354 
355  while (!FillerDone (&TableFiller)) {
356  GetNextFill(&TableFiller, &FillSpec);
357  DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
358  }
359  }
360 } /* AddProtoToClassPruner */
void InitTableFiller(FLOAT32 EndPad, FLOAT32 SidePad, FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER *Filler)
Definition: intproto.cpp:1654
#define CPrunerFor(T, c)
Definition: intproto.h:176
int classify_num_cp_levels
Definition: intproto.cpp:189
BOOL8 FillerDone(TABLE_FILLER *Filler)
Definition: intproto.cpp:1324
float FLOAT32
Definition: host.h:111
#define CPrunerWordIndexFor(c)
Definition: intproto.h:177
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
Definition: intproto.cpp:1586
#define MAX_LEVEL
#define CPrunerMaskFor(L, c)
Definition: intproto.h:179
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, register uinT32 ClassMask, register uinT32 ClassCount, register uinT32 WordIndex)
Definition: intproto.cpp:1274
unsigned int uinT32
Definition: host.h:103
void GetCPPadsForLevel(int Level, FLOAT32 *EndPad, FLOAT32 *SidePad, FLOAT32 *AnglePad)
Definition: intproto.cpp:1508
void AddProtoToProtoPruner ( PROTO  Proto,
int  ProtoId,
INT_CLASS  Class,
bool  debug 
)

Definition at line 364 of file intproto.cpp.

365  {
366 /*
367  ** Parameters:
368  ** Proto floating-pt proto to be added to proto pruner
369  ** ProtoId id of proto
370  ** Class integer class that contains desired proto pruner
371  ** Globals: none
372  ** Operation: This routine updates the proto pruner lookup tables
373  ** for Class to include a new proto identified by ProtoId
374  ** and described by Proto.
375  ** Return: none
376  ** Exceptions: none
377  ** History: Fri Feb 8 13:07:19 1991, DSJ, Created.
378  */
379  FLOAT32 Angle, X, Y, Length;
380  FLOAT32 Pad;
381  int Index;
382  PROTO_SET ProtoSet;
383 
384  if (ProtoId >= Class->NumProtos)
385  cprintf("AddProtoToProtoPruner:assert failed: %d < %d",
386  ProtoId, Class->NumProtos);
387  assert(ProtoId < Class->NumProtos);
388 
389  Index = IndexForProto (ProtoId);
390  ProtoSet = Class->ProtoSets[SetForProto (ProtoId)];
391 
392  Angle = Proto->Angle;
393 #ifndef _WIN32
394  assert(!isnan(Angle));
395 #endif
396 
397  FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index,
398  Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
399  debug);
400 
401  Angle *= 2.0 * PI;
402  Length = Proto->Length;
403 
404  X = Proto->X + X_SHIFT;
405  Pad = MAX (fabs (cos (Angle)) * (Length / 2.0 +
408  fabs (sin (Angle)) * (classify_pp_side_pad *
410 
411  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);
412 
413  Y = Proto->Y + Y_SHIFT;
414  Pad = MAX (fabs (sin (Angle)) * (Length / 2.0 +
417  fabs (cos (Angle)) * (classify_pp_side_pad *
419 
420  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);
421 } /* AddProtoToProtoPruner */
void FillPPCircularBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
Definition: intproto.cpp:1348
#define PRUNER_Y
Definition: intproto.h:33
FLOAT32 Length
Definition: protos.h:50
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
FLOAT32 Y
Definition: protos.h:48
double classify_pp_side_pad
Definition: intproto.cpp:204
#define PI
Definition: const.h:19
#define PRUNER_ANGLE
Definition: intproto.h:34
double classify_pp_end_pad
Definition: intproto.cpp:203
float FLOAT32
Definition: host.h:111
#define X_SHIFT
Definition: intproto.h:38
#define ANGLE_SHIFT
Definition: intproto.h:37
FLOAT32 Angle
Definition: protos.h:49
#define PRUNER_X
Definition: intproto.h:32
void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
Definition: intproto.cpp:1392
#define SetForProto(P)
Definition: intproto.h:161
double classify_pp_angle_pad
Definition: intproto.cpp:202
#define Y_SHIFT
Definition: intproto.h:39
FLOAT32 X
Definition: protos.h:47
uinT16 NumProtos
Definition: intproto.h:106
PROTO_PRUNER ProtoPruner
Definition: intproto.h:94
#define GetPicoFeatureLength()
Definition: picofeat.h:59
#define MAX(x, y)
Definition: ndminx.h:24
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define IndexForProto(P)
Definition: intproto.h:162
FLOAT32 BucketEnd ( int  Bucket,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 1254 of file intproto.cpp.

1254  {
1255 /*
1256  ** Parameters:
1257  ** Bucket bucket whose end is to be computed
1258  ** Offset offset used to map params to buckets
1259  ** NumBuckets total number of buckets
1260  ** Globals: none
1261  ** Operation: This routine returns the parameter value which
1262  ** corresponds to the end of the specified bucket.
1263  ** The bucket number should have been generated using the
1264  ** BucketFor() function with parameters Offset and NumBuckets.
1265  ** Return: Param value corresponding to end position of Bucket.
1266  ** Exceptions: none
1267  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
1268  */
1269  return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
1270 } /* BucketEnd */
float FLOAT32
Definition: host.h:111
int BucketFor ( FLOAT32  Param,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 425 of file intproto.cpp.

425  {
426 /*
427  ** Parameters:
428  ** Param parameter value to map into a bucket number
429  ** Offset amount to shift param before mapping it
430  ** NumBuckets number of buckets to map param into
431  ** Globals: none
432  ** Operation: This routine maps a parameter value into a bucket between
433  ** 0 and NumBuckets-1. Offset is added to the parameter
434  ** before mapping it. Values which map to buckets outside
435  ** the range are truncated to fit within the range. Mapping
436  ** is done by truncating rather than rounding.
437  ** Return: Bucket number corresponding to Param + Offset.
438  ** Exceptions: none
439  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
440  */
441  return ClipToRange(static_cast<int>(MapParam(Param, Offset, NumBuckets)),
442  0, NumBuckets - 1);
443 } /* BucketFor */
#define MapParam(P, O, N)
Definition: intproto.cpp:124
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:64
FLOAT32 BucketStart ( int  Bucket,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 1233 of file intproto.cpp.

1233  {
1234 /*
1235  ** Parameters:
1236  ** Bucket bucket whose start is to be computed
1237  ** Offset offset used to map params to buckets
1238  ** NumBuckets total number of buckets
1239  ** Globals: none
1240  ** Operation: This routine returns the parameter value which
1241  ** corresponds to the beginning of the specified bucket.
1242  ** The bucket number should have been generated using the
1243  ** BucketFor() function with parameters Offset and NumBuckets.
1244  ** Return: Param value corresponding to start position of Bucket.
1245  ** Exceptions: none
1246  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
1247  */
1248  return (((FLOAT32) Bucket / NumBuckets) - Offset);
1249 
1250 } /* BucketStart */
float FLOAT32
Definition: host.h:111
int CircBucketFor ( FLOAT32  Param,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 447 of file intproto.cpp.

447  {
448 /*
449  ** Parameters:
450  ** Param parameter value to map into a circular bucket
451  ** Offset amount to shift param before mapping it
452  ** NumBuckets number of buckets to map param into
453  ** Globals: none
454  ** Operation: This routine maps a parameter value into a bucket between
455  ** 0 and NumBuckets-1. Offset is added to the parameter
456  ** before mapping it. Values which map to buckets outside
457  ** the range are wrapped to a new value in a circular fashion.
458  ** Mapping is done by truncating rather than rounding.
459  ** Return: Bucket number corresponding to Param + Offset.
460  ** Exceptions: none
461  ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
462  */
463  int Bucket;
464 
465  Bucket = static_cast<int>(MapParam(Param, Offset, NumBuckets));
466  if (Bucket < 0)
467  Bucket += NumBuckets;
468  else if (Bucket >= NumBuckets)
469  Bucket -= NumBuckets;
470  return Bucket;
471 } /* CircBucketFor */
#define MapParam(P, O, N)
Definition: intproto.cpp:124
void ConvertConfig ( BIT_VECTOR  Config,
int  ConfigId,
INT_CLASS  Class 
)

Definition at line 494 of file intproto.cpp.

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

Definition at line 1990 of file intproto.cpp.

1990  {
1991  return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
1992 }
void DisplayIntFeature ( const INT_FEATURE_STRUCT Feature,
FLOAT32  Evidence 
)

Definition at line 638 of file intproto.cpp.

638  {
639 /*
640  ** Parameters:
641  ** Feature pico-feature to be displayed
642  ** Evidence best evidence for this feature (0-1)
643  ** Globals:
644  ** FeatureShapes global display list for features
645  ** Operation: This routine renders the specified feature into a
646  ** global display list.
647  ** Return: none
648  ** Exceptions: none
649  ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
650  */
651  ScrollView::Color color = GetMatchColorFor(Evidence);
652  RenderIntFeature(IntMatchWindow, Feature, color);
653  if (FeatureDisplayWindow) {
654  RenderIntFeature(FeatureDisplayWindow, Feature, color);
655  }
656 } /* DisplayIntFeature */
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:181
ScrollView * IntMatchWindow
Definition: intproto.cpp:180
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1822
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence)
Definition: intproto.cpp:1560
void DisplayIntProto ( INT_CLASS  Class,
PROTO_ID  ProtoId,
FLOAT32  Evidence 
)

Definition at line 660 of file intproto.cpp.

660  {
661 /*
662  ** Parameters:
663  ** Class class to take proto from
664  ** ProtoId id of proto in Class to be displayed
665  ** Evidence total evidence for proto (0-1)
666  ** Globals:
667  ** ProtoShapes global display list for protos
668  ** Operation: This routine renders the specified proto into a
669  ** global display list.
670  ** Return: none
671  ** Exceptions: none
672  ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
673  */
674  ScrollView::Color color = GetMatchColorFor(Evidence);
675  RenderIntProto(IntMatchWindow, Class, ProtoId, color);
676  if (ProtoDisplayWindow) {
677  RenderIntProto(ProtoDisplayWindow, Class, ProtoId, color);
678  }
679 } /* DisplayIntProto */
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
Definition: intproto.cpp:1859
ScrollView * IntMatchWindow
Definition: intproto.cpp:180
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:182
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence)
Definition: intproto.cpp:1560
void DoFill ( FILL_SPEC FillSpec,
CLASS_PRUNER_STRUCT Pruner,
register uinT32  ClassMask,
register uinT32  ClassCount,
register uinT32  WordIndex 
)

Definition at line 1274 of file intproto.cpp.

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

Definition at line 1324 of file intproto.cpp.

1324  {
1325 /*
1326  ** Parameters:
1327  ** Filler table filler to check if done
1328  ** Globals: none
1329  ** Operation: Return TRUE if the specified table filler is done, i.e.
1330  ** if it has no more lines to fill.
1331  ** Return: TRUE if no more lines to fill, FALSE otherwise.
1332  ** Exceptions: none
1333  ** History: Tue Feb 19 10:08:05 1991, DSJ, Created.
1334  */
1335  FILL_SWITCH *Next;
1336 
1337  Next = &(Filler->Switch[Filler->NextSwitch]);
1338 
1339  if (Filler->X > Next->X && Next->Type == LastSwitch)
1340  return (TRUE);
1341  else
1342  return (FALSE);
1343 
1344 } /* FillerDone */
SWITCH_TYPE Type
Definition: intproto.cpp:79
#define FALSE
Definition: capi.h:28
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:95
uinT8 NextSwitch
Definition: intproto.cpp:90
#define TRUE
Definition: capi.h:27
void FillPPCircularBits ( uinT32  ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int  Bit,
FLOAT32  Center,
FLOAT32  Spread,
bool  debug 
)

Definition at line 1348 of file intproto.cpp.

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

Definition at line 1392 of file intproto.cpp.

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

Definition at line 735 of file intproto.cpp.

735  {
736  int i;
737 
738  for (i = 0; i < int_class->NumProtoSets; i++) {
739  Efree (int_class->ProtoSets[i]);
740  }
741  if (int_class->ProtoLengths != NULL) {
742  Efree (int_class->ProtoLengths);
743  }
744  Efree(int_class);
745 }
void Efree(void *ptr)
Definition: emalloc.cpp:85
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
#define NULL
Definition: host.h:144
uinT8 * ProtoLengths
Definition: intproto.h:110
uinT8 NumProtoSets
Definition: intproto.h:107
void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 774 of file intproto.cpp.

774  {
775  int i;
776 
777  for (i = 0; i < templates->NumClasses; i++)
778  free_int_class(templates->Class[i]);
779  for (i = 0; i < templates->NumClassPruners; i++)
780  delete templates->ClassPruners[i];
781  Efree(templates);
782 }
void Efree(void *ptr)
Definition: emalloc.cpp:85
void free_int_class(INT_CLASS int_class)
Definition: intproto.cpp:735
INT_CLASS Class[MAX_NUM_CLASSES]
Definition: intproto.h:122
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:123
void GetCPPadsForLevel ( int  Level,
FLOAT32 EndPad,
FLOAT32 SidePad,
FLOAT32 AnglePad 
)

Definition at line 1508 of file intproto.cpp.

1511  {
1512 /*
1513  ** Parameters:
1514  ** Level "tightness" level to return pads for
1515  ** EndPad place to put end pad for Level
1516  ** SidePad place to put side pad for Level
1517  ** AnglePad place to put angle pad for Level
1518  ** Globals: none
1519  ** Operation: This routine copies the appropriate global pad variables
1520  ** into EndPad, SidePad, and AnglePad. This is a kludge used
1521  ** to get around the fact that global control variables cannot
1522  ** be arrays. If the specified level is illegal, the tightest
1523  ** possible pads are returned.
1524  ** Return: none (results are returned in EndPad, SidePad, and AnglePad.
1525  ** Exceptions: none
1526  ** History: Thu Feb 14 08:26:49 1991, DSJ, Created.
1527  */
1528  switch (Level) {
1529  case 0:
1532  *AnglePad = classify_cp_angle_pad_loose / 360.0;
1533  break;
1534 
1535  case 1:
1538  *AnglePad = classify_cp_angle_pad_medium / 360.0;
1539  break;
1540 
1541  case 2:
1544  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1545  break;
1546 
1547  default:
1550  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1551  break;
1552  }
1553  if (*AnglePad > 0.5)
1554  *AnglePad = 0.5;
1555 
1556 } /* GetCPPadsForLevel */
double classify_cp_side_pad_medium
Definition: intproto.cpp:200
double classify_cp_end_pad_loose
Definition: intproto.cpp:196
double classify_cp_angle_pad_medium
Definition: intproto.cpp:193
double classify_cp_side_pad_tight
Definition: intproto.cpp:201
double classify_cp_angle_pad_tight
Definition: intproto.cpp:195
double classify_cp_end_pad_medium
Definition: intproto.cpp:197
double classify_cp_side_pad_loose
Definition: intproto.cpp:199
#define GetPicoFeatureLength()
Definition: picofeat.h:59
double classify_cp_angle_pad_loose
Definition: intproto.cpp:191
double classify_cp_end_pad_tight
Definition: intproto.cpp:198
ScrollView::Color GetMatchColorFor ( FLOAT32  Evidence)

Definition at line 1560 of file intproto.cpp.

1560  {
1561 /*
1562  ** Parameters:
1563  ** Evidence evidence value to return color for
1564  ** Globals: none
1565  ** Operation:
1566  ** Return: Color which corresponds to specified Evidence value.
1567  ** Exceptions: none
1568  ** History: Thu Mar 21 15:24:52 1991, DSJ, Created.
1569  */
1570 
1571  assert (Evidence >= 0.0);
1572  assert (Evidence <= 1.0);
1573 
1574  if (Evidence >= 0.90)
1575  return ScrollView::WHITE;
1576  else if (Evidence >= 0.75)
1577  return ScrollView::GREEN;
1578  else if (Evidence >= 0.50)
1579  return ScrollView::RED;
1580  else
1581  return ScrollView::BLUE;
1582 } /* GetMatchColorFor */
void GetNextFill ( TABLE_FILLER Filler,
FILL_SPEC Fill 
)

Definition at line 1586 of file intproto.cpp.

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

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

Definition at line 1981 of file intproto.cpp.

1981  {
1982  if (FeatureDisplayWindow == NULL) {
1983  FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
1984  50, 700);
1985  }
1986 }
#define NULL
Definition: host.h:144
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:181
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1990
void InitIntMatchWindowIfReqd ( )

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

Definition at line 1949 of file intproto.cpp.

1949  {
1950  if (IntMatchWindow == NULL) {
1951  IntMatchWindow = CreateFeatureSpaceWindow("IntMatchWindow", 50, 200);
1952  SVMenuNode* popup_menu = new SVMenuNode();
1953 
1954  popup_menu->AddChild("Debug Adapted classes", IDA_ADAPTIVE,
1955  "x", "Class to debug");
1956  popup_menu->AddChild("Debug Static classes", IDA_STATIC,
1957  "x", "Class to debug");
1958  popup_menu->AddChild("Debug Both", IDA_BOTH,
1959  "x", "Class to debug");
1960  popup_menu->AddChild("Debug Shape Index", IDA_SHAPE_INDEX,
1961  "0", "Index to debug");
1962  popup_menu->BuildMenu(IntMatchWindow, false);
1963  }
1964 }
void BuildMenu(ScrollView *sv, bool menu_bar=true)
Definition: svmnode.cpp:132
SVMenuNode * AddChild(const char *txt)
Definition: svmnode.cpp:64
#define NULL
Definition: host.h:144
ScrollView * IntMatchWindow
Definition: intproto.cpp:180
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1990
void InitProtoDisplayWindowIfReqd ( )

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

Definition at line 1970 of file intproto.cpp.

1970  {
1971  if (ProtoDisplayWindow == NULL) {
1972  ProtoDisplayWindow = CreateFeatureSpaceWindow("ProtoDisplayWindow",
1973  550, 200);
1974  }
1975 }
#define NULL
Definition: host.h:144
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:182
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1990
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 1654 of file intproto.cpp.

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

Definition at line 683 of file intproto.cpp.

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

Definition at line 749 of file intproto.cpp.

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

Definition at line 1822 of file intproto.cpp.

1823  {
1824  FLOAT32 X, Y, Dx, Dy, Length;
1825 
1826  window->Pen(color);
1827  assert(Feature != NULL);
1828  assert(color != 0);
1829 
1830  X = Feature->X;
1831  Y = Feature->Y;
1832  Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
1833  // The -PI has no significant effect here, but the value of Theta is computed
1834  // using BinaryAnglePlusPi in intfx.cpp.
1835  Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * PI - PI);
1836  Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * PI - PI);
1837 
1838  window->SetCursor(X, Y);
1839  window->DrawTo(X + Dx, Y + Dy);
1840 } /* RenderIntFeature */
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:131
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
void Pen(Color color)
Definition: scrollview.cpp:721
#define NULL
Definition: host.h:144
#define PI
Definition: const.h:19
float FLOAT32
Definition: host.h:111
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
#define GetPicoFeatureLength()
Definition: picofeat.h:59
void RenderIntProto ( ScrollView window,
INT_CLASS  Class,
PROTO_ID  ProtoId,
ScrollView::Color  color 
)

Definition at line 1859 of file intproto.cpp.

1862  {
1863  PROTO_SET ProtoSet;
1864  INT_PROTO Proto;
1865  int ProtoSetIndex;
1866  int ProtoWordIndex;
1867  FLOAT32 Length;
1868  int Xmin, Xmax, Ymin, Ymax;
1869  FLOAT32 X, Y, Dx, Dy;
1870  uinT32 ProtoMask;
1871  int Bucket;
1872 
1873  assert(ProtoId >= 0);
1874  assert(Class != NULL);
1875  assert(ProtoId < Class->NumProtos);
1876  assert(color != 0);
1877  window->Pen(color);
1878 
1879  ProtoSet = Class->ProtoSets[SetForProto(ProtoId)];
1880  ProtoSetIndex = IndexForProto(ProtoId);
1881  Proto = &(ProtoSet->Protos[ProtoSetIndex]);
1882  Length = (Class->ProtoLengths[ProtoId] *
1884  ProtoMask = PPrunerMaskFor(ProtoId);
1885  ProtoWordIndex = PPrunerWordIndexFor(ProtoId);
1886 
1887  // find the x and y extent of the proto from the proto pruning table
1888  Xmin = Ymin = NUM_PP_BUCKETS;
1889  Xmax = Ymax = 0;
1890  for (Bucket = 0; Bucket < NUM_PP_BUCKETS; Bucket++) {
1891  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_X][Bucket][ProtoWordIndex]) {
1892  UpdateRange(Bucket, &Xmin, &Xmax);
1893  }
1894 
1895  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_Y][Bucket][ProtoWordIndex]) {
1896  UpdateRange(Bucket, &Ymin, &Ymax);
1897  }
1898  }
1899  X = (Xmin + Xmax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1900  Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1901  // The -PI has no significant effect here, but the value of Theta is computed
1902  // using BinaryAnglePlusPi in intfx.cpp.
1903  Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * PI - PI);
1904  Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * PI - PI);
1905 
1906  window->SetCursor(X - Dx, Y - Dy);
1907  window->DrawTo(X + Dx, Y + Dy);
1908 } /* RenderIntProto */
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:131
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
#define PRUNER_Y
Definition: intproto.h:33
void Pen(Color color)
Definition: scrollview.cpp:721
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
#define PROTO_PRUNER_SCALE
Definition: intproto.cpp:53
#define NULL
Definition: host.h:144
#define PI
Definition: const.h:19
float FLOAT32
Definition: host.h:111
uinT8 * ProtoLengths
Definition: intproto.h:110
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
#define PRUNER_X
Definition: intproto.h:32
#define SetForProto(P)
Definition: intproto.h:161
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
Definition: intproto.h:95
#define PPrunerMaskFor(I)
Definition: intproto.h:168
#define PPrunerWordIndexFor(I)
Definition: intproto.h:165
#define NUM_PP_BUCKETS
Definition: intproto.h:49
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:74
PROTO_PRUNER ProtoPruner
Definition: intproto.h:94
#define GetPicoFeatureLength()
Definition: picofeat.h:59
#define IndexForProto(P)
Definition: intproto.h:162
unsigned int uinT32
Definition: host.h:103
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 1927 of file intproto.cpp.

1927  {
1928  if (Param < Min) {
1929  if (Id)
1930  cprintf("Warning: Param %s truncated from %f to %d!\n",
1931  Id, Param, Min);
1932  Param = Min;
1933  } else if (Param > Max) {
1934  if (Id)
1935  cprintf("Warning: Param %s truncated from %f to %d!\n",
1936  Id, Param, Max);
1937  Param = Max;
1938  }
1939  return static_cast<int>(floor(Param));
1940 } /* TruncateParam */
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
void UpdateMatchDisplay ( )

Definition at line 476 of file intproto.cpp.

476  {
477 /*
478  ** Parameters: none
479  ** Globals:
480  ** FeatureShapes display list for features
481  ** ProtoShapes display list for protos
482  ** Operation: This routine clears the global feature and proto
483  ** display lists.
484  ** Return: none
485  ** Exceptions: none
486  ** History: Thu Mar 21 15:40:19 1991, DSJ, Created.
487  */
488  if (IntMatchWindow != NULL)
490 } /* ClearMatchDisplay */
#define NULL
Definition: host.h:144
static void Update()
Definition: scrollview.cpp:710
ScrollView * IntMatchWindow
Definition: intproto.cpp:180

Variable Documentation

double classify_cp_angle_pad_loose = 45.0

"Class Pruner Angle Pad Loose"

Definition at line 191 of file intproto.cpp.

double classify_cp_angle_pad_medium = 20.0

"Class Pruner Angle Pad Medium"

Definition at line 193 of file intproto.cpp.

double classify_cp_angle_pad_tight = 10.0

"CLass Pruner Angle Pad Tight"

Definition at line 195 of file intproto.cpp.

double classify_cp_end_pad_loose = 0.5

"Class Pruner End Pad Loose"

Definition at line 196 of file intproto.cpp.

double classify_cp_end_pad_medium = 0.5

"Class Pruner End Pad Medium"

Definition at line 197 of file intproto.cpp.

double classify_cp_end_pad_tight = 0.5

"Class Pruner End Pad Tight"

Definition at line 198 of file intproto.cpp.

double classify_cp_side_pad_loose = 2.5

"Class Pruner Side Pad Loose"

Definition at line 199 of file intproto.cpp.

double classify_cp_side_pad_medium = 1.2

"Class Pruner Side Pad Medium"

Definition at line 200 of file intproto.cpp.

double classify_cp_side_pad_tight = 0.6

"Class Pruner Side Pad Tight"

Definition at line 201 of file intproto.cpp.

int classify_num_cp_levels = 3

"Number of Class Pruner Levels"

Definition at line 189 of file intproto.cpp.

double classify_pp_angle_pad = 45.0

"Proto Pruner Angle Pad"

Definition at line 202 of file intproto.cpp.

double classify_pp_end_pad = 0.5

"Proto Prune End Pad"

Definition at line 203 of file intproto.cpp.

double classify_pp_side_pad = 2.5

"Proto Pruner Side Pad"

Definition at line 204 of file intproto.cpp.

ScrollView* FeatureDisplayWindow = NULL

Definition at line 181 of file intproto.cpp.

ScrollView* IntMatchWindow = NULL

Definition at line 180 of file intproto.cpp.

ScrollView* ProtoDisplayWindow = NULL

Definition at line 182 of file intproto.cpp.