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 390 - (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 390 <hr />
37 :     <h2 align="center">The Diderot Project</h2>
38 :     <hr />
39 :    
40 : jhr 389 <h3>A simple volume renderer in Diderot</h3>
41 : jhr 388
42 : jhr 389 <p>
43 :     The following code is a simple diffuse-only volume rendering with head-light
44 :     written in Diderot.
45 :     It uses an opacity function that varies linearly between two values.
46 :     This example illustrates the use of probing both a field and its gradient.
47 :     </p>
48 : jhr 388 <div align="center">
49 :     <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>
50 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
51 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
52 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
53 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
54 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
55 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
56 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
57 :    
58 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
59 :     <span class="code-type">field#1(3)[]</span> F = img ⊛ bspln3;
60 :    
61 :     <span class="code-kw">actor</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
62 :     {
63 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
64 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
65 :     <span class="code-type">real</span> t = 0.0;
66 :     <span class="code-type">real</span> transp = 1.0;
67 :     <span class="code-type">real</span> gray = 0.0;
68 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
69 :    
70 :     <span class="code-kw">update</span> {
71 :     pos = pos + stepSz*dir;
72 :     <span class="code-kw">if</span> (inside (pos,F)) {
73 :     <span class="code-type">real</span> val = F@pos;
74 :     <span class="code-type">vec3</span> grad = ∇F@pos;
75 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
76 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
77 :     <span class="code-type">real</span> opac =
78 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
79 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
80 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
81 :     transp = transp*(1.0 - opac);
82 :     }
83 :     }
84 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
85 :     transp = 0.0;
86 :     <span class="code-kw">stabilize</span>;
87 :     }
88 :     <span class="code-kw">if</span> (t > 40.0) {
89 :     <span class="code-kw">stabilize</span>;
90 :     }
91 :     t = t + stepSz;
92 :     }
93 :    
94 :     <span class="code-kw">stabilize</span> {
95 :     rgba = [gray, gray, gray, 1.0-transp];
96 :     }
97 :    
98 :     }
99 :    
100 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
101 :     </div>
102 :     </div>
103 :    
104 : jhr 390 <hr />
105 :     Last modified: October 13, 2010.
106 :     <hr />
107 :    
108 : jhr 388 </body>
109 :     </html>

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