ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/tmesh2rad.c
(Generate patch)

Comparing ray/src/cv/tmesh2rad.c (file contents):
Revision 2.6 by greg, Wed Jun 15 15:07:06 1994 UTC vs.
Revision 2.13 by schorsch, Thu Jun 26 00:58:09 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1994 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert a trianglular mesh into a Radiance description.
6   *
# Line 34 | Line 31 | static char SCCSid[] = "$SunId$ LBL";
31  
32   #include "standard.h"
33  
34 < #define  ABS(x)         ((x)>=0 ? (x) : -(x))
34 > #include "tmesh.h"
35  
36   #define VOIDID          "void"          /* this is defined in object.h */
37  
41 #define CALNAME         "tmesh.cal"     /* the name of our auxiliary file */
38   #define PATNAME         "T-pat"         /* triangle pattern name (reused) */
39   #define TEXNAME         "T-nor"         /* triangle texture name (reused) */
40  
# Line 56 | Line 52 | typedef struct {
52   VERTEX  *vlist = NULL;          /* our vertex list */
53   int     nverts = 0;             /* number of vertices in our list */
54  
59 typedef struct {
60        int     ax;             /* major axis */
61        FLOAT   tm[2][3];       /* transformation */
62 } BARYCCM;
63
55   #define novert(i)       ((i)<0|(i)>=nverts || !(vlist[i].flags&V_DEFINED))
56  
57   #define CHUNKSIZ        128     /* vertex allocation chunk size */
# Line 208 | Line 199 | triangle(pn, mod, obj, v1, v2, v3)     /* put out a triang
199   char    *pn, *mod, *obj;
200   register VERTEX *v1, *v2, *v3;
201   {
202 +        static char     vfmt[] = "%18.12g %18.12g %18.12g\n";
203          static int      ntri = 0;
204 +        int             flatness = ISFLAT;
205          BARYCCM bvecs;
206 <        FVECT   bvm[3];
206 >        RREAL   bvm[3][3];
207          register int    i;
208                                          /* compute barycentric coordinates */
209          if (v1->flags & v2->flags & v3->flags & (V_HASINDX|V_HASNORM))
210                  if (comp_baryc(&bvecs, v1->pos, v2->pos, v3->pos) < 0)
211                          return;
212 <                                        /* put out texture (if any) */
212 >                                        /* check flatness */
213          if (v1->flags & v2->flags & v3->flags & V_HASNORM) {
214 +                flatness = flat_tri(v1->pos, v2->pos, v3->pos,
215 +                                        v1->nor, v2->nor, v3->nor);
216 +                if (flatness == DEGEN)
217 +                        return;
218 +        }
219 +                                        /* put out texture (if any) */
220 +        if (flatness == ISBENT || flatness == RVBENT) {
221                  printf("\n%s texfunc %s\n", mod, TEXNAME);
222                  mod = TEXNAME;
223 <                printf("4 dx dy dz %s\n", CALNAME);
223 >                printf("4 dx dy dz %s\n", TCALNAME);
224                  printf("0\n");
225                  for (i = 0; i < 3; i++) {
226                          bvm[i][0] = v1->nor[i];
# Line 233 | Line 233 | register VERTEX        *v1, *v2, *v3;
233          if (*pn && (v1->flags & v2->flags & v3->flags & V_HASINDX)) {
234                  printf("\n%s colorpict %s\n", mod, PATNAME);
235                  mod = PATNAME;
236 <                printf("7 noneg noneg noneg %s %s u v\n", pn, CALNAME);
236 >                printf("7 noneg noneg noneg %s %s u v\n", pn, TCALNAME);
237                  printf("0\n");
238                  for (i = 0; i < 2; i++) {
239                          bvm[i][0] = v1->ndx[i];
# Line 242 | Line 242 | register VERTEX        *v1, *v2, *v3;
242                  }
243                  put_baryc(&bvecs, bvm, 2);
244          }
245 <                                        /* put out triangle */
245 >                                        /* put out (reversed) triangle */
246          printf("\n%s polygon %s.%d\n", mod, obj, ++ntri);
247          printf("0\n0\n9\n");
248 <        printf("%18.12g %18.12g %18.12g\n", v1->pos[0],v1->pos[1],v1->pos[2]);
249 <        printf("%18.12g %18.12g %18.12g\n", v2->pos[0],v2->pos[1],v2->pos[2]);
250 <        printf("%18.12g %18.12g %18.12g\n", v3->pos[0],v3->pos[1],v3->pos[2]);
251 < }
252 <
253 <
254 < int
255 < comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
256 < register BARYCCM        *bcm;
257 < FLOAT   *v1, *v2, *v3;
258 < {
259 <        FLOAT   *vt;
260 <        FVECT   va, vab, vcb;
261 <        double  d;
262 <        int     ax0, ax1;
263 <        register int    i, j;
264 <                                        /* compute major axis */
265 <        for (i = 0; i < 3; i++) {
266 <                vab[i] = v1[i] - v2[i];
267 <                vcb[i] = v3[i] - v2[i];
248 >        if (flatness == RVFLAT || flatness == RVBENT) {
249 >                printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]);
250 >                printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]);
251 >                printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]);
252 >        } else {
253 >                printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]);
254 >                printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]);
255 >                printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]);
256          }
269        fcross(va, vab, vcb);
270        bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1;
271        bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2;
272        ax0 = (bcm->ax + 1) % 3;
273        ax1 = (bcm->ax + 2) % 3;
274        for (j = 0; j < 2; j++) {
275                vab[0] = v1[ax0] - v2[ax0];
276                vcb[0] = v3[ax0] - v2[ax0];
277                vab[1] = v1[ax1] - v2[ax1];
278                vcb[1] = v3[ax1] - v2[ax1];
279                d = vcb[0]*vcb[0] + vcb[1]*vcb[1];
280                if (d <= FTINY)
281                        return(-1);
282                d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d;
283                va[0] = vab[0] - vcb[0]*d;
284                va[1] = vab[1] - vcb[1]*d;
285                d = va[0]*va[0] + va[1]*va[1];
286                if (d <= FTINY)
287                        return(-1);
288                bcm->tm[j][0] = va[0] /= d;
289                bcm->tm[j][1] = va[1] /= d;
290                bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]);
291                                        /* rotate vertices */
292                vt = v1;
293                v1 = v2;
294                v2 = v3;
295                v3 = vt;
296        }
297        return(0);
257   }
258  
259  
301 put_baryc(bcm, com, n)                  /* put barycentric coord. vectors */
302 register BARYCCM        *bcm;
303 register FVECT  com[];
304 int     n;
305 {
306        double  a, b;
307        register int    i, j;
308
309        printf("%d\t%d\n", 1+3*n, bcm->ax);
310        for (i = 0; i < n; i++) {
311                a = com[i][0] - com[i][2];
312                b = com[i][1] - com[i][2];
313                printf("%14.8f %14.8f %14.8f\n",
314                        bcm->tm[0][0]*a + bcm->tm[1][0]*b,
315                        bcm->tm[0][1]*a + bcm->tm[1][1]*b,
316                        bcm->tm[0][2]*a + bcm->tm[1][2]*b + com[i][2]);
317        }
318 }
319
320
260   VERTEX *
261   vnew(id, x, y, z)                       /* create a new vertex */
262   register int    id;
# Line 331 | Line 270 | double x, y, z;
270                  if (vlist == NULL)
271                          vlist = (VERTEX *)malloc(nverts*sizeof(VERTEX));
272                  else
273 <                        vlist = (VERTEX *)realloc((char *)vlist,
273 >                        vlist = (VERTEX *)realloc((void *)vlist,
274                                          nverts*sizeof(VERTEX));
275                  if (vlist == NULL) {
276                          fprintf(stderr,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines