~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/match/match.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /* match.c
  4  * 
  5  * a genericly defined matching structure
  6  * 
  7  * typedef struct match { int type; int label; float weight; void *to1;
  8  * void *to2; struct list *props; } Match; */
  9 
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/vision.h>
 14 #ifdef _PCC
 15 #include <memory.h>
 16 #endif
 17 
 18 /* static variable for unique match label generation */
 19 static int label = 0;
 20 
 21 /* allocate match structure body of specified type */
 22 Match  *match_alloc(int type)
 23 {
 24     Match  *match = ts_ralloc(Match);
 25 
 26     match->type = type;
 27     match->label = label++;
 28     match->weight = (float)1.0;
 29     match->to1 = match->to2 = NULL;
 30     match->props = NULL;
 31     return (match);
 32 }
 33 
 34 /* allocate match structure and make it reference generic pointers of
 35  * specified type
 36  * 
 37  * note that the match structure is for matches between things of the same
 38  * tyoe */
 39 Match  *match_make(void *ptr1, void *ptr2, int type)
 40 {
 41     Match  *match = ts_ralloc(Match);
 42 
 43     match->type = type;
 44     match->label = label++;
 45     match->weight = (float)1.0;
 46     match->to1 = ptr1;
 47     match->to2 = ptr2;
 48     match->props = NULL;
 49     return (match);
 50 }
 51 
 52 /* copy the match data structure and make a copy of its property list
 53  * 
 54  * changes to the properties will be shared */
 55 Match  *match_copy(Match * match)
 56 {
 57     Match  *copy;
 58 
 59     if (match == NULL)
 60         return (NULL);
 61 
 62     copy = ts_ralloc(Match);
 63     (void) memcpy((char *) copy, (char *) match, sizeof(Match));
 64     copy->props = proplist_copy(match->props);
 65     return (copy);
 66 }
 67 
 68 /* find the mostr strongly weighted match in a list */
 69 double  mlist_strongest(List * mlist, double (*cost_func) ( /* ??? */ ))
 70 {
 71     double  maxs = 0;
 72 
 73     while (mlist != NULL)
 74     {
 75         Match  *m = (Match *) mlist->to;
 76         double  s;
 77 
 78         s = (cost_func == NULL) ? m->weight : cost_func(m);
 79 
 80         if (s > maxs)
 81             maxs = s;
 82         mlist = mlist->next;
 83     }
 84     return (maxs);
 85 }
 86 
 87 /* check if to2 is referenced as a ->to2 of any element of the match
 88  * list */
 89 Bool    mlist_to2_exists(List * mlist, void *to2)
 90 {
 91     List   *ptr;
 92 
 93     for (ptr = mlist; ptr != NULL; ptr = ptr->next)
 94         if (((Match *) ptr->to)->to2 == to2)
 95             return (true);
 96     return (false);
 97 }
 98 
 99 /* generate a list of the second reference (->to2) of a match list */
100 List   *mlist_to2_list(List * mlist)
101 {
102     List   *mptr;
103     List   *list = NULL;
104 
105     for (mptr = mlist; mptr != NULL; mptr = mptr->next)
106     {
107         Match  *m = (Match *) mptr->to;
108 
109         list = ref_addtostart(list, (void *) m->to2, m->type);
110     }
111     return (list_reverse(list));
112 }
113 
114 void    match_free(Match * match)
115 {
116     if (match == NULL)
117         return;
118     proplist_freelist(match->props);
119     match->props = NULL;
120     rfree((void *) match);
121 }
122 
123 void    match_copy_free(Match * match)
124 /* don't free up the proplist as this was not allocated 
125    NAT 22/12/99 */
126 {
127     if (match == NULL)
128         return;
129     list_rm_links(match->props);
130     match->props = NULL;
131     rfree((void *) match);
132 }
133 
134 void    mlist_free(List * mlist)
135 /* list of matches */
136 {
137     list_rm(mlist, match_free);
138 }
139 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.