Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /web/htdocs/vr-lite.html
ViewVC logotype

Annotation of /web/htdocs/vr-lite.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 388 - (view) (download) (as text)

1 : jhr 388 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 :     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 :     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 :     <head>
5 :     <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 :     <title>Simple VR example in Diderot</title>
7 :     <meta name="generator" content="BBEdit 9.5" />
8 :     <style type="text/css" title="text/css">
9 :     /* <![CDATA[ */
10 :     .code-display {
11 :     font-family: "Courier", monospace;
12 :     white-space: pre;
13 :     background-color: beige;
14 :     color: mediumblue;
15 :     width: 80%;
16 :     padding: 1em;
17 :     }
18 :     .code-type {
19 :     color: darkblue;
20 :     font-weight: bold;
21 :     }
22 :     .code-kw {
23 :     color: darkblue;
24 :     font-weight: bold;
25 :     }
26 :     .code-comment {
27 :     color: darkred;
28 :     font-style: italic;
29 :     }
30 :     /* ]]> */
31 :     </style>
32 :     </head>
33 :     <body>
34 :    
35 :     // vr-lite.diderot
36 :     //
37 :     // simple diffuse-only volume rendering with head-light, with an
38 :     // opacity function that varies linearly between two values
39 :     //
40 :    
41 :     <div align="center">
42 :     <div align="left" class="code-display"><span class="code-type">input</span> <span class="code-type">string</span> dataFile; <span class="code-comment">// name of dataset</span>
43 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
44 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
45 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
46 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
47 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
48 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
49 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
50 :    
51 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
52 :     <span class="code-type">field#1(3)[]</span> F = img ⊛ bspln3;
53 :    
54 :     <span class="code-kw">actor</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
55 :     {
56 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
57 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
58 :     <span class="code-type">real</span> t = 0.0;
59 :     <span class="code-type">real</span> transp = 1.0;
60 :     <span class="code-type">real</span> gray = 0.0;
61 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
62 :    
63 :     <span class="code-kw">update</span> {
64 :     pos = pos + stepSz*dir;
65 :     <span class="code-kw">if</span> (inside (pos,F)) {
66 :     <span class="code-type">real</span> val = F@pos;
67 :     <span class="code-type">vec3</span> grad = ∇F@pos;
68 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
69 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
70 :     <span class="code-type">real</span> opac =
71 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
72 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
73 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
74 :     transp = transp*(1.0 - opac);
75 :     }
76 :     }
77 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
78 :     transp = 0.0;
79 :     <span class="code-kw">stabilize</span>;
80 :     }
81 :     <span class="code-kw">if</span> (t > 40.0) {
82 :     <span class="code-kw">stabilize</span>;
83 :     }
84 :     t = t + stepSz;
85 :     }
86 :    
87 :     <span class="code-kw">stabilize</span> {
88 :     rgba = [gray, gray, gray, 1.0-transp];
89 :     }
90 :    
91 :     }
92 :    
93 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
94 :     </div>
95 :     </div>
96 :    
97 :     </body>
98 :     </html>

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0