draw_skeleton_vector_graphics.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  13. const Eigen::MatrixXd & C,
  14. const Eigen::MatrixXi & BE)
  15. {
  16. return draw_skeleton_vector_graphics(C,BE,BBW_POINT_COLOR,BBW_LINE_COLOR);
  17. }
  18. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  19. const Eigen::MatrixXd & C,
  20. const Eigen::MatrixXi & BE,
  21. const float * point_color,
  22. const float * line_color)
  23. {
  24. using namespace Eigen;
  25. int old_lighting=0;
  26. double old_line_width=1;
  27. glGetIntegerv(GL_LIGHTING,&old_lighting);
  28. glGetDoublev(GL_LINE_WIDTH,&old_line_width);
  29. int cm;
  30. glGetIntegerv(GL_COLOR_MATERIAL,&cm);
  31. glDisable(GL_LIGHTING);
  32. glDisable(GL_LINE_STIPPLE);
  33. //glEnable(GL_POLYGON_OFFSET_FILL);
  34. glEnable(GL_COLOR_MATERIAL);
  35. glLineWidth(10.0);
  36. glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
  37. float mat_ambient[4] = {0.1,0.1,0.1,1.0};
  38. float mat_specular[4] = {0.0,0.0,0.0,1.0};
  39. float mat_shininess = 1;
  40. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  41. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  42. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
  43. glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
  44. for(int i = 0;i<3;i++)
  45. {
  46. switch(i)
  47. {
  48. case 0: glColor3fv(WHITE); glLineWidth(10); break;
  49. case 1: glColor3fv(BLACK); glLineWidth( 6); break;
  50. case 2: glColor3fv(line_color); glLineWidth( 4); break;
  51. }
  52. // Loop over bone edges
  53. glBegin(GL_LINES);
  54. for(int e = 0;e<BE.rows();e++)
  55. {
  56. RowVector3d tip = C.row(BE(e,0));
  57. RowVector3d tail = C.row(BE(e,1));
  58. glVertex3dv(tip.data());
  59. glVertex3dv(tail.data());
  60. }
  61. glEnd();
  62. }
  63. glColor3fv(point_color);
  64. for(int i = 0;i<C.rows();i++)
  65. {
  66. RowVector3d p = C.row(i);
  67. draw_point(p(0),p(1),p(2));
  68. }
  69. (cm ? glEnable(GL_COLOR_MATERIAL):glDisable(GL_COLOR_MATERIAL));
  70. //glDisable(GL_POLYGON_OFFSET_FILL);
  71. glEnable(GL_LIGHTING);
  72. (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
  73. glLineWidth(old_line_width);
  74. }
  75. template <typename DerivedC, typename DerivedBE, typename DerivedT>
  76. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  77. const Eigen::PlainObjectBase<DerivedC> & C,
  78. const Eigen::PlainObjectBase<DerivedBE> & BE,
  79. const Eigen::PlainObjectBase<DerivedT> & T)
  80. {
  81. return draw_skeleton_vector_graphics(C,BE,T,BBW_POINT_COLOR,BBW_LINE_COLOR);
  82. }
  83. template <typename DerivedC, typename DerivedBE, typename DerivedT>
  84. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  85. const Eigen::PlainObjectBase<DerivedC> & C,
  86. const Eigen::PlainObjectBase<DerivedBE> & BE,
  87. const Eigen::PlainObjectBase<DerivedT> & T,
  88. const float * point_color,
  89. const float * line_color)
  90. {
  91. Eigen::PlainObjectBase<DerivedC> CT;
  92. Eigen::PlainObjectBase<DerivedBE> BET;
  93. const int dim = T.cols();
  94. assert(dim == C.cols());
  95. CT.resize(2*BE.rows(),C.cols());
  96. BET.resize(BE.rows(),2);
  97. for(int e = 0;e<BE.rows();e++)
  98. {
  99. BET(e,0) = 2*e;
  100. BET(e,1) = 2*e+1;
  101. const auto & c0 = C.row(BE(e,0));
  102. const auto & c1 = C.row(BE(e,1));
  103. const auto & L = T.block(e*(dim+1),0,dim,dim);
  104. const auto & t = T.block(e*(dim+1)+dim,0,1,dim);
  105. CT.row(2*e) = c0 * L + t;
  106. CT.row(2*e+1) = c1 * L + t;
  107. }
  108. draw_skeleton_vector_graphics(CT,BET,point_color,line_color);
  109. }
  110. #ifdef IGL_STATIC_LIBRARY
  111. // Explicit template instanciation
  112. 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&);
  113. #endif