tesseract  5.0.0-alpha-619-ge9db
intproto.h File Reference
#include <tesseract/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
 
using INT_FEATURE = INT_FEATURE_STRUCT *
 
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 39 of file intproto.h.

◆ BITS_PER_CP_VECTOR

#define BITS_PER_CP_VECTOR   (CLASSES_PER_CP * NUM_BITS_PER_CLASS)

Definition at line 58 of file intproto.h.

◆ BITS_PER_WERD

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

Definition at line 44 of file intproto.h.

◆ CLASS_PRUNER_CLASS_MASK

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

Definition at line 55 of file intproto.h.

◆ CLASSES_PER_CP

#define CLASSES_PER_CP   32

Definition at line 53 of file intproto.h.

◆ CLASSES_PER_CP_WERD

#define CLASSES_PER_CP_WERD   (CLASSES_PER_CP / NUM_BITS_PER_CLASS)

Definition at line 56 of file intproto.h.

◆ ClassForClassId

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

Definition at line 177 of file intproto.h.

◆ ClassPrunersFor

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

Definition at line 178 of file intproto.h.

◆ CLIP_MATCH_EVIDENCE

#define CLIP_MATCH_EVIDENCE   0x020

Definition at line 192 of file intproto.h.

◆ ClipMatchEvidenceOn

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

Definition at line 200 of file intproto.h.

◆ CPrunerBitIndexFor

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

Definition at line 182 of file intproto.h.

◆ CPrunerFor

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

Definition at line 180 of file intproto.h.

◆ CPrunerIdFor

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

Definition at line 179 of file intproto.h.

◆ CPrunerMaskFor

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

Definition at line 183 of file intproto.h.

◆ CPrunerWordIndexFor

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

Definition at line 181 of file intproto.h.

◆ DISPLAY_FEATURE_MATCHES

#define DISPLAY_FEATURE_MATCHES   0x002

Definition at line 188 of file intproto.h.

◆ DISPLAY_PROTO_MATCHES

#define DISPLAY_PROTO_MATCHES   0x004

Definition at line 189 of file intproto.h.

◆ DisplayFeatureMatchesOn

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

Definition at line 196 of file intproto.h.

◆ DisplayProtoMatchesOn

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

Definition at line 197 of file intproto.h.

◆ IndexForProto

#define IndexForProto (   P)    (P % PROTOS_PER_PROTO_SET)

Definition at line 166 of file intproto.h.

◆ INT_CHAR_NORM_RANGE

#define INT_CHAR_NORM_RANGE   256

Definition at line 129 of file intproto.h.

◆ LegalClassId

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

Definition at line 175 of file intproto.h.

◆ MatchDebuggingOn

#define MatchDebuggingOn (   D)    (D)

Definition at line 194 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 59 of file intproto.h.

◆ MAX_NUM_CONFIGS

#define MAX_NUM_CONFIGS   64

Definition at line 46 of file intproto.h.

◆ MAX_NUM_INT_FEATURES

#define MAX_NUM_INT_FEATURES   512

Definition at line 128 of file intproto.h.

◆ MAX_NUM_PROTO_SETS

#define MAX_NUM_PROTO_SETS   (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)

Definition at line 49 of file intproto.h.

◆ MAX_NUM_PROTOS

#define MAX_NUM_PROTOS   512

Definition at line 47 of file intproto.h.

◆ MAX_PROTO_INDEX

#define MAX_PROTO_INDEX   24

Definition at line 43 of file intproto.h.

◆ MaxNumClassesIn

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

Definition at line 174 of file intproto.h.

◆ MaxNumIntProtosIn

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

Macros

Definition at line 164 of file intproto.h.

◆ NUM_BITS_PER_CLASS

#define NUM_BITS_PER_CLASS   2

Definition at line 54 of file intproto.h.

◆ NUM_CP_BUCKETS

#define NUM_CP_BUCKETS   24

Definition at line 52 of file intproto.h.

◆ NUM_PP_BUCKETS

#define NUM_PP_BUCKETS   64

Definition at line 51 of file intproto.h.

◆ NUM_PP_PARAMS

#define NUM_PP_PARAMS   3

Definition at line 50 of file intproto.h.

◆ PPrunerBitIndexFor

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

Definition at line 171 of file intproto.h.

◆ PPrunerMaskFor

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

Definition at line 172 of file intproto.h.

◆ PPrunerWordIndexFor

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

Definition at line 169 of file intproto.h.

◆ PRINT_FEATURE_MATCHES

#define PRINT_FEATURE_MATCHES   0x008

Definition at line 190 of file intproto.h.

◆ PRINT_MATCH_SUMMARY

#define PRINT_MATCH_SUMMARY   0x001

Definition at line 187 of file intproto.h.

◆ PRINT_PROTO_MATCHES

#define PRINT_PROTO_MATCHES   0x010

Definition at line 191 of file intproto.h.

◆ PrintFeatureMatchesOn

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

Definition at line 198 of file intproto.h.

◆ PrintMatchSummaryOn

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

Definition at line 195 of file intproto.h.

◆ PrintProtoMatchesOn

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

Definition at line 199 of file intproto.h.

◆ ProtoForProtoId

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

Definition at line 167 of file intproto.h.

◆ PROTOS_PER_PP_WERD

#define PROTOS_PER_PP_WERD   BITS_PER_WERD

Definition at line 57 of file intproto.h.

◆ PROTOS_PER_PROTO_SET

#define PROTOS_PER_PROTO_SET   64

Definition at line 48 of file intproto.h.

◆ PRUNER_ANGLE

#define PRUNER_ANGLE   2

Definition at line 36 of file intproto.h.

◆ PRUNER_X

#define PRUNER_X   0

Definition at line 34 of file intproto.h.

◆ PRUNER_Y

#define PRUNER_Y   1

Definition at line 35 of file intproto.h.

◆ SetForProto

#define SetForProto (   P)    (P / PROTOS_PER_PROTO_SET)

Definition at line 165 of file intproto.h.

◆ UnusedClassIdIn

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

Definition at line 176 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 67 of file intproto.h.

◆ WERDS_PER_CP

Definition at line 65 of file intproto.h.

◆ WERDS_PER_CP_VECTOR

#define WERDS_PER_CP_VECTOR   (BITS_PER_CP_VECTOR / BITS_PER_WERD)

Definition at line 61 of file intproto.h.

◆ WERDS_PER_PP

#define WERDS_PER_PP   (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)

Definition at line 64 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 62 of file intproto.h.

◆ X_SHIFT

#define X_SHIFT   (0.5)

Definition at line 40 of file intproto.h.

◆ Y_SHIFT

#define Y_SHIFT   (0.5)

Definition at line 41 of file intproto.h.

Typedef Documentation

◆ CONFIG_PRUNER

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

Definition at line 102 of file intproto.h.

◆ INT_CLASS

typedef struct INT_CLASS_STRUCT * INT_CLASS

◆ INT_FEATURE

Definition at line 149 of file intproto.h.

◆ INT_FEATURE_ARRAY

typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]

Definition at line 151 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 92 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 153 of file intproto.h.

154  {
155  IDA_ADAPTIVE,
156  IDA_STATIC,
158  IDA_BOTH

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 230 of file intproto.cpp.

231  {
232  int Pruner;
233 
234  assert (LegalClassId (ClassId));
235  if (ClassId != Templates->NumClasses) {
236  fprintf(stderr, "Please make sure that classes are added to templates");
237  fprintf(stderr, " in increasing order of ClassIds\n");
238  exit(1);
239  }
240  ClassForClassId (Templates, ClassId) = Class;
241  Templates->NumClasses++;
242 
243  if (Templates->NumClasses > MaxNumClassesIn (Templates)) {
244  Pruner = Templates->NumClassPruners++;
245  Templates->ClassPruners[Pruner] = new CLASS_PRUNER_STRUCT;
246  memset(Templates->ClassPruners[Pruner], 0, sizeof(CLASS_PRUNER_STRUCT));
247  }

◆ 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 260 of file intproto.cpp.

261  {
262  int Index;
263 
264  assert(Class->NumConfigs < MAX_NUM_CONFIGS);
265 
266  Index = Class->NumConfigs++;
267  Class->ConfigLengths[Index] = 0;
268  return Index;

◆ 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 281 of file intproto.cpp.

282  {
283  int Index;
284  int ProtoSetId;
285  PROTO_SET ProtoSet;
286  INT_PROTO Proto;
287  uint32_t *Word;
288 
289  if (Class->NumProtos >= MAX_NUM_PROTOS)
290  return (NO_PROTO);
291 
292  Index = Class->NumProtos++;
293 
294  if (Class->NumProtos > MaxNumIntProtosIn(Class)) {
295  ProtoSetId = Class->NumProtoSets++;
296 
297  ProtoSet = static_cast<PROTO_SET>(Emalloc(sizeof(PROTO_SET_STRUCT)));
298  Class->ProtoSets[ProtoSetId] = ProtoSet;
299  memset(ProtoSet, 0, sizeof(*ProtoSet));
300 
301  /* reallocate space for the proto lengths and install in class */
302  Class->ProtoLengths =
303  static_cast<uint8_t *>(Erealloc(Class->ProtoLengths,
304  MaxNumIntProtosIn(Class) * sizeof(uint8_t)));
305  memset(&Class->ProtoLengths[Index], 0,
306  sizeof(*Class->ProtoLengths) * (MaxNumIntProtosIn(Class) - Index));
307  }
308 
309  /* initialize proto so its length is zero and it isn't in any configs */
310  Class->ProtoLengths[Index] = 0;
311  Proto = ProtoForProtoId (Class, Index);
312  for (Word = Proto->Configs;
313  Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);
314 
315  return (Index);

◆ 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

Definition at line 327 of file intproto.cpp.

331 {
332  CLASS_PRUNER_STRUCT* Pruner;
333  uint32_t ClassMask;
334  uint32_t ClassCount;
335  uint32_t WordIndex;
336  int Level;
337  float EndPad, SidePad, AnglePad;
338  TABLE_FILLER TableFiller;
339  FILL_SPEC FillSpec;
340 
341  Pruner = CPrunerFor (Templates, ClassId);
342  WordIndex = CPrunerWordIndexFor (ClassId);
343  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassId);
344 
345  for (Level = classify_num_cp_levels - 1; Level >= 0; Level--) {
346  GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);
347  ClassCount = CPrunerMaskFor (Level, ClassId);
348  InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);
349 
350  while (!FillerDone (&TableFiller)) {
351  GetNextFill(&TableFiller, &FillSpec);
352  DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
353  }
354  }

◆ 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

Definition at line 366 of file intproto.cpp.

368  {
369  float Angle, X, Y, Length;
370  float Pad;
371  int Index;
372  PROTO_SET ProtoSet;
373 
374  if (ProtoId >= Class->NumProtos)
375  cprintf("AddProtoToProtoPruner:assert failed: %d < %d",
376  ProtoId, Class->NumProtos);
377  assert(ProtoId < Class->NumProtos);
378 
379  Index = IndexForProto (ProtoId);
380  ProtoSet = Class->ProtoSets[SetForProto (ProtoId)];
381 
382  Angle = Proto->Angle;
383 #ifndef _WIN32
384  assert(!std::isnan(Angle));
385 #endif
386 
387  FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index,
388  Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
389  debug);
390 
391  Angle *= 2.0 * M_PI;
392  Length = Proto->Length;
393 
394  X = Proto->X + X_SHIFT;
395  Pad = std::max(fabs (cos (Angle)) * (Length / 2.0 +
396  classify_pp_end_pad *
398  fabs (sin (Angle)) * (classify_pp_side_pad *
400 
401  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);
402 
403  Y = Proto->Y + Y_SHIFT;
404  Pad = std::max(fabs (sin (Angle)) * (Length / 2.0 +
405  classify_pp_end_pad *
407  fabs (cos (Angle)) * (classify_pp_side_pad *
409 
410  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);

◆ Bucket16For()

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

Definition at line 421 of file intproto.cpp.

422  {
423  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
424  return static_cast<uint16_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));

◆ 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 417 of file intproto.cpp.

418  {
419  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
420  return static_cast<uint8_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));

◆ 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 431 of file intproto.cpp.

432  {
433  int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
434  return static_cast<uint8_t>(Modulo(bucket, num_buckets));

◆ 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

Definition at line 462 of file intproto.cpp.

463  {
464  int ProtoId;
465  INT_PROTO Proto;
466  int TotalLength;
467 
468  for (ProtoId = 0, TotalLength = 0;
469  ProtoId < Class->NumProtos; ProtoId++) {
470  if (test_bit(Config, ProtoId)) {
471  Proto = ProtoForProtoId(Class, ProtoId);
472  SET_BIT(Proto->Configs, ConfigId);
473  TotalLength += Class->ProtoLengths[ProtoId];
474  }
475  }
476  Class->ConfigLengths[ConfigId] = TotalLength;

◆ 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 1764 of file intproto.cpp.

1765  {
1766  return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);

◆ 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)

Definition at line 589 of file intproto.cpp.

590  {
591  ScrollView::Color color = GetMatchColorFor(Evidence);
592  RenderIntFeature(IntMatchWindow, Feature, color);
593  if (FeatureDisplayWindow) {
594  RenderIntFeature(FeatureDisplayWindow, Feature, color);
595  }

◆ 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)

Definition at line 607 of file intproto.cpp.

608  {
609  ScrollView::Color color = GetMatchColorFor(Evidence);
610  RenderIntProto(IntMatchWindow, Class, ProtoId, color);
611  if (ProtoDisplayWindow) {
612  RenderIntProto(ProtoDisplayWindow, Class, ProtoId, color);
613  }

◆ free_int_templates()

void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 697 of file intproto.cpp.

698  {
699  int i;
700 
701  for (i = 0; i < templates->NumClasses; i++)
702  free_int_class(templates->Class[i]);
703  for (i = 0; i < templates->NumClassPruners; i++)
704  delete templates->ClassPruners[i];
705  Efree(templates);

◆ InitFeatureDisplayWindowIfReqd()

void InitFeatureDisplayWindowIfReqd ( )

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

Definition at line 1755 of file intproto.cpp.

1756  {
1757  if (FeatureDisplayWindow == nullptr) {
1758  FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
1759  50, 700);
1760  }

◆ InitIntMatchWindowIfReqd()

void InitIntMatchWindowIfReqd ( )

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

Definition at line 1723 of file intproto.cpp.

1724  {
1725  if (IntMatchWindow == nullptr) {
1726  IntMatchWindow = CreateFeatureSpaceWindow("IntMatchWindow", 50, 200);
1727  auto* popup_menu = new SVMenuNode();
1728 
1729  popup_menu->AddChild("Debug Adapted classes", IDA_ADAPTIVE,
1730  "x", "Class to debug");
1731  popup_menu->AddChild("Debug Static classes", IDA_STATIC,
1732  "x", "Class to debug");
1733  popup_menu->AddChild("Debug Both", IDA_BOTH,
1734  "x", "Class to debug");
1735  popup_menu->AddChild("Debug Shape Index", IDA_SHAPE_INDEX,
1736  "0", "Index to debug");
1737  popup_menu->BuildMenu(IntMatchWindow, false);
1738  }

◆ InitProtoDisplayWindowIfReqd()

void InitProtoDisplayWindowIfReqd ( )

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

Definition at line 1744 of file intproto.cpp.

1745  {
1746  if (ProtoDisplayWindow == nullptr) {
1747  ProtoDisplayWindow = CreateFeatureSpaceWindow("ProtoDisplayWindow",
1748  550, 200);
1749  }

◆ 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 625 of file intproto.cpp.

626  {
627  INT_CLASS Class;
628  PROTO_SET ProtoSet;
629  int i;
630 
631  assert(MaxNumConfigs <= MAX_NUM_CONFIGS);
632 
633  Class = static_cast<INT_CLASS>(Emalloc(sizeof(INT_CLASS_STRUCT)));
634  Class->NumProtoSets = ((MaxNumProtos + PROTOS_PER_PROTO_SET - 1) /
636 
637  assert(Class->NumProtoSets <= MAX_NUM_PROTO_SETS);
638 
639  Class->NumProtos = 0;
640  Class->NumConfigs = 0;
641 
642  for (i = 0; i < Class->NumProtoSets; i++) {
643  /* allocate space for a proto set, install in class, and initialize */
644  ProtoSet = static_cast<PROTO_SET>(Emalloc(sizeof(PROTO_SET_STRUCT)));
645  memset(ProtoSet, 0, sizeof(*ProtoSet));
646  Class->ProtoSets[i] = ProtoSet;
647 
648  /* allocate space for the proto lengths and install in class */
649  }
650  if (MaxNumIntProtosIn (Class) > 0) {
651  Class->ProtoLengths =
652  static_cast<uint8_t *>(Emalloc(MaxNumIntProtosIn (Class) * sizeof (uint8_t)));
653  memset(Class->ProtoLengths, 0,
654  MaxNumIntProtosIn(Class) * sizeof(*Class->ProtoLengths));
655  } else {
656  Class->ProtoLengths = nullptr;
657  }
658  memset(Class->ConfigLengths, 0, sizeof(Class->ConfigLengths));
659 
660  return (Class);
661 

◆ 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 681 of file intproto.cpp.

682  {
683  INT_TEMPLATES T;
684  int i;
685 
686  T = static_cast<INT_TEMPLATES>(Emalloc (sizeof (INT_TEMPLATES_STRUCT)));
687  T->NumClasses = 0;
688  T->NumClassPruners = 0;
689 
690  for (i = 0; i < MAX_NUM_CLASSES; i++)
691  ClassForClassId (T, i) = nullptr;
692 
693  return (T);

◆ 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 1603 of file intproto.cpp.

1605  {
1606  float X, Y, Dx, Dy, Length;
1607 
1608  window->Pen(color);
1609  assert(Feature != nullptr);
1610  assert(color != 0);
1611 
1612  X = Feature->X;
1613  Y = Feature->Y;
1614  Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
1615  // The -PI has no significant effect here, but the value of Theta is computed
1616  // using BinaryAnglePlusPi in intfx.cpp.
1617  Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1618  Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1619 
1620  window->SetCursor(X, Y);
1621  window->DrawTo(X + Dx, Y + Dy);

◆ 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

Definition at line 446 of file intproto.cpp.

447  {
448  if (IntMatchWindow != nullptr)
449  IntMatchWindow->Update();
INT_TEMPLATES_STRUCT
Definition: intproto.h:117
PROTO_STRUCT::Length
float Length
Definition: protos.h:41
INT_CLASS_STRUCT::ConfigLengths
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:110
ScrollView
Definition: scrollview.h:97
PROTOS_PER_PROTO_SET
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:48
PRUNER_ANGLE
#define PRUNER_ANGLE
Definition: intproto.h:36
IDA_SHAPE_INDEX
Definition: intproto.h:156
FILL_SPEC
Definition: intproto.cpp:95
GetMatchColorFor
ScrollView::Color GetMatchColorFor(float Evidence)
Definition: intproto.cpp:1371
FillPPLinearBits
void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1224
Emalloc
void * Emalloc(int Size)
Definition: emalloc.cpp:31
MAX_LEVEL
#define MAX_LEVEL
INT_CLASS_STRUCT
Definition: intproto.h:104
INT_FEATURE_STRUCT::Theta
uint8_t Theta
Definition: intproto.h:141
INT_PROTO_STRUCT
Definition: intproto.h:80
Config
CLUSTERCONFIG Config
Definition: commontraining.cpp:88
test_bit
#define test_bit(array, bit)
Definition: bitvec.h:58
INT_CHAR_NORM_RANGE
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:129
INT_PROTO_STRUCT::Configs
uint32_t Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:85
cprintf
void cprintf(const char *format,...)
Definition: callcpp.cpp:32
TABLE_FILLER
Definition: intproto.cpp:82
ScrollView::Pen
void Pen(Color color)
Definition: scrollview.cpp:717
ScrollView::DrawTo
void DrawTo(int x, int y)
Definition: scrollview.cpp:524
PRUNER_X
#define PRUNER_X
Definition: intproto.h:34
InitTableFiller
void InitTableFiller(float EndPad, float SidePad, float AnglePad, PROTO Proto, TABLE_FILLER *Filler)
Definition: intproto.cpp:1440
IntCastRounded
int IntCastRounded(double x)
Definition: helpers.h:173
MAX_NUM_PROTO_SETS
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:49
PROTO_SET_STRUCT::ProtoPruner
PROTO_PRUNER ProtoPruner
Definition: intproto.h:95
INT_CLASS_STRUCT::NumProtos
uint16_t NumProtos
Definition: intproto.h:105
GetNextFill
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
Definition: intproto.cpp:1393
PRUNER_Y
#define PRUNER_Y
Definition: intproto.h:35
INT_TEMPLATES_STRUCT::NumClassPruners
int NumClassPruners
Definition: intproto.h:119
CPrunerWordIndexFor
#define CPrunerWordIndexFor(c)
Definition: intproto.h:181
Y_SHIFT
#define Y_SHIFT
Definition: intproto.h:41
INT_CLASS_STRUCT::NumProtoSets
uint8_t NumProtoSets
Definition: intproto.h:106
IndexForProto
#define IndexForProto(P)
Definition: intproto.h:166
CPrunerMaskFor
#define CPrunerMaskFor(L, c)
Definition: intproto.h:183
LegalClassId
#define LegalClassId(c)
Definition: intproto.h:175
MAX_NUM_CONFIGS
#define MAX_NUM_CONFIGS
Definition: intproto.h:46
MAX_NUM_PROTOS
#define MAX_NUM_PROTOS
Definition: intproto.h:47
MAX_NUM_CLASSES
#define MAX_NUM_CLASSES
Definition: matchdefs.h:29
GetCPPadsForLevel
void GetCPPadsForLevel(int Level, float *EndPad, float *SidePad, float *AnglePad)
Definition: intproto.cpp:1332
NO_PROTO
#define NO_PROTO
Definition: matchdefs.h:40
INT_CLASS_STRUCT::ProtoLengths
uint8_t * ProtoLengths
Definition: intproto.h:109
PROTO_STRUCT::Y
float Y
Definition: protos.h:39
MaxNumIntProtosIn
#define MaxNumIntProtosIn(C)
Definition: intproto.h:164
MapParam
#define MapParam(P, O, N)
Definition: intproto.cpp:118
ANGLE_SHIFT
#define ANGLE_SHIFT
Definition: intproto.h:39
FillerDone
bool FillerDone(TABLE_FILLER *Filler)
Definition: intproto.cpp:1163
PROTO_STRUCT::X
float X
Definition: protos.h:38
INT_TEMPLATES_STRUCT::NumClasses
int NumClasses
Definition: intproto.h:118
CreateFeatureSpaceWindow
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1764
PROTO_STRUCT::Angle
float Angle
Definition: protos.h:40
INT_FEATURE_STRUCT::Y
uint8_t Y
Definition: intproto.h:140
WERDS_PER_CONFIG_VEC
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:67
DoFill
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, uint32_t ClassMask, uint32_t ClassCount, uint32_t WordIndex)
Definition: intproto.cpp:1123
IDA_STATIC
Definition: intproto.h:155
MaxNumClassesIn
#define MaxNumClassesIn(T)
Definition: intproto.h:174
INT_CLASS_STRUCT::ProtoSets
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:108
Erealloc
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
RenderIntProto
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
Definition: intproto.cpp:1637
SET_BIT
#define SET_BIT(array, bit)
Definition: bitvec.h:54
SetForProto
#define SetForProto(P)
Definition: intproto.h:165
INT_TEMPLATES_STRUCT::Class
INT_CLASS Class[MAX_NUM_CLASSES]
Definition: intproto.h:120
SVMenuNode
Definition: svmnode.h:35
PROTO_SET_STRUCT
Definition: intproto.h:94
FillPPCircularBits
void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1185
Efree
void Efree(void *ptr)
Definition: emalloc.cpp:45
CPrunerFor
#define CPrunerFor(T, c)
Definition: intproto.h:180
X_SHIFT
#define X_SHIFT
Definition: intproto.h:40
INT_TEMPLATES_STRUCT::ClassPruners
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:121
Modulo
int Modulo(int a, int b)
Definition: helpers.h:156
CLASS_PRUNER_STRUCT
Definition: intproto.h:75
ScrollView::Update
static void Update()
Definition: scrollview.cpp:708
ScrollView::SetCursor
void SetCursor(int x, int y)
Definition: scrollview.cpp:518
IDA_BOTH
Definition: intproto.h:157
ProtoForProtoId
#define ProtoForProtoId(C, P)
Definition: intproto.h:167
INT_CLASS_STRUCT::NumConfigs
uint8_t NumConfigs
Definition: intproto.h:107
ScrollView::Color
Color
Definition: scrollview.h:100
INT_FEATURE_STRUCT::X
uint8_t X
Definition: intproto.h:139
ClassForClassId
#define ClassForClassId(T, c)
Definition: intproto.h:177
IDA_ADAPTIVE
Definition: intproto.h:154
RenderIntFeature
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1603
GetPicoFeatureLength
#define GetPicoFeatureLength()
Definition: picofeat.h:56