example.cpp 16 KB

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