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

Linux Cross Reference
Tina6/tina-tools/tinatool/draw/drawTv_zoom.c

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_zoom.c,v $
 36  * Date    :  $Date: 2007/02/15 01:55:50 $
 37  * Version :  $Revision: 1.5 $
 38  * CVS Id  :  $Id: drawTv_zoom.c,v 1.5 2007/02/15 01:55:50 paul Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  *
 44  *********
 45 */
 46 
 47 #include "drawTv_zoom.h"
 48 
 49 #if HAVE_CONFIG_H
 50   #include <config.h>
 51 #endif
 52 
 53 #include <stdio.h>
 54 #include <math.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/math/mathDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/image/imgGen_region.h>
 60 #include <tinatool/draw/draw_TvDef.h>
 61 #include <tinatool/draw/draw_TvPro.h>
 62 
 63 Ipos    ipos();
 64 void    tv_erase();
 65 void    tv_orient2();
 66 void    tv_orient3();
 67 void    tv_line();
 68 void    tv_text();
 69 
 70 void    tv_shift(Tv * tv, double dx, double dy)
 71 {
 72     tv->cx += (float)dx;
 73     tv->cy += (float)dy;
 74 }
 75 
 76 void    tv_zoom(Tv * tv, double zoom)
 77 {
 78     double  x = (tv->width / 2 - tv->cx) / tv->scalex;
 79     double  y = (tv->height / 2 - tv->cy) / tv->scaley;
 80 
 81     tv->scalex *= (float)zoom;
 82     tv->scaley *= (float)zoom;
 83     tv->cx = (float)(tv->width / 2 - x * tv->scalex);
 84     tv->cy = (float)(tv->height / 2 - y * tv->scaley);
 85 }
 86 
 87 void    tv_zoomx(Tv * tv, double zoom)
 88 {
 89     double  x = (tv->width / 2 - tv->cx) / tv->scalex;
 90 
 91     tv->scalex *= (float)zoom;
 92     tv->cx = (float)(tv->width / 2 - x * tv->scalex);
 93 }
 94 
 95 void    tv_zoomy(Tv * tv, double zoom)
 96 {
 97     double  y = (tv->height / 2 - tv->cy) / tv->scaley;
 98 
 99     tv->scaley *= (float)zoom;
100     tv->cy = (float)(tv->height / 2 - y * tv->scaley);
101 }
102 
103 void    tv_rot(Tv * tv, double theta)
104 {
105     Vec2    down2 = {Vec2_id};
106     Vec3    down3 = {Vec3_id};
107 
108     down2 = mat2_vprod(rot2(theta), tv->ey2);
109     tv_orient2(tv, down2);
110     down3 = mat3_vprod(rot3(theta, tv->ez3), tv->ey3);
111     tv_orient3(tv, tv->ez3, down3);
112 }
113 
114 void    tv_rot2(Tv * tv, double theta)
115 {
116     Vec2    down2 = {Vec2_id};
117 
118     down2 = mat2_vprod(rot2(theta), tv->ey2);
119     tv_orient2(tv, down2);
120 }
121 
122 void    tv_rot3(Tv * tv, double theta)
123 {
124     Vec2    down2 = {Vec2_id};
125     Vec3    down3 = {Vec3_id};
126 
127     down3 = mat3_vprod(rot3(theta, tv->ez3), tv->ey3);
128     tv_orient3(tv, tv->ez3, down3);
129 }
130 
131 void    tv_twist(Tv * tv, double theta, Vec3 axis)
132 {
133     Mat3    rot = {Mat3_id};
134     Vec3    aim = {Vec3_id};
135     Vec3    down = {Vec3_id};
136 
137     rot = rot3(theta, axis);
138     aim = mat3_vprod(rot, tv->ez3);
139     down = mat3_vprod(rot, tv->ey3);
140     tv_orient3(tv, aim, down);
141 }
142 
143 void    tv_fly(Tv * tv, Vec3 v, Vec3 down)
144 {
145     Vec3    aim = {Vec3_id};
146 
147     aim = vec3_unit(vec3_sum(tv->ez3, v));
148     tv_orient3(tv, aim, down);
149 }
150 
151 static void centredot(Tv * tv)
152 {
153     tv_save_draw(tv);
154     (void) tv_set_op(tv, rop_copy);
155     tv_set_color(tv, black);
156     tv_dot(tv, ipos(tv->width / 2, tv->height / 2));
157     tv_reset_draw(tv);
158 }
159 
160 void    tv_imzoom_proc(Tv * tv, int state, Ipos pos)
161 {
162     double  x, y, dx, dy;
163     static double oldx, oldy;
164     static Vec2 p1 = {Vec2_id};
165     static Vec2 p2 = {Vec2_id};
166     Imregion roi = {Imregion_id};
167 
168     x = pos.x;
169     y = pos.y;
170     switch (state)
171     {
172     case LEFT_DOWN:
173     case MIDDLE_DOWN:
174     case RIGHT_DOWN:
175         tv_set_overlay(tv);     /* also calls tv_save_draw */
176         break;
177     case LEFT_UP:
178     case MIDDLE_UP:
179     case RIGHT_UP:
180         tv_reset_draw(tv);
181         break;
182     }
183 
184 
185     switch (state)
186     {
187     case LEFT_DOWN:
188         oldx = x;
189         oldy = y;
190         tv_erase(tv);
191         centredot(tv);
192         tv->skeldraw(tv);
193         break;
194     case MIDDLE_DOWN:
195         oldx = x;
196         oldy = y;
197         tv_erase(tv);
198         tv->skeldraw(tv);
199         break;
200     case LEFT_DRAG:
201         tv->skeldraw(tv);
202         tv_shift(tv, x - oldx, y - oldy);
203         tv->skeldraw(tv);
204         oldx = x;
205         oldy = y;
206         break;
207     case MIDDLE_DRAG:
208         tv->skeldraw(tv);
209         dx = x - oldx;
210         dy = y - oldy;
211         if (fabs(dx) > fabs(dy))
212             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
213         else
214             tv_rot3(tv,-dy / tv->height);
215         tv->skeldraw(tv);
216         oldx = x;
217         oldy = y;
218         break;
219     case RIGHT_DOWN:
220         p1 = p2 = tv_backproj2(tv, pos);
221         tv_rect2(tv, p1, p2);
222         break;
223     case RIGHT_DRAG:
224         tv_rect2(tv, p1, p2);
225         p2 = tv_backproj2(tv, pos);
226         tv_rect2(tv, p1, p2);
227         break;
228     case RIGHT_UP:
229         tv_rect2(tv, p1, p2);
230         if (vec2_x(p1) > vec2_x(p2))
231             SWAP(double, vec2_x(p1), vec2_x(p2));
232         if (vec2_y(p1) > vec2_y(p2))
233             SWAP(double, vec2_y(p1), vec2_y(p2));
234         roi_fill(&roi, (int) vec2_x(p1), (int) vec2_y(p1),
235                  (int) vec2_x(p2), (int) vec2_y(p2));
236         tv_camera2_roi(tv, &roi);
237     case LEFT_UP:
238     case MIDDLE_UP:
239         tv_free_background(tv);
240         tv_repaint(tv);
241         break;
242     default:
243         break;
244     }
245 }
246 
247 void    tv_zoom2_proc(Tv * tv, int state, Ipos pos)
248 {
249     double  x, y, dx, dy;
250     static double oldx, oldy;
251 
252     x = pos.x;
253     y = pos.y;
254     switch (state)
255     {
256     case LEFT_DOWN:
257     case MIDDLE_DOWN:
258     case RIGHT_DOWN:
259         tv_set_overlay(tv);     /* also calls tv_save_draw */
260         break;
261     case LEFT_UP:
262     case MIDDLE_UP:
263     case RIGHT_UP:
264         tv_reset_draw(tv);
265         break;
266     }
267     switch (state)
268     {
269     case LEFT_DOWN:
270         oldx = x;
271         oldy = y;
272         tv_erase(tv);
273         centredot(tv);
274         tv->skeldraw(tv);
275         break;
276     case MIDDLE_DOWN:
277         oldx = x;
278         oldy = y;
279         tv_erase(tv);
280         tv->skeldraw(tv);
281         break;
282     case LEFT_DRAG:
283         tv->skeldraw(tv);
284         tv_shift(tv, x - oldx, y - oldy);
285         tv->skeldraw(tv);
286         oldx = x;
287         oldy = y;
288         break;
289     case MIDDLE_DRAG:
290         tv->skeldraw(tv);
291         dx = x - oldx;
292         dy = y - oldy;
293         if (fabs(dx) > fabs(dy))
294             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
295         else
296             tv_rot(tv, -dy / tv->height);
297         tv->skeldraw(tv);
298         oldx = x;
299         oldy = y;
300         break;
301     case LEFT_UP:
302     case MIDDLE_UP:
303         tv_free_background(tv);
304         tv_repaint(tv);
305         break;
306     default:
307         break;
308     }
309 }
310 
311 void    tv_zoomaf_proc(Tv * tv, int state, Ipos pos)
312 {
313     double  x, y, dx, dy;
314     static double oldx, oldy;
315 
316     x = pos.x;
317     y = pos.y;
318     switch (state)
319     {
320     case LEFT_DOWN:
321     case MIDDLE_DOWN:
322     case RIGHT_DOWN:
323         tv_set_overlay(tv);     /* also calls tv_save_draw */
324         break;
325     case LEFT_UP:
326     case MIDDLE_UP:
327     case RIGHT_UP:
328         tv_reset_draw(tv);
329         break;
330     }
331     switch (state)
332     {
333     case LEFT_DOWN:
334         oldx = x;
335         oldy = y;
336         tv_erase(tv);
337         centredot(tv);
338         tv->skeldraw(tv);
339         break;
340     case MIDDLE_DOWN:
341         oldx = x;
342         oldy = y;
343         tv_erase(tv);
344         tv->skeldraw(tv);
345         break;
346     case LEFT_DRAG:
347         tv->skeldraw(tv);
348         tv_shift(tv, x - oldx, y - oldy);
349         tv->skeldraw(tv);
350         oldx = x;
351         oldy = y;
352         break;
353     case MIDDLE_DRAG:
354         tv->skeldraw(tv);
355         dx = x - oldx;
356         dy = y - oldy;
357         if (fabs(dx) > fabs(dy))
358             tv_zoomx(tv, (1.0 + x) / (1.0 + oldx));
359         else
360             tv_zoomy(tv, (1.0 + y) / (1.0 + oldy));
361         tv->skeldraw(tv);
362         oldx = x;
363         oldy = y;
364         break;
365     case LEFT_UP:
366     case MIDDLE_UP:
367         tv_free_background(tv);
368         tv_repaint(tv);
369         break;
370     default:
371         break;
372     }
373 }
374 
375 void    tv_zoom3_proc(Tv * tv, int state, Ipos pos)
376 {
377     double  x, y, dx, dy;
378     static double oldx, oldy;
379 
380     x = pos.x;
381     y = pos.y;
382 
383     switch (state)
384     {
385     case LEFT_DOWN:
386     case MIDDLE_DOWN:
387     case RIGHT_DOWN:
388         tv_set_overlay(tv);    /*also calls tv_save_draw */
389         break;
390     case LEFT_UP:
391     case MIDDLE_UP:
392     case RIGHT_UP:
393         tv_reset_draw(tv);
394         break;
395     }
396 
397     switch (state)
398     {
399     case LEFT_DOWN:
400         oldx = x;
401         oldy = y;
402         tv_erase(tv);
403         centredot(tv);
404         tv->skeldraw(tv);
405         break;
406     case MIDDLE_DOWN:
407     case RIGHT_DOWN:
408         oldx = x;
409         oldy = y;
410         tv_erase(tv);
411         tv->skeldraw(tv);
412         break;
413     case LEFT_DRAG:
414         tv->skeldraw(tv);
415         tv_shift(tv, x - oldx, y - oldy);
416         tv->skeldraw(tv);
417         oldx = x;
418         oldy = y;
419         break;
420     case MIDDLE_DRAG:
421         tv->skeldraw(tv);
422         dx = x - oldx;
423         dy = y - oldy;
424         if (fabs(dx) > fabs(dy))
425             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
426         else
427             tv_rot(tv, -dy / tv->height); 
428         tv->skeldraw(tv);
429         oldx = x;
430         oldy = y;
431         break;
432     case RIGHT_DRAG:
433         tv->skeldraw(tv);
434         dx = x - oldx;
435         dy = y - oldy;
436         if (fabs(dx) > fabs(dy))
437         {
438             if (tv->axis_set)
439                 tv_twist(tv, dx / tv->width, tv->axis);
440             else
441                 tv_twist(tv, dx / tv->width, tv->ey3);
442         } else
443             tv_twist(tv, -dy / tv->height, tv->ex3);
444         tv->skeldraw(tv);
445         oldx = x;
446         oldy = y;
447         break;
448     case LEFT_UP:
449     case MIDDLE_UP:
450     case RIGHT_UP:
451         tv_free_background(tv);
452         tv_repaint(tv);
453         break;
454     default:
455         break;
456     }
457 }
458 
459 void    tv_zoomgr_proc(Tv * tv, int state, Ipos pos)
460 {
461     double  x, y, dx, dy;
462     static double oldx, oldy;
463 
464     x = pos.x;
465     y = pos.y;
466     switch (state)
467     {
468     case LEFT_DOWN:
469     case MIDDLE_DOWN:
470     case RIGHT_DOWN:
471         tv_set_overlay(tv);     /* also calls tv_save_draw */
472         break;
473     case LEFT_UP:
474     case MIDDLE_UP:
475     case RIGHT_UP:
476         tv_reset_draw(tv);
477         break;
478     }
479     switch (state)
480     {
481     case LEFT_DOWN:
482         oldx = x;
483         oldy = y;
484         tv_erase(tv);
485         centredot(tv);
486         tv->skeldraw(tv);
487         break;
488     case MIDDLE_DOWN:
489     case RIGHT_DOWN:
490         oldx = x;
491         oldy = y;
492         tv_erase(tv);
493         tv->skeldraw(tv);
494         break;
495     case LEFT_DRAG:
496         tv->skeldraw(tv);
497         tv_shift(tv, x - oldx, y - oldy);
498         tv->skeldraw(tv);
499         oldx = x;
500         oldy = y;
501         break;
502     case MIDDLE_DRAG:
503         tv->skeldraw(tv);
504         dx = x - oldx;
505         dy = y - oldy;
506         if (fabs(dx) > fabs(dy))
507             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
508         tv->skeldraw(tv);
509         oldx = x;
510         oldy = y;
511         break;
512     case RIGHT_DRAG:
513         tv->skeldraw(tv);
514         dx = x - oldx;
515         dy = y - oldy;
516         if (fabs(dx) > fabs(dy))
517         {
518             Vec3    v = {Vec3_id};
519 
520             v = vec3_times(dx / tv->width, tv->ex3);
521             tv_fly(tv, v, tv->axis);
522         } else
523         {
524             Vec3    v = {Vec3_id};
525 
526             v = vec3_times(dy / tv->height, tv->ey3);
527             tv_fly(tv, v, tv->axis);
528         }
529         tv->skeldraw(tv);
530         oldx = x;
531         oldy = y;
532         break;
533     case LEFT_UP:
534     case MIDDLE_UP:
535     case RIGHT_UP:
536         tv_free_background(tv);
537         tv_repaint(tv);
538         break;
539     default:
540         break;
541     }
542 }
543 
544 
545 /**
546  * @brief 3D zoom of the image displayed in a tv.
547  * @param tv The tv in which the mouse pointer is currently located
548  * @param state Code for the state of the mouse buttons.
549  * @param pos The sceen position of the mouse pointer.
550  *
551  * Notes: this version was added as part of the manual landmarking tool for the 
552  * Max Planck collaborative project.  It is the same as tv_zoom3_proc, except that
553  * it does not draw in overlay mode (to prevent screen flicker) and the middle 
554  * button rotation works in 3D not in 2D.  The latter is required because the 
555  * manual landmarking 3D Tv uses a mixture of 2D and 3D drawing functions: the 
556  * 3D rotation is passed to volpack, which produces a 2D image to be displayed in 
557  * the Tv.
558  *
559 */
560 void    tv_zoom4_proc(Tv * tv, int state, Ipos pos)
561 {
562     double  x, y, dx, dy;
563     static double oldx, oldy;
564 
565     x = pos.x;
566     y = pos.y;
567 
568     switch (state)
569     {
570     case RIGHT_DOWN:
571         oldx = x;
572         oldy = y;
573         tv_erase(tv);
574         centredot(tv);
575         tv->skeldraw(tv);
576         break;
577     case MIDDLE_DOWN:
578     case LEFT_DOWN:
579         oldx = x;
580         oldy = y;
581         tv_erase(tv);
582         tv->skeldraw(tv);
583         break;
584     case RIGHT_DRAG:
585         tv->skeldraw(tv);
586         tv_shift(tv, x - oldx, y - oldy);
587         tv->skeldraw(tv);
588         oldx = x;
589         oldy = y;
590         break;
591     case MIDDLE_DRAG:
592         tv->skeldraw(tv);
593         dx = x - oldx;
594         dy = y - oldy;
595         if (fabs(dx) > fabs(dy))
596             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
597         else
598             /* tv_rot(tv, -dy / tv->height); */
599             tv_twist(tv, -dy / tv->height, tv->ez3);
600         tv->skeldraw(tv);
601         oldx = x;
602         oldy = y;
603         break;
604     case LEFT_DRAG:
605         tv->skeldraw(tv);
606         dx = x - oldx;
607         dy = y - oldy;
608         if (fabs(dx) > fabs(dy))
609         {
610             if (tv->axis_set)
611                 tv_twist(tv, dx / tv->width, tv->axis);
612             else
613                 tv_twist(tv, dx / tv->width, tv->ey3);
614         } else
615             tv_twist(tv, -dy / tv->height, tv->ex3);
616         tv->skeldraw(tv);
617         oldx = x;
618         oldy = y;
619         break;
620     case LEFT_UP:
621     case MIDDLE_UP:
622     case RIGHT_UP:
623         tv_free_background(tv);
624         tv_repaint(tv);
625         break;
626     default:
627         break;
628     }
629 }
630 
631 
632 void    tv_zoom_proc(Tv * tv, int state, Ipos pos)
633 {
634     switch (tv->zoomlevel)
635     {
636         case 0:
637         return;
638     case IMZOOM:
639         tv_imzoom_proc(tv, state, pos);
640         break;
641     case ZOOMAF:
642         tv_zoomaf_proc(tv, state, pos);
643         break;
644     case ZOOM2:
645         tv_zoom2_proc(tv, state, pos);
646         break;
647     case ZOOM3:
648         tv_zoom3_proc(tv, state, pos);
649         break;
650     case ZOOMGR:
651         tv_zoomgr_proc(tv, state, pos);
652         break;
653     case ZOOM4:
654         tv_zoom4_proc(tv, state, pos);
655         break;
656     }
657 }
658 

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