Tesseract  3.02
tesseract-ocr/classify/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

namespace  tesseract

Defines

#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   (8 * sizeof (uinT32))
#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   (~(~0 << 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
#define WERDS_PER_CP_VECTOR   (BITS_PER_CP_VECTOR / BITS_PER_WERD)
#define WERDS_PER_PP_VECTOR
#define WERDS_PER_PP
#define WERDS_PER_CP
#define WERDS_PER_CONFIG_VEC
#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)
#define PPrunerWordIndexFor(I)
#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] == NULL)
#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 PROTO_PRUNER [NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
typedef struct PROTO_SET_STRUCTPROTO_SET
typedef uinT32 CONFIG_PRUNER [NUM_PP_PARAMS][NUM_PP_BUCKETS][4]
typedef struct INT_CLASS_STRUCTINT_CLASS
typedef struct
INT_TEMPLATES_STRUCT
INT_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)
int BucketFor (FLOAT32 Param, FLOAT32 Offset, int NumBuckets)
int CircBucketFor (FLOAT32 Param, FLOAT32 Offset, int NumBuckets)
void UpdateMatchDisplay ()
void ConvertConfig (BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
void DisplayIntFeature (const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence)
void DisplayIntProto (INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence)
INT_CLASS NewIntClass (int MaxNumProtos, int MaxNumConfigs)
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)

Define Documentation

#define ANGLE_SHIFT   (0.0)

Definition at line 37 of file intproto.h.

#define BITS_PER_CP_VECTOR   (CLASSES_PER_CP * NUM_BITS_PER_CLASS)

Definition at line 56 of file intproto.h.

#define BITS_PER_WERD   (8 * sizeof (uinT32))

Definition at line 42 of file intproto.h.

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

Definition at line 53 of file intproto.h.

#define CLASSES_PER_CP   32

Definition at line 51 of file intproto.h.

#define CLASSES_PER_CP_WERD   (CLASSES_PER_CP / NUM_BITS_PER_CLASS)

Definition at line 54 of file intproto.h.

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

Definition at line 173 of file intproto.h.

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

Definition at line 174 of file intproto.h.

#define CLIP_MATCH_EVIDENCE   0x020

Definition at line 187 of file intproto.h.

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

Definition at line 195 of file intproto.h.

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

Definition at line 178 of file intproto.h.

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

Definition at line 176 of file intproto.h.

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

Definition at line 175 of file intproto.h.

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

Definition at line 179 of file intproto.h.

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

Definition at line 177 of file intproto.h.

#define DISPLAY_FEATURE_MATCHES   0x002

Definition at line 183 of file intproto.h.

#define DISPLAY_PROTO_MATCHES   0x004

Definition at line 184 of file intproto.h.

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

Definition at line 191 of file intproto.h.

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

Definition at line 192 of file intproto.h.

#define IndexForProto (   P)    (P % PROTOS_PER_PROTO_SET)

Definition at line 162 of file intproto.h.

#define INT_CHAR_NORM_RANGE   256

Definition at line 131 of file intproto.h.

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

Definition at line 171 of file intproto.h.

#define MatchDebuggingOn (   D)    (D)

Definition at line 189 of file intproto.h.

#define MAX_NUM_CLASS_PRUNERS
Value:

Definition at line 57 of file intproto.h.

#define MAX_NUM_CONFIGS   64

Definition at line 44 of file intproto.h.

#define MAX_NUM_INT_FEATURES   512

Definition at line 130 of file intproto.h.

#define MAX_NUM_PROTO_SETS   (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)

Definition at line 47 of file intproto.h.

#define MAX_NUM_PROTOS   512

Definition at line 45 of file intproto.h.

#define MAX_PROTO_INDEX   24

Definition at line 41 of file intproto.h.

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

Definition at line 170 of file intproto.h.

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

---------------------------------------------------------------------------- Macros ----------------------------------------------------------------------------

Definition at line 160 of file intproto.h.

#define NUM_BITS_PER_CLASS   2

Definition at line 52 of file intproto.h.

#define NUM_CP_BUCKETS   24

Definition at line 50 of file intproto.h.

#define NUM_PP_BUCKETS   64

Definition at line 49 of file intproto.h.

#define NUM_PP_PARAMS   3

Definition at line 48 of file intproto.h.

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

Definition at line 167 of file intproto.h.

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

Definition at line 168 of file intproto.h.

#define PPrunerWordIndexFor (   I)
Value:
(((I) % PROTOS_PER_PROTO_SET) /         \
                                PROTOS_PER_PP_WERD)

Definition at line 165 of file intproto.h.

#define PRINT_FEATURE_MATCHES   0x008

Definition at line 185 of file intproto.h.

#define PRINT_MATCH_SUMMARY   0x001

Definition at line 182 of file intproto.h.

#define PRINT_PROTO_MATCHES   0x010

Definition at line 186 of file intproto.h.

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

Definition at line 193 of file intproto.h.

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

Definition at line 190 of file intproto.h.

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

Definition at line 194 of file intproto.h.

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

Definition at line 163 of file intproto.h.

#define PROTOS_PER_PP_WERD   BITS_PER_WERD

Definition at line 55 of file intproto.h.

#define PROTOS_PER_PROTO_SET   64

Definition at line 46 of file intproto.h.

#define PRUNER_ANGLE   2

Definition at line 34 of file intproto.h.

#define PRUNER_X   0

---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------

Definition at line 32 of file intproto.h.

#define PRUNER_Y   1

Definition at line 33 of file intproto.h.

#define SetForProto (   P)    (P / PROTOS_PER_PROTO_SET)

Definition at line 161 of file intproto.h.

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

Definition at line 172 of file intproto.h.

#define WERDS_PER_CONFIG_VEC
Value:

Definition at line 66 of file intproto.h.

#define WERDS_PER_CP
Value:

Definition at line 64 of file intproto.h.

#define WERDS_PER_CP_VECTOR   (BITS_PER_CP_VECTOR / BITS_PER_WERD)

Definition at line 59 of file intproto.h.

#define WERDS_PER_PP
Value:
(NUM_PP_PARAMS * NUM_PP_BUCKETS *               \
                                WERDS_PER_PP_VECTOR)

Definition at line 62 of file intproto.h.

#define WERDS_PER_PP_VECTOR
Value:

Definition at line 60 of file intproto.h.

#define X_SHIFT   (0.5)

Definition at line 38 of file intproto.h.

#define Y_SHIFT   (0.5)

Definition at line 39 of file intproto.h.


Typedef Documentation

typedef uinT32 CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4]

Definition at line 101 of file intproto.h.

typedef struct INT_CLASS_STRUCT * INT_CLASS

Definition at line 145 of file intproto.h.

typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]

Definition at line 147 of file intproto.h.

typedef struct INT_PROTO_STRUCT * INT_PROTO
typedef uinT32 PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]

Definition at line 90 of file intproto.h.

typedef struct PROTO_SET_STRUCT * PROTO_SET

Enumeration Type Documentation

Enumerator:
IDA_ADAPTIVE 
IDA_STATIC 
IDA_SHAPE_INDEX 
IDA_BOTH 

Definition at line 149 of file intproto.h.


Function Documentation

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

Note:
Exceptions: none
History: Mon Feb 11 11:52:08 1991, DSJ, Created.

Definition at line 224 of file intproto.cpp.

                                                                             {
  int Pruner;

  assert (LegalClassId (ClassId));
  if (ClassId != Templates->NumClasses) {
    fprintf(stderr, "Please make sure that classes are added to templates");
    fprintf(stderr, " in increasing order of ClassIds\n");
    exit(1);
  }
  ClassForClassId (Templates, ClassId) = Class;
  Templates->NumClasses++;

  if (Templates->NumClasses > MaxNumClassesIn (Templates)) {
    Pruner = Templates->NumClassPruners++;
    Templates->ClassPruners[Pruner] = new CLASS_PRUNER_STRUCT;
    memset(Templates->ClassPruners[Pruner], 0, sizeof(CLASS_PRUNER_STRUCT));
  }
}                                /* AddIntClass */
int AddIntConfig ( INT_CLASS  Class)

This routine returns the index of the next free config in Class.

Parameters:
Classclass to add new configuration to

Globals: none

Returns:
Index of next free config.
Note:
Exceptions: none
History: Mon Feb 11 14:44:40 1991, DSJ, Created.

Definition at line 257 of file intproto.cpp.

                                  {
  int Index;

  assert(Class->NumConfigs < MAX_NUM_CONFIGS);

  Index = Class->NumConfigs++;
  Class->ConfigLengths[Index] = 0;
  return Index;
}                                /* AddIntConfig */
int AddIntProto ( INT_CLASS  Class)

This routine allocates the next free proto in Class and returns its index.

Parameters:
Classclass to add new proto to

Globals: none

Returns:
Proto index of new proto.
Note:
Exceptions: none
History: Mon Feb 11 13:26:41 1991, DSJ, Created.

Definition at line 281 of file intproto.cpp.

                                 {
  int Index;
  int ProtoSetId;
  PROTO_SET ProtoSet;
  INT_PROTO Proto;
  register uinT32 *Word;

  if (Class->NumProtos >= MAX_NUM_PROTOS)
    return (NO_PROTO);

  Index = Class->NumProtos++;

  if (Class->NumProtos > MaxNumIntProtosIn(Class)) {
    ProtoSetId = Class->NumProtoSets++;

    ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
    Class->ProtoSets[ProtoSetId] = ProtoSet;
    memset(ProtoSet, 0, sizeof(*ProtoSet));

    /* reallocate space for the proto lengths and install in class */
    Class->ProtoLengths =
      (uinT8 *)Erealloc(Class->ProtoLengths,
                        MaxNumIntProtosIn(Class) * sizeof(uinT8));
    memset(&Class->ProtoLengths[Index], 0,
           sizeof(*Class->ProtoLengths) * (MaxNumIntProtosIn(Class) - Index));
  }

  /* initialize proto so its length is zero and it isn't in any configs */
  Class->ProtoLengths[Index] = 0;
  Proto = ProtoForProtoId (Class, Index);
  for (Word = Proto->Configs;
       Word < Proto->Configs + WERDS_PER_CONFIG_VEC; *Word++ = 0);

  return (Index);

}                                /* AddIntProto */
void AddProtoToClassPruner ( PROTO  Proto,
CLASS_ID  ClassId,
INT_TEMPLATES  Templates 
)

Definition at line 320 of file intproto.cpp.

{
  CLASS_PRUNER_STRUCT* Pruner;
  uinT32 ClassMask;
  uinT32 ClassCount;
  uinT32 WordIndex;
  int Level;
  FLOAT32 EndPad, SidePad, AnglePad;
  TABLE_FILLER TableFiller;
  FILL_SPEC FillSpec;

  Pruner = CPrunerFor (Templates, ClassId);
  WordIndex = CPrunerWordIndexFor (ClassId);
  ClassMask = CPrunerMaskFor (MAX_LEVEL, ClassId);

  for (Level = classify_num_cp_levels - 1; Level >= 0; Level--) {
    GetCPPadsForLevel(Level, &EndPad, &SidePad, &AnglePad);
    ClassCount = CPrunerMaskFor (Level, ClassId);
    InitTableFiller(EndPad, SidePad, AnglePad, Proto, &TableFiller);

    while (!FillerDone (&TableFiller)) {
      GetNextFill(&TableFiller, &FillSpec);
      DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
    }
  }
}                                /* AddProtoToClassPruner */
void AddProtoToProtoPruner ( PROTO  Proto,
int  ProtoId,
INT_CLASS  Class,
bool  debug 
)

Definition at line 364 of file intproto.cpp.

                                                        {
/*
 ** Parameters:
 **   Proto floating-pt proto to be added to proto pruner
 **   ProtoId id of proto
 **   Class integer class that contains desired proto pruner
 ** Globals: none
 ** Operation: This routine updates the proto pruner lookup tables
 **   for Class to include a new proto identified by ProtoId
 **   and described by Proto.
 ** Return: none
 ** Exceptions: none
 ** History: Fri Feb  8 13:07:19 1991, DSJ, Created.
 */
  FLOAT32 Angle, X, Y, Length;
  FLOAT32 Pad;
  int Index;
  PROTO_SET ProtoSet;

  if (ProtoId >= Class->NumProtos)
    cprintf("AddProtoToProtoPruner:assert failed: %d < %d",
            ProtoId, Class->NumProtos);
  assert(ProtoId < Class->NumProtos);

  Index = IndexForProto (ProtoId);
  ProtoSet = Class->ProtoSets[SetForProto (ProtoId)];

  Angle = Proto->Angle;
#ifndef _WIN32
  assert(!isnan(Angle));
#endif

  FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index,
                      Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
                      debug);

  Angle *= 2.0 * PI;
  Length = Proto->Length;

  X = Proto->X + X_SHIFT;
  Pad = MAX (fabs (cos (Angle)) * (Length / 2.0 +
                                   classify_pp_end_pad *
                                   GetPicoFeatureLength ()),
             fabs (sin (Angle)) * (classify_pp_side_pad *
                                   GetPicoFeatureLength ()));

  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);

  Y = Proto->Y + Y_SHIFT;
  Pad = MAX (fabs (sin (Angle)) * (Length / 2.0 +
                                   classify_pp_end_pad *
                                   GetPicoFeatureLength ()),
             fabs (cos (Angle)) * (classify_pp_side_pad *
                                   GetPicoFeatureLength ()));

  FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad, debug);
}                                /* AddProtoToProtoPruner */
int BucketFor ( FLOAT32  Param,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 425 of file intproto.cpp.

                                                             {
/*
 ** Parameters:
 **   Param   parameter value to map into a bucket number
 **   Offset    amount to shift param before mapping it
 **   NumBuckets  number of buckets to map param into
 ** Globals: none
 ** Operation: This routine maps a parameter value into a bucket between
 **   0 and NumBuckets-1.  Offset is added to the parameter
 **   before mapping it.  Values which map to buckets outside
 **   the range are truncated to fit within the range.  Mapping
 **   is done by truncating rather than rounding.
 ** Return: Bucket number corresponding to Param + Offset.
 ** Exceptions: none
 ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
 */
  return ClipToRange(static_cast<int>(MapParam(Param, Offset, NumBuckets)),
                     0, NumBuckets - 1);
}                                /* BucketFor */
int CircBucketFor ( FLOAT32  Param,
FLOAT32  Offset,
int  NumBuckets 
)

Definition at line 447 of file intproto.cpp.

                                                                 {
/*
 ** Parameters:
 **   Param   parameter value to map into a circular bucket
 **   Offset    amount to shift param before mapping it
 **   NumBuckets  number of buckets to map param into
 ** Globals: none
 ** Operation: This routine maps a parameter value into a bucket between
 **   0 and NumBuckets-1.  Offset is added to the parameter
 **   before mapping it.  Values which map to buckets outside
 **   the range are wrapped to a new value in a circular fashion.
 **   Mapping is done by truncating rather than rounding.
 ** Return: Bucket number corresponding to Param + Offset.
 ** Exceptions: none
 ** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
 */
  int Bucket;

  Bucket = static_cast<int>(MapParam(Param, Offset, NumBuckets));
  if (Bucket < 0)
    Bucket += NumBuckets;
  else if (Bucket >= NumBuckets)
    Bucket -= NumBuckets;
  return Bucket;
}                                /* CircBucketFor */
void ConvertConfig ( BIT_VECTOR  Config,
int  ConfigId,
INT_CLASS  Class 
)

Definition at line 494 of file intproto.cpp.

                                                                     {
/*
 ** Parameters:
 **   Config    config to be added to class
 **   ConfigId  id to be used for new config
 **   Class   class to add new config to
 ** Globals: none
 ** Operation: 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.
 ** Return: none
 ** Exceptions: none
 ** History: Mon Feb 11 14:57:31 1991, DSJ, Created.
 */
  int ProtoId;
  INT_PROTO Proto;
  int TotalLength;

  for (ProtoId = 0, TotalLength = 0;
    ProtoId < Class->NumProtos; ProtoId++) {
    if (test_bit(Config, ProtoId)) {
      Proto = ProtoForProtoId(Class, ProtoId);
      SET_BIT(Proto->Configs, ConfigId);
      TotalLength += Class->ProtoLengths[ProtoId];
    }
  }
  Class->ConfigLengths[ConfigId] = TotalLength;
}                                /* ConvertConfig */
ScrollView* CreateFeatureSpaceWindow ( const char *  name,
int  xpos,
int  ypos 
)

Definition at line 1991 of file intproto.cpp.

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

Definition at line 638 of file intproto.cpp.

                                                                            {
/*
 ** Parameters:
 **   Feature   pico-feature to be displayed
 **   Evidence  best evidence for this feature (0-1)
 ** Globals:
 **   FeatureShapes global display list for features
 ** Operation: This routine renders the specified feature into a
 **   global display list.
 ** Return: none
 ** Exceptions: none
 ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
 */
  ScrollView::Color color = GetMatchColorFor(Evidence);
  RenderIntFeature(IntMatchWindow, Feature, color);
  if (FeatureDisplayWindow) {
    RenderIntFeature(FeatureDisplayWindow, Feature, color);
  }
}                                /* DisplayIntFeature */
void DisplayIntProto ( INT_CLASS  Class,
PROTO_ID  ProtoId,
FLOAT32  Evidence 
)

Definition at line 660 of file intproto.cpp.

                                                                          {
/*
 ** Parameters:
 **   Class   class to take proto from
 **   ProtoId   id of proto in Class to be displayed
 **   Evidence  total evidence for proto (0-1)
 ** Globals:
 **   ProtoShapes global display list for protos
 ** Operation: This routine renders the specified proto into a
 **   global display list.
 ** Return: none
 ** Exceptions: none
 ** History: Thu Mar 21 14:45:04 1991, DSJ, Created.
 */
  ScrollView::Color color = GetMatchColorFor(Evidence);
  RenderIntProto(IntMatchWindow, Class, ProtoId, color);
  if (ProtoDisplayWindow) {
    RenderIntProto(ProtoDisplayWindow, Class, ProtoId, color);
  }
}                                /* DisplayIntProto */
void free_int_templates ( INT_TEMPLATES  templates)

Definition at line 774 of file intproto.cpp.

                                                 {
  int i;

  for (i = 0; i < templates->NumClasses; i++)
    free_int_class(templates->Class[i]);
  for (i = 0; i < templates->NumClassPruners; i++)
    delete templates->ClassPruners[i];
  Efree(templates);
}
void InitFeatureDisplayWindowIfReqd ( )

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

Definition at line 1982 of file intproto.cpp.

                                      {
  if (FeatureDisplayWindow == NULL) {
    FeatureDisplayWindow = CreateFeatureSpaceWindow("FeatureDisplayWindow",
                                                    50, 700);
  }
}
void InitIntMatchWindowIfReqd ( )

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

Definition at line 1950 of file intproto.cpp.

                                {
  if (IntMatchWindow == NULL) {
    IntMatchWindow = CreateFeatureSpaceWindow("IntMatchWindow", 50, 200);
    SVMenuNode* popup_menu = new SVMenuNode();

    popup_menu->AddChild("Debug Adapted classes", IDA_ADAPTIVE,
                         "x", "Class to debug");
    popup_menu->AddChild("Debug Static classes", IDA_STATIC,
                         "x", "Class to debug");
    popup_menu->AddChild("Debug Both", IDA_BOTH,
                         "x", "Class to debug");
    popup_menu->AddChild("Debug Shape Index", IDA_SHAPE_INDEX,
                         "0", "Index to debug");
    popup_menu->BuildMenu(IntMatchWindow, false);
  }
}
void InitProtoDisplayWindowIfReqd ( )

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

Definition at line 1971 of file intproto.cpp.

                                    {
  if (ProtoDisplayWindow == NULL) {
    ProtoDisplayWindow = CreateFeatureSpaceWindow("ProtoDisplayWindow",
                                                  550, 200);
 }
}
INT_CLASS NewIntClass ( int  MaxNumProtos,
int  MaxNumConfigs 
)

Definition at line 683 of file intproto.cpp.

                                                           {
/*
 ** Parameters:
 **   MaxNumProtos  number of protos to allocate space for
 **   MaxNumConfigs number of configs to allocate space for
 ** Globals: none
 ** Operation: 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.
 ** Return: New class created.
 ** Exceptions: none
 ** History: Fri Feb  8 10:51:23 1991, DSJ, Created.
 */
  INT_CLASS Class;
  PROTO_SET ProtoSet;
  int i;

  assert(MaxNumConfigs <= MAX_NUM_CONFIGS);

  Class = (INT_CLASS) Emalloc(sizeof(INT_CLASS_STRUCT));
  Class->NumProtoSets = ((MaxNumProtos + PROTOS_PER_PROTO_SET - 1) /
                            PROTOS_PER_PROTO_SET);

  assert(Class->NumProtoSets <= MAX_NUM_PROTO_SETS);

  Class->NumProtos = 0;
  Class->NumConfigs = 0;

  for (i = 0; i < Class->NumProtoSets; i++) {
    /* allocate space for a proto set, install in class, and initialize */
    ProtoSet = (PROTO_SET) Emalloc(sizeof(PROTO_SET_STRUCT));
    memset(ProtoSet, 0, sizeof(*ProtoSet));
    Class->ProtoSets[i] = ProtoSet;

    /* allocate space for the proto lengths and install in class */
  }
  if (MaxNumIntProtosIn (Class) > 0) {
    Class->ProtoLengths =
      (uinT8 *)Emalloc(MaxNumIntProtosIn (Class) * sizeof (uinT8));
    memset(Class->ProtoLengths, 0,
           MaxNumIntProtosIn(Class) * sizeof(*Class->ProtoLengths));
  } else {
    Class->ProtoLengths = NULL;
  }
  memset(Class->ConfigLengths, 0, sizeof(Class->ConfigLengths));

  return (Class);

}                                /* NewIntClass */
INT_TEMPLATES NewIntTemplates ( )

Definition at line 749 of file intproto.cpp.

                                {
/*
 ** Parameters: none
 ** Globals: none
 ** Operation: This routine allocates a new set of integer templates
 **   initialized to hold 0 classes.
 ** Return: The integer templates created.
 ** Exceptions: none
 ** History: Fri Feb  8 08:38:51 1991, DSJ, Created.
 */
  INT_TEMPLATES T;
  int i;

  T = (INT_TEMPLATES) Emalloc (sizeof (INT_TEMPLATES_STRUCT));
  T->NumClasses = 0;
  T->NumClassPruners = 0;

  for (i = 0; i < MAX_NUM_CLASSES; i++)
    ClassForClassId (T, i) = NULL;

  return (T);
}                                /* NewIntTemplates */
void RenderIntFeature ( ScrollView window,
const INT_FEATURE_STRUCT Feature,
ScrollView::Color  color 
)

Definition at line 1822 of file intproto.cpp.

                                             {
  FLOAT32 X, Y, Dx, Dy, Length;

  window->Pen(color);
  assert(Feature != NULL);
  assert(color != 0);

  X = Feature->X;
  Y = Feature->Y;
  Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
  // The -PI has no significant effect here, but the value of Theta is computed
  // using BinaryAnglePlusPi in intfx.cpp.
  Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * PI - PI);
  Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * PI - PI);

  window->SetCursor(X, Y);
  window->DrawTo(X + Dx, Y + Dy);
}                                /* RenderIntFeature */
void ShowMatchDisplay ( )
void UpdateMatchDisplay ( )

Definition at line 476 of file intproto.cpp.

                          {
/*
 ** Parameters: none
 ** Globals:
 **   FeatureShapes display list for features
 **   ProtoShapes display list for protos
 ** Operation: This routine clears the global feature and proto
 **   display lists.
 ** Return: none
 ** Exceptions: none
 ** History: Thu Mar 21 15:40:19 1991, DSJ, Created.
 */
  if (IntMatchWindow != NULL)
    IntMatchWindow->Update();
}                                /* ClearMatchDisplay */