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

Linux Cross Reference
Tina4/src/tv/tv_proj2.c

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/tv.h>
  8 
  9 /**2D general projection**/
 10 
 11 static Ipos proj2(Tv * tv, Vec2 v)
 12 {
 13     Ipos    pos = {Ipos_id};
 14     double  x, y;
 15 
 16     v = vec2_diff(v, tv->centre2);
 17     x = tv->cx + tv->scalex * vec2_dot(v, tv->ex2);
 18     y = tv->cy + tv->scaley * vec2_dot(v, tv->ey2);
 19     pos.x = ROUND(x);
 20     pos.y = ROUND(y);
 21     return (pos);
 22 }
 23 
 24 static Vec2 backproj2(Tv * tv, Ipos pos)
 25 {
 26     Vec2    p = {Vec2_id};
 27     double  x = (pos.x - tv->cx) / tv->scalex;
 28     double  y = (pos.y - tv->cy) / tv->scaley;
 29 
 30     p = vec2_sum3(tv->centre2, vec2_times(x, tv->ex2), vec2_times(y, tv->ey2));
 31     return (p);
 32 }
 33 
 34 void    tv_set_proj2(Tv * tv)
 35 {
 36     tv->proj2 = proj2;
 37     tv->backproj2 = backproj2;
 38 }
 39 
 40 /**generic 2D projection**/
 41 
 42 Ipos    tv_proj2(Tv * tv, Vec2 p)
 43 {
 44     return (tv->proj2(tv, p));
 45 }
 46 
 47 Vec2    tv_backproj2(Tv * tv, Ipos pos)
 48 {
 49     return (tv->backproj2(tv, pos));
 50 }
 51 
 52 Bool    tv_ipos_within(Tv * tv, Ipos pos)
 53 {
 54     int     r, c;
 55 
 56     if (tv == NULL)
 57         return (false);
 58 
 59     r = ipos_y(pos);
 60     c = ipos_x(pos);
 61 
 62     return (Bool) (r >= 0 && r < tv->height && c >= 0 && c < tv->width);
 63 }
 64 
 65 /**setting and changing 2D cameras**/
 66 
 67 void    tv_camera2_rect(Tv * tv, Vec2 v1, Vec2 v2)
 68 {
 69     double  x1 = vec2_x(v1);
 70     double  y1 = vec2_y(v1);
 71     double  x2 = vec2_x(v2);
 72     double  y2 = vec2_y(v2);
 73     double  width, height;
 74 
 75     if (tv == NULL || x1 >= x2 || y1 >= y2)
 76         return;
 77     width = x2 - x1;
 78     height = y2 - y1;
 79     tv->scalex = (float)(tv->width / width);
 80     tv->scaley = (float)(tv->height / height);
 81     tv->cx = (float)(tv->width / 2);
 82     tv->cy = (float)(tv->height / 2);
 83     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 + y2) / 2.0);
 84     tv->radius2 = (float)(MAX(width, height));
 85     tv->ex2 = vec2_ex();
 86     tv->ey2 = vec2_minus(vec2_ey());
 87 }
 88 
 89 void    tv_camera2_roi(Tv * tv, Imregion * roi)
 90 {
 91     double  x1 = roi->lx;
 92     double  y1 = roi->ly;
 93     double  x2 = roi->ux;
 94     double  y2 = roi->uy;
 95     double  width, height;
 96 
 97     if(tv == NULL)
 98         return;
 99     if (x1 >= x2 || y1 >= y2)
100         return;
101     width = x2 - x1;
102     height = y2 - y1;
103     tv->scalex = tv->scaley = (float)(MIN(tv->width / width, tv->height / height));
104     tv->cx = (float)(tv->width / 2);
105     tv->cy = (float)(tv->height / 2);
106     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 + y2) / 2.0);
107     tv->radius2 = (float)(MAX(width, height));
108     tv->ex2 = vec2_ex();
109     tv->ey2 = vec2_ey();
110 }
111 
112 void    tv_camera2_image(Tv * tv, int width, int height)
113 {
114     if(tv == NULL)
115         return;
116     tv->scalex = tv->scaley =
117     (float)(MIN(tv->width / (double) width, tv->height / (double) height));
118     tv->cx = (float)(tv->width / 2);
119     tv->cy = (float)(tv->height / 2);
120     tv->centre2 = vec2(width / 2.0, height / 2.0);
121     tv->radius2 = (float)(MAX(width, height));
122     tv->ex2 = vec2_ex();
123     tv->ey2 = vec2_ey();
124 }
125 
126 /* Stretch the camera of a tv to make region of interest of an image
127  * (with given aspect ratio) fill the screen. */
128 void    tv_camera2_roi_stretch(Tv * tv, Imregion * roi, double aspect_ratio)
129 {
130     double  width = (double) (roi->ux - roi->lx);
131     double  cx = (double) (roi->ux + roi->lx) / 2.0;
132     double  cy = (double) (roi->uy + roi->ly) / 2.0;
133 
134     if(tv == NULL)
135         return;
136     tv->scalex = (float)(tv->width / width);
137     tv->scaley = (float)(tv->scalex * aspect_ratio);
138     tv->cx = (float)(tv->width / 2);
139     tv->cy = (float)(tv->height / 2);
140     tv->centre2 = vec2(cx, cy);
141     tv->ex2 = vec2_ex();
142     tv->ey2 = vec2_ey();
143 }
144 
145 void    tv_camera2(Tv * tv, Vec2 centre, double radius, Vec2 down)
146 {
147     if(tv == NULL)
148         return;
149     tv->scalex = tv->scaley = (float)(0.5 * MIN(tv->width, tv->height) / radius);
150     tv->cx = (float)(tv->width / 2);
151     tv->cy = (float)(tv->height / 2);
152     tv->centre2 = centre;
153     tv->radius2 = (float)radius;
154     vec2_basis(down, &tv->ex2, &tv->ey2);
155 }
156 
157 void    tv_orient2(Tv * tv, Vec2 down)
158 {
159     if(tv == NULL)
160         return;
161     vec2_basis(down, &tv->ex2, &tv->ey2);
162 }
163 

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