1 /**@(#)
2 **/
3 #include <math.h>
4 #include <tina/sys.h>
5 #include <tina/sysfuncs.h>
6 #include <tina/math.h>
7 #include <tina/mathfuncs.h>
8 #include <tina/vision.h>
9 #include <tina/visionfuncs.h>
10
11 #define DISP_THRES 1.0
12 #define DISP_GRAD 1.0
13 #define RASTER_THRES 1.0
14 #define HORIZ_THRES 0.995
15
16 static Tstring *form_disp_str(Line2 * line2)
17 {
18 Tstring *es;
19 List *dispstr = NULL;
20 List *mlist;
21 List *mptr;
22 Vec2 v = {Vec2_id};
23 Vec2 p = {Vec2_id};
24
25 if (line2 == NULL)
26 return (NULL);
27
28 v = line2->v;
29 p = line2->p1;
30 es = (Tstring *) prop_get(line2->props, STRING);
31 if (es == NULL)
32 return (NULL);
33
34 mlist = es_get_list_of_matches(es);
35 for (mptr = mlist; mptr != NULL; mptr = mptr->next)
36 {
37 List *dptr;
38 List *end;
39
40 es = (Tstring *) ((Match *) mptr->to)->to2;
41 end = es->end;
42 for (dptr = es->start;; dptr = dptr->next)
43 {
44 Vec2 pm = {Vec2_id};
45 Vec2 *pdisp = ts_ralloc(Vec2);
46 float x, y, d;
47
48 pm = DD_EDGE_POS(dptr);
49 y = vec2_y(pm) - vec2_y(p);
50 x = vec2_x(v) * y / vec2_y(v);
51 d = vec2_x(pm) - vec2_x(p) - x;
52 *pdisp = vec2(sqrt(x * x + y * y), d);
53 dispstr = dd_ref_addtostart(dispstr, (void *) pdisp, VEC2);
54 if (dptr == end)
55 break;
56 }
57 }
58
59 dispstr = sort_ddlist(dispstr, vec2_get_x, NULL);
60 return (str_make(STRING, dispstr, dd_get_end(dispstr)));
61 }
62
63 Line3 *line3_disp_from2d(Line2 * line2)
64 {
65 Tstring *dispstr;
66 Line2 *lined;
67 Vec3 p1 = {Vec3_id};
68 Vec3 p2 = {Vec3_id};
69 Vec2 p = {Vec2_id};
70
71 if (line2 == NULL)
72 return (NULL);
73
74 /* test for horizontal 2D line */
75 if (fabs(vec2_x(line2->v)) > HORIZ_THRES ||
76 fabs(vec2_y(line2->p1) - vec2_y(line2->p2)) < RASTER_THRES)
77 return (NULL);
78
79 dispstr = form_disp_str(line2);
80 if (dispstr == NULL || dispstr->count < 5)
81 {
82 str_rm(dispstr, rfree);
83 return (NULL);
84 }
85 lined = line2_best_fit(dispstr->start, dispstr->end, DISP_THRES);
86 if (lined == NULL || fabs(vec2_y(lined->v) / vec2_x(lined->v)) > DISP_GRAD)
87 {
88 line2_free(lined);
89 return (NULL);
90 }
91 p1 = p2 = vec3_of_vec2(line2->p1);
92 p = vec2_times(vec2_x(lined->p1), line2->v); /* 2d offset of p1 */
93 p1 = vec3_sum(p1, vec3_of_vec2(p));
94 vec3_z(p1) = vec2_y(lined->p1); /* add disparity */
95 p = vec2_times(vec2_x(lined->p2), line2->v); /* 2d offset of p2 */
96 p2 = vec3_sum(p2, vec3_of_vec2(p));
97 vec3_z(p2) = vec2_y(lined->p2); /* add disparity */
98 line2_free(lined);
99 return (line3_make(p1, p2, DISPARITY)); /* has no string
100 * property */
101 }
102
103 Line3 *line3_from_line2(Line2 * line2)
104 {
105 Line3 *line3;
106
107 if (line2 == NULL)
108 return (NULL);
109
110 line3 = line3_disp_from2d(line2);
111 line3_par_proj_3d(line3);
112
113 if (line3 == NULL)
114 return (NULL);
115
116 line3->props = proplist_add(line3->props, (void *) line2, LINE2,
117 (void (*) ()) NULL);
118 line2->props = proplist_add(line2->props, (void *) line3, LINE3,
119 (void (*) ()) NULL);
120
121 return (line3);
122 }
123
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.