Kurt Schwehr Copyright (C) 2003 kdschwehr _at_ ucsd dot edu Viz Lecture Series Lecture 4 $Revision: 531 $
CONTENTS * DEMOS OF THE DAY * PRINTING WITH ENSCRIPT * DRAGGERS * MAKING ANIMATED GIFS * PUTTING TEXT ON IMAGES * NETSCAPE/MOZILLA URL LOADING * SANTA BARBARA BASIN * INSTALLING OPEN INVENTOR ON MAC OSX 10.2 * EMACS QUICK STARTUP * 4DWM TRICKS * WHAT THE HECK IS THIS? * NASA SPACECRAFT MODELS ---------------------------------------------------------------------- * DEMOS OF THE DAY Thanks to Carrie Nishimura for this demo. It uses a blink node to animate a bouncing ball. ivview blinker.iv ---------------------------------------------------------------------- * PRINTING WITH ENSCRIPT Enscript is a very handy unix printing tool that can print two pages per side of a printer. It is only good for straight ASCII text, but I like it and it can save a lot of trees. Here is a sample of how to use it: enscript -2Gr -Pmyprinter VizLecture4.txt enscript -2Gr -pVizLecture4.ps gv VizLecture4.ps gs VizLecture4.ps ghostview VizLecture4.ps xpsview VizLecture4.ps pageview VizLecture4.ps For more info: man enscript ---------------------------------------------------------------------- * DRAGGERS Draggers are a great way to control actions inside of a 3D world. We will first go through how to use a 1 dimensional dragger to create a changeable sea surface. We will then move on to some of the other draggers. First, we need a simple 1D dragger (1d-dragger.iv): #Inventor V2.1 ascii Translate1Dragger {} That's all. This gives you an arrow on the screen. Press the "Esc" key to change from the hand to the arrow. Then click and hold the left mouse button on the arrow. Now drag it around. Now we can add some text that will give us feedback as to what the dragger is putting out (1d-drag-text.iv): DEF dragger Translate1Dragger {} Text3 { string "Offset" = Calculator { C 0 0 0 = USE dragger . translation expression "oa = C[0]" } . oa } This above sample is pretty tricky as it introduces a bunch of concepts altogether. The first is the DEF keyword. This allows us to reuse an object later on in an OpenInventor file. It can also be used to save memory if an object is used many times. Here is a simple def example that reuses one sphere node so you will see more than one sphere (def.iv): DEF s Sphere {} Translation { translation 0 0 3 } USE s The second big concept is the calculator node. Calculators are very handy. They can be used to do all kinds of math within the scene graph. Here we just use a calculator to get the X axis of the draggers translation. Calculators use a set of registers for calculations. Here we use the "oa" register to store the X axis and then send it back to set the string's value with the X offset. If we want to translate the text with the slider we need to add a translation that is controlled by another calculator. This looks pretty much like the one we used for the text, but instead of a single float value we need a 3D vector, so we need to use the oA register and the vec3f function to fill it (1d-drag-object.iv): Transform { translation 0 0 0 = Calculator { C 0 0 0 = USE dragger . translation expression "oA = vec3f(C[0],0,0)" } . oA } To show an example of this all in action, take a look at ocean-slider.iv which shows a sea level rise and fall in the Z direction. Another task you may want to do is to scale an object with a dragger. Turns out that it is almost the same as what we just did above. Instead of a translation, we will use a scaleFactor that is controlled by the draggers translation (scaleObject): Transform { scaleFactor 1 1 1 = Calculator { C 0 0 0 = USE dragger . translation expression "oA = vec3f(C[0],C[0],C[0])" } . oA } For more information, see: man SoTranslate1Dragger man SoCalculator man SoTransform ---------------------------------------------------------------------- * MAKING ANIMATED GIFS A common task that people like to do is to produce animated gifs. There are lots of expensive packages that can do this, but let's look at a simple one called "gifsicle": http://www.lcdf.org/gifsicle/ We will make a simple animation of the NOAA images of the east coast blackout of Aug 2003. First, grab the images from NOAA: http://www.noaanews.noaa.gov/stories/s2015.htm wget http://www.noaanews.noaa.gov/nightlights/blackout081403-20hrsbefore-text.jpg wget http://www.noaanews.noaa.gov/nightlights/blackout081503-7hrsafter-text.jpg Convert the images to gif from jpg: jpegtopnm blackout081403-20hrsbefore-text.jpg | ppmquant 255 | ppmtogif > blackout081403-20hrsbefore-text.gif jpegtopnm blackout081503-7hrsafter-text.jpg | ppmquant 255 | ppmtogif > blackout081503-7hrsafter-text.gif Now make the animation: gifsicle --colors 256 --delay=100 --loop blackout081*.gif > blackout-anim.gif There are many more options to gifsicle. Check the web or man page: setenv MANPATH ${MANPATH}:~schwehr/IRIX64-6.5/man man gifsicle ---------------------------------------------------------------------- * PUTTING TEXT ON IMAGES Sometimes you need to be able to put some text on an image. The large image processing package known as ImageMagick has just the tool for this (along with many many other tasks). Here is a sample command line to add text to an image: convert -pointsize 20 -draw 'text 10,50 "Hello World"' foo.jpg foo2.jpg display foo2.jpg That's all there is to it. Take a look at the IBM tutorial below for more ideas on what can be done. For more info see: http://www-106.ibm.com/developerworks/linux/library/l-graf/?ca=dgr-lnxw04ImageMagick http://freshmeat.net/projects/imagemagick ---------------------------------------------------------------------- * NETSCAPE/MOZILLA URL LOADING In the last lecture, we saw how to use the WWWAnchor node with xcore-ivview to tell netscape how to open a URL/web page. The method used to do this is usable from any script or program and is also available with mozilla. So how was it done? First you must have the browser already running. Here we will use netscape, but mozilla works exactly the same. netscape & Once it is running, just run this on the command line: netscape -remote "openURL(http://earthquake.usgs.gov/recenteqsUS/)" Netscape should now be at the USGS US earthquake page. For more info see: http://wp.netscape.com/newsref/std/x-remote.html http://www.mozilla.org/unix/remote.html ---------------------------------------------------------------------- * SANTA BARBARA BASIN In this section, I will walk you through most of a project based on multibeam data of the Santa Barbara Basin. Many people at SIO work in this area, so it's probably a good one to work on. I will not be starting with the raw mulitbeam data from a ship. Instead, we will start with the MBARI Santa Barbara Basin CD. To produce this CD, someone had to do a fair bit of work to clean and process the data running such programs as mbedit to remove bad beams from each ping (a very time consuming job!) For a tutorial on processing the raw data, you can talk to Uta and get a copy of her tutorial for the SIO ships. So let's jump into the processed data. Take a look at the MBARI website: http://www.mbari.org/data/mapping/SBBasin/default.htm http://www.mbari.org/data/mapping/SBBasin/basin.htm These pages show the EM300 multibeam data and some surrounding land data. You can order the CD from MBARI or copy it from the SIO GDC. Once you have the CD, you will find the data on Disk1 in grids/geo in files with a ".asc" extension. These are Arc/Info ASCII format data files. Take a look at one to see what is inside: less santabarbA_bath.asc head -6 santabarbA_bath.asc ncols 3479 nrows 1371 xllcorner -121.06507 yllcorner 34.08928 cellsize 0.0004349559829 nodata_value -99999 Each file is 6 lines of header, followed by the z-value (depth) of each point in the data set. We will use mbm_arc2grd from mbsystem and gmt to bring in the data. mb-system can be found here: http://www.ldeo.columbia.edu/MB-System/html5/mbsystem.html#index ftp://ftp.ldeo.columbia.edu/pub/mbsystem WARNING: The mbm_arc2grd perl script is only in mbsystem version 5.0 Beta or newer. Also, prior to version 5.0beta32, there is a bug in the script. You will need to edit the script and change "-H6" to "-H0" on the line with xyz2grd. First there is an error in land_topo_geo. The "nodata_value" field should be all lower case. The way it is now will cause mbm_arc2grd to not work head -6 land_topo_geo.asc ncols 2111 nrows 1120 xllcorner -120.845477 yllcorner 33.858087 cellsize 0.00099396289027745 NODATA_value -9999 Create a small perl script to fix the file (fixAsc.pl): #!/usr/bin/perl -pi s/^NODATA/nodata/; Make the script executable and use it: chmod +x fixAsc.pl ./fixAsc land_topo_geo.asc head -6 land_topo_geo.asc Now we are all set to create grid files out of each ascii Arc/Info file. On the IGPP fishnet, you will need to be logged in to a sun that mounts the GDC's tools to use mbm_arc2grd (note the export line in the script) and create the arc2grdAll.bash script: #!/bin/bash export PATH=/net/gdcraid/gdcportal/bin/mbsystem:${PATH} for file in *.asc do echo Converting $file mbm_arc2grd -I$file -O${file%%.asc}.grd done Now run the script. This will take a bit of time and uses an extra 200 MB of disk space. chmod +x arc2grdAll.bash ./arc2grdAll.bash You now have a grd file for each original ascii file: grdinfo land_topo_geo.grd Since these files are pretty big, we can use our OpenInventor skills to write a little script that will produce a labeled bounding box for each grd file (bbox.bash): #!/bin/bash for file in *bath.grd *geo.grd do echo processing $file X=`grdinfo ${file}|grep x_min` Y=`grdinfo ${file}|grep y_min` XMIN=`echo $X | awk '{print $3}'` XMAX=`echo $X | awk '{print $5}'` YMIN=`echo $Y | awk '{print $3}'` YMAX=`echo $Y | awk '{print $5}'` XAVE=`echo $XMIN $XMAX | awk '{print ($1+$2)/2.}'` YAVE=`echo $YMIN $YMAX | awk '{print ($1+$2)/2.}'` out=${file%%.grd}-bbox.iv cat < $out #Inventor V2.1 ascii Separator { Coordinate3 { point [ $XMIN $YMIN 0., $XMAX $YMIN 0., $XMAX $YMAX 0., $XMIN $YMAX 0. ] } BaseColor { rgb [ 1 0 0] } IndexedLineSet { coordIndex [ 0, 1, 2, 3, 0 ] } Translation { translation $XAVE $YAVE 0.05 } Scale { scaleFactor .002 .002 .002 } BaseColor { rgb [ 1 1 1] } Text3 { string "${file%%.grd}" } } EOF done I think this is a pretty clever little script. It draws a square around each grd region and labels the file name. It produces something like this (land_topo_geo-bbox.iv): #Inventor V2.1 ascii Separator { Coordinate3 { point [ -120.845 33.8586 0., -118.747 33.8586 0., -118.747 34.9708 0., -120.845 34.9708 0. ] } BaseColor { rgb [ 1 0 0] } IndexedLineSet { coordIndex [ 0, 1, 2, 3, 0 ] } Translation { translation -119.796 34.4147 0.05 } Scale { scaleFactor .002 .002 .002 } BaseColor { rgb [ 1 1 1] } Text3 { string "land_topo_geo" } } So run the script and look at the output: chmod +x bbox.bash ./bbox.bash ivview *-bbox.iv Now that we know where everything is, we can create some smaller grd files and 3D terrains. The default grds are really large, so we will cut them down by a factor of 4. Here is a script to do this for all of the files (makeTerrains.bash): #!/bin/bash gmtset D_FORMAT = %l.10g # Fix precision problem with grd2xyz for file in *geo.grd *bath.grd do echo processing $file X=`grdinfo ${file}|grep x_min` Y=`grdinfo ${file}|grep y_min` XINC=`echo $X | awk '{print $7}'` YINC=`echo $Y | awk '{print $7}'` grdsample $file -G${file%%.grd}_a4.grd \ -I`echo $XINC | awk '{print $1*4}'` grd2xyz ${file%%.grd}_a4.grd > ${file%%.grd}_a4.xyz terrain ${file%%.grd}_a4.xyz ${file%%.grd}_a4.iv done Now take a look at one of the files: ivview land_topo_geo_a4.iv Here is a handy way to view all of the files (viewAll.bash): #!/bin/bash for file in *_a4.iv do b=${file%%_a4.iv} ivview -name "$b" $file $b-bbox.iv done For my thesis, I'm focusing on the Gaviota Slide. I want the highest resolution model just in the the area of the slide. It is just to the west of the much larger Golita slide. The area of interest is: 120 deg 9 min West -- 120 deg 3 min West 34 deg 20 min North -- 34 deg 24 min North Which is a GMT region of (see "man grdimage"): -R-120:09/-120:03/34:20/34:24 or -R-120.15/-120.05/34.33333333/34.4 Looking thought the IV models of the terrains, the Gaviota Slide is in the following grd files: santabarbA_bath - Lower resolution wide area model santabarbC_bath - The S.B. Basin santabarbF_bath - Northern wall of the basin... highest resolution Based on this, we will start with the "F" file and cut the grid down to right around the slide. Now use gridcut to get the piece, but we have to do a little work to handle the cell size of the grd file format. If we just use our new region straight off, grdcut will fail: grdcut santabarbF_bath.grd -Ggaviota.grd -R-120.15/-120.05/34.33333333/34.4 grdcut: GMT ERROR: (x_max-x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001. grdcut: GMT ERROR: (y_max-y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001. We are lucky here that the grid file has the same spacing in the X and Y dimensions. You can view this as the x_inc and y_inc fields with grdinfo grdinfo santabarbF_bath.grd | grep inc | grep inc | awk '{print $6, $7}' x_inc: 0.000108738 y_inc: 0.000108738 Trying to compute these values is not very fun, but luckily mb_system (version 5 and newer) provides a tool to do this for us. mbm_grdcut will try to give a best fit region. The name of the program may be mbm_grdcut.pl, mbm_grdcut, or mbm_grdcut.perl depending on your system configuration. mbm_grdcut.pl -IsantabarbF_bath.grd -Ogaviota.grd -R-120:09/-120:03/34:20/34:24 -V diffx: 1454.00932392159 1454 Program mbm_grdcut status: Input GRD file: santabarbF_bath.grd Output GRD file: gaviota.grd Input Grid bounds: -120.3081056 -119.7626774 34.30966037 34.4629805 Input grid dimensions: 5017 1411 Grid cell sizes: 0.0001087376796 0.0001087376796 Requested Grid bounds: -120.15 -120.05 34.3333333333333 34.4 Output Grid bounds: -120.150001013862 -120.04996234863 34.3332564464732 34.4000213817476 Output grid dimensions: 921 615 Running grdcut... grdcut santabarbF_bath.grd -Ggaviota.grd -R-120.150001013862/-120.04996234863/34.3332564464732/34.4000213817476 -V grdcut: File spec: W E S N dx dy nx ny: grdcut: Old: -120.308 -119.763 34.3097 34.463 0.000108738 0.000108738 5017 1411 grdcut: New: -120.15 -120.05 34.3333 34.4 0.000108738 0.000108738 921 615 We can now build a 3D model of the Gaviota slide: grd2xyz gaviota.grd > gaviota.xyz terrain gaviota.xyz gaviota.iv ivview -name "Gaviota Slide" gaviota.iv NOTE: There is a bug with terrain generation of very high resolution grd files. This will appear as stripes in the models. This problem exists as of Aug 2003. How about marking the locations of the cores collected in the area? The USGS has a database of cruise metadata called InfoBank. The page for the cruise that I am working with is here and the core locations are under "Samples": http://walrus.wr.usgs.gov/infobank/v/v181sc/html/v-1-81-sc.meta.html We can grab all the core records like this wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.8g2 wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.9g2 wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.10g2 wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.11g2 wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.12g2 wget http://walrus.wr.usgs.gov/infobank/v/v181sc/samp/v-1-81-sc.core.gravitycore.13g2 A small script will create a table of the core locations (getCoreLoc.bash): #!/bin/bash for file in v-1-81-sc.core.gravitycore.*g2 do lat=`grep Latitude $file | awk '{print $3}'` lon=`grep Longitude $file | awk '{print $3}'` id=`grep 'Sample ID' $file | awk '{print $4}'` depth=-`grep 'Water Depth' $file | awk '{print $4}'` length=`grep 'Core Length' $file | awk '{print $4}'` echo $lat $lon $depth ${id}_${length}cm >> v-1-81-sc.corelocations done From these, we build up a table of locations. However, the depth for 09G2 or 08G2 looks suspicious! 34.36500 -120.10700 -477 "10G2_177cm" 34.36700 -120.10800 -455 "11G2_155cm" 34.38200 -120.10800 -336 "12G2_186cm" 34.37300 -120.11800 -396 "13G2_178cm" 34.34700 -120.10700 -545 "8G2_148cm" 34.36000 -120.10300 -977 "9G2_149cm" Using this table we can create labels that mark the location of cores: cat v-1-81-sc.corelocations | awk '{print $1,$2,$4}' > gaviota-coreloc.txt xytext2iv gaviota-coreloc.txt gaviota-coreloc From there, you will need to edit the scale and translations to make the xytext2iv program work at this scale. It was meant for California sized objects. ---------------------------------------------------------------------- * INSTALLING OPEN INVENTOR ON MAC OSX 10.2 Thanks to Davis Thomsen for the initial document after we attacked his new laptop. Installing Inventor on a Ti G4 Powerbook with OSX 1) Install the developer tools that come with OSX. This can be done a couple of ways: a) Install from the disk that comes with OSX when bought at the store b) Install from the packages already on the computer. This way involves installing these packages in a specific order. In /Applications/Installers/Developer Tools/Packages i. install BSDSDK.pkg ii. install DevTools.pkg iii. finally install DevSDK.pkg c) It is possible to download these from the apple website. * http://connect.apple.com (can get a free login) * Click Download Software * Click "Developer Tools" * December 2002 Mac OS X Developer Tools Click "Download" for Dec 2002 Mac OS X Developer Tools WARNING: This is over 300 MB! 2) Install X11. This can be downloaded from the apple website: http://www.apple.com/macosx/x11/ Click Download X11 Public Beta 3 3) Install Fink and Fink Commander Fink: http://fink.sourceforge.net/download/index.php Fink Commander: http://finkcommander.sourceforge.net/ 4) Install the X11 Developer Toolkit At the X11 download page, http://www.apple.com/macosx/x11/download/ Near the bottom right: X11 for Mac OSX Public Beta SDK Download SDK (4.0 Mb) 5) Use Fink Commander to download and install "system-Xfree86" 6) Use Fink Commander to download "motif" (when you type this into the name search field, there will be three results. Install all three. Add the library from the viz center homepage to the correct location. 7) Use Fink Commander to download and install GMT (Generic Mapping Tool) 8) Get the Open Inventor from http://schwehr.org/software/Darwin/OpenInventor-Works/ Untar this file and put in your HOME directory (i.e. /users/you) Also, get the motif library on this web page and put it in /sw/lib. This is because open inventor was build when version 2 of OpenMotif was standard in fink. 9) Add the following lines to your .cshrc: setenv DYLD_LIBRARY_PATH ${HOME}/inventor/lib setenv PATH ${PATH}:${HOME}/inventor/apps/tools/ivview 10) Move the "inventor" folder to ~/ 11) Hopefully the software will work. If you want to install mb_system, here are the Makefile settings that might work for you (provided by Jasper Konter). OS X support for MB-System should be increasing now that Dave Caress has a Titanium G4 laptop as his primary development platform. ftp://ftp.ldeo.columbia.edu/pub/mbsystem # **** EDIT THE PARAMETERS HERE **** # Set the environment parameters: $MBSYSTEM_HOME = "/sw/share/mbsystem"; $OS = "DARWIN"; $BYTESWAPPED = "NO"; $CC = "gcc"; $GRAPHICAL = "YES"; $MOTIFINCDIR = "/sw/include/Xm"; $MOTIFLIBS = "-L/sw/lib -L/usr/X11R6/lib -L/usr/X11R6/include -lXm -lXt -lX11"; $GMTVERSION = "3.4"; $GMTLIBDIR = "/sw/lib"; $GMTINCDIR = "/sw/include"; $NETCDFLIBDIR = "/sw/lib"; $NETCDFINCDIR = "/sw/include"; $LEVITUS = "/sw/share/levitus/annual"; $PROJECTIONS = "$MBSYSTEM_HOME/share/Projections.dat"; $CFLAGS = "-g -I/usr/include/X11R6 -I/usr/X11R6/include -I/sw/include -no-cpp-precomp"; $LFLAGS = "-Wl -force_flat_namespace -lm"; # # **** LEAVE EVERYTHING ELSE BELOW ALONE **** ---------------------------------------------------------------------- * EMACS QUICK STARTUP Emacs is a very powerful editor and I highly recommend it for all sorts of editing and programming tasks. However, it is pretty hard to use till you get the hang of it. Here is a quick tutorial on how to use emacs. The first thing to do is to setup emacs with a special configuration file if you do not already have one. I have a sample setup that you can use: cd cp ~schwehr/.emacs . cp -r ~schwehr/.emacs-lisp . Or here is where you can get the OpenInventor mode files yourself: cd mkdir .emacs-lisp cd .emacs-lisp wget ftp://ftp.sgi.com/sgi/inventor/emacs/iv.el wget ftp://ftp.sgi.com/sgi/inventor/emacs/iv-mode.el Here is the alias that I use to startup emacs in bash: alias e='emacs -fn 6x13 -bg black -fg white' Okay, now we are ready to see a list of commands. The first thing is a quick note on the "meta" and "control" keys. The meta key is written as "M-" and can be done by either pressing the Esc key once followed by the key or by holding down "Alt" or the diamond key on suns and pressing the key at the same time. Experiment to find out what works on your computer. The control key is written as C- and works just as you would expect. You can see a lot of the key combinations if the menus are working by just by clicking on the menu. The key equivalent is listed. C-x C-c Exit emacs C-x C-s Save C-x C-w Save As a different name C-x C-f Open a file ( hint: open "." for a directory) C-x k Close a buffer (a.k.a. file) C-x i Insert a file C-g QUIT!!! Use this if stuck. C-x 2 Split screen editing: top-bottom C-x 3 Split screen editing: left-right C-x 1 Single file editing C-x b Jump to a different open file/buffer C-s Search for string (type C-s again to find next) C-r Search backwards C-k Cut (Kut) to the end of the line C-y Yank the previous cut. (M-y right after to go back to previous cuts) C-_ UNDO! (C-z again to keep undoing) C-space Mark the beginning of a region C-w Cut the region M-w Copy the region M-x query-replace Go through and replace one string with another, but ask first on each one. M-x replace-string Replace all occurrences of a string M-x goto-line Jump to a line number C-x C-g Jump to a line if you use my .emacs M-x compile Compile or run a program Compile if you use my .emacs C-x ` Jump to next compiler error (with gcc or g77) C-x v v RCS/CVS next (check in). Use C-c C-c when done with entering comment M-x info Emacs online documentation... hard to navigate! M-x doctor Talk to a shrink. ---------------------------------------------------------------------- * 4DWM TRICKS The default window manager on the SGI is 4Dwm. It has some keyboard shortcuts that can be very handy with graphics applications. Give them a try: Alt-F3 lower Alt-F5 restore (what does this mean?) Alt-F7 move Alt-F8 resize Alt-F9 minimize Alt-F10 maximize I use move and lower all the time. For more info see: less /usr/lib/X11/system.4Dwmrc man 4Dwm ---------------------------------------------------------------------- * WHAT THE HECK IS THIS? (From ACD) http://www.sunpoint.net/~epa99/104_0482.JPG ---------------------------------------------------------------------- * NASA SPACECRAFT MODELS http://samadhi.jpl.nasa.gov/models/ Here are some simple spacecraft models that you may want to take a look at. Only two are in Inventor format. The others may be converted, but I have not tried them. Converters on the SGI can be found in: ls /usr/sbin/*To*