Kurt Schwehr Copyright (C) 2003 kdschwehr _at_ ucsd dot edu Viz Lecture Series Lecture 3 OPENINVENTOR PART 3 $Revision: 445 $ CONTENTS * DEMO OF THE DAY - Piston Core tweaked for Science * AN OCEANOGRAPHIC EXAMPLE * UNIX PROCESSES * MAKING A TERRAIN ANYWHERE IN THE WORLD - IMG2GRD * SOUND * MORE ABOUT THE SGI - gfxinfo * CHOOSING FONTS * LEVELS OF DETAIL * URL LINKS FOR NETSCAPE - xcore * ON/OFF BUTTONS - xcore * ANIMATION * CYGWIN - X11 ON MS WINDOWS ---------------------------------------------------------------------- * NEW VISUALIZATION EXPERT I would like to introduce Atul Nayak to the SIO visualization community. He has joined us from the Electronic Visualization Laboratory in Chicago. Among other things, he is an expert OpenInventor programmer. Please check out his home page at: http://www.eqinfo.ucsd.edu/~atul/ * DEMO OF THE DAY Take a look at ~schwehr/Science. This is an example of using a combination of xcore scripts and hand tweaking the code to match what you would like to see. I thought that I could do a better job of laying out pictures and figures that what i showed last year. So I removed much of the extraneous material using emacs and then added in some IndexedLineSet nodes (as described in Lecture20 for each figure. These are just 2 lines from the edge of the figure that converge on the core photo at the exact depth of the photo. Sometimes small additions can polish up a presentation and add that extra snap. cd ~schwehr/Science03 ivview 02pc-new/ALLscience.iv & ivview cores127-chirp.iv & To look at where I made the most dramatic changes (which only took 3 lines each), take a look at the smear slide file: ivview 02pc-new/smear/ALL.iv Here is an example of the code that I added for the two lines: Separator { Coordinate3 { point [ -42 0 -247, -10 0 -247, -42 0 -266.7 ] } IndexedLineSet { coordIndex [ 0, 1, 2] } } * AN OCEANOGRAPHIC EXAMPLE Most examples that I have shown so far have been either generic or focused on geology/geophysics. There are plenty of opportunities for visualization in all fields of science. It's just that I'm a geologist. So make up for this, here is an interesting article where the authors show profiles of water properties across ocean basins. We all see this kind of data in the first year class Physical Oceanography here at Scripps. Why not put these kinds of data into a visualization system. In the paper, they use Java and VRML in a web browser, but VRML 1.0 will load up in standard SGI OpenInventor, so this demo would be pretty easy to recreate. I do not recommend trying to use VRML in a browser. It can be a painful experience. Salinity and other water properties can be done just the same way as with seismic lines. The simplest way is to take a picture and texture map it onto a square that covers the same lat and long coordinates. Here is the paper: Multiple Window Visualization on the Web using VRML and the EAI Roberts, Knight, Gibbons, Patel Proceedings of the 7th UK VR-SIG Conf, pages 149-157, Sept 2000. http://www.cs.ukc.ac.uk/pubs/2000/1123/index.html and another. http://www.cs.kent.ac.uk/people/staff/jcr/vrsig98/JCR_VRSIG98.html http://www.cs.kent.ac.uk/people/staff/jcr/vrsig98/vrml/m1_gifAnim.gif http://www.cs.kent.ac.uk/people/staff/jcr/vrsig98/vrml/m1_gifAnim2.gif * UNIX PROCESSES - runon nohup nice When running scientific visualization and processing programs, it is important to know some basics about unix processes, jobs, and priorities. In past lectures, I introduced top and gr_osview that show you what the SGI is doing. Here we will briefly mention three more important programs. The most important of the 3 is "nice". This lowers the priority of your program. This will help keep the machine running more smoothly for other processes and is especially important for the responsiveness of login shells and the screen. Here is how to run a program with nice: ivview sb.iv Top reports this: PID PGRP USERNAME PRI SIZE RES STATE TIME WCPU% CPU% COMMAND 605504 605504 schwehr 20 15M 8880K sleep 0:00 0.2 0.39 ivview ^^^ Notice that the "PRI" is set to 20. Now we try the same with nice: nice ivview sb.iv Top reports this: PID PGRP USERNAME PRI SIZE RES STATE TIME WCPU% CPU% COMMAND 620534 620534 schwehr 10 15M 8912K sleep 0:00 0.1 0.43 ivview ^^^ You should consider doing this with big programs such as fledermaus that really like to hog system resources. The next program is nohup. This program is handy if you have a long running program that takes days. Normally, when you start a job in the background and log out problems ensue. Either the program gets kill or ssh prevents you from logging out until the process finishes. Nohup lets the program run in the background and disconnects the program from the shell/console that you are using. The final program is runon (thanks to Kerry for pointing it out). This is an SGI specific program that controls which CPU a program runs on. Normally an SGI will decide on its own which CPU to run a process on. If you watch gr_osview, you will see the process jump from CPU to CPU over time even when there is no other load. This is pretty wasteful of resources. Every switch requires that the new CPU has to reload its on chip cache and some lookup tables (the TLB for the hard core techies). If you are running a number of single CPU jobs that run for a long time, it may be a good idea to fix them to one CPU. This is especially important for "real-time" processes that must react rapidly to incoming data. Here is how you could run a job to be fixed: (note that CPUs are numbered from 0 to the number CPUs - 1) runon 15 ./my_big_program To chain all these together: runon 15 nohup nice ./my_big_program For more information: man nice man nohup man runon * MAKING A TERRAIN ANYWHERE IN THE WORLD - IMG2GRD One common task for a research project or proposal is to build a base map. Dave Sandwell has made available a very nice data set that we can use to grab any piece of the world quickly. You can then replace sections with higher resolution locate bathymetry from the SIO Geologic Data Center or any other multi beam data that you have access to. The program we will use to extract the data is in the latest version of GMT: img2grd. The GMT homepage: http://gmt.soest.hawaii.edu Dave Sandwell's Topo web page: http://topex.ucsd.edu/marine_topo/text/topo.html For a first project, we will make a base map of the Santa Barbara Basin (a common research location for people at SIO). If you already have the topo database, you can skip the wget command. # Get the img file... WARNING! This file is 137MBs! wget ftp://topex.ucsd.edu/pub/global_topo_2min/topo_8.2.img # Note, wget is not on the igpp machines by default. You can # find it here for the SGI: # ~schwehr/IRIX64-6.5/bin/wget # You can also build wget yourself: # http://freshmeat.net/projects/wget # the file is already on SIO Viz img2grd /omaha/demos/earthquake_point_data/Tuna/raw_data/topo-8.2.img \ -R-121/-119/33.5/35 -GSantaBarbara.grd -T1 -V grdinfo SantaBarbara SantaBarbara.grd: Title: SantaBarbara.grd: Command: grdproject -Jm1 -R-121/-119/33.4805439234/35.0233855806 -I SantaBarbara.grd -V -GSantaBarbara.grd SantaBarbara.grd: Remark: SantaBarbara.grd: Pixel node registration used SantaBarbara.grd: grdfile format # 0 SantaBarbara.grd: x_min: -121 x_max: -119 x_inc: 0.0333333 units: user_x_unit nx: 60 SantaBarbara.grd: y_min: 33.4805 y_max: 35.0234 y_inc: 0.0275507 units: user_y_unit ny: 56 SantaBarbara.grd: z_min: -3597.78 z_max: 2401.03 units: user_z_unit SantaBarbara.grd: scale_factor: 1 add_offset: 0 # Convert the file to an ascii xyz file grd2xyz SantaBarbara.grd > SantaBarbara.xyz # Make an Inventor terrain out of it. terrain SantaBarbara.xyz SantaBarbara.iv # View just the terrain ivview SantaBarbara.iv # View the terrain with the major faults of California ivview SantaBarbara.iv ~schwehr/Lecture2/Cal_flt.iv If you have trouble seeing the white faults on white background in ivview, you can change the color of the faults by adding a line in the Cal_flt.iv file. Put it on the second line of Cal_flt.iv: BaseColor {rgb [1 0 0]} # This is red * SOUND Trying to work with sound across different computing platforms has never been easy, but there is a simple way to include sound in your SGI applications. The SGI sound hardware has gone through some changes lately, so it is not as easy as it used to be. I currently have not figured out how to adjust the line out volume on the Onyx3. Any suggestions on how to do this would be hugely appreciated. To start off, I'll assume that you have an MP3 audio file on your Mac running Mac OSX. The first thing you need to do is convert this file to an AIFF format file. I did this to some files using MP3-to-AIFF 2.5 which I got from http://www.versiontracker.com/ Then use scp to copy the file to your SGI. Then simply use playaiff to hear the sound file. Here are some sample sounds that you can play on your SGI: playaiff -p /usr/share/data/sounds/prosonus/sfx/glass_break.aiff playaiff -p /usr/share/data/sounds/prosonus/sfx/cricket.aiff playaiff -p /usr/share/data/sounds/prosonus/sfx/door_slam.aiff playaiff -p /usr/share/data/sounds/prosonus/sfx/double_ricochet.aiff Another simple program is SGI's say command. This was given to me by some engineer at SGI. I do not remember who and there is no source. Perhaps it is an early version of rsynth. Unfortunately, it does not work on the new digital only audio interfaces on the Onyx3. It does work Octanes: say "Hello world" echo "Say can read from standard in" | say On the Octanes, you can easily change the sound volume. Just select the the Desktop menu from the toolchest and pick "Control Audio." You can also run the audio control from the command line: apanel There are lots of other ways to play sound through SGIs. Often mpg123 is a simple solution, but it is not able to read all MP3 files that are out there. mpg123 my_sound_file.mp3 For more info: man apanel man playaiff man aiff http://www-viz.tamu.edu/~sgi-faq/faq/text/ http://www.sgi.com/tech/faq/audio/ http://groups.google.com/groups?group=comp.sys.sgi.audio NOTE: Sound is a hugely untapped area of "visualization." Most attempts to date have been more painful than helpful. A clever idea in this area could go a long way! * MORE ABOUT AN SGI: For the last two lectures, I have presented more ways to find out about an SGI that you are using. This lecture is no different. We will continue with gfxinfo. This displays information about the graphics subsystem on the SGI: /usr/gfx/gfxinfo Which on sioviz.ucsd.edu (an Onyx3), the results are: Graphics board 0 is "KONAD" graphics. Managed (":0.0") 3200x1200 Display has 8 channels 4 GEs (of 4), occmask = 0x0f 4MB external BEF ram, 32bit path 2 RM10 boards (of 2) 1/1/0/0 Texture Memory: 256MB/256MB/-/- Small pixel depth 32K cmap, 64K external gamma Channel 0: Origin = (0,0) Video Output: 1280 pixels, 1024 lines, 60.00Hz (1280x1024_60.vfo) Channel 3: Origin = (960,0) Video Output: 1280 pixels, 1024 lines, 60.00Hz (1280x1024_60.vfo) Channel 4: Origin = (1920,0) Video Output: 1280 pixels, 1024 lines, 60.00Hz (1280x1024_60.vfo) The most important items here are the texture memory and GEs (graphics engines). This shows us that each graphics board has 256MB of texture memory. It is important to keep this amount in mind. If your models try to use more that this amount of image data as textures, the rendering will get much slower. The amount of texture memory varies quite drastically between machines. The me GE's the faster the system will render triangles. * CHOOSING FONTS Often when doing a demo to an audience, the font you choose for your shell windows is critical. Some fonts do not look profession or are hard to read. Here are a couple ways to find a font that works for you. First, lets start with the SGI specific way. SGI has their own terminal window program called "winterm." This program is somewhat different than xterm. It has a build in font selector that we can use. So let's open a winterm and set the font: winterm -title "Some New Font" # Note that you do not need an "&" # Hold done the right mouse button in the winterm to get a menu # Select "Font" and let go. It will probably start you off with "fixed" in the font name. Try picking "courier (adobe)" in "Family", then "medium" in "Style", and finally "25" in "Size". You should see a nice preview in the middle of the window and the font name will be displayed below: -*-courier-medium-r-normal--25-*-*-*-m-150-iso8859-1 We can now start an xterm or winterm with this nice new font: winterm -font "-*-courier-medium-r-normal--25-*-*-*-m-150-iso8859-1" xterm -fn "-*-courier-medium-r-normal--25-*-*-*-m-150-iso8859-1" Now we can try to find fonts the standard X11/unix way. Start up an xterm with the above font command. Then hold down the CONTROL key and the right mouse button. This will give you a font menu. Try the different sizes. Also try CONTROL and the left and middle mouse buttons. You will get different menus for each. There is a tool which will list all the fonts: xlsfonts. Here is how I search for standard fixed width terminal fonts: xlsfonts | grep x | tail -30 xterm -fn 12x24 & * DRAGGERS - BRIEF INTO AND >>> DEMOS <<< TROV DEX MVACS - Mars Polar Lander ivview simpleDraggers.iv ivview complexDraggers.iv * LEVELS OF DETAIL When we start dealing with huge terrain data sets in OpenInventor, there is a simple technique that can let us render much faster and more efficiently call Levels-Of-Detail (LOD). The simplest way to implement LOD is to cut your terrain into sections. Then make several different resolution models for that patch. If the user starts very far away from the model, they will at first just see the lowest resolution model for the patch. As they get closer, OpenInventor will swap in higher and higher resolution models for that patch. This works great because when you are farther away, it is impossible to see all of the fine details of the highest resolution model. However, the highest resolution models take longer to render. First we will do some examples of LOD with some simple geometry objects. It is harder to understand sometimes with terrains what is actually going on. Here is our first sample program, lod1.iv: #Inventor V2.1 ascii LOD { range [ 10 ] center 0 0 0 Separator { Sphere{} } Separator { Cube{} } } This example is about as simple as it goes. If you wanted to use spheres for markers of points but have many of them, rendering will get slow. What this does is show a sphere when the view is within 10 units of the object and a square when farther away. The distance is specified by the range field. The center field specifies where the range will be calculated from. Here is an example just like above, but the object will disappear when farther than 20 units away (lod2.iv). #Inventor V2.1 ascii LOD { range [ 10, 20 ] center 0 0 0 Separator { Sphere{} } Separator { Cube{} } Separator {} } Finally an example that shows how to have objects with LOD that are not located at the origin (lod3.iv): LOD { range [ 40, 100 ] center 0 0 20 Separator { Translation { translation 0 0 20 } Sphere{} } Separator { Translation { translation 0 0 20 } Cube{} } Separator {} } There is an example of LOD of terrain data from the MVACS (a.k.a. Mars Polar Lander) project in the mvacsLOD directory. More info can be had through the LOD man page: man SoLOD * URL LINKS FOR NETSCAPE OR MOZILLA - not in ivview Now lets do an example where the WWWAnchor node used to create hyperlinks to a web page. We can put links in a 3D model for the use to get more data on a particular objects. At the moment this is setup just for Netscape. Here is an example (link.iv): WWWAnchor { name "http://google.com/" description "If it's not in Google, is it real?" Separator { Sphere{} Translation { translation 1 0.0 0.0 } Text3 { string "Google it!" } } } The URL for the web page to go to is in the name field. Any URL that Netscape 4.x can handle should be okay. The text in the description field is again written to the console. To Run this command: xcore-ivview link.iv For more info: man SoWWWAnchor * ON/OFF BUTTONS - not in ivview One thing that many people like to have in their 3D models are on/off switches. You could toggle a light switch or have certain data visible by request. This is not something directly available in SGI OpenInventor (it is available in VRML with Touch Sensors). However, it has been added to the xcore-ivview program. Here is how to construct a simple switch. You can put any kind of scene graph you want in the the nodes. # switch.iv WWWAnchor { name "switch" description "This text gets written to the console" Separator { BaseColor { rgb [ 1 0 0 ] } Translation { translation 10 0 0 } Sphere {} Translation { translation 1 0 0 } Text3 { string "Press me" } } Switch { whichChild 1 Separator { Cylinder {} # Put your model here } Separator{ Square {} # This is your off state model here } } } # WWW To view this example: xcore-ivview switch.iv This file brings in a new concept. The switch node has several sub-scene graphs below it. The which child field controls with of these fields is displayed. X-Core then uses the WWWAnchor node to detect the user clicking to change between the children. You can have as many children as you like. Note that the first child is number 0. The name field in the WWWAnchor switch tells xcore-ivview that this is a special switch. After the description, there should be an object that the use clicks on to flip the switch. You can also run any arbitrary shell command from a WWWAnchor node in xcore-ivview. An example is sound.iv which plays a different sound when each button is pushed. Just set the name field to be "shell:" and the command that you want to run. Separator { Translation { translation 0 0 0 } WWWAnchor { name "shell:playaiff -p /usr/share/data/sounds/prosonus/sfx/glass_break.aiff" description "A sound" Separator { BaseColor { rgb [ 1 0 0 ] } Sphere {} } } # WWW } # Separators For more info: man SoSwitch man SoWWWAnchor * ANIMATION Animations and moving objects can be a very powerful tool to show either time series data or multiple layers of data that can not all be seen at the same time. There are number of ways to do animations. The standard OpenInventor book, the Inventor Mentor, has a nice example of a windmill turning. On any SGI with the OpenInventor developer CD installed (e.g. arad3d), take a look: ivview /usr/share/src/Inventor/examples/Mentor/01.1.Windmill.iv The code uses a rotation node with an attached elapsed engine that spins the blades. The speed entry controls the rate. RotationXYZ { axis Z angle 0 = ElapsedTime { speed 0.4 } . timeOut } This does not give you a way to jump between sub-scene graphs that we often would like. For that, we need to use something slightly different. The easiest is to use a Blinker node (blink.iv): Blinker { speed 0.2 Sphere {} Cube{} Cone{} Cylinder{} } Pretty simple! So if for example you are like me and working on slumping on continental shelves, you could blink between models of each stage of a slump as it occurs. And there are many more ways to do animation. Here is one based on the SelectOne node (selectone.iv): Translation { translation 0 0 0 = SelectOne { type MFVec3f input [ -3 0 0 , -2.12 2.12 0, 0 3 0 , 2.12 2.12 0, 3 0 0 , 2.12 -2.12 0, 0 -3 0, -2.12 -2.12 0, -3 0 0] index 0 = TimeCounter { min 0 max 8 step 1 frequency 0.1 } . output } . output } Cone {} Here is a full demonstration of a blinker done by Michele Cooke for her PhD thesis. This a visualization of crack growth modeled in Fric2D. Michele was the one who clued me in to the power of Open Inventor. ivview fault45.change.iv For more info: man SoElapsedTime man SoBlinker http://www.geo.umass.edu/faculty/cooke/ * CYGWIN - X11 ON MS WINDOWS (Contributed by Katie P. w/ help from Katie G.) NOTE: This should work on Windows 2000 and XP. Don't know about older versions of MS Windows. Installing cygwin on your windows machine Go to the cygwin website: http://www.cygwin.com/xfree/ Click on the install cygwin/Xfree86 now button. *Important* disable your automatic virus detector (ie. Norton) before you start the installation process. It seems to hang up the set-up wizard for some reason. You can re-enable it once you are done installing. Run the set-up wizard. Follow the instructions about where to save files, download from internet, etc. When you get to the choose download site screen, choose one that is close to you. I used ftp://nas.nasa.gov, and that seemed to work fine. Next, you will see the Select packages screen. Make sure you select the Xfree86 packages. If they say skip next to them, they wont be installed. Click on the little circle thing next to where it says skip to put them onto the list of things to install. (Also, make sure that you have selected openssh if you don't already have an ssh program installed on your computer.) Once the installation is done (it could take a while), go to the directory where you told the install wizard to save your files. Go to cygwin\usr\X11R6\bin\ doubleclick on startxwin to open up an xterm window. I made a shortcut for this one on my desktop. If you don't have a \usr folder, then Xfree86 probably didn't get installed. Go back to the set-up wizard and make sure it was checked on the select packages screen. Now, if everything went OK, you should be able to start up cygwin and log into other machines including sioviz. If your xterm window is open, it should have no problem displaying the SGI graphics. Additional notes... If you have having trouble getting ivview or other programs to display back to your Windows computer, you can try this... it is better to avoid xhost if possible, but if ssh is not setup right, then you may have no choice. run the startxwin.bat program You should now have a bash prompt in a new window and an "X" in the lower right corner of the startup bar. We have two computers. Your windows desktop will be called "mypc" and the sgi "mysgi". On mypc, setup the permissions for X-Windows applications to connect from mysgi WARNING: using xhost opens you up to attacks that are very easy to write. Please avoid xhost if at all possible!!!! mypc % xhost mypc % xhost +mysgi mypc % xhost You will now see your sgi in the list. Log in to your sgi. mypc % ssh -X myusername@mysgi The "-X" tries to enable X11 forwarding. (Thanks to Tom Wible for this tip.) Check out your environment variables to see how things have been configured: mysgi % printenv mysgi % echo $DISPLAY If your display variable isn't localhost:##.0, then ssh tunneling of X-windows is not setup. Set your display variable (this is for csh or tcsh): mysgi % setenv DISPLAY mypc:0 Now try opening a window: mysgi % xterm Hopefully it should all work. One thing of note, new OpenGL and OpenInventor applications should work fine, but older Iris GL or Performer applications will not work. For example, fledermaus will work (but may have problems with fonts), but dmagic will fail.