BIONB 441: Spider GUI                    by Becky Chu

Introduction:

This project stemmed from Eileen Hebet's research of courtship displays among four species of wolf spiders. By enabling a scientist to easily manipulate morphological traits (i.e., by modifying color, diameter or length) and movement (i.e., by modifying courtship behavior), many more observations and experiments can be performed. This will help the scientist analyze animal behavior that would otherwise be difficult, if not impossible, to reproduce using live specimens.

Therefore, this project is a model and simulation of a wolf spider. A user interface needed to be provided to allow for easy manipulation of the animated spider. Therefore, the duo component of this project (i.e., the GUI as one component and the rendering of the spider as another component) is covered in two projects. The actual rendering of the spider is done using opengl/visual c++, while the GUI components are done using Matlab. This report primarily focuses on the GUI component since the focus of this course was on writing Matlab programs as applied to neurobiology and graphics. (For details on how the spider was rendered using opengl/visual c++ and on how the two programs interfaced with each other (i.e., using mex files so that Matlab programs recognized opengl/visual c++ rendering), see meng project report for details).

From this project, I not only learned the programming techniques needed to develop a graphical user interface, but also learned how to design and implement a complex project involving multiple components.


High level design:

The GUI component comprises of two general modules - one for manipulating morphological traits and another for manipulating spider animation. Thus, the GUI window is evenly divided to handle operations in both areas. In this section, I will describe each of the GUI components from a user's perspective (implementation details will be discussed in the Software design section below).

Startup Initialization:
Upon startup time, the parameters contained in a file called 'spider.txt' is loaded. However, no motion is applied to the spider for animation. By default, a file called 'motionfile' is named in the textbox in the lower right corner. In order to view the animation contained in this file, the 'load' button on its left needs to be clicked. (See 'Animation manipulation' section below for details).

The following Menu options are provided:
The menu options primarily focus on data input/output, changing between views of different species, color manipulation of general structures, and playing the animation of the spider. These menu options were created to allow for a broader view of the spider. Here is a list of all the menu items that are available, with a short description of each item:

'File'
'File->Load' Data specifying the spider's morphological traits is stored in ascii text files. Therefore, any spider with set parameters can be loaded by simply selecting a previously stored file from this menu item. (For formatting of such files, see Appendix A.) However, the best method to modify specific parameter settings is through the Graphical user interface. (i.e., see 'Morphological trait manipulation' section and 'Edit->Advanced' menu option below).
'File->Save' save file as ascii text. This will save all the parameter settings that have been changed in the current session to a text file that's specified by the user.
'File->Exit' same as the 'Quit' button on the GUI window. This closes the GUI window altogether.
'View'
'View->S. Duplex' Loads the data from a file called: 'duplex.txt'.
'View->S. Uetzi' Loads the data from a file called: 'uetzi.txt'
'View->S. Stridulans' Loads the data from a file called: 'stridulans.txt'
'View->S. Crassipes' Loads the data from a file called: 'crassipes.txt'
'Edit'
'Edit->Color' This is a submenu which enables the user to modify either the Body color or the Legs color. (For alternative methods of modifying individual legs or leg segment colors, see 'Morphological trait manipulation' section below)
'Edit->Background' Modifies background color.
'Edit->Lighting' This is a submenu which enables the user to modify one of three lighting options: Ambient, Diffuse or Specular Lighting.
'Edit->Advanced' This mode is only advised for the advanced user who wishes to modify individual parameters that can be found in the ascii text files. A simple user listbox is provided to allow the user to select specific parameters to modify. Once the selection has been made, the value of the text box is dynamically adjusted to the current parameter setting. Modifications can be made to the parameter by entering the desired value in the text box and subsequently clicking on the 'Apply' button.
'Play'
'Play->Play' The spider animation can be started by selecting this option. *Note: the spider will make the motion as applied by the 'Animation manipulation' section.
'Play->Stop' Stops spider animation. When the spider is restarted, the motion will be restarted as well. (see 'Animation manipulation' section for alternative methods to pause movement of the spider.)

Morphological trait manipulation:
The listbox provided in the upper left corner has 7 options. A description of each option is provided below.
'Leg Pair I' Refers to the leg pairs towards the front end of the spider.
'Leg Pair II' Refers to the leg pairs directly behind leg pair I.
'Leg Pair III' Refers to the leg pairs directly behind leg pair II.
'Leg Pair IV' Refers to the leg pairs towards the back end of the spider.
'Head' The front end of the first body segment.
'Thorax' The back end of the first body segment.
'Abdomen' The back body segment.
When selecting one of the leg pairs, 8 text boxes and 12 sliders appear in the upper right hand corner of the GUI window. The leg segments are ordered as follows: Leg segment 1 is the segment closest to the body. Leg segment 2 is the segment next closest to the body. Leg segment 4 is the furthest away from the body. See diagram below for details.

The rgb sliders allow individual leg segment colors to be changed. This option allows the scientist to add color to segment 1 of the foreleg, for example. A more general approach to modifying leg colors as a whole is to use the 'Edit->Color->Legs' menu option.

The text boxes allow changing of the each leg segment in length and radius. These units are represented in pixels. There is an important distinction to make between the leg pairs and the rest of the body segments. Selecting one of the other body segments (i.e., head, thorax, or abdomen) will pop up 3 text boxes. The units represented in one of these boxes relate to scale. That is, a text box will appear for height, width and length. However, in order to change the size of these body structures, enter a value that is proportional to the default size. The units were done in this way since the head, thorax and abdomen were made up of many different shapes (i.e., spheres, cylinders, and cones). Because of this, the units for each body segment was not easily changeable for the user through the GUI. However, the parameters are available in ascii text format so that the user can change the parameter settings for specific body segments easily. This requires some knowledge of the format of the files. See Appendix A for formatting details. Individual parameter settings may also be changed by the 'Edit->Advanced' menu option mentioned above.

Animation manipulation:
The last frame on the GUI window (i.e., the bottom frame) helps the user manipulate motion/animation of the spider. The following uicontrol buttons are present:

'Load' Loads the data found in the motionfile. The motionfile is specified in the Text box on the lower right hand corner of the GUI window.
'Save' Saves the spline interpolation data points to the filename specified in the text box on the lower right of the GUI window.
'Apply' Apply the motion that was specified in the spline interpolation plots to the spider. 'Apply' will create a spider if one was not present before.
'Quit' Same functionality as the 'File->Exit' menu option. This quits the entire spider_gui application.
There are four radio buttons present on the bottom of this GUI. Each radio button represents the angle which rotates the corresponding leg segment. See diagram of leg segments above in the 'Morphological trait manipulation' section. Angle '1' is the joint between segment 1 and the body. Angle '2' is the joint between leg segments 1 and 2. Angle '3' is the joint between leg segments 2 and 3. Lastly, angle '4' is the joint between leg segments 3 and 4. Since it only makes sense for these joints to move in one direction, the plots represent the direction with which each segment is allowed to move.

Pausing animation of the spider can also be controlled by clicking on the window where the spider is rendered. Simply click the window labelled 'Spider' to pause and play the animation. Note that using the 'Play->Stop' menu option in conjunction with this method may require the user to click on the 'Spider' window again if the spider was paused and then stopped.

Other user interface features that are contained in the spider window include viewing of the spider at different angles. Click inside the spider window and use the arrow keys on the keyboard to see rotated views of the spider.


Software design:

Implementation details:
There are 2 files in this program, one which builds the GUI components (spider_gui.m), and one which handles all the callbacks from a uicontrol (menu_callback.m). Subroutines contained in these files include functions which control the listbox options, color manipulation (rgb sliders), and loading of files for each of the species.

I created a variable called 'vars' that is essentially global since it is contained in the 'userdata' area of the main figure, figure(1):

vars = 

            myname: 'spider_gui'
     spline1button: 29.0006
     spline2button: 30.0006
     spline3button: 31.0006
     spline4button: 32.0006
          filename: 33.0006
       splineIndex: 1
              tmax: 120
        NumControl: 120
               FPS: 30
    ForceZeroSlope: 1
        AngleRange: 60
                 t: [1x120 double]
                tt: [1x3600 double]
        numSplines: 4
                 y: [120x4 double]
                yy: [3600x4 double]
                sp: 90.0005
             line1: 39.0012
         mousedown: 0
            values: {1x633 cell}
             names: {1x153 cell}
Most of the data contained here controls manipulations needed for spline interpolation. However, the main ones to take note of are the following:
vars.NumControl This controls the number of data points to include in the spline. Since more data points allow for a smoother motion, I've set vars.NumControl to 120.
vars.AngleRange For the angle range, the spider's motion needs to make sense (i.e., if the leg is extended too far back, the motion no longer looks realistic).
vars.values The main structure that controls all spider morphology and animation is contained in vars.values. There are a total of 633 data points contained in this structure. (The first 152 data points track color and morphology of the spider, while the other 481 points track the animation of the spider. (i.e, 120 points track each timestep for one angle/joint. Since there are 4 joints, this adds up to 480 points which track the leg motion. The last data point is used to track the maximum number of time steps that can occur - i.e., max_timestep = vars.NumControl)). This structure is passed to the opengl/visual c++ rendering of the spider through mex files. Implementation details of mex files can be found in the meng project report. However, details on system setup for mex file execution in Matlab is included in Appendix C

Data Input/Output:
The data needed for establishing the morphological traits (e.g., length, color and diameter) are specified in ascii text files. Therefore, users may manipulate the ascii text files directly. (See Appendix A for details on formatting of these files) However, the user interface is provided to allow manipulation of the data in a more coherent and intuitive fashion.
As a default setting, a generic spider is loaded from a file called 'spider.txt'. Therefore, this file needs to be present in the current working directory or Matlab will generate an error when trying to load the data from this file. Other default settings that require file loading include the 'View' menu options for each of the species. In addition, to these files, other files may be loaded and saved by the 'File' menu in the GUI window.
For the spider animation, if a predetermined motion is desired, a text box is supplied at the lower right corner of the GUI screen, rather than an option in one of the menus to avoid confusion with loading of morphological traits. Once the file is entered, clicking on the 'load' button to its left. This will load the data into the GUI application. The format of these files is not changeable through manual human intervention. Therefore, these files must always be generated from the GUI.


Results of the design:

The following diagrams show the GUI application that resulted from the above design decisions. Below is the initial GUI that is displayed when starting up the spider_gui application (see Appendix B for details on how these images were captured):

Next is an image of the GUI after selecting the 'abdomen' option in the listbox and setting the motion on the third angle to have some movement. *Note, the 'abdomen' and 'thorax' width scales are set to 1.5 in the 'spider.txt' parameter file. This is done to give the spheres and cones an elliptical shape for the body segments.

Below is an image of the 'Edit->Background' slider that appears when the menu option is chosen:

Here are samples of images that were created using the spider GUI application. (For more detailed spider images and animation, refer to meng project report.) The image to the left exemplifies specular lighting applied to the spider. The image to the right exemplifies animation that was stopped in mid-motion:


What I would do differently next time:

My primary goals during this project was to design and develop a program which would allow me to learn the essentials needed for computer graphics and GUI design, while applying this knowledge towards a simulation for a biologically based experiment. Since I was able to achieve my primary objectives, I feel satisfied with the methods I used. However, one thing I would likely do differently next time is choose to code the entire project (i.e. the rendering of the spider and the GUI application) in only one language (either Opengl/Visual C++ or Matlab). It seemed that opengl/visual c++ has a lot to offer in terms of rendering the spider using texture binding and such. However, since I was limited by time and resources, I was unable to take advantage of these features. In addition, the interface provided between mex files was limiting at times since I was only able to pass data through a vector. Therefore, I constantly had to ensure that all variables were up-to-date. Lastly, window management between the two applications (i.e., the GUI and the rendered Spider) was not intuitive. I could not find a way to render the spider image in the same window as the GUI due to constraints I found in passing the handle of the GUI figure to the spider program.


Appendix:

A. Formatting of text files:
These text files specify 152 morphological traits of a wolf spider. The parameters range anywhere from color specifications to length, width or scaling factors for individual segments of the spider morphology. See 'spider.txt' for example of a formatted file. The order of the parameters specified in the text files matters since each data point is copied into a vector and passed in as an argument to the opengl/visual c++ program. Therefore, there must always be 152 parameters in the same order as specified in the 'spider.txt' file. Each line of input in these files must also be as follows:
The <parameter value> must be numerical and contain no spaces afterward. However, note the space that exists between the <parameter name> and <parameter value>. Blank lines and commented lines (i.e., lines beginning with '%') are allowed and skipped by the program. Variables specified after the 152nd one are ignored by the program.

B. Capturing images of GUI application
The images contained in the results section of the report were captured using an application called snagit. Simply follow the instructions on the website to download and start using the program. The files contained in this report are simple jpg images that were captured by setting the 'Input' menu option to 'Window' and selecting the 'Image Capture' button.

C. Mex File Execution through Matlab
For this project, the following configurations were used during development:

  • Windows 2000
  • Microsoft Visual C/C++ version 6.0
  • Glut library version 3.7.6
  • Matlab 6p1
  • To execute the mex file, the libraries used for rendering the spider need to be present. This will require that Visual C++ is installed on the system. In addition to the opengl libraries packaged with Visual C++, the glut library needs to be downloaded and installed as well. Precompiled versions of the library can be found at http://www.opengl.org/developers/documentation/glut.html.

    Once the appropriate libraries are installed, the command 'mex -setup' needs to be ran from the Matlab prompt to ensure the system recognizes the appropriate compiler and links in the appropriate libraries (i.e. select the 'Microsoft Visual C/C++ compiler' when prompted). These setup instructions only need to be done once on a system to ensure that all mex files run properly in the future. For further information on mex file setup, please refer to mathworks documentation of mex files.


    References

  • Land, Bruce, medit2.m
  • Chapman, Stephen J., MATLAB Programming for Engineers, Chapter 10, Copyright 2000
  • Pratap, Rudra, Getting Started with MATLAB: A Quick Introduction for Scientists and Engineers, Version 6, Copyright 2002
  • http://www.mathworks.com
  • http://www.snagit.com