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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlmedical/tlmedSroi_mouse.c

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

  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    :  
 37  * Date    :  
 38  * Version : 
 39  * CVS Id  : 
 40  *
 41  *********
 42 */
 43 
 44 #include "tlmedSroi_mouse.h"
 45 
 46 #if HAVE_CONFIG_H
 47 #   include <config.h>
 48 #endif
 49 
 50 
 51 #include <stdio.h>
 52 /*
 53 #include <string.h>
 54 */
 55 
 56 #include <tina/sys/sysDef.h>
 57 #include <tina/sys/sysPro.h>
 58 #include <tina/math/mathDef.h>
 59 #include <tina/math/mathPro.h>
 60 #include <tinatool/draw/drawDef.h>
 61 #include <tinatool/draw/drawPro.h>
 62 #include <tina/image/imgDef.h>
 63 #include <tina/image/imgPro.h>
 64 #include <tina/geometry/geomDef.h>
 65 #include <tina/geometry/geomPro.h>
 66 #include <tina/medical/med_SroiDef.h>
 67 #include <tinatool/draw/drawDef.h>
 68 #include <tinatool/draw/drawPro.h>
 69 #include <tinatool/wdgts/wdgtsDef.h>
 70 #include <tinatool/wdgts/wdgtsPro.h>
 71 #include <tinatool/tlbase/tlbase_InfrDef.h>
 72 #include <tinatool/tlbase/tlbase_InfrPro.h>
 73 #include <tinatool/tlmedical/tlmedSroi_tool.h>
 74 
 75 
 76 static List   *poly = NULL;
 77 static int       pcount = 1;
 78 
 79 static Vec2     ll, lr, ul, ur;
 80 static Vec2     cp, op, sp, ep;
 81 static Vec2     u;
 82 static int      buttonstatus = 0;
 83 static int      last_axis = 0;
 84 
 85 
 86 List *sroi_get_markup()
 87 {
 88   return(dd_get_start(poly));
 89 }
 90 
 91 static void  tv_pframe_draw(Tv *tv)
 92 {
 93   if (tv == NULL)
 94     return;
 95 
 96   tv_line2(tv, ll, lr);
 97   tv_line2(tv, lr, ur);
 98   tv_line2(tv, ur, ul);
 99   tv_line2(tv, ul, ll);
100 }
101 
102 static void update_startframe(Vec2 a, Vec2 b)
103 {
104   if (vec2_x(a) < vec2_x(b))
105   {   
106     vec2_x(ll) = vec2_x(a);
107     vec2_y(ll) = vec2_y(a);
108     vec2_x(ul) = vec2_x(a);
109     vec2_y(ul) = vec2_y(a);
110     vec2_x(lr) = vec2_x(b);
111     vec2_y(lr) = vec2_y(b);
112     vec2_x(ur) = vec2_x(b);
113     vec2_y(ur) = vec2_y(b);
114   } 
115   else {
116     vec2_x(ll) = vec2_x(b);
117     vec2_y(ll) = vec2_y(b);
118     vec2_x(ul) = vec2_x(b);
119     vec2_y(ul) = vec2_y(b);
120     vec2_x(lr) = vec2_x(a);
121     vec2_y(lr) = vec2_y(a);
122     vec2_x(ur) = vec2_x(a);
123     vec2_y(ur) = vec2_y(a);
124   }
125 }
126 
127 
128 static void  paxis_set_start(Tv *tv, Ipos pos)
129 {
130   Vec2  Tv_backproj2();
131 
132   tv_save_draw(tv);
133   tv_set_overlay(tv);
134   
135   switch (buttonstatus)
136   {
137     case 0:
138       cp = op = tv_backproj2(tv, pos);
139       tv_bigdot2(tv, op, 2);
140       break;
141     case 1:
142       cp = op = tv_backproj2(tv, pos);
143       u = vec2_unit(vec2_perp(vec2_diff(ep, sp)));
144       break;
145     case 2:
146       cp = op = tv_backproj2(tv, pos);
147       tv_bigdot2(tv, op, 2);
148       buttonstatus = 0;
149       break;
150   }
151 }
152 
153 
154 static void  paxis_frame_drag(Tv *tv, Ipos pos)
155 {
156   Vec2   Tv_backproj2();
157   double len;
158 
159   switch (buttonstatus)
160   {
161     case 0:
162       tv_line2(tv, op, cp);
163       cp = tv_backproj2(tv, pos);
164       tv_line2(tv, op, cp);
165       break;
166     case 1:
167       tv_pframe_draw(tv);
168       cp = tv_backproj2(tv, pos);
169       if (vec2_mod(cp) > vec2_mod(op))
170         len = vec2_dist(op, cp);
171       else
172         len = -vec2_dist(op, cp);
173       ll = vec2_diff(ll, vec2_times(len, u));
174       lr = vec2_diff(lr, vec2_times(len, u));
175       ul = vec2_sum(ul, vec2_times(len, u));
176       ur = vec2_sum(ur, vec2_times(len, u));
177       tv_pframe_draw(tv);
178       op = cp;
179   }
180 }
181 
182 static void paxis_draw(Tv *tv, int colour, int num)
183 {
184   Sroi_dparams  *params = sroi_get_dparams();
185   Vec2           p1, p2;
186   double         cstep;
187   int            cols;
188 
189   tv_set_color(tv, colour);
190 
191   cols = (params->outer)/2;
192   cstep = vec2_dist(sp, ep)/cols;
193   if (num>params->outer-1)
194   {
195       num -= (params->outer-1);
196       if (num >= (params->outer)/2)
197         num = params->outer - num -1;
198   }
199   else if (num>(params->outer)/2)
200       num = params->outer - num;
201 
202   p1 = vec2_sum(vec2_times((num*cstep), vec2_unit(vec2_diff(lr, ll))), ll);
203   p2 = vec2_sum(vec2_times((num*cstep), vec2_unit(vec2_diff(ur, ul))), ul);
204   tv_line2(tv, p1, p2);
205 
206 }
207 
208 static void paxis_show(Tv *tv, Ipos pos)
209 {
210   Sroi_dparams  *params = sroi_get_dparams();
211   int            i, cols;
212   
213   tv_repaint(tv);
214   tv_set_color(tv, red);
215   tv_pframe_draw(tv);
216   tv_set_color(tv, green);
217   tv_bigdot2(tv, sp, 2);
218   tv_bigdot2(tv, ep, 2);
219   cols = (params->outer)/2;
220   for (i = 1; i < cols; i++)
221   {
222       paxis_draw(tv, yellow, i);
223   }
224 }
225 
226 static void  paxis_set_end(Tv *tv, Ipos pos)
227 {
228   Vec2  Tv_backproj2();
229 
230   tv_reset_draw(tv);
231   tv_repaint(tv);
232   tv_set_color(tv, red);
233   
234   switch (buttonstatus)
235   {
236     case 0:
237       cp = tv_backproj2(tv, pos);
238       tv_bigdot2(tv, op, 2);
239       tv_bigdot2(tv, cp, 2);
240       tv_line2(tv, op, cp);
241       update_startframe(op, cp);
242       sp = op;
243       ep = cp;
244       buttonstatus++;
245       break;
246     case 1:
247       paxis_show(tv, pos);
248       paxis_draw(tv, blue, 1);
249       buttonstatus++;
250       tv_set_mouse(tv,  sroi_markup_mouse());
251       (void) tv_set_activity(tv, MOUSE);
252       break;
253   }
254 }
255 
256 
257 static void  pmove_frame_get(Tv *tv, Ipos pos)
258 {
259   Vec2  Tv_backproj2();
260   
261   op = tv_backproj2(tv, pos);
262   tv_save_draw(tv);
263   tv_set_overlay(tv);
264 
265   switch (buttonstatus)
266   {
267     case 1:
268       if (vec2_dist(op, sp) < vec2_dist(op, ep))
269         sp = op;
270       else
271         ep = op;
272       tv_bigdot2(tv, sp, 2);
273       tv_bigdot2(tv, ep, 2);
274       tv_line2(tv, sp, ep);
275       break;
276 
277     case 2:
278       tv_pframe_draw(tv);
279       break;
280   }
281 }
282 
283 
284 static void  pmove_frame_drag(Tv *tv, Ipos pos)
285 {
286   Vec2  Tv_backproj2();
287   Vec2  diff;
288  
289   cp = tv_backproj2(tv, pos);
290 
291   switch (buttonstatus)
292   {
293     case 1:
294       tv_bigdot2(tv, sp, 2);
295       tv_bigdot2(tv, ep, 2);
296       tv_line2(tv, sp, ep);
297       if (vec2_dist(cp, sp) < vec2_dist(cp, ep))
298         sp = cp;
299       else
300         ep = cp;
301       tv_bigdot2(tv, sp, 2);
302       tv_bigdot2(tv, ep, 2);
303       tv_line2(tv, sp, ep);
304       break;
305     case 2:
306       tv_pframe_draw(tv);
307       diff = vec2_diff(cp, op); 
308       ll = vec2_sum(ll, diff); 
309       lr = vec2_sum(lr, diff); 
310       ul = vec2_sum(ul, diff); 
311       ur = vec2_sum(ur, diff);
312       sp = vec2_sum(sp, diff);
313       ep = vec2_sum(ep, diff); 
314       tv_pframe_draw(tv);
315       break;
316    }
317    op = cp;
318 }
319 
320 static void  pmove_frame_put(Tv *tv, Ipos pos)
321 {
322   Vec2  Tv_backproj2();
323  
324   tv_reset_draw(tv); 
325   tv_repaint(tv);
326   
327   switch (buttonstatus)
328   {
329     case 0:
330       paxis_show(tv, pos);
331       break;
332     case 1:
333       update_startframe(sp, ep);
334       tv_set_color(tv, red);
335       tv_bigdot2(tv, sp, 2);
336       tv_bigdot2(tv, ep, 2);
337       tv_line2(tv, sp, ep);
338       break;
339     case 2:
340       paxis_show(tv, pos);
341       break;
342   }
343 }
344 
345 Tv_mouse  sroi_parall_axis()
346 {
347   last_axis = 0;
348   return(mouse_define(MOUSE_NAME, "parallel",
349                       LEFT_NAME, "frame",
350                       LEFT_DOWN, paxis_set_start,
351                       LEFT_DRAG, paxis_frame_drag,
352                       LEFT_UP,   paxis_set_end,
353                       MIDDLE_NAME, "show",
354                       MIDDLE_DOWN, paxis_show,
355                       RIGHT_NAME, "move",
356                       RIGHT_DOWN, pmove_frame_get,
357                       RIGHT_DRAG, pmove_frame_drag,
358                       RIGHT_UP,   pmove_frame_put,
359                       NULL));
360 }
361 
362 static void raxis_draw(Tv *tv, int colour, int num)
363 {
364   Sroi_dparams  *params = sroi_get_dparams();
365   Vec2           centre, p1;
366   double         rad, nrad, theta, theta_p, cstep;
367   int            marks;
368 
369   tv_set_color(tv, colour);
370   marks = params->outer;
371   cstep = TWOPI/marks;
372   rad = vec2_dist(sp, ep);
373   centre = vec2_times(0.5, vec2_sum(sp, ep));
374 
375   vec2_to_polar(vec2_diff(sp, centre), &nrad, &theta_p);
376   theta = num*cstep + theta_p;
377   p1 = vec2_sum(centre, vec2_of_polar(rad, theta));
378   tv_line2(tv, centre, p1);
379 
380 
381 }
382 
383 static void raxis_show(Tv *tv, Ipos pos)
384 {
385   Sroi_dparams  *params = sroi_get_dparams();
386   Vec2           centre, p1, p2;
387   double         rad, nrad, theta_p;
388   int            i, marks;
389   
390   centre = vec2_times(0.5, vec2_sum(sp, ep));
391   rad = vec2_dist(sp, ep); 
392 
393   tv_repaint(tv);
394   tv_set_color(tv, red);
395   tv_circle2(tv, centre, rad); 
396   vec2_to_polar(vec2_diff(sp, centre), &nrad, &theta_p);
397   p1 = vec2_sum(centre, vec2_of_polar(rad, theta_p));
398   p2 = vec2_sum(centre, vec2_of_polar(rad, (theta_p+PI)));
399   tv_line2(tv, p1, p2);
400   marks = params->outer;
401   for (i=1; i<marks; i++)
402   {
403       raxis_draw(tv, yellow, i);
404   }
405 
406   tv_set_color(tv, green);
407   tv_bigdot2(tv, sp, 2);
408   tv_bigdot2(tv, ep, 2);
409   tv_cross2(tv, centre, 2);
410 }
411 
412 static void  raxis_set_start(Tv *tv, Ipos pos)
413 {
414   Vec2  Tv_backproj2();
415 
416   tv_save_draw(tv);
417   tv_set_overlay(tv);
418   
419   cp = op = tv_backproj2(tv, pos);
420   tv_bigdot2(tv, op, 2);
421 }
422 
423 
424 static void  raxis_frame_drag(Tv *tv, Ipos pos)
425 {
426   Vec2   Tv_backproj2();
427 
428   tv_line2(tv, op, cp);
429   cp = tv_backproj2(tv, pos);
430   tv_line2(tv, op, cp);
431 }
432 
433 
434 static void  raxis_set_end(Tv *tv, Ipos pos)
435 {
436   Vec2  Tv_backproj2();
437 
438   tv_reset_draw(tv);
439   tv_repaint(tv);
440   tv_set_color(tv, red);
441   
442   cp = tv_backproj2(tv, pos);
443   tv_bigdot2(tv, op, 2);
444   tv_bigdot2(tv, cp, 2);
445   tv_line2(tv, op, cp);
446   sp = op;
447   ep = cp;
448   raxis_show(tv, pos);
449   raxis_draw(tv, blue, 1);
450   tv_set_mouse(tv,  sroi_markup_mouse());
451   (void) tv_set_activity(tv, MOUSE);
452 
453 }
454 
455 
456 static void  rmove_frame_get(Tv *tv, Ipos pos)
457 {
458   Vec2  Tv_backproj2();
459   
460   op = tv_backproj2(tv, pos);
461   tv_save_draw(tv);
462   tv_set_overlay(tv);
463 
464   if (vec2_dist(op, sp) < vec2_dist(op, ep))
465     sp = op;
466   else
467     ep = op;
468   tv_bigdot2(tv, sp, 2);
469   tv_bigdot2(tv, ep, 2);
470   tv_line2(tv, sp, ep);
471 }
472 
473 
474 static void  rmove_frame_drag(Tv *tv, Ipos pos)
475 {
476   Vec2  Tv_backproj2();
477  
478   cp = tv_backproj2(tv, pos);
479 
480   tv_bigdot2(tv, sp, 2);
481   tv_bigdot2(tv, ep, 2);
482   tv_line2(tv, sp, ep);
483   if (vec2_dist(cp, sp) < vec2_dist(cp, ep))
484     sp = cp;
485   else
486     ep = cp;
487   tv_bigdot2(tv, sp, 2);
488   tv_bigdot2(tv, ep, 2);
489   tv_line2(tv, sp, ep);
490   op = cp;
491 }
492 
493 
494 static void  rmove_frame_put(Tv *tv, Ipos pos)
495 {
496   Vec2  Tv_backproj2();
497  
498   tv_reset_draw(tv); 
499   raxis_show(tv, pos);
500 }
501 
502 
503 Tv_mouse   sroi_radial_axis()
504 {
505   last_axis = 1;
506   return(mouse_define(MOUSE_NAME, "radial",
507                       LEFT_NAME, "frame",
508                       LEFT_DOWN, raxis_set_start,
509                       LEFT_DRAG, raxis_frame_drag,
510                       LEFT_UP,   raxis_set_end,
511                       MIDDLE_NAME, "show",
512                       MIDDLE_DOWN, raxis_show,
513                       RIGHT_NAME, "move",
514                       RIGHT_DOWN, rmove_frame_get,
515                       RIGHT_DRAG, rmove_frame_drag,
516                       RIGHT_UP,   rmove_frame_put,
517                       NULL));
518 }
519 
520 
521 static  int pnt_list_add(Vec2 cp)
522 {
523   Sroi_dparams *params = sroi_get_dparams();
524 
525   
526   if (pcount == 1)
527   {
528     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&sp), VEC2);
529   }
530   poly = dd_ref_addtoend(poly, (void *)vec2_copy(&cp), VEC2);
531   pcount++;
532 
533   if (!(params->outer%2) && (pcount == (params->outer/2)))
534   {
535     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&ep), VEC2);
536     pcount++;
537   }
538   else if ((params->outer%2) && (pcount == (params->outer/2)))
539   {
540     poly = dd_ref_addtoend(poly, (void *)vec2_copy(&ep), VEC2);
541     pcount++;
542   }
543     
544 
545   return(pcount);
546 }
547 
548 
549 static  void pnt_list_show(Tv *tv)
550 {
551   Sroi_dparams *params = sroi_get_dparams();
552   Vec2          p;
553   List       *lptr = dd_get_start(poly);
554   int           count;
555 
556   for (count = 0; lptr != NULL; lptr = lptr->next, count++)
557   {
558     tv_set_color(tv, red);
559     p = *(Vec2 *)(lptr->to);
560     
561     if (count == 0)
562       tv_set_color(tv, green);
563     else if (!(params->outer%2) && (count == (params->outer/2)))
564       tv_set_color(tv, green);
565     else if ((params->outer%2) && (count == (params->outer/2)))
566       tv_set_color(tv, green);
567       
568     tv_bigdot2(tv, p, 2);
569   }
570 }
571 
572 
573 static  void pnt_place_down(Tv *tv, Ipos pos)
574 {
575   Vec2  Tv_backproj2();
576 
577   tv_save_draw(tv);
578   tv_set_overlay(tv);
579   
580   cp = tv_backproj2(tv, pos);
581   tv_bigdot2(tv, cp, 2);
582 }
583 
584 
585 static  void pnt_place_drag(Tv *tv, Ipos pos)
586 {
587   Vec2  Tv_backproj2();
588   
589   tv_bigdot2(tv, cp, 2);
590   cp = tv_backproj2(tv, pos);
591   tv_bigdot2(tv, cp, 2);
592 }
593 
594 
595 static  void pnt_place_up(Tv *tv, Ipos pos)
596 {
597   int num;
598   tv_reset_draw(tv);
599   tv_repaint(tv);
600   num = pnt_list_add(cp);
601 
602   if (last_axis == 0)
603   {
604     paxis_show(tv, pos);
605     paxis_draw(tv, blue, num);
606   }
607   else
608   {
609     raxis_show(tv, pos);
610     raxis_draw(tv, blue, num);
611   }
612   pnt_list_show(tv);
613 }
614 
615 static  void pnt_redraw_up(Tv *tv, Ipos pos)
616 {
617   tv_reset_draw(tv);
618   tv_repaint(tv);
619 
620   if (last_axis == 0)
621   {
622     paxis_show(tv, pos);
623     paxis_draw(tv, blue, pcount);
624   }
625   else
626   {
627     raxis_show(tv, pos);
628     raxis_draw(tv, blue, pcount);
629   }
630   pnt_list_show(tv);
631 }
632 
633 static  void restart_markup(Tv *tv, Ipos pos)
634 {
635   if (poly != NULL)
636     dd_list_rm(poly, vec2_free);
637   poly = NULL;
638   pcount = 1;
639   if (last_axis == 0)
640   {
641     paxis_show(tv, pos);
642     paxis_draw(tv, blue, 1);
643   }
644   else
645   {
646     raxis_show(tv, pos);
647     raxis_draw(tv, blue, 1);
648   }
649 
650 }
651 
652 
653 Tv_mouse sroi_markup_mouse()
654 {
655   if (poly != NULL)
656     dd_list_rm(poly, vec2_free);
657   poly = NULL;
658   pcount = 1;
659 
660   return(mouse_define(MOUSE_NAME, "markup",
661                       LEFT_NAME, "place",
662                       LEFT_DOWN,  pnt_place_down,
663                       LEFT_DRAG,  pnt_place_drag,
664                       LEFT_UP,    pnt_place_up,
665                       MIDDLE_NAME, "restart",
666                       MIDDLE_DOWN, restart_markup,
667                       RIGHT_NAME, "redraw",
668                       RIGHT_DOWN, pnt_redraw_up,
669                       NULL));
670 }
671 

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