1 /**********
2 *
3 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
4 * University of Manchester, UK. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 *
9 * . Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * . Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * . Neither the name of the University of Manchester nor the names of its
17 * contributors may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisEdge_epi_mouse.c,v $
37 * Date : $Date: 2003/10/01 16:02:47 $
38 * Version : $Revision: 1.3 $
39 * CVS Id : $Id: tlvisEdge_epi_mouse.c,v 1.3 2003/10/01 16:02:47 tony Exp $
40 *
41 * Notes :
42 *
43 *
44 *
45 *********
46 */
47
48 #include "tlvisEdge_epi_mouse.h"
49
50 #if HAVE_CONFIG_H
51 #include <config.h>
52 #endif
53
54 #include <tina/sys/sysDef.h>
55 #include <tina/sys/sysPro.h>
56 #include <tina/math/mathDef.h>
57 #include <tina/math/mathPro.h>
58 #include <tina/geometry/geomDef.h>
59 #include <tina/geometry/geomPro.h>
60 #include <tina/vision/visDef.h>
61 #include <tina/vision/visPro.h>
62
63 #include <tinatool/draw/drawDef.h>
64 #include <tinatool/draw/drawPro.h>
65 #include <tinatool/tlbase/tlbasePro.h>
66
67
68 static Parcam *pcam;
69 static Vec2 left1 = {Vec2_id};
70 static Vec2 left2 = {Vec2_id};
71 static Vec2 right1 = {Vec2_id};
72 static Vec2 right2 = {Vec2_id};
73 static Tv *tvl;
74 static Tv *tvr;
75
76 void new_epipolars(Vec2 p)
77 {
78 Vec2 q = {Vec2_id};
79 Vec2 v = {Vec2_id};
80 Imrect *im;
81 float width;
82
83 pcam = pcam_get();
84 q = p;
85 v = vec2(1.0, 0.0); /* along the x axis of pcam */
86 im = left_image();
87 width = (im == NULL) ? tvl->width : im->width;
88 rectify_pos_and_dir(pcam->derect1, &q, &v);
89 left1 = vec2_sum(q, vec2_times((0 - vec2_x(q)) / vec2_x(v), v));
90 left2 = vec2_sum(q, vec2_times((width - vec2_x(q)) / vec2_x(v), v));
91 q = p;
92 im = right_image();
93 v = vec2(1.0, 0.0); /* along the x axis of pcam */
94 width = (im == NULL) ? tvr->width : im->width;
95 rectify_pos_and_dir(pcam->derect2, &q, &v);
96 right1 = vec2_sum(q, vec2_times((0 - vec2_x(q)) / vec2_x(v), v));
97 right2 = vec2_sum(q, vec2_times((width - vec2_x(q)) / vec2_x(v), v));
98 }
99
100 static void new_rasters(Vec2 p)
101 {
102 Ipos pos = {Ipos_id};
103
104 pos = tv_proj2(tvl, p);
105 ipos_x(pos) = 0;
106 left1 = tv_backproj2(tvl, pos);
107 ipos_x(pos) = tvl->width;
108 left2 = tv_backproj2(tvl, pos);
109 pos = tv_proj2(tvr, p);
110 ipos_x(pos) = 0;
111 right1 = tv_backproj2(tvr, pos);
112 ipos_x(pos) = tvr->width;
113 right2 = tv_backproj2(tvr, pos);
114 }
115
116 static void epi_left_down(Tv * tv, Ipos pos)
117 {
118 pcam = pcam_get();
119 tvl = tv;
120 tvr = right_tv();
121
122 if (pcam == NULL)
123 return;
124
125 new_epipolars(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
126 tv_set_overlay(tvl); /* also calls tv_save_draw */
127 tv_set_overlay(tvr); /* also calls tv_save_draw */
128 tv_line2(tvl, left1, left2);
129 tv_line2(tvr, right1, right2);
130 }
131
132 static void epi_left_drag(Tv * tv, Ipos pos)
133 {
134 if (pcam == NULL)
135 return;
136
137 tv_line2(tvl, left1, left2);
138 tv_line2(tvr, right1, right2);
139 new_epipolars(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
140 tv_line2(tvl, left1, left2);
141 tv_line2(tvr, right1, right2);
142 }
143
144 static void epi_left_up(Tv * tv, Ipos pos)
145 {
146 if (pcam == NULL)
147 return;
148
149 tv_line2(tvl, left1, left2);
150 tv_line2(tvr, right1, right2);
151 new_epipolars(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
152 tv_reset_draw(tvl);
153 tv_reset_draw(tvr);
154 tv_set_color(tvl, cyan);
155 tv_set_color(tvr, cyan);
156 tv_line2(tvl, left1, left2);
157 tv_line2(tvr, right1, right2);
158 }
159
160 static void epi_right_down(Tv * tv, Ipos pos)
161 {
162 pcam = pcam_get();
163 tvl = left_tv();
164 tvr = tv;
165
166 if (pcam == NULL)
167 return;
168
169 new_epipolars(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
170 tv_set_overlay(tvl); /* also calls tv_save_draw */
171 tv_set_overlay(tvr); /* also calls tv_save_draw */
172 tv_line2(tvl, left1, left2);
173 tv_line2(tvr, right1, right2);
174 }
175
176 static void epi_right_drag(Tv * tv, Ipos pos)
177 {
178 if (pcam == NULL)
179 return;
180
181 tv_line2(tvl, left1, left2);
182 tv_line2(tvr, right1, right2);
183 new_epipolars(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
184 tv_line2(tvl, left1, left2);
185 tv_line2(tvr, right1, right2);
186 }
187
188 static void epi_right_up(Tv * tv, Ipos pos)
189 {
190 if (pcam == NULL)
191 return;
192
193 tv_line2(tvl, left1, left2);
194 tv_line2(tvr, right1, right2);
195 new_epipolars(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
196 tv_reset_draw(tvl);
197 tv_reset_draw(tvr);
198 tv_set_color(tvl, cyan);
199 tv_set_color(tvr, cyan);
200 tv_line2(tvl, left1, left2);
201 tv_line2(tvr, right1, right2);
202 }
203
204 Tv_mouse left_epi_mouse(void)
205 {
206 return (mouse_define(LEFT_DOWN, epi_left_down,
207 LEFT_DRAG, epi_left_drag,
208 LEFT_UP, epi_left_up, NULL));
209 }
210
211 Tv_mouse right_epi_mouse(void)
212 {
213 return (mouse_define(LEFT_DOWN, epi_right_down,
214 LEFT_DRAG, epi_right_drag,
215 LEFT_UP, epi_right_up, NULL));
216 }
217
218 static void raster_left_down(Tv * tv, Ipos pos)
219 {
220 pcam = pcam_get();
221 tvl = tv;
222 tvr = right_tv();
223
224 if (pcam == NULL)
225 return;
226
227 new_rasters(tv_backproj2(tv, pos));
228 tv_set_overlay(tvl); /* also calls tv_save_draw */
229 tv_set_overlay(tvr); /* also calls tv_save_draw */
230 tv_line2(tvl, left1, left2);
231 tv_line2(tvr, right1, right2);
232 }
233
234 static void raster_left_drag(Tv * tv, Ipos pos)
235 {
236 if (pcam == NULL)
237 return;
238
239 tv_line2(tvl, left1, left2);
240 tv_line2(tvr, right1, right2);
241 new_rasters(tv_backproj2(tv, pos));
242 tv_line2(tvl, left1, left2);
243 tv_line2(tvr, right1, right2);
244 }
245
246 static void raster_left_up(Tv * tv, Ipos pos)
247 {
248 if (pcam == NULL)
249 return;
250
251 tv_line2(tvl, left1, left2);
252 tv_line2(tvr, right1, right2);
253 new_rasters(tv_backproj2(tv, pos));
254 tv_reset_draw(tvl);
255 tv_reset_draw(tvr);
256 tv_set_color(tvl, cyan);
257 tv_set_color(tvr, cyan);
258 tv_line2(tvl, left1, left2);
259 tv_line2(tvr, right1, right2);
260 }
261
262 static void raster_right_down(Tv * tv, Ipos pos)
263 {
264 pcam = pcam_get();
265 tvl = left_tv();
266 tvr = tv;
267
268 if (pcam == NULL)
269 return;
270
271 new_rasters(tv_backproj2(tv, pos));
272 tv_set_overlay(tvl); /* also calls tv_save_draw */
273 tv_set_overlay(tvr); /* also calls tv_save_draw */
274 tv_line2(tvl, left1, left2);
275 tv_line2(tvr, right1, right2);
276 }
277
278 static void raster_right_drag(Tv * tv, Ipos pos)
279 {
280 if (pcam == NULL)
281 return;
282
283 tv_line2(tvl, left1, left2);
284 tv_line2(tvr, right1, right2);
285 new_rasters(tv_backproj2(tv, pos));
286 tv_line2(tvl, left1, left2);
287 tv_line2(tvr, right1, right2);
288 }
289
290 static void raster_right_up(Tv * tv, Ipos pos)
291 {
292 if (pcam == NULL)
293 return;
294
295 tv_line2(tvl, left1, left2);
296 tv_line2(tvr, right1, right2);
297 new_rasters(tv_backproj2(tv, pos));
298 tv_reset_draw(tvl);
299 tv_reset_draw(tvr);
300 tv_set_color(tvl, cyan);
301 tv_set_color(tvr, cyan);
302 tv_line2(tvl, left1, left2);
303 tv_line2(tvr, right1, right2);
304 }
305
306 Tv_mouse left_raster_mouse(void)
307 {
308 return (mouse_define(LEFT_DOWN, raster_left_down,
309 LEFT_DRAG, raster_left_drag,
310 LEFT_UP, raster_left_up, NULL));
311 }
312
313 Tv_mouse right_raster_mouse(void)
314 {
315 return (mouse_define(LEFT_DOWN, raster_right_down,
316 LEFT_DRAG, raster_right_drag,
317 LEFT_UP, raster_right_up, NULL));
318 }
319
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.