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

Comparing ray/src/cv/obj2rad.c (file contents):
Revision 2.13 by greg, Wed Jun 15 15:07:08 1994 UTC vs.
Revision 2.16 by greg, Wed Jul 24 13:07:41 1996 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #include "trans.h"
19  
20 + #include "tmesh.h"
21 +
22   #include <ctype.h>
23  
22 #define TCALNAME        "tmesh.cal"     /* triangle interp. file */
24   #define PATNAME         "M-pat"         /* mesh pattern name (reused) */
25   #define TEXNAME         "M-nor"         /* mesh texture name (reused) */
26   #define DEFOBJ          "unnamed"       /* default object name */
27   #define DEFMAT          "white"         /* default material name */
28  
28 #define  ABS(x)         ((x)>=0 ? (x) : -(x))
29
29   #define pvect(v)        printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2])
30  
31   FVECT   *vlist;                 /* our vertex list */
# Line 36 | Line 35 | int    nvns;
35   FLOAT   (*vtlist)[2];           /* map vertex list */
36   int     nvts;
37  
39 typedef struct {
40        int     ax;             /* major axis */
41        FLOAT   tm[2][3];       /* transformation */
42 } BARYCCM;
43
38   typedef int     VNDX[3];        /* vertex index (point,map,normal) */
39  
40   #define CHUNKSIZ        256     /* vertex allocation chunk size */
# Line 564 | Line 558 | char   *v1, *v2, *v3;
558          char    *mod;
559          VNDX    v1i, v2i, v3i;
560          BARYCCM bvecs;
561 <        FVECT   bcoor[3];
561 >        FLOAT   bcoor[3][3];
562          int     texOK, patOK;
563          register int    i;
564  
# Line 574 | Line 568 | char   *v1, *v2, *v3;
568          if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3))
569                  return(0);
570                                          /* compute barycentric coordinates */
571 <        texOK = !flatten && (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0);
571 >        if (!flatten && v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0)
572 >                switch (flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]],
573 >                        vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]])) {
574 >                case DEGEN:             /* zero area */
575 >                        return(-1);
576 >                case RVFLAT:            /* reversed normals, but flat */
577 >                case ISFLAT:            /* smoothing unnecessary */
578 >                        texOK = 0;
579 >                        break;
580 >                case RVBENT:            /* reversed normals with smoothing */
581 >                case ISBENT:            /* proper smoothing */
582 >                        texOK = 1;
583 >                        break;
584 >                }
585 >        else
586 >                texOK = 0;
587   #ifdef TEXMAPS
588          patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0);
589   #else
# Line 620 | Line 629 | char   *v1, *v2, *v3;
629          pvect(vlist[v3i[0]]);
630  
631          return(1);
623 }
624
625
626 int
627 comp_baryc(bcm, v1, v2, v3)             /* compute barycentric vectors */
628 register BARYCCM        *bcm;
629 FLOAT   *v1, *v2, *v3;
630 {
631        FLOAT   *vt;
632        FVECT   va, vab, vcb;
633        double  d;
634        int     ax0, ax1;
635        register int    i, j;
636                                        /* compute major axis */
637        for (i = 0; i < 3; i++) {
638                vab[i] = v1[i] - v2[i];
639                vcb[i] = v3[i] - v2[i];
640        }
641        fcross(va, vab, vcb);
642        bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1;
643        bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2;
644        ax0 = (bcm->ax + 1) % 3;
645        ax1 = (bcm->ax + 2) % 3;
646        for (j = 0; j < 2; j++) {
647                vab[0] = v1[ax0] - v2[ax0];
648                vcb[0] = v3[ax0] - v2[ax0];
649                vab[1] = v1[ax1] - v2[ax1];
650                vcb[1] = v3[ax1] - v2[ax1];
651                d = vcb[0]*vcb[0] + vcb[1]*vcb[1];
652                if (d <= FTINY)
653                        return(-1);
654                d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d;
655                va[0] = vab[0] - vcb[0]*d;
656                va[1] = vab[1] - vcb[1]*d;
657                d = va[0]*va[0] + va[1]*va[1];
658                if (d <= FTINY)
659                        return(-1);
660                bcm->tm[j][0] = va[0] /= d;
661                bcm->tm[j][1] = va[1] /= d;
662                bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]);
663                                        /* rotate vertices */
664                vt = v1;
665                v1 = v2;
666                v2 = v3;
667                v3 = vt;
668        }
669        return(0);
670 }
671
672
673 put_baryc(bcm, com, n)                  /* put barycentric coord. vectors */
674 register BARYCCM        *bcm;
675 register FVECT  com[];
676 int     n;
677 {
678        double  a, b;
679        register int    i, j;
680
681        printf("%d\t%d\n", 1+3*n, bcm->ax);
682        for (i = 0; i < n; i++) {
683                a = com[i][0] - com[i][2];
684                b = com[i][1] - com[i][2];
685                printf("%14.8f %14.8f %14.8f\n",
686                        bcm->tm[0][0]*a + bcm->tm[1][0]*b,
687                        bcm->tm[0][1]*a + bcm->tm[1][1]*b,
688                        bcm->tm[0][2]*a + bcm->tm[1][2]*b + com[i][2]);
689        }
632   }
633  
634  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines