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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomCam_gen.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomCam_gen.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomCam_gen.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes : general camera functions
 34  *
 35  *********
 36 */
 37 
 38 #include "geomCam_gen.h"
 39 
 40 #if HAVE_CONFIG_H
 41   #include <config.h>
 42 #endif
 43 
 44 #include <math.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/geometry/geom_CamDef.h>
 50 
 51 /* ARGSUSED quieten lint */
 52 Camera *cam_alloc(int type)
 53 /* unused */
 54 {
 55     Camera *cam = ts_ralloc(Camera);
 56 
 57     cam->label = new_label();
 58 
 59     return (cam);
 60 }
 61 
 62 void    cam_comp_default_rects(Camera * cam)
 63 {
 64     double  kx, ky;
 65     double  cx, cy;
 66 
 67     if (cam == NULL)
 68         return;
 69 
 70     kx = cam->ax * cam->f / cam->pixel;
 71     ky = cam->ay * cam->f / cam->pixel;
 72     cx = cam->cx;
 73     cy = cam->cy;
 74 
 75     cam->cam_to_im = mat3(kx, 0.0, cx,
 76                           0.0, ky, cy,
 77                           0.0, 0.0, 1.0);
 78 
 79     cam->im_to_cam = mat3(1.0 / kx, 0.0, -cx / kx,
 80                           0.0, 1.0 / ky, -cy / ky,
 81                           0.0, 0.0, 1.0);
 82 }
 83 
 84 Camera *cam_make(unsigned int type, Transform3 * transf, double f, double pix, double ax, double ay, double cx, double cy, int width, int height)
 85 {
 86     Camera *cam = ts_ralloc(Camera);
 87 
 88     cam->type = type;
 89     cam->label = new_label();
 90 
 91     cam->f = (float)f;
 92     cam->ax = (float)ax;
 93     cam->ay = (float)ay;
 94     cam->cx = (float)cx;
 95     cam->cy = (float)cy;
 96     cam->pixel = (float)pix;
 97     cam->width = width;
 98     cam->height = height;
 99 
100     cam->distort_params = NULL;
101     cam->distort_func = cam->correct_func = NULL;
102     cam->correct_func = NULL;
103     cam->copy_dist_func = NULL;
104     cam->transf = trans3_copy(transf);
105 
106     cam_comp_default_rects(cam);
107 
108     return (cam);
109 }
110 
111 Camera *cam_copy(Camera * cam)
112 {
113     Camera *new_cam;
114 
115     if (cam == NULL)
116         return (NULL);
117     new_cam = cam_make(cam->type, cam->transf, cam->f, cam->pixel,
118                        cam->ax, cam->ay, cam->cx, cam->cy,
119                        cam->width, cam->height);
120     new_cam->correct_func = cam->correct_func;
121     new_cam->distort_func = cam->distort_func;
122     if (cam->distort_params != NULL)
123     {
124         if (cam->copy_dist_func != NULL)
125         {
126             new_cam->distort_params = cam->copy_dist_func(cam->distort_params);
127             new_cam->copy_dist_func = cam->copy_dist_func;
128         } else
129         {
130             format("warning: distortion parameters not copied\n");
131             new_cam->correct_func = new_cam->distort_func = NULL;
132         }
133     } else                      /* no distortion now */
134         new_cam->correct_func = new_cam->distort_func = NULL;
135     return (new_cam);
136 }
137 
138 Bool    cam_scale_to_image(Camera * cam, Imrect * im)
139 {
140     int     hscale, wscale;
141     Bool    larger;
142 
143     if (cam == NULL || im == NULL)
144         return (false);
145 
146     if (cam->width == im->width && cam->height == im->height)
147         return (true);
148 
149     if (cam->width > im->width)
150     {
151         larger = true;
152         wscale = cam->width / im->width;
153         if (cam->width != wscale * im->width)
154             return (false);     /* can't scale camera */
155     } else
156     {
157         larger = false;
158         wscale = im->width / cam->width;
159         if (im->width != wscale * cam->width)
160             return (false);     /* can't scale camera */
161     }
162 
163     if (cam->height > im->height)
164     {
165         if (larger == false)
166             return (false);
167         hscale = cam->height / im->height;
168         if (hscale != wscale || cam->height != hscale * im->height)
169             return (false);     /* cant scale camera */
170     } else
171     {
172         if (larger == true)
173             return (false);
174         hscale = im->height / cam->height;
175         if (hscale != wscale || im->height != hscale * cam->height)
176             return (false);     /* cant scale camera */
177     }
178 
179     if (larger)
180     {
181         cam->width /= wscale;
182         cam->height /= wscale;
183         cam->pixel *= wscale;   /* the pixel size increases */
184         cam->cx /= wscale;
185         cam->cy /= wscale;
186     } else
187     {
188         cam->width *= wscale;
189         cam->height *= wscale;
190         cam->pixel /= wscale;   /* the pixel size decreases */
191         cam->cx *= wscale;
192         cam->cy *= wscale;
193     }
194     cam_comp_default_rects(cam);
195     return (true);
196 }
197 
198 void    cam_free(Camera * cam)
199 {
200     if (cam == NULL)
201         return;
202 
203     if (cam->transf)
204         rfree((void *) cam->transf);
205     if (cam->distort_params)
206         rfree((void *) cam->distort_params);
207 
208     rfree((void *) cam);
209 }
210 

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