draw_point.cpp 2.5 KB

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