$search
00001 /* 00002 James R. Diebel 00003 Stanford University 00004 00005 Started: 30 August 2004 00006 Last revised: 31 Sugust 2004 00007 00008 viewmesh.cc - Utility to view a MSH file in an OpenGL window 00009 00010 Depends on: 00011 - Mesh class (mesh.hh) 00012 -- Vec3d class (vec3d.hh) 00013 -- Vert class (vert.hh) 00014 -- Edge class (edge.hh) 00015 -- Face class (face.hh) 00016 - Timer class (timer.hh) 00017 - TriMesh class (trimesh.h) 00018 - GUI namespace (gui.hh) 00019 -- OpenGL 00020 -- GLUT 00021 -- GLUI 00022 */ 00023 00024 #include <iostream> 00025 #include <fstream> 00026 #include <string.h> 00027 #include <IL/il.h> 00028 #include <IL/ilu.h> 00029 #include <IL/ilut.h> 00030 #include "bmtk/mesh.hh" 00031 #include "bmtk/viewmesh.hh" 00032 #include "bmtk/timer.hh" 00033 00034 #define D2R 0.017453293 00035 #define R2D 57.29578 00036 00037 using namespace std; 00038 00039 // Data contained within namespace to avoid collisions 00040 namespace procmesh { 00041 // Mesh data to be displayed 00042 Mesh* m; 00043 Mesh* dm; 00044 00045 // Image Library ID 00046 ILuint ImgId; 00047 int screenShotNumber = 0; 00048 char screenShotName[100]; 00049 int screenShots = 0; 00050 00051 // Windowing details (default values if no options file) 00052 int wx0 = 200; // upper left of main window 00053 int wy0 = 0; 00054 int wdx = 1000; // size of main window 00055 int wdy = 800; 00056 int cx0 = 0; // upper left of control window 00057 int cy0 = 0; 00058 int bdx, bdy; // size of window manager border 00059 float offsetX; 00060 00061 // Viewpoint variables (default values if no options file) 00062 float xyAspect; 00063 int lastX, lastY; 00064 float rotationX = 0.0, rotationY = 0.0; 00065 float lightRotX = 0.0, lightRotY = 0.0; 00066 float rotationXStore = 0.0, rotationYStore = 0.0; 00067 int motionMode; 00068 Vec3d center; 00069 Vec3d centerStore;; 00070 00071 // These are the live variables passed into GLUI 00072 // (default values if no options file) 00073 int dataSet = 0; 00074 int triMesh0 = 0; 00075 int triMesh = 0; 00076 int wireframe0 = 0; 00077 int wireframe = 0; 00078 int points0 = 0; 00079 int points = 0; 00080 int face2face = 0; 00081 int face2vert = 0; 00082 int edgeAngles = 0; 00083 int vertPotentials = 0; 00084 int vertGradients = 0; 00085 int faceColors = 1; 00086 int centerSphere = 1; 00087 int meshBoundary = 0; 00088 int vertGradVecs = 0; 00089 int segment = 0; 00090 int vertNorm = 0; 00091 int blackWhite = 0; 00092 00093 int keypoints = 0; 00094 int vertNormals = 0; 00095 int edge2face = 0; 00096 int face2edge = 0; 00097 int polyMesh = 0; 00098 int polyWire = 0; 00099 int deciMesh = 0; 00100 int deciWire = 0; 00101 int text = 0; 00102 int textMode = 0; 00103 int lines = 1; 00104 int offset = 0; 00105 00106 float gs2 = 1.0; 00107 float gsn2 = 1.0; 00108 00109 // character arrays for on-screen messages 00110 char sizeInfo[sizeof(GLUI_String)] = {""}; 00111 char potentialInfo[sizeof(GLUI_String)] = {""}; 00112 00113 int objectColor[3] = {100,100,100}; 00114 int diffuseIntensity = 100; 00115 int ambientIntensity = 50; 00116 int main_window; 00117 float scale = 1.0; 00118 float scaleStore = 1.0; 00119 int counter = 0; 00120 00121 float delta=1.0; 00122 float deltaStore; 00123 00124 // Pointers to the windows and some of the controls we'll create 00125 GLUI *glui; 00126 GLUI_Spinner *objectRSpinner, *objectGSpinner, *objectBSpinner, 00127 *ambientSpinner, *deltaSpinner, 00128 *gs2Spinner, *gsn2Spinner, *dataSetSpinner,*segThreshSpinner; 00129 GLUI_Rollout *visualsRollout; 00130 00131 // Miscellaneous global variables 00132 GLfloat light_ambient[4]; 00133 GLfloat light_diffuse[4]; 00134 GLfloat light_zero[] = {0, 0, 0, 0}; 00135 GLfloat light_one[] = {1, 1, 1, 0}; 00136 GLfloat light_position[] = {-1.0f, 1.0f, 1.0f, 0.0f}; 00137 } 00138 using namespace procmesh; 00139 00140 int main (int argc, char *argv[]) { 00141 // if bad command line args, give usage instructions and exit 00142 if (argc < 2) { 00143 cout << endl 00144 << "Usage: viewmesh file.msh [file.reg]" << endl; 00145 exit(1); 00146 } 00147 00148 // Initialize Glut 00149 glutInit(&argc,argv); 00150 // Initialize DevIL (Developer's Image Library) 00151 ilInit(); 00152 iluInit(); 00153 ilutRenderer(ILUT_OPENGL); 00154 // Since we are only using one image at a time, initialize it now 00155 ilGenImages(1, &ImgId); 00156 // Bind this image name 00157 ilBindImage(ImgId); 00158 00159 00160 // read mesh from file 00161 Mesh m; 00162 m.readMesh(argv[1]); 00163 00164 // find mesh properties that are independent of options 00165 m.findMeshProps(); 00166 m.findRegionProps(); 00167 00168 // find mesh properties that depend on options 00169 m.readOptions("mrf_options.dat"); 00170 m.findMeshPotential(); 00171 m.findLocalEdgePotentials(); 00172 m.findVertGradients(); 00173 m.findSearchDirs(true); 00174 00175 // if a region file is provided, read it 00176 if (argc == 3) m.importRegions(argv[2]); 00177 00178 // initialize OpenGL window class 00179 startGUI(&m); 00180 00181 return 0; 00182 } 00183 00184 // GLUI control callback 00185 void controlCB(int control) { 00186 if (control == -1) { 00187 cout << "Exiting..." << endl << flush; 00188 exit(0); 00189 } 00190 if (control == 62) { 00191 if (faceColors) { 00192 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_zero); 00193 glLightfv(GL_LIGHT0, GL_AMBIENT, light_one); 00194 } 00195 else { 00196 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 00197 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 00198 } 00199 } 00200 if (control == 63) { 00201 if ((triMesh || triMesh0) && (triMesh != triMesh0)) { 00202 triMesh = !triMesh; 00203 triMesh0 = !triMesh0; 00204 } 00205 if ((wireframe || wireframe0) && (wireframe != wireframe0)) { 00206 wireframe = !wireframe; 00207 wireframe0 = !wireframe0; 00208 } 00209 if ((points || points0) && (points != points0)) { 00210 points = !points; 00211 points0 = !points0; 00212 } 00213 glui->sync_live(); 00214 00215 } 00216 if (control == 64) { 00217 if (lines) { 00218 glPolygonOffset(1.0,0.1); 00219 glEnable(GL_POLYGON_OFFSET_FILL); 00220 } else { 00221 glDisable(GL_POLYGON_OFFSET_FILL); 00222 } 00223 } 00224 00225 if (control == 100) { 00226 saveOptions(); 00227 m->writeOptions("mrf_options.dat"); 00228 } 00229 if (control == 150) { 00230 center = (m->boxMin + m->boxMax)/2; 00231 } 00232 if (control == 151) { 00233 int temp = textMode; textMode = 1; 00234 m->runCG(); 00235 textMode = temp; 00236 } 00237 if (control == 152) { 00238 m->reset(); 00239 sprintf(potentialInfo,"Potential: %.2f",m->psi); 00240 myGlutDisplay(); 00241 } 00242 if (control == 154) { 00243 m->anneal(); 00244 } 00245 if (control == 155) { 00246 int temp = textMode; textMode = 2; 00247 m->runSegmentation(); 00248 update(); 00249 textMode = temp; 00250 } 00251 00252 if (control == 156) { 00253 cout << "Saving Mesh..." << endl; 00254 m->writeMesh(m->filename); 00255 } 00256 00257 if (control == 157) { 00258 if (dm) delete dm; 00259 dm = m->genDecimatedMesh(); 00260 update(); 00261 } 00262 00263 if (control == 250) { 00264 for (int i=0;i<3;i++) { 00265 light_ambient[i] = float(ambientIntensity)/100.0f; 00266 } 00267 if (faceColors) { 00268 glLightfv(GL_LIGHT0, GL_AMBIENT, light_one); 00269 } 00270 else { 00271 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 00272 } 00273 } 00274 if (control == 251) { 00275 m->setVertVar(gs2); 00276 m->setNormalVar(gsn2); 00277 m->findMeshPotential(); 00278 m->findLocalEdgePotentials(); 00279 m->findVertGradients(); 00280 m->findSearchDirs(true); 00281 update(); 00282 } 00283 } 00284 00285 // Parses keyboard commands 00286 void myGlutKeyboard(unsigned char Key, int x, int y) { 00287 float dRX,dRY,dS,dDelta; 00288 float dC[3]; 00289 switch(Key) 00290 { 00291 case 27: 00292 case 'q': case 'Q': 00293 exit(0); 00294 case 's': case 'S': 00295 takeScreenShot(); break; 00296 case 'r': case 'R': 00297 rotationXStore = rotationX; 00298 rotationYStore = rotationY; 00299 centerStore[0] = center[0]; 00300 centerStore[1] = center[1]; 00301 centerStore[2] = center[2]; 00302 scaleStore = scale; 00303 deltaStore = delta; 00304 break; 00305 case 'g': case 'G': 00306 dRX = (rotationXStore - rotationX)/float(100); 00307 dRY = (rotationYStore - rotationY)/float(100); 00308 dS = (scaleStore - scale)/float(100); 00309 dC[0] = (centerStore[0] - center[0])/float(100); 00310 dC[1] = (centerStore[1] - center[1])/float(100); 00311 dC[2] = (centerStore[2] - center[2])/float(100); 00312 dDelta = (deltaStore - delta)/float(100); 00313 for (int i = 0;i<100;i++) { 00314 rotationX += dRX; 00315 rotationY += dRY; 00316 scale += dS; 00317 delta += dDelta; 00318 center[0] += dC[0]; 00319 center[1] += dC[1]; 00320 center[2] += dC[2]; 00321 update(); 00322 } 00323 break; 00324 case 'f': case 'F': 00325 dRX = -(rotationXStore - rotationX)/float(100); 00326 dRY = -(rotationYStore - rotationY)/float(100); 00327 dS = -(scaleStore - scale)/float(100); 00328 dC[0] = -(centerStore[0] - center[0])/float(100); 00329 dC[1] = -(centerStore[1] - center[1])/float(100); 00330 dC[2] = -(centerStore[2] - center[2])/float(100); 00331 dDelta = -(deltaStore - delta)/float(100); 00332 rotationX = rotationXStore; 00333 rotationY = rotationYStore; 00334 scale = scaleStore; 00335 delta = deltaStore; 00336 center[0] = centerStore[0]; 00337 center[1] = centerStore[1]; 00338 center[2] = centerStore[2]; 00339 myGlutDisplay(); 00340 for (int i = 0;i<100;i++) { 00341 rotationX += dRX; 00342 rotationY += dRY; 00343 scale += dS; 00344 delta += dDelta; 00345 center[0] += dC[0]; 00346 center[1] += dC[1]; 00347 center[2] += dC[2]; 00348 update(); 00349 } 00350 break; 00351 }; 00352 00353 glutPostRedisplay(); 00354 } 00355 00356 // Passes keyboard commands to the appropriate interpreter 00357 void myGlutMenu(int value) { 00358 myGlutKeyboard(value, 0, 0); 00359 } 00360 00361 // Run each time OpenGL renders a frame 00362 void myGlutIdle(void) { 00363 // According to the GLUT specification, the current window is 00364 // undefined during an idle callback. So we need to explicitly change 00365 // it if necessary 00366 if (glutGetWindow() != main_window) 00367 glutSetWindow(main_window); 00368 00369 glutPostRedisplay(); 00370 00371 // if it is our first iterations, 00372 // infer the size of the window manager border 00373 if (!counter) { 00374 bdx = glutGet(GLUT_WINDOW_X) - wx0; 00375 bdy = glutGet(GLUT_WINDOW_Y) - wy0; 00376 } 00377 00378 // Updates frame counter 00379 counter++; 00380 } 00381 00382 // Parses mouse button presses 00383 void myGlutMouse(int button, int button_state, int x, int y) { 00384 lastX = x; 00385 lastY = y; 00386 if (button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN) { 00387 if (glutGetModifiers() == GLUT_ACTIVE_CTRL) 00388 motionMode = 3; // translate on surface of screen 00389 else 00390 motionMode = 1; // rotate 00391 } 00392 if (button == GLUT_RIGHT_BUTTON && button_state == GLUT_DOWN) { 00393 if (glutGetModifiers() == GLUT_ACTIVE_CTRL) 00394 motionMode = 4; // translate into/out of screen 00395 else if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) 00396 motionMode = 5; // move light source 00397 else 00398 motionMode = 2; // zoom 00399 } 00400 00401 if (button_state == GLUT_UP) { 00402 motionMode = 0; // no motion 00403 myGlutDisplay(); 00404 } 00405 } 00406 00407 // Parses mouse motion 00408 void myGlutMotion(int x, int y) { 00409 if (motionMode == 1) { // rotate 00410 rotationX += float(y - lastY)/4.0f; 00411 rotationY += float(x - lastX)/4.0f; 00412 //rotationX += float(x - lastX)/4.0f; 00413 //rotationY += float(y - lastY)/4.0f; 00414 //cout << rotationX << " " << rotationY << endl << flush; 00415 } else if (motionMode == 2) { // zoom 00416 int diff = y - lastY; 00417 int mag = abs(y - lastY); 00418 for (int i=0;i<mag;i++) { 00419 if (diff < 0) scale *= 1.01; 00420 else scale /= 1.01; 00421 } 00422 } else if (motionMode == 3) { // translate left/right, up/down 00423 float distX = 0.1*m->box*float(x - lastX)/float(wdx); 00424 float distY = 0.1*m->box*float(y - lastY)/float(wdy); 00425 center[0] -= distX*cos(rotationY*D2R); 00426 center[2] -= distX*sin(rotationY*D2R); 00427 center[0] += distY*sin(rotationX*D2R)*sin(rotationY*D2R); 00428 center[1] += distY*cos(rotationX*D2R); 00429 center[2] -= distY*sin(rotationX*D2R)*cos(rotationY*D2R); 00430 } else if (motionMode == 4) { // translate into/out of screen 00431 float distZ = 0.1*m->box*float(y - lastY)/float(wdy); 00432 center[0] -= distZ*cos(rotationX*D2R)*sin(rotationY*D2R); 00433 center[1] += distZ*sin(rotationX*D2R); 00434 center[2] += distZ*cos(rotationX*D2R)*cos(rotationY*D2R); 00435 } else if (motionMode == 5) { // move light source 00436 lightRotX += float(y - lastY)/4.0f; 00437 lightRotY += float(x - lastX)/4.0f; 00438 light_position[0] = cos(lightRotX*D2R)*sin(lightRotY*D2R); 00439 light_position[1] = sin(lightRotX*D2R)*sin(lightRotY*D2R); 00440 light_position[2] = cos(lightRotY*D2R); 00441 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 00442 } 00443 if (motionMode) { 00444 lastX = x; 00445 lastY = y; 00446 } 00447 00448 glutPostRedisplay(); 00449 } 00450 00451 // tells GLUT when the window has been reshaped 00452 void myGlutReshape(int x, int y) { 00453 wdx = x; wdy = y; 00454 xyAspect = (float)x / (float)y; 00455 glViewport(0, 0, x, y); 00456 00457 glutPostRedisplay(); 00458 } 00459 00460 00461 float neg(float arg) { 00462 return (fabs(arg) - arg)/2; 00463 } 00464 00465 // Draws the actual mesh with calls directly to OpenGL 00466 void drawMesh(void) { 00467 // Draw the triangles 00468 if (triMesh && !m->nd && !deciMesh) { 00469 float color; 00470 glBegin(GL_TRIANGLES); 00471 for (int i=0;i<m->nf;i++) { 00472 if (meshBoundary && m->f[i].bound) continue; 00473 float* n; 00474 if (segment) n = &(m->f[i].r->n.x[0]); 00475 else n = &(m->f[i].n.x[0]); 00476 glNormal3d(n[0],n[1],n[2]); 00477 if (faceColors) glColor4f(fabs(n[0]),fabs(n[1]),fabs(n[2]),0.5); 00478 else glColor4f(float(objectColor[0])/100, 00479 float(objectColor[1])/100, 00480 float(objectColor[2])/100,.5); 00481 for (int j=0;j<3;j++) { 00482 if (vertPotentials) { 00483 color = (m->f[i].v[j]->psiEdge + m->f[i].v[j]->psi)/delta; 00484 glColor4f(color,color,color,0); 00485 } 00486 if (vertGradients) { 00487 glColor4f(fabs(m->f[i].v[j]->gradPsi[0])/delta, 00488 fabs(m->f[i].v[j]->gradPsi[1])/delta, 00489 fabs(m->f[i].v[j]->gradPsi[2])/delta,0); 00490 } 00491 if (vertNorm) { 00492 if (faceColors) glColor4f(fabs(m->f[i].v[j]->n[0]), 00493 fabs(m->f[i].v[j]->n[1]), 00494 fabs(m->f[i].v[j]->n[2]),0); 00495 glNormal3d(m->f[i].v[j]->n[0], 00496 m->f[i].v[j]->n[1], 00497 m->f[i].v[j]->n[2]); 00498 } 00499 glVertex3d(m->f[i].v[j]->x[0], m->f[i].v[j]->x[1], m->f[i].v[j]->x[2]); 00500 } 00501 } 00502 glEnd(); 00503 } 00504 if (triMesh0) { 00505 float color; 00506 glBegin(GL_TRIANGLES); 00507 for (int i=0;i<m->nf;i++) { 00508 if (meshBoundary && m->f[i].bound) continue; 00509 float* n; 00510 n = &(m->f[i].n0.x[0]); 00511 glNormal3d(n[0],n[1],n[2]); 00512 if (faceColors) glColor4f(fabs(n[0]),fabs(n[1]),fabs(n[2]),0.5); 00513 else if (triMesh && triMesh0) glColor4f(0.75,0.75,0.75,0.5); 00514 else glColor4f(float(objectColor[0])/100, 00515 float(objectColor[1])/100, 00516 float(objectColor[2])/100,.5); 00517 for (int j=0;j<3;j++) { 00518 glVertex3d(m->f[i].v[j]->x0[0], 00519 m->f[i].v[j]->x0[1], 00520 m->f[i].v[j]->x0[2]); 00521 } 00522 } 00523 glEnd(); 00524 } 00525 00526 if (triMesh && m->nd) { 00527 float color; 00528 glBegin(GL_TRIANGLES); 00529 for (int i=0;i<m->nf;i++) { 00530 float* n; 00531 if (segment) n = &(m->f[i].r->ns[dataSet].x[0]); 00532 else n = &(m->f[i].ns[dataSet].x[0]); 00533 glNormal3d(n[0],n[1],n[2]); 00534 if (faceColors) { 00535 glColor4f(fabs(n[0]),fabs(n[1]),fabs(n[2]),0.5); 00536 } else glColor4f(float(objectColor[0])/100, 00537 float(objectColor[1])/100, 00538 float(objectColor[2])/100,.5); 00539 for (int j=0;j<3;j++) { 00540 glVertex3d(m->f[i].v[j]->xs[dataSet][0], 00541 m->f[i].v[j]->xs[dataSet][1], 00542 m->f[i].v[j]->xs[dataSet][2]); 00543 } 00544 } 00545 glEnd(); 00546 } 00547 00548 // Draw the triangles 00549 if (offset) glTranslatef(offsetX*2*delta*cos(rotationY*D2R),0.0f, 00550 offsetX*2*delta*sin(rotationY*D2R)); 00551 if (deciMesh && dm) { 00552 float color; 00553 glBegin(GL_TRIANGLES); 00554 for (int i=0;i<dm->nf;i++) { 00555 float* n; 00556 if (dm->nd) n = &(dm->f[i].ns[dataSet].x[0]); 00557 else n = &(dm->f[i].n.x[0]); 00558 glNormal3d(n[0],n[1],n[2]); 00559 00560 if (faceColors) { 00561 glColor4f(fabs(n[0]),fabs(n[1]),fabs(n[2]),0.5); 00562 } else glColor4f(float(objectColor[0])/100, 00563 float(objectColor[1])/100, 00564 float(objectColor[2])/100,.5); 00565 for (int j=0;j<3;j++) { 00566 /*glNormal3d(dm->f[i].v[j]->n[0], 00567 dm->f[i].v[j]->n[1], 00568 dm->f[i].v[j]->n[2]);*/ 00569 if (dm->nd) glVertex3d(dm->f[i].v[j]->xs[dataSet][0], 00570 dm->f[i].v[j]->xs[dataSet][1], 00571 dm->f[i].v[j]->xs[dataSet][2]); 00572 else glVertex3d(dm->f[i].v[j]->x[0], 00573 dm->f[i].v[j]->x[1], 00574 dm->f[i].v[j]->x[2]); 00575 } 00576 } 00577 glEnd(); 00578 } 00579 if (deciWire && dm) { 00580 float color; 00581 for (int i=0;i<dm->nf;i++) { 00582 glColor4f(0,0,0,0); 00583 glBegin(GL_LINE_LOOP); 00584 for (int j=0;j<3;j++) { 00585 if (dm->nd) glVertex3d(dm->f[i].v[j]->xs[dataSet][0], 00586 dm->f[i].v[j]->xs[dataSet][1], 00587 dm->f[i].v[j]->xs[dataSet][2]); 00588 else glVertex3d(dm->f[i].v[j]->x[0], 00589 dm->f[i].v[j]->x[1], 00590 dm->f[i].v[j]->x[2]); 00591 } 00592 glEnd(); 00593 } 00594 } 00595 if (offset) glTranslatef(-offsetX*2*delta*cos(rotationY*D2R),0.0f, 00596 -offsetX*2*delta*sin(rotationY*D2R)); 00597 00598 // Draw the wireframe 00599 if (wireframe0) { 00600 glBegin(GL_LINES); 00601 if (!edgeAngles) glColor4f(0,0,0,0.5); 00602 glNormal3d(0,0,0); 00603 for (int i=0;i<m->ne;i++) { 00604 if (edgeAngles) { 00605 float color = m->e[i].psi/delta; 00606 glColor4f(color,color,color,0); 00607 } 00608 glVertex3d(m->e[i].v[0]->x0[0], 00609 m->e[i].v[0]->x0[1], 00610 m->e[i].v[0]->x0[2]); 00611 glVertex3d(m->e[i].v[1]->x0[0], 00612 m->e[i].v[1]->x0[1], 00613 m->e[i].v[1]->x0[2]); 00614 } 00615 glEnd(); 00616 } 00617 if (wireframe) { 00618 glBegin(GL_LINES); 00619 if (!edgeAngles) glColor4f(0,0,0,0.5); 00620 glNormal3d(0,0,0); 00621 for (int i=0;i<m->ne;i++) { 00622 if (segment && 0) { 00623 if (m->e[i].nf == 2) { 00624 if(m->e[i].f[0]->r == m->e[i].f[1]->r) continue; 00625 } else continue; 00626 } 00627 if (edgeAngles) { 00628 float color = m->e[i].psi/delta; 00629 glColor4f(color,color,color,0); 00630 } 00631 if (m->nd) { 00632 glVertex3d(m->e[i].v[0]->xs[dataSet][0], 00633 m->e[i].v[0]->xs[dataSet][1], 00634 m->e[i].v[0]->xs[dataSet][2]); 00635 glVertex3d(m->e[i].v[1]->xs[dataSet][0], 00636 m->e[i].v[1]->xs[dataSet][1], 00637 m->e[i].v[1]->xs[dataSet][2]); 00638 } else { 00639 glVertex3d(m->e[i].v[0]->x[0], 00640 m->e[i].v[0]->x[1], 00641 m->e[i].v[0]->x[2]); 00642 glVertex3d(m->e[i].v[1]->x[0], 00643 m->e[i].v[1]->x[1], 00644 m->e[i].v[1]->x[2]); 00645 } 00646 } 00647 glEnd(); 00648 } 00649 00650 if (points) { 00651 glBegin(GL_POINTS); 00652 glColor4f(1,1,1,0.5); 00653 for (int i=0;i<m->nv;i++) { 00654 glVertex3d(m->v[i].x[0], 00655 m->v[i].x[1], 00656 m->v[i].x[2]); 00657 } 00658 glEnd(); 00659 } 00660 00661 if (points0) { 00662 glBegin(GL_POINTS); 00663 glColor4f(1,1,1,0.5); 00664 for (int i=0;i<m->nv;i++) { 00665 glVertex3d(m->v[i].x0[0], 00666 m->v[i].x0[1], 00667 m->v[i].x0[2]); 00668 } 00669 glEnd(); 00670 } 00671 00672 // draw points flagged as boundary points between regions 00673 if (keypoints) { 00674 glBegin(GL_POINTS); 00675 glColor4f(1,1,1,0.5); 00676 for (int i=0;i<m->nv;i++) { 00677 if (m->v[i].flag < -3) { 00678 glVertex3d(m->v[i].x[0], 00679 m->v[i].x[1], 00680 m->v[i].x[2]); 00681 } 00682 } 00683 glEnd(); 00684 } 00685 00686 if (offset) glTranslatef(offsetX*2*delta*cos(rotationY*D2R),0.0f, 00687 offsetX*2*delta*sin(rotationY*D2R)); 00688 if (polyWire) { 00689 for (int i=0;i<m->nr;i++) { 00690 if (m->r[i].vi.size() > 3) { 00691 glBegin(GL_LINE_LOOP); 00692 float color = 0; 00693 glColor4f(color,color,color,0.5f); 00694 for(int j=0;j<m->r[i].vi.size();j++) { 00695 if (m->r[i].vi[j] < 0) { 00696 if (m->r[i].vi[j] == -1) { 00697 glEnd(); 00698 glBegin(GL_LINE_LOOP); 00699 } 00700 continue; 00701 } else { 00702 if (m->nd) glVertex3d(m->v[m->r[i].vi[j]].xs[dataSet][0], 00703 m->v[m->r[i].vi[j]].xs[dataSet][1], 00704 m->v[m->r[i].vi[j]].xs[dataSet][2]); 00705 else glVertex3d(m->v[m->r[i].vi[j]].x[0], 00706 m->v[m->r[i].vi[j]].x[1], 00707 m->v[m->r[i].vi[j]].x[2]); 00708 } 00709 } 00710 glEnd(); 00711 } 00712 } 00713 } 00714 00715 if (polyMesh) { 00716 for (int i=0;i<m->nr;i++) { 00717 glBegin(GL_TRIANGLES); 00718 if (!faceColors) glColor4f(float(objectColor[0])/100, 00719 float(objectColor[1])/100, 00720 float(objectColor[2])/100,.5); 00721 glNormal3d(m->r[i].n.x[0],m->r[i].n.x[1],m->r[i].n.x[2]); 00722 for(int j=0;j<m->r[i].tvi.size();j++) { 00723 if (m->r[i].tvi[j] >= 0) { 00724 glNormal3d(m->r[i].ni[j][0], 00725 m->r[i].ni[j][1], 00726 m->r[i].ni[j][2]); 00727 if (faceColors) 00728 glColor4f(fabs(m->r[i].ni[j][0]), 00729 fabs(m->r[i].ni[j][1]), 00730 fabs(m->r[i].ni[j][2]),0.5); 00731 glVertex3d(m->v[m->r[i].tvi[j]].x[0], 00732 m->v[m->r[i].tvi[j]].x[1], 00733 m->v[m->r[i].tvi[j]].x[2]); 00734 } 00735 } 00736 glEnd(); 00737 } 00738 } 00739 if (offset) glTranslatef(-offsetX*2*delta*cos(rotationY*D2R),0.0f, 00740 -offsetX*2*delta*sin(rotationY*D2R)); 00741 00742 // Draw the mesh boundary 00743 if (meshBoundary && 0) { 00744 glBegin(GL_LINES); 00745 glColor4f(0,0,0,0.5); 00746 glNormal3d(0,0,0); 00747 for (int i=0;i<m->ne;i++) { 00748 if (m->e[i].nf == 1) { 00749 glVertex3d(m->e[i].v[0]->x[0], 00750 m->e[i].v[0]->x[1], 00751 m->e[i].v[0]->x[2]); 00752 glVertex3d(m->e[i].v[1]->x[0], 00753 m->e[i].v[1]->x[1], 00754 m->e[i].v[1]->x[2]); 00755 } 00756 } 00757 glEnd(); 00758 00759 glBegin(GL_POINTS); 00760 for (int i=0;i<m->nv;i++) { 00761 if (m->v[i].bound) { 00762 glVertex3d(m->v[i].x[0], 00763 m->v[i].x[1], 00764 m->v[i].x[2]); 00765 } 00766 } 00767 glEnd(); 00768 00769 glBegin(GL_TRIANGLES); 00770 glColor4f(1,1,1,0.5); 00771 for (int i=0;i<m->nf;i++) { 00772 if (m->f[i].bound) { 00773 glVertex3d(m->f[i].v[0]->x[0], 00774 m->f[i].v[0]->x[1], 00775 m->f[i].v[0]->x[2]); 00776 glVertex3d(m->f[i].v[1]->x[0], 00777 m->f[i].v[1]->x[1], 00778 m->f[i].v[1]->x[2]); 00779 glVertex3d(m->f[i].v[2]->x[0], 00780 m->f[i].v[2]->x[1], 00781 m->f[i].v[2]->x[2]); 00782 } 00783 } 00784 glEnd(); 00785 } 00786 00787 // Draw the gradient vector field 00788 if (vertGradVecs) { 00789 glBegin(GL_LINES); 00790 glColor4f(0,0,0,0.5); 00791 glNormal3d(0,0,0); 00792 for (int i=0;i<m->nv;i++) { 00793 glVertex3d(m->v[i].x[0],m->v[i].x[1],m->v[i].x[2]); 00794 glVertex3d(m->v[i].x[0]+m->v[i].gradPsi[0]/(2*delta), 00795 m->v[i].x[1]+m->v[i].gradPsi[1]/(2*delta), 00796 m->v[i].x[2]+m->v[i].gradPsi[2]/(2*delta)); 00797 } 00798 glEnd(); 00799 } 00800 00801 // Draw the vertex normal vector field 00802 if (vertNormals) { 00803 glBegin(GL_LINES); 00804 glColor4f(0,0,0,0.5); 00805 glNormal3d(0,0,0); 00806 for (int i=0;i<m->nv;i++) { 00807 glVertex3d(m->v[i].x[0],m->v[i].x[1],m->v[i].x[2]); 00808 glVertex3d(m->v[i].x[0]+m->v[i].n[0]/delta, 00809 m->v[i].x[1]+m->v[i].n[1]/delta, 00810 m->v[i].x[2]+m->v[i].n[2]/delta); 00811 } 00812 glEnd(); 00813 } 00814 00815 // Draw the face-to-face links 00816 if (face2face) { 00817 glBegin(GL_LINES); 00818 glColor4f(1.0,0,0,0); 00819 glNormal3d(0,0,0); 00820 for (int i=0;i<m->nf;i++) { 00821 for (int j=0;j<m->f[i].nf;j++) { 00822 glVertex3d(m->f[i].x[0],m->f[i].x[1],m->f[i].x[2]); 00823 glVertex3d(m->f[i].f[j]->x[0],m->f[i].f[j]->x[1],m->f[i].f[j]->x[2]); 00824 } 00825 } 00826 glEnd(); 00827 } 00828 00829 // Draw the face-to-vertex links 00830 if (face2vert) { 00831 glBegin(GL_LINES); 00832 glColor4f(0,1.0,0,0); 00833 glNormal3d(0,0,0); 00834 for (int i=0;i<m->nf;i++) { 00835 for (int j=0;j<3;j++) { 00836 glVertex3d(m->f[i].x[0],m->f[i].x[1],m->f[i].x[2]); 00837 glVertex3d(m->f[i].v[j]->x[0],m->f[i].v[j]->x[1],m->f[i].v[j]->x[2]); 00838 } 00839 } 00840 glEnd(); 00841 } 00842 00843 // Draw edge-to-face links 00844 if (edge2face) { 00845 glBegin(GL_LINES); 00846 glColor4f(1.0,0,0,0); 00847 glNormal3d(0,0,0); 00848 for (int i=0;i<m->ne;i++) { 00849 for (int j=0;j<m->e[i].nf;j++) { 00850 glVertex3d(0.5*(m->e[i].v[0]->x[0] + m->e[i].v[1]->x[0]), 00851 0.5*(m->e[i].v[0]->x[1] + m->e[i].v[1]->x[1]), 00852 0.5*(m->e[i].v[0]->x[2] + m->e[i].v[1]->x[2])); 00853 glVertex3d(m->e[i].f[j]->x[0],m->e[i].f[j]->x[1],m->e[i].f[j]->x[2]); 00854 } 00855 } 00856 glEnd(); 00857 } 00858 00859 // Draw face-to-edge links 00860 if (face2edge) { 00861 glBegin(GL_LINES); 00862 glColor4f(1.0,0,0,0); 00863 glNormal3d(0,0,0); 00864 for (int i=0;i<m->nf;i++) { 00865 for (int j=0;j<3;j++) { 00866 glVertex3d(m->f[i].x[0],m->f[i].x[1],m->f[i].x[2]); 00867 glVertex3d(0.5*(m->f[i].e[j]->v[0]->x[0] + m->f[i].e[j]->v[1]->x[0]), 00868 0.5*(m->f[i].e[j]->v[0]->x[1] + m->f[i].e[j]->v[1]->x[1]), 00869 0.5*(m->f[i].e[j]->v[0]->x[2] + m->f[i].e[j]->v[1]->x[2])); 00870 } 00871 } 00872 glEnd(); 00873 } 00874 00875 } 00876 00877 00878 // Displays everything to the screen 00879 void myGlutDisplay(void) { 00880 //glClearColor(.9f, .9f, .9f, 1.0f); 00881 //glClearColor(0.3, 0.3, 0.3, 1.0f); 00882 if (blackWhite) glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 00883 else glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 00884 00885 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00886 00887 glMatrixMode(GL_PROJECTION); 00888 glLoadIdentity(); 00889 glFrustum(-xyAspect*.0008, xyAspect*.0008, -.0008, .0008, .01, 15.0); 00890 glMatrixMode(GL_MODELVIEW); 00891 00892 glLoadIdentity(); 00893 glTranslatef(0.0, 0.0, -1.2f); 00894 glRotatef(rotationX, 1.0, 0.0, 0.0); 00895 glRotatef(rotationY, 0.0, 1.0, 0.0); 00896 00897 // Render the center of rotation 00898 if (centerSphere || motionMode > 2) { 00899 glColor4f(1,0,0,0); 00900 glutSolidSphere(0.005,10,10); 00901 } 00902 00903 // Scale things according to zoom factor 00904 glScalef(scale, scale, scale); 00905 00906 // Render the mesh 00907 if (offset) glTranslatef(-offsetX*delta*cos(rotationY*D2R),0.0f, 00908 -offsetX*delta*sin(rotationY*D2R)); 00909 glTranslatef(-center[0], -center[1], -center[2]); 00910 drawMesh(); 00911 glTranslatef(center[0], center[1], center[2]); 00912 if (offset) glTranslatef(offsetX*delta*cos(rotationY*D2R),0.0f, 00913 offsetX*delta*sin(rotationY*D2R)); 00914 00915 // Disable lighting and set up ortho projection to render text 00916 glDisable(GL_LIGHTING); 00917 glMatrixMode(GL_PROJECTION); 00918 glLoadIdentity(); 00919 gluOrtho2D(0.0, 100.0, 0.0, 100.0); 00920 glMatrixMode(GL_MODELVIEW); 00921 glLoadIdentity(); 00922 glColor3ub(255,255,255); 00923 glRasterPos2i(10, 10); 00924 00925 // Render a few messages 00926 int color; 00927 if (blackWhite) color = 0; 00928 else color = 255; 00929 if (text) { 00930 if (textMode < 3) { 00931 if (offset) { 00932 char left[] = "Decimated Mesh"; 00933 char right[] = "Original Mesh"; 00934 glColor3ub(color,color,color); glRasterPos2i(20, 5); 00935 for(int i=0;i<(int)strlen(left);i++) 00936 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, left[i]); 00937 glColor3ub(color,color,color); glRasterPos2i(60, 5); 00938 for(int i=0;i<(int)strlen(right);i++) 00939 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, right[i]); 00940 } else if (triMesh) { 00941 char status[] = "Viewing: Reconstructed Surface"; 00942 glColor3ub(color,color,color); glRasterPos2i(5, 95); 00943 for(int i=0;i<(int)strlen(status);i++) 00944 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, status[i]); 00945 } else if (triMesh0) { 00946 char status[] = "Viewing: Original Surface"; 00947 glColor3ub(color,color,color); glRasterPos2i(5, 95); 00948 for(int i=0;i<(int)strlen(status);i++) 00949 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, status[i]); 00950 } else if (polyMesh) { 00951 char status[] = "Viewing: Decimated Surface"; 00952 glColor3ub(color,color,color); glRasterPos2i(5, 95); 00953 for(int i=0;i<(int)strlen(status);i++) 00954 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, status[i]); 00955 } 00956 } 00957 if (textMode == 1) { 00958 char status[] = "Performing CG Optimization..."; 00959 glColor3ub(color,color,color); glRasterPos2i(5, 90); 00960 for(int i=0;i<(int)strlen(status);i++) 00961 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, status[i]); 00962 } 00963 if (textMode == 2) { 00964 char status[] = "Performing Segmentation..."; 00965 glColor3ub(color,color,color); glRasterPos2i(5, 90); 00966 for(int i=0;i<(int)strlen(status);i++) 00967 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, status[i]); 00968 } 00969 if (textMode == 10) { 00970 glColor3ub(color,color,color); glRasterPos2i(5, 90); 00971 for(int i=0;i<(int)strlen(potentialInfo);i++) 00972 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, potentialInfo[i]); 00973 } 00974 } 00975 glEnable(GL_LIGHTING); 00976 00977 glutSwapBuffers(); 00978 } 00979 00980 void saveOptions() { 00981 cout << "- Saving GUI options..." << flush; 00982 ofstream fout("gui_options.dat"); 00983 if (fout) { 00984 // Window details 00985 fout << glutGet(GLUT_WINDOW_X) - bdx << " "; 00986 fout << glutGet(GLUT_WINDOW_Y) - bdy << endl; 00987 fout << glutGet(GLUT_WINDOW_WIDTH) << " "; 00988 fout << glutGet(GLUT_WINDOW_HEIGHT) << endl; 00989 fout << cx0 << endl; 00990 fout << cy0 << endl; 00991 00992 // Viewpoint variables 00993 fout << center[0] << " "; 00994 fout << center[1] << " "; 00995 fout << center[2] << endl; 00996 fout << rotationX << " "; 00997 fout << rotationY << endl; 00998 fout << lightRotX << " "; 00999 fout << lightRotY << endl; 01000 fout << scale << endl; 01001 fout << delta << endl; 01002 fout << blackWhite << endl; 01003 01004 // Visuals 01005 fout << triMesh << endl; 01006 fout << triMesh0 << endl; 01007 fout << wireframe << endl; 01008 fout << wireframe0 << endl; 01009 fout << points << endl; 01010 fout << points0 << endl; 01011 fout << polyMesh << endl; 01012 fout << lines << endl; 01013 fout << offset << endl; 01014 fout << face2face << endl; 01015 fout << face2vert << endl; 01016 fout << edgeAngles << endl; 01017 fout << vertPotentials << endl; 01018 fout << vertGradients << endl; 01019 fout << faceColors << endl; 01020 fout << centerSphere << endl; 01021 fout << meshBoundary << endl; 01022 fout << vertGradVecs << endl; 01023 fout << segment << endl; 01024 fout << objectColor[0] << " "; 01025 fout << objectColor[1] << " "; 01026 fout << objectColor[2] << endl; 01027 fout << diffuseIntensity << endl; 01028 fout << ambientIntensity << endl; 01029 } 01030 01031 fout.close(); 01032 cout << "Done." << endl << flush; 01033 } 01034 01035 void loadOptions() { 01036 cout << "- Loading GUI options..." << flush; 01037 ifstream fin("gui_options.dat"); 01038 if (fin) { 01039 // Window details 01040 fin >> wx0; 01041 fin >> wy0; 01042 fin >> wdx; 01043 fin >> wdy; 01044 fin >> cx0; 01045 fin >> cy0; 01046 01047 // Viewpoint variables 01048 fin >> center[0]; 01049 fin >> center[1]; 01050 fin >> center[2]; 01051 fin >> rotationX; 01052 fin >> rotationY; 01053 fin >> lightRotX; 01054 fin >> lightRotY; 01055 fin >> scale; 01056 fin >> delta; 01057 fin >> blackWhite; 01058 01059 // Visuals 01060 fin >> triMesh; 01061 fin >> triMesh0; 01062 fin >> wireframe; 01063 fin >> wireframe0; 01064 fin >> points; 01065 fin >> points0; 01066 fin >> polyMesh; 01067 fin >> lines; 01068 fin >> offset; 01069 fin >> face2face; 01070 fin >> face2vert; 01071 fin >> edgeAngles; 01072 fin >> vertPotentials; 01073 fin >> vertGradients; 01074 fin >> faceColors; 01075 fin >> centerSphere; 01076 fin >> meshBoundary; 01077 fin >> vertGradVecs; 01078 fin >> segment; 01079 fin >> objectColor[0]; 01080 fin >> objectColor[1]; 01081 fin >> objectColor[2]; 01082 fin >> diffuseIntensity; 01083 fin >> ambientIntensity; 01084 } 01085 01086 for (int i=0;i<3;i++) { 01087 light_diffuse[i] = float(diffuseIntensity)/100.0f; 01088 light_ambient[i] = float(ambientIntensity)/100.0f; 01089 } 01090 light_position[0] = cos(lightRotX*D2R)*sin(lightRotY*D2R); 01091 light_position[1] = sin(lightRotX*D2R)*sin(lightRotY*D2R); 01092 light_position[2] = cos(lightRotY*D2R); 01093 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 01094 gs2 = m->gs2; 01095 gsn2 = m->gsn2; 01096 fin.close(); 01097 cout << "Done." << endl << flush; 01098 } 01099 01100 void update(void) { 01101 sprintf(potentialInfo,"Potential: %.2f",m->psi); 01102 myGlutDisplay(); 01103 if (screenShots) takeScreenShot(); 01104 } 01105 01106 void takeScreenShot() { 01107 // Define file name 01108 if (screenShotNumber<10) { 01109 sprintf(screenShotName,"images/screenshot00%1d.jpg", 01110 screenShotNumber); 01111 } else if (screenShotNumber<100) { 01112 sprintf(screenShotName,"images/screenshot0%1d.jpg", 01113 screenShotNumber); 01114 } else { 01115 sprintf(screenShotName,"images/screenshot%1d.jpg", 01116 screenShotNumber); 01117 } 01118 cout << "Saving image: " << screenShotName << endl << flush;; 01119 01120 // Grab OpenGL screenshot 01121 ilutRenderer(ILUT_OPENGL); 01122 ilutGLScreen(); 01123 01124 // And save the resulting image to disk, overwriting if needed 01125 ilEnable(IL_FILE_OVERWRITE); 01126 ilSaveImage((const ILstring)screenShotName); 01127 01128 screenShotNumber++; 01129 } 01130 01131 01132 // Starts the graphical user interface 01133 int startGUI(Mesh *m_) { 01134 // Set local variables to passed values 01135 m = m_; 01136 offsetX = (m->boxMax[0] - m->boxMin[0])/10.0f; 01137 01138 01139 // initialize on-screen messages 01140 sprintf(sizeInfo,"%i Vertices",m->nv); 01141 sprintf(potentialInfo,"Potential: %.2f",m->psi); 01142 01143 m->registerCB(update); 01144 01145 // Load options file 01146 loadOptions(); 01147 01149 // Initialize GLUT and create window // 01151 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 01152 glutInitWindowPosition(wx0, wy0); 01153 glutInitWindowSize(wdx, wdy); 01154 01155 main_window = glutCreateWindow("ViewMesh 1.0"); 01156 glutDisplayFunc(myGlutDisplay); 01157 glutReshapeFunc(myGlutReshape); 01158 glutKeyboardFunc(myGlutKeyboard); 01159 glutMotionFunc(myGlutMotion); 01160 glutMouseFunc(myGlutMouse); 01161 01162 // Set up OpenGL lights 01163 glEnable(GL_LIGHTING); 01164 glEnable(GL_NORMALIZE); 01165 01166 glEnable(GL_LIGHT0); 01167 if (faceColors) { 01168 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_zero); 01169 glLightfv(GL_LIGHT0, GL_AMBIENT, light_one); 01170 } 01171 else { 01172 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 01173 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 01174 } 01175 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 01176 01177 // Set up OpenGL materials 01178 glEnable(GL_COLOR_MATERIAL); 01179 01180 // Make sure lines appear above polygons 01181 if (lines) { 01182 glPolygonOffset(1.0,0.1); 01183 glEnable(GL_POLYGON_OFFSET_FILL); 01184 } else { 01185 glDisable(GL_POLYGON_OFFSET_FILL); 01186 } 01187 01188 // Enable z-buferring and others 01189 glEnable(GL_DEPTH_TEST); 01190 glClearDepth(1.0f); 01191 glDepthFunc(GL_LEQUAL); 01192 glPointSize(1); 01193 //glEnable(GL_CULL_FACE); 01194 01195 01197 // Here's the GLUI code // 01199 cout << "- Starting GLUI version " << GLUI_Master.get_version() << endl; 01200 01201 // name, flags, x, and y 01202 glui = GLUI_Master.create_glui("Control Panel", cx0, cy0, 0); 01203 01204 glui->add_statictext("ViewMesh 1.0"); 01205 visualsRollout = glui->add_rollout("Visuals", true); 01206 01207 // Control for the visual display 01208 glui->add_checkbox_to_panel 01209 (visualsRollout,"Original Mesh",&triMesh0,0); 01210 glui->add_checkbox_to_panel 01211 (visualsRollout,"Orig. Wireframe",&wireframe0,0); 01212 glui->add_checkbox_to_panel 01213 (visualsRollout,"Orig. Point Cloud",&points0,0); 01214 glui->add_checkbox_to_panel 01215 (visualsRollout,"Current Mesh",&triMesh,0); 01216 glui->add_checkbox_to_panel 01217 (visualsRollout,"Curr. Wireframe",&wireframe,0); 01218 glui->add_checkbox_to_panel 01219 (visualsRollout,"Curr. Point Cloud",&points,0); 01220 glui->add_button_to_panel(visualsRollout,"Swap",63,controlCB); 01221 glui->add_checkbox_to_panel 01222 (visualsRollout,"Vert Norms",&vertNorm,0); 01223 glui->add_checkbox_to_panel 01224 (visualsRollout,"Face-to-Face",&face2face,0); 01225 glui->add_checkbox_to_panel 01226 (visualsRollout,"Face-to-Vertex",&face2vert,0); 01227 glui->add_checkbox_to_panel 01228 (visualsRollout,"Edge Angles",&edgeAngles,0); 01229 glui->add_checkbox_to_panel 01230 (visualsRollout,"Vert Potentials",&vertPotentials,0); 01231 glui->add_checkbox_to_panel 01232 (visualsRollout,"Vert Gradients",&vertGradients,0); 01233 glui->add_checkbox_to_panel 01234 (visualsRollout,"Face Colors",&faceColors,62, controlCB); 01235 glui->add_checkbox_to_panel 01236 (visualsRollout,"Center Sphere",¢erSphere,0); 01237 glui->add_checkbox_to_panel 01238 (visualsRollout,"Mesh Boundary",&meshBoundary,0); 01239 glui->add_checkbox_to_panel 01240 (visualsRollout,"Vert Normals",&vertNormals,0); 01241 glui->add_checkbox_to_panel 01242 (visualsRollout,"Vert Grad Vecs",&vertGradVecs,0); 01243 glui->add_checkbox_to_panel 01244 (visualsRollout,"Segmentation",&segment,0); 01245 glui->add_checkbox_to_panel 01246 (visualsRollout,"Key Points",&keypoints,0); 01247 glui->add_checkbox_to_panel 01248 (visualsRollout,"PolyMesh",&polyMesh,0); 01249 glui->add_checkbox_to_panel 01250 (visualsRollout,"PolyWire",&polyWire,0); 01251 glui->add_checkbox_to_panel 01252 (visualsRollout,"DeciMesh",&deciMesh,0); 01253 glui->add_checkbox_to_panel 01254 (visualsRollout,"DeciWire",&deciWire,0); 01255 glui->add_checkbox_to_panel 01256 (visualsRollout,"Text",&text,0); 01257 glui->add_checkbox_to_panel 01258 (visualsRollout,"Black/White",&blackWhite,65, controlCB); 01259 glui->add_checkbox_to_panel 01260 (visualsRollout,"Lines",&lines,64, controlCB); 01261 glui->add_checkbox_to_panel 01262 (visualsRollout,"Offset",&offset,0); 01263 01264 // Add some controls for lights 01265 objectRSpinner = glui->add_spinner_to_panel 01266 (visualsRollout, "Object Red:", GLUI_SPINNER_INT, 01267 &(objectColor[0]),250,controlCB); 01268 objectRSpinner->set_int_limits(0, 100); 01269 objectGSpinner = glui->add_spinner_to_panel 01270 (visualsRollout, "Object Green:", GLUI_SPINNER_INT, 01271 &(objectColor[1]),250,controlCB); 01272 objectGSpinner->set_int_limits(0, 100); 01273 objectBSpinner = glui->add_spinner_to_panel 01274 (visualsRollout, "Object Blue:", GLUI_SPINNER_INT, 01275 &(objectColor[2]),250,controlCB); 01276 objectBSpinner->set_int_limits(0, 100); 01277 ambientSpinner = glui->add_spinner_to_panel 01278 (visualsRollout, "Ambient:", GLUI_SPINNER_INT, 01279 &ambientIntensity,250,controlCB); 01280 ambientSpinner->set_int_limits(0, 100); 01281 01282 deltaSpinner = glui->add_spinner_to_panel 01283 (visualsRollout, "Delta:", GLUI_SPINNER_FLOAT, 01284 &delta,0,controlCB); 01285 deltaSpinner->set_float_limits(0,100); 01286 01287 gs2Spinner = glui->add_spinner_to_panel 01288 (visualsRollout, "Vert Var:", GLUI_SPINNER_FLOAT, 01289 &gs2,251,controlCB); 01290 gs2Spinner->set_float_limits(0,100000); 01291 01292 gsn2Spinner = glui->add_spinner_to_panel 01293 (visualsRollout, "Normal Var:", GLUI_SPINNER_FLOAT, 01294 &gsn2,251,controlCB); 01295 gsn2Spinner->set_float_limits(0,10); 01296 01297 segThreshSpinner = glui->add_spinner_to_panel 01298 (visualsRollout, "Seg Thresh", GLUI_SPINNER_FLOAT, 01299 &(m->segThresh),251,controlCB); 01300 segThreshSpinner->set_float_limits(0,10); 01301 01302 glui->add_checkbox 01303 ("Take Screenshots",&screenShots,0); 01304 01305 // Recenter button 01306 glui->add_button("Recenter",150,controlCB); 01307 // A 'run' button 01308 glui->add_button("Run",151,controlCB); 01309 glui->add_button("Run Anneal",154,controlCB); 01310 glui->add_button("Reset",152,controlCB); 01311 glui->add_button("Segment",155,controlCB); 01312 glui->add_button("Tessellate",157,controlCB); 01313 01314 // Save mesh button 01315 glui->add_button("Save Mesh", 156,controlCB); 01316 01317 // Save options button 01318 glui->add_button("Save Options",100,controlCB); 01319 // A 'quit' button 01320 glui->add_button("Quit", -1,controlCB); 01321 01322 // Add some controls for lights 01323 dataSetSpinner = glui->add_spinner 01324 ("Data Set:", GLUI_SPINNER_INT, 01325 &dataSet,250,controlCB); 01326 dataSetSpinner->set_int_limits(0, (m->nd-1)); 01327 01328 // Link windows to GLUI, and register idle callback 01329 glui->set_main_gfx_window(main_window); 01330 01331 // We register the idle callback with GLUI, not with GLUT 01332 GLUI_Master.set_glutIdleFunc(myGlutIdle); 01333 01334 // Regular GLUT main loop 01335 glutMainLoop(); 01336 01337 return 0; 01338 }