Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.4 KiB

  1. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All rights reserved.
  4. //
  5. // Module:
  6. // hound.h
  7. //
  8. // Description:
  9. // Definitions for the hound project.
  10. //
  11. // Author:
  12. // jbenn
  13. //
  14. //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  15. #ifndef __INCLUDE_HOUND
  16. #define __INCLUDE_HOUND
  17. #include "common.h"
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. ////
  23. //// Structures to hold the Hound database.
  24. ////
  25. // Limit we force on the number of components in one model. Most models have
  26. // a much smaller number of components.
  27. #define MAX_HOUND_COMPONENTS 20
  28. // Limit on the number of features in a single feature vector. Currently
  29. // the max strokes Zilla allows times the # of features per stroke.
  30. #define MAX_HOUND_FEATURES (29 * 4)
  31. // MAx stroke count at which we use the midpoints of each stroke.
  32. #define MAX_HOUND_STROKES_USE_MIDPOINT 4
  33. // Pair of features referenced by dependency.
  34. typedef struct tagDEPEND_PAIR
  35. {
  36. BYTE dependor;
  37. BYTE depende;
  38. } DEPEND_PAIR;
  39. // Weight structure used for dependencies.
  40. typedef struct tagDEPEND_WEIGHT
  41. {
  42. signed char weight;
  43. BYTE scale;
  44. } DEPEND_WEIGHT;
  45. // Per space information.
  46. // Store size of space as two WORDs so we only have to have WORD alignment,
  47. // instead of DWORD alignment. This data is in the resource, and is read-
  48. // only as a result.
  49. typedef struct tagHOUND_SPACE {
  50. WORD spaceSizeLow; // Space size, low word.
  51. WORD spaceSizeHigh; // Space size, high word.
  52. BYTE spaceNumber; // Space number (stroke count, after cracking)
  53. BYTE numFeat; // Number of features per sample.
  54. BYTE spare;
  55. BYTE maxComponents; // Max components in any model in the space.
  56. WORD maxDependancy; // Max dependencies in any model in the space.
  57. WORD cPairOneByte; // Count of 1 byte dependency pair table entries.
  58. WORD cPairTable; // Count of all dependency pair table entries.
  59. WORD cWeightOneByte; // Count of 1 byte dependency weight table entries.
  60. WORD cWeightTable; // Count of all dependency weight table entries.
  61. BYTE modelData[2]; // Variable size array containing model tables and data.
  62. } HOUND_SPACE;
  63. // The main header.
  64. typedef struct tagHOUND_DB {
  65. int cSpaces; // Number of spaces loaded.
  66. UINT minSpace; // Min and Max space numbers loaded
  67. UINT maxSpace; // (minSpace - maxSpace) + 1 == cSpaces
  68. HOUND_SPACE **ppSpaces; // Data on each space loaded.
  69. BYTE **appModelIndex[30]; // Index for each model in each space (set when used).
  70. } HOUND_DB;
  71. // Global holding information to access loaded hound database.
  72. extern HOUND_DB g_houndDB;
  73. ////
  74. //// Functions for handling Hound DB.
  75. ////
  76. // Load the resource file with the hound data.
  77. BOOL HoundLoadRes(HINSTANCE hInst, int resNumber, int resType,
  78. LOCRUN_INFO *pLocRunInfo);
  79. // Unload the resource file with the hound data. Actually just frees allocated memory, but if we
  80. // ever need to actually unload the resources, this is where it will go.
  81. BOOL HoundUnLoadRes();
  82. // Load hound data from a file.
  83. BOOL HoundLoadFile(
  84. LOCRUN_INFO *pLocRunInfo,
  85. LOAD_INFO *pLoadInfo,
  86. wchar_t *pwchPathName
  87. );
  88. // Unload hound data loaded from a file.
  89. BOOL HoundUnLoadFile(LOAD_INFO *pInfo);
  90. #ifndef HWX_PRODUCT
  91. // Load hound data for a single space from a file.
  92. extern HOUND_SPACE *HoundSpaceLoadFile(wchar_t *pwchFileName);
  93. // Parse a Hound space and record the location of each model in it.
  94. extern BOOL ParseHoundSpace(HOUND_SPACE *pSpace);
  95. // Print out each code point supported and the number of models it has.
  96. extern BOOL HoundPrintModelList(FILE *pFile);
  97. // Variables set by ParseHoundSpace.
  98. extern int g_maxModelsPerCP;
  99. extern int g_iMinModelHead;
  100. extern int g_iMaxModelHead;
  101. // Given a data sample and a code point, give the score for each model for
  102. // that code point. This fills in the scores in order of the models in
  103. // the DB. The array must be big enough to hold all the scores. The return
  104. // value give the number of entries filled in.
  105. extern int HoundMatchCodePoint(
  106. wchar_t dchLabel,
  107. const BYTE * const pSampleVector,
  108. double *pScores
  109. );
  110. // Copy one of the loaded models to an output file.
  111. extern int HoundCopyModelToFile(FILE *pFile, wchar_t dchLabel, int iModel);
  112. #endif
  113. // Find the most likely model (code point) given a case
  114. extern BOOL HoundMatch(UINT iSpace, const BYTE * const pSampleVector, ALT_LIST *pAltList);
  115. // Find the most likely model (code point) given a case with numFeatSample / 4 strokes
  116. // log p(model|x) = log p(x|model) - normalization value
  117. // normalization constant = log( \sum_i p(x|model_i) * p(model_i) )
  118. // We are only interested in ranking models, and it is therefore not necessary to normalize.
  119. // This would not be the case if we want to return the actualy probability for model(s)
  120. // Notice: If bounding boxes didn't change (too much) each time a new stroke is added
  121. // there is a HUGE possibility for improving computational efficiency for this function.
  122. // In this case most of the computations from previous strokes can be re-used.
  123. // Do all spaces from current length up.
  124. extern VOID HoundStartMatch(
  125. const BYTE * pSampleVector,
  126. BYTE numFeatSample,
  127. ALT_LIST *pAltList,
  128. const DWORD *pdwAbort, // Address of abort parameter
  129. DWORD cstrk // Number of strokes in character
  130. );
  131. // Given a data sample and a code point, give the score for that model.
  132. extern BOOL HoundMatchSingle(
  133. UINT iSpace,
  134. wchar_t dchLabel,
  135. const BYTE * const pSampleVector,
  136. double *pScore
  137. );
  138. #ifdef __cplusplus
  139. };
  140. #endif
  141. #endif // !__INCLUDE_HOUND