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

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

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

Diff markup

Differences between /tina-tools/tinatool/draw/drawTv_proj2.c (Architecture alpha) and /tina-tools/tinatool/draw/drawTv_proj2.c (Architecture ppc)


  1 /*********                                          1 /*********
  2  * Copyright (c) 2003, Division of Imaging Sci      2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights r      3  * University of Manchester, UK.  All rights reserved.
  4  *                                                  4  * 
  5  * Redistribution and use in source and binary      5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following c      6  * are permitted provided that the following conditions are met:
  7  *                                                  7  * 
  8  *   . Redistributions of source code must ret      8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the followi      9  *     this list of conditions and the following disclaimer.
 10  *                                                 10  *    
 11  *   . Redistributions in binary form must rep     11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the followi     12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with th     13  *     and/or other materials provided with the distribution.
 14  *                                                 14  * 
 15  *   . Neither the name of the University of M     15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or      16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written     17  *     software without specific prior written permission.
 18  *                                                 18  * 
 19  *                                                 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT      20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCL     21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND F     22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPY     23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL     24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT L     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,      26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THE     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUD     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS S     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.                     30  * POSSIBILITY OF SUCH DAMAGE.
 31  *                                                 31  *
 32  **********                                        32  **********
 33  *                                                 33  *
 34  * Program :    TINA                               34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-too     35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_proj2.c,v $
 36  * Date    :  $Date: 2003/10/01 16:02:47 $         36  * Date    :  $Date: 2003/10/01 16:02:47 $
 37  * Version :  $Revision: 1.2 $                     37  * Version :  $Revision: 1.2 $
 38  * CVS Id  :  $Id: drawTv_proj2.c,v 1.2 2003/1     38  * CVS Id  :  $Id: drawTv_proj2.c,v 1.2 2003/10/01 16:02:47 tony Exp $
 39  *                                                 39  *
 40  * Author  : Legacy TINA                           40  * Author  : Legacy TINA
 41  *                                                 41  *
 42  * Notes :                                         42  * Notes :
 43  *                                                 43  *
 44  *********                                         44  *********
 45 */                                                 45 */
 46                                                    46 
 47 #include "drawTv_proj2.h"                          47 #include "drawTv_proj2.h"
 48                                                    48 
 49 #if HAVE_CONFIG_H                                  49 #if HAVE_CONFIG_H
 50   #include <config.h>                              50   #include <config.h>
 51 #endif                                             51 #endif
 52                                                    52 
 53 #include <stdio.h>                                 53 #include <stdio.h>
 54 #include <tina/sys/sysDef.h>                       54 #include <tina/sys/sysDef.h>
 55 #include <tina/math/mathDef.h>                     55 #include <tina/math/mathDef.h>
 56 #include <tina/math/mathPro.h>                     56 #include <tina/math/mathPro.h>
 57 #include <tinatool/draw/draw_TvDef.h>              57 #include <tinatool/draw/draw_TvDef.h>
 58                                                    58 
 59 /**2D general projection**/                        59 /**2D general projection**/
 60                                                    60 
 61 static Ipos proj2(Tv * tv, Vec2 v)                 61 static Ipos proj2(Tv * tv, Vec2 v)
 62 {                                                  62 {
 63     Ipos    pos = {Ipos_id};                       63     Ipos    pos = {Ipos_id};
 64     double  x, y;                                  64     double  x, y;
 65                                                    65 
 66     v = vec2_diff(v, tv->centre2);                 66     v = vec2_diff(v, tv->centre2);
 67     x = tv->cx + tv->scalex * vec2_dot(v, tv->     67     x = tv->cx + tv->scalex * vec2_dot(v, tv->ex2);
 68     y = tv->cy + tv->scaley * vec2_dot(v, tv->     68     y = tv->cy + tv->scaley * vec2_dot(v, tv->ey2);
 69     pos.x = ROUND(x);                              69     pos.x = ROUND(x);
 70     pos.y = ROUND(y);                              70     pos.y = ROUND(y);
 71     return (pos);                                  71     return (pos);
 72 }                                                  72 }
 73                                                    73 
 74 static Vec2 backproj2(Tv * tv, Ipos pos)           74 static Vec2 backproj2(Tv * tv, Ipos pos)
 75 {                                                  75 {
 76     Vec2    p = {Vec2_id};                         76     Vec2    p = {Vec2_id};
 77     double  x = (pos.x - tv->cx) / tv->scalex;     77     double  x = (pos.x - tv->cx) / tv->scalex;
 78     double  y = (pos.y - tv->cy) / tv->scaley;     78     double  y = (pos.y - tv->cy) / tv->scaley;
 79                                                    79 
 80     p = vec2_sum3(tv->centre2, vec2_times(x, t     80     p = vec2_sum3(tv->centre2, vec2_times(x, tv->ex2), vec2_times(y, tv->ey2));
 81     return (p);                                    81     return (p);
 82 }                                                  82 }
 83                                                    83 
 84 void    tv_set_proj2(Tv * tv)                      84 void    tv_set_proj2(Tv * tv)
 85 {                                                  85 {
 86     tv->proj2 = proj2;                             86     tv->proj2 = proj2;
 87     tv->backproj2 = backproj2;                     87     tv->backproj2 = backproj2;
 88 }                                                  88 }
 89                                                    89 
 90 /**generic 2D projection**/                        90 /**generic 2D projection**/
 91                                                    91 
 92 Ipos    tv_proj2(Tv * tv, Vec2 p)                  92 Ipos    tv_proj2(Tv * tv, Vec2 p)
 93 {                                                  93 {
 94     return (tv->proj2(tv, p));                     94     return (tv->proj2(tv, p));
 95 }                                                  95 }
 96                                                    96 
 97 Vec2    tv_backproj2(Tv * tv, Ipos pos)            97 Vec2    tv_backproj2(Tv * tv, Ipos pos)
 98 {                                                  98 {
 99     return (tv->backproj2(tv, pos));               99     return (tv->backproj2(tv, pos));
100 }                                                 100 }
101                                                   101 
102 Bool    tv_ipos_within(Tv * tv, Ipos pos)         102 Bool    tv_ipos_within(Tv * tv, Ipos pos)
103 {                                                 103 {
104     int     r, c;                                 104     int     r, c;
105                                                   105 
106     if (tv == NULL)                               106     if (tv == NULL)
107         return (false);                           107         return (false);
108                                                   108 
109     r = ipos_y(pos);                              109     r = ipos_y(pos);
110     c = ipos_x(pos);                              110     c = ipos_x(pos);
111                                                   111 
112     return (Bool) (r >= 0 && r < tv->height &&    112     return (Bool) (r >= 0 && r < tv->height && c >= 0 && c < tv->width);
113 }                                                 113 }
114                                                   114 
115 /**setting and changing 2D cameras**/             115 /**setting and changing 2D cameras**/
116                                                   116 
117 void    tv_camera2_rect(Tv * tv, Vec2 v1, Vec2    117 void    tv_camera2_rect(Tv * tv, Vec2 v1, Vec2 v2)
118 {                                                 118 {
119     double  x1 = vec2_x(v1);                      119     double  x1 = vec2_x(v1);
120     double  y1 = vec2_y(v1);                      120     double  y1 = vec2_y(v1);
121     double  x2 = vec2_x(v2);                      121     double  x2 = vec2_x(v2);
122     double  y2 = vec2_y(v2);                      122     double  y2 = vec2_y(v2);
123     double  width, height;                        123     double  width, height;
124                                                   124 
125     if (tv == NULL || x1 >= x2 || y1 >= y2)       125     if (tv == NULL || x1 >= x2 || y1 >= y2)
126         return;                                   126         return;
127     width = x2 - x1;                              127     width = x2 - x1;
128     height = y2 - y1;                             128     height = y2 - y1;
129     tv->scalex = (float)(tv->width / width);      129     tv->scalex = (float)(tv->width / width);
130     tv->scaley = (float)(tv->height / height);    130     tv->scaley = (float)(tv->height / height);
131     tv->cx = (float)(tv->width / 2);              131     tv->cx = (float)(tv->width / 2);
132     tv->cy = (float)(tv->height / 2);             132     tv->cy = (float)(tv->height / 2);
133     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 +     133     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 + y2) / 2.0);
134     tv->radius2 = (float)(MAX(width, height));    134     tv->radius2 = (float)(MAX(width, height));
135     tv->ex2 = vec2_ex();                          135     tv->ex2 = vec2_ex();
136     tv->ey2 = vec2_minus(vec2_ey());              136     tv->ey2 = vec2_minus(vec2_ey());
137 }                                                 137 }
138                                                   138 
139 void    tv_camera2_roi(Tv * tv, Imregion * roi    139 void    tv_camera2_roi(Tv * tv, Imregion * roi)
140 {                                                 140 {
141     double  x1 = roi->lx;                         141     double  x1 = roi->lx;
142     double  y1 = roi->ly;                         142     double  y1 = roi->ly;
143     double  x2 = roi->ux;                         143     double  x2 = roi->ux;
144     double  y2 = roi->uy;                         144     double  y2 = roi->uy;
145     double  width, height;                        145     double  width, height;
146                                                   146 
147     if(tv == NULL)                                147     if(tv == NULL)
148         return;                                   148         return;
149     if (x1 >= x2 || y1 >= y2)                     149     if (x1 >= x2 || y1 >= y2)
150         return;                                   150         return;
151     width = x2 - x1;                              151     width = x2 - x1;
152     height = y2 - y1;                             152     height = y2 - y1;
153     tv->scalex = tv->scaley = (float)(MIN(tv->    153     tv->scalex = tv->scaley = (float)(MIN(tv->width / width, tv->height / height));
154     tv->cx = (float)(tv->width / 2);              154     tv->cx = (float)(tv->width / 2);
155     tv->cy = (float)(tv->height / 2);             155     tv->cy = (float)(tv->height / 2);
156     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 +     156     tv->centre2 = vec2((x1 + x2) / 2.0, (y1 + y2) / 2.0);
157     tv->radius2 = (float)(MAX(width, height));    157     tv->radius2 = (float)(MAX(width, height));
158     tv->ex2 = vec2_ex();                          158     tv->ex2 = vec2_ex();
159     tv->ey2 = vec2_ey();                          159     tv->ey2 = vec2_ey();
160 }                                                 160 }
161                                                   161 
162 void    tv_camera2_image(Tv * tv, int width, i    162 void    tv_camera2_image(Tv * tv, int width, int height)
163 {                                                 163 {
164     if(tv == NULL)                                164     if(tv == NULL)
165         return;                                   165         return;
166     tv->scalex = tv->scaley =                     166     tv->scalex = tv->scaley =
167     (float)(MIN(tv->width / (double) width, tv    167     (float)(MIN(tv->width / (double) width, tv->height / (double) height));
168     tv->cx = (float)(tv->width / 2);              168     tv->cx = (float)(tv->width / 2);
169     tv->cy = (float)(tv->height / 2);             169     tv->cy = (float)(tv->height / 2);
170     tv->centre2 = vec2(width / 2.0, height / 2    170     tv->centre2 = vec2(width / 2.0, height / 2.0);
171     tv->radius2 = (float)(MAX(width, height));    171     tv->radius2 = (float)(MAX(width, height));
172     tv->ex2 = vec2_ex();                          172     tv->ex2 = vec2_ex();
173     tv->ey2 = vec2_ey();                          173     tv->ey2 = vec2_ey();
174 }                                                 174 }
175                                                   175 
176 /* Stretch the camera of a tv to make region o    176 /* Stretch the camera of a tv to make region of interest of an image
177  * (with given aspect ratio) fill the screen.     177  * (with given aspect ratio) fill the screen. */
178 void    tv_camera2_roi_stretch(Tv * tv, Imregi    178 void    tv_camera2_roi_stretch(Tv * tv, Imregion * roi, double aspect_ratio)
179 {                                                 179 {
180     double  width = (double) (roi->ux - roi->l    180     double  width = (double) (roi->ux - roi->lx);
181     double  cx = (double) (roi->ux + roi->lx)     181     double  cx = (double) (roi->ux + roi->lx) / 2.0;
182     double  cy = (double) (roi->uy + roi->ly)     182     double  cy = (double) (roi->uy + roi->ly) / 2.0;
183                                                   183 
184     if(tv == NULL)                                184     if(tv == NULL)
185         return;                                   185         return;
186     tv->scalex = (float)(tv->width / width);      186     tv->scalex = (float)(tv->width / width);
187     tv->scaley = (float)(tv->scalex * aspect_r    187     tv->scaley = (float)(tv->scalex * aspect_ratio);
188     tv->cx = (float)(tv->width / 2);              188     tv->cx = (float)(tv->width / 2);
189     tv->cy = (float)(tv->height / 2);             189     tv->cy = (float)(tv->height / 2);
190     tv->centre2 = vec2(cx, cy);                   190     tv->centre2 = vec2(cx, cy);
191     tv->ex2 = vec2_ex();                          191     tv->ex2 = vec2_ex();
192     tv->ey2 = vec2_ey();                          192     tv->ey2 = vec2_ey();
193 }                                                 193 }
194                                                   194 
195 void    tv_camera2(Tv * tv, Vec2 centre, doubl    195 void    tv_camera2(Tv * tv, Vec2 centre, double radius, Vec2 down)
196 {                                                 196 {
197     if(tv == NULL)                                197     if(tv == NULL)
198         return;                                   198         return;
199     tv->scalex = tv->scaley = (float)(0.5 * MI    199     tv->scalex = tv->scaley = (float)(0.5 * MIN(tv->width, tv->height) / radius);
200     tv->cx = (float)(tv->width / 2);              200     tv->cx = (float)(tv->width / 2);
201     tv->cy = (float)(tv->height / 2);             201     tv->cy = (float)(tv->height / 2);
202     tv->centre2 = centre;                         202     tv->centre2 = centre;
203     tv->radius2 = (float)radius;                  203     tv->radius2 = (float)radius;
204     vec2_basis(down, &tv->ex2, &tv->ey2);         204     vec2_basis(down, &tv->ex2, &tv->ey2);
205 }                                                 205 }
206                                                   206 
207 void    tv_orient2(Tv * tv, Vec2 down)            207 void    tv_orient2(Tv * tv, Vec2 down)
208 {                                                 208 {
209     if(tv == NULL)                                209     if(tv == NULL)
210         return;                                   210         return;
211     vec2_basis(down, &tv->ex2, &tv->ey2);         211     vec2_basis(down, &tv->ex2, &tv->ey2);
212 }                                                 212 }
213                                                   213 

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