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

SCM Repository

[diderot] Annotation of /branches/pure-cfg/test/mip-cam.diderot
ViewVC logotype

Annotation of /branches/pure-cfg/test/mip-cam.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 689 - (view) (download)

1 : glk 689 // mip-cam
2 :     //
3 :     // initial demo of what could be boilerplate camera code,
4 :     // for maximum intensity projection
5 :    
6 :     //string dataFile = "../data/txs-pad3.nrrd";
7 :     //vec3 camEye = [25.0, 15.0, 10.0];
8 :     //vec3 camAt = [3.0, 3.0, 3.0];
9 :     //vec3 camUp = [0.0, 0.0, 1.0];
10 :     //real camNear = -5.0;
11 :     //real camFar = 5.0;
12 :     //real camFOV = 18.0;
13 :     //int imgResU = 320;
14 :     //int imgResV = 240;
15 :     //real rayStep = 0.1;
16 :    
17 :     string dataFile = "../data/vfrhand-nohip.nhdr";
18 :     vec3 camEye = [127.331, -1322.05, 272.53];
19 :     vec3 camAt = [63.0, 82.6536, 101.999];
20 :     vec3 camUp = [0.9987, 0.0459166, -0.0221267];
21 :     real camNear = -78.0;
22 :     real camFar = 78.0;
23 :     real camFOV = 5.0;
24 :     int imgResU = 320;
25 :     int imgResV = 240;
26 :     real rayStep = 1.0;
27 :    
28 :     image(3)[] img = load (dataFile);
29 :     //field#2(3)[] F = img ⊛ bspln3;
30 :     field#0(3)[] F = img ⊛ tent;
31 :    
32 :     strand RayCast (int ui, int vi)
33 :     {
34 :     real camDist = |camAt - camEye|;
35 :     real camVspNear = camDist + camNear;
36 :     real camVspFar = camDist + camFar;
37 :     vec3 camN = (camAt - camEye)/camDist;
38 :     // HEY (want) camN × camUp;
39 :     vec3 camTmpV = cross(camN,camUp);
40 :     // HEY (want) it would be nice if we could have initializing statements
41 :     // here; I had to create camTmpV to normalize the cross product, having
42 :     // chosen not to use "cross(camN,camUp)/|cross(camN,camUp)|".
43 :     // In this particular case, could also use
44 :     // "vec3 camU = normalize(cross(camN,camUp))"
45 :     vec3 camU = camTmpV/|camTmpV|;
46 :     vec3 camV = cross(camN,camU);
47 :     // HEY (want) sin()/cos() --> tan(), when tan() exists
48 :     real camTmpR = camFOV*3.1415926536/360.0;
49 :     real camVmax = sin(camTmpR)/cos(camTmpR)*camDist;
50 :     real camUmax = camVmax*real(imgResU)/real(imgResV);
51 :     // HEY (want) would like to say:
52 :     // real rayU = lerp(-0.5, ui, imgResU-0.5, -camUmax, camUmax)
53 :     // HEY (BUG) C syntax error with "real(ui) - -0.5" vs "real(ui) + 0.5";
54 :     // generated C code looks like "(float)p_ui_0--0.5e0f"
55 :     real rayU = 2.0*camUmax*(real(ui) + 0.5)/real(imgResU) - camUmax;
56 :     real rayV = 2.0*camVmax*(real(vi) + 0.5)/real(imgResV) - camVmax;
57 :     vec3 rayDir = (camDist*camN + rayU*camU + rayV*camV)/camDist;
58 :    
59 :     real rayN = camVspNear;
60 :     output real maxval = 0.0;
61 :    
62 :     update
63 :     {
64 :     vec3 rayPos = camEye + rayN*rayDir;
65 :     if (inside (rayPos,F)) {
66 :     maxval = max(maxval, F@rayPos);
67 :     }
68 :     if (rayN > camVspFar)
69 :     stabilize;
70 :     rayN = rayN + rayStep;
71 :     }
72 :    
73 :     /* render: output maxval */
74 :     }
75 :    
76 :     initially [ RayCast(ui, vi) | vi in 0..(imgResV-1), ui in 0..(imgResU-1) ];

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