Tesseract
3.02
|
Go to the source code of this file.
Classes | |
struct | TEMP_PROTO_STRUCT |
struct | TEMP_CONFIG_STRUCT |
struct | PERM_CONFIG_STRUCT |
union | ADAPTED_CONFIG |
struct | ADAPT_CLASS_STRUCT |
struct | ADAPT_TEMPLATES_STRUCT |
Defines | |
#define | NumNonEmptyClassesIn(Template) ((Template)->NumNonEmptyClasses) |
#define | IsEmptyAdaptedClass(Class) |
#define | ConfigIsPermanent(Class, ConfigId) (test_bit ((Class)->PermConfigs, ConfigId)) |
#define | MakeConfigPermanent(Class, ConfigId) (SET_BIT ((Class)->PermConfigs, ConfigId)) |
#define | MakeProtoPermanent(Class, ProtoId) (SET_BIT ((Class)->PermProtos, ProtoId)) |
#define | TempConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Temp) |
#define | PermConfigFor(Class, ConfigId) ((Class)->Config[ConfigId].Perm) |
#define | IncreaseConfidence(TempConfig) ((TempConfig)->NumTimesSeen++) |
Typedefs | |
typedef TEMP_PROTO_STRUCT * | TEMP_PROTO |
typedef TEMP_CONFIG_STRUCT * | TEMP_CONFIG |
typedef PERM_CONFIG_STRUCT * | PERM_CONFIG |
typedef ADAPT_CLASS_STRUCT * | ADAPT_CLASS |
typedef ADAPT_TEMPLATES_STRUCT * | ADAPT_TEMPLATES |
Functions | |
void | AddAdaptedClass (ADAPT_TEMPLATES Templates, ADAPT_CLASS Class, CLASS_ID ClassId) |
void | FreeTempProto (void *arg) |
void | FreeTempConfig (TEMP_CONFIG Config) |
ADAPT_CLASS | NewAdaptedClass () |
void | free_adapted_class (ADAPT_CLASS adapt_class) |
void | free_adapted_templates (ADAPT_TEMPLATES templates) |
TEMP_CONFIG | NewTempConfig (int MaxProtoId, int FontinfoId) |
TEMP_PROTO | NewTempProto () |
ADAPT_CLASS | ReadAdaptedClass (FILE *File) |
PERM_CONFIG | ReadPermConfig (FILE *File) |
TEMP_CONFIG | ReadTempConfig (FILE *File) |
void | WriteAdaptedClass (FILE *File, ADAPT_CLASS Class, int NumConfigs) |
void | WritePermConfig (FILE *File, PERM_CONFIG Config) |
void | WriteTempConfig (FILE *File, TEMP_CONFIG Config) |
#define ConfigIsPermanent | ( | Class, | |
ConfigId | |||
) | (test_bit ((Class)->PermConfigs, ConfigId)) |
Definition at line 93 of file adaptive.h.
#define IncreaseConfidence | ( | TempConfig | ) | ((TempConfig)->NumTimesSeen++) |
Definition at line 108 of file adaptive.h.
#define IsEmptyAdaptedClass | ( | Class | ) |
((Class)->NumPermConfigs == 0 && \ (Class)->TempProtos == NIL_LIST)
Definition at line 90 of file adaptive.h.
#define MakeConfigPermanent | ( | Class, | |
ConfigId | |||
) | (SET_BIT ((Class)->PermConfigs, ConfigId)) |
Definition at line 96 of file adaptive.h.
#define MakeProtoPermanent | ( | Class, | |
ProtoId | |||
) | (SET_BIT ((Class)->PermProtos, ProtoId)) |
Definition at line 99 of file adaptive.h.
#define NumNonEmptyClassesIn | ( | Template | ) | ((Template)->NumNonEmptyClasses) |
Definition at line 88 of file adaptive.h.
#define PermConfigFor | ( | Class, | |
ConfigId | |||
) | ((Class)->Config[ConfigId].Perm) |
Definition at line 105 of file adaptive.h.
#define TempConfigFor | ( | Class, | |
ConfigId | |||
) | ((Class)->Config[ConfigId].Temp) |
Definition at line 102 of file adaptive.h.
typedef ADAPT_CLASS_STRUCT* ADAPT_CLASS |
Definition at line 73 of file adaptive.h.
typedef ADAPT_TEMPLATES_STRUCT* ADAPT_TEMPLATES |
Definition at line 83 of file adaptive.h.
typedef PERM_CONFIG_STRUCT* PERM_CONFIG |
Definition at line 55 of file adaptive.h.
typedef TEMP_CONFIG_STRUCT* TEMP_CONFIG |
Definition at line 48 of file adaptive.h.
typedef TEMP_PROTO_STRUCT* TEMP_PROTO |
Definition at line 37 of file adaptive.h.
void AddAdaptedClass | ( | ADAPT_TEMPLATES | Templates, |
ADAPT_CLASS | Class, | ||
CLASS_ID | ClassId | ||
) |
This routine adds a new adapted class to an existing set of adapted templates.
Templates | set of templates to add new class to |
Class | new class to add to templates |
ClassId | class id to associate with new class |
Definition at line 49 of file adaptive.cpp.
{ INT_CLASS IntClass; assert (Templates != NULL); assert (Class != NULL); assert (LegalClassId (ClassId)); assert (UnusedClassIdIn (Templates->Templates, ClassId)); assert (Class->NumPermConfigs == 0); IntClass = NewIntClass (1, 1); AddIntClass (Templates->Templates, ClassId, IntClass); assert (Templates->Class[ClassId] == NULL); Templates->Class[ClassId] = Class; } /* AddAdaptedClass */
void free_adapted_class | ( | ADAPT_CLASS | adapt_class | ) |
Definition at line 136 of file adaptive.cpp.
{ int i; for (i = 0; i < MAX_NUM_CONFIGS; i++) { if (ConfigIsPermanent (adapt_class, i) && PermConfigFor (adapt_class, i) != NULL) FreePermConfig (PermConfigFor (adapt_class, i)); else if (!ConfigIsPermanent (adapt_class, i) && TempConfigFor (adapt_class, i) != NULL) FreeTempConfig (TempConfigFor (adapt_class, i)); } FreeBitVector (adapt_class->PermProtos); FreeBitVector (adapt_class->PermConfigs); destroy_nodes (adapt_class->TempProtos, FreeTempProto); Efree(adapt_class); }
void free_adapted_templates | ( | ADAPT_TEMPLATES | templates | ) |
Definition at line 199 of file adaptive.cpp.
{ if (templates != NULL) { int i; for (i = 0; i < (templates->Templates)->NumClasses; i++) free_adapted_class (templates->Class[i]); free_int_templates (templates->Templates); Efree(templates); } }
void FreeTempConfig | ( | TEMP_CONFIG | Config | ) |
This routine frees all memory consumed by a temporary configuration.
Config | config to be freed |
Definition at line 80 of file adaptive.cpp.
{ assert (Config != NULL); destroy_nodes (Config->ContextsSeen, memfree); FreeBitVector (Config->Protos); free_struct (Config, sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT"); } /* FreeTempConfig */
void FreeTempProto | ( | void * | arg | ) |
Definition at line 90 of file adaptive.cpp.
{ PROTO proto = (PROTO) arg; free_struct (proto, sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT"); }
ADAPT_CLASS NewAdaptedClass | ( | ) |
This operation allocates and initializes a new adapted class data structure and returns a ptr to it.
Definition at line 113 of file adaptive.cpp.
{ ADAPT_CLASS Class; int i; Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT)); Class->NumPermConfigs = 0; Class->MaxNumTimesSeen = 0; Class->TempProtos = NIL_LIST; Class->PermProtos = NewBitVector (MAX_NUM_PROTOS); Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS); zero_all_bits (Class->PermProtos, WordsInVectorOfSize (MAX_NUM_PROTOS)); zero_all_bits (Class->PermConfigs, WordsInVectorOfSize (MAX_NUM_CONFIGS)); for (i = 0; i < MAX_NUM_CONFIGS; i++) TempConfigFor (Class, i) = NULL; return (Class); } /* NewAdaptedClass */
TEMP_CONFIG NewTempConfig | ( | int | MaxProtoId, |
int | FontinfoId | ||
) |
This routine allocates and returns a new temporary config.
MaxProtoId | max id of any proto in new config |
FontinfoId | font information from pre-trained templates |
Definition at line 223 of file adaptive.cpp.
{ TEMP_CONFIG Config; int NumProtos = MaxProtoId + 1; Config = (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT"); Config->Protos = NewBitVector (NumProtos); Config->NumTimesSeen = 1; Config->MaxProtoId = MaxProtoId; Config->ProtoVectorSize = WordsInVectorOfSize (NumProtos); Config->ContextsSeen = NIL_LIST; zero_all_bits (Config->Protos, Config->ProtoVectorSize); Config->FontinfoId = FontinfoId; return (Config); } /* NewTempConfig */
TEMP_PROTO NewTempProto | ( | ) |
This routine allocates and returns a new temporary proto.
Definition at line 254 of file adaptive.cpp.
{ return ((TEMP_PROTO) alloc_struct (sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT")); } /* NewTempProto */
ADAPT_CLASS ReadAdaptedClass | ( | FILE * | File | ) |
Read an adapted class description from File and return a ptr to the adapted class.
File | open file to read adapted class from |
Definition at line 315 of file adaptive.cpp.
{ int NumTempProtos; int NumConfigs; int i; ADAPT_CLASS Class; TEMP_PROTO TempProto; /* first read high level adapted class structure */ Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT)); fread ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File); /* then read in the definitions of the permanent protos and configs */ Class->PermProtos = NewBitVector (MAX_NUM_PROTOS); Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS); fread ((char *) Class->PermProtos, sizeof (uinT32), WordsInVectorOfSize (MAX_NUM_PROTOS), File); fread ((char *) Class->PermConfigs, sizeof (uinT32), WordsInVectorOfSize (MAX_NUM_CONFIGS), File); /* then read in the list of temporary protos */ fread ((char *) &NumTempProtos, sizeof (int), 1, File); Class->TempProtos = NIL_LIST; for (i = 0; i < NumTempProtos; i++) { TempProto = (TEMP_PROTO) alloc_struct (sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT"); fread ((char *) TempProto, sizeof (TEMP_PROTO_STRUCT), 1, File); Class->TempProtos = push_last (Class->TempProtos, TempProto); } /* then read in the adapted configs */ fread ((char *) &NumConfigs, sizeof (int), 1, File); for (i = 0; i < NumConfigs; i++) if (test_bit (Class->PermConfigs, i)) Class->Config[i].Perm = ReadPermConfig (File); else Class->Config[i].Temp = ReadTempConfig (File); return (Class); } /* ReadAdaptedClass */
PERM_CONFIG ReadPermConfig | ( | FILE * | File | ) |
Read a permanent configuration description from File and return a ptr to it.
File | open file to read permanent config from |
Definition at line 404 of file adaptive.cpp.
{ PERM_CONFIG Config = (PERM_CONFIG) alloc_struct(sizeof(PERM_CONFIG_STRUCT), "PERM_CONFIG_STRUCT"); uinT8 NumAmbigs; fread ((char *) &NumAmbigs, sizeof(uinT8), 1, File); Config->Ambigs = (UNICHAR_ID *)Emalloc(sizeof(UNICHAR_ID) * (NumAmbigs + 1)); fread(Config->Ambigs, sizeof(UNICHAR_ID), NumAmbigs, File); Config->Ambigs[NumAmbigs] = -1; fread(&(Config->FontinfoId), sizeof(int), 1, File); return (Config); } /* ReadPermConfig */
TEMP_CONFIG ReadTempConfig | ( | FILE * | File | ) |
Read a temporary configuration description from File and return a ptr to it.
File | open file to read temporary config from |
Definition at line 431 of file adaptive.cpp.
{ TEMP_CONFIG Config; Config = (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT), "TEMP_CONFIG_STRUCT"); fread ((char *) Config, sizeof (TEMP_CONFIG_STRUCT), 1, File); Config->Protos = NewBitVector (Config->ProtoVectorSize * BITSINLONG); fread ((char *) Config->Protos, sizeof (uinT32), Config->ProtoVectorSize, File); return (Config); } /* ReadTempConfig */
void WriteAdaptedClass | ( | FILE * | File, |
ADAPT_CLASS | Class, | ||
int | NumConfigs | ||
) |
This routine writes a binary representation of Class to File.
File | open file to write Class to |
Class | adapted class to write to File |
NumConfigs | number of configs in Class |
Definition at line 461 of file adaptive.cpp.
{ int NumTempProtos; LIST TempProtos; int i; /* first write high level adapted class structure */ fwrite ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File); /* then write out the definitions of the permanent protos and configs */ fwrite ((char *) Class->PermProtos, sizeof (uinT32), WordsInVectorOfSize (MAX_NUM_PROTOS), File); fwrite ((char *) Class->PermConfigs, sizeof (uinT32), WordsInVectorOfSize (MAX_NUM_CONFIGS), File); /* then write out the list of temporary protos */ NumTempProtos = count (Class->TempProtos); fwrite ((char *) &NumTempProtos, sizeof (int), 1, File); TempProtos = Class->TempProtos; iterate (TempProtos) { void* proto = first_node(TempProtos); fwrite ((char *) proto, sizeof (TEMP_PROTO_STRUCT), 1, File); } /* then write out the adapted configs */ fwrite ((char *) &NumConfigs, sizeof (int), 1, File); for (i = 0; i < NumConfigs; i++) if (test_bit (Class->PermConfigs, i)) WritePermConfig (File, Class->Config[i].Perm); else WriteTempConfig (File, Class->Config[i].Temp); } /* WriteAdaptedClass */
void WritePermConfig | ( | FILE * | File, |
PERM_CONFIG | Config | ||
) |
This routine writes a binary representation of a permanent configuration to File.
File | open file to write Config to |
Config | permanent config to write to File |
Definition at line 537 of file adaptive.cpp.
{ uinT8 NumAmbigs = 0; assert (Config != NULL); while (Config->Ambigs[NumAmbigs] > 0) ++NumAmbigs; fwrite((char *) &NumAmbigs, sizeof(uinT8), 1, File); fwrite(Config->Ambigs, sizeof(UNICHAR_ID), NumAmbigs, File); fwrite(&(Config->FontinfoId), sizeof(int), 1, File); } /* WritePermConfig */
void WriteTempConfig | ( | FILE * | File, |
TEMP_CONFIG | Config | ||
) |
This routine writes a binary representation of a temporary configuration to File.
File | open file to write Config to |
Config | temporary config to write to File |
Definition at line 561 of file adaptive.cpp.
{ assert (Config != NULL); /* contexts not yet implemented */ assert (Config->ContextsSeen == NULL); fwrite ((char *) Config, sizeof (TEMP_CONFIG_STRUCT), 1, File); fwrite ((char *) Config->Protos, sizeof (uinT32), Config->ProtoVectorSize, File); } /* WriteTempConfig */