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

Linux Cross Reference
Tina5/tina-tools/tinatool/draw/drawTv_zlowl.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_zlowl.c,v $
 36  * Date    :  $Date: 2007/02/15 01:55:50 $
 37  * Version :  $Revision: 1.3 $
 38  * CVS Id  :  $Id: drawTv_zlowl.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  * low level drawing routines (usually called through tv_zbuff_draw_routines)
 44  *
 45  *********
 46 */
 47 
 48 #include "drawTv_zlowl.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <limits.h>
 56 #include <tina/sys/sysDef.h>
 57 #include <tina/sys/sysPro.h>
 58 #include <tina/math/mathDef.h>
 59 #include <tina/math/mathPro.h>
 60 #include <tina/geometry/geomDef.h>
 61 #include <tina/geometry/geomPro.h>
 62 #include <tinatool/draw/draw_TvDef.h>
 63 #include <tinatool/draw/draw_TvPro.h>
 64 #include <tina/image/imgGen_get.h>
 65 
 66 /* z-buffer draw point */
 67 Bool    tv_zbuff_point(Tv * tv, Ipos pos, int z)
 68 {
 69     Bool    flag = tv_zbuff(tv, pos, z);
 70 
 71     if (flag)
 72         tv_point(tv, pos);
 73     return (flag);
 74 }
 75 
 76 /* z-buffer draw segment of 3D-curve */
 77 void    tv_zbuff_seg3(Tv * tv, Vec3(*curve) (), void *data, double t1, double t2, Bool drawend)
 78 {
 79     Ipos    pos1 =
 80     {Ipos_id};
 81     Ipos    pos2 =
 82     {Ipos_id};
 83     int     z1, z2;
 84     int     dist;
 85 
 86     if (tv == NULL || curve == NULL)
 87         return;
 88 
 89     pos1 = tv_zbuff_proj3(tv, curve(data, t1), &z1);
 90     pos2 = tv_zbuff_proj3(tv, curve(data, t2), &z2);
 91     if ((dist = ipos_maxabs(pos1, pos2)) == 0)
 92     {
 93         if (drawend)
 94             (void) tv_zbuff_point(tv, pos1, z1);
 95     } else if (dist == 1)
 96     {
 97         (void) tv_zbuff_point(tv, pos1, z1);
 98         if (drawend)
 99             (void) tv_zbuff_point(tv, pos2, z2);
100     } else
101     {
102         double  tm = 0.5 * (t1 + t2);
103 
104         tv_zbuff_seg3(tv, curve, data, t1, tm, false);
105         tv_zbuff_seg3(tv, curve, data, tm, t2, true);
106     }
107 }
108 
109 /* z-buffer draw interpolated intensities in general polygon */
110 void    tv_zbuff_interp_general_poly(Tv * tv, int n, Ipos * p, int *z, double *g)
111 {
112     int     i, j, k;
113     int     ly = INT_MAX, uy = -INT_MAX;
114 
115     for (i = 0; i < n; ++i)
116     {
117         if (ipos_y(p[i]) < ly)
118             ly = ipos_y(p[i]);
119         if (ipos_y(p[i]) > uy)
120             uy = ipos_y(p[i]);
121     }
122 
123     for (i = ly; i <= uy; i++)
124     {
125         int     lx = INT_MAX, ux = -INT_MAX;
126         double  lg = 0.0;
127         double  ug = 0.0;
128         double  lz = 0.0;
129         double  uz = 0.0;
130         double  dz = 0.0;
131         double  dg = 0.0;
132 
133         for (j = 0; j < n; ++j)
134         {
135             k = (j + 1) % n;
136             if (ipos_y(p[j]) == i && ipos_y(p[k]) == i)
137             {
138                 if (ipos_x(p[j]) < lx)
139                 {
140                     lx = ipos_x(p[j]);
141                     lg = g[j];
142                     lz = z[j];
143                 }
144                 if (ipos_x(p[k]) < lx)
145                 {
146                     lx = ipos_x(p[k]);
147                     lg = g[k];
148                     lz = z[k];
149                 }
150                 if (ipos_x(p[j]) > ux)
151                 {
152                     ux = ipos_x(p[j]);
153                     ug = g[j];
154                     uz = z[j];
155                 }
156                 if (ipos_x(p[k]) > ux)
157                 {
158                     ux = ipos_x(p[k]);
159                     ug = g[k];
160                     uz = z[k];
161                 }
162             } else if (ipos_y(p[j]) == i)
163             {
164                 if (ipos_x(p[j]) < lx)
165                 {
166                     lx = ipos_x(p[j]);
167                     lg = g[j];
168                     lz = z[j];
169                 }
170                 if (ipos_x(p[j]) > ux)
171                 {
172                     ux = ipos_x(p[j]);
173                     ug = g[j];
174                     uz = z[j];
175                 }
176             } else if (ipos_y(p[k]) == i)
177             {
178                 if (ipos_x(p[k]) < lx)
179                 {
180                     lx = ipos_x(p[k]);
181                     lg = g[k];
182                     lz = z[k];
183                 }
184                 if (ipos_x(p[k]) > ux)
185                 {
186                     ux = ipos_x(p[k]);
187                     ug = g[k];
188                     uz = z[k];
189                 }
190             } else if (BETWEEN(i, ipos_y(p[j]), ipos_y(p[k])))
191             {
192                 double  scale;
193                 double  x_val, g_val, z_val;
194                 int     x_round;
195 
196                 scale =
197                     (double) (i - ipos_y(p[j])) / (ipos_y(p[k]) - ipos_y(p[j]));
198                 x_val = ipos_x(p[j]) + (ipos_x(p[k]) - ipos_x(p[j])) * scale;
199                 g_val = g[j] + (g[k] - g[j]) * scale;
200                 z_val = z[j] + (z[k] - z[j]) * scale;
201 
202                 x_round = ROUND(x_val);
203 
204                 if (x_round < lx)
205                 {
206                     lx = x_round;
207                     lg = g_val;
208                     lz = z_val;
209                 }
210                 if (x_round > ux)
211                 {
212                     ux = x_round;
213                     ug = g_val;
214                     uz = z_val;
215                 }
216             }
217         }
218 
219         if (ux != lx)
220         {
221             dz = (uz - lz) / (ux - lx);
222             dg = (ug - lg) / (ux - lx);
223         } else
224             dz = dg = 0.0;
225         for (j = lx; j <= ux; j++, lz += dz, lg += dg)
226         {
227             tv_color_set(tv, tv->zbuff->color(lg));
228             (void) tv_zbuff_point(tv, ipos(j, i), ROUND(lz));
229         }
230     }
231 }
232 
233 /* z-buffer draw interpolated intensities in convex polygon */
234 void    tv_zbuff_interp_convex_poly(Tv * tv, int n, Ipos * p, int *z, double *g)
235 {
236     int     i, j, k;
237     int     ly = INT_MAX, uy = -INT_MAX;
238 
239     /* cheap test for visibility; better one required */
240     for (i = 0; i < n; ++i)
241         if (tv_ipos_within(tv, p[i]))
242             break;
243     if (i == n)                 /* polygon not within tv */
244         return;
245 
246     for (i = 0; i < n; ++i)
247     {
248         if (ipos_y(p[i]) < ly)
249             ly = ipos_y(p[i]);
250         if (ipos_y(p[i]) > uy)
251             uy = ipos_y(p[i]);
252     }
253 
254     for (i = ly; i <= uy; i++)
255     {
256         int     lx = INT_MAX, ux = -INT_MAX;
257         double  lg = 0.0;
258         double  ug = 0.0;
259         double  lz = 0.0;
260         double  uz = 0.0;
261         double  dz = 0.0;
262         double  dg = 0.0;
263 
264         for (j = 0; j < n; ++j)
265         {
266             k = (j + 1) % n;
267             if (ipos_y(p[j]) == i && ipos_y(p[k]) == i)
268             {
269                 if (ipos_x(p[j]) < lx)
270                 {
271                     lx = ipos_x(p[j]);
272                     lg = g[j];
273                     lz = z[j];
274                 }
275                 if (ipos_x(p[k]) < lx)
276                 {
277                     lx = ipos_x(p[k]);
278                     lg = g[k];
279                     lz = z[k];
280                 }
281                 if (ipos_x(p[j]) > ux)
282                 {
283                     ux = ipos_x(p[j]);
284                     ug = g[j];
285                     uz = z[j];
286                 }
287                 if (ipos_x(p[k]) > ux)
288                 {
289                     ux = ipos_x(p[k]);
290                     ug = g[k];
291                     uz = z[k];
292                 }
293             } else if (ipos_y(p[j]) == i)
294             {
295                 if (ipos_x(p[j]) < lx)
296                 {
297                     lx = ipos_x(p[j]);
298                     lg = g[j];
299                     lz = z[j];
300                 }
301                 if (ipos_x(p[j]) > ux)
302                 {
303                     ux = ipos_x(p[j]);
304                     ug = g[j];
305                     uz = z[j];
306                 }
307             } else if (ipos_y(p[k]) == i)
308             {
309                 if (ipos_x(p[k]) < lx)
310                 {
311                     lx = ipos_x(p[k]);
312                     lg = g[k];
313                     lz = z[k];
314                 }
315                 if (ipos_x(p[k]) > ux)
316                 {
317                     ux = ipos_x(p[k]);
318                     ug = g[k];
319                     uz = z[k];
320                 }
321             } else if (BETWEEN(i, ipos_y(p[j]), ipos_y(p[k])))
322             {
323                 double  scale;
324                 double  x_val, g_val, z_val;
325                 int     x_round;
326 
327                 scale = (double) (i - ipos_y(p[j])) / (ipos_y(p[k]) - ipos_y(p[j]));
328                 x_val = ipos_x(p[j]) + (ipos_x(p[k]) - ipos_x(p[j])) * scale;
329                 g_val = g[j] + (g[k] - g[j]) * scale;
330                 z_val = z[j] + (z[k] - z[j]) * scale;
331 
332                 x_round = ROUND(x_val);
333 
334                 if (x_round < lx)
335                 {
336                     lx = x_round;
337                     lg = g_val;
338                     lz = z_val;
339                 }
340                 if (x_round > ux)
341                 {
342                     ux = x_round;
343                     ug = g_val;
344                     uz = z_val;
345                 }
346             }
347         }
348 
349         if (ux != lx)
350         {
351             dz = (uz - lz) / (ux - lx);
352             dg = (ug - lg) / (ux - lx);
353         } else
354             dz = dg = 0.0;
355         for (j = lx; j <= ux; j++, lz += dz, lg += dg)
356         {
357             tv_color_set(tv, tv->zbuff->color(lg));
358             (void) tv_zbuff_point(tv, ipos(j, i), ROUND(lz));
359         }
360     }
361 }
362 
363 /* z-buffer draw interpolated image intensities in convex polygon */
364 void    tv_zbuff_image_convex_poly(Tv * tv, int n, Ipos * p, int *z, float *r, float *c, Imrect * im)
365 {
366     int     i, j, k;
367     int     ly = INT_MAX, uy = -INT_MAX;
368 
369     /* cheap test for visibility; better one required */
370     for (i = 0; i < n; ++i)
371         if (tv_ipos_within(tv, p[i]))
372             break;
373     if (i == n)                 /* polygon not within tv */
374         return;
375 
376     for (i = 0; i < n; ++i)
377     {
378         if (ipos_y(p[i]) < ly)
379             ly = ipos_y(p[i]);
380         if (ipos_y(p[i]) > uy)
381             uy = ipos_y(p[i]);
382     }
383 
384     for (i = ly; i <= uy; i++)
385     {
386         int     lx = INT_MAX, ux = -INT_MAX;
387         double  lr = 0.0;
388         double  ur = 0.0;
389         double  lc = 0.0;
390         double  uc = 0.0;
391         double  lz = 0.0;
392         double  uz = 0.0;
393         double  dz = 0.0;
394         double  dr = 0.0;
395         double  dc = 0.0;
396 
397         for (j = 0; j < n; ++j)
398         {
399             k = (j + 1) % n;
400             if (ipos_y(p[j]) == i && ipos_y(p[k]) == i)
401             {
402                 if (ipos_x(p[j]) < lx)
403                 {
404                     lx = ipos_x(p[j]);
405                     lr = r[j];
406                     lc = c[j];
407                     lz = z[j];
408                 }
409                 if (ipos_x(p[k]) < lx)
410                 {
411                     lx = ipos_x(p[k]);
412                     lr = r[k];
413                     lc = c[k];
414                     lz = z[k];
415                 }
416                 if (ipos_x(p[j]) > ux)
417                 {
418                     ux = ipos_x(p[j]);
419                     ur = r[j];
420                     uc = c[j];
421                     uz = z[j];
422                 }
423                 if (ipos_x(p[k]) > ux)
424                 {
425                     ux = ipos_x(p[k]);
426                     ur = r[k];
427                     uc = c[k];
428                     uz = z[k];
429                 }
430             } else if (ipos_y(p[j]) == i)
431             {
432                 if (ipos_x(p[j]) < lx)
433                 {
434                     lx = ipos_x(p[j]);
435                     lr = r[j];
436                     lc = c[j];
437                     lz = z[j];
438                 }
439                 if (ipos_x(p[j]) > ux)
440                 {
441                     ux = ipos_x(p[j]);
442                     ur = r[j];
443                     uc = c[j];
444                     uz = z[j];
445                 }
446             } else if (ipos_y(p[k]) == i)
447             {
448                 if (ipos_x(p[k]) < lx)
449                 {
450                     lx = ipos_x(p[k]);
451                     lr = r[k];
452                     lc = c[k];
453                     lz = z[k];
454                 }
455                 if (ipos_x(p[k]) > ux)
456                 {
457                     ux = ipos_x(p[k]);
458                     ur = r[k];
459                     uc = c[k];
460                     uz = z[k];
461                 }
462             } else if (BETWEEN(i, ipos_y(p[j]), ipos_y(p[k])))
463             {
464                 double  scale;
465                 double  x_val, r_val, c_val, z_val;
466                 int     x_round;
467 
468                 scale = (double) (i - ipos_y(p[j])) / (ipos_y(p[k]) - ipos_y(p[j]));
469                 x_val = ipos_x(p[j]) + (ipos_x(p[k]) - ipos_x(p[j])) * scale;
470                 r_val = r[j] + (r[k] - r[j]) * scale;
471                 c_val = c[j] + (c[k] - c[j]) * scale;
472                 z_val = z[j] + (z[k] - z[j]) * scale;
473 
474                 x_round = ROUND(x_val);
475 
476                 if (x_round < lx)
477                 {
478                     lx = x_round;
479                     lr = r_val;
480                     lc = c_val;
481                     lz = z_val;
482                 }
483                 if (x_round > ux)
484                 {
485                     ux = x_round;
486                     ur = r_val;
487                     uc = c_val;
488                     uz = z_val;
489                 }
490             }
491         }
492 
493         if (ux != lx)
494         {
495             dz = (uz - lz) / (ux - lx);
496             dr = (ur - lr) / (ux - lx);
497             dc = (uc - lc) / (ux - lx);
498         } else
499             dz = dr = dc = 0.0;
500         for (j = lx; j <= ux; j++, lz += dz, lr += dr, lc += dc)
501         {
502             int     gl = im_sub_pix(im, lr, lc);
503 
504             if (gl > 255)
505                 gl = 255;
506             if (gl < 0)
507                 gl = 0;
508             tv_color_set(tv, gl);
509             (void) tv_zbuff_point(tv, ipos(j, i), ROUND(lz));
510         }
511     }
512 }
513 
514 /* z-buffer draw interpolated intensities in convex quadrilateral */
515 void    tv_zbuff_interp_quad(Tv * tv, Ipos p00, Ipos p10, Ipos p01, Ipos p11, int z00, int z10, int z01, int z11, double g00, double g10, double g01, double g11)
516 {
517     Ipos    p[4] =
518     {
519         {Ipos_id},
520         {Ipos_id},
521         {Ipos_id},
522     {Ipos_id}};
523     int     z[4];
524     double  g[4];
525 
526     p[0] = p00;
527     p[1] = p10;
528     p[3] = p01;
529     p[2] = p11;
530     z[0] = z00;
531     z[1] = z10;
532     z[3] = z01;
533     z[2] = z11;
534     g[0] = g00;
535     g[1] = g10;
536     g[3] = g01;
537     g[2] = g11;
538 
539     tv_zbuff_interp_convex_poly(tv, 4, p, z, g);
540 }
541 
542 /* recursive patch drawing code */
543 /* was static - SMC 28/9/93 */
544 Tv_patch patch_make(double u1, double v1, double u2, double v2)
545 {
546     int     i, j;
547     Tv_patch patch =
548     {Tv_patch_id};
549 
550     patch.u[0] = u1;
551     patch.u[1] = 0.5 * (u1 + u2);
552     patch.u[2] = u2;
553     patch.v[0] = v1;
554     patch.v[1] = 0.5 * (v1 + v2);
555     patch.v[2] = v2;
556     for (i = 0; i < 3; i++)
557         for (j = 0; j < 3; j++)
558         {
559             patch.flag[i][j] = 0;
560             patch.pos[i][j] = ipos_zero();      /* SMC 28/9/93 */
561         }
562     return (patch);
563 }
564 
565 static Bool drawdiscontinuities = true;
566 void    tv_drawdiscontinuities_set(Tv * tv, Bool flag)
567 {
568     drawdiscontinuities = flag;
569 }
570 
571 /* recusively divide patch (up to limit ni calls) until patch edges and
572  * grey levels are well approximated (called by tv_zbuff_patch3) */
573 static void tv_zbuff_patch(Tv * tv, Vec3(*surf) (), Vec3(*normal) (), void *data, Tv_patch patch, int ni)
574 {
575     Ipos   *pos[3];
576     double  u[3], v[3];
577     double *g[3];
578     int    *z[3], *flag[3];
579     Bool    splitu = true, splitv = true, back = tv->zbuff->backdraw;
580     double  egray = 0.01;
581     int     epos = 2, i, j;
582     int     d1, d2, d3, d4;
583 
584     for (i = 0; i < 3; i++)
585     {
586         pos[i] = &patch.pos[i][0];
587         u[i] = patch.u[i];
588         v[i] = patch.v[i];
589         flag[i] = &patch.flag[i][0];
590         z[i] = &patch.z[i][0];
591         g[i] = &patch.g[i][0];
592     }
593 
594     if (flag[0][0] &&
595         !(IN_TV(tv, pos[0][0]) || IN_TV(tv, pos[2][0]) ||
596           IN_TV(tv, pos[0][2]) || IN_TV(tv, pos[2][2])))
597         return;
598 
599     for (i = 0; i < 3; i++)
600         for (j = 0; j < 3; j++)
601             if (!flag[i][j])
602             {
603                 Vec3    x =
604                 {Vec3_id};
605                 Vec3    n =
606                 {Vec3_id};
607 
608                 x = surf(data, u[i], v[j]);
609                 if (normal == NULL)
610                     n = interp_normal(surf, data, u[i], v[j], x);
611                 else
612                     n = normal(data, u[i], v[j]);
613                 pos[i][j] = tv_zbuff_proj3(tv, x, &z[i][j]);
614                 g[i][j] = tv->zbuff->shade(tv, n, x);
615             }
616     /** facing away **/
617     if (!back && g[0][0] < 0 && g[0][1] < 0 && g[0][2] < 0 &&
618         g[1][0] < 0 && g[1][1] < 0 && g[1][2] < 0 &&
619         g[2][0] < 0 && g[2][1] < 0 && g[2][2])
620         return;
621 
622     for (i = 0; i < 3; i++)
623         for (j = 0; j < 3; j++)
624             g[i][j] = fabs(g[i][j]);
625 
626 
627     d1 = ipos_manhattan(pos[0][0], pos[2][0]);
628     d2 = ipos_manhattan(pos[0][2], pos[2][2]);
629     d3 = ipos_manhattan(pos[0][0], pos[0][2]);
630     d4 = ipos_manhattan(pos[2][0], pos[2][2]);
631     if (d1 < 4 && d2 < 4)
632         splitu = false;
633     if (d3 < 4 && d4 < 4)
634         splitv = false;
635 
636     if (splitu &&
637         ipos_maxabs(pos[1][0], ipos_midpoint(pos[0][0], pos[2][0])) < epos &&
638         fabs(g[1][0] - 0.5 * (g[0][0] + g[2][0])) < egray &&
639         ipos_maxabs(pos[1][2], ipos_midpoint(pos[0][2], pos[2][2])) < epos &&
640         fabs(g[1][2] - 0.5 * (g[0][2] + g[2][2])) < egray)
641         splitu = false;
642 
643     if (splitv &&
644         ipos_maxabs(pos[0][1], ipos_midpoint(pos[0][0], pos[0][2])) < epos &&
645         fabs(g[0][1] - 0.5 * (g[0][0] + g[0][2])) < egray &&
646         ipos_maxabs(pos[2][1], ipos_midpoint(pos[2][0], pos[2][2])) < epos &&
647         fabs(g[2][1] - 0.5 * (g[2][0] + g[2][2])) < egray)
648         splitv = false;
649 
650     if (ni <= 0)
651     {
652         if (drawdiscontinuities == false)
653             return;
654         else
655             splitu = splitv = false;
656     }
657     if (splitu && splitv)
658     {
659         for (i = 0; i < 2; i++)
660             for (j = 0; j < 2; j++)
661             {
662                 Tv_patch q = {Tv_patch_id};
663                 int     oi, oj;
664 
665                 q = patch_make(u[i], v[j], u[i + 1], v[j + 1]);
666                 for (oi = 0; oi < 2; oi++)
667                 {
668                     int     oi2 = 2 * oi;
669 
670                     for (oj = 0; oj < 2; oj++)
671                     {
672                         int     oj2 = 2 * oj;
673 
674                         q.flag[oi2][oj2] = 1;
675                         q.pos[oi2][oj2] = pos[i + oi][j + oj];
676                         q.z[oi2][oj2] = z[i + oi][j + oj];
677                         q.g[oi2][oj2] = g[i + oi][j + oj];
678                     }
679                 }
680                 tv_zbuff_patch(tv, surf, normal, data, q, ni - 1);
681             }
682     } else if (splitu)
683     {
684         for (i = 0; i < 2; i++)
685         {
686             Tv_patch q =
687             {Tv_patch_id};
688             int     oi, oj;
689 
690             q = patch_make(u[i], v[0], u[i + 1], v[2]);
691             for (oi = 0; oi < 2; oi++)
692             {
693                 int     oi2 = 2 * oi;
694 
695                 for (oj = 0; oj < 3; oj++)
696                 {
697                     q.flag[oi2][oj] = 1;
698                     q.pos[oi2][oj] = pos[i + oi][oj];
699                     q.z[oi2][oj] = z[i + oi][oj];
700                     q.g[oi2][oj] = g[i + oi][oj];
701                 }
702             }
703             tv_zbuff_patch(tv, surf, normal, data, q, ni - 1);
704         }
705     } else if (splitv)
706     {
707         for (j = 0; j < 2; j++)
708         {
709             Tv_patch q =
710             {Tv_patch_id};
711             int     oi, oj;
712 
713             q = patch_make(u[0], v[j], u[2], v[j + 1]);
714             for (oi = 0; oi < 3; oi++)
715             {
716                 for (oj = 0; oj < 2; oj++)
717                 {
718                     int     oj2 = 2 * oj;
719 
720                     q.flag[oi][oj2] = 1;
721                     q.pos[oi][oj2] = pos[oi][j + oj];
722                     q.z[oi][oj2] = z[oi][j + oj];
723                     q.g[oi][oj2] = g[oi][j + oj];
724                 }
725             }
726             tv_zbuff_patch(tv, surf, normal, data, q, ni - 1);
727         }
728     } else
729     {
730         for (i = 0; i < 2; i++)
731             for (j = 0; j < 2; j++)
732                 tv_zbuff_interp_quad(tv,
733                                      pos[i][j], pos[i + 1][j], pos[i][j + 1], pos[i + 1][j + 1],
734                    z[i][j], z[i + 1][j], z[i][j + 1], z[i + 1][j + 1],
735                   g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]);
736     }
737 }
738 
739 /* z-buffer draw  patch (up to limit ni sub-divisions) surf(u, v)
740  * returns surface point norm(u, v) returns surface normal */
741 void    tv_zbuff_patch3(Tv * tv, Vec3(*surf) (), Vec3(*normal) (), void *data, double u1, double v1, double u2, double v2, int ni)
742 {
743     Tv_patch patch =
744     {Tv_patch_id};
745 
746     if (tv == NULL || surf == NULL)
747         return;
748     patch = patch_make(u1, v1, u2, v2);
749     tv_zbuff_patch(tv, surf, normal, data, patch, ni);
750 }
751 

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