example.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. #include <igl/OpenGL_convenience.h>
  2. #include <igl/per_face_normals.h>
  3. #include <igl/two_axis_valuator_fixed_up.h>
  4. #include <igl/normalize_row_lengths.h>
  5. #include <igl/draw_mesh.h>
  6. #include <igl/draw_floor.h>
  7. #include <igl/quat_to_mat.h>
  8. #include <igl/report_gl_error.h>
  9. #include <igl/readOBJ.h>
  10. #include <igl/readDMAT.h>
  11. #include <igl/readOFF.h>
  12. #include <igl/readMESH.h>
  13. #include <igl/jet.h>
  14. #include <igl/readWRL.h>
  15. #include <igl/trackball.h>
  16. #include <igl/list_to_matrix.h>
  17. #include <igl/snap_to_canonical_view_quat.h>
  18. #include <igl/snap_to_fixed_up.h>
  19. #include <igl/polygon_mesh_to_triangle_mesh.h>
  20. #include <igl/material_colors.h>
  21. #include <igl/barycenter.h>
  22. #include <igl/matlab_format.h>
  23. #include <igl/ReAntTweakBar.h>
  24. #include <igl/pathinfo.h>
  25. #include <igl/Camera.h>
  26. #include <igl/get_seconds.h>
  27. #include <igl/cgal/remesh_self_intersections.h>
  28. #include <igl/cgal/intersect_other.h>
  29. #ifdef __APPLE__
  30. # include <GLUT/glut.h>
  31. #else
  32. # include <GL/glut.h>
  33. #endif
  34. #include <Eigen/Core>
  35. #include <vector>
  36. #include <iostream>
  37. #include <algorithm>
  38. struct State
  39. {
  40. igl::Camera camera;
  41. } s;
  42. enum RotationType
  43. {
  44. ROTATION_TYPE_IGL_TRACKBALL = 0,
  45. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  46. NUM_ROTATION_TYPES = 2,
  47. } rotation_type;
  48. bool is_rotating = false;
  49. int down_x,down_y;
  50. igl::Camera down_camera;
  51. bool is_animating = false;
  52. double animation_start_time = 0;
  53. double ANIMATION_DURATION = 0.5;
  54. Eigen::Quaterniond animation_from_quat;
  55. Eigen::Quaterniond animation_to_quat;
  56. // Use vector for range-based `for`
  57. std::vector<State> undo_stack;
  58. std::vector<State> redo_stack;
  59. void push_undo()
  60. {
  61. undo_stack.push_back(s);
  62. // Clear
  63. redo_stack = std::vector<State>();
  64. }
  65. void undo()
  66. {
  67. using namespace std;
  68. if(!undo_stack.empty())
  69. {
  70. redo_stack.push_back(s);
  71. s = undo_stack.front();
  72. undo_stack.pop_back();
  73. }
  74. }
  75. void redo()
  76. {
  77. using namespace std;
  78. if(!redo_stack.empty())
  79. {
  80. undo_stack.push_back(s);
  81. s = redo_stack.front();
  82. redo_stack.pop_back();
  83. }
  84. }
  85. void TW_CALL set_rotation_type(const void * value, void * clientData)
  86. {
  87. using namespace Eigen;
  88. using namespace std;
  89. using namespace igl;
  90. const RotationType old_rotation_type = rotation_type;
  91. rotation_type = *(const RotationType *)(value);
  92. if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
  93. old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
  94. {
  95. push_undo();
  96. animation_from_quat = s.camera.m_rotation_conj;
  97. snap_to_fixed_up(animation_from_quat,animation_to_quat);
  98. // start animation
  99. animation_start_time = get_seconds();
  100. is_animating = true;
  101. }
  102. }
  103. void TW_CALL get_rotation_type(void * value, void *clientData)
  104. {
  105. RotationType * rt = (RotationType *)(value);
  106. *rt = rotation_type;
  107. }
  108. // Width and height of window
  109. int width,height;
  110. // Position of light
  111. float light_pos[4] = {0.1,0.1,-0.9,0};
  112. // V,U Vertex positions
  113. // C,D Colors
  114. // N,W Normals
  115. // mid combined "centroid"
  116. Eigen::MatrixXd V,N,C,Z,mid,U,W,D;
  117. // F,G faces
  118. Eigen::MatrixXi F,G;
  119. bool has_other = false;
  120. bool show_A = true;
  121. bool show_B = true;
  122. int selected_col = 0;
  123. // Bounding box diagonal length
  124. double bbd;
  125. // Running ambient occlusion
  126. Eigen::VectorXd S;
  127. int tot_num_samples = 0;
  128. #define REBAR_NAME "temp.rbr"
  129. igl::ReTwBar rebar; // Pointer to the tweak bar
  130. void reshape(int width,int height)
  131. {
  132. using namespace std;
  133. // Save width and height
  134. ::width = width;
  135. ::height = height;
  136. glMatrixMode(GL_PROJECTION);
  137. glLoadIdentity();
  138. glViewport(0,0,width,height);
  139. // Send the new window size to AntTweakBar
  140. TwWindowSize(width, height);
  141. // Set aspect for all cameras
  142. s.camera.m_aspect = (double)width/(double)height;
  143. for(auto & s : undo_stack)
  144. {
  145. s.camera.m_aspect = (double)width/(double)height;
  146. }
  147. for(auto & s : redo_stack)
  148. {
  149. s.camera.m_aspect = (double)width/(double)height;
  150. }
  151. }
  152. void push_scene()
  153. {
  154. using namespace igl;
  155. using namespace std;
  156. glMatrixMode(GL_PROJECTION);
  157. glPushMatrix();
  158. glLoadIdentity();
  159. auto & camera = s.camera;
  160. gluPerspective(camera.m_angle,camera.m_aspect,camera.m_near,camera.m_far);
  161. glMatrixMode(GL_MODELVIEW);
  162. glPushMatrix();
  163. glLoadIdentity();
  164. gluLookAt(
  165. camera.eye()(0), camera.eye()(1), camera.eye()(2),
  166. camera.at()(0), camera.at()(1), camera.at()(2),
  167. camera.up()(0), camera.up()(1), camera.up()(2));
  168. }
  169. void pop_scene()
  170. {
  171. glMatrixMode(GL_PROJECTION);
  172. glPopMatrix();
  173. glMatrixMode(GL_MODELVIEW);
  174. glPopMatrix();
  175. }
  176. void pop_object()
  177. {
  178. glPopMatrix();
  179. }
  180. // Scale and shift for object
  181. void push_object()
  182. {
  183. glPushMatrix();
  184. glScaled(2./bbd,2./bbd,2./bbd);
  185. glTranslated(-mid(0,0),-mid(0,1),-mid(0,2));
  186. }
  187. // Set up double-sided lights
  188. void lights()
  189. {
  190. using namespace std;
  191. glEnable(GL_LIGHTING);
  192. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  193. glEnable(GL_LIGHT0);
  194. glEnable(GL_LIGHT1);
  195. float amb[4];
  196. amb[0] = amb[1] = amb[2] = 0;
  197. amb[3] = 1.0;
  198. float diff[4] = {0.0,0.0,0.0,0.0};
  199. diff[0] = diff[1] = diff[2] = (1.0 - 0/0.4);;
  200. diff[3] = 1.0;
  201. float zeros[4] = {0.0,0.0,0.0,0.0};
  202. float pos[4];
  203. copy(light_pos,light_pos+4,pos);
  204. glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
  205. glLightfv(GL_LIGHT0,GL_DIFFUSE,diff);
  206. glLightfv(GL_LIGHT0,GL_SPECULAR,zeros);
  207. glLightfv(GL_LIGHT0,GL_POSITION,pos);
  208. pos[0] *= -1;
  209. pos[1] *= -1;
  210. pos[2] *= -1;
  211. glLightfv(GL_LIGHT1,GL_AMBIENT,amb);
  212. glLightfv(GL_LIGHT1,GL_DIFFUSE,diff);
  213. glLightfv(GL_LIGHT1,GL_SPECULAR,zeros);
  214. glLightfv(GL_LIGHT1,GL_POSITION,pos);
  215. }
  216. const float back[4] = {30.0/255.0,30.0/255.0,50.0/255.0,0};
  217. void display()
  218. {
  219. using namespace Eigen;
  220. using namespace igl;
  221. using namespace std;
  222. glClearColor(back[0],back[1],back[2],0);
  223. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  224. if(is_animating)
  225. {
  226. double t = (get_seconds() - animation_start_time)/ANIMATION_DURATION;
  227. if(t > 1)
  228. {
  229. t = 1;
  230. is_animating = false;
  231. }
  232. const Quaterniond q = animation_from_quat.slerp(t,animation_to_quat).normalized();
  233. s.camera.orbit(q.conjugate());
  234. }
  235. glDisable(GL_LIGHTING);
  236. lights();
  237. push_scene();
  238. glEnable(GL_DEPTH_TEST);
  239. glDepthFunc(GL_LEQUAL);
  240. glEnable(GL_NORMALIZE);
  241. glEnable(GL_COLOR_MATERIAL);
  242. glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
  243. push_object();
  244. // Draw the model
  245. // Set material properties
  246. glEnable(GL_COLOR_MATERIAL);
  247. const auto draw = [](
  248. const MatrixXd & V,
  249. const MatrixXi & F,
  250. const MatrixXd & N,
  251. const MatrixXd & C)
  252. {
  253. glEnable(GL_POLYGON_OFFSET_FILL); // Avoid Stitching!
  254. glPolygonOffset(1.0,1);
  255. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  256. draw_mesh(V,F,N,C);
  257. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  258. glDisable(GL_COLOR_MATERIAL);
  259. const float black[4] = {0,0,0,1};
  260. glColor4fv(black);
  261. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
  262. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black);
  263. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
  264. glLightfv(GL_LIGHT0, GL_AMBIENT, black);
  265. glLightfv(GL_LIGHT0, GL_DIFFUSE, black);
  266. glLineWidth(1.0);
  267. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  268. draw_mesh(V,F,N,C);
  269. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  270. glEnable(GL_COLOR_MATERIAL);
  271. };
  272. if(show_A)
  273. {
  274. draw(V,F,N,C);
  275. }
  276. if(show_B)
  277. {
  278. draw(U,G,W,D);
  279. }
  280. pop_object();
  281. // Draw a nice floor
  282. glPushMatrix();
  283. const double floor_offset =
  284. -2./bbd*(V.col(1).maxCoeff()-mid(1));
  285. glTranslated(0,floor_offset,0);
  286. const float GREY[4] = {0.5,0.5,0.6,1.0};
  287. const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  288. draw_floor(GREY,DARK_GREY);
  289. glPopMatrix();
  290. pop_scene();
  291. report_gl_error();
  292. TwDraw();
  293. glutSwapBuffers();
  294. if(is_animating)
  295. {
  296. glutPostRedisplay();
  297. }
  298. }
  299. void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
  300. {
  301. using namespace std;
  302. using namespace igl;
  303. using namespace Eigen;
  304. GLint viewport[4];
  305. glGetIntegerv(GL_VIEWPORT,viewport);
  306. if(wheel == 0 && TwMouseMotion(mouse_x, viewport[3] - mouse_y))
  307. {
  308. static double mouse_scroll_y = 0;
  309. const double delta_y = 0.125*direction;
  310. mouse_scroll_y += delta_y;
  311. TwMouseWheel(mouse_scroll_y);
  312. return;
  313. }
  314. push_undo();
  315. auto & camera = s.camera;
  316. if(wheel==0)
  317. {
  318. // factor of zoom change
  319. double s = (1.-0.01*direction);
  320. //// FOV zoom: just widen angle. This is hardly ever appropriate.
  321. //camera.m_angle *= s;
  322. //camera.m_angle = min(max(camera.m_angle,1),89);
  323. camera.push_away(s);
  324. }else
  325. {
  326. // Dolly zoom:
  327. camera.dolly_zoom((double)direction*1.0);
  328. }
  329. }
  330. void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
  331. {
  332. using namespace std;
  333. using namespace Eigen;
  334. using namespace igl;
  335. bool tw_using = TwEventMouseButtonGLUT(glutButton,glutState,mouse_x,mouse_y);
  336. switch(glutButton)
  337. {
  338. case GLUT_RIGHT_BUTTON:
  339. case GLUT_LEFT_BUTTON:
  340. {
  341. switch(glutState)
  342. {
  343. case 1:
  344. // up
  345. glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
  346. is_rotating = false;
  347. break;
  348. case 0:
  349. // down
  350. if(!tw_using)
  351. {
  352. glutSetCursor(GLUT_CURSOR_CYCLE);
  353. // collect information for trackball
  354. is_rotating = true;
  355. down_camera = s.camera;
  356. down_x = mouse_x;
  357. down_y = mouse_y;
  358. }
  359. break;
  360. }
  361. break;
  362. }
  363. // Scroll down
  364. case 3:
  365. {
  366. mouse_wheel(0,-1,mouse_x,mouse_y);
  367. break;
  368. }
  369. // Scroll up
  370. case 4:
  371. {
  372. mouse_wheel(0,1,mouse_x,mouse_y);
  373. break;
  374. }
  375. // Scroll left
  376. case 5:
  377. {
  378. mouse_wheel(1,-1,mouse_x,mouse_y);
  379. break;
  380. }
  381. // Scroll right
  382. case 6:
  383. {
  384. mouse_wheel(1,1,mouse_x,mouse_y);
  385. break;
  386. }
  387. }
  388. glutPostRedisplay();
  389. }
  390. void mouse_drag(int mouse_x, int mouse_y)
  391. {
  392. using namespace igl;
  393. using namespace Eigen;
  394. if(is_rotating)
  395. {
  396. glutSetCursor(GLUT_CURSOR_CYCLE);
  397. Quaterniond q;
  398. auto & camera = s.camera;
  399. switch(rotation_type)
  400. {
  401. case ROTATION_TYPE_IGL_TRACKBALL:
  402. {
  403. // Rotate according to trackball
  404. igl::trackball<double>(
  405. width,
  406. height,
  407. 2.0,
  408. down_camera.m_rotation_conj.coeffs().data(),
  409. down_x,
  410. down_y,
  411. mouse_x,
  412. mouse_y,
  413. q.coeffs().data());
  414. break;
  415. }
  416. case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
  417. {
  418. // Rotate according to two axis valuator with fixed up vector
  419. two_axis_valuator_fixed_up(
  420. width, height,
  421. 2.0,
  422. down_camera.m_rotation_conj,
  423. down_x, down_y, mouse_x, mouse_y,
  424. q);
  425. break;
  426. }
  427. default:
  428. break;
  429. }
  430. camera.orbit(q.conjugate());
  431. }else
  432. {
  433. TwEventMouseMotionGLUT(mouse_x, mouse_y);
  434. }
  435. glutPostRedisplay();
  436. }
  437. void color_selfintersections(
  438. const Eigen::MatrixXd & V,
  439. const Eigen::MatrixXi & F,
  440. Eigen::MatrixXd & C)
  441. {
  442. using namespace igl;
  443. using namespace Eigen;
  444. MatrixXd SV;
  445. MatrixXi SF,IF;
  446. VectorXi J,IM;
  447. RemeshSelfIntersectionsParam params;
  448. params.detect_only = true;
  449. remesh_self_intersections(V,F,params,SV,SF,IF,J,IM);
  450. C.resize(F.rows(),3);
  451. C.col(0).setConstant(0.4);
  452. C.col(1).setConstant(0.8);
  453. C.col(2).setConstant(0.3);
  454. for(int f = 0;f<IF.rows();f++)
  455. {
  456. C.row(IF(f,0)) = RowVector3d(1,0.4,0.4);
  457. C.row(IF(f,1)) = RowVector3d(1,0.4,0.4);
  458. }
  459. }
  460. void color_intersections(
  461. const Eigen::MatrixXd & V,
  462. const Eigen::MatrixXi & F,
  463. const Eigen::MatrixXd & U,
  464. const Eigen::MatrixXi & G,
  465. Eigen::MatrixXd & C,
  466. Eigen::MatrixXd & D)
  467. {
  468. using namespace igl;
  469. using namespace Eigen;
  470. MatrixXi IF;
  471. const bool first_only = false;
  472. intersect_other(V,F,U,G,first_only,IF);
  473. C.resize(F.rows(),3);
  474. C.col(0).setConstant(0.4);
  475. C.col(1).setConstant(0.8);
  476. C.col(2).setConstant(0.3);
  477. D.resize(G.rows(),3);
  478. D.col(0).setConstant(0.4);
  479. D.col(1).setConstant(0.3);
  480. D.col(2).setConstant(0.8);
  481. for(int f = 0;f<IF.rows();f++)
  482. {
  483. C.row(IF(f,0)) = RowVector3d(1,0.4,0.4);
  484. D.row(IF(f,1)) = RowVector3d(0.8,0.7,0.3);
  485. }
  486. }
  487. void key(unsigned char key, int mouse_x, int mouse_y)
  488. {
  489. using namespace std;
  490. switch(key)
  491. {
  492. // ESC
  493. case char(27):
  494. rebar.save(REBAR_NAME);
  495. // ^C
  496. case char(3):
  497. exit(0);
  498. default:
  499. if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
  500. {
  501. cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
  502. }
  503. }
  504. glutPostRedisplay();
  505. }
  506. int main(int argc, char * argv[])
  507. {
  508. using namespace Eigen;
  509. using namespace igl;
  510. using namespace std;
  511. // init mesh
  512. string filename = "../shared/truck.obj";
  513. string filename_other = "";
  514. switch(argc)
  515. {
  516. case 3:
  517. // Read and prepare mesh
  518. filename_other = argv[2];
  519. has_other=true;
  520. // fall through
  521. case 2:
  522. // Read and prepare mesh
  523. filename = argv[1];
  524. break;
  525. default:
  526. cerr<<"Usage:"<<endl<<" ./example input.obj [other.obj]"<<endl;
  527. cout<<endl<<"Opening default mesh..."<<endl;
  528. }
  529. const auto read = []
  530. (const string & filename, MatrixXd & V, MatrixXi & F, MatrixXd & N) -> bool
  531. {
  532. // dirname, basename, extension and filename
  533. string d,b,ext,f;
  534. pathinfo(filename,d,b,ext,f);
  535. // Convert extension to lower case
  536. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  537. vector<vector<double > > vV,vN,vTC;
  538. vector<vector<int > > vF,vFTC,vFN;
  539. if(ext == "obj")
  540. {
  541. // Convert extension to lower case
  542. if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
  543. {
  544. return false;
  545. }
  546. }else if(ext == "off")
  547. {
  548. // Convert extension to lower case
  549. if(!igl::readOFF(filename,vV,vF,vN))
  550. {
  551. return false;
  552. }
  553. }else if(ext == "wrl")
  554. {
  555. // Convert extension to lower case
  556. if(!igl::readWRL(filename,vV,vF))
  557. {
  558. return false;
  559. }
  560. //}else
  561. //{
  562. // // Convert extension to lower case
  563. // MatrixXi T;
  564. // if(!igl::readMESH(filename,V,T,F))
  565. // {
  566. // return false;
  567. // }
  568. // //if(F.size() > T.size() || F.size() == 0)
  569. // {
  570. // boundary_facets(T,F);
  571. // }
  572. }
  573. if(vV.size() > 0)
  574. {
  575. if(!list_to_matrix(vV,V))
  576. {
  577. return false;
  578. }
  579. polygon_mesh_to_triangle_mesh(vF,F);
  580. }
  581. // Compute normals, centroid, colors, bounding box diagonal
  582. per_face_normals(V,F,N);
  583. return true;
  584. };
  585. if(!read(filename,V,F,N))
  586. {
  587. return 1;
  588. }
  589. if(has_other)
  590. {
  591. if(!read(argv[2],U,G,W))
  592. {
  593. return 1;
  594. }
  595. mid = 0.25*(V.colwise().maxCoeff() + V.colwise().minCoeff()) +
  596. 0.25*(U.colwise().maxCoeff() + U.colwise().minCoeff());
  597. bbd = max(
  598. (V.colwise().maxCoeff() - V.colwise().minCoeff()).maxCoeff(),
  599. (U.colwise().maxCoeff() - U.colwise().minCoeff()).maxCoeff());
  600. color_intersections(V,F,U,G,C,D);
  601. }else
  602. {
  603. mid = 0.5*(V.colwise().maxCoeff() + V.colwise().minCoeff());
  604. bbd = (V.colwise().maxCoeff() - V.colwise().minCoeff()).maxCoeff();
  605. color_selfintersections(V,F,C);
  606. }
  607. // Init glut
  608. glutInit(&argc,argv);
  609. if( !TwInit(TW_OPENGL, NULL) )
  610. {
  611. // A fatal error occured
  612. fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
  613. return 1;
  614. }
  615. // Create a tweak bar
  616. rebar.TwNewBar("TweakBar");
  617. rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D,
  618. s.camera.m_rotation_conj.coeffs().data(), "open readonly=true");
  619. s.camera.push_away(3);
  620. s.camera.dolly_zoom(25-s.camera.m_angle);
  621. TwType RotationTypeTW = ReTwDefineEnumFromString("RotationType",
  622. "igl_trackball,two-a...-fixed-up");
  623. rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
  624. set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
  625. if(has_other)
  626. {
  627. rebar.TwAddVarRW("show_A",TW_TYPE_BOOLCPP,&show_A, "key=a",false);
  628. rebar.TwAddVarRW("show_B",TW_TYPE_BOOLCPP,&show_B, "key=b",false);
  629. }
  630. rebar.load(REBAR_NAME);
  631. glutInitDisplayString("rgba depth double samples>=8 ");
  632. glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT));
  633. glutCreateWindow("mesh-intersections");
  634. glutDisplayFunc(display);
  635. glutReshapeFunc(reshape);
  636. glutKeyboardFunc(key);
  637. glutMouseFunc(mouse);
  638. glutMotionFunc(mouse_drag);
  639. glutPassiveMotionFunc(
  640. [](int x, int y)
  641. {
  642. TwEventMouseMotionGLUT(x,y);
  643. glutPostRedisplay();
  644. });
  645. static std::function<void(int)> timer_bounce;
  646. auto timer = [] (int ms) {
  647. timer_bounce(ms);
  648. };
  649. timer_bounce = [&] (int ms) {
  650. glutTimerFunc(ms, timer, ms);
  651. glutPostRedisplay();
  652. };
  653. glutTimerFunc(500, timer, 500);
  654. glutMainLoop();
  655. return 0;
  656. }