📄 intproto.cpp
字号:
/* first read the high level template struct */ Templates = NewIntTemplates (); // Read Templates in parts for 64 bit compatibility. if (fread(&Templates->NumClasses, sizeof(int), 1, File) != 1 || fread(&Templates->NumClassPruners, sizeof(int), 1, File) != 1) cprintf ("Bad read of inttemp!\n"); for (i = 0; i <= MAX_CLASS_ID; ++i) { if (fread(&Templates->IndexFor[i], sizeof(CLASS_INDEX), 1, File) != 1) cprintf("Bad read of inttemp!\n"); } for (i = 0; i < MAX_NUM_CLASSES; ++i) { if (fread(&Templates->ClassIdFor[i], sizeof(CLASS_ID), 1, File) != 1) cprintf("Bad read of inttemp!\n"); } for (i = 0; i < MAX_NUM_CLASSES + MAX_NUM_CLASS_PRUNERS; ++i) { int junk; if (fread(&junk, sizeof(junk), 1, File) != 1) cprintf("Bad read of inttemp!\n"); } // Swap status is determined automatically. swap = Templates->NumClassPruners < 0 || Templates->NumClassPruners > MAX_NUM_CLASS_PRUNERS; if (swap) { reverse32 (&Templates->NumClassPruners); reverse32 (&Templates->NumClasses); for (i = 0; i < MAX_CLASS_ID + 1; i++) reverse16 (&Templates->IndexFor[i]); } /* then read in the class pruners */ for (i = 0; i < NumClassPrunersIn (Templates); i++) { Pruner = (CLASS_PRUNER) Emalloc (sizeof (CLASS_PRUNER_STRUCT)); if ((nread = fread ((char *) Pruner, 1, sizeof (CLASS_PRUNER_STRUCT), File)) != sizeof (CLASS_PRUNER_STRUCT)) cprintf ("Bad read of inttemp!\n"); if (swap) { for (j = 0; j < NUM_CP_BUCKETS; j++) { for (x = 0; x < NUM_CP_BUCKETS; x++) { for (y = 0; y < NUM_CP_BUCKETS; y++) { for (z = 0; z < WERDS_PER_CP_VECTOR; z++) { reverse32 (&Pruner[j][x][y][z]); } } } } } Templates->ClassPruner[i] = Pruner; } /* then read in each class */ for (i = 0; i < NumClassesIn (Templates); i++) { /* first read in the high level struct for the class */ Class = (INT_CLASS) Emalloc (sizeof (INT_CLASS_STRUCT)); if (fread(&Class->NumProtos, sizeof(Class->NumProtos), 1, File) != 1 || fread(&Class->NumProtoSets, sizeof(Class->NumProtoSets), 1, File) != 1 || fread(&Class->NumConfigs, sizeof(Class->NumConfigs), 1, File) != 1) cprintf ("Bad read of inttemp!\n"); for (j = 0; j <= MAX_NUM_PROTO_SETS; ++j) { int junk; if (fread(&junk, sizeof(junk), 1, File) != 1) cprintf ("Bad read of inttemp!\n"); } for (j = 0; j < MAX_NUM_CONFIGS; ++j) { if (fread(&Class->ConfigLengths[j], sizeof(UINT16), 1, File) != 1) cprintf ("Bad read of inttemp!\n"); } if (swap) { reverse16 (&Class->NumProtos); for (j = 0; j < MAX_NUM_CONFIGS; j++) reverse16 (&Class->ConfigLengths[j]); } ClassForIndex (Templates, i) = Class; /* then read in the proto lengths */ Lengths = (UINT8 *) Emalloc (sizeof (UINT8) * MaxNumIntProtosIn (Class)); if ((nread = fread ((char *) Lengths, sizeof (UINT8), MaxNumIntProtosIn (Class), File)) != MaxNumIntProtosIn (Class)) cprintf ("Bad read of inttemp!\n"); Class->ProtoLengths = Lengths; /* then read in the proto sets */ for (j = 0; j < NumProtoSetsIn (Class); j++) { ProtoSet = (PROTO_SET) Emalloc (sizeof (PROTO_SET_STRUCT)); if ((nread = fread ((char *) ProtoSet, 1, sizeof (PROTO_SET_STRUCT), File)) != sizeof (PROTO_SET_STRUCT)) cprintf ("Bad read of inttemp!\n"); if (swap) { for (x = 0; x < NUM_PP_PARAMS; x++) for (y = 0; y < NUM_PP_BUCKETS; y++) for (z = 0; z < WERDS_PER_PP_VECTOR; z++) reverse32 (&ProtoSet->ProtoPruner[x][y][z]); for (x = 0; x < PROTOS_PER_PROTO_SET; x++) for (y = 0; y < WERDS_PER_CONFIG_VEC; y++) reverse32 (&ProtoSet->Protos[x].Configs[y]); } ProtoSetIn (Class, j) = ProtoSet; } } return (Templates);} /* ReadIntTemplates *//*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDvoid ShowMatchDisplay() {/* ** Parameters: none ** Globals: ** FeatureShapes display list containing feature matches ** ProtoShapes display list containing proto matches ** Operation: This routine sends the shapes in the global display ** lists to the match debugger window. ** Return: none ** Exceptions: none ** History: Thu Mar 21 15:47:33 1991, DSJ, Created. */ void *window; /* Size of drawable */ if (IntMatchWindow == NULL) { IntMatchWindow = c_create_window ("IntMatchWindow", 50, 200, 520, 520, -130.0, 130.0, -130.0, 130.0); } else c_clear_window(IntMatchWindow); window = IntMatchWindow; c_line_color_index(window, Grey); /* Default size of drawing */ if (NormMethod == baseline) { c_move (window, -1000.0, INT_BASELINE); c_draw (window, 1000.0, INT_BASELINE); c_move (window, -1000.0, INT_DESCENDER); c_draw (window, 1000.0, INT_DESCENDER); c_move (window, -1000.0, INT_XHEIGHT); c_draw (window, 1000.0, INT_XHEIGHT); c_move (window, -1000.0, INT_CAPHEIGHT); c_draw (window, 1000.0, INT_CAPHEIGHT); c_move (window, INT_MIN_X, -1000.0); c_draw (window, INT_MIN_X, 1000.0); c_move (window, INT_MAX_X, -1000.0); c_draw (window, INT_MAX_X, 1000.0); } else { c_move (window, INT_XCENTER - INT_XRADIUS, INT_YCENTER - INT_YRADIUS); c_draw (window, INT_XCENTER + INT_XRADIUS, INT_YCENTER - INT_YRADIUS); c_move (window, INT_XCENTER - INT_XRADIUS, INT_YCENTER + INT_YRADIUS); c_draw (window, INT_XCENTER + INT_XRADIUS, INT_YCENTER + INT_YRADIUS); c_move (window, INT_XCENTER - INT_XRADIUS, INT_YCENTER - INT_YRADIUS); c_draw (window, INT_XCENTER - INT_XRADIUS, INT_YCENTER + INT_YRADIUS); c_move (window, INT_XCENTER + INT_XRADIUS, INT_YCENTER - INT_YRADIUS); c_draw (window, INT_XCENTER + INT_XRADIUS, INT_YCENTER + INT_YRADIUS); c_move(window, INT_MIN_X, INT_MIN_Y); c_draw(window, INT_MIN_X, INT_MAX_Y); c_move(window, INT_MIN_X, INT_MIN_Y); c_draw(window, INT_MAX_X, INT_MIN_Y); c_move(window, INT_MAX_X, INT_MAX_Y); c_draw(window, INT_MIN_X, INT_MAX_Y); c_move(window, INT_MAX_X, INT_MAX_Y); c_draw(window, INT_MAX_X, INT_MIN_Y); }} /* ShowMatchDisplay */#endif/*---------------------------------------------------------------------------*/void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) {/* ** 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_CLASS Class; /* first write the high level template struct */ fwrite ((char *) Templates, sizeof (INT_TEMPLATES_STRUCT), 1, File); /* then write out the class pruners */ for (i = 0; i < NumClassPrunersIn (Templates); i++) fwrite ((char *) (Templates->ClassPruner[i]), sizeof (CLASS_PRUNER_STRUCT), 1, File); /* then write out each class */ for (i = 0; i < NumClassesIn (Templates); i++) { Class = ClassForIndex (Templates, i); /* first write out the high level struct for the class */ fwrite ((char *) Class, sizeof (INT_CLASS_STRUCT), 1, File); /* then write out the proto lengths */ fwrite ((char *) (Class->ProtoLengths), sizeof (UINT8), MaxNumIntProtosIn (Class), File); /* then write out the proto sets */ for (j = 0; j < NumProtoSetsIn (Class); j++) fwrite ((char *) ProtoSetIn (Class, j), sizeof (PROTO_SET_STRUCT), 1, File); }} /* WriteIntTemplates *//**---------------------------------------------------------------------------- Private Code----------------------------------------------------------------------------**//*---------------------------------------------------------------------------*/FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) {/* ** Parameters: ** Bucket bucket whose start is to be computed ** Offset offset used to map params to buckets ** NumBuckets total number of buckets ** Globals: none ** Operation: This routine returns the parameter value which ** corresponds to the beginning of the specified bucket. ** The bucket number should have been generated using the ** BucketFor() function with parameters Offset and NumBuckets. ** Return: Param value corresponding to start position of Bucket. ** Exceptions: none ** History: Thu Feb 14 13:24:33 1991, DSJ, Created. */ return (((FLOAT32) Bucket / NumBuckets) - Offset);} /* BucketStart *//*---------------------------------------------------------------------------*/FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) {/* ** Parameters: ** Bucket bucket whose end is to be computed ** Offset offset used to map params to buckets ** NumBuckets total number of buckets ** Globals: none ** Operation: This routine returns the parameter value which ** corresponds to the end of the specified bucket. ** The bucket number should have been generated using the ** BucketFor() function with parameters Offset and NumBuckets. ** Return: Param value corresponding to end position of Bucket. ** Exceptions: none ** History: Thu Feb 14 13:24:33 1991, DSJ, Created. */ return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);} /* BucketEnd *//*---------------------------------------------------------------------------*/void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER Pruner, register UINT32 ClassMask, register UINT32 ClassCount, register UINT32 WordIndex) {/* ** Parameters: ** FillSpec specifies which bits to fill in pruner ** Pruner class pruner to be filled ** ClassMask indicates which bits to change in each word ** ClassCount indicates what to change bits to ** WordIndex indicates which word to change ** Globals: none ** Operation: This routine fills in the section of a class pruner ** corresponding to a single x value for a single proto of ** a class. ** Return: none ** Exceptions: none ** History: Tue Feb 19 11:11:29 1991, DSJ, Created. */ register int X, Y, Angle; register UINT32 OldWord; X = FillSpec->X; if (X < 0) X = 0; if (X >= NUM_CP_BUCKETS) X = NUM_CP_BUCKETS - 1; if (FillSpec->YStart < 0) FillSpec->YStart = 0; if (FillSpec->YEnd >= NUM_CP_BUCKETS) FillSpec->YEnd = NUM_CP_BUCKETS - 1; for (Y = FillSpec->YStart; Y <= FillSpec->YEnd; Y++) for (Angle = FillSpec->AngleStart; TRUE; CircularIncrement (Angle, NUM_CP_BUCKETS)) { OldWord = Pruner[X][Y][Angle][WordIndex]; if (ClassCount > (OldWord & ClassMask)) { OldWord &= ~ClassMask; OldWord |= ClassCount; Pruner[X][Y][Angle][WordIndex] = OldWord; } if (Angle == FillSpec->AngleEnd) break; }} /* DoFill *//*---------------------------------------------------------------------------*/BOOL8 FillerDone(TABLE_FILLER *Filler) {/* ** Parameters: ** Filler table filler to check if done ** Globals: none ** Operation: Return TRUE if the specified table filler is done, i.e. ** if it has no more lines to fill. ** Return: TRUE if no more lines to fill, FALSE otherwise. ** Exceptions: none ** History: Tue Feb 19 10:08:05 1991, DSJ, Created. */ FILL_SWITCH *Next; Next = &(Filler->Switch[Filler->NextSwitch]); if (Filler->X > Next->X && Next->Type == LastSwitch) return (TRUE); else return (FALSE);} /* FillerDone *//*---------------------------------------------------------------------------*/voidFillPPCircularBits (UINT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],int Bit, FLOAT32 Center, FLOAT32 Spread) {/* ** Parameters: ** ParamTable table of bit vectors, one per param bucket ** Bit bit position in vectors to be 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 circular dimension, i.e. bucket 0 is adjacent ** to the last bucket. It is assumed that Center and Spread ** are expressed in a circular coordinate system whose range ** is 0 to 1. ** Return: none ** Exceptions: none ** History: Tue Oct 16 09:26:54 1990, DSJ, Created. */ int i, FirstBucket, LastBucket; if (Spread > 0.5) Spread = 0.5; FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS); if (FirstBucket < 0) FirstBucket += NUM_PP_BUCKETS; LastBucket = (int) floor ((Center + Spread) * NUM_PP_BUCKETS); if (LastBucket >= NUM_PP_BUCKETS) LastBucket -= NUM_PP_BUCKETS; if (LearningDebugLevel >= 2) cprintf ("Circular fill from %d to %d", FirstBucket, LastBucket); for (i = FirstBucket; TRUE; CircularIncrement (i, NUM_PP_BUCKETS)) { SET_BIT (ParamTable[i], Bit); /* exit loop after we have set the bit for the last bucket */ if (i == LastBucket) break; }} /* FillPPCircularBits *//*---------------------------------------------------------------------------*/voidFillPPLinearBits (UINT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],int Bit, FLOAT32 Center, FLOAT32 Spread) {/* ** 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; FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS); if (FirstBucket < 0) FirstBucket = 0; LastBucket = (int) floor ((Center + Spread) * NUM_PP_BUCKETS); if (LastBucket >= NUM_PP_BUCKETS) LastBucket = NUM_PP_BUCKETS - 1; if (LearningDebugLevel >= 2) cprintf ("Linear fill from %d to %d", FirstBucket, LastBucket); for (i = FirstBucket; i <= LastBucket; i++) SET_BIT (ParamTable[i], Bit);} /* FillPPLinearBits *//*---------------------------------------------------------------------------*/#ifndef GRAPHICS_DISABLEDCLASS_ID GetClassToDebug(const char *Prompt) {/* ** 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. */ return window_wait (IntMatchWindow);} /* GetClassToDebug */#endif/*---------------------------------------------------------------------------*/void GetCPPadsForLevel(int Level,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -