draw_skeleton_vector_graphics.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "draw_skeleton_vector_graphics.h"
  9. #include "OpenGL_convenience.h"
  10. #include "draw_point.h"
  11. #include "material_colors.h"
  12. #ifndef IGL_NO_OPENGL
  13. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  14. const Eigen::MatrixXd & C,
  15. const Eigen::MatrixXi & BE)
  16. {
  17. return draw_skeleton_vector_graphics(C,BE,BBW_POINT_COLOR,BBW_LINE_COLOR);
  18. }
  19. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  20. const Eigen::MatrixXd & C,
  21. const Eigen::MatrixXi & BE,
  22. const float * point_color,
  23. const float * line_color)
  24. {
  25. using namespace Eigen;
  26. int old_lighting=0;
  27. double old_line_width=1;
  28. glGetIntegerv(GL_LIGHTING,&old_lighting);
  29. glGetDoublev(GL_LINE_WIDTH,&old_line_width);
  30. int cm;
  31. glGetIntegerv(GL_COLOR_MATERIAL,&cm);
  32. glDisable(GL_LIGHTING);
  33. glDisable(GL_LINE_STIPPLE);
  34. //glEnable(GL_POLYGON_OFFSET_FILL);
  35. glEnable(GL_COLOR_MATERIAL);
  36. glLineWidth(10.0);
  37. glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
  38. float mat_ambient[4] = {0.1,0.1,0.1,1.0};
  39. float mat_specular[4] = {0.0,0.0,0.0,1.0};
  40. float mat_shininess = 1;
  41. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  42. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  43. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
  44. glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
  45. for(int i = 0;i<3;i++)
  46. {
  47. switch(i)
  48. {
  49. case 0: glColor3fv(WHITE); glLineWidth(10); break;
  50. case 1: glColor3fv(BLACK); glLineWidth( 6); break;
  51. case 2: glColor3fv(line_color); glLineWidth( 4); break;
  52. }
  53. // Loop over bone edges
  54. glBegin(GL_LINES);
  55. for(int e = 0;e<BE.rows();e++)
  56. {
  57. RowVector3d tip = C.row(BE(e,0));
  58. RowVector3d tail = C.row(BE(e,1));
  59. glVertex3dv(tip.data());
  60. glVertex3dv(tail.data());
  61. }
  62. glEnd();
  63. }
  64. glColor3fv(point_color);
  65. for(int i = 0;i<C.rows();i++)
  66. {
  67. RowVector3d p = C.row(i);
  68. draw_point(p(0),p(1),p(2));
  69. }
  70. (cm ? glEnable(GL_COLOR_MATERIAL):glDisable(GL_COLOR_MATERIAL));
  71. //glDisable(GL_POLYGON_OFFSET_FILL);
  72. glEnable(GL_LIGHTING);
  73. (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
  74. glLineWidth(old_line_width);
  75. }
  76. template <typename DerivedC, typename DerivedBE, typename DerivedT>
  77. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  78. const Eigen::PlainObjectBase<DerivedC> & C,
  79. const Eigen::PlainObjectBase<DerivedBE> & BE,
  80. const Eigen::PlainObjectBase<DerivedT> & T)
  81. {
  82. return draw_skeleton_vector_graphics(C,BE,T,BBW_POINT_COLOR,BBW_LINE_COLOR);
  83. }
  84. template <typename DerivedC, typename DerivedBE, typename DerivedT>
  85. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  86. const Eigen::PlainObjectBase<DerivedC> & C,
  87. const Eigen::PlainObjectBase<DerivedBE> & BE,
  88. const Eigen::PlainObjectBase<DerivedT> & T,
  89. const float * point_color,
  90. const float * line_color)
  91. {
  92. Eigen::PlainObjectBase<DerivedC> CT;
  93. Eigen::PlainObjectBase<DerivedBE> BET;
  94. const int dim = T.cols();
  95. assert(dim == C.cols());
  96. CT.resize(2*BE.rows(),C.cols());
  97. BET.resize(BE.rows(),2);
  98. for(int e = 0;e<BE.rows();e++)
  99. {
  100. BET(e,0) = 2*e;
  101. BET(e,1) = 2*e+1;
  102. const auto & c0 = C.row(BE(e,0));
  103. const auto & c1 = C.row(BE(e,1));
  104. const auto & L = T.block(e*(dim+1),0,dim,dim);
  105. const auto & t = T.block(e*(dim+1)+dim,0,1,dim);
  106. CT.row(2*e) = c0 * L + t;
  107. CT.row(2*e+1) = c1 * L + t;
  108. }
  109. draw_skeleton_vector_graphics(CT,BET,point_color,line_color);
  110. }
  111. #endif
  112. #ifdef IGL_STATIC_LIBRARY
  113. // Explicit template instanciation
  114. #ifndef IGL_NO_OPENGL
  115. template void igl::draw_skeleton_vector_graphics<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
  116. #endif
  117. #endif