draw_point.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "draw_point.h"
  2. #ifndef IGL_NO_OPENGL
  3. // Implementation
  4. #include "OpenGL_convenience.h"
  5. #include <cassert>
  6. #include <cmath>
  7. IGL_INLINE void igl::draw_point(
  8. const double x,
  9. const double y,
  10. const double z,
  11. const double requested_r,
  12. const bool selected)
  13. {
  14. // Push GL settings
  15. //GLboolean old_depth_test;
  16. //glGetBooleanv(GL_DEPTH_TEST,&old_depth_test);
  17. GLboolean old_lighting;
  18. glGetBooleanv(GL_LIGHTING,&old_lighting);
  19. glEnable( GL_POINT_SMOOTH );
  20. float f;
  21. glGetFloatv(GL_POINT_SIZE_MAX,&f);
  22. assert(requested_r<=0.5*f);
  23. double r = (requested_r<0.5*f?requested_r:0.5*f);
  24. //glDisable(GL_DEPTH_TEST);
  25. glDisable(GL_LIGHTING);
  26. // get current color
  27. float color[4];
  28. glGetFloatv(GL_CURRENT_COLOR,color);
  29. double outline_size = (r>7 ? sqrt(r/7.0) : 1.0);
  30. // White outline
  31. glColor4f(1,1,1,color[3]);
  32. glPointSize(2*r);
  33. glBegin(GL_POINTS);
  34. glVertex3d(x,y,z);
  35. glEnd();
  36. // Black outline
  37. glColor4f(0,0,0,color[3]);
  38. glPointSize(2*r-2*outline_size);
  39. glBegin(GL_POINTS);
  40. glVertex3d(x,y,z);
  41. glEnd();
  42. // Foreground
  43. glColor4fv(color);
  44. glPointSize(2*r-4*outline_size);
  45. glBegin(GL_POINTS);
  46. glVertex3d(x,y,z);
  47. glEnd();
  48. // Selection inner circle
  49. if(selected)
  50. {
  51. glColor4f(0,0,0,color[3]);
  52. double selected_size = 2*r-7*outline_size;
  53. selected_size = (selected_size>3?selected_size:3);
  54. glPointSize(selected_size);
  55. glBegin(GL_POINTS);
  56. glVertex3d(x,y,z);
  57. glEnd();
  58. }
  59. // reset color
  60. glColor4fv(color);
  61. // Pop GL settings
  62. if(old_lighting) glEnable(GL_LIGHTING);
  63. //if(old_depth_test) glEnable(GL_DEPTH_TEST);
  64. }
  65. template <typename DerivedP>
  66. IGL_INLINE void igl::draw_point(
  67. const Eigen::PlainObjectBase<DerivedP> & P,
  68. const double requested_r,
  69. const bool selected)
  70. {
  71. return draw_point(P(0),P(1),P(2),requested_r,selected);
  72. }
  73. #ifndef IGL_HEADER_ONLY
  74. template void igl::draw_point<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, double, bool);
  75. #endif
  76. #endif