draw_point.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // THIS IS OVERZEALOUS on Mac OS X: OpenGL reports a smaller point size than
  30. // possible.
  31. //assert(requested_r<=0.5*f);
  32. double r = (requested_r<0.5*f?requested_r:0.5*f);
  33. //glDisable(GL_DEPTH_TEST);
  34. glDisable(GL_LIGHTING);
  35. // get current color
  36. float color[4];
  37. glGetFloatv(GL_CURRENT_COLOR,color);
  38. double outline_size = (r>7 ? sqrt(r/7.0) : 1.0);
  39. // White outline
  40. glColor4f(1,1,1,color[3]);
  41. glPointSize(2*r);
  42. glBegin(GL_POINTS);
  43. glVertex3d(x,y,z);
  44. glEnd();
  45. // Black outline
  46. glColor4f(0,0,0,color[3]);
  47. glPointSize(2*r-2*outline_size);
  48. glBegin(GL_POINTS);
  49. glVertex3d(x,y,z);
  50. glEnd();
  51. // Foreground
  52. glColor4fv(color);
  53. glPointSize(2*r-4*outline_size);
  54. glBegin(GL_POINTS);
  55. glVertex3d(x,y,z);
  56. glEnd();
  57. // Selection inner circle
  58. if(selected)
  59. {
  60. glColor4f(0,0,0,color[3]);
  61. double selected_size = 2*r-7*outline_size;
  62. selected_size = (selected_size>3?selected_size:3);
  63. glPointSize(selected_size);
  64. glBegin(GL_POINTS);
  65. glVertex3d(x,y,z);
  66. glEnd();
  67. }
  68. // reset color
  69. glColor4fv(color);
  70. // Pop GL settings
  71. if(old_lighting) glEnable(GL_LIGHTING);
  72. //if(old_depth_test) glEnable(GL_DEPTH_TEST);
  73. }
  74. template <typename DerivedP>
  75. IGL_INLINE void igl::draw_point(
  76. const Eigen::PlainObjectBase<DerivedP> & P,
  77. const double requested_r,
  78. const bool selected)
  79. {
  80. switch(P.size())
  81. {
  82. case 2:
  83. return draw_point(P(0),P(1),0,requested_r,selected);
  84. default:
  85. return draw_point(P(0),P(1),P(2),requested_r,selected);
  86. }
  87. }
  88. #ifdef IGL_STATIC_LIBRARY
  89. 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);
  90. 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);
  91. #endif
  92. #endif