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

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

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

  1 /**@(#)
  2 **/
  3 /**
  4 *
  5 * edge.c
  6 *
  7 * edge handling functions
  8 *
  9 *
 10 * typedef struct edgel
 11 * {
 12 *     int type;
 13 *     int label;
 14 *     struct vec2 pos;
 15 *     float orient;
 16 *     float contrast;
 17 *     struct list *props;
 18 * } Edgel;
 19 *
 20 */
 21 
 22 #include <stdio.h>
 23 #include <tina/sys.h>
 24 #include <tina/sys_types.h>
 25 #include <tina/sysfuncs.h>
 26 #include <tina/math.h>
 27 #include <tina/mathfuncs.h>
 28 #include <tina/tina_types.h>
 29 #include <tina/edge.h>
 30 #ifdef _PCC
 31 #include <memory.h>
 32 #endif
 33 
 34 static int label;
 35 
 36 Edgel  *edge_alloc(int type)
 37 {
 38     Edgel  *edge = ts_ralloc(Edgel);
 39 
 40     edge->type = type;
 41     edge->label = label++;
 42     edge->pos = vec2_zero();
 43     edge->orient = edge->contrast = (float) 0.0;
 44     edge->props = NULL;
 45     return (edge);
 46 }
 47 
 48 Edge_conn *econn_alloc(void)
 49 {
 50     Edge_conn *econn = ts_ralloc(Edge_conn);
 51 
 52     econn->conns = NULL;
 53     econn->c1 = econn->c2 = NULL;
 54     econn->count = 0;
 55     return (econn);
 56 }
 57 
 58 void    edge_free(Edgel * edge)
 59 {
 60     if (edge == NULL)
 61         return;
 62     proplist_freelist(edge->props);
 63     rfree((void *) edge);
 64 }
 65 
 66 void    econn_free(Edge_conn * econn)
 67 {
 68     list_rm_links(econn->conns);
 69     rfree((void *) econn);
 70 }
 71 
 72 Edgel  *edge_copy(Edgel * edge)
 73 {
 74     Edgel  *copy;
 75     List   *proplist_copy();
 76 
 77     if (edge == NULL)
 78         return (NULL);
 79 
 80     copy = ts_ralloc(Edgel);
 81     (void) memcpy((char *) copy, (char *) edge, sizeof(Edgel));
 82     copy->props = proplist_copy(edge->props);
 83     return (copy);
 84 }
 85 
 86 void   *edge_sindex_prop_get(Edgel * e, int ptype)
 87 
 88 /* type of prop required */
 89 {
 90     Tstring *es;
 91 
 92     if (e == NULL)
 93         return (NULL);
 94 
 95     es = (Tstring *) prop_get(e->props, SINDEX);
 96     return ((es == NULL) ? NULL : prop_get(es->props, ptype));
 97 }
 98 
 99 void   *edge_prop_get(Edgel * e, int ptype)
100 
101 /* type of prop required */
102 {
103     return ((e == NULL) ? NULL : prop_get(e->props, ptype));
104 }
105 
106 /* Get position of edge in image if possible */
107 Vec2    edge_image_pos(Edgel * edge)
108 {
109     Vec2   *pos = NULL;
110 
111     if (edge->type & EDGE_GET_RECT_MASK)        /* rectified in some way */
112         pos = prop_get(edge->props, IMPOS);
113 
114     return ((pos == NULL) ? edge->pos : *pos);
115 }
116 
117 void    edge_set_type_remove_me(Edgel * edge)
118 {
119     edge->type = REMOVE_ME;
120 }
121 
122 /* ARGSUSED quieten lint */
123 void    edge_rm_on_remove_me(Edgel * edge, int type, Imrect * edgerect, int i, int j)
124 {
125     if (edge->type == REMOVE_ME)
126     {
127         edge_free(edge);
128         IM_PTR(edgerect, i, j) = NULL;
129     }
130 }
131 
132 void    edge_save_pos_prop(Edgel * edge, int type, int prop_type)
133 {
134     Vec2   *p;
135 
136     if (type != EDGE || edge == NULL)
137         return;
138 
139     p = vec2_alloc();
140     *p = edge->pos;
141     edge->props = proplist_addifnp(edge->props, (void *) p, prop_type, vec2_free, true);
142 }
143 
144 void    edge_get_pos_prop(Edgel * edge, int type, int prop_type)
145 {
146     Vec2   *p;
147 
148     if (type != EDGE || edge == NULL)
149         return;
150 
151     p = prop_get(edge->props, prop_type);
152     if (p != NULL)
153         edge->pos = *p;
154 }
155 
156 void    edge_print(FILE * fp, Edgel * edge)
157 {
158     (void) fprintf(fp, "Edge type %d label %d ", edge->type, edge->label);
159     vec2_print(fp, edge->pos);
160     (void) fprintf(fp, "or %f con %f\n", edge->orient, edge->contrast);
161 }
162 
163 void    edge_format(Edgel * edge)
164 {
165     format("Edge type %d label %d ", edge->type, edge->label);
166     vec2_format(edge->pos);
167     format("or %f con %f\n", edge->orient, edge->contrast);
168 }
169 

~ [ 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.