example.cpp 16 KB

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