Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

gl_box Class Reference

A class to enable GL drawing in an FLTK window. More...

#include <gl_box.h>

List of all members.

Public Member Functions

void set_limits (double min_coords[3], double max_coords[3])
 Function to set the x, y and z limits of the data to display.

void reset_view ()
 Function to reset the viewing parameters for the gl_box.

void set_stereo (int option)
 Function to select between 4 stereo/fullscreen options.

void draw_axes ()
 Function to draw arrows for the x, y and z axes.

void draw_box ()
 Function to draw a single pixel wide box surrounding the data.

void copy_image_to_ppm ()
 Function to copy the current image to a ppm file.

void add_to_color (int i, int amount)
 Function to add or subtract 1 (or more) from a color component.

void set_movie (movie *m)
 Function to tell gl_box the current movie object.

void draw ()
 Function called by FLTK to draw the Fl_Gl_Window.

void draw_frame (bool left)
 Function to draw a frame.

void gl_init ()
 Function to set some initial values for OpenGL.

template<class T, class S> void draw (sphere< T, S > *s)
 Function to draw one sphere.

template<class T, class S> void draw (gl_cylinder< T, S > *c)
 Function to draw one cylinder.

int handle (int event)
 Function to handle keyboard and mouse events.

 gl_box (int x, int y, int w, int h, const char *label=0)
 Constructor which sets the location and size of the gl_box.


Public Attributes

moviem
 Pointer to the current movie object.

double eye [3]
 Current x, y, and z coordinates of the viewing point.

double focus [3]
 This is the x, y and z value for focusing the camera.

double min_coords [3]
 Minimum coordinates for all objects in all frames.

double max_coords [3]
 Maximum coordinates for all objects in all frames.

double max_diff
 Maximum difference over x, y and z dimensions between min_coords and max_coords.

ap_array< drawable > * objects
 Array of objects to draw.

ap_array< gl_cylinder_f > * gl_cylinders
 Array of gl_cylinders with float coordinates.

ap_array< gl_cylinder_s > * short_gl_cylinders
 Array of gl_cylinders with short int coordinates.

ap_array< byte > * pixels
 Array of bytes used when reading pixels from display memory to save a frame in a ppm file.

double distance
 Current distance from the view point to the origin.

double near_percent
 Percentage of the original far clipping distance to use as the front clipping distance.

double far_percent
 Percentage to add to the near_percent to compute the far clipping distance.

bool rotating
 Whether the image is being rotated.

int wobble
 Whether the image is wobbling.

double wobble_theta
 Angle of wobble.

timeval wobble_start
 Time when wobble was started.

timeval now
 Current time.

bool full
 Whether in fullscreen mode or not.

bool stereo
 Whether in stereo mode.

bool cross_eyed
 Whether in cross-eyed stereo mode.

double eye_separation
int spin_rate
 Rate of spin.

double spin
 Amount of spin (spin_rate * theta).

timeval last_spin
 Time of last spin calculation.

int save_detail
 Level of detail to save while rotating.

double save_delay
 Delay value to save while rotating.

int mouse_start_x
 Starting mouse x position for rotations.

int mouse_start_y
 Starting mouse y position for rotations.

int mouse_x
 Current mouse x for rotations.

int mouse_y
 Current mouse y for rotations.

Arcball * a
 Glui rotation control class.

Arcball * light_arcball
 Glui rotation control class for light.

ap_color bg_color
bool stop
 Whether frames are advancing or not.

bool lights
 Whether lighting is enabled.

bool blend
 Whether blending is enabled.

bool axes
 Whether axes should be drawn.

bool box
 Whether a box should be drawn.

bool save_frame
 Whether the next frame should be saved.

int save_movie
 Whether all the frames should be saved.

char * ppm_file
 File name for saving the frame.

const char * ppm_prefix
 File name prefix for saving frames.

int detail
 Level of detail for rendering.

GLUquadricObj * qobj
 Used to build OpenGL display lists.

int sphere_lists
 Starting value for sphere display lists.

int cylinder_lists
 Starting value for cylinder display lists.

int highlight
 Highlight index.

bool quash
 Whether the image motion is quashed.

bool need_to_copy
 Whether new spheres and cylinders need to be copied to the objects array before sorting.


Static Public Attributes

const double theta = 0.00025
 A small angle to multiply by spin to determine the current rotation angle.


Detailed Description

A class to enable GL drawing in an FLTK window.

FLTK uses an Fl_Gl_Window widget to provide access to OpenGL from an FLTK application. The simplest way to use Fl_Gl_Window is to derive your own class from it and over-ride the draw and handle functions.

The draw function is used to do all OpenGL drawing. It is called by the FLTK code whenever the window needs to be drawn. Sometimes when the draw function is called, the window's shape will have changed. This can be detected by calling the valid function. When valid returns false, it is necessary to reset the window size and viewing parameters for OpenGL.

The handle function is called with mouse and keyboard events. This class uses mouse events in the gl_box to control rotation of the data displayed using OpenGL.

The code for rotation is extracted from the <A HREF="http://www.cs.unc.edu/~rademach/glui/> GLUI code by Paul Rademacher. Glui provides a nice set of user interface widgets which are written using OpenGL and glut. The GLUI_Rotation widget provides an excellent tool for rotating an OpenGL object. After a short reading of the GLUI_Rotation code, I decided to try to use the classes below the GLUI_Rotation widget, all of which perform only numerical calculations. The separation of GUI code from the mathematics was perfect and there was not much required in gl_box to achieve the same sort of smooth rotations as in glui.


Constructor & Destructor Documentation

gl_box::gl_box int  x,
int  y,
int  w,
int  h,
const char *  label = 0
 

Constructor which sets the location and size of the gl_box.

The gl_box is placed in the Fl_Window wherever desired. Care needs to be taken to avoid any overlap between the gl_box and other objects in the main Fl_Window.

Parameters:
x The x coordinate for the gl_box relative to the main window.
y The y coordinate for the gl_box relative to the main window.
w The width for the gl_box.
h The height for the gl_box.
label A text string for the gl_box.


Member Function Documentation

void gl_box::set_limits double  min_coords[3],
double  max_coords[3]
 

Function to set the x, y and z limits of the data to display.

For a movie the minimum and maximum coordinates are based on all the frames of the movie file. For a molecule the limits are based on the atoms' coordinates.

Parameters:
min_coords Array of x, y, and z minimums
max_coords Array of x, y, and z maximums

void gl_box::reset_view  ) 
 

Function to reset the viewing parameters for the gl_box.

It sets the viewing position to the original position on the z axis with the focus being in the middle of the data. It also turns off spinning. Last it sets the size to the default which can be quite useful for molecules when it will result in proper atom/bond sizes.

void gl_box::set_stereo int  option  ) 
 

Function to select between 4 stereo/fullscreen options.

Parameters:
option Which stereo/fullscreen option
0 means not fullscreen or stereo 1 means fullscreen 2 means stereo 3 means cross-eyed stereo

void gl_box::draw_axes  ) 
 

Function to draw arrows for the x, y and z axes.

The x axis is red, the y axis is green and the z axis is blue.

void gl_box::draw_box  ) 
 

Function to draw a single pixel wide box surrounding the data.

void gl_box::copy_image_to_ppm  ) 
 

Function to copy the current image to a ppm file.

The file name is in ppm_file.

void gl_box::add_to_color int  i,
int  amount
 

Function to add or subtract 1 (or more) from a color component.

Animp uses the r, g, b, and a keys to subtract 1 from the red, green, blue and alpha values for the selected color. It uses the capital letters to add to these values. Modifications are limited to the 0-255 range.

Parameters:
i Color component to modify (0-3 for r,g,b,a)
amount Amount to add to the component

void gl_box::set_movie movie m  ) 
 

Function to tell gl_box the current movie object.

void gl_box::draw  ) 
 

Function called by FLTK to draw the Fl_Gl_Window.

Internally draw calls draw_frame(true) to draw the left frame and, if in stereo or cross-eyed stereo mode, it calls draw_frame(false) to draw the right frame.

void gl_box::draw_frame bool  left  ) 
 

Function to draw a frame.

Parameters:
left True if the frame to be drawn is the left of a stereo pair

void gl_box::gl_init  ) 
 

Function to set some initial values for OpenGL.

This function is called the first time the draw function is called. It set some defaults like the light and material parameters and prepares OpenGL display lists to make drawing faster.

template<class T, class S>
void gl_box::draw sphere< T, S > *  s  ) 
 

Function to draw one sphere.

This function is called from gl_box::draw() to draw one sphere. It sets the color and draws the sphere at the proper location using an OpenGL display list. There are 10 different display lists used to draw spheres - each with a different setting for the level of detail. Smaller spheres are drawn with less detail to speed up the rendering. This is a template class which allows using the same code to draw spheres with short int coordinates and spheres with float coordinates.

template<class T, class S>
void gl_box::draw gl_cylinder< T, S > *  c  ) 
 

Function to draw one cylinder.

This function is called from gl_box::draw() to draw one cylinder. It sets the color and draws the cylinder at the proper location using an OpenGL display list. There are 10 different display lists used to draw cylinders - each with a different setting for the level of detail. Smaller cylinders are drawn with less detail to speed up the rendering. This is a template class which allows using the same code to draw cylinders with short int coordinates and cylinders with float coordinates.

int gl_box::handle int  event  ) 
 

Function to handle keyboard and mouse events.

Keyboard and mouse events are passed into gl_box from FLTK when they are not directed for the GUI objects on the screen. The handle function uses only the mouse events. Mouse events control the rotation using the GLUI Arcball class.


Member Data Documentation

movie* gl_box::m
 

Pointer to the current movie object.

The gl_box code must display the objects in the frames maintained in the movie object. This makes it almost necessary to have access to the movie object in all the gl_box functions.

double gl_box::eye[3]
 

Current x, y, and z coordinates of the viewing point.

When gl_box rotates, it basically moves the eye position around on a sphere centered at the origin of the model space. This is necessary since distances to objects need to be computed. It is much easier to leave the object coordinates fixed and rotate the view point.

double gl_box::focus[3]
 

This is the x, y and z value for focusing the camera.

double gl_box::min_coords[3]
 

Minimum coordinates for all objects in all frames.

double gl_box::max_coords[3]
 

Maximum coordinates for all objects in all frames.

double gl_box::max_diff
 

Maximum difference over x, y and z dimensions between min_coords and max_coords.

ap_array<drawable>* gl_box::objects
 

Array of objects to draw.

Spheres and cylinders of various types need to be combined in one array to be sorted.

ap_array<gl_cylinder_f>* gl_box::gl_cylinders
 

Array of gl_cylinders with float coordinates.

Cylinders must be converted to gl_cylinders to be displayed. Gl_cylinders have a computed axis of rotation and an angle of rotation to be used when drawn.

ap_array<gl_cylinder_s>* gl_box::short_gl_cylinders
 

Array of gl_cylinders with short int coordinates.

ap_array<byte>* gl_box::pixels
 

Array of bytes used when reading pixels from display memory to save a frame in a ppm file.

double gl_box::distance
 

Current distance from the view point to the origin.

double gl_box::near_percent
 

Percentage of the original far clipping distance to use as the front clipping distance.

double gl_box::far_percent
 

Percentage to add to the near_percent to compute the far clipping distance.

bool gl_box::rotating
 

Whether the image is being rotated.

int gl_box::wobble
 

Whether the image is wobbling.

double gl_box::wobble_theta
 

Angle of wobble.

timeval gl_box::wobble_start
 

Time when wobble was started.

timeval gl_box::now
 

Current time.

bool gl_box::full
 

Whether in fullscreen mode or not.

bool gl_box::stereo
 

Whether in stereo mode.

bool gl_box::cross_eyed
 

Whether in cross-eyed stereo mode.

double gl_box::eye_separation
 

int gl_box::spin_rate
 

Rate of spin.

When the image is spinning on its own spin_rate is non-zero. It can spin either clockwise or counter-clockwise and at different rates which are set as integer values of spin_rate.

double gl_box::spin
 

Amount of spin (spin_rate * theta).

timeval gl_box::last_spin
 

Time of last spin calculation.

int gl_box::save_detail
 

Level of detail to save while rotating.

double gl_box::save_delay
 

Delay value to save while rotating.

int gl_box::mouse_start_x
 

Starting mouse x position for rotations.

int gl_box::mouse_start_y
 

Starting mouse y position for rotations.

int gl_box::mouse_x
 

Current mouse x for rotations.

int gl_box::mouse_y
 

Current mouse y for rotations.

Arcball* gl_box::a
 

Glui rotation control class.

Arcball* gl_box::light_arcball
 

Glui rotation control class for light.

ap_color gl_box::bg_color
 

bool gl_box::stop
 

Whether frames are advancing or not.

bool gl_box::lights
 

Whether lighting is enabled.

bool gl_box::blend
 

Whether blending is enabled.

bool gl_box::axes
 

Whether axes should be drawn.

bool gl_box::box
 

Whether a box should be drawn.

bool gl_box::save_frame
 

Whether the next frame should be saved.

int gl_box::save_movie
 

Whether all the frames should be saved.

char* gl_box::ppm_file
 

File name for saving the frame.

const char* gl_box::ppm_prefix
 

File name prefix for saving frames.

int gl_box::detail
 

Level of detail for rendering.

GLUquadricObj* gl_box::qobj
 

Used to build OpenGL display lists.

int gl_box::sphere_lists
 

Starting value for sphere display lists.

int gl_box::cylinder_lists
 

Starting value for cylinder display lists.

int gl_box::highlight
 

Highlight index.

If a color is being selected for modifications, animp will flash all the objects of that color using a sequence of hightlight colors. When highlight is 0, no highlighting is being done. Otherwise highlight is the index into the array of highlight colors to use for the next display.

bool gl_box::quash
 

Whether the image motion is quashed.

bool gl_box::need_to_copy
 

Whether new spheres and cylinders need to be copied to the objects array before sorting.

When the frame advances new objects must be copied prior to sorting. When the frame number is the same as the last time, there is no need to copy.

const double gl_box::theta = 0.00025 [static]
 

A small angle to multiply by spin to determine the current rotation angle.


The documentation for this class was generated from the following files:
Generated on Thu Nov 27 08:17:11 2003 for Animp - Animated Particles by doxygen 1.3.2