📄 intproto.cpp
字号:
** 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 >= NumIntProtosIn (Class)) cprintf ("AddProtoToProtoPruner:assert failed: %d < %d", ProtoId, NumIntProtosIn (Class)); assert (ProtoId < NumIntProtosIn (Class)); Index = IndexForProto (ProtoId); ProtoSet = ProtoSetIn (Class, SetForProto (ProtoId)); Angle = ProtoAngle (Proto); FillPPCircularBits (ProtoSet->ProtoPruner[PRUNER_ANGLE], Index, Angle + ANGLE_SHIFT, PPAnglePad / 360.0); Angle *= 2.0 * PI; Length = ProtoLength (Proto); X = ProtoX (Proto) + X_SHIFT; Pad = max (fabs (cos (Angle)) * (Length / 2.0 + PPEndPad * GetPicoFeatureLength ()), fabs (sin (Angle)) * (PPSidePad * GetPicoFeatureLength ())); FillPPLinearBits (ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad); Y = ProtoY (Proto) + Y_SHIFT; Pad = max (fabs (sin (Angle)) * (Length / 2.0 + PPEndPad * GetPicoFeatureLength ()), fabs (cos (Angle)) * (PPSidePad * GetPicoFeatureLength ())); FillPPLinearBits (ProtoSet->ProtoPruner[PRUNER_Y], Index, Y, Pad);} /* AddProtoToProtoPruner *//*---------------------------------------------------------------------------*/int BucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets) {/* ** 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. */ int Bucket; Bucket = (int) MapParam (Param, Offset, NumBuckets); if (Bucket < 0) Bucket = 0; else if (Bucket >= NumBuckets) Bucket = NumBuckets - 1; return (Bucket);} /* BucketFor *//*---------------------------------------------------------------------------*/int CircBucketFor(FLOAT32 Param, FLOAT32 Offset, int NumBuckets) {/* ** 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 = (int) MapParam (Param, Offset, NumBuckets); if (Bucket < 0) Bucket += NumBuckets; else if (Bucket >= NumBuckets) Bucket -= NumBuckets; return (Bucket);} /* CircBucketFor *//*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoid UpdateMatchDisplay() {/* ** 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) c_make_current(IntMatchWindow);} /* ClearMatchDisplay */#endif/*---------------------------------------------------------------------------*/void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class) {/* ** 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 < NumIntProtosIn (Class); ProtoId++) if (test_bit (Config, ProtoId)) { Proto = ProtoForProtoId (Class, ProtoId); SET_BIT (Proto->Configs, ConfigId); TotalLength += LengthForProtoId (Class, ProtoId); } LengthForConfigId (Class, ConfigId) = TotalLength;} /* ConvertConfig *//*---------------------------------------------------------------------------*/void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) {/* ** Parameters: ** Proto floating-pt proto to be converted to integer format ** ProtoId id of proto ** Class integer class to add converted proto to ** Globals: none ** Operation: This routine converts Proto to integer format and ** installs it as ProtoId in Class. ** Return: none ** Exceptions: none ** History: Fri Feb 8 11:22:43 1991, DSJ, Created. */ INT_PROTO P; FLOAT32 Param; assert (ProtoId < NumIntProtosIn (Class)); P = ProtoForProtoId (Class, ProtoId); Param = CoefficientA (Proto) * 128; P->A = TruncateParam (Param, -128, 127, NULL); Param = -CoefficientB (Proto) * 256; P->B = TruncateParam (Param, 0, 255, NULL); Param = CoefficientC (Proto) * 128; P->C = TruncateParam (Param, -128, 127, NULL); Param = ProtoAngle (Proto) * 256; if (Param < 0 || Param >= 256) P->Angle = 0; else P->Angle = (UINT8) Param; /* round proto length to nearest integer number of pico-features */ Param = (ProtoLength (Proto) / GetPicoFeatureLength ()) + 0.5; LengthForProtoId (Class, ProtoId) = TruncateParam (Param, 1, 255, NULL); if (LearningDebugLevel >= 2) cprintf ("Converted ffeat to (A=%d,B=%d,C=%d,L=%d)", P->A, P->B, P->C, LengthForProtoId (Class, ProtoId));} /* ConvertProto *//*---------------------------------------------------------------------------*/INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) {/* ** Parameters: ** FloatProtos prototypes in old floating pt format ** Globals: none ** Operation: This routine converts from the old floating point format ** to the new integer format. ** Return: New set of training templates in integer format. ** Exceptions: none ** History: Thu Feb 7 14:40:42 1991, DSJ, Created. */ INT_TEMPLATES IntTemplates; CLASS_TYPE FClass; INT_CLASS IClass; int ClassId; int ProtoId; int ConfigId; IntTemplates = NewIntTemplates (); for (ClassId = 0; ClassId < NUMBER_OF_CLASSES; ClassId++) { FClass = &(FloatProtos[ClassId]); if (NumProtosIn (FClass) > 0) { assert (UnusedClassIdIn (IntTemplates, ClassId)); IClass = NewIntClass (NumProtosIn (FClass), NumConfigsIn (FClass)); AddIntClass(IntTemplates, ClassId, IClass); for (ProtoId = 0; ProtoId < NumProtosIn (FClass); ProtoId++) { AddIntProto(IClass); ConvertProto (ProtoIn (FClass, ProtoId), ProtoId, IClass); AddProtoToProtoPruner (ProtoIn (FClass, ProtoId), ProtoId, IClass); AddProtoToClassPruner (ProtoIn (FClass, ProtoId), ClassId, IntTemplates); } for (ConfigId = 0; ConfigId < NumConfigsIn (FClass); ConfigId++) { AddIntConfig(IClass); ConvertConfig (ConfigIn (FClass, ConfigId), ConfigId, IClass); } } } return (IntTemplates);} /* CreateIntTemplates *//*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoid DisplayIntFeature(INT_FEATURE Feature, FLOAT32 Evidence) {/* ** 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. */ C_COL Color; Color = GetMatchColorFor (Evidence); RenderIntFeature(IntMatchWindow, Feature, Color);} /* DisplayIntFeature *//*---------------------------------------------------------------------------*/void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence) {/* ** 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. */ C_COL Color; Color = GetMatchColorFor (Evidence); RenderIntProto(IntMatchWindow, Class, ProtoId, Color);} /* DisplayIntProto */#endif/*---------------------------------------------------------------------------*/void InitIntProtoVars() {/* ** Parameters: none ** Globals: none ** Operation: Initialize the control variables for the integer proto ** routines. ** Return: none ** Exceptions: none ** History: Tue Feb 12 08:04:34 1991, DSJ, Created. */ MakeNumCPLevels(); MakeCPAnglePadLoose(); MakeCPAnglePadMedium(); MakeCPAnglePadTight(); MakeCPEndPadLoose(); MakeCPEndPadMedium(); MakeCPEndPadTight(); MakeCPSidePadLoose(); MakeCPSidePadMedium(); MakeCPSidePadTight(); MakePPAnglePad(); MakePPEndPad(); MakePPSidePad();} /* InitIntProtoVars *//*---------------------------------------------------------------------------*/INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs) {/* ** 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; register UINT32 *Word; assert (MaxNumConfigs <= MAX_NUM_CONFIGS); Class = (INT_CLASS) Emalloc (sizeof (INT_CLASS_STRUCT)); NumProtoSetsIn (Class) = ((MaxNumProtos + PROTOS_PER_PROTO_SET - 1) / PROTOS_PER_PROTO_SET); assert (NumProtoSetsIn (Class) <= MAX_NUM_PROTO_SETS); NumIntProtosIn (Class) = 0; NumIntConfigsIn (Class) = 0; for (i = 0; i < NumProtoSetsIn (Class); i++) { /* allocate space for a proto set, install in class, and initialize */ ProtoSet = (PROTO_SET) Emalloc (sizeof (PROTO_SET_STRUCT)); ProtoSetIn (Class, i) = ProtoSet; for (Word = (UINT32 *) (ProtoPrunerFor (ProtoSet)); Word < (UINT32 *) (ProtoPrunerFor (ProtoSet)) + WERDS_PER_PP; *Word++ = 0); /* allocate space for the proto lengths and install in class */ } Class->ProtoLengths = (UINT8 *) Emalloc (MaxNumIntProtosIn (Class) * sizeof (UINT8)); return (Class);} /* NewIntClass *//*-------------------------------------------------------------------------*/void free_int_class( /*class to free */ INT_CLASS int_class) { int i; for (i = 0; i < NumProtoSetsIn (int_class); i++) { Efree (ProtoSetIn (int_class, i)); } Efree (int_class->ProtoLengths); Efree(int_class);}/*---------------------------------------------------------------------------*/INT_TEMPLATES NewIntTemplates() {/* ** 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)); NumClassesIn (T) = 0; NumClassPrunersIn (T) = 0; /* initialize mapping tables */ for (i = 0; i <= MAX_CLASS_ID; i++) IndexForClassId (T, i) = ILLEGAL_CLASS; for (i = 0; i < MAX_NUM_CLASSES; i++) ClassIdForIndex (T, i) = NO_CLASS; return (T);} /* NewIntTemplates *//*---------------------------------------------------------------------------*/void free_int_templates(INT_TEMPLATES templates) { int i; for (i = 0; i < NumClassesIn (templates); i++) free_int_class (ClassForIndex (templates, i)); for (i = 0; i < NumClassPrunersIn (templates); i++) Efree (templates->ClassPruner[i]); Efree(templates);}/*---------------------------------------------------------------------------*/INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) {/* ** Parameters: ** File open file to read templates from ** Globals: none ** Operation: This routine reads a set of integer templates from ** File. File must already be open and must be in the ** correct binary format. ** Return: Pointer to integer templates read from File. ** Exceptions: none ** History: Wed Feb 27 11:48:46 1991, DSJ, Created. */ int i, j, x, y, z; int nread; INT_TEMPLATES Templates; CLASS_PRUNER Pruner; INT_CLASS Class; UINT8 *Lengths; PROTO_SET ProtoSet;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -