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 452 - (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 : jhr 452 <title>Simple VR example in Diderot</title>
6 : jhr 388 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 :     <meta name="generator" content="BBEdit 9.5" />
8 : jhr 452 <link rel="stylesheet" href="./diderot.css" type="text/css">
9 : jhr 388 </head>
10 :     <body>
11 :    
12 : jhr 452 <div class="logo"><img src="images/logo2-504x216.png" alt="The Diderot Project" width="504" height="216"></div>
13 : jhr 390
14 : jhr 389 <h3>A simple volume renderer in Diderot</h3>
15 : jhr 388
16 : jhr 389 <p>
17 :     The following code is a simple diffuse-only volume rendering with head-light
18 :     written in Diderot.
19 :     It uses an opacity function that varies linearly between two values.
20 :     This example illustrates the use of probing both a field and its gradient.
21 :     </p>
22 : jhr 388 <div align="center">
23 :     <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>
24 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
25 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
26 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
27 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
28 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
29 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
30 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
31 :    
32 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
33 :     <span class="code-type">field#1(3)[]</span> F = img ⊛ bspln3;
34 :    
35 :     <span class="code-kw">actor</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
36 :     {
37 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
38 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
39 :     <span class="code-type">real</span> t = 0.0;
40 :     <span class="code-type">real</span> transp = 1.0;
41 :     <span class="code-type">real</span> gray = 0.0;
42 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
43 :    
44 :     <span class="code-kw">update</span> {
45 :     pos = pos + stepSz*dir;
46 :     <span class="code-kw">if</span> (inside (pos,F)) {
47 :     <span class="code-type">real</span> val = F@pos;
48 :     <span class="code-type">vec3</span> grad = ∇F@pos;
49 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
50 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
51 :     <span class="code-type">real</span> opac =
52 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
53 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
54 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
55 :     transp = transp*(1.0 - opac);
56 :     }
57 :     }
58 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
59 :     transp = 0.0;
60 :     <span class="code-kw">stabilize</span>;
61 :     }
62 :     <span class="code-kw">if</span> (t > 40.0) {
63 :     <span class="code-kw">stabilize</span>;
64 :     }
65 :     t = t + stepSz;
66 :     }
67 :    
68 :     <span class="code-kw">stabilize</span> {
69 :     rgba = [gray, gray, gray, 1.0-transp];
70 :     }
71 :    
72 :     }
73 :    
74 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
75 :     </div>
76 :     </div>
77 :    
78 : jhr 390 <hr />
79 :     Last modified: October 13, 2010.
80 :     <hr />
81 :    
82 : jhr 388 </body>
83 :     </html>

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