#include <gl_box.h>
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 | |
movie * | m |
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. |
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 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.
|
|
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.
|
|
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. |
|
Function to select between 4 stereo/fullscreen options.
|
|
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. |
|
Function to draw a single pixel wide box surrounding the data.
|
|
Function to copy the current image to a ppm file. The file name is in ppm_file. |
|
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.
|
|
Function to tell gl_box the current movie object.
|
|
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. |
|
Function to draw a frame.
|
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
This is the x, y and z value for focusing the camera.
|
|
Minimum coordinates for all objects in all frames.
|
|
Maximum coordinates for all objects in all frames.
|
|
Maximum difference over x, y and z dimensions between min_coords and max_coords.
|
|
Array of objects to draw. Spheres and cylinders of various types need to be combined in one array to be sorted. |
|
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. |
|
Array of gl_cylinders with short int coordinates.
|
|
Array of bytes used when reading pixels from display memory to save a frame in a ppm file.
|
|
Current distance from the view point to the origin.
|
|
Percentage of the original far clipping distance to use as the front clipping distance.
|
|
Percentage to add to the near_percent to compute the far clipping distance.
|
|
Whether the image is being rotated.
|
|
Whether the image is wobbling.
|
|
Angle of wobble.
|
|
Time when wobble was started.
|
|
Current time.
|
|
Whether in fullscreen mode or not.
|
|
Whether in stereo mode.
|
|
Whether in cross-eyed stereo mode.
|
|
|
|
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. |
|
Amount of spin (spin_rate * theta).
|
|
Time of last spin calculation.
|
|
Level of detail to save while rotating.
|
|
Delay value to save while rotating.
|
|
Starting mouse x position for rotations.
|
|
Starting mouse y position for rotations.
|
|
Current mouse x for rotations.
|
|
Current mouse y for rotations.
|
|
Glui rotation control class.
|
|
Glui rotation control class for light.
|
|
|
|
Whether frames are advancing or not.
|
|
Whether lighting is enabled.
|
|
Whether blending is enabled.
|
|
Whether axes should be drawn.
|
|
Whether a box should be drawn.
|
|
Whether the next frame should be saved.
|
|
Whether all the frames should be saved.
|
|
File name for saving the frame.
|
|
File name prefix for saving frames.
|
|
Level of detail for rendering.
|
|
Used to build OpenGL display lists.
|
|
Starting value for sphere display lists.
|
|
Starting value for cylinder display lists.
|
|
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. |
|
Whether the image motion is quashed.
|
|
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. |
|
A small angle to multiply by spin to determine the current rotation angle.
|