revert prefetching: it didn't work
[sparrow.git] / edges.h
blob0542510ae736a2b4f06c3cdbb630f6f85283130d
1 #ifndef __SPARROW_EDGES_H__
2 #define __SPARROW_EDGES_H__
4 #define SAFETY_LAG 3;
5 #define SIG_WEIGHT 2
7 /* for discarding outliers */
8 #define OUTLIER_RADIUS 7
9 #define OUTLIER_THRESHOLD (OUTLIER_RADIUS * OUTLIER_RADIUS)
11 #define BAD_PIXEL 0xffff
13 #define FL_DUMPFILE "/tmp/edges.dump"
15 #define COLOUR_QUANT 1
16 #define COLOUR_MASK (0xff >> COLOUR_QUANT)
18 /*if squared error between observed error and predicted error exceeds this,
19 ignore the observation */
20 #define CORNER_EXACT_THRESHOLD 16
22 /*a corner based on fewer than this number of projects cannot be considered
23 settled */
24 #define MIN_CORNER_ESTIMATES 5
26 /* nice big word. acos(1.0 - MAX_NONCOLLINEARITY) = angle of deviation. This
27 is used when lining up known points to estimte the position of lost ones.
28 0.005: 5.7 degrees, 0.01: 8.1, 0.02: 11.5, 0.04: 16.3, 0.08: 23.1
29 1 pixel deviation in 32 -> ~ 1/33 == 0.03 (if I understand correctly)
31 #define MAX_NONCOLLINEARITY 0.02
33 typedef enum corner_status {
34 CORNER_UNUSED,
35 CORNER_PROJECTED,
36 CORNER_EXACT,
37 CORNER_SETTLED,
38 } corner_status_t;
40 typedef enum edges_state {
41 EDGES_FIND_NOISE,
42 EDGES_FIND_LINES,
43 EDGES_FIND_CORNERS,
44 EDGES_WAIT_FOR_PLAY,
46 EDGES_NEXT_STATE,
47 } edges_state_t;
49 #define USE_FLOAT_COORDS 1
51 #if USE_FLOAT_COORDS
52 typedef float coord_t;
53 typedef float coord_sum_t;
54 #define QUANTISE_DELTA(d)((d) / LINE_PERIOD)
56 #else
57 /* the mesh is stored in a fixed point notation.*/
58 #define SPARROW_FIXED_POINT 9
60 typedef int coord_t;
61 typedef gint64 coord_sum_t;
62 #define QUANTISE_DELTA(d)(((d) + LINE_PERIOD / 2) / LINE_PERIOD)
64 #endif
66 typedef struct sparrow_estimator_s {
67 int x1;
68 int y1;
69 int x2;
70 int y2;
71 int x3;
72 int y3;
73 //int mul; /* estimate: x1,y1 + mul * diff */
74 } sparrow_estimator_t;
76 typedef struct sparrow_corner_s {
77 coord_t x;
78 coord_t y;
79 /*dyr -> dy to next point right
80 dxd ->dx to next point down */
81 coord_t dxr;
82 coord_t dyr;
83 coord_t dxd;
84 coord_t dyd;
85 corner_status_t status;
86 } sparrow_corner_t;
88 typedef struct sparrow_voter_s {
89 coord_t x;
90 coord_t y;
91 guint32 signal;
92 } sparrow_voter_t;
94 typedef struct sparrow_point_s {
95 coord_t x;
96 coord_t y;
97 } sparrow_point_t;
99 typedef struct sparrow_cluster_s {
100 int n;
101 sparrow_voter_t voters[8];
102 } sparrow_cluster_t;
105 typedef union sparrow_signal_s {
106 guint16 v_signal;
107 guint16 h_signal;
108 } sparrow_signal_t;
111 typedef struct sparrow_intersect_s {
112 guint16 lines[2];
113 guint16 signal[2];
114 } sparrow_intersect_t;
116 typedef struct sparrow_line_s {
117 gint offset;
118 sparrow_axis_t dir;
119 gint index;
120 } sparrow_line_t;
122 /*condensed version of <struct sparrow_find_lines_s> for saving: contains no
123 pointers or other unnecessary things that might vary in size across
124 architectures. */
125 typedef struct sparrow_fl_condensed {
126 gint32 n_vlines;
127 gint32 n_hlines;
128 } sparrow_fl_condensed_t;
130 typedef struct sparrow_find_lines_s {
131 sparrow_line_t *h_lines;
132 sparrow_line_t *v_lines;
133 sparrow_line_t **shuffled_lines;
134 int current;
135 int n_lines;
136 int n_vlines;
137 int n_hlines;
138 gint shift1;
139 gint shift2;
140 sparrow_intersect_t *map;
141 sparrow_corner_t *mesh_mem;
142 sparrow_corner_t *mesh;
143 sparrow_corner_t *mesh_next;
144 sparrow_cluster_t *clusters;
145 double *dither;
146 IplImage *debug;
147 IplImage *threshold;
148 IplImage *working;
149 IplImage *input;
150 edges_state_t state;
151 } sparrow_find_lines_t;
154 #define DEBUG_FIND_LINES(fl)GST_DEBUG( \
155 "fl:\n" \
156 " sparrow_line_t *h_lines: %p\n" \
157 " sparrow_line_t *v_lines: %p\n" \
158 " sparrow_line_t **shuffled_lines: %p\n" \
159 " int current: %d\n" \
160 " int n_lines: %d\n" \
161 " int n_vlines: %d\n" \
162 " int n_hlines: %d\n" \
163 " gint shift1: %d\n" \
164 " gint shift2: %d\n" \
165 " sparrow_intersect_t *map: %p\n" \
166 " sparrow_corner_t *mesh: %p\n" \
167 " sparrow_cluster_t *clusters: %p\n" \
168 " double *dither: %p \n" \
169 " IplImage *debug: %p\n" \
170 " IplImage *threshold: %p\n" \
171 " IplImage *working: %p\n" \
172 " IplImage *input: %p\n" \
173 " edges_state_t state: %d\n" \
175 (fl)->h_lines, \
176 (fl)->v_lines, \
177 (fl)->shuffled_lines, \
178 (fl)->current, \
179 (fl)->n_lines, \
180 (fl)->n_vlines, \
181 (fl)->n_hlines, \
182 (fl)->shift1, \
183 (fl)->shift2, \
184 (fl)->map, \
185 (fl)->mesh, \
186 (fl)->clusters, \
187 (fl)->dither, \
188 (fl)->debug, \
189 (fl)->threshold, \
190 (fl)->working, \
191 (fl)->input, \
192 (fl)->state \
194 //#undef debug_find_lines
195 //#define debug_find_lines(x) /* */
198 #endif /*have this .h*/