introduction to virtual reality visualization by the cave systemintroduction to virtual reality...

41
Advanced Methods for Space Simulations, edited by H. Usui and Y. Omura, pp. 167–207. c TERRAPUB, Tokyo, 2007. Introduction to Virtual Reality Visualization by the CAVE system Nobuaki Ohno and Akira Kageyama Earth Simulator Center, Japan Agency for Marine-Earth Science and Technology, 3173-25 Showa-machi, Yokohama 236-0001, Japan The virtual reality (VR) technology provides us a three-dimensional, immersive, and fully interactive visualization environment. Among various VR systems, the CAVE is the most attractive option for simulation researchers. In this chapter, we introduce basics of CAVE programming. The readers will be able to make a visual- ization software for the CAVE by themselves. 1 Introduction Simulation science is supported by two key technologies; computation and visu- alization. The technology of computation, or computer, is still keeping an exponential growth. In this sense, we are living in a golden age of simulation science. However, a high-rise building should be supported by balanced pillars. Unfortunately, the devel- opment of visualization technology does not catch up with its counterpart. It would be absurd if we had to spend a month to understand a simulation data obtained by one-hour-job on a high-performance computer. In the Stone Age of computer simulation when 1-dimensional (1-D) phenomena are mostly simulated, simple graph plot on a piece of paper would have been sufcient to understand or to visualize the data. When 2-D simulation were common, iso-line plots and contour color plots on papers or computer monitor screens would have been enough. In the beginning of 1990’s, 3-D simulations with the grid size of O (100 3 ) be- came to be not rare. We familiarized ourselves with newly introduced visualization technology at that time; it was a combination of visualization software and graphic workstations (GWS). We could instantly see, for example, an isosurface of 100 3 grid points through the GWS’s screen. We could zoom in, rotate, color the objects, and change the isosurface levels, via graphical user interface with the mouse. By the in- teractive manipulation through the GWS’s screen, we could grasp 3-D structure of the numerical data. This visualization technology based on GWS was certainly powerful enough at that time. Now, the complexity of target phenomena on the present high-end super compu- ter, such as the Earth Simulator 1 , are extremely high; the typical grid size is O (1000 3 ). 1 http://www.es.jamstec.go.jp/esc/eng/index.html 167

Upload: others

Post on 28-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Advanced Methods for Space Simulations, edited by H. Usui and Y. Omura, pp. 167–207.c© TERRAPUB, Tokyo, 2007.

Introduction to Virtual Reality Visualizationby the CAVE system

Nobuaki Ohno and Akira Kageyama

Earth Simulator Center,Japan Agency for Marine-Earth Science and Technology,

3173-25 Showa-machi, Yokohama 236-0001, Japan

The virtual reality (VR) technology provides us a three-dimensional, immersive,and fully interactive visualization environment. Among various VR systems, theCAVE is the most attractive option for simulation researchers. In this chapter, weintroduce basics of CAVE programming. The readers will be able to make a visual-ization software for the CAVE by themselves.

1 IntroductionSimulation science is supported by two key technologies; computation and visu-

alization. The technology of computation, or computer, is still keeping an exponentialgrowth. In this sense, we are living in a golden age of simulation science. However, ahigh-rise building should be supported by balanced pillars. Unfortunately, the devel-opment of visualization technology does not catch up with its counterpart. It wouldbe absurd if we had to spend a month to understand a simulation data obtained byone-hour-job on a high-performance computer.

In the Stone Age of computer simulation when 1-dimensional (1-D) phenomenaare mostly simulated, simple graph plot on a piece of paper would have been sufficientto understand or to visualize the data. When 2-D simulation were common, iso-lineplots and contour color plots on papers or computer monitor screens would have beenenough.

In the beginning of 1990’s, 3-D simulations with the grid size of O(1003) be-came to be not rare. We familiarized ourselves with newly introduced visualizationtechnology at that time; it was a combination of visualization software and graphicworkstations (GWS). We could instantly see, for example, an isosurface of 1003 gridpoints through the GWS’s screen. We could zoom in, rotate, color the objects, andchange the isosurface levels, via graphical user interface with the mouse. By the in-teractive manipulation through the GWS’s screen, we could grasp 3-D structure of thenumerical data. This visualization technology based on GWS was certainly powerfulenough at that time.

Now, the complexity of target phenomena on the present high-end super compu-ter, such as the Earth Simulator1, are extremely high; the typical grid size is O(10003).

1http://www.es.jamstec.go.jp/esc/eng/index.html

167

Page 2: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

168 N. Ohno and A. Kageyama

Fig. 1. The CAVE system in Earth Simulator Center, called BRAVE.

Fig. 2. (a) Stereo glasses. (b) A portable controller, wand.

Thanks to the advanced graphic hardware these days, we can certainly render, ro-tate and control an isosurface of a scalar data on O(10003) grid points. However, thecomplicated shape itself of the isosurface prevents us from the intuitive and immedi-ate understanding of the 3-D structure of the scalar field.

Another limitation of the GWS-based visualization technology is the ability (orinability) of visualization of vector fields. In our simulation research, 3-D vectorfield is common, for example, the fluid flow, electric field, and magnetic field. Weneed to grasp spatial structure of the 3-D vector fields defined on O(10003) gridpoints in order to understand what was simulated on the computer. This is reallya challenging task and obviously beyond the GWS-based visualization technology.Simulation scientists today really need innovation in the visualization technology thatsuits the modern high-performance computer. And we believe that the virtual reality(VR) is the answer.

Everyone who experiences a modern VR system for the first time would be sur-prised by its high quality of computed reality. They feel like they are deeply im-mersed, or really standing, in the mimicked world. In order to produce such a deep

Page 3: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 169

absorption into the VR world, there are three important visual factors2; (1) stereoview, (2) immersive view, and (3) interactive view. Among various kinds of availableVR hardware, we believe that the CAVE [Cruz-Neira:1993] system is the best suitedto our purpose of the visualization of large scale 3-D scalar and vector fields.

The CAVE is developed at Electric Visualization Laboratory (EVL), University ofIllinois3. We installed our CAVE system at Earth Simulator Center, Japan Agency forMarine-Earth Science and Technology (JAMSTEC) in 2002, and named it BRAVE.

2 Hardware of VR Visualization: BRAVEBRAVE has a cubic room of the volume (3m)3. It has four stereo screens (three

walls and a floor) as shown in Fig. 1. The viewer stands in the BRAVE room on thefloor screen, wearing a pair of stereo glasses [Fig. 2(a)], having a portable controllercalled wand [Fig. 2(b)]. Stereo images are projected on the three walls and the floorby four DLP projectors [Fig. 3(a)]. A GWS (SGI Onyx3800) is used to generate thestereo images [Fig. 3(b)]4. The Onyx3800 in our system has 12 CPUs, 24GB mem-ory, and 2 graphics pipes. Since the viewer inside the BRAVE room is surroundedby stereo images on the three walls and the floor, he or she can look around in theBRAVE room, keeping the wide range of stereo view angle. This strongly gener-ates the immersive sense of the viewer. The refresh rate of the image is 96 Hz: Theright-eye image and the left-eye image are projected alternately with 48 Hz each. Theimage refresh is synchronized with the alternate shutter of the stereo glasses by theinfrared emitter/sensor system. The images on the boundaries between the walls andthe floor are smoothly connected. The viewer can easily forget the existence of theboundaries. Actually, we saw some people had banged on the BRAVE’s walls!

BRAVE has a magnetic tracking system to detect the position and direction ofthe viewer’s eyes in the room. A transmitter of the magnetic tracking system is in-stalled on the ceiling of the BRAVE room and a small magnetic sensor is attachedon the stereo glasses [see Fig. 2(a)]. Another magnetic sensor is installed in thewand [Fig. 2(b)] to detect the position and direction of the wand (or the viewer’shand). All the projected images are automatically adjusted following the viewer’shead motion in real time. Therefore, everything looks natural from the viewer whocan incline, walk, sit, or even jump in the BRAVE room to observe 3-D objects in thevirtual world.

The wand, which has 3 buttons and 1 joystick5, is used as an interface with thevirtual world (or simulation data). For example, when the viewer presses a wandbutton, a virtual menu appears in front of him or her, and he or she can choose a visu-alization method by shooting a menu panel by a virtual laser beam emitted from thewand. If one presses another button after choosing “Tracer Particle” menu, a virtualtracer particle appears at the tip of the wand, and when the button is released, the

2Sonifications [Tamura:2001] and haptics are other important VR technology that could be applied inscientific visualization.

3http://www.evl.uic.edu/index2.php34Recently, the CAVE system is sometimes constructed with PC cluster instead of expensive GWS.5A “trackball” may suit to its shape, but it is historically called joystick.

Page 4: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

170 N. Ohno and A. Kageyama

Fig. 3. (a) A DLP projector which projects stereo images on a BRAVE’s screen. (b) SGI Onyx3800.

Fig. 4. A CAVE program based on OpenGL Performer and pfCAVELib.

particle “flies” under the eyes following the velocity field showing the flow structureby its trajectory.

To model the virtual world in the CAVE, one can use (i) OpenGL, or (ii) OpenGLPerformer. The OpenGL is a standard API for developing 3D computer graphics(CG) software [Shreiner:2003, 2004], it is used to define the visualization objects andits illumination. A CAVE application program is essentially a kind of common CGsoftware without the projection part which is automatically processed by a basic VRlibrary for the CAVE called CAVELib. So, if you are familiar with CG programmingusing OpenGL, it would be easy to make your own CAVE applications.

When you want to make an elaborated visual simulation software such as a drivesimulator, you can use pfCAVELib, which enables you to make a CAVE applica-tion written on OpenGL Performer. Fig. 4 shows an example of CAVE applicationprograms using OpenGL Performer with pfCAVELib. Here whole premises of Na-

Page 5: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 171

tional Institute for Fusion Science (NIFS) in Japan are shown in the CAVE. One ofthe authors (N. Ohno), who developed this software, is walking through this “Vir-tual NIFS”. The object data of Virtual NIFS, which is written in the Open Inventorformat, was created by himself using a freely available 3-D modeling software and adigital camera for textures. OpenGL Performer can display not only the Open Inven-tor format but also various formats of 3-D data. Although we will not mention it anyfurther, interested users may refer to the web site of OpenGL Performer6.

3 CAVE Programming IntroductionIn this section, we introduce how to make a program of the CAVE application.

The readers are supposed to be familiar with C/C++ and OpenGL but need not to beexpert. You will find that making a CAVE program is a lot easier than you expect.3.1 Sample Program 1

First, see the following very simple CAVE application, which displays a whitetriangle in the CAVE [Fig. 5].

1 /*2 *--------------------------------------------------------3 * Sample code : triangle.c4 *5 * by Nobuaki Ohno, 20056 *7 *--------------------------------------------------------8 */910 #include <cave_ogl.h>11 #include <unistd.h>1213 void14 init_gl (void)15 {1617 glClearColor (0., 0., 0., 0.);1819 }2021 void22 draw (void)23 {24 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);25 glPushMatrix ();26 glColor3f (1.0, 1.0, 1.0);27 glTranslatef (0.0, 5.0, -5.0);28 glBegin (GL_TRIANGLES);29 glVertex3f (-2.0, 0.0, 0.0);

6http://www.sgi.com/products/software/performer/

Page 6: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

172 N. Ohno and A. Kageyama

30 glVertex3f (2.0, 0.0, 0.0);31 glVertex3f (0.0, 4.0, 0.0);32 glEnd ();33 glPopMatrix ();34 }3536 main (int argc, char **argv)37 {3839 CAVEConfigure (&argc, argv, NULL);4041 CAVEInit ();4243 CAVEInitApplication (init_gl, 0);4445 CAVEDisplay (draw, 0);4647 while (!CAVEgetbutton (CAVE_ESCKEY))48 sginap (10);4950 CAVEExit ();51 }

This is very short but a still complete CAVE program. The function init gl()[line 14] does the initialization of OpenGL, and draw [line 22] displays a whitetriangle in the CAVE. The readers who are familiar with OpenGL may easily under-stand the two functions. Notice that there is no projection- or stereo-related func-tion in draw or any other part. As we mentioned, the projection part of a CAVEprogram is automatically taken care by CAVELib. In the main function, some im-portant CAVELib functions are called. void CAVEInit [line 41] does the ini-tialization of the CAVE. By void CAVEInitApplication(CAVECALLBACK,int,...) [line 43] and our init gl, OpenGL is initialized. voidCAVEDisplay(CAVECALLBACK, int,...) [line 45] specifies rendering func-tion, which is draw in this case. This program displays a white triangle until the ESCkey is pressed [line 47].

When you use GLUT library, which is a popular toolkit for writing OpenGL pro-grams, the main function would be like this,

1 main(int argc, char **argv)2 {3 glutInit(&argc, argv);45 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);6 glutInitWindowPosition(100, 100);7 glutInitWindowSize(500, 500);8 glutCreateWindow("Analogy");

Page 7: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 173

Fig. 5. A white triangle is displayed in the CAVE by sample program “triangle.c”.

Fig. 6. A developer uses the CAVE simulator.

9

10 glutDisplayFunc(draw);

11 glutReshapeFunc(resize);

12 glutKeyboardFunc(keyboard);

13 glutIdleFunc(compute);

14

15 init_gl();

16

17 glutMainLoop();

18

19 }

Here, draw includes rendering part using GLUT.

Page 8: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

174 N. Ohno and A. Kageyama

3.2 CAVE SimulatorIt is a common practice that the program development, including the CAVE pro-

gram development, involves repeated cycle of to code, compile, test and debug. Itwould be very annoying if one had to get into the CAVE room, with the stereo glassesevery time for the test step in the above development cycle. Fortunately, CAVE sim-ulator is available which simulates the projected images and operations on the XWindow. By using the CAVE simulator, the developer can test the application with-out going into the CAVE room. Fig. 6 shows a snapshot of the CAVE simulator forthe test program “triangle.c”.

The CAVE simulator can display the CAVE’s room on GWS or PC screen fromthe viewer’s point of view as well as from outside the room. The wand and theviewer’s head are displayed by symbols. The viewer’s movement and the operationsof the wand in the CAVE can be simulated by using the keyboard and mouse. Fre-quently used operations of the CAVE simulator are summarized in Table 1 to Table 4.

Table 1. Head motions

Keyboard and Mouse Head Motion

← / → / ↑ / ↓ key move left/right/forward/backward

Shift key + ↑ key move upward

Shift key + ↓ key move downward

Table 2. Wand Operations

Keyboard and Mouse Wand

Ctrl key + Mouse movement move the wand left/right/forward/backward

Shift key + Mouse movement move the wand left/right/upward/downward

Alt key + Mouse movement rotate the wand left/right/upward/downward

Table 3. Wand buttons and trackball operations

Keyboard and Mouse Wand

Mouse left/middle/right button wand left/middle/right button

Space key + Mouse movement move trackball(Joystick)

Fig. 7 shows a screen snapshot of the CAVE simulator which simulates “trian-gle.c” result. The red gadget in the center is the symbol for the wand.

Hereafter, the sample snapshots in this section are those of the CAVE simulator.

Page 9: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 175

Table 4. Other Controls

Keyboard Control

1 key view from viewer’s point of view

2 key view from outside

w key make wand visible/invisible

u key make viewer’s head visible/invisible

p key reset head and wand to the initial

Insert key make frame of the CAVE’s room visible/invisible

Fig. 7. This is a snapshot of CAVE simulator of “triangle.c”. The red gadget indicates the wand.

3.3 Processes of CAVE ApplicationA CAVE program is a multi-process program. There are three kinds of processes.

• Tracking Process

• Display Process

• Application Computation Process

The Tracking Process detects, in real time, the positions and directions of the stereoglasses and the wand while a CAVE application is running. The CAVE programmercan retrieve the position/direction data from this Tracking Process.

The Display Process draws the stereo images on the screens. The CAVELib auto-matically calculates the stereo projection based on the viewer’s eyes. Generally, thereare multiple Display Processes while a CAVE application is running.

Page 10: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

176 N. Ohno and A. Kageyama

The Application Computation Process does calculations of, for example, orbits ofthe particle tracers. The functions which you want the Application Computation Pro-cess to do should be called in the “while loop” (for example, at the line 47 triangle.c)in the main function.

The Display Processes and the Application Computation Process communicatevia the shared memory allocated by “void *CAVEMalloc(size t)” [Fig. 8].If you want to move a ball in the CAVE, for example, the variables for the ball’scoordinates have to be stored on the shared memory.

Fig. 8. Processes communicate each other via the shared memory.

3.4 Animation

The following is a sample program to show how to use the shared memory andcarry out the animation in the CAVE. This program makes white star-shaped objects,or snowflakes, rotate and fall in the CAVE [Fig. 9].

Fig. 9. Snowflakes are falling in the CAVE. This is a snapshot of CAVE simulator.

Page 11: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 177

1 /*2 *--------------------------------------------------------3 * Sample code : Snowfall.c4 *5 * by Akira Kageyama, 19986 * modified by Nobuaki Ohno, 20057 *8 *--------------------------------------------------------9 */1011 #include <cave_ogl.h>12 #include <GL/glu.h>13 #include <stdlib.h>14 #include <unistd.h>15 #include <strings.h>161718 #define NFLAKES 50019 #define XMAX 20.020 #define YMAX 20.021 #define ZMAX 10.022 #define XMIN (-20.0)23 #define YMIN (-5.0)24 #define ZMIN (-20.0)2526 /* The data that will be shared between processes */27 struct _snowdata28 {29 float xpos;30 float ypos;31 float zpos;32 float xaxis;33 float yaxis;34 float zaxis;35 float spin;36 };3738 void init_gl (void), draw (struct _snowdata *);39 struct _snowdata *init_shmem (void);40 void compute (struct _snowdata *);4142 static GLuint flake_indx;4344 main (int argc, char **argv)45 {46 struct _snowdata *snows;

Page 12: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

178 N. Ohno and A. Kageyama

47 CAVEConfigure (&argc, argv, NULL);48 snows = init_shmem ();49 CAVEInit ();50 CAVEInitApplication (init_gl, 0);51 CAVEDisplay ((CAVECALLBACK) draw, 1, snows);52 while (!CAVEgetbutton (CAVE_ESCKEY))53 {54 compute (snows);55 sginap (1);56 }57 CAVEExit ();58 }5960 float61 randmf (void)62 {63 float r, rndmax;6465 rndmax = (float)(RAND_MAX + 1);66 r = rand () / rndmax;6768 return r;69 }7071 struct _snowdata *72 init_shmem (void)73 {74 int i;75 struct _snowdata *snows;7677 snows = (_snowdata *) CAVEMalloc (78 NFLAKES * sizeof (struct _snowdata));79 bzero (snows, NFLAKES * sizeof (struct _snowdata));8081 for (i = 0; i < NFLAKES; i++)82 {83 snows[i].xpos = XMIN + (XMAX - XMIN) * randmf ();84 snows[i].ypos = YMIN + (YMAX - YMIN) * randmf ();85 snows[i].zpos = ZMIN + (ZMAX - ZMIN) * randmf ();86 snows[i].xaxis = randmf ();87 snows[i].yaxis = randmf ();88 snows[i].zaxis = randmf ();89 }9091 return snows;92 }93

Page 13: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 179

94 void95 compute (struct _snowdata *snows)96 {97 int i;98 float y, angle, velocity = 0.5;99 float t = CAVEGetTime ();100 static float prev_t = 0.0;101102 for (i = 0; i < NFLAKES; i++)103 {104 y = snows[i].ypos - velocity * (t - prev_t);105 if (y < YMIN)106 y = YMAX;107 snows[i].ypos = y;108 angle = t * 50;109110 angle = (int)angle % 360;111112 snows[i].spin = angle;113 }114 prev_t = t;115 }116117 void118 init_gl (void)119 {120 float flake_size = 0.5;121 GLuint tmp_indx;122123 glDisable (GL_LIGHTING);124 glColor3f (1.0, 1.0, 1.0);125 glClearColor (0., 0., 0., 0.);126127 tmp_indx = glGenLists (1);128 glNewList (tmp_indx, GL_COMPILE);129 glBegin (GL_POLYGON);130 glVertex3f (flake_size / 2, 0.0, 0.0);131 glVertex3f (0.0, flake_size * sqrt (3.0) / 2.0, 0.0);132 glVertex3f (-flake_size / 2, 0.0, 0.0);133 glEnd ();134 glEndList ();135136 flake_indx = glGenLists (1);137 glNewList (flake_indx, GL_COMPILE);138 glPushMatrix ();139 glCallList (tmp_indx);140 glPushMatrix ();

Page 14: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

180 N. Ohno and A. Kageyama

141 glRotatef (180.0, 1.0, 0.0, 0.0);142 glTranslatef (0.0, -flake_size / sqrt (3.0), 0.0);143 glCallList (tmp_indx);144 glPopMatrix ();145 glEndList ();146 }147148 void149 draw (struct _snowdata *snows)150 {151 int i;152153 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);154155 for (i = 0; i < NFLAKES; i++)156 {157 glPushMatrix ();158 glTranslatef (snows[i].xpos, snows[i].ypos,159 snows[i].zpos);160 glRotatef (snows[i].spin,161 snows[i].xaxis, snows[i].yaxis,162 snows[i].zaxis);163 glCallList (flake_indx);164 glPopMatrix ();165 }166167 }

The function compute(struct snowdata *) [line 95] is called in theApplication Computation Process. This function calculates the coordinates and therotation-angles of the snowflakes. Because the results are stored on the shared mem-ory, the Display Processes can access them and draw the snowflakes rotating andfalling in the CAVE.

As suggested in compute [line 95] and draw [line 149], in which only the y-component of the coordinates is changed to simulate the falling snowflakes. Thecoordinate system of the CAVE is set as shown in Fig. 10. (Make sure of the coor-dinate system of your CAVE system especially when your CAVE has less than fourscreens.)

The function to allocate the shared memory, void *CAVEMalloc(size t),must be called between CAVEConfigure and CAVEInit, so init shmem iscalled at line 48. The function float CAVEGetTime() returns the seconds passedsince the initialization of the CAVE. The default limit of the shared memory is 8MB.If you want to increase it, useint CAVESetOption(CAVEID pid, int size) and CAVE SHMEM SIZEfor pid, with the size in bytes.

Page 15: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 181

Fig. 10. Coordinate system of BRAVE.

Here is one more sample program for the animation. This program takes you theouter space to see the solar system [Fig. 11].

1 /*2 *--------------------------------------------------------3 * Sample code : solar_system.c4 *5 * by Nobuaki Ohno, 20056 *7 *--------------------------------------------------------8 */910 #include <cave_ogl.h>11 #include <GL/glu.h>12 #include <stdlib.h>13 #include <unistd.h>14 #include <strings.h>15 #include <math.h>1617 #define PI 3.1415918 #define NUM_PLANET 1019 #define YPOS 5.020 #define ORBIT_MAG 1.521 #define PLANET_MAG 0.152223 /* The data that will be shared between processes */24 struct _planetdata {25 float xpos;26 float ypos;

Page 16: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

182 N. Ohno and A. Kageyama

27 float zpos;28 };2930 void init_gl(void), draw(struct _planetdata *);31 struct _planetdata *init_shmem(void);32 void compute(struct _planetdata *);3334 GLUquadricObj *sphereOBJ;35 GLUquadricObj *diskOBJ;3637 GLuint orbits;38 GLuint planet_obj[NUM_PLANET];39 /*40 0: Mercury, 1: Venus, 2: Earth, 3: Mars41 4: Jupitar, 5: Satrun, 6: Uranus, 7: Neptune, 8: Pluto42 */4344 GLfloat planet_color[NUM_PLANET][3] = {45 {1.0, 0.89, 0.76}, {1.0, 0.49, 0.31}, {0.0, 0.0, 1.0},46 {0.82, 0.41, 0.12}, {0.96, 0.96, 0.86}, {1.0, 0.92, 0.76},47 {0.69, 0.77, 0.05}, {0.0, 0.0, 1.0}, {0.5, 0.5, 0.05}48 };4950 GLfloat planet_rad[NUM_PLANET] =51 { 0.38, 0.95, 1.0, 0.53, 11.2, 9.5, 4.0, 3.9, 0.18 };52 float rev_rad[NUM_PLANET] =53 { 0.39, 0.72, 1.0, 1.5, 5.2, 9.6, 19.1, 30.2, 39.5 };54 float period[NUM_PLANET] =55 { 0.24, 0.63, 1.0, 1.9, 11.9, 29.5, 84.0, 165.0, 247.0 };5657 main(int argc, char **argv)58 {59 struct _planetdata *planet;60 CAVEConfigure(&argc, argv, NULL);61 planet = init_shmem();62 CAVEInit();63 CAVEInitApplication(init_gl, 0);64 CAVEDisplay((CAVECALLBACK) draw, 1, planet);65 while (!CAVEgetbutton(CAVE_ESCKEY)) {66 compute(planet);67 sginap(1);68 }69 CAVEExit();70 }717273 struct _planetdata *init_shmem(void)

Page 17: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 183

74 {75 int i;76 struct _planetdata *planet;7778 planet =79 (_planetdata *) CAVEMalloc(NUM_PLANET *80 sizeof(struct _planetdata));81 bzero(planet, NUM_PLANET * sizeof(struct _planetdata));8283 for (i = 0; i < NUM_PLANET; i++) {8485 planet[i].xpos = ORBIT_MAG * rev_rad[i];86 planet[i].ypos = YPOS;87 planet[i].zpos = 0.0;8889 }9091 return planet;92 }9394 void compute(struct _planetdata *planet)95 {96 int i;97 float angle;98 float t = CAVEGetTime();99100 for (i = 0; i < NUM_PLANET; i++) {101 angle = (int) (t * 50.0 / period[i]) % 360;102103 planet[i].xpos =104 ORBIT_MAG * rev_rad[i]105 * cos(2.0 * PI * angle / 360.0);106 planet[i].zpos =107 ORBIT_MAG * rev_rad[i]108 * sin(2.0 * PI * angle / 360.0);109110 }111 }112113 void init_gl(void)114 {115 int i, j;116 GLfloat diffuse[4];117 GLfloat ambient[4];118 GLfloat specular[4] = { 1.0, 1.0, 1.0, 1.0 };119120 GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 0.0 };

Page 18: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

184 N. Ohno and A. Kageyama

121 GLfloat light_ambient[] = { 0.3, 0.3, 0.3, 0.0 };122 GLfloat light_specular[] = { 1.0, 1.0, 1.0, 0.0 };123 GLfloat light_position[] = { 0.0, 1.0, 1.0, 0.0 };124125 glEnable(GL_LIGHT0);126127 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);128 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);129 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);130 glLightfv(GL_LIGHT0, GL_POSITION, light_position);131132 glColor3f(1.0, 1.0, 1.0);133 glClearColor(0., 0., 0., 0.);134135 sphereOBJ = gluNewQuadric();136 diskOBJ = gluNewQuadric();137138 ambient[3] = 1.0;139 diffuse[3] = 1.0;140141 for (i = 0; i < NUM_PLANET; i++) {142143 ambient[0] = planet_color[i][0];144 ambient[1] = planet_color[i][1];145 ambient[2] = planet_color[i][2];146147 diffuse[0] = 0.75 * planet_color[i][0];148 diffuse[1] = 0.75 * planet_color[i][1];149 diffuse[2] = 0.75 * planet_color[i][2];150151152 planet_obj[i] = glGenLists(1);153 glNewList(planet_obj[i], GL_COMPILE);154 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);155 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);156 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);157 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);158159 gluSphere(sphereOBJ,160 planet_rad[i] * PLANET_MAG, 32, 32);161162 if (i == 5) { /* For Saturn’s ring */163 glPushMatrix();164 glRotatef(75.0, 1.0, 0.0, 0.0);165 gluDisk(diskOBJ, 1.2 * PLANET_MAG * planet_rad[i],166 2.25 * PLANET_MAG * planet_rad[i], 32, 32);167 glPopMatrix();

Page 19: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 185

168 }169 glEndList();170 }171172 orbits = glGenLists(1);173 glNewList(orbits, GL_COMPILE);174175 for (i = 0; i < NUM_PLANET; i++) {176177 glBegin(GL_LINE_STRIP);178 for (j = 0; j < 720; j++) {179180 glVertex3f(ORBIT_MAG * rev_rad[i]181 * cos(2.0 * PI * j / 360.0),182 YPOS,183 ORBIT_MAG * rev_rad[i]184 * sin(2.0 * PI * j / 360.0));185186 }187 glEnd();188189 }190191 glEndList();192193 }194195 void draw(struct _planetdata *planet)196 {197 int i;198199 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);200201 glCallList(orbits);202203 glEnable(GL_LIGHTING);204205 for (i = 0; i < NUM_PLANET; i++) {206207 glPushMatrix();208 glTranslatef(planet[i].xpos,209 planet[i].ypos, planet[i].zpos);210211 glCallList(planet_obj[i]);212213 glPopMatrix();214 }

Page 20: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

186 N. Ohno and A. Kageyama

215216 glDisable(GL_LIGHTING);217 }

The orbits of the planets are supposed to be pure circles in this program. Incorpo-rating more accurate orbits and periods of the revolutions, the sun, and comets as wellas texture mapping to the planets for more realistic appearance are left to the readers.

Fig. 11. Nine planets revolve around the origin.

3.5 Stereo Glasses and WandAs we mentioned, the Tracking Process detects the positions and directions of the

stereo glasses and the wand all the time and you can retrieve the data. The TrackingProcess also detects the states of the buttons and joystick of the wand, for exam-ple, whether the left button are pressed or not. You can create a highly interactiveapplication by using following functions,

• void CAVEGetPosition(CAVEID pid, float vec[3]),

• void CAVEGetVector(CAVEID vid, float vec[3]).

Various positions can be obtained by the former function. For example, Setting“pid” CAVE HEAD, and you can obtain the viewer’s position via vec[3]. Andthe directions can also be obtained by the latter function. The obtained vector is au-tomatically normalized. The pids and vids are summarized in Table 5 and Table 6.

The change of button’s state can be retrieved by

• int CAVEButtonChange(int button) /* button = 1, 2, 3 */.

Page 21: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 187

Table 5. pids for positions

Stereo Glasses Wand

CAVE HEAD CAVE WAND

CAVE LEFT EYE

CAVE RIGHT EYE

Table 6. vids for direction

Stereo Glasses Wand

CAVE HEAD FRONT CAVE WAND FRONT

CAVE HEAD BACK CAVE WAND BACK

CAVE HEAD LEFT CAVE WAND LEFT

CAVE HEAD RIGHT CAVE WAND RIGHT

CAVE HEAD UP CAVE WAND UP

CAVE HEAD DOWN CAVE WAND DOWN

If the state does not change compared to the one you checked last time, this functionreturns 0. It returns 1, if the button has been pressed, and -1 if released.

There are some useful macros for the wand. The macros CAVEBUTTON1,CAVEBUTTON2 and CAVEBUTTON3 give us whether each wand button is beingpressed or not. If being pressed, it returns value 1, and if not, value 0.

Some functions and macros introduced here are used in the following program.This program makes your wand a “beam sword” like the one appearing in sciencefiction movies (but you cannot cut anything with it). When pressing the left button ofthe wand, the wand is emitting a pale green blade [Fig. 12].

1 /*2 *--------------------------------------------------------3 * Sample code : sword.c4 *5 * by Nobuaki Ohno, 20056 *7 *--------------------------------------------------------8 */910 #include <cave_ogl.h>11 #include <unistd.h>1213 #define LENGTH 3.01415 /* The data that will be shared between processes */

Page 22: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

188 N. Ohno and A. Kageyama

16 struct _sworddata17 {18 float wand[3];19 float tip[3];20 int on;21 };2223 void init_gl (void), draw (struct _sworddata *);24 struct _sworddata *init_shmem (void);25 void compute (struct _sworddata *);2627 main (int argc, char **argv)28 {29 struct _sworddata *sword;30 CAVEConfigure (&argc, argv, NULL);31 sword = init_shmem ();32 CAVEInit ();33 CAVEInitApplication (init_gl, 0);34 CAVEDisplay ((CAVECALLBACK) draw, 1, sword);35 while (!CAVEgetbutton (CAVE_ESCKEY))36 {37 compute (sword);38 sginap (1);39 }40 CAVEExit ();41 }424344 struct _sworddata *45 init_shmem (void)46 {47 int i;48 struct _sworddata *sword;4950 sword = (_sworddata *) CAVEMalloc (51 sizeof (struct _sworddata));5253 for (i = 0; i < 3; i++)54 {55 sword->wand[i] = 0.0;56 sword->tip[i] = 0.0;57 }5859 sword->on = 0;6061 return sword;62 }

Page 23: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 189

6364 void65 compute (struct _sworddata *sword)66 {6768 int i;69 float w[3], d[3], t[3];7071 if (CAVEBUTTON1)72 {73 CAVEGetPosition (CAVE_WAND, w);74 CAVEGetVector (CAVE_WAND_FRONT, d);7576 for (i = 0; i < 3; i++)77 {78 t[i] = LENGTH * d[i] + w[i];79 sword->wand[i] = w[i];80 sword->tip[i] = t[i];81 }82 sword->on = 1;83 }84 else85 {86 sword->on = 0;87 }88 }8990 void91 init_gl (void)92 {93 glDisable (GL_LIGHTING);94 glClearColor (0., 0., 0., 0.);9596 }9798 void99 draw (struct _sworddata *sword)100 {101102 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);103104 if (sword->on)105 {106 glLineWidth (12.0);107 glBegin (GL_LINES);108 glColor3f (1.0, 1.0, 1.0);109 glVertex3fv (sword->wand);

Page 24: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

190 N. Ohno and A. Kageyama

110 glColor3f (0.7, 1.0, 0.5);111 glVertex3fv (sword->tip);112 glEnd ();113114 }115 }

If you do not want to keep pressing the left button of the wand to make it emittingthe blade, use CAVEButtonChange(1) instead of CAVEBUTTON1 in compute.If you replace compute by the following, you can switch on and off the blade bypushing the left button.

1 void2 compute (struct _sworddata *sword)3 {45 int i;6 float w[3], d[3], t[3];78 if(CAVEButtonChange(1) == -1) {910 if(sword->on == 0) sword->on = 1;11 else sword->on = 0;1213 }141516 if (sword->on == 1)17 {18 CAVEGetPosition (CAVE_WAND, w);19 CAVEGetVector (CAVE_WAND_FRONT, d);2021 for (i = 0; i < 3; i++)22 {23 t[i] = LENGTH * d[i] + w[i];24 sword->wand[i] = w[i];25 sword->tip[i] = t[i];26 }2728 }293031 }

Note that if your wand has four buttons, CAVEButtonChange(4)and CAVEBUTTON4 works for the fourth button.

Page 25: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 191

Fig. 12. The wand emitting a pale green blade.

The macros CAVE JOYSTICK X and CAVE JOYSTICK Y give us the coordi-nates of joystick, namely how much the trackball (joystick) is moved from the neutralposition, in range from -1.0 to 1.0. Here, X means left-right direction and Y meansup-down direction. They will be used in the program in the next subsection.3.6 Navigation

You can walk in the CAVE’s 3m×3m×3m room, and the magnetic head trackingsystem automatically adjusts the screen images as you move. When you want to lookthe backside of an object floating in front of you in the center of the CAVE room, justwalk through the object and turn around. But what if the object is floating in the spaceover the other side of a CAVE’s wall screen? For those cases CAVELib provides aconvenient mechanism called navigation which enables you to translate or rotate thecoordinates (or CAVE room) in the VR world by calling the following functions,

• void CAVENavTranslate(float, float, float),

• void CAVENavRot(float, char),

/* first argument is the angle and the second is the axis */

• void CAVENavTransform().

The following program is a modified version of “Snowfall.c” with navigation.The function navigate is added [line 184] and called in the “while loop” in themain function, andCAVENavTransform is added [line 157] in the draw in the Snowfall.c. Movingthe joystick up or down, the CAVE room (and you) moves into the direction where

Page 26: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

192 N. Ohno and A. Kageyama

the wand points in the VR world, and moving it left or right, that of the room ro-tates [Fig. 13]. As a result, you can move the objects to where you want in the VRworld by this mechanism.

Fig. 13. Concept of Navigation. The object is isosurface of pressure of spherical tokamakplasma [Mizuguchi:2000].

1 /*2 *--------------------------------------------------------3 * Sample code : Snowfall_nav.c4 *5 * by Akira Kageyama, 19986 * modified by Nobuaki Ohno, 20057 *8 *--------------------------------------------------------9 */1011 #include <cave_ogl.h>12 #include <GL/glu.h>13 #include <stdlib.h>14 #include <unistd.h>15 #include <strings.h>1617 #define NFLAKES 50018 #define XMAX 20.019 #define YMAX 20.020 #define ZMAX 10.021 #define XMIN (-20.0)22 #define YMIN (-5.0)23 #define ZMIN (-20.0)2425 #define SPEED 5.0f26 /* Max navigation speed in feet per second */2728 /* The data that will be shared between processes */29 struct _snowdata30 {

Page 27: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 193

31 float xpos;32 float ypos;33 float zpos;34 float xaxis;35 float yaxis;36 float zaxis;37 float spin;38 float color[3];39 };4041 void init_gl (void), draw (struct _snowdata *);42 struct _snowdata *init_shmem (void);43 void compute (struct _snowdata *);44 void navigate (void);4546 static GLuint flake_indx;4748 main (int argc, char **argv)49 {50 struct _snowdata *snows;51 CAVEConfigure (&argc, argv, NULL);52 snows = init_shmem ();53 CAVEInit ();54 CAVEInitApplication (init_gl, 0);55 CAVEDisplay ((CAVECALLBACK) draw, 1, snows);56 while (!CAVEgetbutton (CAVE_ESCKEY))57 {58 compute (snows);59 navigate ();60 sginap (1);61 }62 CAVEExit ();63 }6465 float66 randmf (void)67 {68 float r, rndmax;6970 rndmax = (float)(RAND_MAX + 1);71 r = rand () / rndmax;7273 return r;74 }7576 struct _snowdata *77 init_shmem (void)

Page 28: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

194 N. Ohno and A. Kageyama

78 {79 int i;80 struct _snowdata *snows;8182 snows = (_snowdata *) CAVEMalloc (83 NFLAKES * sizeof (struct _snowdata));84 bzero (snows, NFLAKES * sizeof (struct _snowdata));8586 for (i = 0; i < NFLAKES; i++)87 {88 snows[i].xpos = XMIN + (XMAX - XMIN) * randmf ();89 snows[i].ypos = YMIN + (YMAX - YMIN) * randmf ();90 snows[i].zpos = ZMIN + (ZMAX - ZMIN) * randmf ();91 snows[i].xaxis = randmf ();92 snows[i].yaxis = randmf ();93 snows[i].zaxis = randmf ();9495 snows[i].color[0] = randmf ();96 snows[i].color[1] = randmf ();97 snows[i].color[2] = randmf ();98 }99100 return snows;101 }102103 void104 compute (struct _snowdata *snows)105 {106 int i;107 float y, angle, velocity = 0.5;108 float t = CAVEGetTime ();109 static float prev_t = 0.0;110111 for (i = 0; i < NFLAKES; i++)112 {113 y = snows[i].ypos - velocity * (t - prev_t);114 if (y < YMIN)115 y = YMAX;116 snows[i].ypos = y;117 angle = t * 50;118119 angle = (int)angle % 360;120121 snows[i].spin = angle;122123 }124 prev_t = t;

Page 29: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 195

125 }126127 void128 init_gl (void)129 {130 float flake_size = 0.5;131 GLuint tmp_indx;132133 glDisable (GL_LIGHTING);134 glClearColor (0., 0., 0., 0.);135136 tmp_indx = glGenLists (1);137 glNewList (tmp_indx, GL_COMPILE);138 glBegin (GL_POLYGON);139 glVertex3f (flake_size / 2, 0.0, 0.0);140 glVertex3f (0.0, flake_size * sqrt (3.0) / 2.0, 0.0);141 glVertex3f (-flake_size / 2, 0.0, 0.0);142 glEnd ();143 glEndList ();144145 flake_indx = glGenLists (1);146 glNewList (flake_indx, GL_COMPILE);147 glPushMatrix ();148 glCallList (tmp_indx);149 glPushMatrix ();150 glRotatef (180.0, 1.0, 0.0, 0.0);151 glTranslatef (0.0, -flake_size / sqrt (3.0), 0.0);152 glCallList (tmp_indx);153 glPopMatrix ();154 glEndList ();155 }156157 void158 draw (struct _snowdata *snows)159 {160 int i;161162 glClear (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);163164 CAVENavTransform ();165166 for (i = 0; i < NFLAKES; i++)167 {168169 glColor3fv (snows[i].color);170171 glPushMatrix ();

Page 30: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

196 N. Ohno and A. Kageyama

172 glTranslatef (snows[i].xpos, snows[i].ypos,173 snows[i].zpos);174 glRotatef (snows[i].spin,175 snows[i].xaxis, snows[i].yaxis,176 snows[i].zaxis);177 glCallList (flake_indx);178 glPopMatrix ();179 }180181 }182183 void184 navigate (void)185 {186187 float wfront[3], nav;188 float jx = CAVE_JOYSTICK_X, jy = CAVE_JOYSTICK_Y, dt, t;189 static float prevtime = 0;190191 t = CAVEGetTime ();192 dt = t - prevtime;193194 if (fabs (jy) > 0.2)195 {196 CAVEGetVector (CAVE_WAND_FRONT, wfront);197198 nav = jy * SPEED * dt;199200 CAVENavTranslate (wfront[0] * nav,201 wfront[1] * nav,202 wfront[2] * nav);203 }204205 if (fabs (jx) > 0.2)206 CAVENavRot (-jx * 90.0f * dt, ’y’);207208 prevtime = t;209210 }

You can go away from the snow falling area by moving the joystick of the wand[Fig. 14]. Another major change applied to this program is the color of the snowflakes.

Notice that NAV has to be attached to the “pid” and “vid” in the previous sub-section to get the positions and the directions of the glasses and wand in the navigatedcoordinate.

Page 31: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 197

Fig. 14. (a) The viewer is in the snow falling area. (b) The snow falling area is half outside the CAVEroom by the navigation.

3.7 Summary of this sectionSo far, we introduced 15 CAVELib functions and 2 kinds of macros which are

summarized in Table 7. Those would be minimum set to make basic CAVE applica-tions. If you want to know more about CAVELib, see CAVELib User and ReferenceGuide7. Our CAVE programming guide [Kageyama:1998] written in Japanese isavailable in our web site8.

4 Virtual LHDBased on the CAVELib explained in the previous section and OpenGL CG tech-

niques, one of the authors (A. Kageyama) developed Virtual LHD program [seeFigs. 15 and 16]9. The LHD (Large Helical Device) is a fusion experiment deviceat National Institute for Fusion Science (NIFS), Japan. Mimicking the real LHD, Vir-tual LHD has toroidal and poloidal coils and vacuum vessel. The viewer in the CAVEcan walk through the virtual LHD which is shown in the real scale size. The reality isso high that many people experiencing this program for the first time stretched theirarms trying to touch the coils. Virtual LHD program reads MHD equilibrium datacalculated by HINT code [Harafuji:1989] which is one of the standard codes for theMHD equilibrium of helical systems. One sees magnetic surfaces, field lines, particleorbits, pressure isosurfaces in the CAVE. One can interactively change the isosur-face level by “touching” a virtual level bar in the CAVE. Details of the Virtual LHDprogram was described in [Kageyama:1998].

Although this software was very useful, it could be used only for analyzing LHDsimulation data. We concluded that making a CAVE software for each simulation,

7http://www.vrco.com/8http://www.es.jamstec.go.jp/esc/research/Solid/members/kage/profile/papers/1998 cave manual.pdf9http://www.es.jamstec.go.jp/esc/research/Solid/members/kage/vlhd/index.en.html

Page 32: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

198 N. Ohno and A. Kageyama

Table 7. CAVELib Functions and MacrosFunctions and Macros

Basic Functions void CAVEConfigure(int *, char **, char **)

CAVEInit()

void CAVEInitApplication(CAVECALLBACK, int, ...)

CAVEDisplay(CAVECALLBACK, int, ...)

void CAVEExit()

int CAVESetOption(CAVEID, int)

Shared Memory void *CAVEMalloc(size t)

Tracking void CAVEGetPosition(CAVEID pid, float v[3])

void CAVEGetVector(CAVEID vid, float v[3])

Wand int CAVEButtonChange(int)

CAVEBUTTONn, n = 1, 2, 3

CAVE JOYSTICK x, x = X, Y

Navigation void CAVENavTranslate(float, float, float)

void CAVENavRot(float, char)

void CAVENavTransform()

Others float CAVEGetTime()

boolean CAVEgetbutton(CAVE DEVICE ID)

Fig. 15. Helical coils and a pressure isosurface. By touching a level bar (not seen) by the wand, theisosurface level is interactively controlled. The wand is a portable controller with buttons.

one by one, was not productive. So, we started development of a general-purpose VRvisualization software called VFIVE for the scientific VR visualization in the CAVEsystems.

Page 33: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 199

Fig. 16. A magnetic field line. The field line tracing starts from the wand tip position when a button ispressed.

5 General-Purpose CAVE Visualization Software VFIVEThe development of VFIVE10 started around 1999 [Kageyama:2000] and the lat-

est stable version is v3.7. The present development version with major revise is v3.8.The very final version of VFIVE will be v5.

Fig. 17. Interactive menu of our original VR visualization software VFIVE.

5.1 VFIVE v3.7The basic design and core functions of VFIVE are almost fixed in v3.7, which

are summarized in Table 8. A great emphasis was placed on fully interactive controlof the visualization methods, data, and the user interface in the CAVE’s VR environ-ment. For example, one can control the isosurface levels by vertical motion of thehand with the wand; it is also possible to change the slice position of orthoslicer bythe wand’s motion. From our experience of using the CAVE as a scientific visualiza-tion tool from the end of 1990’s [Kageyama:1999], we see that a common pitfall is to

10http://www.es.jamstec.go.jp/esc/research/Solid/members/kage/vfive/index.html

Page 34: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

200 N. Ohno and A. Kageyama

use it just as a (very expensive) “3-D object viewer”. We should make the best use ofCAVE’s VR features; that is stereo, immersive, and especially interactive view.

We implemented several kinds of visualization methods for vector fields. All ofthem make use of the VR features of the CAVE. For example, vector arrows showstens of small arrows around your hand, within an invisible sphere of diameter of2 feet. As you move your hand, all the arrows follow your hand’s motion. Thelength and direction of each arrow indicates the vector at the sampled point. Theinterpolation is automatically applied in real time.

Table 8. VFIVE v3.7function Figure

user interface virtual menu panel fig. 17

virtual laser beam fig. 17

scalar field vis. ortho-slice planes fig. 18

local slice plane not shown

isosurface fig 18

vector field vis. tracer particles fig. 19

field (force) lines (fig. 23)

vector arrows fig. 20

spotlighted particles not shown

Fig. 18. Scalar field visualization by isosurface, and orthoslicer.

Page 35: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 201

Fig. 19. Vector field visualization by tracer particles. When you press a wand button in the CAVE room,a tracer particle appears at the tip of the wand. You can intuitively and directly decide the startingpositions of the tracers by controlling the wand’s (or your hand’s) position.

Fig. 20. Interactive vector field visualization by arrows with the isosurface rendering. The arrows changethe length and direction, following your hand’s motion in real time with the automatic interpolation ofthe vector field.

5.2 VFIVE v3.8Recently, we have improved the VFIVE in two major aspects: First, we included

an important scalar visualization method that was missing in the previous version;volume rendering [Drebin:1988]. Another improvement is that we have integratedsome basic modules of VTK into VFIVE.

Page 36: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

202 N. Ohno and A. Kageyama

Table 9. New features in VFIVE v3.8

function Figure

scalar field vis. volume rendering fig. 21

contour lines (VTK) fig. 22

vector field vis. tubed stream lines (VTK) fig. 23

stream surfaces (VTK) fig. 24

The volume rendering is a visualization method of scalar fields that is useful,for example, to show the distribution of plasma density ρ(x, y, z) of the 3-D globalsimulation of the magnetosphere. It is known that ρ is highly localized near the Earth.The isosurface is not useful for the visualization of this kind of scalar field; you needto try nearly infinite number of different isosurface levels to grasp the overall 3-Ddistribution of ρ. Similarly, the orthoslicer is not useful because one needs to try alot of slices to grasp 3-D distribution of ρ. The volume rendering fits this kind ofvisualization of 3-D scalar field. We have developed a volume rendering module ofVFIVE and slotted into v3.8.

Generally, the volume rendering is considered as a “heavy” visualization tech-nique for the CAVE-type VR systems since it requires millions of ray cast calculationper second to realize the real time response to viewer’s eyes motion in the CAVEroom. We succeeded in realizing a very fast volume rendering by the 3-D texture-map technique [Schroeder:2002]. In this technique, many semi-transparent texturemapped slices, which are orthogonal to the viewer’s line of sight, are pulled out fromthe 3-D volumetric data. The 3-D volumetric data is made in advance from the scalarfield (such as ρ) by specifying the colors and opacities of each box element (voxel).The texture slices are blended by the graphics card. Therefore, we can avoid theheavy calculations of software ray casting. This is the reason why we can carry outthe fast volume rendering in the CAVE. For example, the refresh rate of the volumerendering shown in Fig. 21 (vorticity distribution of Earth’s outer core) is severalframes per second, which is satisfactory for our visualization purpose.

The VTK (Visualization Tool Kit)11 is an general visualization software that in-cludes many visualization methods. It is an attractive idea to combine VFIVE’s inter-active visualization environment in the CAVE with VTK’s sophisticated visualizationgismos. There are several previous works [Rajlich:1998, Hall:1999, Shamonin:2002]to use VTK in the CAVE. Among them, we follow the idea of vtkActorToPF [Ra-jlich:1998]. A difference from the original vtkActorToPF is that we do not useOpenGL Performer. We have revised VFIVE that the Application Computation Pro-cess computes the polygonal data by VTK and send them to the Display Processesvia the hard disk drive, and the Display Processes receive and draw the data. In thisway we have succeeded to integrate some basic visualization methods of VTK into

11see also http://public.kitware.com/VTK/

Page 37: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 203

Fig. 21. Real time volume rendering implemented in VFIVE v3.8 with arrows. Compare with isosurfacerendering in Fig. 20. The high speed volume rendering is realized by the 3-D texture-map technique.

Fig. 22. Contour lines by VTK in VFIVE v3.8. The pressure of MHD simulation of the Earth’s magne-toshere is visualized.

VFIVE v3.8. For instance, we can show VTK’s contour lines [Fig. 22], tubed flowlines [Fig. 23], stream surfaces [Fig. 24] in the CAVE (see Table 9).

6 SummarySince the output data of 3-D computer simulation today are highly complicated,

the visualization should be performed in a 3-D, interactive, and immersive environ-ment. Modern VR technology provides us such an opportunity. Among various VRsystems available today, we believe that the CAVE system is superior to others for ourpurpose. As we explained in this chapter, developing a CAVE application program is

Page 38: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

204 N. Ohno and A. Kageyama

Fig. 23. Stream tube by VTK in VFIVE v3.8. The tube’s color changes according to local amplitude ofthe vector field. The tube’s diameter can also be changed by the amplitude if one wishes. Here, the flowvelocity of the solar wind is visualized. The geomagnetic field is also visualized by the (not tubed) fieldlines.

Fig. 24. Stream surfaces by VTK in VFIVE v3.8. The color changes according to the local amplitude ofthe vector field. The flow velocity of the solar wind is visualized. The pressure is also visualized bycontour lines

not difficult owing to the sophisticated CAVELib. Our sample programs will providea good starting point for your own visualization software for the CAVE.

The main obstacle for popularization of the CAVE has been its cost. However,recent development of the graphics hardware for PCs is drastically changing the sit-uation. Inexpensive PC-based CAVE systems will predominate over more expensiveGWS-based CAVEs in near future.

We speculate that every supercomputer center in the world will install the CAVE-

Page 39: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 205

type VR facility for the VR visualization in future, and use the software like VFIVEfor practical and productive simulation science.

Acknowledgments. We thank all members of Advanced Perception Research Group of EarthSimulator Center for their help in the development of VFIVE v3.8 and Prof. Tatsuki Oginoat Nagoya Univ. and Dr. Naoki Mizuguchi at NIFS for providing us their MHD simulationdata We also thank Prof. Tetsuya Sato, the director-general of the Earth Simulator Center, forfruitful discussion and encouragement.

Appendix A. VTK in CAVEWhen you want to make a visualization software for the CAVE without taking

much time to study the visualization algorithms and methods, we suggest to use VTKin CAVE.

VTK is an general visualization software that includes many visualization meth-ods, from basic ones to sophisticated ones, with open source codes. The usage ofVTK is very simple. All you have to do is to make “VTK Pipeline”. The followingcode is a part of VTK pipeline implementing “contour lines”.

1 Array = vtkDoubleArray::New();23 x_coord = vtkDoubleArray::New();4 y_coord = vtkDoubleArray::New();5 z_coord = vtkDoubleArray::New();67 Rectidata = vtkRectilinearGrid::New();89 Lut = vtkLookupTable::New();10 CLines = vtkContourFilter::New();11 Mapper = vtkPolyDataMapper::New();12 Actor = vtkActor::New();1314 Array -> SetArray(elev_data, size, 1);1516 x_coord -> SetArray(coorddata->x, n1, 1);17 y_coord -> SetArray(coorddata->y, n2, 1);18 z_coord -> SetArray(&z, 1, 1);1920 Rectidata -> SetDimensions(n1, n2, 1);21 Rectidata -> SetXCoordinates(x_coord);22 Rectidata -> SetYCoordinates(y_coord);23 Rectidata -> SetZCoordinates(z_coord);2425 Rectidata -> GetPointData() -> SetScalars(Array);2627 Lut -> SetHueRange(0.7, 0.0);28 Lut -> Build();29

Page 40: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

206 N. Ohno and A. Kageyama

30 CLines -> SetInput(Rectidata);31 CLines -> GenerateValues(30, min, max);3233 Mapper -> SetInput(CLines -> GetOutput());34 Mapper -> SetLookupTable(Lut);35 Mapper -> SetColorModeToMapScalars();36 Mapper -> SetScalarRange(min, max);3738 Actor -> SetMapper(Mapper);

This VTK pipeline visualizes the data, whose size is n1 × n2 and pointer is“elev data” [line 14], by rainbow-colored 30 contour lines. The z-componentof the coordinate of the lines is set to be “z”. Looking at the code, you realize thatwith VTK, you can make pretty good visualization software without the knowledgeof the underlying algorithms of the visualization methods. However, using VTK ina CAVE application is not obvious because of VTK’s design. Some people workout the ways to do it. “vtkActorToPF” is a famous translator and the detail designis described in the paper [Leigh:1998] but this requires your CAVE application tobe written on IRIS Performer (or OpenGL Performer). “vtk2CAVE” is a translatorwhich does not require IRIS Performer. This software draws the polygonal data ofthe vtkActor copied on the shared memory by OpenGL. “VtkCave” is a library whichenables you to make CAVE applications with VTK. You can choose the translatorsand library depending on API or make a translator by yourselves if you want to useVTK in your CAVE applications.

ReferencesCruz-Neira, C., Sandin, D. J., and DeFanti, T. A., Surrounded-Screen Projection-Based Virtual Reality:

The Design and Implementation of the CAVE, ACM SIGGRAPH 93, 135–142, 1993.

Drebin, R. A., Carpenter, L., and Hanrahan, P., Volume Rendering, Computer Graphics, 22, 65–74, 1988.

Hall, M., “vtk2CAVE” Translator, 1999.http://www.cave.vt.edu/people/shore/vtk/vtk2CAVE/

Harafuji, K., Hayashi, T. and Sato, T., Computational study of three-dimensional magnetohydrodynamicequilibria in toroidal helical systems, J. Comput. Phys., 81, 169–192, 1989.

Kageyama, A. and Sato, T., CompleXcope Programming Guide, NIFS-MEMO-28, 1998; available athttp://www.es.jamstec.go.jp/esc/research/Solid/members/kage/profile/papers/1998 cave manual.pdf (inJapanese)

Kageyama, A., Hayashi, T., Horiuchi, R., Watanabe, K., and Sato, T., Data Visualization by a VirtualReality System, Proceedings of 16th International Conference on the Numerical Simulation of Plasmas,138–142, 1998.

Kageyama, A., Tamura, Y., and Sato, T., Scientific Visualization in Physics Research by CompleXcopeCAVE System, Trans. Virtual Reality Soc. Japan, 4, 717–722, 1999.

Kageyama, A., Tamura, Y., and Sato, T., Visualization of Vector Field by Virtual Reality, Progress Theor.Phys. Suppl., 138, 665–673, 2000.

Leigh, J., Rajlich, P., Stein, R., Johnson, A. E., DeFanti T. A., LIMBO/VTK: A Tool for Rapid Tele-Immersive Visualization, CDROM proceedings of IEEE Visualizaton ’98, 1998.

Mizuguchi, N., Hayashi, T. and Sato, T., Dynamics of spherical tokamak plasma on the internal reconnec-tion event, Physics of Plasmas, 7, 940–949, 2000.

Page 41: Introduction to Virtual Reality Visualization by the CAVE systemIntroduction to Virtual Reality Visualization by the CAVE system 169 absorption into the VR world, there are three important

Introduction to Virtual Reality Visualization by the CAVE system 207

Rajlich, P., “vtkActorToPF” Translator, 1998.http://brighton.ncsa.uiuc.edu/˜prajlich/vtkActorToPF/

Schroeder, W., Martin, K., and Lorensen, B., section 7.5, in The Visualization Toolkit, Third Edition, 496pp, Kitware Inc., New York, 2002.

Shamonin, D., “VtkCave” library, 2002.http://staff.science.uva.nl/˜dshamoni/myprojects/VtkCave.html

Shreiner, D., OpenGL Reference Manual, Fourth Edition, 736 pp, Addison-Wesley Professional, Mas-sachusetts, 2004.

Shreiner, D., Woo, M., Neider, J. and Davis, T., OpenGL Programming Guide, Fourth Edition, 560 pp,Addison-Wesley Professional, Massachusetts, 2003.

Tamura, Y., Kageyama, A., Sato, T., Fujiwara, S., and Nakamura, H., Virtual Reality System to Visuailzeand Aurolize Numerical Simulation Data, Comput. Phys. Comm., 142, 227–230, 2001.