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 390 - (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 :     <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 :     border: 1px solid #CBCBCB;
14 :     background-color: #FFF8ED;
15 :     color: mediumblue;
16 :     width: 800px;
17 :     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 :     <hr />
37 :     <h2 align="center">The Diderot Project</h2>
38 :     <hr />
39 :    
40 :     <h3>A simple volume renderer in Diderot</h3>
41 :    
42 :     <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 :     <p>
49 :     This version uses the ASCII syntax for the convolution and differentiation operator.
50 :     A Unicode version can be found <a href="vr-lite.html">here</a>.
51 :     <div align="center">
52 :     <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>
53 :     <span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1; <span class="code-comment">// size of steps</span>
54 :     <span class="code-type">input</span> <span class="code-type">vec3</span> eye; <span class="code-comment">// location of eye point</span>
55 :     <span class="code-type">input</span> <span class="code-type">vec3</span> orig; <span class="code-comment">// location of pixel (0,0)</span>
56 :     <span class="code-type">input</span> <span class="code-type">vec3</span> cVec; <span class="code-comment">// vector between pixels horizontally</span>
57 :     <span class="code-type">input</span> <span class="code-type">vec3</span> rVec; <span class="code-comment">// vector between pixels vertically</span>
58 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMin; <span class="code-comment">// highest value with opacity 0.0</span>
59 :     <span class="code-type">input</span> <span class="code-type">real</span> valOpacMax; <span class="code-comment">// lowest value with opacity 1.0 </span>
60 :    
61 :     <span class="code-type">image(3)[]</span> img = load (dataFile);
62 :     <span class="code-type">field#1(3)[]</span> F = img <span class="code-kw">(*)</span> bspln3;
63 :    
64 :     <span class="code-kw">actor</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
65 :     {
66 :     <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
67 :     <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
68 :     <span class="code-type">real</span> t = 0.0;
69 :     <span class="code-type">real</span> transp = 1.0;
70 :     <span class="code-type">real</span> gray = 0.0;
71 :     <span class="code-type">output</span> <span class="code-type">vec4</span> rgba = [0.0, 0.0, 0.0, 0.0];
72 :    
73 :     <span class="code-kw">update</span> {
74 :     pos = pos + stepSz*dir;
75 :     <span class="code-kw">if</span> (inside (pos,F)) {
76 :     <span class="code-type">real</span> val = F@pos;
77 :     <span class="code-type">vec3</span> grad = <span class="code-kw">D</span> F@pos;
78 :     <span class="code-type">vec3</span> norm = -grad / |grad|;
79 :     <span class="code-kw">if</span> (val > valOpacMin) { <span class="code-comment">// we have some opacity </span>
80 :     <span class="code-type">real</span> opac =
81 :     1.0 <span class="code-kw">if</span> (val > valOpacMax)
82 :     <span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
83 :     gray = gray + transp*opac*max(0.0, dot(-dir,norm));
84 :     transp = transp*(1.0 - opac);
85 :     }
86 :     }
87 :     <span class="code-kw">if</span> (transp < 0.01) { <span class="code-comment">// early ray termination</span>
88 :     transp = 0.0;
89 :     <span class="code-kw">stabilize</span>;
90 :     }
91 :     <span class="code-kw">if</span> (t > 40.0) {
92 :     <span class="code-kw">stabilize</span>;
93 :     }
94 :     t = t + stepSz;
95 :     }
96 :    
97 :     <span class="code-kw">stabilize</span> {
98 :     rgba = [gray, gray, gray, 1.0-transp];
99 :     }
100 :    
101 :     }
102 :    
103 :     <span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];
104 :     </div>
105 :     </div>
106 :    
107 :     <hr />
108 :     Last modified: October 13, 2010.
109 :     <hr />
110 :    
111 :     </body>
112 :     </html>

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