00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #include <unistd.h>
00067 #include <GL/glut.h>
00068 #include <mui/mui.h>
00069 #include <stdio.h>
00070 #include <iostream>
00071 #include <algorithm>
00072 #include <utility>
00073 #include <vector>
00074 #include <string>
00075 #include "Controller.h"
00076 #include "View.h"
00077 using namespace std;
00078 View view;
00079 Controller controller;
00080 int subwindow;
00082 void init(void)
00083 {
00084 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00085 glClearColor(0.0, 0.0, 0.0, 0.0);
00086 glEnable(GL_DEPTH_TEST);
00087 glEnable(GL_LINE_SMOOTH);
00088 glLineWidth(2.0);
00089 glShadeModel(GL_SMOOTH);
00090 }
00091
00093 void display(void)
00094 {
00095 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00096 view.display();
00097 glutSwapBuffers();
00098 }
00099
00101 void motion(int x, int y)
00102 {
00103 glutPostRedisplay();
00104 }
00105
00106
00107
00109 void reshape(int w, int h)
00110 {
00111 glViewport(0, 0, w, h);
00112 glMatrixMode(GL_PROJECTION);
00113 glLoadIdentity();
00114
00115
00116 if (h == 0)
00117 view.aspect_ratio = (float) w;
00118 else
00119 view.aspect_ratio = (float) w / (float) h;
00120
00121 gluPerspective(50.0, view.aspect_ratio, 1.0, 200.0);
00122 glMatrixMode(GL_MODELVIEW);
00123 glLoadIdentity();
00124
00125 view.ScreenWidth = w;
00126 view.ScreenHeight = h;
00127 }
00128
00129
00131 void keyboard(unsigned char key, int x, int y)
00132 {
00133 glutSetWindow(subwindow);
00134 switch (key) {
00135 case '0':
00136 view.set_solo_chunk(0);
00137 break;
00138 case '1':
00139 view.set_solo_chunk(1);
00140 break;
00141 case '2':
00142 view.set_solo_chunk(2);
00143 break;
00144 case '3':
00145 view.set_solo_chunk(3);
00146 break;
00147 case '4':
00148 view.set_solo_chunk(4);
00149 break;
00150 case '5':
00151 view.set_solo_chunk(5);
00152 break;
00153 case '6':
00154 view.set_solo_chunk(6);
00155 break;
00156 case '7':
00157 view.set_solo_chunk(7);
00158 break;
00159 case '8':
00160 view.set_solo_chunk(8);
00161 break;
00162 case '9':
00163 view.set_solo_chunk(9);
00164 break;
00165 case '-':
00166 view.set_solo_chunk(-1);
00167 break;
00168 case 'Q':
00169 case 'q':
00170 case 27:
00171 exit(0);
00172 break;
00173 case 'A':
00174 view.animate(-1);
00175 break;
00176 case 'a':
00177 view.animate(1);
00178 break;
00179 case 'F':
00180 case 'f':
00181 view.toggle_fillpoly();
00182 break;
00183 case 'L':
00184 case 'l':
00185 view.toggle_showlabel();
00186 break;
00187 case 'E':
00188 case 'e':
00189 view.toggle_showlength();
00190 break;
00191 case 'O':
00192 case 'o':
00193 view.toggle_opaque();
00194 break;
00195 case 'c':
00196 case 'C':
00197 view.rotatecolormap();
00198 break;
00199 case 'V':
00200 case 'v':
00201 view.toggle_pointmode();
00202 break;
00203 case 'Z':
00204 view.zoomout();
00205 break;
00206 case 'z':
00207 view.zoomin();
00208 break;
00209 case 'i':
00210 view.move_y(1.0);
00211 break;
00212 case 'm':
00213 view.move_y(-1.0);
00214 break;
00215 case 'j':
00216 view.move_x(-1.0);
00217 break;
00218 case 'k':
00219 view.move_x(1.0);
00220 break;
00221 case 'y':
00222 view.move_z(-1.0);
00223 break;
00224 case 'b':
00225 view.move_z(1.0);
00226 break;
00227 case 'N':
00228 case 'n':
00229 view.next_step();
00230 break;
00231 case 'p':
00232 case 'P':
00233 view.prev_step();
00234 break;
00235 }
00236 snprintf(controller.timestring,80,"%d",view.get_currstep());
00237 muiChangeLabel(controller.timestep_number,controller.timestring);
00238 view.display();
00239 glutPostWindowRedisplay(subwindow);
00240 glutPostWindowRedisplay(1);
00241 }
00242
00244 void movers(int key, int x, int y)
00245 {
00246 glutSetWindow(subwindow);
00247 switch (key) {
00248 case GLUT_KEY_LEFT:
00249 view.rotate_y(1);
00250 break;
00251 case GLUT_KEY_RIGHT:
00252 view.rotate_y(-1);
00253 break;
00254 case GLUT_KEY_UP:
00255 view.rotate_x(1);
00256 break;
00257 case GLUT_KEY_DOWN:
00258 view.rotate_x(-1);
00259 break;
00260 case GLUT_KEY_PAGE_UP:
00261 view.rotate_z(1);
00262 break;
00263 case GLUT_KEY_PAGE_DOWN:
00264 view.rotate_z(-1);
00265 break;
00266 }
00267 glutPostWindowRedisplay(subwindow);
00268 }
00269
00270
00272 void interpclick(int click)
00273 {
00274
00275 keyboard((unsigned int) click,0,0);
00276 }
00277
00279 void bcallback(muiObject *obj, enum muiReturnValue r)
00280 {
00281 r = r;
00282 keyboard(muiGetID(obj),0,0);
00283 }
00284
00285 void chunkcallback(muiObject *obj, enum muiReturnValue r)
00286 {
00287 glutSetWindow(subwindow);
00288 view.set_solo_chunk(atoi(muiGetTBString(controller.chunkbox)));
00289 view.display();
00290 glutPostWindowRedisplay(subwindow);
00291 glutPostWindowRedisplay(1);
00292
00293 }
00294
00295 void nochunkcallback(muiObject *obj, enum muiReturnValue r)
00296 {
00297 glutSetWindow(subwindow);
00298 view.set_solo_chunk(-1);
00299 view.display();
00300 glutPostWindowRedisplay(subwindow);
00301 glutPostWindowRedisplay(1);
00302
00303 }
00304
00305 void timecallback(muiObject *obj, enum muiReturnValue r)
00306 {
00307 glutSetWindow(subwindow);
00308 view.display_step(atoi(muiGetTBString(controller.seltimebox)));
00309 snprintf(controller.timestring,80,"%d",view.get_currstep());
00310 muiChangeLabel(controller.timestep_number,controller.timestring);
00311 glutPostWindowRedisplay(subwindow);
00312 glutPostWindowRedisplay(1);
00313
00314 }
00315
00316
00318 void idle(void)
00319 {
00320 glutPostRedisplay();
00321 }
00322
00324 int main(int argc, char **argv)
00325 {
00326
00327
00328
00329 glutInit(&argc, argv);
00330 glutInitWindowSize(400, 550);
00331 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
00332 glutCreateWindow("TetController");
00333 muiInit();
00334 controller=Controller(glutGetWindow());
00335
00336 glutSpecialFunc(movers);
00337 glutInitWindowSize(500, 500);
00338 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
00339 subwindow=glutCreateWindow("Tetraviewer");
00340 init();
00341 srand48(65);
00342 cout << "
00343 a : animate timestep forwards to end
00344 A : animate timestep backwards to start
00345 f : toggle fill mode (opaque or transparent faces)
00346 o : toggle line mode (emphasis lines)
00347 e : toggle edge length labels
00348 l : toggle vertex labels
00349 v : vertex view mode (vertex points only)
00350 c : cycle color map (random, chunk, point)
00351 z : zoom in
00352 Z : zoom out
00353 n : next timestep
00354 p : prev timestep
00355 q : quit
00356 0-9 : choose only chunk 0..9
00357 - : all chunks
00358 arrow and page up/down keys to rotate x y z
00359 \n";
00360 for (int i = 1; i < argc; i++) {
00361 if (!view.loadfile(argv[i])) {
00362 fprintf(stderr, "loadfile %s failed\n", argv[i]);
00363 return (1);
00364 }
00365 }
00366 glutIdleFunc(idle);
00367 glutReshapeFunc(reshape);
00368 glutDisplayFunc(display);
00369 glutMotionFunc(motion);
00370 glutKeyboardFunc(keyboard);
00371 glutSpecialFunc(movers);
00372 view.make_random_color_set();
00373 view.recenter();
00374 view.display_first();
00375 glutMainLoop();
00376 return 0;
00377 }