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

Linux Cross Reference
TINA5/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 Lesser 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 Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser 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  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomCam_gen.c,v $
 23  * Date    :  $Date: 2002/12/09 11:51:23 $
 24  * Version :  $Revision: 1.1.1.1 $
 25  * CVS Id  :  $Id: geomCam_gen.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : general camera functions
 30  *
 31  *********
 32 */
 33 
 34 #include "geomCam_gen.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <tina/sys/sysDef.h>
 42 #include <tina/sys/sysPro.h>
 43 #include <tina/math/mathDef.h>
 44 #include <tina/math/mathPro.h>
 45 #include <tina/geometry/geom_CamDef.h>
 46 
 47 /* ARGSUSED quieten lint */
 48 Camera *cam_alloc(int type)
 49 /* unused */
 50 {
 51     Camera *cam = ts_ralloc(Camera);
 52 
 53     cam->label = new_label();
 54 
 55     return (cam);
 56 }
 57 
 58 void    cam_comp_default_rects(Camera * cam)
 59 {
 60     double  kx, ky;
 61     double  cx, cy;
 62 
 63     if (cam == NULL)
 64         return;
 65 
 66     kx = cam->ax * cam->f / cam->pixel;
 67     ky = cam->ay * cam->f / cam->pixel;
 68     cx = cam->cx;
 69     cy = cam->cy;
 70 
 71     cam->cam_to_im = mat3(kx, 0.0, cx,
 72                           0.0, ky, cy,
 73                           0.0, 0.0, 1.0);
 74 
 75     cam->im_to_cam = mat3(1.0 / kx, 0.0, -cx / kx,
 76                           0.0, 1.0 / ky, -cy / ky,
 77                           0.0, 0.0, 1.0);
 78 }
 79 
 80 Camera *cam_make(unsigned int type, Transform3 * transf, double f, double pix, double ax, double ay, double cx, double cy, int width, int height)
 81 {
 82     Camera *cam = ts_ralloc(Camera);
 83 
 84     cam->type = type;
 85     cam->label = new_label();
 86 
 87     cam->f = (float)f;
 88     cam->ax = (float)ax;
 89     cam->ay = (float)ay;
 90     cam->cx = (float)cx;
 91     cam->cy = (float)cy;
 92     cam->pixel = (float)pix;
 93     cam->width = width;
 94     cam->height = height;
 95 
 96     cam->distort_params = NULL;
 97     cam->distort_func = cam->correct_func = NULL;
 98     cam->correct_func = NULL;
 99     cam->copy_dist_func = NULL;
100     cam->transf = trans3_copy(transf);
101 
102     cam_comp_default_rects(cam);
103 
104     return (cam);
105 }
106 
107 Camera *cam_copy(Camera * cam)
108 {
109     Camera *new_cam;
110 
111     if (cam == NULL)
112         return (NULL);
113     new_cam = cam_make(cam->type, cam->transf, cam->f, cam->pixel,
114                        cam->ax, cam->ay, cam->cx, cam->cy,
115                        cam->width, cam->height);
116     new_cam->correct_func = cam->correct_func;
117     new_cam->distort_func = cam->distort_func;
118     if (cam->distort_params != NULL)
119     {
120         if (cam->copy_dist_func != NULL)
121         {
122             new_cam->distort_params = cam->copy_dist_func(cam->distort_params);
123             new_cam->copy_dist_func = cam->copy_dist_func;
124         } else
125         {
126             format("warning: distortion parameters not copied\n");
127             new_cam->correct_func = new_cam->distort_func = NULL;
128         }
129     } else                      /* no distortion now */
130         new_cam->correct_func = new_cam->distort_func = NULL;
131     return (new_cam);
132 }
133 
134 Bool    cam_scale_to_image(Camera * cam, Imrect * im)
135 {
136     int     hscale, wscale;
137     Bool    larger;
138 
139     if (cam == NULL || im == NULL)
140         return (false);
141 
142     if (cam->width == im->width && cam->height == im->height)
143         return (true);
144 
145     if (cam->width > im->width)
146     {
147         larger = true;
148         wscale = cam->width / im->width;
149         if (cam->width != wscale * im->width)
150             return (false);     /* can't scale camera */
151     } else
152     {
153         larger = false;
154         wscale = im->width / cam->width;
155         if (im->width != wscale * cam->width)
156             return (false);     /* can't scale camera */
157     }
158 
159     if (cam->height > im->height)
160     {
161         if (larger == false)
162             return (false);
163         hscale = cam->height / im->height;
164         if (hscale != wscale || cam->height != hscale * im->height)
165             return (false);     /* cant scale camera */
166     } else
167     {
168         if (larger == true)
169             return (false);
170         hscale = im->height / cam->height;
171         if (hscale != wscale || im->height != hscale * cam->height)
172             return (false);     /* cant scale camera */
173     }
174 
175     if (larger)
176     {
177         cam->width /= wscale;
178         cam->height /= wscale;
179         cam->pixel *= wscale;   /* the pixel size increases */
180         cam->cx /= wscale;
181         cam->cy /= wscale;
182     } else
183     {
184         cam->width *= wscale;
185         cam->height *= wscale;
186         cam->pixel /= wscale;   /* the pixel size decreases */
187         cam->cx *= wscale;
188         cam->cy *= wscale;
189     }
190     cam_comp_default_rects(cam);
191     return (true);
192 }
193 
194 void    cam_free(Camera * cam)
195 {
196     if (cam == NULL)
197         return;
198 
199     if (cam->transf)
200         rfree((void *) cam->transf);
201     if (cam->distort_params)
202         rfree((void *) cam->distort_params);
203 
204     rfree((void *) cam);
205 }
206 

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