tesseract  4.0.0-1-g2a2b
intproto.h File Reference
#include "genericvector.h"
#include "matchdefs.h"
#include "mfoutline.h"
#include "protos.h"
#include "scrollview.h"
#include "unicharset.h"

Go to the source code of this file.

Classes

struct  CLASS_PRUNER_STRUCT
 
struct  INT_PROTO_STRUCT
 
struct  PROTO_SET_STRUCT
 
struct  INT_CLASS_STRUCT
 
struct  INT_TEMPLATES_STRUCT
 
struct  INT_FEATURE_STRUCT
 

Namespaces

 tesseract
 

Macros

#define PRUNER_X   0
 
#define PRUNER_Y   1
 
#define PRUNER_ANGLE   2
 
#define ANGLE_SHIFT   (0.0)
 
#define X_SHIFT   (0.5)
 
#define Y_SHIFT   (0.5)
 
#define MAX_PROTO_INDEX   24
 
#define BITS_PER_WERD   static_cast<int>(8 * sizeof(uint32_t))
 
#define MAX_NUM_CONFIGS   64
 
#define MAX_NUM_PROTOS   512
 
#define PROTOS_PER_PROTO_SET   64
 
#define MAX_NUM_PROTO_SETS   (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
 
#define NUM_PP_PARAMS   3
 
#define NUM_PP_BUCKETS   64
 
#define NUM_CP_BUCKETS   24
 
#define CLASSES_PER_CP   32
 
#define NUM_BITS_PER_CLASS   2
 
#define CLASS_PRUNER_CLASS_MASK   (~(~0u << NUM_BITS_PER_CLASS))
 
#define CLASSES_PER_CP_WERD   (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
 
#define PROTOS_PER_PP_WERD   BITS_PER_WERD
 
#define BITS_PER_CP_VECTOR   (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
 
#define MAX_NUM_CLASS_PRUNERS   ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP)
 
#define WERDS_PER_CP_VECTOR   (BITS_PER_CP_VECTOR / BITS_PER_WERD)
 
#define WERDS_PER_PP_VECTOR   ((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD)
 
#define WERDS_PER_PP   (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)
 
#define WERDS_PER_CP   (NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
 
#define WERDS_PER_CONFIG_VEC   ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / BITS_PER_WERD)
 
#define MAX_NUM_INT_FEATURES   512
 
#define INT_CHAR_NORM_RANGE   256
 
#define MaxNumIntProtosIn(C)   (C->NumProtoSets * PROTOS_PER_PROTO_SET)
 
#define SetForProto(P)   (P / PROTOS_PER_PROTO_SET)
 
#define IndexForProto(P)   (P % PROTOS_PER_PROTO_SET)
 
#define ProtoForProtoId(C, P)   (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))
 
#define PPrunerWordIndexFor(I)   (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)
 
#define PPrunerBitIndexFor(I)   ((I) % PROTOS_PER_PP_WERD)
 
#define PPrunerMaskFor(I)   (1 << PPrunerBitIndexFor(I))
 
#define MaxNumClassesIn(T)   (T->NumClassPruners * CLASSES_PER_CP)
 
#define LegalClassId(c)   ((c) >= 0 && (c) <= MAX_CLASS_ID)
 
#define UnusedClassIdIn(T, c)   ((T)->Class[c] == nullptr)
 
#define ClassForClassId(T, c)   ((T)->Class[c])
 
#define ClassPrunersFor(T)   ((T)->ClassPruner)
 
#define CPrunerIdFor(c)   ((c) / CLASSES_PER_CP)
 
#define CPrunerFor(T, c)   ((T)->ClassPruners[CPrunerIdFor(c)])
 
#define CPrunerWordIndexFor(c)   (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
 
#define CPrunerBitIndexFor(c)   (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
 
#define CPrunerMaskFor(L, c)   (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)
 
#define PRINT_MATCH_SUMMARY   0x001
 
#define DISPLAY_FEATURE_MATCHES   0x002
 
#define DISPLAY_PROTO_MATCHES   0x004
 
#define PRINT_FEATURE_MATCHES   0x008
 
#define PRINT_PROTO_MATCHES   0x010
 
#define CLIP_MATCH_EVIDENCE   0x020
 
#define MatchDebuggingOn(D)   (D)
 
#define PrintMatchSummaryOn(D)   ((D)&PRINT_MATCH_SUMMARY)
 
#define DisplayFeatureMatchesOn(D)   ((D)&DISPLAY_FEATURE_MATCHES)
 
#define DisplayProtoMatchesOn(D)   ((D)&DISPLAY_PROTO_MATCHES)
 
#define PrintFeatureMatchesOn(D)   ((D)&PRINT_FEATURE_MATCHES)
 
#define PrintProtoMatchesOn(D)   ((D)&PRINT_PROTO_MATCHES)
 
#define ClipMatchEvidenceOn(D)   ((D)&CLIP_MATCH_EVIDENCE)
 

Typedefs

typedef struct INT_PROTO_STRUCTINT_PROTO
 
typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
 
typedef struct PROTO_SET_STRUCTPROTO_SET
 
typedef uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
 
typedef struct INT_CLASS_STRUCTINT_CLASS
 
typedef struct INT_TEMPLATES_STRUCTINT_TEMPLATES
 
typedef INT_FEATURE_STRUCTINT_FEATURE
 
typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
 

Enumerations

enum  IntmatcherDebugAction { IDA_ADAPTIVE, IDA_STATIC, IDA_SHAPE_INDEX, IDA_BOTH }
 

Functions

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 ShowMatchDisplay ()
 
void tesseract::ClearFeatureSpaceWindow (NORM_METHOD norm_method, ScrollView *window)
 
void RenderIntFeature (ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
 
void InitIntMatchWindowIfReqd ()
 
void InitProtoDisplayWindowIfReqd ()
 
void InitFeatureDisplayWindowIfReqd ()
 
ScrollViewCreateFeatureSpaceWindow (const char *name, int xpos, int ypos)
 

Macro Definition Documentation

◆ ANGLE_SHIFT

#define ANGLE_SHIFT   (0.0)

Definition at line 40 of file intproto.h.

◆ BITS_PER_CP_VECTOR

#define BITS_PER_CP_VECTOR   (CLASSES_PER_CP * NUM_BITS_PER_CLASS)

Definition at line 59 of file intproto.h.

◆ BITS_PER_WERD

#define BITS_PER_WERD   static_cast<int>(8 * sizeof(uint32_t))

Definition at line 45 of file intproto.h.

◆ CLASS_PRUNER_CLASS_MASK

#define CLASS_PRUNER_CLASS_MASK   (~(~0u << NUM_BITS_PER_CLASS))

Definition at line 56 of file intproto.h.

◆ CLASSES_PER_CP

#define CLASSES_PER_CP   32

Definition at line 54 of file intproto.h.

◆ CLASSES_PER_CP_WERD

#define CLASSES_PER_CP_WERD   (CLASSES_PER_CP / NUM_BITS_PER_CLASS)

Definition at line 57 of file intproto.h.

◆ ClassForClassId

#define ClassForClassId (   T,
 
)    ((T)->Class[c])

Definition at line 176 of file intproto.h.

◆ ClassPrunersFor

#define ClassPrunersFor (   T)    ((T)->ClassPruner)

Definition at line 177 of file intproto.h.

◆ CLIP_MATCH_EVIDENCE

#define CLIP_MATCH_EVIDENCE   0x020

Definition at line 191 of file intproto.h.

◆ ClipMatchEvidenceOn

#define ClipMatchEvidenceOn (   D)    ((D)&CLIP_MATCH_EVIDENCE)

Definition at line 199 of file intproto.h.

◆ CPrunerBitIndexFor

#define CPrunerBitIndexFor (   c)    (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)

Definition at line 181 of file intproto.h.

◆ CPrunerFor

#define CPrunerFor (   T,
 
)    ((T)->ClassPruners[CPrunerIdFor(c)])

Definition at line 179 of file intproto.h.

◆ CPrunerIdFor

#define CPrunerIdFor (   c)    ((c) / CLASSES_PER_CP)

Definition at line 178 of file intproto.h.

◆ CPrunerMaskFor

#define CPrunerMaskFor (   L,
 
)    (((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)

Definition at line 182 of file intproto.h.

◆ CPrunerWordIndexFor

#define CPrunerWordIndexFor (   c)    (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)

Definition at line 180 of file intproto.h.

◆ DISPLAY_FEATURE_MATCHES

#define DISPLAY_FEATURE_MATCHES   0x002

Definition at line 187 of file intproto.h.

◆ DISPLAY_PROTO_MATCHES

#define DISPLAY_PROTO_MATCHES   0x004

Definition at line 188 of file intproto.h.

◆ DisplayFeatureMatchesOn

#define DisplayFeatureMatchesOn (   D)    ((D)&DISPLAY_FEATURE_MATCHES)

Definition at line 195 of file intproto.h.

◆ DisplayProtoMatchesOn

#define DisplayProtoMatchesOn (   D)    ((D)&DISPLAY_PROTO_MATCHES)

Definition at line 196 of file intproto.h.

◆ IndexForProto

#define IndexForProto (   P)    (P % PROTOS_PER_PROTO_SET)

Definition at line 165 of file intproto.h.

◆ INT_CHAR_NORM_RANGE

#define INT_CHAR_NORM_RANGE   256

Definition at line 130 of file intproto.h.

◆ LegalClassId

#define LegalClassId (   c)    ((c) >= 0 && (c) <= MAX_CLASS_ID)

Definition at line 174 of file intproto.h.

◆ MatchDebuggingOn

#define MatchDebuggingOn (   D)    (D)

Definition at line 193 of file intproto.h.

◆ MAX_NUM_CLASS_PRUNERS

#define MAX_NUM_CLASS_PRUNERS   ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP)

Definition at line 60 of file intproto.h.

◆ MAX_NUM_CONFIGS

#define MAX_NUM_CONFIGS   64

Definition at line 47 of file intproto.h.

◆ MAX_NUM_INT_FEATURES

#define MAX_NUM_INT_FEATURES   512

Definition at line 129 of file intproto.h.

◆ MAX_NUM_PROTO_SETS

#define MAX_NUM_PROTO_SETS   (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)

Definition at line 50 of file intproto.h.

◆ MAX_NUM_PROTOS

#define MAX_NUM_PROTOS   512

Definition at line 48 of file intproto.h.

◆ MAX_PROTO_INDEX

#define MAX_PROTO_INDEX   24

Definition at line 44 of file intproto.h.

◆ MaxNumClassesIn

#define MaxNumClassesIn (   T)    (T->NumClassPruners * CLASSES_PER_CP)

Definition at line 173 of file intproto.h.

◆ MaxNumIntProtosIn

#define MaxNumIntProtosIn (   C)    (C->NumProtoSets * PROTOS_PER_PROTO_SET)

Macros

Definition at line 163 of file intproto.h.

◆ NUM_BITS_PER_CLASS

#define NUM_BITS_PER_CLASS   2

Definition at line 55 of file intproto.h.

◆ NUM_CP_BUCKETS

#define NUM_CP_BUCKETS   24

Definition at line 53 of file intproto.h.

◆ NUM_PP_BUCKETS

#define NUM_PP_BUCKETS   64

Definition at line 52 of file intproto.h.

◆ NUM_PP_PARAMS

#define NUM_PP_PARAMS   3

Definition at line 51 of file intproto.h.

◆ PPrunerBitIndexFor

#define PPrunerBitIndexFor (   I)    ((I) % PROTOS_PER_PP_WERD)

Definition at line 170 of file intproto.h.

◆ PPrunerMaskFor

#define PPrunerMaskFor (   I)    (1 << PPrunerBitIndexFor(I))

Definition at line 171 of file intproto.h.

◆ PPrunerWordIndexFor

#define PPrunerWordIndexFor (   I)    (((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)

Definition at line 168 of file intproto.h.

◆ PRINT_FEATURE_MATCHES

#define PRINT_FEATURE_MATCHES   0x008

Definition at line 189 of file intproto.h.

◆ PRINT_MATCH_SUMMARY

#define PRINT_MATCH_SUMMARY   0x001

Definition at line 186 of file intproto.h.

◆ PRINT_PROTO_MATCHES

#define PRINT_PROTO_MATCHES   0x010

Definition at line 190 of file intproto.h.

◆ PrintFeatureMatchesOn

#define PrintFeatureMatchesOn (   D)    ((D)&PRINT_FEATURE_MATCHES)

Definition at line 197 of file intproto.h.

◆ PrintMatchSummaryOn

#define PrintMatchSummaryOn (   D)    ((D)&PRINT_MATCH_SUMMARY)

Definition at line 194 of file intproto.h.

◆ PrintProtoMatchesOn

#define PrintProtoMatchesOn (   D)    ((D)&PRINT_PROTO_MATCHES)

Definition at line 198 of file intproto.h.

◆ ProtoForProtoId

#define ProtoForProtoId (   C,
 
)    (&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))

Definition at line 166 of file intproto.h.

◆ PROTOS_PER_PP_WERD

#define PROTOS_PER_PP_WERD   BITS_PER_WERD

Definition at line 58 of file intproto.h.

◆ PROTOS_PER_PROTO_SET

#define PROTOS_PER_PROTO_SET   64

Definition at line 49 of file intproto.h.

◆ PRUNER_ANGLE

#define PRUNER_ANGLE   2

Definition at line 37 of file intproto.h.

◆ PRUNER_X

#define PRUNER_X   0

Definition at line 35 of file intproto.h.

◆ PRUNER_Y

#define PRUNER_Y   1

Definition at line 36 of file intproto.h.

◆ SetForProto

#define SetForProto (   P)    (P / PROTOS_PER_PROTO_SET)

Definition at line 164 of file intproto.h.

◆ UnusedClassIdIn

#define UnusedClassIdIn (   T,
 
)    ((T)->Class[c] == nullptr)

Definition at line 175 of file intproto.h.

◆ WERDS_PER_CONFIG_VEC

#define WERDS_PER_CONFIG_VEC   ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / BITS_PER_WERD)

Definition at line 68 of file intproto.h.

◆ WERDS_PER_CP

Definition at line 66 of file intproto.h.

◆ WERDS_PER_CP_VECTOR

#define WERDS_PER_CP_VECTOR   (BITS_PER_CP_VECTOR / BITS_PER_WERD)

Definition at line 62 of file intproto.h.

◆ WERDS_PER_PP

#define WERDS_PER_PP   (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)

Definition at line 65 of file intproto.h.

◆ WERDS_PER_PP_VECTOR

#define WERDS_PER_PP_VECTOR   ((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD)

Definition at line 63 of file intproto.h.

◆ X_SHIFT

#define X_SHIFT   (0.5)

Definition at line 41 of file intproto.h.

◆ Y_SHIFT

#define Y_SHIFT   (0.5)

Definition at line 42 of file intproto.h.

Typedef Documentation

◆ CONFIG_PRUNER

typedef uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]

Definition at line 103 of file intproto.h.

◆ INT_CLASS

typedef struct INT_CLASS_STRUCT * INT_CLASS

◆ INT_FEATURE

Definition at line 148 of file intproto.h.

◆ INT_FEATURE_ARRAY

typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]

Definition at line 150 of file intproto.h.

◆ INT_PROTO

typedef struct INT_PROTO_STRUCT * INT_PROTO

◆ INT_TEMPLATES

◆ PROTO_PRUNER

typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]

Definition at line 93 of file intproto.h.

◆ PROTO_SET

typedef struct PROTO_SET_STRUCT * PROTO_SET

Enumeration Type Documentation

◆ IntmatcherDebugAction

Enumerator
IDA_ADAPTIVE 
IDA_STATIC 
IDA_SHAPE_INDEX 
IDA_BOTH 

Definition at line 152 of file intproto.h.

152  {
153  IDA_ADAPTIVE,
154  IDA_STATIC,
156  IDA_BOTH
157 };

Function Documentation

◆ AddIntClass()

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

Public Function Prototypes

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ ShowMatchDisplay()

void ShowMatchDisplay ( )

◆ 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