draw_point.cpp 2.5 KB

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