Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

drawTv_proj3.c

Go to the documentation of this file.
00001 /*********
00002  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
00003  * University of Manchester, UK.  All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  * 
00008  *   . Redistributions of source code must retain the above copyright notice, 
00009  *     this list of conditions and the following disclaimer.
00010  *    
00011  *   . Redistributions in binary form must reproduce the above copyright notice,
00012  *     this list of conditions and the following disclaimer in the documentation 
00013  *     and/or other materials provided with the distribution.
00014  * 
00015  *   . Neither the name of the University of Manchester nor the names of its
00016  *     contributors may be used to endorse or promote products derived from this 
00017  *     software without specific prior written permission.
00018  * 
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  **********
00033  *
00034  * Program :    TINA
00035  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_proj3.c,v $
00036  * Date    :  $Date: 2003/10/01 16:02:47 $
00037  * Version :  $Revision: 1.2 $
00038  * CVS Id  :  $Id: drawTv_proj3.c,v 1.2 2003/10/01 16:02:47 tony Exp $
00039  *
00040  * Author  : Legacy TINA
00041  *
00042  * Notes :
00043  *
00044  *********
00045 */
00046 
00047 #include "drawTv_proj3.h"
00048 
00049 #if HAVE_CONFIG_H
00050   #include <config.h>
00051 #endif
00052 
00053 #include <math.h>
00054 #include <float.h>
00055 #include <limits.h>
00056 #include <tina/sys/sysDef.h>
00057 #include <tina/math/mathDef.h>
00058 #include <tina/math/mathPro.h>
00059 #include <tinatool/draw/draw_TvDef.h>
00060 
00063 static Ipos proj3_orth(Tv * tv, Vec3 v)
00064 {
00065     Ipos    pos = {Ipos_id};
00066     double  x, y;
00067 
00068     v = vec3_diff(v, tv->centre3);
00069     x = tv->cx + tv->scalex * vec3_dot(v, tv->ex3);
00070     y = tv->cy + tv->scaley * vec3_dot(v, tv->ey3);
00071     pos.x = ROUND(x);
00072     pos.y = ROUND(y);
00073     return (pos);
00074 }
00075 
00076 static void ray3_orth(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
00077 {
00078     double  x = (pos.x - tv->cx) / tv->scalex;
00079     double  y = (pos.y - tv->cy) / tv->scaley;
00080 
00081     *p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
00082     *v = tv->ez3;
00083 }
00084 
00085 static Vec3 backproj3_orth(Tv * tv, Ipos pos)
00086 {
00087     Vec3    p = {Vec3_id};
00088     double  x = (pos.x - tv->cx) / tv->scalex;
00089     double  y = (pos.y - tv->cy) / tv->scaley;
00090 
00091     p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
00092     return (p);
00093 }
00094 
00095 void    tv_set_proj3_orth(Tv * tv)
00096 {
00097     tv->proj3type = ORTH;
00098     tv->proj3 = proj3_orth;
00099     tv->ray3 = ray3_orth;
00100     tv->backproj3 = backproj3_orth;
00101 }
00102 
00105 static Ipos proj3_persp(Tv * tv, Vec3 v)
00106 {
00107     Ipos    pos = {Ipos_id};
00108     double  x, y;
00109 
00110     v = vec3_unit(vec3_diff(v, tv->pcentre));
00111     v = vec3_inter_line_plane(tv->pcentre, v, tv->centre3, tv->ez3);
00112     v = vec3_diff(v, tv->centre3);
00113     x = tv->cx + tv->scalex * vec3_dot(v, tv->ex3);
00114     y = tv->cy + tv->scaley * vec3_dot(v, tv->ey3);
00115     pos.x = ROUND(x);
00116     pos.y = ROUND(y);
00117     return (pos);
00118 }
00119 
00120 static void ray3_persp(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
00121 {
00122     double  x = (pos.x - tv->cx) / tv->scalex;
00123     double  y = (pos.y - tv->cy) / tv->scaley;
00124     Vec3    q = {Vec3_id};
00125 
00126     q = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
00127     *p = tv->pcentre;
00128     *v = vec3_unit(vec3_diff(q, tv->pcentre));
00129 }
00130 
00131 static Vec3 backproj3_persp(Tv * tv, Ipos pos)
00132 {
00133     Vec3    p = {Vec3_id};
00134     double  x = (pos.x - tv->cx) / tv->scalex;
00135     double  y = (pos.y - tv->cy) / tv->scaley;
00136 
00137     p = vec3_sum3(tv->centre3, vec3_times(x, tv->ex3), vec3_times(y, tv->ey3));
00138     return (p);
00139 }
00140 
00141 void    tv_set_proj3_persp(Tv * tv)
00142 {
00143     tv->proj3type = PERSP;
00144     tv->proj3 = proj3_persp;
00145     tv->ray3 = ray3_persp;
00146     tv->backproj3 = backproj3_persp;
00147 }
00148 
00151 Ipos    tv_proj3(Tv * tv, Vec3 p)
00152 {
00153     return (tv->proj3(tv, p));
00154 }
00155 
00156 void    tv_ray3(Tv * tv, Ipos pos, Vec3 * p, Vec3 * v)
00157 {
00158     tv->ray3(tv, pos, p, v);
00159 }
00160 
00161 Vec3    tv_backproj3(Tv * tv, Ipos pos)
00162 {
00163     return (tv->backproj3(tv, pos));
00164 }
00165 
00166 double  tv_dist3(Tv * tv, Vec3 p)
00167 {
00168     if (tv == NULL)
00169         return (FLT_MAX);
00170     switch (tv->proj3type)
00171     {
00172     case ORTH:
00173         return (vec3_dot(vec3_diff(p, tv->centre3), tv->ez3));
00174     case PERSP:
00175         return (vec3_dist(p, tv->pcentre));
00176     }
00177     return (FLT_MAX);
00178 }
00179 
00180 Ipos    tv_zbuff_proj3(Tv * tv, Vec3 p, int *iz)
00181 {
00182     double  z;
00183 
00184     z = (tv_dist3(tv, p) - tv->zbuff->zmin) / (tv->zbuff->zmax - tv->zbuff->zmin);
00185     if (z < 0.0 || z > 1.0)
00186         *iz = INT_MAX;
00187     else
00188         *iz = ROUND(INT_MAX * z);
00189     return (tv_proj3(tv, p));
00190 }
00191 
00194 void    tv_camera3(Tv * tv, Vec3 centre, double radius, double pscale, Vec3 aim, Vec3 down)
00195 {
00196     tv->scalex = tv->scaley = (float)(0.5 * MIN(tv->width, tv->height) / radius);
00197     tv->cx = (float)(tv->width / 2.0);
00198     tv->cy = (float)(tv->height / 2.0);
00199     tv->centre3 = centre;
00200     tv->radius3 = (float)radius;
00201     vec3_basis(aim, down, &tv->ex3, &tv->ey3, &tv->ez3);
00202     tv->pscale = (float)pscale;
00203     tv->pcentre = vec3_diff(centre, vec3_times(pscale * radius, tv->ez3));
00204 }
00205 
00206 void    tv_aim3(Tv * tv, Vec3 aim)
00207 {
00208     vec3_basis(aim, vec3_ey(), &tv->ex3, &tv->ey3, &tv->ez3);
00209 }
00210 
00211 void    tv_orient3(Tv * tv, Vec3 aim, Vec3 down)
00212 {
00213     vec3_basis(aim, down, &tv->ex3, &tv->ey3, &tv->ez3);
00214     tv->pcentre = vec3_diff(tv->centre3,
00215                        vec3_times(tv->pscale * tv->radius3, tv->ez3));
00216 }
00217 
00218 void    tv_set_axis(Tv * tv, Vec3 axis)
00219 {
00220     tv->axis = vec3_unit(axis);
00221     tv->axis_set = true;
00222 }
00223 
00224 void    tv_unset_axis(Tv * tv)
00225 {
00226     tv->axis_set = false;
00227 }
00228 
00229 double  tv_pscale(Tv * tv, double pscale)
00230 {
00231     double  oldpscale = tv->pscale;
00232 
00233     tv->pscale = (float)pscale;
00234     return (oldpscale);
00235 }
00236 
00237 void    tv_set_proj3(Tv * tv, int type)
00238 {
00239     if (tv == NULL)
00240         return;
00241 
00242     switch (type)
00243     {
00244     case ORTH:
00245         tv_set_proj3_orth(tv);
00246         break;
00247     case PERSP:
00248         tv_set_proj3_persp(tv);
00249         break;
00250     }
00251 }

Generated on Thu Nov 12 02:20:44 2009 for Tools by doxygen 1.3.6