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 389 - (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 : jhr 389 border: 1px solid #CBCBCB;
14 :     background-color: #FFF8ED;
15 : jhr 388 color: mediumblue;
16 : jhr 389 width: 800px;
17 : jhr 388 padding: 1em;
18 :     }
19 :     .code-type {
20 :     color: darkblue;
21 :     font-weight: bold;
22 :     }
23 :     .code-kw {
24 :     color: darkblue;
25 :     font-weight: bold;
26 :     }
27 :     .code-comment {
28 :     color: darkred;
29 :     font-style: italic;
30 :     }
31 :     /* ]]> */
32 :     </style>
33 :     </head>
34 :     <body>
35 :    
36 : jhr 389 <h3>A simple volume renderer in Diderot</h3>
37 : jhr 388
38 : jhr 389 <p>
39 :     The following code is a simple diffuse-only volume rendering with head-light
40 :     written in Diderot.
41 :     It uses an opacity function that varies linearly between two values.
42 :     This example illustrates the use of probing both a field and its gradient.
43 :     </p>
44 : jhr 388 <div align="center">
45 :     <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>
46 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
47 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
48 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
49 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
50 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
51 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
52 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
53 :    
54 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
55 :     <span class="code-type">field#1(3)[]</span> F = img ⊛ bspln3;
56 :    
57 :     <span class="code-kw">actor</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
58 :     {
59 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
60 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
61 :     <span class="code-type">real</span> t = 0.0;
62 :     <span class="code-type">real</span> transp = 1.0;
63 :     <span class="code-type">real</span> gray = 0.0;
64 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
65 :    
66 :     <span class="code-kw">update</span> {
67 :     pos = pos + stepSz*dir;
68 :     <span class="code-kw">if</span> (inside (pos,F)) {
69 :     <span class="code-type">real</span> val = F@pos;
70 :     <span class="code-type">vec3</span> grad = ∇F@pos;
71 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
72 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
73 :     <span class="code-type">real</span> opac =
74 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
75 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
76 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
77 :     transp = transp*(1.0 - opac);
78 :     }
79 :     }
80 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
81 :     transp = 0.0;
82 :     <span class="code-kw">stabilize</span>;
83 :     }
84 :     <span class="code-kw">if</span> (t > 40.0) {
85 :     <span class="code-kw">stabilize</span>;
86 :     }
87 :     t = t + stepSz;
88 :     }
89 :    
90 :     <span class="code-kw">stabilize</span> {
91 :     rgba = [gray, gray, gray, 1.0-transp];
92 :     }
93 :    
94 :     }
95 :    
96 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
97 :     </div>
98 :     </div>
99 :    
100 :     </body>
101 :     </html>

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