tesseract  4.0.0-1-g2a2b
intproto.cpp File Reference
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cassert>
#include "classify.h"
#include "callcpp.h"
#include "emalloc.h"
#include "fontinfo.h"
#include "genericvector.h"
#include "globals.h"
#include "helpers.h"
#include "intproto.h"
#include "mfoutline.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)   (std::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

float BucketStart (int Bucket, float Offset, int NumBuckets)
 
float BucketEnd (int Bucket, float Offset, int NumBuckets)
 
void DoFill (FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, uint32_t ClassMask, uint32_t ClassCount, uint32_t WordIndex)
 
bool FillerDone (TABLE_FILLER *Filler)
 
void FillPPCircularBits (uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
 
void FillPPLinearBits (uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
 
void GetCPPadsForLevel (int Level, float *EndPad, float *SidePad, float *AnglePad)
 
ScrollView::Color GetMatchColorFor (float Evidence)
 
void GetNextFill (TABLE_FILLER *Filler, FILL_SPEC *Fill)
 
void InitTableFiller (float EndPad, float SidePad, float 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 (float 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_t Bucket8For (float param, float offset, int num_buckets)
 
uint16_t Bucket16For (float param, float offset, int num_buckets)
 
uint8_t CircBucketFor (float param, float offset, int num_buckets)
 
void UpdateMatchDisplay ()
 
void ConvertConfig (BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
 
void DisplayIntFeature (const INT_FEATURE_STRUCT *Feature, float Evidence)
 
void DisplayIntProto (INT_CLASS Class, PROTO_ID ProtoId, float Evidence)
 
INT_CLASS NewIntClass (int MaxNumProtos, int MaxNumConfigs)
 
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 = nullptr
 
ScrollViewFeatureDisplayWindow = nullptr
 
ScrollViewProtoDisplayWindow = nullptr
 
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

◆ AS

#define AS   ANGLE_SHIFT

◆ CircularIncrement

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

macro for performing circular increments of bucket indices

Definition at line 117 of file intproto.cpp.

◆ HV_TOLERANCE

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

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

Definition at line 66 of file intproto.cpp.

◆ INT_BASELINE

#define INT_BASELINE   (0.25 * INT_CHAR_NORM_RANGE)

Definition at line 52 of file intproto.cpp.

◆ INT_CAPHEIGHT

#define INT_CAPHEIGHT   (1.0 * INT_CHAR_NORM_RANGE)

Definition at line 54 of file intproto.cpp.

◆ INT_DESCENDER

#define INT_DESCENDER   (0.0 * INT_CHAR_NORM_RANGE)

Definition at line 51 of file intproto.cpp.

◆ INT_MAX_X

#define INT_MAX_X   INT_CHAR_NORM_RANGE

Definition at line 62 of file intproto.cpp.

◆ INT_MAX_Y

#define INT_MAX_Y   INT_CHAR_NORM_RANGE

Definition at line 63 of file intproto.cpp.

◆ INT_MIN_X

#define INT_MIN_X   0

Definition at line 60 of file intproto.cpp.

◆ INT_MIN_Y

#define INT_MIN_Y   0

Definition at line 61 of file intproto.cpp.

◆ INT_XCENTER

#define INT_XCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 56 of file intproto.cpp.

◆ INT_XHEIGHT

#define INT_XHEIGHT   (0.75 * INT_CHAR_NORM_RANGE)

Definition at line 53 of file intproto.cpp.

◆ INT_XRADIUS

#define INT_XRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 58 of file intproto.cpp.

◆ INT_YCENTER

#define INT_YCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 57 of file intproto.cpp.

◆ INT_YRADIUS

#define INT_YRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 59 of file intproto.cpp.

◆ MapParam

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

macro for mapping floats to ints without bounds checking

Definition at line 120 of file intproto.cpp.

◆ MAX_LEVEL

#define MAX_LEVEL   2

◆ MAX_NUM_SWITCHES

#define MAX_NUM_SWITCHES   3

Definition at line 71 of file intproto.cpp.

◆ NB

#define NB   NUM_CP_BUCKETS

◆ OLD_MAX_NUM_CONFIGS

#define OLD_MAX_NUM_CONFIGS   32

Definition at line 109 of file intproto.cpp.

◆ OLD_WERDS_PER_CONFIG_VEC

#define OLD_WERDS_PER_CONFIG_VEC
Value:
#define BITS_PER_WERD
Definition: intproto.h:45
#define OLD_MAX_NUM_CONFIGS
Definition: intproto.cpp:109

Definition at line 110 of file intproto.cpp.

◆ PROTO_PRUNER_SCALE

#define PROTO_PRUNER_SCALE   (4.0)

Definition at line 49 of file intproto.cpp.

◆ XS

#define XS   X_SHIFT

◆ YS

#define YS   Y_SHIFT

Enumeration Type Documentation

◆ SWITCH_TYPE

Enumerator
StartSwitch 
EndSwitch 
LastSwitch 

Definition at line 68 of file intproto.cpp.

Function Documentation

◆ AddIntClass()

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

Definition at line 232 of file intproto.cpp.

232  {
233  int Pruner;
234 
235  assert (LegalClassId (ClassId));
236  if (ClassId != Templates->NumClasses) {
237  fprintf(stderr, "Please make sure that classes are added to templates");
238  fprintf(stderr, " in increasing order of ClassIds\n");
239  exit(1);
240  }
241  ClassForClassId (Templates, ClassId) = Class;
242  Templates->NumClasses++;
243 
244  if (Templates->NumClasses > MaxNumClassesIn (Templates)) {
245  Pruner = Templates->NumClassPruners++;
246  Templates->ClassPruners[Pruner] = new CLASS_PRUNER_STRUCT;
247  memset(Templates->ClassPruners[Pruner], 0, sizeof(CLASS_PRUNER_STRUCT));
248  }
249 } /* AddIntClass */
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:122
#define LegalClassId(c)
Definition: intproto.h:174
#define MaxNumClassesIn(T)
Definition: intproto.h:173
#define ClassForClassId(T, c)
Definition: intproto.h:176

◆ AddIntConfig()

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.

Definition at line 262 of file intproto.cpp.

262  {
263  int Index;
264 
265  assert(Class->NumConfigs < MAX_NUM_CONFIGS);
266 
267  Index = Class->NumConfigs++;
268  Class->ConfigLengths[Index] = 0;
269  return Index;
270 } /* AddIntConfig */
uint8_t NumConfigs
Definition: intproto.h:108
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:111

◆ AddIntProto()

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.

Definition at line 283 of file intproto.cpp.

283  {
284  int Index;
285  int ProtoSetId;
286  PROTO_SET ProtoSet;
287  INT_PROTO Proto;
288  uint32_t *Word;
289 
290  if (Class->NumProtos >= MAX_NUM_PROTOS)
291  return (NO_PROTO);
292 
293  Index = Class->NumProtos++;
294 
295  if (Class->NumProtos > MaxNumIntProtosIn(Class)) {
296  ProtoSetId = Class->NumProtoSets++;
297 
298  ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
299  Class->ProtoSets[ProtoSetId] = ProtoSet;
300  memset(ProtoSet, 0, sizeof(*ProtoSet));
301 
302  /* reallocate space for the proto lengths and install in class */
303  Class->ProtoLengths =
304  (uint8_t *)Erealloc(Class->ProtoLengths,
305  MaxNumIntProtosIn(Class) * sizeof(uint8_t));
306  memset(&Class->ProtoLengths[Index], 0,
307  sizeof(*Class->ProtoLengths) * (MaxNumIntProtosIn(Class) - Index));
308  }
309 
310  /* initialize proto so its length is zero and it isn't in any configs */
311  Class->ProtoLengths[Index] = 0;
312  Proto = ProtoForProtoId (Class, Index);
313  for (Word = Proto->Configs;
314  Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);
315 
316  return (Index);
317 }
uint32_t Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:86
void * Emalloc(int Size)
Definition: emalloc.cpp:31
#define ProtoForProtoId(C, P)
Definition: intproto.h:166
uint8_t NumProtoSets
Definition: intproto.h:107
uint8_t * ProtoLengths
Definition: intproto.h:110
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
#define MAX_NUM_PROTOS
Definition: intproto.h:48
#define MaxNumIntProtosIn(C)
Definition: intproto.h:163
struct PROTO_SET_STRUCT * PROTO_SET
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
uint16_t NumProtos
Definition: intproto.h:106
#define NO_PROTO
Definition: matchdefs.h:43
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68

◆ AddProtoToClassPruner()

void AddProtoToClassPruner ( PROTO  Proto,
CLASS_ID  ClassId,
INT_TEMPLATES  Templates 
)

This routine adds Proto to the class pruning tables for the specified class in Templates.

Globals:

  • classify_num_cp_levels number of levels used in the class pruner
    Parameters
    Protofloating-pt proto to add to class pruner
    ClassIdclass id corresponding to Proto
    Templatesset of templates containing class pruner
    Returns
    none

Definition at line 330 of file intproto.cpp.

333 {
334  CLASS_PRUNER_STRUCT* Pruner;
335  uint32_t ClassMask;
336  uint32_t ClassCount;
337  uint32_t WordIndex;
338  int Level;
339  float EndPad, SidePad, AnglePad;
340  TABLE_FILLER TableFiller;
341  FILL_SPEC FillSpec;
342 
343  Pruner = CPrunerFor (Templates, ClassId);
344  WordIndex = CPrunerWordIndexFor (ClassId);
345  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassId);
346 
347  for (Level = classify_num_cp_levels - 1; Level >= 0; Level--) {
348  GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);
349  ClassCount = CPrunerMaskFor (Level, ClassId);
350  InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);
351 
352  while (!FillerDone (&TableFiller)) {
353  GetNextFill(&TableFiller, &FillSpec);
354  DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
355  }
356  }
357 } /* AddProtoToClassPruner */
void InitTableFiller(float EndPad, float SidePad, float AnglePad, PROTO Proto, TABLE_FILLER *Filler)
Definition: intproto.cpp:1465
int classify_num_cp_levels
Definition: intproto.cpp:185
bool FillerDone(TABLE_FILLER *Filler)
Definition: intproto.cpp:1177
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
Definition: intproto.cpp:1415
#define CPrunerWordIndexFor(c)
Definition: intproto.h:180
#define CPrunerMaskFor(L, c)
Definition: intproto.h:182
void GetCPPadsForLevel(int Level, float *EndPad, float *SidePad, float *AnglePad)
Definition: intproto.cpp:1352
#define MAX_LEVEL
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, uint32_t ClassMask, uint32_t ClassCount, uint32_t WordIndex)
Definition: intproto.cpp:1137
#define CPrunerFor(T, c)
Definition: intproto.h:179

◆ AddProtoToProtoPruner()

void AddProtoToProtoPruner ( PROTO  Proto,
int  ProtoId,
INT_CLASS  Class,
bool  debug 
)

This routine updates the proto pruner lookup tables for Class to include a new proto identified by ProtoId and described by Proto.

Parameters
Protofloating-pt proto to be added to proto pruner
ProtoIdid of proto
Classinteger class that contains desired proto pruner
debugdebug flag
Note
Globals: none
Returns
none

Definition at line 370 of file intproto.cpp.

371  {
372  float Angle, X, Y, Length;
373  float Pad;
374  int Index;
375  PROTO_SET ProtoSet;
376 
377  if (ProtoId >= Class->NumProtos)
378  cprintf("AddProtoToProtoPruner:assert failed: %d < %d",
379  ProtoId, Class->NumProtos);
380  assert(ProtoId < Class->NumProtos);
381 
382  Index = IndexForProto (ProtoId);
383  ProtoSet = Class->ProtoSets[SetForProto (ProtoId)];
384 
385  Angle = Proto->Angle;
386 #ifndef _WIN32
387  assert(!std::isnan(Angle));
388 #endif
389 
390  FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index,
391  Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
392  debug);
393 
394  Angle *= 2.0 * M_PI;
395  Length = Proto->Length;
396 
397  X = Proto->X + X_SHIFT;
398  Pad = std::max(fabs (cos (Angle)) * (Length / 2.0 +
401  fabs (sin (Angle)) * (classify_pp_side_pad *
403 
404  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);
405 
406  Y = Proto->Y + Y_SHIFT;
407  Pad = std::max(fabs (sin (Angle)) * (Length / 2.0 +
410  fabs (cos (Angle)) * (classify_pp_side_pad *
412 
413  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);
414 } /* AddProtoToProtoPruner */
#define PRUNER_ANGLE
Definition: intproto.h:37
void cprintf(const char *format,...)
Definition: callcpp.cpp:33
float X
Definition: protos.h:46
#define PRUNER_X
Definition: intproto.h:35
double classify_pp_angle_pad
Definition: intproto.cpp:198
double classify_pp_end_pad
Definition: intproto.cpp:199
#define Y_SHIFT
Definition: intproto.h:42
float Y
Definition: protos.h:47
#define GetPicoFeatureLength()
Definition: picofeat.h:57
float Length
Definition: protos.h:49
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
#define ANGLE_SHIFT
Definition: intproto.h:40
double classify_pp_side_pad
Definition: intproto.cpp:200
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
#define SetForProto(P)
Definition: intproto.h:164
float Angle
Definition: protos.h:48
void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1201
#define IndexForProto(P)
Definition: intproto.h:165
#define X_SHIFT
Definition: intproto.h:41
uint16_t NumProtos
Definition: intproto.h:106
#define PRUNER_Y
Definition: intproto.h:36
void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1242

◆ Bucket16For()

uint16_t Bucket16For ( float  param,
float  offset,
int  num_buckets 
)

Definition at line 425 of file intproto.cpp.

425  {
426  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
427  return static_cast<uint16_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
428 }
#define MapParam(P, O, N)
Definition: intproto.cpp:120
int IntCastRounded(double x)
Definition: helpers.h:168

◆ Bucket8For()

uint8_t Bucket8For ( float  param,
float  offset,
int  num_buckets 
)

Returns a quantized bucket for the given param shifted by offset, notionally (param + offset) * num_buckets, but clipped and casted to the appropriate type.

Definition at line 421 of file intproto.cpp.

421  {
422  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
423  return static_cast<uint8_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
424 }
#define MapParam(P, O, N)
Definition: intproto.cpp:120
int IntCastRounded(double x)
Definition: helpers.h:168

◆ BucketEnd()

float BucketEnd ( int  Bucket,
float  Offset,
int  NumBuckets 
)

This routine returns the parameter value which corresponds to the end of the specified bucket. The bucket number should have been generated using the BucketFor() function with parameters Offset and NumBuckets.

Parameters
Bucketbucket whose end is to be computed
Offsetoffset used to map params to buckets
NumBucketstotal number of buckets
Returns
Param value corresponding to end position of Bucket.
Note
Globals: none

Definition at line 1121 of file intproto.cpp.

1121  {
1122  return (((float) (Bucket + 1) / NumBuckets) - Offset);
1123 } /* BucketEnd */

◆ BucketStart()

float BucketStart ( int  Bucket,
float  Offset,
int  NumBuckets 
)

This routine returns the parameter value which corresponds to the beginning of the specified bucket. The bucket number should have been generated using the BucketFor() function with parameters Offset and NumBuckets.

Parameters
Bucketbucket whose start is to be computed
Offsetoffset used to map params to buckets
NumBucketstotal number of buckets
Returns
Param value corresponding to start position of Bucket.
Note
Globals: none

Definition at line 1105 of file intproto.cpp.

1105  {
1106  return (((float) Bucket / NumBuckets) - Offset);
1107 
1108 } /* BucketStart */

◆ CircBucketFor()

uint8_t CircBucketFor ( float  param,
float  offset,
int  num_buckets 
)

Returns a quantized bucket for the given circular param shifted by offset, notionally (param + offset) * num_buckets, but modded and casted to the appropriate type.

Definition at line 435 of file intproto.cpp.

435  {
436  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
437  return static_cast<uint8_t>(Modulo(bucket, num_buckets));
438 } /* CircBucketFor */
int Modulo(int a, int b)
Definition: helpers.h:153
#define MapParam(P, O, N)
Definition: intproto.cpp:120
int IntCastRounded(double x)
Definition: helpers.h:168

◆ ConvertConfig()

void ConvertConfig ( BIT_VECTOR  Config,
int  ConfigId,
INT_CLASS  Class 
)

This operation updates the config vectors of all protos in Class to indicate that the protos with 1's in Config belong to a new configuration identified by ConfigId. It is assumed that the length of the Config bit vector is equal to the number of protos in Class.

Parameters
Configconfig to be added to class
ConfigIdid to be used for new config
Classclass to add new config to
Returns
none
Note
Globals: none

Definition at line 469 of file intproto.cpp.

469  {
470  int ProtoId;
471  INT_PROTO Proto;
472  int TotalLength;
473 
474  for (ProtoId = 0, TotalLength = 0;
475  ProtoId < Class->NumProtos; ProtoId++) {
476  if (test_bit(Config, ProtoId)) {
477  Proto = ProtoForProtoId(Class, ProtoId);
478  SET_BIT(Proto->Configs, ConfigId);
479  TotalLength += Class->ProtoLengths[ProtoId];
480  }
481  }
482  Class->ConfigLengths[ConfigId] = TotalLength;
483 } /* ConvertConfig */
CLUSTERCONFIG Config
uint32_t Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:86
#define ProtoForProtoId(C, P)
Definition: intproto.h:166
uint8_t * ProtoLengths
Definition: intproto.h:110
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:111
uint16_t NumProtos
Definition: intproto.h:106
#define test_bit(array, bit)
Definition: bitvec.h:61
#define SET_BIT(array, bit)
Definition: bitvec.h:57

◆ CreateFeatureSpaceWindow()

ScrollView* CreateFeatureSpaceWindow ( const char *  name,
int  xpos,
int  ypos 
)

Creates a window of the appropriate size for displaying elements in feature space.

Definition at line 1789 of file intproto.cpp.

1789  {
1790  return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
1791 }

◆ DisplayIntFeature()

void DisplayIntFeature ( const INT_FEATURE_STRUCT Feature,
float  Evidence 
)

This routine renders the specified feature into a global display list.

Globals:

  • FeatureShapes global display list for features
    Parameters
    Featurepico-feature to be displayed
    Evidencebest evidence for this feature (0-1)
    Returns
    none

Definition at line 599 of file intproto.cpp.

599  {
600  ScrollView::Color color = GetMatchColorFor(Evidence);
601  RenderIntFeature(IntMatchWindow, Feature, color);
602  if (FeatureDisplayWindow) {
603  RenderIntFeature(FeatureDisplayWindow, Feature, color);
604  }
605 } /* DisplayIntFeature */
ScrollView::Color GetMatchColorFor(float Evidence)
Definition: intproto.cpp:1391
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:177
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1628
ScrollView * IntMatchWindow
Definition: intproto.cpp:176

◆ DisplayIntProto()

void DisplayIntProto ( INT_CLASS  Class,
PROTO_ID  ProtoId,
float  Evidence 
)

This routine renders the specified proto into a global display list.

Globals:

  • ProtoShapes global display list for protos
    Parameters
    Classclass to take proto from
    ProtoIdid of proto in Class to be displayed
    Evidencetotal evidence for proto (0-1)
    Returns
    none

Definition at line 618 of file intproto.cpp.

618  {
619  ScrollView::Color color = GetMatchColorFor(Evidence);
620  RenderIntProto(IntMatchWindow, Class, ProtoId, color);
621  if (ProtoDisplayWindow) {
622  RenderIntProto(ProtoDisplayWindow, Class, ProtoId, color);
623  }
624 } /* DisplayIntProto */
ScrollView::Color GetMatchColorFor(float Evidence)
Definition: intproto.cpp:1391
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:178
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
Definition: intproto.cpp:1662
ScrollView * IntMatchWindow
Definition: intproto.cpp:176

◆ DoFill()

void DoFill ( FILL_SPEC FillSpec,
CLASS_PRUNER_STRUCT Pruner,
uint32_t  ClassMask,
uint32_t  ClassCount,
uint32_t  WordIndex 
)

This routine fills in the section of a class pruner corresponding to a single x value for a single proto of a class.

Parameters
FillSpecspecifies which bits to fill in pruner
Prunerclass pruner to be filled
ClassMaskindicates which bits to change in each word
ClassCountindicates what to change bits to
WordIndexindicates which word to change
Returns
none
Note
Globals: none

Definition at line 1137 of file intproto.cpp.

1141  {
1142  int X, Y, Angle;
1143  uint32_t OldWord;
1144 
1145  X = FillSpec->X;
1146  if (X < 0)
1147  X = 0;
1148  if (X >= NUM_CP_BUCKETS)
1149  X = NUM_CP_BUCKETS - 1;
1150 
1151  if (FillSpec->YStart < 0)
1152  FillSpec->YStart = 0;
1153  if (FillSpec->YEnd >= NUM_CP_BUCKETS)
1154  FillSpec->YEnd = NUM_CP_BUCKETS - 1;
1155 
1156  for (Y = FillSpec->YStart; Y <= FillSpec->YEnd; Y++)
1157  for (Angle = FillSpec->AngleStart;
1159  OldWord = Pruner->p[X][Y][Angle][WordIndex];
1160  if (ClassCount > (OldWord & ClassMask)) {
1161  OldWord &= ~ClassMask;
1162  OldWord |= ClassCount;
1163  Pruner->p[X][Y][Angle][WordIndex] = OldWord;
1164  }
1165  if (Angle == FillSpec->AngleEnd)
1166  break;
1167  }
1168 } /* DoFill */
#define TRUE
Definition: capi.h:51
int8_t YEnd
Definition: intproto.cpp:100
uint8_t AngleEnd
Definition: intproto.cpp:101
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:78
uint8_t AngleStart
Definition: intproto.cpp:101
int8_t YStart
Definition: intproto.cpp:100
#define NUM_CP_BUCKETS
Definition: intproto.h:53
int8_t X
Definition: intproto.cpp:99
#define CircularIncrement(i, r)
Definition: intproto.cpp:117

◆ FillerDone()

bool FillerDone ( TABLE_FILLER Filler)

Return TRUE if the specified table filler is done, i.e. if it has no more lines to fill.

Parameters
Fillertable filler to check if done
Returns
TRUE if no more lines to fill, FALSE otherwise.
Note
Globals: none

Definition at line 1177 of file intproto.cpp.

1177  {
1178  FILL_SWITCH *Next;
1179 
1180  Next = &(Filler->Switch[Filler->NextSwitch]);
1181 
1182  return Filler->X > Next->X && Next->Type == LastSwitch;
1183 
1184 } /* FillerDone */
SWITCH_TYPE Type
Definition: intproto.cpp:75
int8_t X
Definition: intproto.cpp:88
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:91
int8_t X
Definition: intproto.cpp:76
uint8_t NextSwitch
Definition: intproto.cpp:86

◆ FillPPCircularBits()

void FillPPCircularBits ( uint32_t  ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int  Bit,
float  Center,
float  Spread,
bool  debug 
)

This routine sets Bit in each bit vector whose bucket lies within the range Center +- Spread. The fill is done for a circular dimension, i.e. bucket 0 is adjacent to the last bucket. It is assumed that Center and Spread are expressed in a circular coordinate system whose range is 0 to 1.

Parameters
ParamTabletable of bit vectors, one per param bucket
Bitbit position in vectors to be filled
Centercenter of filled area
Spreadspread of filled area
debugdebug flag
Returns
none
Note
Globals: none

Definition at line 1201 of file intproto.cpp.

1202  {
1203  int i, FirstBucket, LastBucket;
1204 
1205  if (Spread > 0.5)
1206  Spread = 0.5;
1207 
1208  FirstBucket = static_cast<int>(std::floor((Center - Spread) * NUM_PP_BUCKETS));
1209  if (FirstBucket < 0)
1210  FirstBucket += NUM_PP_BUCKETS;
1211 
1212  LastBucket = static_cast<int>(std::floor((Center + Spread) * NUM_PP_BUCKETS));
1213  if (LastBucket >= NUM_PP_BUCKETS)
1214  LastBucket -= NUM_PP_BUCKETS;
1215  if (debug) tprintf("Circular fill from %d to %d", FirstBucket, LastBucket);
1216  for (i = FirstBucket; TRUE; CircularIncrement (i, NUM_PP_BUCKETS)) {
1217  SET_BIT (ParamTable[i], Bit);
1218 
1219  /* exit loop after we have set the bit for the last bucket */
1220  if (i == LastBucket)
1221  break;
1222  }
1223 
1224 } /* FillPPCircularBits */
#define TRUE
Definition: capi.h:51
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define NUM_PP_BUCKETS
Definition: intproto.h:52
#define CircularIncrement(i, r)
Definition: intproto.cpp:117
#define SET_BIT(array, bit)
Definition: bitvec.h:57

◆ FillPPLinearBits()

void FillPPLinearBits ( uint32_t  ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int  Bit,
float  Center,
float  Spread,
bool  debug 
)

This routine sets Bit in each bit vector whose bucket lies within the range Center +- Spread. The fill is done for a linear dimension, i.e. there is no wrap-around for this dimension. It is assumed that Center and Spread are expressed in a linear coordinate system whose range is approximately 0 to 1. Values outside this range will be clipped.

Parameters
ParamTabletable of bit vectors, one per param bucket
Bitbit number being filled
Centercenter of filled area
Spreadspread of filled area
debugdebug flag
Returns
none
Note
Globals: none

Definition at line 1242 of file intproto.cpp.

1243  {
1244  int i, FirstBucket, LastBucket;
1245 
1246  FirstBucket = static_cast<int>(std::floor((Center - Spread) * NUM_PP_BUCKETS));
1247  if (FirstBucket < 0)
1248  FirstBucket = 0;
1249 
1250  LastBucket = static_cast<int>(std::floor((Center + Spread) * NUM_PP_BUCKETS));
1251  if (LastBucket >= NUM_PP_BUCKETS)
1252  LastBucket = NUM_PP_BUCKETS - 1;
1253 
1254  if (debug) tprintf("Linear fill from %d to %d", FirstBucket, LastBucket);
1255  for (i = FirstBucket; i <= LastBucket; i++)
1256  SET_BIT (ParamTable[i], Bit);
1257 
1258 } /* FillPPLinearBits */
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
#define NUM_PP_BUCKETS
Definition: intproto.h:52
#define SET_BIT(array, bit)
Definition: bitvec.h:57

◆ free_int_templates()

void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 708 of file intproto.cpp.

708  {
709  int i;
710 
711  for (i = 0; i < templates->NumClasses; i++)
712  free_int_class(templates->Class[i]);
713  for (i = 0; i < templates->NumClassPruners; i++)
714  delete templates->ClassPruners[i];
715  Efree(templates);
716 }
INT_CLASS Class[MAX_NUM_CLASSES]
Definition: intproto.h:121
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:122
void Efree(void *ptr)
Definition: emalloc.cpp:45

◆ GetCPPadsForLevel()

void GetCPPadsForLevel ( int  Level,
float *  EndPad,
float *  SidePad,
float *  AnglePad 
)

This routine copies the appropriate global pad variables into EndPad, SidePad, and AnglePad. This is a kludge used to get around the fact that global control variables cannot be arrays. If the specified level is illegal, the tightest possible pads are returned.

Parameters
Level"tightness" level to return pads for
EndPadplace to put end pad for Level
SidePadplace to put side pad for Level
AnglePadplace to put angle pad for Level
Returns
none (results are returned in EndPad, SidePad, and AnglePad.
Note
Globals: none

Definition at line 1352 of file intproto.cpp.

1355  {
1356  switch (Level) {
1357  case 0:
1360  *AnglePad = classify_cp_angle_pad_loose / 360.0;
1361  break;
1362 
1363  case 1:
1366  *AnglePad = classify_cp_angle_pad_medium / 360.0;
1367  break;
1368 
1369  case 2:
1372  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1373  break;
1374 
1375  default:
1378  *AnglePad = classify_cp_angle_pad_tight / 360.0;
1379  break;
1380  }
1381  if (*AnglePad > 0.5)
1382  *AnglePad = 0.5;
1383 
1384 } /* GetCPPadsForLevel */
double classify_cp_angle_pad_loose
Definition: intproto.cpp:187
double classify_cp_angle_pad_medium
Definition: intproto.cpp:189
double classify_cp_angle_pad_tight
Definition: intproto.cpp:191
#define GetPicoFeatureLength()
Definition: picofeat.h:57
double classify_cp_end_pad_tight
Definition: intproto.cpp:194
double classify_cp_end_pad_medium
Definition: intproto.cpp:193
double classify_cp_side_pad_loose
Definition: intproto.cpp:195
double classify_cp_end_pad_loose
Definition: intproto.cpp:192
double classify_cp_side_pad_tight
Definition: intproto.cpp:197
double classify_cp_side_pad_medium
Definition: intproto.cpp:196

◆ GetMatchColorFor()

ScrollView::Color GetMatchColorFor ( float  Evidence)
Parameters
Evidenceevidence value to return color for
Returns
Color which corresponds to specified Evidence value.
Note
Globals: none

Definition at line 1391 of file intproto.cpp.

1391  {
1392  assert (Evidence >= 0.0);
1393  assert (Evidence <= 1.0);
1394 
1395  if (Evidence >= 0.90)
1396  return ScrollView::WHITE;
1397  else if (Evidence >= 0.75)
1398  return ScrollView::GREEN;
1399  else if (Evidence >= 0.50)
1400  return ScrollView::RED;
1401  else
1402  return ScrollView::BLUE;
1403 } /* GetMatchColorFor */

◆ GetNextFill()

void GetNextFill ( TABLE_FILLER Filler,
FILL_SPEC Fill 
)

This routine returns (in Fill) the specification of the next line to be filled from Filler. FillerDone() should always be called before GetNextFill() to ensure that we do not run past the end of the fill table.

Parameters
Fillerfiller to get next fill spec from
Fillplace to put spec for next fill
Returns
none (results are returned in Fill)
Note
Globals: none

Definition at line 1415 of file intproto.cpp.

1415  {
1416  FILL_SWITCH *Next;
1417 
1418  /* compute the fill assuming no switches will be encountered */
1419  Fill->AngleStart = Filler->AngleStart;
1420  Fill->AngleEnd = Filler->AngleEnd;
1421  Fill->X = Filler->X;
1422  Fill->YStart = Filler->YStart >> 8;
1423  Fill->YEnd = Filler->YEnd >> 8;
1424 
1425  /* update the fill info and the filler for ALL switches at this X value */
1426  Next = &(Filler->Switch[Filler->NextSwitch]);
1427  while (Filler->X >= Next->X) {
1428  Fill->X = Filler->X = Next->X;
1429  if (Next->Type == StartSwitch) {
1430  Fill->YStart = Next->Y;
1431  Filler->StartDelta = Next->Delta;
1432  Filler->YStart = Next->YInit;
1433  }
1434  else if (Next->Type == EndSwitch) {
1435  Fill->YEnd = Next->Y;
1436  Filler->EndDelta = Next->Delta;
1437  Filler->YEnd = Next->YInit;
1438  }
1439  else { /* Type must be LastSwitch */
1440  break;
1441  }
1442  Filler->NextSwitch++;
1443  Next = &(Filler->Switch[Filler->NextSwitch]);
1444  }
1445 
1446  /* prepare the filler for the next call to this routine */
1447  Filler->X++;
1448  Filler->YStart += Filler->StartDelta;
1449  Filler->YEnd += Filler->EndDelta;
1450 
1451 } /* GetNextFill */
SWITCH_TYPE Type
Definition: intproto.cpp:75
int8_t YEnd
Definition: intproto.cpp:100
int8_t X
Definition: intproto.cpp:88
int16_t Delta
Definition: intproto.cpp:78
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:91
int8_t Y
Definition: intproto.cpp:76
uint8_t AngleEnd
Definition: intproto.cpp:101
uint8_t AngleStart
Definition: intproto.cpp:87
int16_t StartDelta
Definition: intproto.cpp:90
int16_t YInit
Definition: intproto.cpp:77
int16_t EndDelta
Definition: intproto.cpp:90
int16_t YEnd
Definition: intproto.cpp:89
uint8_t AngleStart
Definition: intproto.cpp:101
int8_t YStart
Definition: intproto.cpp:100
int8_t X
Definition: intproto.cpp:76
uint8_t AngleEnd
Definition: intproto.cpp:87
int8_t X
Definition: intproto.cpp:99
uint8_t NextSwitch
Definition: intproto.cpp:86
int16_t YStart
Definition: intproto.cpp:89

◆ InitFeatureDisplayWindowIfReqd()

void InitFeatureDisplayWindowIfReqd ( )

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

Definition at line 1780 of file intproto.cpp.

1780  {
1781  if (FeatureDisplayWindow == nullptr) {
1782  FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
1783  50, 700);
1784  }
1785 }
ScrollView * FeatureDisplayWindow
Definition: intproto.cpp:177
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1789

◆ InitIntMatchWindowIfReqd()

void InitIntMatchWindowIfReqd ( )

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

Definition at line 1748 of file intproto.cpp.

1748  {
1749  if (IntMatchWindow == nullptr) {
1750  IntMatchWindow = CreateFeatureSpaceWindow("IntMatchWindow", 50, 200);
1751  SVMenuNode* popup_menu = new SVMenuNode();
1752 
1753  popup_menu->AddChild("Debug Adapted classes", IDA_ADAPTIVE,
1754  "x", "Class to debug");
1755  popup_menu->AddChild("Debug Static classes", IDA_STATIC,
1756  "x", "Class to debug");
1757  popup_menu->AddChild("Debug Both", IDA_BOTH,
1758  "x", "Class to debug");
1759  popup_menu->AddChild("Debug Shape Index", IDA_SHAPE_INDEX,
1760  "0", "Index to debug");
1761  popup_menu->BuildMenu(IntMatchWindow, false);
1762  }
1763 }
SVMenuNode * AddChild(const char *txt)
Definition: svmnode.cpp:58
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1789
ScrollView * IntMatchWindow
Definition: intproto.cpp:176
void BuildMenu(ScrollView *sv, bool menu_bar=true)
Definition: svmnode.cpp:120

◆ InitProtoDisplayWindowIfReqd()

void InitProtoDisplayWindowIfReqd ( )

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

Definition at line 1769 of file intproto.cpp.

1769  {
1770  if (ProtoDisplayWindow == nullptr) {
1771  ProtoDisplayWindow = CreateFeatureSpaceWindow("ProtoDisplayWindow",
1772  550, 200);
1773  }
1774 }
ScrollView * ProtoDisplayWindow
Definition: intproto.cpp:178
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1789

◆ InitTableFiller()

void InitTableFiller ( float  EndPad,
float  SidePad,
float  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
Returns
none (results are returned in Filler)
Note
Globals: none

Definition at line 1465 of file intproto.cpp.

1471 {
1472  float Angle;
1473  float X, Y, HalfLength;
1474  float Cos, Sin;
1475  float XAdjust, YAdjust;
1476  FPOINT Start, Switch1, Switch2, End;
1477  int S1 = 0;
1478  int S2 = 1;
1479 
1480  Angle = Proto->Angle;
1481  X = Proto->X;
1482  Y = Proto->Y;
1483  HalfLength = Proto->Length / 2.0;
1484 
1485  Filler->AngleStart = CircBucketFor(Angle - AnglePad, AS, NB);
1486  Filler->AngleEnd = CircBucketFor(Angle + AnglePad, AS, NB);
1487  Filler->NextSwitch = 0;
1488 
1489  if (fabs (Angle - 0.0) < HV_TOLERANCE || fabs (Angle - 0.5) < HV_TOLERANCE) {
1490  /* horizontal proto - handle as special case */
1491  Filler->X = Bucket8For(X - HalfLength - EndPad, XS, NB);
1492  Filler->YStart = Bucket16For(Y - SidePad, YS, NB * 256);
1493  Filler->YEnd = Bucket16For(Y + SidePad, YS, NB * 256);
1494  Filler->StartDelta = 0;
1495  Filler->EndDelta = 0;
1496  Filler->Switch[0].Type = LastSwitch;
1497  Filler->Switch[0].X = Bucket8For(X + HalfLength + EndPad, XS, NB);
1498  } else if (fabs(Angle - 0.25) < HV_TOLERANCE ||
1499  fabs(Angle - 0.75) < HV_TOLERANCE) {
1500  /* vertical proto - handle as special case */
1501  Filler->X = Bucket8For(X - SidePad, XS, NB);
1502  Filler->YStart = Bucket16For(Y - HalfLength - EndPad, YS, NB * 256);
1503  Filler->YEnd = Bucket16For(Y + HalfLength + EndPad, YS, NB * 256);
1504  Filler->StartDelta = 0;
1505  Filler->EndDelta = 0;
1506  Filler->Switch[0].Type = LastSwitch;
1507  Filler->Switch[0].X = Bucket8For(X + SidePad, XS, NB);
1508  } else {
1509  /* diagonal proto */
1510 
1511  if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) {
1512  /* rising diagonal proto */
1513  Angle *= 2.0 * M_PI;
1514  Cos = fabs(cos(Angle));
1515  Sin = fabs(sin(Angle));
1516 
1517  /* compute the positions of the corners of the acceptance region */
1518  Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1519  Start.y = Y - (HalfLength + EndPad) * Sin + SidePad * Cos;
1520  End.x = 2.0 * X - Start.x;
1521  End.y = 2.0 * Y - Start.y;
1522  Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1523  Switch1.y = Y - (HalfLength + EndPad) * Sin - SidePad * Cos;
1524  Switch2.x = 2.0 * X - Switch1.x;
1525  Switch2.y = 2.0 * Y - Switch1.y;
1526 
1527  if (Switch1.x > Switch2.x) {
1528  S1 = 1;
1529  S2 = 0;
1530  }
1531 
1532  /* translate into bucket positions and deltas */
1533  Filler->X = Bucket8For(Start.x, XS, NB);
1534  Filler->StartDelta = -(int16_t) ((Cos / Sin) * 256);
1535  Filler->EndDelta = (int16_t) ((Sin / Cos) * 256);
1536 
1537  XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1538  YAdjust = XAdjust * Cos / Sin;
1539  Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1540  YAdjust = XAdjust * Sin / Cos;
1541  Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1542 
1543  Filler->Switch[S1].Type = StartSwitch;
1544  Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1545  Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1546  XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1547  YAdjust = XAdjust * Sin / Cos;
1548  Filler->Switch[S1].YInit = Bucket16For(Switch1.y - YAdjust, YS, NB * 256);
1549  Filler->Switch[S1].Delta = Filler->EndDelta;
1550 
1551  Filler->Switch[S2].Type = EndSwitch;
1552  Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1553  Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1554  XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1555  YAdjust = XAdjust * Cos / Sin;
1556  Filler->Switch[S2].YInit = Bucket16For(Switch2.y + YAdjust, YS, NB * 256);
1557  Filler->Switch[S2].Delta = Filler->StartDelta;
1558 
1559  Filler->Switch[2].Type = LastSwitch;
1560  Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1561  } else {
1562  /* falling diagonal proto */
1563  Angle *= 2.0 * M_PI;
1564  Cos = fabs(cos(Angle));
1565  Sin = fabs(sin(Angle));
1566 
1567  /* compute the positions of the corners of the acceptance region */
1568  Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1569  Start.y = Y + (HalfLength + EndPad) * Sin - SidePad * Cos;
1570  End.x = 2.0 * X - Start.x;
1571  End.y = 2.0 * Y - Start.y;
1572  Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1573  Switch1.y = Y + (HalfLength + EndPad) * Sin + SidePad * Cos;
1574  Switch2.x = 2.0 * X - Switch1.x;
1575  Switch2.y = 2.0 * Y - Switch1.y;
1576 
1577  if (Switch1.x > Switch2.x) {
1578  S1 = 1;
1579  S2 = 0;
1580  }
1581 
1582  /* translate into bucket positions and deltas */
1583  Filler->X = Bucket8For(Start.x, XS, NB);
1584  Filler->StartDelta = static_cast<int16_t>(ClipToRange<int>(
1585  -IntCastRounded((Sin / Cos) * 256), INT16_MIN, INT16_MAX));
1586  Filler->EndDelta = static_cast<int16_t>(ClipToRange<int>(
1587  IntCastRounded((Cos / Sin) * 256), INT16_MIN, INT16_MAX));
1588 
1589  XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1590  YAdjust = XAdjust * Sin / Cos;
1591  Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1592  YAdjust = XAdjust * Cos / Sin;
1593  Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1594 
1595  Filler->Switch[S1].Type = EndSwitch;
1596  Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1597  Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1598  XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1599  YAdjust = XAdjust * Sin / Cos;
1600  Filler->Switch[S1].YInit = Bucket16For(Switch1.y + YAdjust, YS, NB * 256);
1601  Filler->Switch[S1].Delta = Filler->StartDelta;
1602 
1603  Filler->Switch[S2].Type = StartSwitch;
1604  Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1605  Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1606  XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1607  YAdjust = XAdjust * Cos / Sin;
1608  Filler->Switch[S2].YInit = Bucket16For(Switch2.y - YAdjust, YS, NB * 256);
1609  Filler->Switch[S2].Delta = Filler->EndDelta;
1610 
1611  Filler->Switch[2].Type = LastSwitch;
1612  Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1613  }
1614  }
1615 } /* InitTableFiller */
SWITCH_TYPE Type
Definition: intproto.cpp:75
uint16_t Bucket16For(float param, float offset, int num_buckets)
Definition: intproto.cpp:425
float X
Definition: protos.h:46
int8_t X
Definition: intproto.cpp:88
int16_t Delta
Definition: intproto.cpp:78
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:435
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:91
int8_t Y
Definition: intproto.cpp:76
Definition: fpoint.h:30
float Y
Definition: protos.h:47
float Length
Definition: protos.h:49
#define XS
#define HV_TOLERANCE
Definition: intproto.cpp:66
uint8_t AngleStart
Definition: intproto.cpp:87
int16_t StartDelta
Definition: intproto.cpp:90
float y
Definition: fpoint.h:31
int16_t YInit
Definition: intproto.cpp:77
int16_t EndDelta
Definition: intproto.cpp:90
int IntCastRounded(double x)
Definition: helpers.h:168
int16_t YEnd
Definition: intproto.cpp:89
float BucketEnd(int Bucket, float Offset, int NumBuckets)
Definition: intproto.cpp:1121
int8_t X
Definition: intproto.cpp:76
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:421
float BucketStart(int Bucket, float Offset, int NumBuckets)
Definition: intproto.cpp:1105
float Angle
Definition: protos.h:48
#define YS
uint8_t AngleEnd
Definition: intproto.cpp:87
#define AS
#define NB
uint8_t NextSwitch
Definition: intproto.cpp:86
int16_t YStart
Definition: intproto.cpp:89
float x
Definition: fpoint.h:31

◆ NewIntClass()

INT_CLASS NewIntClass ( int  MaxNumProtos,
int  MaxNumConfigs 
)

This routine creates a new integer class data structure and returns it. Sufficient space is allocated to handle the specified number of protos and configs.

Parameters
MaxNumProtosnumber of protos to allocate space for
MaxNumConfigsnumber of configs to allocate space for
Returns
New class created.
Note
Globals: none

Definition at line 636 of file intproto.cpp.

636  {
637  INT_CLASS Class;
638  PROTO_SET ProtoSet;
639  int i;
640 
641  assert(MaxNumConfigs <= MAX_NUM_CONFIGS);
642 
643  Class = (INT_CLASS) Emalloc(sizeof(INT_CLASS_STRUCT));
644  Class->NumProtoSets = ((MaxNumProtos + PROTOS_PER_PROTO_SET - 1) /
646 
647  assert(Class->NumProtoSets <= MAX_NUM_PROTO_SETS);
648 
649  Class->NumProtos = 0;
650  Class->NumConfigs = 0;
651 
652  for (i = 0; i < Class->NumProtoSets; i++) {
653  /* allocate space for a proto set, install in class, and initialize */
654  ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
655  memset(ProtoSet, 0, sizeof(*ProtoSet));
656  Class->ProtoSets[i] = ProtoSet;
657 
658  /* allocate space for the proto lengths and install in class */
659  }
660  if (MaxNumIntProtosIn (Class) > 0) {
661  Class->ProtoLengths =
662  (uint8_t *)Emalloc(MaxNumIntProtosIn (Class) * sizeof (uint8_t));
663  memset(Class->ProtoLengths, 0,
664  MaxNumIntProtosIn(Class) * sizeof(*Class->ProtoLengths));
665  } else {
666  Class->ProtoLengths = nullptr;
667  }
668  memset(Class->ConfigLengths, 0, sizeof(Class->ConfigLengths));
669 
670  return (Class);
671 
672 } /* NewIntClass */
struct INT_CLASS_STRUCT * INT_CLASS
void * Emalloc(int Size)
Definition: emalloc.cpp:31
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:50
uint8_t NumProtoSets
Definition: intproto.h:107
uint8_t * ProtoLengths
Definition: intproto.h:110
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
uint8_t NumConfigs
Definition: intproto.h:108
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
#define MaxNumIntProtosIn(C)
Definition: intproto.h:163
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:111
struct PROTO_SET_STRUCT * PROTO_SET
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:49
uint16_t NumProtos
Definition: intproto.h:106

◆ NewIntTemplates()

INT_TEMPLATES NewIntTemplates ( )

This routine allocates a new set of integer templates initialized to hold 0 classes.

Returns
The integer templates created.
Note
Globals: none

Definition at line 692 of file intproto.cpp.

692  {
693  INT_TEMPLATES T;
694  int i;
695 
696  T = (INT_TEMPLATES) Emalloc (sizeof (INT_TEMPLATES_STRUCT));
697  T->NumClasses = 0;
698  T->NumClassPruners = 0;
699 
700  for (i = 0; i < MAX_NUM_CLASSES; i++)
701  ClassForClassId (T, i) = nullptr;
702 
703  return (T);
704 } /* NewIntTemplates */
void * Emalloc(int Size)
Definition: emalloc.cpp:31
#define ClassForClassId(T, c)
Definition: intproto.h:176
#define MAX_NUM_CLASSES
Definition: matchdefs.h:32
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES

◆ RenderIntFeature()

void RenderIntFeature ( ScrollView window,
const INT_FEATURE_STRUCT Feature,
ScrollView::Color  color 
)

This routine renders the specified feature into ShapeList.

Parameters
windowto add feature rendering to
Featurefeature to be rendered
colorcolor to use for feature rendering
Returns
New shape list with rendering of Feature added.
Note
Globals: none

Definition at line 1628 of file intproto.cpp.

1629  {
1630  float X, Y, Dx, Dy, Length;
1631 
1632  window->Pen(color);
1633  assert(Feature != nullptr);
1634  assert(color != 0);
1635 
1636  X = Feature->X;
1637  Y = Feature->Y;
1638  Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
1639  // The -PI has no significant effect here, but the value of Theta is computed
1640  // using BinaryAnglePlusPi in intfx.cpp.
1641  Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1642  Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1643 
1644  window->SetCursor(X, Y);
1645  window->DrawTo(X + Dx, Y + Dy);
1646 } /* RenderIntFeature */
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:130
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
#define GetPicoFeatureLength()
Definition: picofeat.h:57
void Pen(Color color)
Definition: scrollview.cpp:722

◆ RenderIntProto()

void RenderIntProto ( ScrollView window,
INT_CLASS  Class,
PROTO_ID  ProtoId,
ScrollView::Color  color 
)

This routine extracts the parameters of the specified proto from the class description and adds a rendering of the proto onto the ShapeList.

Parameters
windowScrollView instance
Classclass that proto is contained in
ProtoIdid of proto to be rendered
colorcolor to render proto in

Globals: none

Returns
New shape list with a rendering of one proto added.

Definition at line 1662 of file intproto.cpp.

1665  {
1666  PROTO_SET ProtoSet;
1667  INT_PROTO Proto;
1668  int ProtoSetIndex;
1669  int ProtoWordIndex;
1670  float Length;
1671  int Xmin, Xmax, Ymin, Ymax;
1672  float X, Y, Dx, Dy;
1673  uint32_t ProtoMask;
1674  int Bucket;
1675 
1676  assert(ProtoId >= 0);
1677  assert(Class != nullptr);
1678  assert(ProtoId < Class->NumProtos);
1679  assert(color != 0);
1680  window->Pen(color);
1681 
1682  ProtoSet = Class->ProtoSets[SetForProto(ProtoId)];
1683  ProtoSetIndex = IndexForProto(ProtoId);
1684  Proto = &(ProtoSet->Protos[ProtoSetIndex]);
1685  Length = (Class->ProtoLengths[ProtoId] *
1687  ProtoMask = PPrunerMaskFor(ProtoId);
1688  ProtoWordIndex = PPrunerWordIndexFor(ProtoId);
1689 
1690  // find the x and y extent of the proto from the proto pruning table
1691  Xmin = Ymin = NUM_PP_BUCKETS;
1692  Xmax = Ymax = 0;
1693  for (Bucket = 0; Bucket < NUM_PP_BUCKETS; Bucket++) {
1694  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_X][Bucket][ProtoWordIndex]) {
1695  UpdateRange(Bucket, &Xmin, &Xmax);
1696  }
1697 
1698  if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_Y][Bucket][ProtoWordIndex]) {
1699  UpdateRange(Bucket, &Ymin, &Ymax);
1700  }
1701  }
1702  X = (Xmin + Xmax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1703  Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1704  // The -PI has no significant effect here, but the value of Theta is computed
1705  // using BinaryAnglePlusPi in intfx.cpp.
1706  Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
1707  Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
1708 
1709  window->SetCursor(X - Dx, Y - Dy);
1710  window->DrawTo(X + Dx, Y + Dy);
1711 } /* RenderIntProto */
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:130
#define PRUNER_X
Definition: intproto.h:35
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
uint8_t * ProtoLengths
Definition: intproto.h:110
#define GetPicoFeatureLength()
Definition: picofeat.h:57
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
Definition: intproto.h:97
#define PPrunerWordIndexFor(I)
Definition: intproto.h:168
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
#define SetForProto(P)
Definition: intproto.h:164
#define PROTO_PRUNER_SCALE
Definition: intproto.cpp:49
#define IndexForProto(P)
Definition: intproto.h:165
#define NUM_PP_BUCKETS
Definition: intproto.h:52
uint8_t Angle
Definition: intproto.h:85
#define PRUNER_Y
Definition: intproto.h:36
void Pen(Color color)
Definition: scrollview.cpp:722
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:121
#define PPrunerMaskFor(I)
Definition: intproto.h:171

◆ TruncateParam()

int TruncateParam ( float  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.

Definition at line 1727 of file intproto.cpp.

1727  {
1728  if (Param < Min) {
1729  if (Id)
1730  cprintf("Warning: Param %s truncated from %f to %d!\n",
1731  Id, Param, Min);
1732  Param = Min;
1733  } else if (Param > Max) {
1734  if (Id)
1735  cprintf("Warning: Param %s truncated from %f to %d!\n",
1736  Id, Param, Max);
1737  Param = Max;
1738  }
1739  return static_cast<int>(std::floor(Param));
1740 } /* TruncateParam */
void cprintf(const char *format,...)
Definition: callcpp.cpp:33

◆ UpdateMatchDisplay()

void UpdateMatchDisplay ( )

This routine clears the global feature and proto display lists.

Globals:

  • FeatureShapes display list for features
  • ProtoShapes display list for protos
    Returns
    none

Definition at line 451 of file intproto.cpp.

451  {
452  if (IntMatchWindow != nullptr)
454 } /* ClearMatchDisplay */
static void Update()
Definition: scrollview.cpp:711
ScrollView * IntMatchWindow
Definition: intproto.cpp:176

Variable Documentation

◆ classify_cp_angle_pad_loose

double classify_cp_angle_pad_loose = 45.0

"Class Pruner Angle Pad Loose"

Definition at line 187 of file intproto.cpp.

◆ classify_cp_angle_pad_medium

double classify_cp_angle_pad_medium = 20.0

"Class Pruner Angle Pad Medium"

Definition at line 189 of file intproto.cpp.

◆ classify_cp_angle_pad_tight

double classify_cp_angle_pad_tight = 10.0

"CLass Pruner Angle Pad Tight"

Definition at line 191 of file intproto.cpp.

◆ classify_cp_end_pad_loose

double classify_cp_end_pad_loose = 0.5

"Class Pruner End Pad Loose"

Definition at line 192 of file intproto.cpp.

◆ classify_cp_end_pad_medium

double classify_cp_end_pad_medium = 0.5

"Class Pruner End Pad Medium"

Definition at line 193 of file intproto.cpp.

◆ classify_cp_end_pad_tight

double classify_cp_end_pad_tight = 0.5

"Class Pruner End Pad Tight"

Definition at line 194 of file intproto.cpp.

◆ classify_cp_side_pad_loose

double classify_cp_side_pad_loose = 2.5

"Class Pruner Side Pad Loose"

Definition at line 195 of file intproto.cpp.

◆ classify_cp_side_pad_medium

double classify_cp_side_pad_medium = 1.2

"Class Pruner Side Pad Medium"

Definition at line 196 of file intproto.cpp.

◆ classify_cp_side_pad_tight

double classify_cp_side_pad_tight = 0.6

"Class Pruner Side Pad Tight"

Definition at line 197 of file intproto.cpp.

◆ classify_num_cp_levels

int classify_num_cp_levels = 3

"Number of Class Pruner Levels"

Definition at line 185 of file intproto.cpp.

◆ classify_pp_angle_pad

double classify_pp_angle_pad = 45.0

"Proto Pruner Angle Pad"

Definition at line 198 of file intproto.cpp.

◆ classify_pp_end_pad

double classify_pp_end_pad = 0.5

"Proto Prune End Pad"

Definition at line 199 of file intproto.cpp.

◆ classify_pp_side_pad

double classify_pp_side_pad = 2.5

"Proto Pruner Side Pad"

Definition at line 200 of file intproto.cpp.

◆ FeatureDisplayWindow

ScrollView* FeatureDisplayWindow = nullptr

Definition at line 177 of file intproto.cpp.

◆ IntMatchWindow

ScrollView* IntMatchWindow = nullptr

Definition at line 176 of file intproto.cpp.

◆ ProtoDisplayWindow

ScrollView* ProtoDisplayWindow = nullptr

Definition at line 178 of file intproto.cpp.