ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/tmesh.c
Revision: 2.3
Committed: Sat Feb 22 02:07:23 2003 UTC (21 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +3 -6 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.3 static const char RCSid[] = "$Id$";
3 greg 2.1 #endif
4     /*
5     * Compute and print barycentric coordinates for triangle meshes
6     */
7    
8     #include <stdio.h>
9    
10     #include "fvect.h"
11    
12     #include "tmesh.h"
13    
14     #define ABS(x) ((x) >= 0 ? (x) : -(x))
15    
16    
17     int
18 greg 2.2 flat_tri(v1, v2, v3, n1, n2, n3) /* determine if triangle is flat */
19     FVECT v1, v2, v3, n1, n2, n3;
20     {
21     double d1, d2, d3;
22     FVECT vt1, vt2, vn;
23     /* compute default normal */
24     vt1[0] = v2[0] - v1[0]; vt1[1] = v2[1] - v1[1]; vt1[2] = v2[2] - v1[2];
25     vt2[0] = v3[0] - v2[0]; vt2[1] = v3[1] - v2[1]; vt2[2] = v3[2] - v2[2];
26     fcross(vn, vt1, vt2);
27     if (normalize(vn) == 0.0)
28     return(DEGEN);
29     /* compare to supplied normals */
30     d1 = DOT(vn, n1); d2 = DOT(vn, n2); d3 = DOT(vn, n3);
31     if (d1 < 0 && d2 < 0 && d3 < 0) {
32     if (d1 > -COSTOL || d2 > -COSTOL || d3 > -COSTOL)
33     return(RVBENT);
34     return(RVFLAT);
35     }
36     if (d1 < COSTOL || d2 < COSTOL || d3 < COSTOL)
37     return(ISBENT);
38     return(ISFLAT);
39     }
40    
41    
42     int
43 greg 2.1 comp_baryc(bcm, v1, v2, v3) /* compute barycentric vectors */
44     register BARYCCM *bcm;
45     FLOAT *v1, *v2, *v3;
46     {
47     FLOAT *vt;
48     FVECT va, vab, vcb;
49     double d;
50     int ax0, ax1;
51     register int i, j;
52     /* compute major axis */
53     for (i = 0; i < 3; i++) {
54     vab[i] = v1[i] - v2[i];
55     vcb[i] = v3[i] - v2[i];
56     }
57     fcross(va, vab, vcb);
58     bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1;
59     bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2;
60     ax0 = (bcm->ax + 1) % 3;
61     ax1 = (bcm->ax + 2) % 3;
62     for (j = 0; j < 2; j++) {
63     vab[0] = v1[ax0] - v2[ax0];
64     vcb[0] = v3[ax0] - v2[ax0];
65     vab[1] = v1[ax1] - v2[ax1];
66     vcb[1] = v3[ax1] - v2[ax1];
67     d = vcb[0]*vcb[0] + vcb[1]*vcb[1];
68 greg 2.3 if (d <= FTINY*FTINY)
69 greg 2.1 return(-1);
70     d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d;
71     va[0] = vab[0] - vcb[0]*d;
72     va[1] = vab[1] - vcb[1]*d;
73     d = va[0]*va[0] + va[1]*va[1];
74 greg 2.3 if (d <= FTINY*FTINY)
75 greg 2.1 return(-1);
76     bcm->tm[j][0] = va[0] /= d;
77     bcm->tm[j][1] = va[1] /= d;
78     bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]);
79     /* rotate vertices */
80     vt = v1;
81     v1 = v2;
82     v2 = v3;
83     v3 = vt;
84     }
85     return(0);
86     }
87    
88    
89     put_baryc(bcm, com, n) /* put barycentric coord. vectors */
90     register BARYCCM *bcm;
91     register FLOAT com[][3];
92     int n;
93     {
94     double a, b;
95     register int i, j;
96    
97     printf("%d\t%d\n", 1+3*n, bcm->ax);
98     for (i = 0; i < n; i++) {
99     a = com[i][0] - com[i][2];
100     b = com[i][1] - com[i][2];
101     printf("%14.8f %14.8f %14.8f\n",
102     bcm->tm[0][0]*a + bcm->tm[1][0]*b,
103     bcm->tm[0][1]*a + bcm->tm[1][1]*b,
104     bcm->tm[0][2]*a + bcm->tm[1][2]*b + com[i][2]);
105     }
106     }