ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/tmesh.c
Revision: 2.1
Committed: Wed Jun 22 12:35:23 1994 UTC (30 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 2.1 /* Copyright (c) 1994 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Compute and print barycentric coordinates for triangle meshes
9     */
10    
11     #include <stdio.h>
12    
13     #include "fvect.h"
14    
15     #include "tmesh.h"
16    
17     #define ABS(x) ((x) >= 0 ? (x) : -(x))
18    
19    
20     int
21     comp_baryc(bcm, v1, v2, v3) /* compute barycentric vectors */
22     register BARYCCM *bcm;
23     FLOAT *v1, *v2, *v3;
24     {
25     FLOAT *vt;
26     FVECT va, vab, vcb;
27     double d;
28     int ax0, ax1;
29     register int i, j;
30     /* compute major axis */
31     for (i = 0; i < 3; i++) {
32     vab[i] = v1[i] - v2[i];
33     vcb[i] = v3[i] - v2[i];
34     }
35     fcross(va, vab, vcb);
36     bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1;
37     bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2;
38     ax0 = (bcm->ax + 1) % 3;
39     ax1 = (bcm->ax + 2) % 3;
40     for (j = 0; j < 2; j++) {
41     vab[0] = v1[ax0] - v2[ax0];
42     vcb[0] = v3[ax0] - v2[ax0];
43     vab[1] = v1[ax1] - v2[ax1];
44     vcb[1] = v3[ax1] - v2[ax1];
45     d = vcb[0]*vcb[0] + vcb[1]*vcb[1];
46     if (d <= FTINY)
47     return(-1);
48     d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d;
49     va[0] = vab[0] - vcb[0]*d;
50     va[1] = vab[1] - vcb[1]*d;
51     d = va[0]*va[0] + va[1]*va[1];
52     if (d <= FTINY)
53     return(-1);
54     bcm->tm[j][0] = va[0] /= d;
55     bcm->tm[j][1] = va[1] /= d;
56     bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]);
57     /* rotate vertices */
58     vt = v1;
59     v1 = v2;
60     v2 = v3;
61     v3 = vt;
62     }
63     return(0);
64     }
65    
66    
67     put_baryc(bcm, com, n) /* put barycentric coord. vectors */
68     register BARYCCM *bcm;
69     register FLOAT com[][3];
70     int n;
71     {
72     double a, b;
73     register int i, j;
74    
75     printf("%d\t%d\n", 1+3*n, bcm->ax);
76     for (i = 0; i < n; i++) {
77     a = com[i][0] - com[i][2];
78     b = com[i][1] - com[i][2];
79     printf("%14.8f %14.8f %14.8f\n",
80     bcm->tm[0][0]*a + bcm->tm[1][0]*b,
81     bcm->tm[0][1]*a + bcm->tm[1][1]*b,
82     bcm->tm[0][2]*a + bcm->tm[1][2]*b + com[i][2]);
83     }
84     }