example.cpp 16 KB

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