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

Linux Cross Reference
Tina5/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     switch (state)
383     {
384     case LEFT_DOWN:
385     case MIDDLE_DOWN:
386     case RIGHT_DOWN:
387         tv_set_overlay(tv);     /* also calls tv_save_draw */
388         break;
389     case LEFT_UP:
390     case MIDDLE_UP:
391     case RIGHT_UP:
392         tv_reset_draw(tv);
393         break;
394     }
395     switch (state)
396     {
397     case LEFT_DOWN:
398         oldx = x;
399         oldy = y;
400         tv_erase(tv);
401         centredot(tv);
402         tv->skeldraw(tv);
403         break;
404     case MIDDLE_DOWN:
405     case RIGHT_DOWN:
406         oldx = x;
407         oldy = y;
408         tv_erase(tv);
409         tv->skeldraw(tv);
410         break;
411     case LEFT_DRAG:
412         tv->skeldraw(tv);
413         tv_shift(tv, x - oldx, y - oldy);
414         tv->skeldraw(tv);
415         oldx = x;
416         oldy = y;
417         break;
418     case MIDDLE_DRAG:
419         tv->skeldraw(tv);
420         dx = x - oldx;
421         dy = y - oldy;
422         if (fabs(dx) > fabs(dy))
423             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
424         else
425             tv_rot(tv, -dy / tv->height);
426         tv->skeldraw(tv);
427         oldx = x;
428         oldy = y;
429         break;
430     case RIGHT_DRAG:
431         tv->skeldraw(tv);
432         dx = x - oldx;
433         dy = y - oldy;
434         if (fabs(dx) > fabs(dy))
435         {
436             if (tv->axis_set)
437                 tv_twist(tv, dx / tv->width, tv->axis);
438             else
439                 tv_twist(tv, dx / tv->width, tv->ey3);
440         } else
441             tv_twist(tv, -dy / tv->height, tv->ex3);
442         tv->skeldraw(tv);
443         oldx = x;
444         oldy = y;
445         break;
446     case LEFT_UP:
447     case MIDDLE_UP:
448     case RIGHT_UP:
449         tv_free_background(tv);
450         tv_repaint(tv);
451         break;
452     default:
453         break;
454     }
455 }
456 
457 void    tv_zoomgr_proc(Tv * tv, int state, Ipos pos)
458 {
459     double  x, y, dx, dy;
460     static double oldx, oldy;
461 
462     x = pos.x;
463     y = pos.y;
464     switch (state)
465     {
466     case LEFT_DOWN:
467     case MIDDLE_DOWN:
468     case RIGHT_DOWN:
469         tv_set_overlay(tv);     /* also calls tv_save_draw */
470         break;
471     case LEFT_UP:
472     case MIDDLE_UP:
473     case RIGHT_UP:
474         tv_reset_draw(tv);
475         break;
476     }
477     switch (state)
478     {
479     case LEFT_DOWN:
480         oldx = x;
481         oldy = y;
482         tv_erase(tv);
483         centredot(tv);
484         tv->skeldraw(tv);
485         break;
486     case MIDDLE_DOWN:
487     case RIGHT_DOWN:
488         oldx = x;
489         oldy = y;
490         tv_erase(tv);
491         tv->skeldraw(tv);
492         break;
493     case LEFT_DRAG:
494         tv->skeldraw(tv);
495         tv_shift(tv, x - oldx, y - oldy);
496         tv->skeldraw(tv);
497         oldx = x;
498         oldy = y;
499         break;
500     case MIDDLE_DRAG:
501         tv->skeldraw(tv);
502         dx = x - oldx;
503         dy = y - oldy;
504         if (fabs(dx) > fabs(dy))
505             tv_zoom(tv, (1.0 + x) / (1.0 + oldx));
506         tv->skeldraw(tv);
507         oldx = x;
508         oldy = y;
509         break;
510     case RIGHT_DRAG:
511         tv->skeldraw(tv);
512         dx = x - oldx;
513         dy = y - oldy;
514         if (fabs(dx) > fabs(dy))
515         {
516             Vec3    v = {Vec3_id};
517 
518             v = vec3_times(dx / tv->width, tv->ex3);
519             tv_fly(tv, v, tv->axis);
520         } else
521         {
522             Vec3    v = {Vec3_id};
523 
524             v = vec3_times(dy / tv->height, tv->ey3);
525             tv_fly(tv, v, tv->axis);
526         }
527         tv->skeldraw(tv);
528         oldx = x;
529         oldy = y;
530         break;
531     case LEFT_UP:
532     case MIDDLE_UP:
533     case RIGHT_UP:
534         tv_free_background(tv);
535         tv_repaint(tv);
536         break;
537     default:
538         break;
539     }
540 }
541 
542 void    tv_zoom_proc(Tv * tv, int state, Ipos pos)
543 {
544     switch (tv->zoomlevel)
545     {
546         case 0:
547         return;
548     case IMZOOM:
549         tv_imzoom_proc(tv, state, pos);
550         break;
551     case ZOOMAF:
552         tv_zoomaf_proc(tv, state, pos);
553         break;
554     case ZOOM2:
555         tv_zoom2_proc(tv, state, pos);
556         break;
557     case ZOOM3:
558         tv_zoom3_proc(tv, state, pos);
559         break;
560     case ZOOMGR:
561         tv_zoomgr_proc(tv, state, pos);
562         break;
563     }
564 }
565 

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