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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : jhr 390 <!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 390 <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 390 </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 :     <h3>A simple volume renderer in Diderot</h3>
15 :    
16 :     <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 :     <p>
23 :     This version uses the ASCII syntax for the convolution and differentiation operator.
24 :     A Unicode version can be found <a href="vr-lite.html">here</a>.
25 :     <div align="center">
26 :     <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>
27 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
28 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
29 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
30 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
31 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
32 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
33 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
34 :    
35 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
36 :     <span class="code-type">field#1(3)[]</span> F = img <span class="code-kw">(*)</span> bspln3;
37 :    
38 : jhr 485 <span class="code-kw">strand</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
39 : jhr 390 {
40 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
41 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
42 :     <span class="code-type">real</span> t = 0.0;
43 :     <span class="code-type">real</span> transp = 1.0;
44 :     <span class="code-type">real</span> gray = 0.0;
45 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
46 :    
47 :     <span class="code-kw">update</span> {
48 :     pos = pos + stepSz*dir;
49 :     <span class="code-kw">if</span> (inside (pos,F)) {
50 :     <span class="code-type">real</span> val = F@pos;
51 :     <span class="code-type">vec3</span> grad = <span class="code-kw">D</span> F@pos;
52 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
53 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
54 :     <span class="code-type">real</span> opac =
55 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
56 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
57 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
58 :     transp = transp*(1.0 - opac);
59 :     }
60 :     }
61 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
62 :     transp = 0.0;
63 :     <span class="code-kw">stabilize</span>;
64 :     }
65 :     <span class="code-kw">if</span> (t > 40.0) {
66 :     <span class="code-kw">stabilize</span>;
67 :     }
68 :     t = t + stepSz;
69 :     }
70 :    
71 :     <span class="code-kw">stabilize</span> {
72 :     rgba = [gray, gray, gray, 1.0-transp];
73 :     }
74 :    
75 :     }
76 :    
77 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
78 :     </div>
79 :     </div>
80 :    
81 :     <hr />
82 :     Last modified: October 13, 2010.
83 :     <hr />
84 :    
85 :     </body>
86 :     </html>

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