example.cpp 16 KB

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