1 /**********
2 *
3 *
4 * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
5 * University of Manchester, UK. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without modification,
8 * are permitted provided that the following conditions are met:
9 *
10 * . Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * . Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * . Neither the name of the University of Manchester nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 **********
34 *
35 * Program : TINA
36 * File : $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisEdge_order_mouse.c,v $
37 * Date : $Date: 2007/02/15 01:55:50 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: tlvisEdge_order_mouse.c,v 1.4 2007/02/15 01:55:50 paul Exp $
40 *
41 * Notes :
42 *
43 *
44 *
45 *********
46 */
47
48 #include "tlvisEdge_order_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 #include <tinatool/tlvision/tlvisEdge_stest_tool.h>
67
68
69 static Parcam *pcam;
70 static Vec2 left1 = {Vec2_id};
71 static Vec2 left2 = {Vec2_id};
72 static Vec2 right1 = {Vec2_id};
73 static Vec2 right2 = {Vec2_id};
74 static int raster;
75 static Tv *tvl;
76 static Tv *tvr;
77
78 static void order_match(void)
79 {
80 stest_order_match(raster);
81 }
82
83 static void new_order(Vec2 p)
84 {
85 Vec2 q = {Vec2_id};
86 Vec2 v = {Vec2_id};
87 Imrect *im;
88 float width;
89
90 q = p;
91 raster = vec2_y(p); /* the rectified y coordinate */
92 v = vec2(1.0, 0.0); /* along the x axis of pcam */
93 im = left_image();
94 width = (im == NULL) ? tvl->width : im->width;
95 rectify_pos_and_dir(pcam->derect1, &q, &v);
96 left1 = vec2_sum(q, vec2_times((0 - vec2_x(q)) / vec2_x(v), v));
97 left2 = vec2_sum(q, vec2_times((width - vec2_x(q)) / vec2_x(v), v));
98 q = p;
99 im = right_image();
100 v = vec2(1.0, 0.0); /* along the x axis of pcam */
101 width = (im == NULL) ? tvr->width : im->width;
102 rectify_pos_and_dir(pcam->derect2, &q, &v);
103 right1 = vec2_sum(q, vec2_times((0 - vec2_x(q)) / vec2_x(v), v));
104 right2 = vec2_sum(q, vec2_times((width - vec2_x(q)) / vec2_x(v), v));
105 }
106
107 static void order_left_down(Tv * tv, Ipos pos)
108 {
109 pcam = pcam_get();
110 tvl = tv;
111 tvr = right_tv();
112
113 if (pcam == NULL)
114 return;
115
116 new_order(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
117 tv_set_overlay(tvl); /* also calls tv_save_draw */
118 tv_set_overlay(tvr); /* also calls tv_save_draw */
119 tv_line2(tvl, left1, left2);
120 tv_line2(tvr, right1, right2);
121 }
122
123 static void order_left_drag(Tv * tv, Ipos pos)
124 {
125 if (pcam == NULL)
126 return;
127
128 tv_line2(tvl, left1, left2);
129 tv_line2(tvr, right1, right2);
130 new_order(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
131 tv_line2(tvl, left1, left2);
132 tv_line2(tvr, right1, right2);
133 }
134
135 static void order_left_up(Tv * tv, Ipos pos)
136 {
137 if (pcam == NULL)
138 return;
139
140 tv_line2(tvl, left1, left2);
141 tv_line2(tvr, right1, right2);
142 new_order(rectify_pos(pcam->rect1, tv_backproj2(tv, pos)));
143 tv_reset_draw(tvl);
144 tv_reset_draw(tvr);
145 tv_set_color(tvl, cyan);
146 tv_set_color(tvr, cyan);
147 tv_line2(tvl, left1, left2);
148 tv_line2(tvr, right1, right2);
149 }
150
151 static void order_right_down(Tv * tv, Ipos pos)
152 {
153 pcam = pcam_get();
154 tvl = left_tv();
155 tvr = tv;
156
157 if (pcam == NULL)
158 return;
159
160 new_order(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
161 tv_set_overlay(tvl); /* also calls tv_save_draw */
162 tv_set_overlay(tvr); /* also calls tv_save_draw */
163 tv_line2(tvl, left1, left2);
164 tv_line2(tvr, right1, right2);
165 }
166
167 static void order_right_drag(Tv * tv, Ipos pos)
168 {
169 if (pcam == NULL)
170 return;
171
172 tv_line2(tvl, left1, left2);
173 tv_line2(tvr, right1, right2);
174 new_order(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
175 tv_line2(tvl, left1, left2);
176 tv_line2(tvr, right1, right2);
177 }
178
179 static void order_right_up(Tv * tv, Ipos pos)
180 {
181 if (pcam == NULL)
182 return;
183
184 tv_line2(tvl, left1, left2);
185 tv_line2(tvr, right1, right2);
186 new_order(rectify_pos(pcam->rect2, tv_backproj2(tv, pos)));
187 tv_reset_draw(tvl);
188 tv_reset_draw(tvr);
189 tv_set_color(tvl, cyan);
190 tv_set_color(tvr, cyan);
191 tv_line2(tvl, left1, left2);
192 tv_line2(tvr, right1, right2);
193 }
194
195 Tv_mouse left_order_mouse(void)
196 {
197 return (mouse_define(LEFT_DOWN, order_left_down,
198 LEFT_DRAG, order_left_drag,
199 LEFT_UP, order_left_up,
200 MIDDLE_UP, order_match, NULL));
201 }
202
203 Tv_mouse right_order_mouse(void)
204 {
205 return (mouse_define(LEFT_DOWN, order_right_down,
206 LEFT_DRAG, order_right_drag,
207 LEFT_UP, order_right_up,
208 MIDDLE_UP, order_match, NULL));
209 }
210
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.