[Thread Prev][Thread Next][Index]

Virtual Reality out of Ferret



Hi Ferreteers,

Attached is a script which writes Virtual Reality files out of ferret.
Why would you want to try this? It allows you to generate 3-D surfaces
out of ferret and then fly around them using a VRML viewer - directly
out of your web browser. So far we have a script which generates up to
two surfaces, each colored by a different variable if you like. I have
found this useful for looking at sea surface properties over bathymetry.

Unfortunately the script cannot handle missing values in the variables
used to generate the surfaces, so you will have to zero or smooth them
out beforehand. The colorizing variables should set the color to black
if they have missing values; otherwise the palette is blue (low) to red
(high).
Have fun and let me know of any glaring errors.

-Al Hermann
hermann@pmel.noaa.gov


! Ferret virtual world generator
!
! Al Hermann and Chris Moore 12/4/98
!
! hermann@pmel.noaa.gov
!
! This script writes out a Virtual Reality (.wrl) file for one to 
! four variables for subsequent viewing by a browser with the appropriate 
! plug-in (such as the Cosmo Viewer; if you don't have it go to 
! http://www.cosmosoftware.com/products/player and download for free)
! We have a few convenient vantage points programmed in for viewing
! the resulting surfaces from the north, south, east or west and from
! above
!
! Variables are assumed to be on a regular grid with evenly spaced x 
! and evenly spaced y (but need not be the same spacing in x and y)
! A surface representing the values of the one variable may be 
! colored according to values of the second variable or just left
! monochrome; a second colored surface can also be requested
! (for instance you might want to show the sea surface with bathymetry).
! The palette used for coloring is blue (lowest) to red (highest)
!
! z is positive downwards so bathymetry values (increasing with depth)
! will appear in the usual oceanographic way
!
! You will want to scale the surface variables to get a pleasing shape;
! try making the range in height about the same as the range of the x-axis 
! for a pleasing result (for example, if you have a region which is
! 10x10, a reasonable range for the z-values would be 0-10 - so the aspect
! ratio of the box is then 1x1x1)
!
! NOTES: 
! **You MUST explicitly set a region using i and j BEFORE you invoke this script,
! e.g. set reg/i=1:10/j=1:10
!
! **This script CANNOT handle missing values in the surfaces so set them to some 
! convenient value (such as zero) or otherwise fill them beforehand if any are 
! present. Missing values in the varaibles used for coloring are set to black
!
! usage: go fer_vrml wrlname var1 [var1col] [var2] [var2col] 
!
! wrlname = name of your world - i.e. you get a file called "wrlname.wrl"
! var1 - first variable to render as a surface height
! var1col - a variable to color the first surface 
!           (if blank then you get a red surface)
! var2 - second variable to render as a surface height
!           (if blank you get just the first surface)
! var2col - a variable to color the second surface 
!           (if blank then you get a red surface)
! 
!
! EXAMPLE:
!
! Try this simple gaussian surface
! let surfc1=-5.*exp(-.2*((i-5)*(i-5)+(j-5)*(j-5)))
! let colorit = i+j
! set reg/i=1:10/j=1:10
! go fer_vrml test surfc1 colorit
!
! Want two surfaces? Try
! go fer_vrml test surfc1 colorit -1.*surfc1 -1.*colorit
!
! Open you browser and go to the file called "test.wrl"
! and have a pleasant flight! 
!
let/quiet ii=i
let/quiet jj=j
let/quiet xx=x
let/quiet yy=y
let/quiet imax = ii[i=@max]
let/quiet imin = ii[i=@min]
let/quiet jmax = jj[j=@max]
let/quiet jmin = jj[j=@min]
let/quiet xmax = xx[i=@max]
let/quiet xmin = xx[i=@min]
let/quiet ymax = yy[j=@max]
let/quiet ymin = yy[j=@min]

let/quiet xd = imax-imin+1
let/quiet zd = jmax-jmin+1
let/quiet dx = (xmax-xmin)/(imax-imin)
let/quiet dz = (ymax-ymin)/(jmax-jmin)
let/quiet xsize= (xd-1)*dx
let/quiet zsize= (zd-1)*dz
let/quiet xmid = xsize/2.
let/quiet zmid = -1.*zsize/2.

sp rm $1.wrl
sp echo "#VRML V2.0 utf8" | cat >> $1.wrl
sp echo "# END_HEADER" | cat >> $1.wrl

sp echo "Background {skyColor 0 0 0}" | cat >> $1.wrl 

sp echo "Viewpoint {" | cat >> $1.wrl
sp echo "  position `xmid` 0 `zsize` " | cat >> $1.wrl 
sp echo "  orientation 1.0 0.0 0.0 -0. # rotating -.0 radians around x axis" | cat >> $1.wrl
sp echo '  description "look north"' | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

sp echo "Viewpoint {" | cat >> $1.wrl
sp echo "  position `-1.*xsize` 0 `zmid` " | cat >> $1.wrl
sp echo "  orientation 0 1.0 0. -1.541 # rotating pi/2 radians around y axis" | cat >> $1.wrl
sp echo '  description "look east"' | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

sp echo "Viewpoint {" | cat >> $1.wrl
sp echo "  position `xmid` 0 `-2.*zsize`" | cat >> $1.wrl
sp echo "  orientation 0 1.0 0. -3.1416 # rotating pi/2 radians around y axis" | cat >> $1.wrl
sp echo '  description "look south"' | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

sp echo "Viewpoint {" | cat >> $1.wrl
sp echo "  position `2.*xsize` 0 `zmid`" | cat >> $1.wrl
sp echo "  orientation 0 1.0 0. -4.682 # rotating 3/2 pi radians around y axis" | cat >> $1.wrl
sp echo '  description "look west"' | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

sp echo "Viewpoint {" | cat >> $1.wrl
sp echo "  position `xmid` `3.*xsize` `zmid`" | cat >> $1.wrl
sp echo "  orientation 1.0 0. 0. -1.541 # rotating pi/4 radians around x axis" | cat >> $1.wrl
sp echo '  description "look down"' | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl



sp echo "        DirectionalLight {" | cat >> $1.wrl
sp echo "                on              TRUE" | cat >> $1.wrl
sp echo "                intensity       0.50" | cat >> $1.wrl
sp echo "                color           1 1 1" | cat >> $1.wrl         
sp echo "                direction       -1. -1. -0." | cat >> $1.wrl
sp echo "        } #Directional Light  " | cat >> $1.wrl  




sp echo "Transform {" | cat >> $1.wrl
sp echo "translation `xmid` 0 0" | cat >> $1.wrl 
sp echo "children [" | cat >> $1.wrl
sp echo "Shape {" | cat >> $1.wrl
sp echo " appearance Appearance { material Material {" | cat >> $1.wrl
sp echo "	diffuseColor 1.0 0.0 0.0}}" | cat >> $1.wrl
sp echo " geometry Box { size `xsize` `xsize*.01` `xsize*.01` }" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl


sp echo "Transform {" | cat >> $1.wrl
sp echo "translation 0 `-1.*xmid` 0" | cat >> $1.wrl
sp echo "children [" | cat >> $1.wrl
sp echo "Shape {" | cat >> $1.wrl
sp echo " appearance Appearance { material Material {" | cat >> $1.wrl
sp echo "	diffuseColor 0.0 0.0 1.0}}" | cat >> $1.wrl
sp echo " geometry Box { size `xsize*.01` `xsize` `xsize*.01` }" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

sp echo "Transform {" | cat >> $1.wrl
sp echo "translation 0 0 `zmid`" | cat >> $1.wrl
sp echo "children [" | cat >> $1.wrl
sp echo "Shape {" | cat >> $1.wrl
sp echo " appearance Appearance { material Material {" | cat >> $1.wrl
sp echo "	diffuseColor 0.0 1.0 0.0}}" | cat >> $1.wrl
sp echo " geometry Box { size `zsize*.01` `zsize*.01` `zsize` } " | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl



sp echo "Transform {" | cat >> $1.wrl
sp echo "translation 0 0 0" | cat >> $1.wrl
sp echo "rotation 1. 0. 0. 3.14159" | cat >> $1.wrl
sp echo "children [" | cat >> $1.wrl
sp echo "Shape {" | cat >> $1.wrl
sp echo "appearance Appearance {" | cat >> $1.wrl
sp echo "        material Material {" | cat >> $1.wrl
sp echo "          diffuseColor 0.8 0.8 0.8" | cat >> $1.wrl
sp echo "          specularColor 0.2 0.2 0.2" | cat >> $1.wrl
sp echo "		transparency 0." | cat >> $1.wrl
sp echo "        }" | cat >> $1.wrl
sp echo "      }" | cat >> $1.wrl
sp echo "  geometry ElevationGrid {" | cat >> $1.wrl
sp echo "         solid FALSE" | cat >> $1.wrl
sp echo "	 xDimension `xd`" | cat >> $1.wrl
sp echo "	 zDimension `zd`" | cat >> $1.wrl
sp echo "	 xSpacing `dx`" | cat >> $1.wrl
sp echo "	 zSpacing `dz`" | cat >> $1.wrl
sp echo "	 creaseAngle 0.785" | cat >> $1.wrl

sp echo "	 height  [" | cat >> $1.wrl

list/nohead/append/file=$1.wrl/format=(e13.6,",") $2

sp echo "]" | cat >> $1.wrl

sp echo "	colorPerVertex TRUE" | cat >> $1.wrl
sp echo "	color Color {" | cat >> $1.wrl
sp echo "	color[" | cat >> $1.wrl
let colvar= $3"0.*$2"
let colvarmin=colvar[i=`imin`:`imax`@min,j=`jmin`:`jmax`@min]
let colvarmax=colvar[i=`imin`:`imax`@max,j=`jmin`:`jmax`@max]
let colsc =(colvar-colvarmin+1.e-10)/(colvarmax-colvarmin+1.e-10)
let ramp = 1.
let bamp = ramp
let gamp = ramp
let blue = if (colsc lt .5) then bamp*(1.) else bamp*(1.-2.*(colsc-.5))
let green= gamp*(1.-2.*abs(colsc-0.5))
let red= if (colsc gt .5) then ramp*(1.) else ramp*(2.*(colsc-0.))
list/nohead/append/file=$1.wrl/format=(3f5.2,",") missing(red,0.),missing(green,0.),missing(blue,0.)
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl


sp echo "}" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl

! skip the next section if only one surface

let testval = $4"-999+0.*$2"

IF `testval[i=1,j=1] ne -999` THEN

sp echo "Transform {" | cat >> $1.wrl
sp echo "translation 0 0 0" | cat >> $1.wrl
sp echo "rotation 1. 0. 0. 3.14159" | cat >> $1.wrl
sp echo "children [" | cat >> $1.wrl
sp echo "Shape {" | cat >> $1.wrl
sp echo "appearance Appearance {" | cat >> $1.wrl
sp echo "        material Material {" | cat >> $1.wrl
sp echo "          diffuseColor .8 .8 .8" | cat >> $1.wrl
sp echo "          specularColor 0.2 0.2 0.2" | cat >> $1.wrl
sp echo "          transparency 0."  | cat >> $1.wrl
sp echo "        }" | cat >> $1.wrl
sp echo "      }" | cat >> $1.wrl
sp echo "  geometry ElevationGrid {" | cat >> $1.wrl
sp echo "         solid FALSE" | cat >> $1.wrl
sp echo "	 xDimension `xd`" | cat >> $1.wrl
sp echo "	 zDimension `zd`" | cat >> $1.wrl
sp echo "	 xSpacing `dx`" | cat >> $1.wrl
sp echo "	 zSpacing `dz`" | cat >> $1.wrl
sp echo "	 creaseAngle 0.785" | cat >> $1.wrl
sp echo "	 height  [" | cat >> $1.wrl

list/nohead/append/file=$1.wrl/format=(e13.6,",") $4

sp echo "]" | cat >> $1.wrl

sp echo "	colorPerVertex TRUE" | cat >> $1.wrl
sp echo "	color Color {" | cat >> $1.wrl
sp echo "	color[" | cat >> $1.wrl
let colvar2= $5"0.*$4"
let colvarmin2=colvar2[i=`imin`:`imax`@min,j=`jmin`:`jmax`@min]
let colvarmax2=colvar2[i=`imin`:`imax`@max,j=`jmin`:`jmax`@max]
let colsc2 =(colvar2-colvarmin2+1.e-10)/(colvarmax2-colvarmin2+1.e-10)
let ramp = 1.
let bamp = ramp
let gamp = ramp
let blue2 = if (colsc2 lt .5) then bamp*(1.) else bamp*(1.-2.*(colsc2-.5))
let green2= gamp*(1.-2.*abs(colsc2-0.5))
let red2= if (colsc2 gt .5) then ramp*(1.) else ramp*(2.*(colsc2-0.))
list/nohead/append/file=$1.wrl/format=(3f5.2,",") missing(red2,0.),missing(green2,0.),missing(blue2,0.)
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl


sp echo "}" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl
sp echo "]" | cat >> $1.wrl
sp echo "}" | cat >> $1.wrl


ENDIF

exit 




























[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement