draw_skeleton_vector_graphics.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. glLineWidth(10.0);
  26. int cm;
  27. glGetIntegerv(GL_COLOR_MATERIAL,&cm);
  28. glDisable(GL_LIGHTING);
  29. glDisable(GL_LINE_STIPPLE);
  30. //glEnable(GL_POLYGON_OFFSET_FILL);
  31. glEnable(GL_COLOR_MATERIAL);
  32. glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
  33. float mat_ambient[4] = {0.1,0.1,0.1,1.0};
  34. float mat_specular[4] = {0.0,0.0,0.0,1.0};
  35. float mat_shininess = 1;
  36. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  37. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
  38. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
  39. glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
  40. for(int i = 0;i<3;i++)
  41. {
  42. switch(i)
  43. {
  44. case 0: glColor3fv(WHITE); glLineWidth(10); break;
  45. case 1: glColor3fv(BLACK); glLineWidth( 6); break;
  46. case 2: glColor3fv(line_color); glLineWidth( 4); break;
  47. }
  48. // Loop over bone edges
  49. glBegin(GL_LINES);
  50. for(int e = 0;e<BE.rows();e++)
  51. {
  52. RowVector3d tip = C.row(BE(e,0));
  53. RowVector3d tail = C.row(BE(e,1));
  54. glVertex3dv(tip.data());
  55. glVertex3dv(tail.data());
  56. }
  57. glEnd();
  58. }
  59. glColor3fv(point_color);
  60. for(int i = 0;i<C.rows();i++)
  61. {
  62. RowVector3d p = C.row(i);
  63. draw_point(p(0),p(1),p(2));
  64. }
  65. (cm ? glEnable(GL_COLOR_MATERIAL):glDisable(GL_COLOR_MATERIAL));
  66. //glDisable(GL_POLYGON_OFFSET_FILL);
  67. glEnable(GL_LIGHTING);
  68. }
  69. template <typename DerivedC, typename DerivedBE, typename DerivedT>
  70. IGL_INLINE void igl::draw_skeleton_vector_graphics(
  71. const Eigen::PlainObjectBase<DerivedC> & C,
  72. const Eigen::PlainObjectBase<DerivedBE> & BE,
  73. const Eigen::PlainObjectBase<DerivedT> & T)
  74. {
  75. Eigen::PlainObjectBase<DerivedC> CT;
  76. Eigen::PlainObjectBase<DerivedBE> BET;
  77. const int dim = T.cols();
  78. assert(dim == C.cols());
  79. CT.resize(2*BE.rows(),C.cols());
  80. BET.resize(BE.rows(),2);
  81. for(int e = 0;e<BE.rows();e++)
  82. {
  83. BET(e,0) = 2*e;
  84. BET(e,1) = 2*e+1;
  85. const auto & c0 = C.row(BE(e,0));
  86. const auto & c1 = C.row(BE(e,1));
  87. const auto & L = T.block(e*(dim+1),0,dim,dim);
  88. const auto & t = T.block(e*(dim+1)+dim,0,1,dim);
  89. CT.row(2*e) = c0 * L + t;
  90. CT.row(2*e+1) = c1 * L + t;
  91. }
  92. draw_skeleton_vector_graphics(CT,BET);
  93. }
  94. #ifndef IGL_HEADER_ONLY
  95. // Explicit template instanciation
  96. 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&);
  97. #endif