Back to index

radiance  4R0+20100331
preload.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: preload.c,v 2.9 2005/09/15 18:06:23 greg Exp $";
00003 #endif
00004 /*
00005  * Preload associated object structures to maximize memory sharing.
00006  *
00007  *  External symbols declared in ray.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include "standard.h"
00013 #include "octree.h"
00014 #include "object.h"
00015 #include "otypes.h"
00016 #include "face.h"
00017 #include "cone.h"
00018 #include "instance.h"
00019 #include "mesh.h"
00020 #include "color.h"
00021 #include "data.h"
00022 #include "func.h"
00023 #include "ray.h"
00024 
00025 
00026 /* KEEP THIS ROUTINE CONSISTENT WITH THE DIFFERENT OBJECT FUNCTIONS! */
00027 
00028 
00029 extern int
00030 load_os(                    /* load associated data for object */
00031        register OBJREC      *op
00032 )
00033 {
00034        DATARRAY  *dp;
00035 
00036        switch (op->otype) {
00037        case OBJ_FACE:              /* polygon */
00038               getface(op);
00039               return(1);
00040        case OBJ_CONE:              /* cone */
00041        case OBJ_RING:              /* disk */
00042        case OBJ_CYLINDER:   /* cylinder */
00043        case OBJ_CUP:        /* inverted cone */
00044        case OBJ_TUBE:              /* inverted cylinder */
00045               getcone(op, 1);
00046               return(1);
00047        case OBJ_INSTANCE:   /* octree instance */
00048               getinstance(op, IO_ALL);
00049               return(1);
00050        case OBJ_MESH:              /* mesh instance */
00051               getmeshinst(op, IO_ALL);
00052               return(1);
00053        case PAT_CPICT:             /* color picture */
00054               if (op->oargs.nsargs < 4)
00055                      goto sargerr;
00056               getpict(op->oargs.sarg[3]);
00057               getfunc(op, 4, 0x3<<5, 0);
00058               return(1);
00059        case PAT_CDATA:             /* color data */
00060               dp = getdata(op->oargs.sarg[3]);
00061               getdata(op->oargs.sarg[4]);
00062               getdata(op->oargs.sarg[5]);
00063               getfunc(op, 6, ((1<<dp->nd)-1)<<7, 0);
00064               return(1);
00065        case PAT_BDATA:             /* brightness data */
00066               if (op->oargs.nsargs < 2)
00067                      goto sargerr;
00068               dp = getdata(op->oargs.sarg[1]);
00069               getfunc(op, 2, ((1<<dp->nd)-1)<<3, 0);
00070               return(1);
00071        case PAT_BFUNC:             /* brightness function */
00072               getfunc(op, 1, 0x1, 0);
00073               return(1);
00074        case PAT_CFUNC:             /* color function */
00075               getfunc(op, 3, 0x7, 0);
00076               return(1);
00077        case TEX_DATA:              /* texture data */
00078               if (op->oargs.nsargs < 6)
00079                      goto sargerr;
00080               dp = getdata(op->oargs.sarg[3]);
00081               getdata(op->oargs.sarg[4]);
00082               getdata(op->oargs.sarg[5]);
00083               getfunc(op, 6, ((1<<dp->nd)-1)<<7, 1);
00084               return(1);
00085        case TEX_FUNC:              /* texture function */
00086               getfunc(op, 3, 0x7, 1);
00087               return(1);
00088        case MIX_DATA:              /* mixture data */
00089               dp = getdata(op->oargs.sarg[3]);
00090               getfunc(op, 4, ((1<<dp->nd)-1)<<5, 0);
00091               return(1);
00092        case MIX_PICT:              /* mixture picture */
00093               getpict(op->oargs.sarg[3]);
00094               getfunc(op, 4, 0x3<<5, 0);
00095               return(1);
00096        case MIX_FUNC:              /* mixture function */
00097               getfunc(op, 3, 0x4, 0);
00098               return(1);
00099        case MAT_PLASTIC2:   /* anisotropic plastic */
00100        case MAT_METAL2:     /* anisotropic metal */
00101               getfunc(op, 3, 0x7, 1);
00102               return(1);
00103        case MAT_BRTDF:             /* BRDTfunc material */
00104               getfunc(op, 9, 0x3f, 0);
00105               return(1);
00106        case MAT_PDATA:             /* plastic BRDF data */
00107        case MAT_MDATA:             /* metal BRDF data */
00108        case MAT_TDATA:             /* trans BRDF data */
00109               if (op->oargs.nsargs < 2)
00110                      goto sargerr;
00111               getdata(op->oargs.sarg[1]);
00112               getfunc(op, 2, 0, 0);
00113               return(1);
00114        case MAT_PFUNC:             /* plastic BRDF func */
00115        case MAT_MFUNC:             /* metal BRDF func */
00116        case MAT_TFUNC:             /* trans BRDF func */
00117               getfunc(op, 1, 0, 0);
00118               return(1);
00119        case MAT_DIRECT1:    /* prism1 material */
00120               getfunc(op, 4, 0xf, 1);
00121               return(1);
00122        case MAT_DIRECT2:    /* prism2 material */
00123               getfunc(op, 8, 0xff, 1);
00124               return(1);
00125        }
00126                      /* nothing to load for the remaining types */
00127        return(0);
00128 sargerr:
00129        objerror(op, USER, "too few string arguments");
00130        return 0; /* pro forma return */
00131 }
00132 
00133 
00134 extern void
00135 preload_objs(void)          /* preload object data structures */
00136 {
00137        register OBJECT on;
00138                             /* note that nobjects may change during loop */
00139        for (on = 0; on < nobjects; on++)
00140               load_os(objptr(on));
00141 }