Back to index

radiance  4R0+20100331
Defines | Functions | Variables
genbranch.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "random.h"

Go to the source code of this file.

Defines

#define errf()   (var*(0.5-frandom()))

Functions

static void stick (char *mat, beg, end, double rad)
static void branch (beg, end, double rad, int lvl)
void printhead (int ac, char **av)
int main (int argc, argv)

Variables

static const char RCSid [] = "$Id: genbranch.c,v 2.7 2003/11/16 10:29:38 schorsch Exp $"
double bstart [3] = {0.0, 0.0, 0.0}
double bend [3] = {28.0, 8.0, 0.0}
double bthick = .6
double bnarrow = .4
double bratio = .4
char * branchmat = "m_bark"
char * leafmat = "m_leaf"
int nshoots = 7
int rdepth = 3
double var = 0.3

Define Documentation

#define errf ( )    (var*(0.5-frandom()))

Definition at line 18 of file genbranch.c.


Function Documentation

static void branch ( beg  ,
end  ,
double  rad,
int  lvl 
) [static]

Definition at line 59 of file genbranch.c.

{
       double  sqrt();
       double  newbeg[3], newend[3];
       double  t;
       int  i, j;
       
       if (lvl == 0) {
              stick(leafmat, beg, end, rad);
              return;
       }

       stick(branchmat, beg, end, rad);

       for (i = 1; i <= nshoots; i++) {
                                          /* right branch */
              t = (i+errf())/(nshoots+2);
              t = (t + sqrt(t))/2.0;
              for (j = 0; j < 3; j++) {
                     newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
                     newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
              }
              newend[0] += (end[2]-newbeg[2])*bratio*(1+errf());
              newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
              newend[2] -= (end[0]-newbeg[0])*bratio*(1+errf());
              branch(newbeg, newend,
                            (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
              
                                          /* left branch */
              t = (i+errf())/(nshoots+2);
              t = (t + sqrt(t))/2.0;
              for (j = 0; j < 3; j++) {
                     newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
                     newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
              }
              newend[0] -= (end[2]-newbeg[2])*bratio*(1+errf());
              newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
              newend[2] += (end[0]-newbeg[0])*bratio*(1+errf());
              branch(newbeg, newend,
                            (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
argv   
)

Definition at line 121 of file genbranch.c.

{
       int  i, j;

       for (i = 1; i < argc && argv[i][0] == '-'; i++)
              switch (argv[i][1]) {
              case 'b':                   /* branch */
                     switch (argv[i][2]) {
                     case 's':                   /* start */
                            bstart[0] = atof(argv[++i]);
                            bstart[1] = atof(argv[++i]);
                            bstart[2] = atof(argv[++i]);
                            break;
                     case 'e':                   /* end */
                            bend[0] = atof(argv[++i]);
                            bend[1] = atof(argv[++i]);
                            bend[2] = atof(argv[++i]);
                            break;
                     case 't':                   /* thickness */
                            bthick = atof(argv[++i]);
                            break;
                     case 'n':                   /* narrow */
                            bnarrow = atof(argv[++i]);
                            break;
                     case 'r':                   /* ratio */
                            bratio = atof(argv[++i]);
                            break;
                     case 'm':                   /* material */
                            branchmat = argv[++i];
                            break;
                     default:
                            goto unkopt;
                     }
                     break;
              case 'l':                   /* leaf */
                     switch (argv[i][2]) {
                     case 'm':                   /* material */
                            leafmat = argv[++i];
                            break;
                     default:
                            goto unkopt;
                     }
                     break;
              case 'n':                   /* number of offshoots */
                     nshoots = atoi(argv[++i]);
                     break;
              case 'r':                   /* recursion depth */
                     rdepth = atoi(argv[++i]);
                     break;
              case 's':                   /* seed */
                     j = atoi(argv[++i]);
                     while (j-- > 0)
                            frandom();
                     break;
              case 'v':                   /* variability */
                     var = atof(argv[++i]);
                     break;
              default:;
unkopt:                     fprintf(stderr, "%s: unknown option: %s\n",
                                   argv[0], argv[i]);
                     exit(1);
              }
       
       if (i != argc) {
              fprintf(stderr, "%s: bad argument\n", argv[0]);
              exit(1);
       }
       printhead(argc, argv);

       branch(bstart, bend, bthick, rdepth);

       return(0);
}

Here is the call graph for this function:

void printhead ( int  ac,
char **  av 
)

Definition at line 107 of file genbranch.c.

{
       putchar('#');
       while (ac--) {
              putchar(' ');
              fputs(*av++, stdout);
       }
       putchar('\n');
}
static void stick ( char *  mat,
beg  ,
end  ,
double  rad 
) [static]

Definition at line 36 of file genbranch.c.

{
       static int  nsticks = 0;
       
       printf("\n%s cone s%d\n", mat, nsticks);
       printf("0\n0\n8\n");
       printf("\t%18.12g\t%18.12g\t%18.12g\n", beg[0], beg[1], beg[2]);
       printf("\t%18.12g\t%18.12g\t%18.12g\n", end[0], end[1], end[2]);
       printf("\t%18.12g\t%18.12g\n", rad, bnarrow*rad);

       printf("\n%s sphere e%d\n", mat, nsticks);
       printf("0\n0\n4");
       printf("\t%18.12g\t%18.12g\t%18.12g\t%18.12g\n",
                     end[0], end[1], end[2], bnarrow*rad);

       nsticks++;
}

Here is the caller graph for this function:


Variable Documentation

double bend[3] = {28.0, 8.0, 0.0}

Definition at line 21 of file genbranch.c.

double bnarrow = .4

Definition at line 23 of file genbranch.c.

char* branchmat = "m_bark"

Definition at line 25 of file genbranch.c.

double bratio = .4

Definition at line 24 of file genbranch.c.

double bstart[3] = {0.0, 0.0, 0.0}

Definition at line 20 of file genbranch.c.

double bthick = .6

Definition at line 22 of file genbranch.c.

char* leafmat = "m_leaf"

Definition at line 27 of file genbranch.c.

int nshoots = 7

Definition at line 29 of file genbranch.c.

const char RCSid[] = "$Id: genbranch.c,v 2.7 2003/11/16 10:29:38 schorsch Exp $" [static]

Definition at line 2 of file genbranch.c.

int rdepth = 3

Definition at line 30 of file genbranch.c.

double var = 0.3

Definition at line 32 of file genbranch.c.