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

Comparing ray/src/gen/genbranch.c (file contents):
Revision 2.5 by greg, Sat Feb 22 02:07:23 2003 UTC vs.
Revision 2.6 by schorsch, Sun Jun 8 12:03:09 2003 UTC

# Line 32 | Line 32 | int  rdepth = 3;                       /* recursion depth */
32   double  var = 0.3;                      /* variability */
33  
34  
35 + static void
36 + stick(mat, beg, end, rad)               /* output a branch or leaf */
37 + char  *mat;
38 + double  beg[3], end[3];
39 + double  rad;
40 + {
41 +        static int  nsticks = 0;
42 +        
43 +        printf("\n%s cone s%d\n", mat, nsticks);
44 +        printf("0\n0\n8\n");
45 +        printf("\t%18.12g\t%18.12g\t%18.12g\n", beg[0], beg[1], beg[2]);
46 +        printf("\t%18.12g\t%18.12g\t%18.12g\n", end[0], end[1], end[2]);
47 +        printf("\t%18.12g\t%18.12g\n", rad, bnarrow*rad);
48 +
49 +        printf("\n%s sphere e%d\n", mat, nsticks);
50 +        printf("0\n0\n4");
51 +        printf("\t%18.12g\t%18.12g\t%18.12g\t%18.12g\n",
52 +                        end[0], end[1], end[2], bnarrow*rad);
53 +
54 +        nsticks++;
55 + }
56 +
57 +
58 + static void
59 + branch(beg, end, rad, lvl)              /* generate branch recursively */
60 + double  beg[3], end[3];
61 + double  rad;
62 + int  lvl;
63 + {
64 +        double  sqrt();
65 +        double  newbeg[3], newend[3];
66 +        double  t;
67 +        int  i, j;
68 +        
69 +        if (lvl == 0) {
70 +                stick(leafmat, beg, end, rad);
71 +                return;
72 +        }
73 +
74 +        stick(branchmat, beg, end, rad);
75 +
76 +        for (i = 1; i <= nshoots; i++) {
77 +                                                /* right branch */
78 +                t = (i+errf())/(nshoots+2);
79 +                t = (t + sqrt(t))/2.0;
80 +                for (j = 0; j < 3; j++) {
81 +                        newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
82 +                        newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
83 +                }
84 +                newend[0] += (end[2]-newbeg[2])*bratio*(1+errf());
85 +                newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
86 +                newend[2] -= (end[0]-newbeg[0])*bratio*(1+errf());
87 +                branch(newbeg, newend,
88 +                                (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
89 +                
90 +                                                /* left branch */
91 +                t = (i+errf())/(nshoots+2);
92 +                t = (t + sqrt(t))/2.0;
93 +                for (j = 0; j < 3; j++) {
94 +                        newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
95 +                        newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
96 +                }
97 +                newend[0] -= (end[2]-newbeg[2])*bratio*(1+errf());
98 +                newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
99 +                newend[2] += (end[0]-newbeg[0])*bratio*(1+errf());
100 +                branch(newbeg, newend,
101 +                                (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
102 +        }
103 + }
104 +
105 +
106 + printhead(ac, av)               /* print command header */
107 + register int  ac;
108 + register char  **av;
109 + {
110 +        putchar('#');
111 +        while (ac--) {
112 +                putchar(' ');
113 +                fputs(*av++, stdout);
114 +        }
115 +        putchar('\n');
116 + }
117 +
118 +
119   main(argc, argv)
120   int  argc;
121   char  *argv[];
# Line 108 | Line 192 | unkopt:                        fprintf(stderr, "%s: unknown option: %s\n",
192          return(0);
193   }
194  
111
112 branch(beg, end, rad, lvl)              /* generate branch recursively */
113 double  beg[3], end[3];
114 double  rad;
115 int  lvl;
116 {
117        double  sqrt();
118        double  newbeg[3], newend[3];
119        double  t;
120        int  i, j;
121        
122        if (lvl == 0) {
123                stick(leafmat, beg, end, rad);
124                return;
125        }
126
127        stick(branchmat, beg, end, rad);
128
129        for (i = 1; i <= nshoots; i++) {
130                                                /* right branch */
131                t = (i+errf())/(nshoots+2);
132                t = (t + sqrt(t))/2.0;
133                for (j = 0; j < 3; j++) {
134                        newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
135                        newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
136                }
137                newend[0] += (end[2]-newbeg[2])*bratio*(1+errf());
138                newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
139                newend[2] -= (end[0]-newbeg[0])*bratio*(1+errf());
140                branch(newbeg, newend,
141                                (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
142                
143                                                /* left branch */
144                t = (i+errf())/(nshoots+2);
145                t = (t + sqrt(t))/2.0;
146                for (j = 0; j < 3; j++) {
147                        newbeg[j] = newend[j] = (end[j]-beg[j])*t + beg[j];
148                        newend[j] += (end[j]-beg[j])*(1+errf())/(nshoots+2);
149                }
150                newend[0] -= (end[2]-newbeg[2])*bratio*(1+errf());
151                newend[1] += (end[1]-newbeg[1])*bratio*(1+errf());
152                newend[2] += (end[0]-newbeg[0])*bratio*(1+errf());
153                branch(newbeg, newend,
154                                (1-(1-bnarrow)*t)*(1+2*bratio)/3*rad, lvl-1);
155        }
156 }
157
158
159 stick(mat, beg, end, rad)               /* output a branch or leaf */
160 char  *mat;
161 double  beg[3], end[3];
162 double  rad;
163 {
164        static int  nsticks = 0;
165        
166        printf("\n%s cone s%d\n", mat, nsticks);
167        printf("0\n0\n8\n");
168        printf("\t%18.12g\t%18.12g\t%18.12g\n", beg[0], beg[1], beg[2]);
169        printf("\t%18.12g\t%18.12g\t%18.12g\n", end[0], end[1], end[2]);
170        printf("\t%18.12g\t%18.12g\n", rad, bnarrow*rad);
171
172        printf("\n%s sphere e%d\n", mat, nsticks);
173        printf("0\n0\n4");
174        printf("\t%18.12g\t%18.12g\t%18.12g\%18.12g\n",
175                        end[0], end[1], end[2], bnarrow*rad);
176
177        nsticks++;
178 }
179
180
181 printhead(ac, av)               /* print command header */
182 register int  ac;
183 register char  **av;
184 {
185        putchar('#');
186        while (ac--) {
187                putchar(' ');
188                fputs(*av++, stdout);
189        }
190        putchar('\n');
191 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines