example.cpp 17 KB

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