draw_point.cpp 2.6 KB

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