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

Linux Cross Reference
TINA5/tina-libs/tina/geometry/geomCam_dstrt.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_dstrt.c,v $
 23  * Date    :  $Date: 2002/12/09 11:51:23 $
 24  * Version :  $Revision: 1.1.1.1 $
 25  * CVS Id  :  $Id: geomCam_dstrt.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  *
 31  *********
 32 */
 33 
 34 #include "geomCam_dstrt.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/image/imgDef.h>
 46 #include <tina/geometry/geomDef.h>
 47 #include <tina/geometry/geom_CamDef.h>
 48 #include <tina/geometry/geom_EdgeDef.h>
 49 #include <tina/geometry/geom_EdgePro.h>
 50 #include <tina/geometry/geomCam_rect.h>
 51 
 52 
 53 Vec2    radial_distort(Vec2 w, double *a)
 54 {
 55     Vec2    v = {Vec2_id};
 56     double  radsq;
 57 
 58     radsq = w.el[0] * w.el[0] + w.el[1] * w.el[1];
 59     v.el[0] = (float)((1.0 - a[1] * radsq) * w.el[0]);
 60     v.el[1] = (float)((1.0 - a[1] * radsq) * w.el[1]);
 61     return (v);
 62 }
 63 
 64 Vec2    radial_correct(Vec2 w, double *a)
 65 {
 66     Vec2    v = {Vec2_id};
 67     double  radsq;
 68 
 69     v.el[0] = w.el[0];
 70     v.el[1] = w.el[1];
 71 
 72     radsq = v.el[0] * v.el[0] + v.el[1] * v.el[1];
 73     v.el[0] = (float)((1.0 + a[1] * radsq) * w.el[0]);
 74     v.el[1] = (float)((1.0 + a[1] * radsq) * w.el[1]);
 75 
 76     radsq = v.el[0] * v.el[0] + v.el[1] * v.el[1];
 77     v.el[0] = (float)((1.0 + a[1] * radsq) * w.el[0]);
 78     v.el[1] = (float)((1.0 + a[1] * radsq) * w.el[1]);
 79     return (v);
 80 }
 81 
 82 Vec2    cam_correct(Vec2 u, Camera * cam)
 83 
 84 
 85 
 86 /* this routine cannot be called with a NULL cam pointer */
 87 {
 88     if ((cam->correct_func != NULL) && (cam->distort_params != NULL))
 89     {
 90         /* change from image to unit camera coordinates */
 91         u = rectify_pos(cam->im_to_cam, u);
 92         /** allow for optical distortion **/
 93         u = cam->correct_func(u, cam->distort_params);
 94         /** change back to image coordinates **/
 95         u = rectify_pos(cam->cam_to_im, u);
 96     }
 97     return (u);
 98 }
 99 
100 void   *cam_distort_copy(double *b)
101 {
102     int     i, n;
103     double *a;
104 
105     n = (int) (b[0] + 0.5);
106     a = (double *) ralloc((unsigned) (sizeof(double) * (n + 1)));
107     for (i = 0; i < n + 1; i++)
108         a[i] = b[i];
109     return(a);
110 }
111 
112 /* ARGSUSED quieten lint */
113 void    edge_apply_corr(Edgel * edge, int type, Camera * cam)
114 
115 /* unused */
116 
117 {
118     if (edge == NULL || cam == NULL || cam->correct_func == NULL || cam->distort_params == NULL)
119         return;
120     edge->type &= EDGE_SET_CORR_MASK;
121     edge->type |= EDGE_CORRECTED;
122     edge->pos = cam_correct(edge->pos, cam);
123 }
124 
125 /* ARGSUSED quieten lint */
126 void    edge_add_corr_prop(Edgel * edge, int type, Camera * cam)
127 {
128     Vec2   *r;
129 
130     if (edge == NULL || cam == NULL || cam->correct_func == NULL || cam->distort_params == NULL)
131         return;
132     r = vec2_alloc();
133 
134     *r = cam_correct(edge->pos, cam);
135     edge->props = proplist_addifnp(edge->props, (void *) r, CORRPOS, vec2_free, true);
136 }
137 
138 void    er_add_corrpos_prop(Imrect * er, Camera * cam)
139 {
140     er_apply_to_all_edges(er, edge_add_corr_prop, (void *) cam);
141 }
142 
143 void    er_correct(Imrect * er, Camera * cam)
144 {
145     er_apply_to_all_edges(er, edge_apply_corr, (void *) cam);
146 }
147 

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