example.cpp 16 KB

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