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_par_proj.c,v $
23 * Date : $Date: 2005/01/09 17:49:25 $
24 * Version : $Revision: 1.3 $
25 * CVS Id : $Id: geomCam_par_proj.c,v 1.3 2005/01/09 17:49:25 paul Exp $
26 *
27 * Author : Legacy TINA
28 *
29 * Notes :
30 *
31 * module to project from parallel camera disparity coords to word
32 * coords and visa versa
33 *
34 * f is focal length of parallel camera in pixel units I is inter-ocular
35 * separation in units of the word coord
36 *
37 *********
38 */
39
40 #include "geomCam_par_proj.h"
41
42 #if HAVE_CONFIG_H
43 #include <config.h>
44 #endif
45
46 #include <math.h>
47 #include <tina/sys/sysDef.h>
48 #include <tina/sys/sysPro.h>
49 #include <tina/math/mathDef.h>
50 #include <tina/math/mathPro.h>
51 #include <tina/geometry/geomDef.h>
52 #include <tina/geometry/geom_LineDef.h>
53 #include <tina/geometry/geom_LinePro.h>
54 #include <tina/geometry/geom_PlaneDef.h>
55
56
57 static float f = (float)1.0, I = (float)1.0; /* static data! */
58
59 void set_par_proj(double fnew, double Inew)
60 {
61 f = (float)fnew;
62 I = (float)Inew;
63 }
64
65 void par_proj_set(double fnew, double Inew)
66 {
67 f = (float)fnew;
68 I = (float)Inew;
69 }
70
71 void par_proj_get(float *fp, float *Ip)
72 {
73 *fp = f;
74 *Ip = I;
75 }
76
77 void par_proj_ray(Vec2 u, Vec3 * p, Vec3 * v)
78 {
79 *p = vec3_zero(); /* the origin of parallel coords */
80
81 *v = vec3_of_vec2(u);
82 vec3_z(*v) = f;
83 *v = vec3_unit(*v);
84 }
85
86 Vec3 vec3_par_proj_3d(Vec3 p)
87 {
88 float proj = -I / vec3_z(p);
89
90 vec3_z(p) = f;
91 return (vec3_times(proj, p));
92 }
93
94 Vec3 vec3_par_proj_disp(Vec3 p)
95 {
96 float proj = f / vec3_z(p);
97
98 vec3_z(p) = -I;
99 return (vec3_times(proj, p));
100 }
101
102 void vec3_pp3d_inplace(Vec3 * p)
103 {
104 float proj;
105
106 if (p == NULL)
107 return;
108
109 proj = -I / vec3_z(*p);
110 vec3_z(*p) = f;
111 *p = vec3_times(proj, *p);
112 }
113
114 void vec3_ppdisp_inplace(Vec3 * p)
115 {
116 float proj;
117
118 if (p == NULL)
119 return;
120
121 proj = f / vec3_z(*p);
122 vec3_z(*p) = -I;
123 *p = vec3_times(proj, *p);
124 }
125
126 void line3_par_proj_3d(Line3 * line)
127 {
128 if (line == NULL)
129 return;
130
131 line->p1 = vec3_par_proj_3d(line->p1);
132 line->p2 = vec3_par_proj_3d(line->p2);
133 line3_remake(line, THREEDIM);
134 }
135
136 void line3_par_proj_disp(Line3 * line)
137 {
138 if (line == NULL)
139 return;
140
141 line->p1 = vec3_par_proj_disp(line->p1);
142 line->p2 = vec3_par_proj_disp(line->p2);
143 line3_remake((Line3 *) line, DISPARITY);
144 }
145
146 void plane_par_proj_3d(Plane * plane)
147 {
148 float D; /* PX + QY + RZ = D disparity coords */
149 float d; /* px + qy + rz = d world coords */
150 Vec3 n = {Vec3_id};
151 float mag;
152
153 if (plane == NULL)
154 return;
155
156 n = plane->n;
157
158 /* first convert plane to algerbraic form n.x = n.p */
159 D = (float)vec3_dot(plane->p, plane->n); /* |closest approach to origin| */
160
161 /* derive 3D algebra from disp algebra Px + Qy - Dz/f = RI */
162 d = vec3_z(n) * I;
163 vec3_z(n) = -D / f;
164
165 mag = (float)vec3_mod(n);
166 plane->n = vec3_times(1 / mag, n); /* make unit vector */
167 plane->p = vec3_times(d / mag, plane->n); /* point closest to
168 * origin */
169 plane->type = THREEDIM;
170 }
171
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.