1# Demonstrate use of a voxel grid to assign color values to 2# components of a surface plot. 3# splot with points 4# splot with pm3d 5 6# test for voxel support in this copy of gnuplot 7if (!exists("VoxelDistance")) exit 8 9load "gen-random.inc" 10 11unset key 12rlow = -4.0 13rhigh = 4.0 14set xrange [rlow:rhigh]; set yrange [rlow:rhigh]; set zrange [rlow:rhigh] 15set xtics axis nomirror; set ytics axis nomirror; set ztics axis nomirror; 16set border 0 17set xyplane at 0 18set xzeroaxis lt -1; set yzeroaxis lt -1; set zzeroaxis lt -1; 19set view 68, 28, 1.6, 0.9 20tstring(n) = sprintf("Gaussian 3D cloud of %d random samples\ncolored by local point density", n) 21set title tstring(nsamp) 22 23set palette cubehelix negative 24set log cb; unset cbtics; 25set cblabel "point density" 26 27# define 100 x 100 x 100 voxel grid 28set vgrid $vdensity size 100 29vclear $vdensity 30 31# fill a spherical region around each point in $random 32vfill $random using 1:2:3:(0.33):(1.0) 33 34splot $random using 1:2:3:(voxel($1,$2,$3)) with points pt 7 ps 0.5 lc palette 35 36pause -1 "<cr> to continue" 37 38set title "step through volume using the density values to color a surface\n" \ 39 . "splot '++' using 1:2:(z):(voxel($1,$2,z)) with pm3d" 40 41set view 48, 114 42set sample 50,50; set isosample 50,50 43set cbrange [1:40] 44set pm3d depthorder noborder interpolate 2,2 45set pm3d noclipcb 46set style fill transparent solid 0.5 47set obj 1 rectangle from screen 0,0,0 to screen 1,1,1 behind fs solid 1.0 fc "white" 48 49# 50# The loops should only be done if the session is interactive 51# 52if (!exists("NO_ANIMATION")) { 53 do for [iz = -35 : 0] { 54 z = iz / 10. 55 splot '++' using 1:2:(z):(voxel($1,$2,z)) with pm3d 56 ; pause 0.1 57 } 58 do for [iz = 35 : 0 : -1] { 59 z = iz / 10. 60 splot '++' using 1:(-z):2:(voxel($1,-z,$2)) with pm3d, \ 61 '++' using 1:2:(0):(voxel($1,$2,0)) with pm3d 62 ; pause 0.1 63 } 64} else { 65 print "Skipping animation" 66} 67 68# 69# replot once with all three axis slices 70# 71set title "orthogonal slices through volume\n" \ 72 . "using the density values to color the surfaces" 73splot '++' using 1:(0):2:(voxel($1,0,$2)) with pm3d, \ 74 '++' using 1:2:(0):(voxel($1,$2,0)) with pm3d, \ 75 '++' using (0):1:2:(voxel(0,$1,$2)) with pm3d 76 77pause -1 "<cr> to continue" 78 79# 80# release storage space 81# 82unset vgrid $vdensity 83 84reset 85