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

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

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_proj3.c,v $
 36  * Date    :  $Date: 2003/10/01 16:02:47 $
 37  * Version :  $Revision: 1.2 $
 38  * CVS Id  :  $Id: drawTv_proj3.c,v 1.2 2003/10/01 16:02:47 tony Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  *
 44  *********
 45 */
 46 
 47 #include "drawTv_proj3.h"
 48 
 49 #if HAVE_CONFIG_H
 50   #include <config.h>
 51 #endif
 52 
 53 #include <math.h>
 54 #include <float.h>
 55 #include <limits.h>
 56 #include <tina/sys/sysDef.h>
 57 #include <tina/math/mathDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tinatool/draw/draw_TvDef.h>
 60 
 61 /**orthographic projection**/
 62 
 63 static Ipos proj3_orth(Tv * tv, Vec3 v)
 64 {
 65     Ipos    pos = {Ipos_id};
 66     double  x, y;
 67 
 68     v = vec3_diff(v, tv->centre3);
 69     x = tv->cx + tv->scalex * vec3_dot(v, tv->ex3);
 70     y = tv->cy + tv->scaley * vec3_dot(v, tv->ey3);
 71     pos.x = ROUND(x);
 72     pos.y = ROUND(y);
 73     return (pos);
 74 }
 75 
 76 static void ray3_orth(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
 77 {
 78     double  x = (pos.x - tv->cx) / tv->scalex;
 79     double  y = (pos.y - tv->cy) / tv->scaley;
 80 
 81     *p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
 82     *v = tv->ez3;
 83 }
 84 
 85 static Vec3 backproj3_orth(Tv * tv, Ipos pos)
 86 {
 87     Vec3    p = {Vec3_id};
 88     double  x = (pos.x - tv->cx) / tv->scalex;
 89     double  y = (pos.y - tv->cy) / tv->scaley;
 90 
 91     p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
 92     return (p);
 93 }
 94 
 95 void    tv_set_proj3_orth(Tv * tv)
 96 {
 97     tv->proj3type = ORTH;
 98     tv->proj3 = proj3_orth;
 99     tv->ray3 = ray3_orth;
100     tv->backproj3 = backproj3_orth;
101 }
102 
103 /**perspective projection**/
104 
105 static Ipos proj3_persp(Tv * tv, Vec3 v)
106 {
107     Ipos    pos = {Ipos_id};
108     double  x, y;
109 
110     v = vec3_unit(vec3_diff(v, tv->pcentre));
111     v = vec3_inter_line_plane(tv->pcentre, v, tv->centre3, tv->ez3);
112     v = vec3_diff(v, tv->centre3);
113     x = tv->cx + tv->scalex * vec3_dot(v, tv->ex3);
114     y = tv->cy + tv->scaley * vec3_dot(v, tv->ey3);
115     pos.x = ROUND(x);
116     pos.y = ROUND(y);
117     return (pos);
118 }
119 
120 static void ray3_persp(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
121 {
122     double  x = (pos.x - tv->cx) / tv->scalex;
123     double  y = (pos.y - tv->cy) / tv->scaley;
124     Vec3    q = {Vec3_id};
125 
126     q = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
127     *p = tv->pcentre;
128     *v = vec3_unit(vec3_diff(q, tv->pcentre));
129 }
130 
131 static Vec3 backproj3_persp(Tv * tv, Ipos pos)
132 {
133     Vec3    p = {Vec3_id};
134     double  x = (pos.x - tv->cx) / tv->scalex;
135     double  y = (pos.y - tv->cy) / tv->scaley;
136 
137     p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
138     return (p);
139 }
140 
141 void    tv_set_proj3_persp(Tv * tv)
142 {
143     tv->proj3type = PERSP;
144     tv->proj3 = proj3_persp;
145     tv->ray3 = ray3_persp;
146     tv->backproj3 = backproj3_persp;
147 }
148 
149 /**generic 3D projection**/
150 
151 Ipos    tv_proj3(Tv * tv, Vec3 p)
152 {
153     return (tv->proj3(tv, p));
154 }
155 
156 void    tv_ray3(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
157 {
158     tv->ray3(tv, pos, p, v);
159 }
160 
161 Vec3    tv_backproj3(Tv * tv, Ipos pos)
162 {
163     return (tv->backproj3(tv, pos));
164 }
165 
166 double  tv_dist3(Tv * tv, Vec3 p)
167 {
168     if (tv == NULL)
169         return (FLT_MAX);
170     switch (tv->proj3type)
171     {
172     case ORTH:
173         return (vec3_dot(vec3_diff(p, tv->centre3), tv->ez3));
174     case PERSP:
175         return (vec3_dist(p, tv->pcentre));
176     }
177     return (FLT_MAX);
178 }
179 
180 Ipos    tv_zbuff_proj3(Tv * tv, Vec3 p, int *iz)
181 {
182     double  z;
183 
184     z = (tv_dist3(tv, p) - tv->zbuff->zmin) / (tv->zbuff->zmax - tv->zbuff->zmin);
185     if (z < 0.0 || z > 1.0)
186         *iz = INT_MAX;
187     else
188         *iz = ROUND(INT_MAX * z);
189     return (tv_proj3(tv, p));
190 }
191 
192 /**setting down and changing the 3D camera**/
193 
194 void    tv_camera3(Tv * tv, Vec3 centre, double radius, double pscale, Vec3 aim, Vec3 down)
195 {
196     tv->scalex = tv->scaley = (float)(0.5 * MIN(tv->width, tv->height) / radius);
197     tv->cx = (float)(tv->width / 2.0);
198     tv->cy = (float)(tv->height / 2.0);
199     tv->centre3 = centre;
200     tv->radius3 = (float)radius;
201     vec3_basis(aim, down, &tv->ex3, &tv->ey3, &tv->ez3);
202     tv->pscale = (float)pscale;
203     tv->pcentre = vec3_diff(centre, vec3_times(pscale * radius, tv->ez3));
204 }
205 
206 void    tv_aim3(Tv * tv, Vec3 aim)
207 {
208     vec3_basis(aim, vec3_ey(), &tv->ex3, &tv->ey3, &tv->ez3);
209 }
210 
211 void    tv_orient3(Tv * tv, Vec3 aim, Vec3 down)
212 {
213     vec3_basis(aim, down, &tv->ex3, &tv->ey3, &tv->ez3);
214     tv->pcentre = vec3_diff(tv->centre3,
215                        vec3_times(tv->pscale * tv->radius3, tv->ez3));
216 }
217 
218 void    tv_set_axis(Tv * tv, Vec3 axis)
219 {
220     tv->axis = vec3_unit(axis);
221     tv->axis_set = true;
222 }
223 
224 void    tv_unset_axis(Tv * tv)
225 {
226     tv->axis_set = false;
227 }
228 
229 double  tv_pscale(Tv * tv, double pscale)
230 {
231     double  oldpscale = tv->pscale;
232 
233     tv->pscale = (float)pscale;
234     return (oldpscale);
235 }
236 
237 void    tv_set_proj3(Tv * tv, int type)
238 {
239     if (tv == NULL)
240         return;
241 
242     switch (type)
243     {
244     case ORTH:
245         tv_set_proj3_orth(tv);
246         break;
247     case PERSP:
248         tv_set_proj3_persp(tv);
249         break;
250     }
251 }
252 

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