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

SCM Repository

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

View of /web/htdocs/vr-lite.html

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1112 - (download) (as text) (annotate)
Thu May 5 01:30:20 2011 UTC (9 years, 9 months ago) by jhr
File size: 4265 byte(s)
  Update for syntax changes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<title>Simple VR example in Diderot</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="generator" content="BBEdit 9.5" />
	<link rel="stylesheet" href="./diderot.css" type="text/css">

<div class="logo"><img src="images/logo2-504x216.png" alt="The Diderot Project" width="504" height="216"></div>

<h3>A simple volume renderer in Diderot</h3>

The following code is a simple diffuse-only volume rendering with head-light
written in Diderot.
It uses an opacity function that varies linearly between two values.
This example illustrates the use of probing both a field and its gradient.
<div align="center">
<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>
<span class="code-type">input</span> <span class="code-type">real</span> stepSz = 0.1;  <span class="code-comment">// size of steps</span>
<span class="code-type">input</span> <span class="code-type">vec3</span> eye;           <span class="code-comment">// location of eye point</span>
<span class="code-type">input</span> <span class="code-type">vec3</span> orig;          <span class="code-comment">// location of pixel (0,0)</span>
<span class="code-type">input</span> <span class="code-type">vec3</span> cVec;          <span class="code-comment">// vector between pixels horizontally</span>
<span class="code-type">input</span> <span class="code-type">vec3</span> rVec;          <span class="code-comment">// vector between pixels vertically</span>
<span class="code-type">input</span> <span class="code-type">real</span> valOpacMin;    <span class="code-comment">// highest value with opacity 0.0</span>
<span class="code-type">input</span> <span class="code-type">real</span> valOpacMax;    <span class="code-comment">// lowest value with opacity 1.0 </span>

<span class="code-type">image(3)[]</span> img = load (dataFile);
<span class="code-type">field#1(3)[]</span> F = img ⊛ bspln3;

<span class="code-kw">strand</span> RayCast (<span class="code-type">int</span> row, <span class="code-type">int</span> col)
    <span class="code-type">vec3</span> pos = orig + <span class="code-type">real</span>(row)*rVec + <span class="code-type">real</span>(col)*cVec;
    <span class="code-type">vec3</span> dir = (pos - eye)/|pos - eye|;
    <span class="code-type">real</span> t = 0.0;
    <span class="code-type">real</span> transp = 1.0;
    <span class="code-type">real</span> gray = 0.0;
    <span class="code-type">output</span> <span class="code-type">vec4</span>	rgba = [0.0, 0.0, 0.0, 0.0];

    <span class="code-kw">update</span> {
        pos = pos + stepSz*dir;
        <span class="code-kw">if</span> (inside (pos,F)) {
            <span class="code-type">real</span> val = F(pos);
            <span class="code-type">vec3</span> grad = ∇F(pos);
            <span class="code-type">vec3</span> norm = -grad / |grad|;
            <span class="code-kw">if</span> (val > valOpacMin) {  <span class="code-comment">// we have some opacity </span>
                <span class="code-type">real</span> opac =
			1.0 <span class="code-kw">if</span> (val > valOpacMax)
			<span class="code-kw">else</span> (val - valOpacMin)/(valOpacMax - valOpacMin);
                gray = gray + transp*opac*max(0.0, dot(-dir,norm));
                transp = transp*(1.0 - opac);
        <span class="code-kw">if</span> (transp < 0.01) {  <span class="code-comment">// early ray termination</span>
            transp = 0.0;
            <span class="code-kw">stabilize</span>;
        <span class="code-kw">if</span> (t > 40.0) {
            <span class="code-kw">stabilize</span>;
        t = t + stepSz;

     <span class="code-kw">stabilize</span> {
        rgba = [gray, gray, gray, 1.0-transp];


<span class="code-kw">initially</span> [ RayCast(r, c) | r in 0..199, c in 0..199 ];

<hr />
Last modified: October 13, 2010.
<hr />


ViewVC Help
Powered by ViewVC 1.0.0