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

Linux Cross Reference
Tina4/src/tools/smartROI/sroi_mouse.c

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

  1 /*
  2  * sroi_mouse.c
  3  *
  4  * mouse functions 
  5  *
  6  */
  7 
  8 #include <stdio.h>
  9 #include <string.h>
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/mathfuncs.h>
 14 #include <tina/vision.h>
 15 #include <tina/visionfuncs.h>
 16 #include <tina/tv.h>
 17 #include <tina/tvfuncs.h>
 18 #include <tina/draw.h>
 19 #include <tina/drawfuncs.h>
 20 #include <tina/infrtoolfuncs.h>
 21 #include <tina/toolsfuncs.h>
 22 #include <tina/sroi_tool.h>
 23 
 24 
 25 static List   *poly = NULL;
 26 static int       pcount = 0;
 27 
 28 static Vec2     ll, lr, ul, ur;
 29 static Vec2     cp, op, sp, ep;
 30 static Vec2     u;
 31 static int      buttonstatus = 0;
 32 static int      last_axis = 0;
 33 
 34 
 35 List *sroi_get_markup()
 36 {
 37   return(dd_get_start(poly));
 38 }
 39 
 40 static void  tv_pframe_draw(Tv *tv)
 41 {
 42   if (tv == NULL)
 43     return;
 44 
 45   tv_line2(tv, ll, lr);
 46   tv_line2(tv, lr, ur);
 47   tv_line2(tv, ur, ul);
 48   tv_line2(tv, ul, ll);
 49 }
 50 
 51 
 52 static void  tv_rframe_draw(Tv *tv)
 53 {
 54   if (tv == NULL)
 55     return;
 56 }
 57 
 58 
 59 static void update_startframe(Vec2 a, Vec2 b)
 60 {
 61   if (vec2_x(a) < vec2_x(b))
 62   {   
 63     vec2_x(ll) = vec2_x(a);
 64     vec2_y(ll) = vec2_y(a);
 65     vec2_x(ul) = vec2_x(a);
 66     vec2_y(ul) = vec2_y(a);
 67     vec2_x(lr) = vec2_x(b);
 68     vec2_y(lr) = vec2_y(b);
 69     vec2_x(ur) = vec2_x(b);
 70     vec2_y(ur) = vec2_y(b);
 71   } 
 72   else {
 73     vec2_x(ll) = vec2_x(b);
 74     vec2_y(ll) = vec2_y(b);
 75     vec2_x(ul) = vec2_x(b);
 76     vec2_y(ul) = vec2_y(b);
 77     vec2_x(lr) = vec2_x(a);
 78     vec2_y(lr) = vec2_y(a);
 79     vec2_x(ur) = vec2_x(a);
 80     vec2_y(ur) = vec2_y(a);
 81   }
 82 }
 83 
 84 
 85 static void  paxis_set_start(Tv *tv, Ipos pos)
 86 {
 87   Vec2  Tv_backproj2();
 88 
 89   tv_save_draw(tv);
 90   tv_set_overlay(tv);
 91   
 92   switch (buttonstatus)
 93   {
 94     case 0:
 95       cp = op = tv_backproj2(tv, pos);
 96       tv_bigdot2(tv, op, 2);
 97       break;
 98     case 1:
 99       cp = op = tv_backproj2(tv, pos);
100       u = vec2_unit(vec2_perp(vec2_diff(ep, sp)));
101       break;
102     case 2:
103       cp = op = tv_backproj2(tv, pos);
104       tv_bigdot2(tv, op, 2);
105       buttonstatus = 0;
106       break;
107   }
108 }
109 
110 
111 static void  paxis_frame_drag(Tv *tv, Ipos pos)
112 {
113   Vec2   Tv_backproj2();
114   double len;
115 
116   switch (buttonstatus)
117   {
118     case 0:
119       tv_line2(tv, op, cp);
120       cp = tv_backproj2(tv, pos);
121       tv_line2(tv, op, cp);
122       break;
123     case 1:
124       tv_pframe_draw(tv);
125       cp = tv_backproj2(tv, pos);
126       if (vec2_mod(cp) > vec2_mod(op))
127         len = vec2_dist(op, cp);
128       else
129         len = -vec2_dist(op, cp);
130       ll = vec2_diff(ll, vec2_times(len, u));
131       lr = vec2_diff(lr, vec2_times(len, u));
132       ul = vec2_sum(ul, vec2_times(len, u));
133       ur = vec2_sum(ur, vec2_times(len, u));
134       tv_pframe_draw(tv);
135       op = cp;
136   }
137 }
138 
139 
140 static void  paxis_set_end(Tv *tv, Ipos pos)
141 {
142   Vec2  Tv_backproj2();
143 
144   tv_reset_draw(tv);
145   tv_repaint(tv);
146   tv_set_color(tv, red);
147   
148   switch (buttonstatus)
149   {
150     case 0:
151       cp = tv_backproj2(tv, pos);
152       tv_bigdot2(tv, op, 2);
153       tv_bigdot2(tv, cp, 2);
154       tv_line2(tv, op, cp);
155       update_startframe(op, cp);
156       sp = op;
157       ep = cp;
158       buttonstatus++;
159       break;
160     case 1:
161       paxis_show(tv, pos);
162       buttonstatus++;
163       break;
164   }    
165 
166 }
167 
168 
169 static void  pmove_frame_get(Tv *tv, Ipos pos)
170 {
171   Vec2  Tv_backproj2();
172   
173   op = tv_backproj2(tv, pos);
174   tv_save_draw(tv);
175   tv_set_overlay(tv);
176 
177   switch (buttonstatus)
178   {
179     case 1:
180       if (vec2_dist(op, sp) < vec2_dist(op, ep))
181         sp = op;
182       else
183         ep = op;
184       tv_bigdot2(tv, sp, 2);
185       tv_bigdot2(tv, ep, 2);
186       tv_line2(tv, sp, ep);
187       break;
188 
189     case 2:
190       tv_pframe_draw(tv);
191       break;
192   }
193 }
194 
195 
196 static void  pmove_frame_drag(Tv *tv, Ipos pos)
197 {
198   Vec2  Tv_backproj2();
199   Vec2  diff;
200  
201   cp = tv_backproj2(tv, pos);
202 
203   switch (buttonstatus)
204   {
205     case 1:
206       tv_bigdot2(tv, sp, 2);
207       tv_bigdot2(tv, ep, 2);
208       tv_line2(tv, sp, ep);
209       if (vec2_dist(cp, sp) < vec2_dist(cp, ep))
210         sp = cp;
211       else
212         ep = cp;
213       tv_bigdot2(tv, sp, 2);
214       tv_bigdot2(tv, ep, 2);
215       tv_line2(tv, sp, ep);
216       break;
217     case 2:
218       tv_pframe_draw(tv);
219       diff = vec2_diff(cp, op); 
220       ll = vec2_sum(ll, diff); 
221       lr = vec2_sum(lr, diff); 
222       ul = vec2_sum(ul, diff); 
223       ur = vec2_sum(ur, diff);
224       sp = vec2_sum(sp, diff);
225       ep = vec2_sum(ep, diff); 
226       tv_pframe_draw(tv);
227       break;
228    }
229    op = cp;
230 }
231 
232 
233 static void paxis_show(Tv *tv, Ipos pos)
234 {
235   Sroi_dparams  *params = sroi_get_dparams();
236   Vec2           p1, p2;
237   double         cstep;
238   int            i, cols;
239   
240   tv_repaint(tv);
241   tv_set_color(tv, red);
242   tv_pframe_draw(tv);
243   tv_set_color(tv, blue);
244   tv_bigdot2(tv, sp, 2);
245   tv_bigdot2(tv, ep, 2);
246   tv_set_color(tv, yellow);
247   cols = (params->outer)/2;
248   cstep = vec2_dist(sp, ep)/cols;
249   for (i = 1; i < cols; i++)
250   {
251     p1 = vec2_sum(vec2_times((i*cstep), vec2_unit(vec2_diff(lr, ll))), ll);
252     p2 = vec2_sum(vec2_times((i*cstep), vec2_unit(vec2_diff(ur, ul))), ul);
253     tv_line2(tv, p1, p2);
254   }
255 }
256 
257 static void  pmove_frame_put(Tv *tv, Ipos pos)
258 {
259   Vec2  Tv_backproj2();
260  
261   tv_reset_draw(tv); 
262   tv_repaint(tv);
263   
264   switch (buttonstatus)
265   {
266     case 0:
267       paxis_show(tv, pos);
268       break;
269     case 1:
270       update_startframe(sp, ep);
271       tv_set_color(tv, red);
272       tv_bigdot2(tv, sp, 2);
273       tv_bigdot2(tv, ep, 2);
274       tv_line2(tv, sp, ep);
275       break;
276     case 2:
277       paxis_show(tv, pos);
278       break;
279   }
280 }
281 
282 Tv_mouse  sroi_parall_axis()
283 {
284   last_axis = 0;
285   return(mouse_define(MOUSE_NAME, "parallel",
286                       LEFT_NAME, "frame",
287                       LEFT_DOWN, paxis_set_start,
288                       LEFT_DRAG, paxis_frame_drag,
289                       LEFT_UP,   paxis_set_end,
290                       MIDDLE_NAME, "show",
291                       MIDDLE_DOWN, paxis_show,
292                       RIGHT_NAME, "move",
293                       RIGHT_DOWN, pmove_frame_get,
294                       RIGHT_DRAG, pmove_frame_drag,
295                       RIGHT_UP,   pmove_frame_put,
296                       NULL));
297 }
298 
299 
300 static void raxis_show(Tv *tv, Ipos pos)
301 {
302   Sroi_dparams  *params = sroi_get_dparams();
303   Vec2           centre, p1, p2;
304   double         rad, nrad, theta, theta_p, cstep;
305   int            i, marks;
306   
307   centre = vec2_times(0.5, vec2_sum(sp, ep));
308   rad = vec2_dist(sp, ep); 
309 
310   tv_repaint(tv);
311   tv_set_color(tv, red);
312   tv_circle2(tv, centre, rad); 
313   tv_set_color(tv, yellow);
314   marks = (params->outer + 1);
315   cstep = TWOPI/marks;
316   vec2_to_polar(vec2_diff(sp, centre), &nrad, &theta_p);
317   p1 = vec2_sum(centre, vec2_of_polar(rad, theta_p));
318   p2 = vec2_sum(centre, vec2_of_polar(rad, (theta_p+PI)));
319   tv_line2(tv, p1, p2);
320   for (i = 1; i < marks/2; i++)
321   {
322     vec2_to_polar(vec2_diff(p1, centre), &nrad, &theta);    
323     theta = i*cstep + theta_p;
324     p1 = vec2_sum(centre, vec2_of_polar(rad, theta));
325     vec2_to_polar(vec2_diff(p2, centre), &nrad, &theta);    
326     theta = i*cstep + theta_p + PI;
327     p2 = vec2_sum(centre, vec2_of_polar(rad, theta));
328     tv_line2(tv, p1, p2);
329   }
330 
331   tv_set_color(tv, blue);
332   tv_bigdot2(tv, sp, 2);
333   tv_bigdot2(tv, ep, 2);
334   tv_cross2(tv, centre, 2);
335 }
336 
337 static void  raxis_set_start(Tv *tv, Ipos pos)
338 {
339   Vec2  Tv_backproj2();
340 
341   tv_save_draw(tv);
342   tv_set_overlay(tv);
343   
344   cp = op = tv_backproj2(tv, pos);
345   tv_bigdot2(tv, op, 2);
346 }
347 
348 
349 static void  raxis_frame_drag(Tv *tv, Ipos pos)
350 {
351   Vec2   Tv_backproj2();
352   double len;
353 
354   tv_line2(tv, op, cp);
355   cp = tv_backproj2(tv, pos);
356   tv_line2(tv, op, cp);
357 }
358 
359 
360 static void  raxis_set_end(Tv *tv, Ipos pos)
361 {
362   Vec2  Tv_backproj2();
363 
364   tv_reset_draw(tv);
365   tv_repaint(tv);
366   tv_set_color(tv, red);
367   
368   cp = tv_backproj2(tv, pos);
369   tv_bigdot2(tv, op, 2);
370   tv_bigdot2(tv, cp, 2);
371   tv_line2(tv, op, cp);
372   sp = op;
373   ep = cp;
374   raxis_show(tv, pos);
375 }
376 
377 
378 static void  rmove_frame_get(Tv *tv, Ipos pos)
379 {
380   Vec2  Tv_backproj2();
381   
382   op = tv_backproj2(tv, pos);
383   tv_save_draw(tv);
384   tv_set_overlay(tv);
385 
386   if (vec2_dist(op, sp) < vec2_dist(op, ep))
387     sp = op;
388   else
389     ep = op;
390   tv_bigdot2(tv, sp, 2);
391   tv_bigdot2(tv, ep, 2);
392   tv_line2(tv, sp, ep);
393 }
394 
395 
396 static void  rmove_frame_drag(Tv *tv, Ipos pos)
397 {
398   Vec2  Tv_backproj2();
399   Vec2  diff;
400  
401   cp = tv_backproj2(tv, pos);
402 
403   tv_bigdot2(tv, sp, 2);
404   tv_bigdot2(tv, ep, 2);
405   tv_line2(tv, sp, ep);
406   if (vec2_dist(cp, sp) < vec2_dist(cp, ep))
407     sp = cp;
408   else
409     ep = cp;
410   tv_bigdot2(tv, sp, 2);
411   tv_bigdot2(tv, ep, 2);
412   tv_line2(tv, sp, ep);
413   op = cp;
414 }
415 
416 
417 static void  rmove_frame_put(Tv *tv, Ipos pos)
418 {
419   Vec2  Tv_backproj2();
420  
421   tv_reset_draw(tv); 
422   raxis_show(tv, pos);
423 }
424 
425 
426 Tv_mouse   sroi_radial_axis()
427 {
428   last_axis = 1;
429   return(mouse_define(MOUSE_NAME, "radial",
430                       LEFT_NAME, "frame",
431                       LEFT_DOWN, raxis_set_start,
432                       LEFT_DRAG, raxis_frame_drag,
433                       LEFT_UP,   raxis_set_end,
434                       MIDDLE_NAME, "show",
435                       MIDDLE_DOWN, raxis_show,
436                       RIGHT_NAME, "move",
437                       RIGHT_DOWN, rmove_frame_get,
438                       RIGHT_DRAG, rmove_frame_drag,
439                       RIGHT_UP,   rmove_frame_put,
440                       NULL));
441 }
442 
443 
444 static  void pnt_list_add(Vec2 cp)
445 {
446   Sroi_dparams *params = sroi_get_dparams();
447   
448   if (pcount == 0)
449   {
450     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&sp), VEC2);
451     pcount++;
452   }
453   else if (!(params->outer%2) && (pcount == (params->outer/2+1)))
454   {
455     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&ep), VEC2);
456     pcount++;
457   }
458   else if ((params->outer%2) && (pcount == (params->outer/2)))
459   {
460     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&ep), VEC2);
461     pcount++;
462   }
463     
464   poly = dd_ref_addtoend(poly, (void *)vec2_copy(&cp), VEC2);
465   pcount++;
466 }
467 
468 
469 static  void pnt_list_show(Tv *tv)
470 {
471   Sroi_dparams *params = sroi_get_dparams();
472   Vec2          p;
473   List       *lptr = dd_get_start(poly);
474   int           count;
475 
476   for (count = 0; lptr != NULL; lptr = lptr->next, count++)
477   {
478     tv_set_color(tv, red);
479     p = *(Vec2 *)(lptr->to);
480     
481     if (count == 0)
482       tv_set_color(tv, blue);
483     else if (!(params->outer%2) && (count == (params->outer/2+1)))
484       tv_set_color(tv, blue);
485     else if ((params->outer%2) && (count == (params->outer/2)))
486       tv_set_color(tv, blue);
487       
488     tv_bigdot2(tv, p, 2);
489   }
490 }
491 
492 
493 static  void pnt_place_down(Tv *tv, Ipos pos)
494 {
495   Vec2  Tv_backproj2();
496 
497   tv_save_draw(tv);
498   tv_set_overlay(tv);
499   
500   cp = tv_backproj2(tv, pos);
501   tv_bigdot2(tv, cp, 2);
502 }
503 
504 
505 static  void pnt_place_drag(Tv *tv, Ipos pos)
506 {
507   Vec2  Tv_backproj2();
508   
509   tv_bigdot2(tv, cp, 2);
510   cp = tv_backproj2(tv, pos);
511   tv_bigdot2(tv, cp, 2);
512 }
513 
514 
515 static  void pnt_place_up(Tv *tv, Ipos pos)
516 {
517   tv_reset_draw(tv);
518   tv_repaint(tv);
519   pnt_list_add(cp);
520   if (last_axis == 0)
521     paxis_show(tv, pos);
522   else
523     raxis_show(tv, pos);
524   pnt_list_show(tv);
525 }
526 
527 
528 static  void restart_markup(Tv *tv, Ipos pos)
529 {
530   if (poly != NULL)
531     dd_list_rm(poly, vec2_free);
532   poly = NULL;
533   pcount = 0;
534 }
535 
536 
537 Tv_mouse sroi_markup_mouse()
538 {
539   if (poly != NULL)
540     dd_list_rm(poly, vec2_free);
541   poly = NULL;
542   pcount = 0;
543 
544   return(mouse_define(MOUSE_NAME, "markup",
545                       LEFT_NAME, "place",
546                       LEFT_DOWN,  pnt_place_down,
547                       LEFT_DRAG,  pnt_place_drag,
548                       LEFT_UP,    pnt_place_up,
549                       MIDDLE_NAME, "restart",
550                       MIDDLE_DOWN, restart_markup,
551                       RIGHT_NAME, "redraw",
552                       RIGHT_DOWN, pnt_place_up,
553                       NULL));
554 }
555 

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