Back to index

radiance  4R0+20100331
p_func.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: p_func.c,v 2.7 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  p_func.c - routine for procedural patterns.
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "ray.h"
00011 #include  "func.h"
00012 #include  "rtotypes.h"
00013 
00014 /*
00015  *     A procedural pattern can either be a brightness or a
00016  *  color function.  A brightness function is given as:
00017  *
00018  *     modifier brightfunc name
00019  *     2+ bvarname filename xf
00020  *     0
00021  *     n A1 A2 ..
00022  *
00023  *  A color function is given as:
00024  *
00025  *     modifier colorfunc name
00026  *     4+ rvarname gvarname bvarname filename xf
00027  *     0
00028  *     n A1 A2 ..
00029  *
00030  *  Filename is the name of the file where the variable definitions
00031  *  can be found.  The list of real arguments can be accessed by
00032  *  definitions in the file.  The xf is a transformation
00033  *  to get from the original coordinates to the current coordinates.
00034  */
00035 
00036 
00037 extern int
00038 p_bfunc(                    /* compute brightness pattern */
00039        OBJREC  *m,
00040        RAY  *r
00041 )
00042 {
00043        double  bval;
00044        register MFUNC  *mf;
00045 
00046        if (m->oargs.nsargs < 2)
00047               objerror(m, USER, "bad # arguments");
00048        mf = getfunc(m, 1, 0x1, 0);
00049        setfunc(m, r);
00050        errno = 0;
00051        bval = evalue(mf->ep[0]);
00052        if (errno == EDOM || errno == ERANGE) {
00053               objerror(m, WARNING, "compute error");
00054               return(0);
00055        }
00056        scalecolor(r->pcol, bval);
00057        return(0);
00058 }
00059 
00060 
00061 extern int
00062 p_cfunc(                    /* compute color pattern */
00063        OBJREC  *m,
00064        RAY  *r
00065 )
00066 {
00067        COLOR  cval;
00068        register MFUNC  *mf;
00069 
00070        if (m->oargs.nsargs < 4)
00071               objerror(m, USER, "bad # arguments");
00072        mf = getfunc(m, 3, 0x7, 0);
00073        setfunc(m, r);
00074        errno = 0;
00075        setcolor(cval, evalue(mf->ep[0]),
00076                      evalue(mf->ep[1]),
00077                      evalue(mf->ep[2]));
00078        if (errno == EDOM || errno == ERANGE) {
00079               objerror(m, WARNING, "compute error");
00080               return(0);
00081        }
00082        multcolor(r->pcol, cval);
00083        return(0);
00084 }