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

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

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawPaint_shade.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: drawPaint_shade.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  : Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "drawPaint_shade.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/math/mathDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/geometry/geomDef.h>
 60 #include <tina/geometry/geomPro.h>
 61 #include <tina/image/imgGen_get.h>
 62 #include <tinatool/draw/draw_TvDef.h>
 63 #include <tinatool/draw/draw_TvPro.h>
 64 #include <tinatool/draw/draw_PaintDef.h>
 65 #include <tinatool/draw/draw_PaintPro.h>
 66 
 67 void    zbuff_image_terrain3_old(Tv * tv, Vec3 ** p, char **mask, int m, int n, Imrect * image)
 68 
 69 
 70 
 71 /* m rows and n cols */
 72 
 73 {
 74     int     i, j;
 75     int   **g;                  /* shadding model */
 76 
 77     if (tv == NULL || p == NULL)
 78         return;
 79 
 80     g = iarray_alloc(0, 0, m, n);
 81 
 82     for (i = 0; i < m; ++i)
 83         for (j = 0; j < n; ++j)
 84             if (mask == NULL || mask[i][j])
 85             {
 86                 g[i][j] = im_sub_pix(image, vec3_y(p[i][j]), vec3_x(p[i][j]));
 87                 if (g[i][j] > 255)
 88                     g[i][j] = 255;
 89                 if (g[i][j] < 0)
 90                     g[i][j] = 0;
 91             }
 92     m--;
 93     n--;
 94     for (i = 0; i < m; ++i)
 95         for (j = 0; j < n; ++j)
 96         {
 97             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
 98                                  !mask[i][j + 1] || !mask[i + 1][j]))
 99                 continue;
100 
101             tv_zbuff_interp_quad3(tv,
102                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
103                   g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]);
104         }
105 }
106 
107 void    zbuff_image_terrain3(Tv * tv, Vec3 ** p, char **mask, int m, int n, Imrect * image)
108 
109 
110 
111 /* m rows and n cols */
112 
113 {
114     int     i, j;
115 
116     if (tv == NULL || p == NULL)
117         return;
118 
119     m--;
120     n--;
121     for (i = 0; i < m; ++i)
122         for (j = 0; j < n; ++j)
123         {
124             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
125                                  !mask[i][j + 1] || !mask[i + 1][j]))
126                 continue;
127 
128             tv_zbuff_image_quad3(tv,
129                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
130                                  vec3_y(p[i][j]), vec3_y(p[i + 1][j]),
131                          vec3_y(p[i][j + 1]), vec3_y(p[i + 1][j + 1]),
132                                  vec3_x(p[i][j]), vec3_x(p[i + 1][j]),
133                          vec3_x(p[i][j + 1]), vec3_x(p[i + 1][j + 1]),
134                                  image);
135         }
136 }
137 
138 void    zbuff_shade_terrain3(Tv * tv, Vec3 ** p, char **mask, int m, int n)
139 
140 
141 
142 /* m rows and n cols */
143 {
144     int     i, j;
145     int   **g;                  /* shadding model */
146 
147     if (tv == NULL || p == NULL)
148         return;
149 
150     g = iarray_alloc(0, 0, m, n);
151 
152     for (i = 0; i < m; ++i)
153         for (j = 0; j < n; ++j)
154         {
155             Vec3    vx = {Vec3_id};
156             Vec3    vy = {Vec3_id};
157             Vec3    normal = {Vec3_id};
158 
159             if (mask != NULL && !mask[i][j])
160                 continue;
161 
162             if (i == m - 1 || (mask != NULL && !mask[i + 1][j]))
163                 vy = vec3_diff(p[i][j], p[i - 1][j]);
164             else
165                 vy = vec3_diff(p[i + 1][j], p[i][j]);
166 
167             if (j == n - 1 || (mask != NULL && !mask[i][j + 1]))
168                 vx = vec3_diff(p[i][j], p[i][j - 1]);
169             else
170                 vx = vec3_diff(p[i][j + 1], p[i][j]);
171 
172             normal = vec3_unit(vec3_cross(vx, vy));     /* surface normal at i,j */
173 
174             g[i][j] = (int)(64.0 + 191.0 * fabs(vec3_dot(normal, tv->ez3)));
175             if (g[i][j] > 255)
176                 g[i][j] = 255;
177         }
178 
179     m--;
180     n--;
181     for (i = 0; i < m; ++i)
182         for (j = 0; j < n; ++j)
183         {
184             if (mask != NULL && (!mask[i][j] || !mask[i + 1][j + 1] ||
185                                  !mask[i][j + 1] || !mask[i + 1][j]))
186                 continue;
187 
188             tv_zbuff_interp_quad3(tv,
189                    p[i][j], p[i + 1][j], p[i][j + 1], p[i + 1][j + 1],
190                   g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]);
191         }
192 }
193 
194 
195 /* A 3 vector of VEC3 */
196 void    zbuff_shade_tri3(Tv * tv, Vec3 * tri)
197 {
198     Ipos    p[3] = {{Ipos_id}, {Ipos_id}, {Ipos_id}};
199     Vec3    normal = {Vec3_id};
200     int     i, z[3];
201     double  gl, g[3];
202 
203     if (tv == NULL)
204         return;
205 
206     normal = vec3_unitcross(vec3_diff(tri[0], tri[1]), vec3_diff(tri[1], tri[2]));
207 
208     gl = 0.4 + 0.6 * fabs(vec3_dot(normal, tv->ez3));
209 
210     for (i = 0; i < 3; ++i)
211     {
212         p[i] = tv_zbuff_proj3(tv, tri[i], &z[i]);
213         g[i] = gl;
214     }
215 
216     tv_zbuff_interp_convex_poly(tv, 3, p, z, g);
217 }
218 
219 void    zbuff_shade_cone(Tv * tv, Cone * cone)
220 {
221     double  t1, t2;
222     Vec3    cone_point();
223 
224     if (cone == NULL)
225         return;
226 
227     t1 = cone->c1->conic->t1;
228     t2 = cone->c1->conic->t2;
229     tv_zbuff_surf3(tv, cone_point, (Vec3(*) ()) NULL, (void *) cone, 0.0, t1, 1.0, t2, 1, 4, 10);
230 }
231 

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