00001
00004
00005
00006
00007
00008
00009
#include "../src/main.h"
00010
#include "../src/Graph.h"
00011
#include "../src/RadialLayout.h"
00012
#include "../src/GLUTCallbackFunctions.h"
00013
00014
00015 int main_window;
00016
00017 Graph *
graph_;
00018 RadialLayout *
radial_layout_;
00019
00020 GLuint
screen_width_;
00021 GLuint
screen_height_;
00022
00023 GLuint
selected_animation_speed_;
00024 GLint
selected_render_mode_;
00025
00026 GLuint
clicked_object_id_ = 0;
00027 GLuint
motion_object_id_ = 0;
00028
00029 bool is_animation_mode_active_ =
false;
00030 bool is_fullscreen_mode_on_ =
false;
00031
00032 bool is_animation_running_ =
false;
00033 GLuint
num_iterations_ = 0;
00034
00035 GLint
last_x_pos_;
00036 GLint
last_y_pos_;
00037
00038 bool is_reset_rotation_ =
true;
00039 GLfloat
x_rotation_ = 0.0;
00040 GLfloat
y_rotation_ = 0.0;
00041 GLfloat
z_rotation_ = 0.0;
00042
00043 bool is_left_mouse_button_down_ =
true;
00044 int is_caption_enabled_ =
true;
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void createGLUTWindow(
Graph *graph,
RadialLayout *radial_layout,
00055 GLuint screen_width, GLuint screen_height)
00056 {
00057
screen_width_ = screen_width <= 0 ? 100 : screen_width;
00058
screen_height_ = screen_height <= 0 ? 100 : screen_height;
00059
if (graph == NULL)
00060 {
00061 cerr <<
"Graph is NULL." << endl;
00062 exit(0);
00063 }
00064
graph_ = graph;
00065
00066
if (radial_layout == NULL)
00067 {
00068 cerr <<
"Radial Layout is NULL." << endl;
00069 exit(0);
00070 }
00071
radial_layout_ = radial_layout;
00072
00073 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
00074 glutInitWindowPosition(50, 50);
00075 glutInitWindowSize(800, 600);
00076
main_window = glutCreateWindow(
"InfoViz: Animated Radial Tree Exploration");
00077
00078
00079 glutDisplayFunc(
renderScene);
00080
00081 glutReshapeFunc(
myGLUTReshapeFunc);
00082 glutKeyboardFunc(
myGLUTKeyboardEventFunc);
00083 glutMouseFunc(
myGLUTMouseEventFunc);
00084 glutMotionFunc(
myGlutMotion);
00085
00086
00087
graph_->
createGraph(
"Hallo");
00088
00089
createGLUI();
00090
00091 glutMainLoop();
00092 }
00093
00094
00095
00096
00097
00098 void createGLUI()
00099 {
00100
00101 GLUI *glui_window = GLUI_Master.create_glui(
"Menu");
00102
00103
00104 GLUI_Spinner *animation_speed_spinner =
00105 glui_window->add_spinner(
"Speed:", GLUI_SPINNER_INT,
00106 &
selected_animation_speed_);
00107
00108 animation_speed_spinner->set_int_limits(100, 2000);
00109
00110
00111 GLUI_Panel *radio_group_panel = glui_window->add_panel(
"Render Mode");
00112 GLUI_RadioGroup *render_mode_radio_group =
00113 glui_window->add_radiogroup_to_panel(radio_group_panel,
00114 &
selected_render_mode_, 1,
00115 (GLUI_Update_CB)
updateRenderMode);
00116
00117
00118 glui_window->add_checkbox(
"Enable Caption", &
is_caption_enabled_, 2,
00119 (GLUI_Update_CB)
toggleCaptionEnabling);
00120 glui_window->add_radiobutton_to_group(render_mode_radio_group,
00121
"Ivan's Version");
00122 glui_window->add_radiobutton_to_group(render_mode_radio_group,
00123
"Laura's Version");
00124 glui_window->add_button(
"Demo", 0, (GLUI_Update_CB)
startDemoMode);
00125 glui_window->add_button(
"Reset Rotation", 0,
00126 (GLUI_Update_CB)
resetSceneRotation);
00127 glui_window->add_separator();
00128 glui_window->add_button(
"Quit", 0, (GLUI_Update_CB)exit);
00129
00130 glui_window->set_main_gfx_window(
main_window);
00131
00132
00133 GLUI_Master.set_glutIdleFunc(
myGLUTIdleFunc);
00134 }
00135
00136
00137
00138
00139
00140 void renderScene()
00141 {
00142
if ((
is_animation_running_ ==
false)
00143 && (
is_animation_mode_active_ ==
true))
00144 {
00145
num_iterations_ = 1;
00146
is_animation_running_ =
true;
00147
graph_->
setAnimationMode(
true);
00148 }
00149
if (
num_iterations_ <=
selected_animation_speed_)
00150 {
00151 ++
num_iterations_;
00152 }
00153
00154
graph_->
setAnimationSpeed(&
selected_animation_speed_);
00155
00156 GLfloat width_height_aspect =
00157 (GLfloat)
screen_width_ / (GLfloat)
screen_height_;
00158
00159 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
00160 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00161
00162
00163
00164 glFrustum(-width_height_aspect * 0.04, width_height_aspect * 0.04, -0.04,
00165 0.04, 0.1, 15.0);
00166
00167 glMatrixMode( GL_MODELVIEW );
00168 glLoadIdentity();
00169
00170
00171 gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0);
00172
00173
00174 GLint num_circles = 10;
00175
00176
00177 GLfloat radius = -0.1f;
00178 GLUquadricObj *qobj;
00179 qobj = gluNewQuadric();
00180
00182
if (
is_reset_rotation_ ==
true)
00183 {
00184 glRotatef(0.0f, 0.0f, 1.0f, 0.0f);
00185 glRotatef(0.0f, 1.0f, 0.0f, 0.0f);
00186 glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
00187
is_reset_rotation_ =
false;
00188
y_rotation_ = 0.0f;
00189
x_rotation_ = 0.0f;
00190
last_y_pos_ = 0.0f;
00191
last_x_pos_ = 0.0f;
00192
myGlutMotion(
last_x_pos_,
last_y_pos_);
00193 }
00194
else
00195 {
00196 glRotatef(
y_rotation_, 0.0f, 1.0f, 0.0f);
00197 glRotatef(
x_rotation_, 1.0f, 0.0f, 0.0f);
00198 glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
00199 }
00201 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
00202 glEnable(GL_LINE_SMOOTH);
00204 gluQuadricNormals(qobj, GLU_SMOOTH);
00205 glDisable(GL_BLEND);
00206
radial_layout_ -> setNumberDisplayedRings(num_circles);
00207
radial_layout_ -> setRadiusOfRing(1, radius);
00208
radial_layout_ -> renderRadialLayout(qobj);
00209
00210 glInitNames();
00211 glPushName(0);
00212
graph_->
setSceneRotation(
x_rotation_,
y_rotation_,
z_rotation_);
00213
graph_->
drawGraph(qobj);
00214 glColor3f(1.0f, 1.0f, 1.0f);
00215 glDisable(GL_LINE_SMOOTH);
00216
00217
00218 glutSwapBuffers();
00219 gluDeleteQuadric(qobj);
00220 }
00221
00222
00223
00224
00225
00226 void myGLUTIdleFunc()
00227 {
00228
00229
00230
if (glutGetWindow() !=
main_window)
00231 {
00232 glutSetWindow(
main_window);
00233 }
00234 glutPostRedisplay();
00235 }
00236
00237
00238
00239
00240
00241 void myGLUTReshapeFunc(GLint screen_width, GLint screen_height)
00242 {
00243 GLfloat width_height_aspect =
00244 (GLfloat)screen_width / (GLfloat)screen_height;
00245
00246 glViewport(0, 0, screen_width, screen_height);
00247
00248 glMatrixMode(GL_PROJECTION);
00249 glLoadIdentity();
00250
00251 glutPostRedisplay();
00252 }
00253
00254
00255
00256
00257
00258 void updateRenderMode()
00259 {
00260
graph_->
toggleRenderMode();
00261 }
00262
00263
00264
00265
00266
00267 void startDemoMode()
00268 {
00269
if (
is_animation_mode_active_ ==
false)
00270 {
00271
num_iterations_ = 1;
00272
is_animation_mode_active_ =
true;
00273
is_animation_running_ =
true;
00274
graph_->
setAnimationMode(
true);
00275 }
00276
else
00277 {
00278
is_animation_mode_active_ =
false;
00279 }
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289 void myGLUTKeyboardEventFunc(
unsigned char key,
int x_pos,
int y_pos)
00290 {
00291
switch(key)
00292 {
00293
case 27 :
00294
case 'q' :
00295 exit(0);
00296
case GLUT_KEY_F1 :
00297
if (!
is_fullscreen_mode_on_)
00298 {
00299 glutFullScreen();
00300
is_fullscreen_mode_on_ =
true;
00301 }
00302
else
00303 {
00304 glutReshapeWindow(800, 600);
00305
is_fullscreen_mode_on_ =
false;
00306 }
00307
break;
00308
case 'a' :
00309
startDemoMode();
00310
break;
00311
case 'm' :
00312
graph_->
toggleRenderMode();
00313
break;
00314
default :
00315
break;
00316 };
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 void myGLUTMouseEventFunc(
int button,
int state,
int x_pos,
int y_pos)
00328 {
00329
if (button == GLUT_LEFT_BUTTON)
00330 {
00331 cout << x_pos <<
" " << y_pos << endl;
00332
00333
00334
clicked_object_id_ =
retrieveObjectID(x_pos, y_pos);
00335
graph_->
highlightNodeIfSelected(
clicked_object_id_);
00336
00337
if ((
graph_->
isANodeClicked(
clicked_object_id_))
00338 && (
is_animation_running_ ==
false))
00339 {
00340
num_iterations_ = 1;
00341
is_animation_running_ =
true;
00342
graph_->
setCenterNode(
clicked_object_id_);
00343 }
00344 }
00345
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
00346 {
00347
is_left_mouse_button_down_ =
true;
00348 }
00349
else
00350 {
00351
is_left_mouse_button_down_ =
false;
00352 }
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362 int retrieveObjectID(
int x_coord,
int y_coord)
00363 {
00364
int objectsFound = 0;
00365
int viewportCoords[4] = {0};
00366
00367
unsigned int selectBuffer[1024] = {0};
00368
00369 glSelectBuffer(1024, selectBuffer);
00370 glGetIntegerv(GL_VIEWPORT, viewportCoords);
00371
00372 glMatrixMode(GL_PROJECTION);
00373 glPushMatrix();
00374 glRenderMode(GL_SELECT);
00375 glLoadIdentity();
00376 gluPickMatrix(x_coord, viewportCoords[3] - y_coord, 2, 2, viewportCoords);
00377
00378 gluPerspective(45.0f,(
float)
screen_width_/(
float)
screen_height_,0.1f,150.0f);
00379 glMatrixMode(GL_MODELVIEW);
00380
00381
renderScene();
00382
00383 objectsFound = glRenderMode(GL_RENDER);
00384 glMatrixMode(GL_PROJECTION);
00385 glPopMatrix();
00386
00387 glMatrixMode(GL_MODELVIEW);
00388
00389
if (objectsFound > 0)
00390 {
00391
unsigned int lowestDepth = selectBuffer[1];
00392
00393
int selectedObject = selectBuffer[3];
00394
00395
00396
return selectedObject;
00397 }
00398
return 0;
00399 }
00400
00401
00402
00403
00404
00405
00406
00407 void myGlutMotion(
int x_pos,
int y_pos)
00408 {
00409
if (!
is_left_mouse_button_down_)
00410 {
00411
x_rotation_ += (GLfloat) (y_pos -
last_y_pos_);
00412
y_rotation_ += (GLfloat) (x_pos -
last_x_pos_);
00413
00414
last_x_pos_ = x_pos;
00415
last_y_pos_ = y_pos;
00416
00417
if ((
last_x_pos_ ==
screen_width_ / 2) ||
00418 (
last_y_pos_ ==
screen_height_ / 2))
00419 {
00420 }
00421
else
00422 {
00423
if (((x_pos -
screen_width_ / 2) * (
last_y_pos_ -
screen_height_ / 2)
00424 - (
last_x_pos_ -
screen_width_ / 2) * (y_pos -
screen_height_ / 2))
00425 > 0)
00426 {
00427
z_rotation_ += (GLfloat) ((abs(x_pos -
last_x_pos_)
00428 + abs(y_pos -
last_y_pos_)));
00429 }
00430
else
00431 {
00432
z_rotation_ += (GLfloat) (-1*(abs(x_pos -
last_x_pos_)
00433 + abs(y_pos -
last_y_pos_)));
00434 }
00435 }
00436
00437 glutPostRedisplay();
00438 }
00439 }
00440
00441
00442
00443
00444
00445 void resetSceneRotation()
00446 {
00447
is_reset_rotation_ =
true;
00448 }
00449
00450
00451
00452
00453
00454
00455 void toggleCaptionEnabling()
00456 {
00457
graph_->
toggleCaptionMode();
00458 }
00459
00460