Back to index

radiance  4R0+20100331
multisamp.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: multisamp.c,v 2.5 2003/06/07 12:50:20 schorsch Exp $";
00003 #endif
00004 /*
00005  * Binary space partitioning curve for multidimensional sampling.
00006  *
00007  *     Written by Christophe Schlick
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include <stdlib.h>
00013 
00014 #include "random.h"
00015 
00016 void
00017 multisamp(t, n, r)   /* convert 1-dimensional sample to N dimensions */
00018 double t[];                 /* returned N-dimensional vector */
00019 register int  n;            /* number of dimensions */
00020 double r;                   /* 1-dimensional sample [0,1) */
00021 {
00022        int    j;
00023        register int  i, k;
00024        int    ti[8];
00025        double s;
00026 
00027        i = n;
00028        while (i-- > 0)
00029               ti[i] = 0;
00030        j = 8;
00031        while (j--) {
00032               k = s = r*(1<<n);
00033               r = s - k;
00034               i = n;
00035               while (i-- > 0)
00036                      ti[i] += ti[i] + ((k>>i) & 1);
00037        }
00038        i = n;
00039        while (i-- > 0)
00040               t[i] = 1./256. * (ti[i] + frandom());
00041 }