tesseract 4.1.1
Loading...
Searching...
No Matches
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 "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

namespace  tesseract
 

Macros

#define _USE_MATH_DEFINES
 
#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)
 

Macro Definition Documentation

◆ _USE_MATH_DEFINES

#define _USE_MATH_DEFINES

Definition at line 21 of file intproto.cpp.

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

◆ INT_BASELINE

#define INT_BASELINE   (0.25 * INT_CHAR_NORM_RANGE)

Definition at line 51 of file intproto.cpp.

◆ INT_CAPHEIGHT

#define INT_CAPHEIGHT   (1.0 * INT_CHAR_NORM_RANGE)

Definition at line 53 of file intproto.cpp.

◆ INT_DESCENDER

#define INT_DESCENDER   (0.0 * INT_CHAR_NORM_RANGE)

Definition at line 50 of file intproto.cpp.

◆ INT_MAX_X

#define INT_MAX_X   INT_CHAR_NORM_RANGE

Definition at line 61 of file intproto.cpp.

◆ INT_MAX_Y

#define INT_MAX_Y   INT_CHAR_NORM_RANGE

Definition at line 62 of file intproto.cpp.

◆ INT_MIN_X

#define INT_MIN_X   0

Definition at line 59 of file intproto.cpp.

◆ INT_MIN_Y

#define INT_MIN_Y   0

Definition at line 60 of file intproto.cpp.

◆ INT_XCENTER

#define INT_XCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 55 of file intproto.cpp.

◆ INT_XHEIGHT

#define INT_XHEIGHT   (0.75 * INT_CHAR_NORM_RANGE)

Definition at line 52 of file intproto.cpp.

◆ INT_XRADIUS

#define INT_XRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

Definition at line 57 of file intproto.cpp.

◆ INT_YCENTER

#define INT_YCENTER   (0.5 * INT_CHAR_NORM_RANGE)

Definition at line 56 of file intproto.cpp.

◆ INT_YRADIUS

#define INT_YRADIUS   (0.2 * INT_CHAR_NORM_RANGE)

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

◆ MAX_LEVEL

#define MAX_LEVEL   2

◆ MAX_NUM_SWITCHES

#define MAX_NUM_SWITCHES   3

Definition at line 70 of file intproto.cpp.

◆ NB

#define NB   NUM_CP_BUCKETS

◆ OLD_MAX_NUM_CONFIGS

#define OLD_MAX_NUM_CONFIGS   32

Definition at line 108 of file intproto.cpp.

◆ OLD_WERDS_PER_CONFIG_VEC

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

Definition at line 109 of file intproto.cpp.

◆ PROTO_PRUNER_SCALE

#define PROTO_PRUNER_SCALE   (4.0)

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

@ StartSwitch
Definition: intproto.cpp:68
@ EndSwitch
Definition: intproto.cpp:68
@ LastSwitch
Definition: intproto.cpp:68

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 231 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 }
248} /* AddIntClass */
#define ClassForClassId(T, c)
Definition: intproto.h:178
#define LegalClassId(c)
Definition: intproto.h:176
#define MaxNumClassesIn(T)
Definition: intproto.h:175
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
Definition: intproto.h:122

◆ 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 261 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;
269} /* AddIntConfig */
#define MAX_NUM_CONFIGS
Definition: intproto.h:47
uint16_t ConfigLengths[MAX_NUM_CONFIGS]
Definition: intproto.h:111
uint8_t NumConfigs
Definition: intproto.h:108

◆ 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 282 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);
316}
#define MaxNumIntProtosIn(C)
Definition: intproto.h:165
#define MAX_NUM_PROTOS
Definition: intproto.h:48
#define WERDS_PER_CONFIG_VEC
Definition: intproto.h:68
#define ProtoForProtoId(C, P)
Definition: intproto.h:168
void * Erealloc(void *ptr, int size)
Definition: emalloc.cpp:38
void * Emalloc(int Size)
Definition: emalloc.cpp:31
#define NO_PROTO
Definition: matchdefs.h:41
uint32_t Configs[WERDS_PER_CONFIG_VEC]
Definition: intproto.h:86
uint8_t NumProtoSets
Definition: intproto.h:107
uint16_t NumProtos
Definition: intproto.h:106
uint8_t * ProtoLengths
Definition: intproto.h:110
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
Definition: intproto.h:109

◆ 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 328 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 }
355} /* AddProtoToClassPruner */
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
Definition: intproto.cpp:1392
void GetCPPadsForLevel(int Level, float *EndPad, float *SidePad, float *AnglePad)
Definition: intproto.cpp:1331
#define MAX_LEVEL
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, uint32_t ClassMask, uint32_t ClassCount, uint32_t WordIndex)
Definition: intproto.cpp:1122
void InitTableFiller(float EndPad, float SidePad, float AnglePad, PROTO Proto, TABLE_FILLER *Filler)
Definition: intproto.cpp:1439
bool FillerDone(TABLE_FILLER *Filler)
Definition: intproto.cpp:1162
#define CPrunerWordIndexFor(c)
Definition: intproto.h:182
#define CPrunerMaskFor(L, c)
Definition: intproto.h:184
#define CPrunerFor(T, c)
Definition: intproto.h:181

◆ 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 367 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
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);
411} /* AddProtoToProtoPruner */
void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1223
void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug)
Definition: intproto.cpp:1184
#define ANGLE_SHIFT
Definition: intproto.h:40
#define IndexForProto(P)
Definition: intproto.h:167
#define X_SHIFT
Definition: intproto.h:41
#define PRUNER_Y
Definition: intproto.h:36
#define PRUNER_ANGLE
Definition: intproto.h:37
#define SetForProto(P)
Definition: intproto.h:166
#define Y_SHIFT
Definition: intproto.h:42
#define PRUNER_X
Definition: intproto.h:35
#define GetPicoFeatureLength()
Definition: picofeat.h:57
void cprintf(const char *format,...)
Definition: callcpp.cpp:32
PROTO_PRUNER ProtoPruner
Definition: intproto.h:96
float Angle
Definition: protos.h:42
float Length
Definition: protos.h:43
float Y
Definition: protos.h:41
float X
Definition: protos.h:40

◆ Bucket16For()

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

Definition at line 422 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));
425}
int IntCastRounded(double x)
Definition: helpers.h:175
#define MapParam(P, O, N)
Definition: intproto.cpp:119

◆ 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 418 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));
421}

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

1108 {
1109 return ((static_cast<float>(Bucket + 1) / NumBuckets) - Offset);
1110} /* 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 1092 of file intproto.cpp.

1092 {
1093 return ((static_cast<float>(Bucket) / NumBuckets) - Offset);
1094
1095} /* 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 432 of file intproto.cpp.

432 {
433 int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
434 return static_cast<uint8_t>(Modulo(bucket, num_buckets));
435} /* CircBucketFor */
int Modulo(int a, int b)
Definition: helpers.h:158

◆ 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 463 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;
477} /* ConvertConfig */
#define test_bit(array, bit)
Definition: bitvec.h:59
#define SET_BIT(array, bit)
Definition: bitvec.h:55
CLUSTERCONFIG Config

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

1763 {
1764 return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
1765}

◆ 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 590 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 }
596} /* DisplayIntFeature */
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
Definition: intproto.cpp:1602
ScrollView::Color GetMatchColorFor(float Evidence)
Definition: intproto.cpp:1370

◆ 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 608 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 }
614} /* DisplayIntProto */
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
Definition: intproto.cpp:1636

◆ 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

Definition at line 1122 of file intproto.cpp.

1126 {
1127 int X, Y, Angle;
1128 uint32_t OldWord;
1129
1130 X = FillSpec->X;
1131 if (X < 0)
1132 X = 0;
1133 if (X >= NUM_CP_BUCKETS)
1134 X = NUM_CP_BUCKETS - 1;
1135
1136 if (FillSpec->YStart < 0)
1137 FillSpec->YStart = 0;
1138 if (FillSpec->YEnd >= NUM_CP_BUCKETS)
1139 FillSpec->YEnd = NUM_CP_BUCKETS - 1;
1140
1141 for (Y = FillSpec->YStart; Y <= FillSpec->YEnd; Y++)
1142 for (Angle = FillSpec->AngleStart; ;
1144 OldWord = Pruner->p[X][Y][Angle][WordIndex];
1145 if (ClassCount > (OldWord & ClassMask)) {
1146 OldWord &= ~ClassMask;
1147 OldWord |= ClassCount;
1148 Pruner->p[X][Y][Angle][WordIndex] = OldWord;
1149 }
1150 if (Angle == FillSpec->AngleEnd)
1151 break;
1152 }
1153} /* DoFill */
#define CircularIncrement(i, r)
Definition: intproto.cpp:116
#define NUM_CP_BUCKETS
Definition: intproto.h:53
uint8_t AngleEnd
Definition: intproto.cpp:100
int8_t X
Definition: intproto.cpp:98
int8_t YEnd
Definition: intproto.cpp:99
uint8_t AngleStart
Definition: intproto.cpp:100
int8_t YStart
Definition: intproto.cpp:99
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
Definition: intproto.h:78

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

1162 {
1163 FILL_SWITCH *Next;
1164
1165 Next = &(Filler->Switch[Filler->NextSwitch]);
1166
1167 return Filler->X > Next->X && Next->Type == LastSwitch;
1168
1169} /* FillerDone */
int8_t X
Definition: intproto.cpp:75
SWITCH_TYPE Type
Definition: intproto.cpp:74
int8_t X
Definition: intproto.cpp:87
uint8_t NextSwitch
Definition: intproto.cpp:85
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
Definition: intproto.cpp:90

◆ 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

Definition at line 1184 of file intproto.cpp.

1185 {
1186 int i, FirstBucket, LastBucket;
1187
1188 if (Spread > 0.5)
1189 Spread = 0.5;
1190
1191 FirstBucket = static_cast<int>(std::floor((Center - Spread) * NUM_PP_BUCKETS));
1192 if (FirstBucket < 0)
1193 FirstBucket += NUM_PP_BUCKETS;
1194
1195 LastBucket = static_cast<int>(std::floor((Center + Spread) * NUM_PP_BUCKETS));
1196 if (LastBucket >= NUM_PP_BUCKETS)
1197 LastBucket -= NUM_PP_BUCKETS;
1198 if (debug) tprintf("Circular fill from %d to %d", FirstBucket, LastBucket);
1199 for (i = FirstBucket; true; CircularIncrement (i, NUM_PP_BUCKETS)) {
1200 SET_BIT (ParamTable[i], Bit);
1201
1202 /* exit loop after we have set the bit for the last bucket */
1203 if (i == LastBucket)
1204 break;
1205 }
1206
1207} /* FillPPCircularBits */
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
#define NUM_PP_BUCKETS
Definition: intproto.h:52

◆ 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

Definition at line 1223 of file intproto.cpp.

1224 {
1225 int i, FirstBucket, LastBucket;
1226
1227 FirstBucket = static_cast<int>(std::floor((Center - Spread) * NUM_PP_BUCKETS));
1228 if (FirstBucket < 0)
1229 FirstBucket = 0;
1230
1231 LastBucket = static_cast<int>(std::floor((Center + Spread) * NUM_PP_BUCKETS));
1232 if (LastBucket >= NUM_PP_BUCKETS)
1233 LastBucket = NUM_PP_BUCKETS - 1;
1234
1235 if (debug) tprintf("Linear fill from %d to %d", FirstBucket, LastBucket);
1236 for (i = FirstBucket; i <= LastBucket; i++)
1237 SET_BIT (ParamTable[i], Bit);
1238
1239} /* FillPPLinearBits */

◆ free_int_templates()

void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 698 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);
706}
void Efree(void *ptr)
Definition: emalloc.cpp:45
INT_CLASS Class[MAX_NUM_CLASSES]
Definition: intproto.h:121

◆ 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

Definition at line 1331 of file intproto.cpp.

1334 {
1335 switch (Level) {
1336 case 0:
1337 *EndPad = classify_cp_end_pad_loose * GetPicoFeatureLength ();
1338 *SidePad = classify_cp_side_pad_loose * GetPicoFeatureLength ();
1339 *AnglePad = classify_cp_angle_pad_loose / 360.0;
1340 break;
1341
1342 case 1:
1343 *EndPad = classify_cp_end_pad_medium * GetPicoFeatureLength ();
1344 *SidePad = classify_cp_side_pad_medium * GetPicoFeatureLength ();
1345 *AnglePad = classify_cp_angle_pad_medium / 360.0;
1346 break;
1347
1348 case 2:
1349 *EndPad = classify_cp_end_pad_tight * GetPicoFeatureLength ();
1350 *SidePad = classify_cp_side_pad_tight * GetPicoFeatureLength ();
1351 *AnglePad = classify_cp_angle_pad_tight / 360.0;
1352 break;
1353
1354 default:
1355 *EndPad = classify_cp_end_pad_tight * GetPicoFeatureLength ();
1356 *SidePad = classify_cp_side_pad_tight * GetPicoFeatureLength ();
1357 *AnglePad = classify_cp_angle_pad_tight / 360.0;
1358 break;
1359 }
1360 if (*AnglePad > 0.5)
1361 *AnglePad = 0.5;
1362
1363} /* GetCPPadsForLevel */

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

1370 {
1371 assert (Evidence >= 0.0);
1372 assert (Evidence <= 1.0);
1373
1374 if (Evidence >= 0.90)
1375 return ScrollView::WHITE;
1376 else if (Evidence >= 0.75)
1377 return ScrollView::GREEN;
1378 else if (Evidence >= 0.50)
1379 return ScrollView::RED;
1380 else
1381 return ScrollView::BLUE;
1382} /* 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

Definition at line 1392 of file intproto.cpp.

1392 {
1393 FILL_SWITCH *Next;
1394
1395 /* compute the fill assuming no switches will be encountered */
1396 Fill->AngleStart = Filler->AngleStart;
1397 Fill->AngleEnd = Filler->AngleEnd;
1398 Fill->X = Filler->X;
1399 Fill->YStart = Filler->YStart >> 8;
1400 Fill->YEnd = Filler->YEnd >> 8;
1401
1402 /* update the fill info and the filler for ALL switches at this X value */
1403 Next = &(Filler->Switch[Filler->NextSwitch]);
1404 while (Filler->X >= Next->X) {
1405 Fill->X = Filler->X = Next->X;
1406 if (Next->Type == StartSwitch) {
1407 Fill->YStart = Next->Y;
1408 Filler->StartDelta = Next->Delta;
1409 Filler->YStart = Next->YInit;
1410 }
1411 else if (Next->Type == EndSwitch) {
1412 Fill->YEnd = Next->Y;
1413 Filler->EndDelta = Next->Delta;
1414 Filler->YEnd = Next->YInit;
1415 }
1416 else { /* Type must be LastSwitch */
1417 break;
1418 }
1419 Filler->NextSwitch++;
1420 Next = &(Filler->Switch[Filler->NextSwitch]);
1421 }
1422
1423 /* prepare the filler for the next call to this routine */
1424 Filler->X++;
1425 Filler->YStart += Filler->StartDelta;
1426 Filler->YEnd += Filler->EndDelta;
1427
1428} /* GetNextFill */
int16_t Delta
Definition: intproto.cpp:77
int16_t YInit
Definition: intproto.cpp:76
int8_t Y
Definition: intproto.cpp:75
int16_t StartDelta
Definition: intproto.cpp:89
uint8_t AngleEnd
Definition: intproto.cpp:86
uint8_t AngleStart
Definition: intproto.cpp:86
int16_t YStart
Definition: intproto.cpp:88
int16_t YEnd
Definition: intproto.cpp:88
int16_t EndDelta
Definition: intproto.cpp:89

◆ InitFeatureDisplayWindowIfReqd()

void InitFeatureDisplayWindowIfReqd ( )

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

Definition at line 1754 of file intproto.cpp.

1754 {
1755 if (FeatureDisplayWindow == nullptr) {
1756 FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
1757 50, 700);
1758 }
1759}
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
Definition: intproto.cpp:1763

◆ InitIntMatchWindowIfReqd()

void InitIntMatchWindowIfReqd ( )

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

Definition at line 1722 of file intproto.cpp.

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

◆ InitProtoDisplayWindowIfReqd()

void InitProtoDisplayWindowIfReqd ( )

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

Definition at line 1743 of file intproto.cpp.

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

◆ 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. Results are returned in Filler.

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

Definition at line 1439 of file intproto.cpp.

1445{
1446 float Angle;
1447 float X, Y, HalfLength;
1448 float Cos, Sin;
1449 float XAdjust, YAdjust;
1450 FPOINT Start, Switch1, Switch2, End;
1451 int S1 = 0;
1452 int S2 = 1;
1453
1454 Angle = Proto->Angle;
1455 X = Proto->X;
1456 Y = Proto->Y;
1457 HalfLength = Proto->Length / 2.0;
1458
1459 Filler->AngleStart = CircBucketFor(Angle - AnglePad, AS, NB);
1460 Filler->AngleEnd = CircBucketFor(Angle + AnglePad, AS, NB);
1461 Filler->NextSwitch = 0;
1462
1463 if (fabs (Angle - 0.0) < HV_TOLERANCE || fabs (Angle - 0.5) < HV_TOLERANCE) {
1464 /* horizontal proto - handle as special case */
1465 Filler->X = Bucket8For(X - HalfLength - EndPad, XS, NB);
1466 Filler->YStart = Bucket16For(Y - SidePad, YS, NB * 256);
1467 Filler->YEnd = Bucket16For(Y + SidePad, YS, NB * 256);
1468 Filler->StartDelta = 0;
1469 Filler->EndDelta = 0;
1470 Filler->Switch[0].Type = LastSwitch;
1471 Filler->Switch[0].X = Bucket8For(X + HalfLength + EndPad, XS, NB);
1472 } else if (fabs(Angle - 0.25) < HV_TOLERANCE ||
1473 fabs(Angle - 0.75) < HV_TOLERANCE) {
1474 /* vertical proto - handle as special case */
1475 Filler->X = Bucket8For(X - SidePad, XS, NB);
1476 Filler->YStart = Bucket16For(Y - HalfLength - EndPad, YS, NB * 256);
1477 Filler->YEnd = Bucket16For(Y + HalfLength + EndPad, YS, NB * 256);
1478 Filler->StartDelta = 0;
1479 Filler->EndDelta = 0;
1480 Filler->Switch[0].Type = LastSwitch;
1481 Filler->Switch[0].X = Bucket8For(X + SidePad, XS, NB);
1482 } else {
1483 /* diagonal proto */
1484
1485 if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) {
1486 /* rising diagonal proto */
1487 Angle *= 2.0 * M_PI;
1488 Cos = fabs(cos(Angle));
1489 Sin = fabs(sin(Angle));
1490
1491 /* compute the positions of the corners of the acceptance region */
1492 Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1493 Start.y = Y - (HalfLength + EndPad) * Sin + SidePad * Cos;
1494 End.x = 2.0 * X - Start.x;
1495 End.y = 2.0 * Y - Start.y;
1496 Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1497 Switch1.y = Y - (HalfLength + EndPad) * Sin - SidePad * Cos;
1498 Switch2.x = 2.0 * X - Switch1.x;
1499 Switch2.y = 2.0 * Y - Switch1.y;
1500
1501 if (Switch1.x > Switch2.x) {
1502 S1 = 1;
1503 S2 = 0;
1504 }
1505
1506 /* translate into bucket positions and deltas */
1507 Filler->X = Bucket8For(Start.x, XS, NB);
1508 Filler->StartDelta = -static_cast<int16_t>((Cos / Sin) * 256);
1509 Filler->EndDelta = static_cast<int16_t>((Sin / Cos) * 256);
1510
1511 XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1512 YAdjust = XAdjust * Cos / Sin;
1513 Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1514 YAdjust = XAdjust * Sin / Cos;
1515 Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1516
1517 Filler->Switch[S1].Type = StartSwitch;
1518 Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1519 Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1520 XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1521 YAdjust = XAdjust * Sin / Cos;
1522 Filler->Switch[S1].YInit = Bucket16For(Switch1.y - YAdjust, YS, NB * 256);
1523 Filler->Switch[S1].Delta = Filler->EndDelta;
1524
1525 Filler->Switch[S2].Type = EndSwitch;
1526 Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1527 Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1528 XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1529 YAdjust = XAdjust * Cos / Sin;
1530 Filler->Switch[S2].YInit = Bucket16For(Switch2.y + YAdjust, YS, NB * 256);
1531 Filler->Switch[S2].Delta = Filler->StartDelta;
1532
1533 Filler->Switch[2].Type = LastSwitch;
1534 Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1535 } else {
1536 /* falling diagonal proto */
1537 Angle *= 2.0 * M_PI;
1538 Cos = fabs(cos(Angle));
1539 Sin = fabs(sin(Angle));
1540
1541 /* compute the positions of the corners of the acceptance region */
1542 Start.x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1543 Start.y = Y + (HalfLength + EndPad) * Sin - SidePad * Cos;
1544 End.x = 2.0 * X - Start.x;
1545 End.y = 2.0 * Y - Start.y;
1546 Switch1.x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1547 Switch1.y = Y + (HalfLength + EndPad) * Sin + SidePad * Cos;
1548 Switch2.x = 2.0 * X - Switch1.x;
1549 Switch2.y = 2.0 * Y - Switch1.y;
1550
1551 if (Switch1.x > Switch2.x) {
1552 S1 = 1;
1553 S2 = 0;
1554 }
1555
1556 /* translate into bucket positions and deltas */
1557 Filler->X = Bucket8For(Start.x, XS, NB);
1558 Filler->StartDelta = static_cast<int16_t>(ClipToRange<int>(
1559 -IntCastRounded((Sin / Cos) * 256), INT16_MIN, INT16_MAX));
1560 Filler->EndDelta = static_cast<int16_t>(ClipToRange<int>(
1561 IntCastRounded((Cos / Sin) * 256), INT16_MIN, INT16_MAX));
1562
1563 XAdjust = BucketEnd(Filler->X, XS, NB) - Start.x;
1564 YAdjust = XAdjust * Sin / Cos;
1565 Filler->YStart = Bucket16For(Start.y - YAdjust, YS, NB * 256);
1566 YAdjust = XAdjust * Cos / Sin;
1567 Filler->YEnd = Bucket16For(Start.y + YAdjust, YS, NB * 256);
1568
1569 Filler->Switch[S1].Type = EndSwitch;
1570 Filler->Switch[S1].X = Bucket8For(Switch1.x, XS, NB);
1571 Filler->Switch[S1].Y = Bucket8For(Switch1.y, YS, NB);
1572 XAdjust = Switch1.x - BucketStart(Filler->Switch[S1].X, XS, NB);
1573 YAdjust = XAdjust * Sin / Cos;
1574 Filler->Switch[S1].YInit = Bucket16For(Switch1.y + YAdjust, YS, NB * 256);
1575 Filler->Switch[S1].Delta = Filler->StartDelta;
1576
1577 Filler->Switch[S2].Type = StartSwitch;
1578 Filler->Switch[S2].X = Bucket8For(Switch2.x, XS, NB);
1579 Filler->Switch[S2].Y = Bucket8For(Switch2.y, YS, NB);
1580 XAdjust = Switch2.x - BucketStart(Filler->Switch[S2].X, XS, NB);
1581 YAdjust = XAdjust * Cos / Sin;
1582 Filler->Switch[S2].YInit = Bucket16For(Switch2.y - YAdjust, YS, NB * 256);
1583 Filler->Switch[S2].Delta = Filler->EndDelta;
1584
1585 Filler->Switch[2].Type = LastSwitch;
1586 Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
1587 }
1588 }
1589} /* InitTableFiller */
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:418
#define XS
float BucketStart(int Bucket, float Offset, int NumBuckets)
Definition: intproto.cpp:1092
#define NB
float BucketEnd(int Bucket, float Offset, int NumBuckets)
Definition: intproto.cpp:1108
#define HV_TOLERANCE
Definition: intproto.cpp:65
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:432
uint16_t Bucket16For(float param, float offset, int num_buckets)
Definition: intproto.cpp:422
#define AS
#define YS
Definition: fpoint.h:29
float y
Definition: fpoint.h:30
float x
Definition: fpoint.h:30

◆ 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 626 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
662} /* NewIntClass */
#define MAX_NUM_PROTO_SETS
Definition: intproto.h:50
#define PROTOS_PER_PROTO_SET
Definition: intproto.h:49

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

682 {
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);
694} /* NewIntTemplates */
#define MAX_NUM_CLASSES
Definition: matchdefs.h:30

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

1603 {
1604 float X, Y, Dx, Dy, Length;
1605
1606 window->Pen(color);
1607 assert(Feature != nullptr);
1608 assert(color != 0);
1609
1610 X = Feature->X;
1611 Y = Feature->Y;
1612 Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
1613 // The -PI has no significant effect here, but the value of Theta is computed
1614 // using BinaryAnglePlusPi in intfx.cpp.
1615 Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1616 Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
1617
1618 window->SetCursor(X, Y);
1619 window->DrawTo(X + Dx, Y + Dy);
1620} /* RenderIntFeature */
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:130
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
void Pen(Color color)
Definition: scrollview.cpp:719

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

1639 {
1640 PROTO_SET ProtoSet;
1641 INT_PROTO Proto;
1642 int ProtoSetIndex;
1643 int ProtoWordIndex;
1644 float Length;
1645 int Xmin, Xmax, Ymin, Ymax;
1646 float X, Y, Dx, Dy;
1647 uint32_t ProtoMask;
1648 int Bucket;
1649
1650 assert(ProtoId >= 0);
1651 assert(Class != nullptr);
1652 assert(ProtoId < Class->NumProtos);
1653 assert(color != 0);
1654 window->Pen(color);
1655
1656 ProtoSet = Class->ProtoSets[SetForProto(ProtoId)];
1657 ProtoSetIndex = IndexForProto(ProtoId);
1658 Proto = &(ProtoSet->Protos[ProtoSetIndex]);
1659 Length = (Class->ProtoLengths[ProtoId] *
1661 ProtoMask = PPrunerMaskFor(ProtoId);
1662 ProtoWordIndex = PPrunerWordIndexFor(ProtoId);
1663
1664 // find the x and y extent of the proto from the proto pruning table
1665 Xmin = Ymin = NUM_PP_BUCKETS;
1666 Xmax = Ymax = 0;
1667 for (Bucket = 0; Bucket < NUM_PP_BUCKETS; Bucket++) {
1668 if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_X][Bucket][ProtoWordIndex]) {
1669 UpdateRange(Bucket, &Xmin, &Xmax);
1670 }
1671
1672 if (ProtoMask & ProtoSet->ProtoPruner[PRUNER_Y][Bucket][ProtoWordIndex]) {
1673 UpdateRange(Bucket, &Ymin, &Ymax);
1674 }
1675 }
1676 X = (Xmin + Xmax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1677 Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE;
1678 // The -PI has no significant effect here, but the value of Theta is computed
1679 // using BinaryAnglePlusPi in intfx.cpp.
1680 Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
1681 Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
1682
1683 window->SetCursor(X - Dx, Y - Dy);
1684 window->DrawTo(X + Dx, Y + Dy);
1685} /* RenderIntProto */
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:120
#define PROTO_PRUNER_SCALE
Definition: intproto.cpp:48
#define PPrunerWordIndexFor(I)
Definition: intproto.h:170
#define PPrunerMaskFor(I)
Definition: intproto.h:173
uint8_t Angle
Definition: intproto.h:85
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
Definition: intproto.h:97

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

1701 {
1702 if (Param < Min) {
1703 if (Id)
1704 cprintf("Warning: Param %s truncated from %f to %d!\n",
1705 Id, Param, Min);
1706 Param = Min;
1707 } else if (Param > Max) {
1708 if (Id)
1709 cprintf("Warning: Param %s truncated from %f to %d!\n",
1710 Id, Param, Max);
1711 Param = Max;
1712 }
1713 return static_cast<int>(std::floor(Param));
1714} /* TruncateParam */

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

447 {
448 if (IntMatchWindow != nullptr)
449 IntMatchWindow->Update();
450} /* ClearMatchDisplay */
static void Update()
Definition: scrollview.cpp:709