example.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. #include <igl/draw_skeleton_3d.h>
  2. #include <igl/draw_skeleton_vector_graphics.h>
  3. #include <igl/two_axis_valuator_fixed_up.h>
  4. #include <igl/readOBJ.h>
  5. #include <igl/readTGF.h>
  6. #include <igl/writeOBJ.h>
  7. #include <igl/writeOFF.h>
  8. #include <igl/readWRL.h>
  9. #include <igl/report_gl_error.h>
  10. #include <igl/triangulate.h>
  11. #include <igl/readOFF.h>
  12. #include <igl/readMESH.h>
  13. #include <igl/draw_mesh.h>
  14. #include <igl/draw_floor.h>
  15. #include <igl/pathinfo.h>
  16. #include <igl/list_to_matrix.h>
  17. #include <igl/quat_to_mat.h>
  18. #include <igl/per_face_normals.h>
  19. #include <igl/material_colors.h>
  20. #include <igl/trackball.h>
  21. #include <igl/snap_to_canonical_view_quat.h>
  22. #include <igl/snap_to_fixed_up.h>
  23. #include <igl/REDRUM.h>
  24. #include <igl/Camera.h>
  25. #include <igl/ReAntTweakBar.h>
  26. #include <igl/get_seconds.h>
  27. #include <igl/forward_kinematics.h>
  28. #include <igl/tetgen/mesh_with_skeleton.h>
  29. #include <igl/boundary_conditions.h>
  30. #include <igl/normalize_row_sums.h>
  31. #include <igl/lbs_matrix.h>
  32. #include <igl/bbw/bbw.h>
  33. #include <Eigen/Core>
  34. #include <Eigen/Geometry>
  35. #ifdef __APPLE__
  36. #include <GLUT/glut.h>
  37. #include <Carbon/Carbon.h>
  38. #else
  39. #include <GL/glut.h>
  40. #endif
  41. #include <string>
  42. #include <vector>
  43. #include <stack>
  44. #include <iostream>
  45. enum SkelStyleType
  46. {
  47. SKEL_STYLE_TYPE_3D = 0,
  48. SKEL_STYLE_TYPE_VECTOR_GRAPHICS = 1,
  49. NUM_SKEL_STYLE_TYPE = 2
  50. }skel_style;
  51. Eigen::MatrixXd V,N,C,W,M;
  52. Eigen::VectorXd Vmid,Vmin,Vmax;
  53. double bbd = 1.0;
  54. Eigen::MatrixXi F,BE;
  55. Eigen::VectorXi P;
  56. struct State
  57. {
  58. igl::Camera camera;
  59. } s;
  60. bool wireframe = false;
  61. bool skeleton_on_top = false;
  62. // See README for descriptions
  63. enum RotationType
  64. {
  65. ROTATION_TYPE_IGL_TRACKBALL = 0,
  66. ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
  67. NUM_ROTATION_TYPES = 2,
  68. } rotation_type;
  69. std::stack<State> undo_stack;
  70. std::stack<State> redo_stack;
  71. bool is_rotating = false;
  72. int down_x,down_y;
  73. igl::Camera down_camera;
  74. bool is_animating = false;
  75. double animation_start_time = 0;
  76. double ANIMATION_DURATION = 0.5;
  77. Eigen::Quaterniond animation_from_quat;
  78. Eigen::Quaterniond animation_to_quat;
  79. int width,height;
  80. Eigen::Vector4f light_pos(-0.1,-0.1,0.9,0);
  81. #define REBAR_NAME "temp.rbr"
  82. igl::ReTwBar rebar;
  83. void push_undo()
  84. {
  85. undo_stack.push(s);
  86. // Clear
  87. redo_stack = std::stack<State>();
  88. }
  89. // No-op setter, does nothing
  90. void TW_CALL no_op(const void * /*value*/, void * /*clientData*/)
  91. {
  92. }
  93. void TW_CALL set_rotation_type(const void * value, void * clientData)
  94. {
  95. using namespace Eigen;
  96. using namespace std;
  97. using namespace igl;
  98. const RotationType old_rotation_type = rotation_type;
  99. rotation_type = *(const RotationType *)(value);
  100. if(rotation_type == ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP &&
  101. old_rotation_type != ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP)
  102. {
  103. push_undo();
  104. animation_from_quat = s.camera.m_rotation_conj;
  105. snap_to_fixed_up(animation_from_quat,animation_to_quat);
  106. // start animation
  107. animation_start_time = get_seconds();
  108. is_animating = true;
  109. }
  110. }
  111. void TW_CALL get_rotation_type(void * value, void *clientData)
  112. {
  113. RotationType * rt = (RotationType *)(value);
  114. *rt = rotation_type;
  115. }
  116. void reshape(int width, int height)
  117. {
  118. ::width = width;
  119. ::height = height;
  120. glViewport(0,0,width,height);
  121. // Send the new window size to AntTweakBar
  122. TwWindowSize(width, height);
  123. s.camera.m_aspect = (double)width/(double)height;
  124. }
  125. void push_scene()
  126. {
  127. using namespace igl;
  128. using namespace std;
  129. glMatrixMode(GL_PROJECTION);
  130. glPushMatrix();
  131. glLoadIdentity();
  132. auto & camera = s.camera;
  133. gluPerspective(camera.m_angle,camera.m_aspect,camera.m_near,camera.m_far);
  134. glMatrixMode(GL_MODELVIEW);
  135. glPushMatrix();
  136. glLoadIdentity();
  137. gluLookAt(
  138. camera.eye()(0), camera.eye()(1), camera.eye()(2),
  139. camera.at()(0), camera.at()(1), camera.at()(2),
  140. camera.up()(0), camera.up()(1), camera.up()(2));
  141. }
  142. void push_object()
  143. {
  144. using namespace igl;
  145. glPushMatrix();
  146. glScaled(2./bbd,2./bbd,2./bbd);
  147. glTranslated(-Vmid(0),-Vmid(1),-Vmid(2));
  148. }
  149. void pop_object()
  150. {
  151. glPopMatrix();
  152. }
  153. void pop_scene()
  154. {
  155. glMatrixMode(GL_PROJECTION);
  156. glPopMatrix();
  157. glMatrixMode(GL_MODELVIEW);
  158. glPopMatrix();
  159. }
  160. // Set up double-sided lights
  161. void lights()
  162. {
  163. using namespace std;
  164. using namespace Eigen;
  165. glEnable(GL_LIGHTING);
  166. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  167. glEnable(GL_LIGHT0);
  168. glEnable(GL_LIGHT1);
  169. float WHITE[4] = {0.8,0.8,0.8,1.};
  170. float GREY[4] = {0.4,0.4,0.4,1.};
  171. float BLACK[4] = {0.,0.,0.,1.};
  172. Vector4f pos = light_pos;
  173. glLightfv(GL_LIGHT0,GL_AMBIENT,GREY);
  174. glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
  175. glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
  176. glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
  177. pos(0) *= -1;
  178. pos(1) *= -1;
  179. pos(2) *= -1;
  180. glLightfv(GL_LIGHT1,GL_AMBIENT,GREY);
  181. glLightfv(GL_LIGHT1,GL_DIFFUSE,WHITE);
  182. glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
  183. glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
  184. }
  185. void display()
  186. {
  187. using namespace igl;
  188. using namespace std;
  189. using namespace Eigen;
  190. const float back[4] = {30.0/255.0,30.0/255.0,50.0/255.0,0};
  191. glClearColor(back[0],back[1],back[2],0);
  192. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  193. if(is_animating)
  194. {
  195. double t = (get_seconds() - animation_start_time)/ANIMATION_DURATION;
  196. if(t > 1)
  197. {
  198. t = 1;
  199. is_animating = false;
  200. }
  201. Quaterniond q = animation_from_quat.slerp(t,animation_to_quat).normalized();
  202. auto & camera = s.camera;
  203. camera.orbit(q.conjugate());
  204. }
  205. glEnable(GL_DEPTH_TEST);
  206. glEnable(GL_NORMALIZE);
  207. lights();
  208. push_scene();
  209. // Draw a nice floor
  210. glEnable(GL_DEPTH_TEST);
  211. glPushMatrix();
  212. const double floor_offset =
  213. -2./bbd*(V.col(1).maxCoeff()-Vmid(1));
  214. glTranslated(0,floor_offset,0);
  215. const float GREY[4] = {0.5,0.5,0.6,1.0};
  216. const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  217. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  218. draw_floor(GREY,DARK_GREY);
  219. glPopMatrix();
  220. push_object();
  221. // Set material properties
  222. glDisable(GL_COLOR_MATERIAL);
  223. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, SILVER_AMBIENT);
  224. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, SILVER_DIFFUSE );
  225. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SILVER_SPECULAR);
  226. glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 128);
  227. vector<Quaterniond> dQ(BE.rows(),Quaterniond::Identity()),vQ;
  228. vector<Vector3d> vT;
  229. Matrix3d A = Matrix3d::Identity();
  230. for(int e = 0;e<BE.rows();e++)
  231. {
  232. dQ[e] = AngleAxisd((sin(get_seconds()+e))*0.06*PI,A.col(e%3));
  233. }
  234. forward_kinematics(C,BE,P,dQ,vQ,vT);
  235. const int dim = C.cols();
  236. MatrixXd T(BE.rows()*(dim+1),dim);
  237. for(int e = 0;e<BE.rows();e++)
  238. {
  239. Affine3d a = Affine3d::Identity();
  240. a.translate(vT[e]);
  241. a.rotate(vQ[e]);
  242. T.block(e*(dim+1),0,dim+1,dim) =
  243. a.matrix().transpose().block(0,0,dim+1,dim);
  244. }
  245. if(wireframe)
  246. {
  247. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  248. }
  249. glLineWidth(1.0);
  250. MatrixXd U = M*T;
  251. per_face_normals(U,F,N);
  252. draw_mesh(U,F,N);
  253. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  254. if(skeleton_on_top)
  255. {
  256. glDisable(GL_DEPTH_TEST);
  257. }
  258. switch(skel_style)
  259. {
  260. default:
  261. case SKEL_STYLE_TYPE_3D:
  262. draw_skeleton_3d(C,BE,T);
  263. break;
  264. case SKEL_STYLE_TYPE_VECTOR_GRAPHICS:
  265. draw_skeleton_vector_graphics(C,BE,T);
  266. break;
  267. }
  268. pop_object();
  269. pop_scene();
  270. report_gl_error();
  271. TwDraw();
  272. glutSwapBuffers();
  273. glutPostRedisplay();
  274. }
  275. void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
  276. {
  277. using namespace std;
  278. using namespace igl;
  279. using namespace Eigen;
  280. GLint viewport[4];
  281. glGetIntegerv(GL_VIEWPORT,viewport);
  282. if(wheel == 0 && TwMouseMotion(mouse_x, viewport[3] - mouse_y))
  283. {
  284. static double mouse_scroll_y = 0;
  285. const double delta_y = 0.125*direction;
  286. mouse_scroll_y += delta_y;
  287. TwMouseWheel(mouse_scroll_y);
  288. return;
  289. }
  290. push_undo();
  291. auto & camera = s.camera;
  292. if(wheel==0)
  293. {
  294. // factor of zoom change
  295. double s = (1.-0.01*direction);
  296. //// FOV zoom: just widen angle. This is hardly ever appropriate.
  297. //camera.m_angle *= s;
  298. //camera.m_angle = min(max(camera.m_angle,1),89);
  299. camera.push_away(s);
  300. }else
  301. {
  302. // Dolly zoom:
  303. camera.dolly_zoom((double)direction*1.0);
  304. }
  305. }
  306. void mouse(int glutButton, int glutState, int mouse_x, int mouse_y)
  307. {
  308. using namespace std;
  309. using namespace Eigen;
  310. using namespace igl;
  311. bool tw_using = TwEventMouseButtonGLUT(glutButton,glutState,mouse_x,mouse_y);
  312. switch(glutButton)
  313. {
  314. case GLUT_RIGHT_BUTTON:
  315. case GLUT_LEFT_BUTTON:
  316. {
  317. switch(glutState)
  318. {
  319. case 1:
  320. // up
  321. glutSetCursor(GLUT_CURSOR_INHERIT);
  322. is_rotating = false;
  323. break;
  324. case 0:
  325. if(!tw_using)
  326. {
  327. push_undo();
  328. glutSetCursor(GLUT_CURSOR_CYCLE);
  329. // collect information for trackball
  330. is_rotating = true;
  331. down_camera = s.camera;
  332. down_x = mouse_x;
  333. down_y = mouse_y;
  334. }
  335. break;
  336. }
  337. break;
  338. }
  339. // Scroll down
  340. case 3:
  341. {
  342. mouse_wheel(0,-1,mouse_x,mouse_y);
  343. break;
  344. }
  345. // Scroll up
  346. case 4:
  347. {
  348. mouse_wheel(0,1,mouse_x,mouse_y);
  349. break;
  350. }
  351. // Scroll left
  352. case 5:
  353. {
  354. mouse_wheel(1,-1,mouse_x,mouse_y);
  355. break;
  356. }
  357. // Scroll right
  358. case 6:
  359. {
  360. mouse_wheel(1,1,mouse_x,mouse_y);
  361. break;
  362. }
  363. }
  364. }
  365. void mouse_drag(int mouse_x, int mouse_y)
  366. {
  367. using namespace igl;
  368. using namespace std;
  369. using namespace Eigen;
  370. if(is_rotating)
  371. {
  372. glutSetCursor(GLUT_CURSOR_CYCLE);
  373. Quaterniond q;
  374. auto & camera = s.camera;
  375. switch(rotation_type)
  376. {
  377. case ROTATION_TYPE_IGL_TRACKBALL:
  378. {
  379. // Rotate according to trackball
  380. igl::trackball<double>(
  381. width,
  382. height,
  383. 2.0,
  384. down_camera.m_rotation_conj.coeffs().data(),
  385. down_x,
  386. down_y,
  387. mouse_x,
  388. mouse_y,
  389. q.coeffs().data());
  390. break;
  391. }
  392. case ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP:
  393. {
  394. // Rotate according to two axis valuator with fixed up vector
  395. two_axis_valuator_fixed_up(
  396. width, height,
  397. 2.0,
  398. down_camera.m_rotation_conj,
  399. down_x, down_y, mouse_x, mouse_y,
  400. q);
  401. break;
  402. }
  403. default:
  404. break;
  405. }
  406. camera.orbit(q.conjugate());
  407. }
  408. }
  409. void init_relative()
  410. {
  411. using namespace Eigen;
  412. using namespace igl;
  413. per_face_normals(V,F,N);
  414. Vmax = V.colwise().maxCoeff();
  415. Vmin = V.colwise().minCoeff();
  416. Vmid = 0.5*(Vmax + Vmin);
  417. bbd = (Vmax-Vmin).norm();
  418. }
  419. void undo()
  420. {
  421. using namespace std;
  422. if(!undo_stack.empty())
  423. {
  424. redo_stack.push(s);
  425. s = undo_stack.top();
  426. undo_stack.pop();
  427. }
  428. }
  429. void redo()
  430. {
  431. using namespace std;
  432. if(!redo_stack.empty())
  433. {
  434. undo_stack.push(s);
  435. s = redo_stack.top();
  436. redo_stack.pop();
  437. }
  438. }
  439. void key(unsigned char key, int mouse_x, int mouse_y)
  440. {
  441. using namespace std;
  442. using namespace igl;
  443. using namespace Eigen;
  444. int mod = glutGetModifiers();
  445. const bool command_down = GLUT_ACTIVE_COMMAND & mod;
  446. const bool shift_down = GLUT_ACTIVE_SHIFT & mod;
  447. switch(key)
  448. {
  449. // ESC
  450. case char(27):
  451. rebar.save(REBAR_NAME);
  452. // ^C
  453. case char(3):
  454. exit(0);
  455. case 'z':
  456. case 'Z':
  457. if(command_down)
  458. {
  459. if(shift_down)
  460. {
  461. redo();
  462. }else
  463. {
  464. undo();
  465. }
  466. break;
  467. }else
  468. {
  469. push_undo();
  470. Quaterniond q;
  471. snap_to_canonical_view_quat(s.camera.m_rotation_conj,1.0,q);
  472. s.camera.orbit(q.conjugate());
  473. }
  474. default:
  475. if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
  476. {
  477. cout<<"Unknown key command: "<<key<<" "<<int(key)<<endl;
  478. }
  479. }
  480. }
  481. bool init_weights(
  482. const Eigen::MatrixXd & V,
  483. const Eigen::MatrixXi & F,
  484. const Eigen::MatrixXd & C,
  485. const Eigen::MatrixXi & BE,
  486. Eigen::MatrixXd & W)
  487. {
  488. using namespace igl;
  489. using namespace Eigen;
  490. // Mesh with samples on skeleton
  491. // New vertices of tet mesh, V prefaces VV
  492. MatrixXd VV;
  493. MatrixXi TT,FF,CE;
  494. VectorXi P;
  495. if(!mesh_with_skeleton(V,F,C,P,BE,CE,10,VV,TT,FF))
  496. {
  497. return false;
  498. }
  499. // List of boundary indices (aka fixed value indices into VV)
  500. VectorXi b;
  501. // List of boundary conditions of each weight function
  502. MatrixXd bc;
  503. if(!boundary_conditions(VV,TT,C,P,BE,CE,b,bc))
  504. {
  505. return false;
  506. }
  507. // compute BBW
  508. // Default bbw data and flags
  509. BBWData bbw_data;
  510. bbw_data.active_set_params.max_iter = 4;
  511. // Weights matrix
  512. if(!bbw(VV,TT,b,bc,bbw_data,W))
  513. {
  514. return false;
  515. }
  516. // Normalize weights to sum to one
  517. normalize_row_sums(W,W);
  518. W.conservativeResize(V.rows(),W.cols());
  519. return true;
  520. }
  521. int main(int argc, char * argv[])
  522. {
  523. using namespace std;
  524. using namespace Eigen;
  525. using namespace igl;
  526. string filename = "../shared/cheburashka.off";
  527. string skel_filename = "../shared/cheburashka.tgf";
  528. if(argc < 3)
  529. {
  530. cerr<<"Usage:"<<endl<<" ./example input.obj"<<endl;
  531. cout<<endl<<"Opening default mesh..."<<endl;
  532. }else
  533. {
  534. // Read and prepare mesh
  535. filename = argv[1];
  536. skel_filename = argv[2];
  537. }
  538. // print key commands
  539. cout<<"[Click] and [drag] Rotate model using trackball."<<endl;
  540. cout<<"[Z,z] Snap rotation to canonical view."<<endl;
  541. cout<<"[⌘ Z] Undo."<<endl;
  542. cout<<"[⇧ ⌘ Z] Redo."<<endl;
  543. cout<<"[^C,ESC] Exit."<<endl;
  544. // dirname, basename, extension and filename
  545. string d,b,ext,f;
  546. pathinfo(filename,d,b,ext,f);
  547. // Convert extension to lower case
  548. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  549. vector<vector<double > > vV,vN,vTC;
  550. vector<vector<int > > vF,vFTC,vFN;
  551. if(ext == "obj")
  552. {
  553. // Convert extension to lower case
  554. if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
  555. {
  556. return 1;
  557. }
  558. }else if(ext == "off")
  559. {
  560. // Convert extension to lower case
  561. if(!igl::readOFF(filename,vV,vF,vN))
  562. {
  563. return 1;
  564. }
  565. }else if(ext == "wrl")
  566. {
  567. // Convert extension to lower case
  568. if(!igl::readWRL(filename,vV,vF))
  569. {
  570. return 1;
  571. }
  572. //}else
  573. //{
  574. // // Convert extension to lower case
  575. // MatrixXi T;
  576. // if(!igl::readMESH(filename,V,T,F))
  577. // {
  578. // return 1;
  579. // }
  580. // //if(F.size() > T.size() || F.size() == 0)
  581. // {
  582. // boundary_faces(T,F);
  583. // }
  584. }
  585. if(vV.size() > 0)
  586. {
  587. if(!list_to_matrix(vV,V))
  588. {
  589. return 1;
  590. }
  591. triangulate(vF,F);
  592. }
  593. readTGF(skel_filename,C,BE);
  594. // Recover parent indices because (C,BE) is crappy format for a tree.
  595. P.resize(BE.rows(),1);
  596. for(int e = 0;e<BE.rows();e++)
  597. {
  598. P(e) = -1;
  599. for(int f = 0;f<BE.rows();f++)
  600. {
  601. if(BE(e,0) == BE(f,1))
  602. {
  603. P(e) = f;
  604. }
  605. }
  606. }
  607. init_weights(V,F,C,BE,W);
  608. lbs_matrix(V,W,M);
  609. init_relative();
  610. // Init glut
  611. glutInit(&argc,argv);
  612. if( !TwInit(TW_OPENGL, NULL) )
  613. {
  614. // A fatal error occured
  615. fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
  616. return 1;
  617. }
  618. // Create a tweak bar
  619. rebar.TwNewBar("TweakBar");
  620. rebar.TwAddVarRW("camera_rotation", TW_TYPE_QUAT4D,
  621. s.camera.m_rotation_conj.coeffs().data(), "open readonly=true");
  622. TwType RotationTypeTW = ReTwDefineEnumFromString("RotationType",
  623. "igl_trackball,two-a...-fixed-up");
  624. rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
  625. set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
  626. rebar.TwAddVarRW("skeleton_on_top", TW_TYPE_BOOLCPP,&skeleton_on_top,"key=O");
  627. rebar.TwAddVarRW("wireframe", TW_TYPE_BOOLCPP,&wireframe,"key=l");
  628. TwType SkelStyleTypeTW = ReTwDefineEnumFromString("SkelStyleType",
  629. "3d,vector-graphics");
  630. rebar.TwAddVarRW("style",SkelStyleTypeTW,&skel_style,"key=s");
  631. rebar.load(REBAR_NAME);
  632. // Init antweakbar
  633. glutInitDisplayString( "rgba depth double samples>=8 ");
  634. glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
  635. glutCreateWindow("upright");
  636. glutDisplayFunc(display);
  637. glutReshapeFunc(reshape);
  638. glutKeyboardFunc(key);
  639. glutMouseFunc(mouse);
  640. glutMotionFunc(mouse_drag);
  641. glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
  642. glutMainLoop();
  643. return 0;
  644. }