doxygen classify/intproto.cpp

This commit is contained in:
Jim O'Regan 2015-07-20 14:08:23 +01:00
parent f5c71d4eea
commit f85655b304

View File

@ -207,15 +207,15 @@ double_VAR(classify_pp_side_pad, 2.5, "Proto Pruner Side Pad");
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
Public Code Public Code
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
// Builds a feature from an FCOORD for position with all the necessary /// Builds a feature from an FCOORD for position with all the necessary
// clipping and rounding. /// clipping and rounding.
INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(const FCOORD& pos, uinT8 theta) INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(const FCOORD& pos, uinT8 theta)
: X(ClipToRange<inT16>(static_cast<inT16>(pos.x() + 0.5), 0, 255)), : X(ClipToRange<inT16>(static_cast<inT16>(pos.x() + 0.5), 0, 255)),
Y(ClipToRange<inT16>(static_cast<inT16>(pos.y() + 0.5), 0, 255)), Y(ClipToRange<inT16>(static_cast<inT16>(pos.y() + 0.5), 0, 255)),
Theta(theta), Theta(theta),
CP_misses(0) { CP_misses(0) {
} }
// Builds a feature from ints with all the necessary clipping and casting. /** Builds a feature from ints with all the necessary clipping and casting. */
INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(int x, int y, int theta) INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(int x, int y, int theta)
: X(static_cast<uinT8>(ClipToRange(x, 0, MAX_UINT8))), : X(static_cast<uinT8>(ClipToRange(x, 0, MAX_UINT8))),
Y(static_cast<uinT8>(ClipToRange(y, 0, MAX_UINT8))), Y(static_cast<uinT8>(ClipToRange(y, 0, MAX_UINT8))),
@ -223,7 +223,6 @@ INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(int x, int y, int theta)
CP_misses(0) { CP_misses(0) {
} }
/*---------------------------------------------------------------------------*/
/** /**
* This routine adds a new class structure to a set of * This routine adds a new class structure to a set of
* templates. Classes have to be added to Templates in * templates. Classes have to be added to Templates in
@ -258,7 +257,6 @@ void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class) {
} /* AddIntClass */ } /* AddIntClass */
/*---------------------------------------------------------------------------*/
/** /**
* This routine returns the index of the next free config * This routine returns the index of the next free config
* in Class. * in Class.
@ -282,7 +280,6 @@ int AddIntConfig(INT_CLASS Class) {
} /* AddIntConfig */ } /* AddIntConfig */
/*---------------------------------------------------------------------------*/
/** /**
* This routine allocates the next free proto in Class and * This routine allocates the next free proto in Class and
* returns its index. * returns its index.
@ -330,25 +327,24 @@ int AddIntProto(INT_CLASS Class) {
return (Index); return (Index);
} /* AddIntProto */ }
/*---------------------------------------------------------------------------*/ /**
* 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
* @param Proto floating-pt proto to add to class pruner
* @param ClassId class id corresponding to Proto
* @param Templates set of templates containing class pruner
* @return none
* @note Exceptions: none
* @note History: Wed Feb 13 08:49:54 1991, DSJ, Created.
*/
void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
INT_TEMPLATES Templates) INT_TEMPLATES Templates)
/*
** Parameters:
** Proto floating-pt proto to add to class pruner
** ClassId class id corresponding to Proto
** Templates set of templates containing class pruner
** Globals:
** classify_num_cp_levels number of levels used in the class pruner
** Operation: This routine adds Proto to the class pruning tables
** for the specified class in Templates.
** Return: none
** Exceptions: none
** History: Wed Feb 13 08:49:54 1991, DSJ, Created.
*/
#define MAX_LEVEL 2 #define MAX_LEVEL 2
{ {
CLASS_PRUNER_STRUCT* Pruner; CLASS_PRUNER_STRUCT* Pruner;
@ -377,22 +373,21 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
} /* AddProtoToClassPruner */ } /* AddProtoToClassPruner */
/*---------------------------------------------------------------------------*/ /**
* This routine updates the proto pruner lookup tables
* for Class to include a new proto identified by ProtoId
* and described by Proto.
* @param Proto floating-pt proto to be added to proto pruner
* @param ProtoId id of proto
* @param Class integer class that contains desired proto pruner
* @param debug debug flag
* @note Globals: none
* @return none
* @note Exceptions: none
* @note History: Fri Feb 8 13:07:19 1991, DSJ, Created.
*/
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
INT_CLASS Class, bool debug) { INT_CLASS Class, bool debug) {
/*
** 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 Angle, X, Y, Length;
FLOAT32 Pad; FLOAT32 Pad;
int Index; int Index;
@ -773,18 +768,17 @@ void free_int_templates(INT_TEMPLATES templates) {
namespace tesseract { namespace tesseract {
INT_TEMPLATES Classify::ReadIntTemplates(FILE *File) { /**
/* * This routine reads a set of integer templates from
** Parameters: * File. File must already be open and must be in the
** File open file to read templates from * correct binary format.
** Globals: none * @param File open file to read templates from
** Operation: This routine reads a set of integer templates from * @return Pointer to integer templates read from File.
** File. File must already be open and must be in the * @note Globals: none
** correct binary format. * @note Exceptions: none
** Return: Pointer to integer templates read from File. * @note History: Wed Feb 27 11:48:46 1991, DSJ, Created.
** Exceptions: none
** History: Wed Feb 27 11:48:46 1991, DSJ, Created.
*/ */
INT_TEMPLATES Classify::ReadIntTemplates(FILE *File) {
int i, j, w, x, y, z; int i, j, w, x, y, z;
BOOL8 swap; BOOL8 swap;
int nread; int nread;
@ -1081,20 +1075,19 @@ INT_TEMPLATES Classify::ReadIntTemplates(FILE *File) {
} /* ReadIntTemplates */ } /* ReadIntTemplates */
/*---------------------------------------------------------------------------*/
#ifndef GRAPHICS_DISABLED #ifndef GRAPHICS_DISABLED
void Classify::ShowMatchDisplay() { /**
/* * This routine sends the shapes in the global display
** Parameters: none * lists to the match debugger window.
** Globals: *
** FeatureShapes display list containing feature matches * Globals:
** ProtoShapes display list containing proto matches * - FeatureShapes display list containing feature matches
** Operation: This routine sends the shapes in the global display * - ProtoShapes display list containing proto matches
** lists to the match debugger window. * @return none
** Return: none * @note Exceptions: none
** Exceptions: none * @note History: Thu Mar 21 15:47:33 1991, DSJ, Created.
** History: Thu Mar 21 15:47:33 1991, DSJ, Created.
*/ */
void Classify::ShowMatchDisplay() {
InitIntMatchWindowIfReqd(); InitIntMatchWindowIfReqd();
if (ProtoDisplayWindow) { if (ProtoDisplayWindow) {
ProtoDisplayWindow->Clear(); ProtoDisplayWindow->Clear();
@ -1117,8 +1110,8 @@ void Classify::ShowMatchDisplay() {
} }
} /* ShowMatchDisplay */ } /* ShowMatchDisplay */
// Clears the given window and draws the featurespace guides for the /// Clears the given window and draws the featurespace guides for the
// appropriate normalization method. /// appropriate normalization method.
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window) { void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window) {
window->Clear(); window->Clear();
@ -1141,21 +1134,19 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window) {
} }
#endif #endif
/*---------------------------------------------------------------------------*/ /**
* This routine writes Templates to File. The format
* is an efficient binary format. File must already be open
* for writing.
* @param File open file to write templates to
* @param Templates templates to save into File
* @return none
* @note Globals: none
* @note Exceptions: none
* @note History: Wed Feb 27 11:48:46 1991, DSJ, Created.
*/
void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
const UNICHARSET& target_unicharset) { const UNICHARSET& target_unicharset) {
/*
** Parameters:
** File open file to write templates to
** Templates templates to save into File
** Globals: none
** Operation: This routine writes Templates to File. The format
** is an efficient binary format. File must already be open
** for writing.
** Return: none
** Exceptions: none
** History: Wed Feb 27 11:48:46 1991, DSJ, Created.
*/
int i, j; int i, j;
INT_CLASS Class; INT_CLASS Class;
int unicharset_size = target_unicharset.size(); int unicharset_size = target_unicharset.size();
@ -1219,43 +1210,39 @@ void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
Private Code Private Code
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/ /**
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) { * This routine returns the parameter value which
/* * corresponds to the beginning of the specified bucket.
** Parameters: * The bucket number should have been generated using the
** Bucket bucket whose start is to be computed * BucketFor() function with parameters Offset and NumBuckets.
** Offset offset used to map params to buckets * @param Bucket bucket whose start is to be computed
** NumBuckets total number of buckets * @param Offset offset used to map params to buckets
** Globals: none * @param NumBuckets total number of buckets
** Operation: This routine returns the parameter value which * @return Param value corresponding to start position of Bucket.
** corresponds to the beginning of the specified bucket. * @note Globals: none
** The bucket number should have been generated using the * @note Exceptions: none
** BucketFor() function with parameters Offset and NumBuckets. * @note History: Thu Feb 14 13:24:33 1991, DSJ, Created.
** Return: Param value corresponding to start position of Bucket.
** Exceptions: none
** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
*/ */
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) {
return (((FLOAT32) Bucket / NumBuckets) - Offset); return (((FLOAT32) Bucket / NumBuckets) - Offset);
} /* BucketStart */ } /* BucketStart */
/*---------------------------------------------------------------------------*/ /**
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) { * This routine returns the parameter value which
/* * corresponds to the end of the specified bucket.
** Parameters: * The bucket number should have been generated using the
** Bucket bucket whose end is to be computed * BucketFor() function with parameters Offset and NumBuckets.
** Offset offset used to map params to buckets * @param Bucket bucket whose end is to be computed
** NumBuckets total number of buckets * @param Offset offset used to map params to buckets
** Globals: none * @param NumBuckets total number of buckets
** Operation: This routine returns the parameter value which * @return Param value corresponding to end position of Bucket.
** corresponds to the end of the specified bucket. * @note Globals: none
** The bucket number should have been generated using the * @note Exceptions: none
** BucketFor() function with parameters Offset and NumBuckets. * @note History: Thu Feb 14 13:24:33 1991, DSJ, Created.
** Return: Param value corresponding to end position of Bucket.
** Exceptions: none
** History: Thu Feb 14 13:24:33 1991, DSJ, Created.
*/ */
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) {
return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset); return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
} /* BucketEnd */ } /* BucketEnd */
@ -1378,27 +1365,25 @@ void FillPPCircularBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
} /* FillPPCircularBits */ } /* FillPPCircularBits */
/*---------------------------------------------------------------------------*/ /**
* 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.
* @param ParamTable table of bit vectors, one per param bucket
* @param Bit bit number being filled
* @param Center center of filled area
* @param Spread spread of filled area
* @return none
* @note Globals: none
* @note Exceptions: none
* @note History: Tue Oct 16 09:26:54 1990, DSJ, Created.
*/
void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) { int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) {
/*
** Parameters:
** ParamTable table of bit vectors, one per param bucket
** Bit bit number being filled
** Center center of filled area
** Spread spread of filled area
** Globals: none
** Operation: 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.
** Return: none
** Exceptions: none
** History: Tue Oct 16 09:26:54 1990, DSJ, Created.
*/
int i, FirstBucket, LastBucket; int i, FirstBucket, LastBucket;
FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS); FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS);
@ -1419,18 +1404,17 @@ void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifndef GRAPHICS_DISABLED #ifndef GRAPHICS_DISABLED
namespace tesseract { namespace tesseract {
/**
* This routine prompts the user with Prompt and waits
* for the user to enter something in the debug window.
* @param Prompt prompt to print while waiting for input from window
* @return Character entered in the debug window.
* @note Globals: none
* @note Exceptions: none
* @note History: Thu Mar 21 16:55:13 1991, DSJ, Created.
*/
CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on, CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on,
bool* pretrained_on, int* shape_id) { bool* pretrained_on, int* shape_id) {
/*
** Parameters:
** Prompt prompt to print while waiting for input from window
** Globals: none
** Operation: This routine prompts the user with Prompt and waits
** for the user to enter something in the debug window.
** Return: Character entered in the debug window.
** Exceptions: none
** History: Thu Mar 21 16:55:13 1991, DSJ, Created.
*/
tprintf("%s\n", Prompt); tprintf("%s\n", Prompt);
SVEvent* ev; SVEvent* ev;
SVEventType ev_type; SVEventType ev_type;
@ -1494,27 +1478,25 @@ CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on,
} // namespace tesseract } // namespace tesseract
#endif #endif
/*---------------------------------------------------------------------------*/ /**
* 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.
* @param Level "tightness" level to return pads for
* @param EndPad place to put end pad for Level
* @param SidePad place to put side pad for Level
* @param AnglePad place to put angle pad for Level
* @return none (results are returned in EndPad, SidePad, and AnglePad.
* @note Globals: none
* @note Exceptions: none
* @note History: Thu Feb 14 08:26:49 1991, DSJ, Created.
*/
void GetCPPadsForLevel(int Level, void GetCPPadsForLevel(int Level,
FLOAT32 *EndPad, FLOAT32 *EndPad,
FLOAT32 *SidePad, FLOAT32 *SidePad,
FLOAT32 *AnglePad) { FLOAT32 *AnglePad) {
/*
** Parameters:
** Level "tightness" level to return pads for
** EndPad place to put end pad for Level
** SidePad place to put side pad for Level
** AnglePad place to put angle pad for Level
** Globals: none
** Operation: 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.
** Return: none (results are returned in EndPad, SidePad, and AnglePad.
** Exceptions: none
** History: Thu Feb 14 08:26:49 1991, DSJ, Created.
*/
switch (Level) { switch (Level) {
case 0: case 0:
*EndPad = classify_cp_end_pad_loose * GetPicoFeatureLength (); *EndPad = classify_cp_end_pad_loose * GetPicoFeatureLength ();
@ -1546,18 +1528,14 @@ void GetCPPadsForLevel(int Level,
} /* GetCPPadsForLevel */ } /* GetCPPadsForLevel */
/*---------------------------------------------------------------------------*/ /**
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) { * @param Evidence evidence value to return color for
/* * @return Color which corresponds to specified Evidence value.
** Parameters: * @note Globals: none
** Evidence evidence value to return color for * @note Exceptions: none
** Globals: none * @note History: Thu Mar 21 15:24:52 1991, DSJ, Created.
** Operation:
** Return: Color which corresponds to specified Evidence value.
** Exceptions: none
** History: Thu Mar 21 15:24:52 1991, DSJ, Created.
*/ */
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) {
assert (Evidence >= 0.0); assert (Evidence >= 0.0);
assert (Evidence <= 1.0); assert (Evidence <= 1.0);
@ -1572,21 +1550,19 @@ ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) {
} /* GetMatchColorFor */ } /* GetMatchColorFor */
/*---------------------------------------------------------------------------*/ /**
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
** Parameters: * always be called before GetNextFill() to ensure that we
** Filler filler to get next fill spec from * do not run past the end of the fill table.
** Fill place to put spec for next fill * @param Filler filler to get next fill spec from
** Globals: none * @param Fill place to put spec for next fill
** Operation: This routine returns (in Fill) the specification of * @return none (results are returned in Fill)
** the next line to be filled from Filler. FillerDone() should * @note Globals: none
** always be called before GetNextFill() to ensure that we * @note Exceptions: none
** do not run past the end of the fill table. * @note History: Tue Feb 19 10:17:42 1991, DSJ, Created.
** Return: none (results are returned in Fill)
** Exceptions: none
** History: Tue Feb 19 10:17:42 1991, DSJ, Created.
*/ */
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
FILL_SWITCH *Next; FILL_SWITCH *Next;
/* compute the fill assuming no switches will be encountered */ /* compute the fill assuming no switches will be encountered */
@ -1625,7 +1601,6 @@ void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
} /* GetNextFill */ } /* GetNextFill */
/*---------------------------------------------------------------------------*/
/** /**
* This routine computes a data structure (Filler) * This routine computes a data structure (Filler)
* which can be used to fill in a rectangle surrounding * which can be used to fill in a rectangle surrounding
@ -1635,9 +1610,8 @@ void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
* @param Proto proto to create a filler for * @param Proto proto to create a filler for
* @param Filler place to put table filler * @param Filler place to put table filler
* *
* Globals: none
*
* @return none (results are returned in Filler) * @return none (results are returned in Filler)
* @note Globals: none
* @note Exceptions: none * @note Exceptions: none
* @note History: Thu Feb 14 09:27:05 1991, DSJ, Created. * @note History: Thu Feb 14 09:27:05 1991, DSJ, Created.
*/ */
@ -1794,14 +1768,13 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#ifndef GRAPHICS_DISABLED #ifndef GRAPHICS_DISABLED
/* /**
* Parameters: * This routine renders the specified feature into ShapeList.
* ShapeList shape list to add feature rendering to * @param ShapeList shape list to add feature rendering to
* Feature feature to be rendered * @param Feature feature to be rendered
* Color color to use for feature rendering * @param Color color to use for feature rendering
* Globals: none * @return New shape list with rendering of Feature added.
* Operation: This routine renders the specified feature into ShapeList. * @note Globals: none
* Return: New shape list with rendering of Feature added.
* @note Exceptions: none * @note Exceptions: none
* @note History: Thu Mar 21 14:57:41 1991, DSJ, Created. * @note History: Thu Mar 21 14:57:41 1991, DSJ, Created.
*/ */
@ -1826,8 +1799,7 @@ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
} /* RenderIntFeature */ } /* RenderIntFeature */
/*---------------------------------------------------------------------------*/ /**
/*
* This routine extracts the parameters of the specified * This routine extracts the parameters of the specified
* proto from the class description and adds a rendering of * proto from the class description and adds a rendering of
* the proto onto the ShapeList. * the proto onto the ShapeList.
@ -1894,7 +1866,6 @@ void RenderIntProto(ScrollView *window,
} /* RenderIntProto */ } /* RenderIntProto */
#endif #endif
/*---------------------------------------------------------------------------*/
/** /**
* This routine truncates Param to lie within the range * This routine truncates Param to lie within the range
* of Min-Max inclusive. If a truncation is performed, and * of Min-Max inclusive. If a truncation is performed, and
@ -1971,8 +1942,8 @@ void InitFeatureDisplayWindowIfReqd() {
} }
} }
// Creates a window of the appropriate size for displaying elements /// Creates a window of the appropriate size for displaying elements
// in feature space. /// in feature space.
ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos) { ScrollView* CreateFeatureSpaceWindow(const char* name, int xpos, int ypos) {
return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true); return new ScrollView(name, xpos, ypos, 520, 520, 260, 260, true);
} }