瀏覽代碼

draw point in Alec's 2d style

Former-commit-id: d42f6fa23541bd046087636172e85ccc6ac68118
jalec 13 年之前
父節點
當前提交
0d4d643d08
共有 2 個文件被更改,包括 112 次插入0 次删除
  1. 83 0
      include/igl/draw_point.cpp
  2. 29 0
      include/igl/draw_point.h

+ 83 - 0
include/igl/draw_point.cpp

@@ -0,0 +1,83 @@
+#include "draw_point.h"
+
+// Implementation
+#if __APPLE__
+#  include <OpenGL/gl.h>
+#else
+#  ifdef _WIN32
+#    define NOMINMAX
+#    include <Windows.h>
+#    undef NOMINMAX
+#  endif
+#  include <GL/gl.h>
+#endif
+
+#include <cassert>
+#include <cmath>
+
+IGL_INLINE void igl::draw_point(
+  const double x,
+  const double y,
+  const double z,
+  const double requested_r,
+  const bool selected)
+{
+  // Push GL settings
+  //GLboolean old_depth_test;
+  //glGetBooleanv(GL_DEPTH_TEST,&old_depth_test);
+  GLboolean old_lighting;
+  glGetBooleanv(GL_LIGHTING,&old_lighting);
+
+  float f;
+  glGetFloatv(GL_POINT_SIZE_MAX,&f);
+  assert(requested_r<=0.5*f);
+  double r = (requested_r<0.5*f?requested_r:0.5*f);
+
+  //glDisable(GL_DEPTH_TEST);
+  glDisable(GL_LIGHTING);
+
+  // get current color
+  float color[4];
+  glGetFloatv(GL_CURRENT_COLOR,color);
+
+  double outline_size = (r>7 ? sqrt(r/7.0) : 1.0);
+
+  // White outline
+  glColor4f(1,1,1,color[3]);
+  glPointSize(2*r);
+  glBegin(GL_POINTS);
+  glVertex3d(x,y,z);
+  glEnd();
+  // Black outline
+  glColor4f(0,0,0,color[3]);
+  glPointSize(2*r-2*outline_size);
+  glBegin(GL_POINTS);
+  glVertex3d(x,y,z);
+  glEnd();
+  
+  // Foreground
+  glColor4fv(color);
+  glPointSize(2*r-4*outline_size);
+  glBegin(GL_POINTS);
+  glVertex3d(x,y,z);
+  glEnd();
+  // Selection inner circle
+  if(selected)
+  {
+    glColor4f(0,0,0,color[3]);
+    double selected_size = 2*r-7*outline_size;
+    selected_size = (selected_size>3?selected_size:3);
+    glPointSize(selected_size);
+    glBegin(GL_POINTS);
+    glVertex3d(x,y,z);
+    glEnd();
+  }
+
+  // reset color
+  glColor4fv(color);
+
+  // Pop GL settings
+  if(old_lighting) glEnable(GL_LIGHTING);
+  //if(old_depth_test) glEnable(GL_DEPTH_TEST);
+}
+

+ 29 - 0
include/igl/draw_point.h

@@ -0,0 +1,29 @@
+#ifndef IGL_DRAW_POINT_H
+#define IGL_DRAW_POINT_H
+#include "igl_inline.h"
+namespace igl
+{
+  // Draw a nice looking, colored dot at a given point in 3d.
+  //
+  // Note: expects that GL_CURRENT_COLOR is set with the desired foreground color
+  // 
+  // Inputs:
+  //   x  x-coordinate of point, modelview coordinates
+  //   y  y-coordinate of point, modelview coordinates
+  //   z  z-coordinate of point, modelview coordinates
+  //   requested_r  outer-most radius of dot {7}, measured in screen space pixels
+  //   selected  fills inner circle with black {false}
+  // Asserts that requested_r does not exceed 0.5*GL_POINT_SIZE_MAX
+  IGL_INLINE void draw_point(
+    const double x,
+    const double y,
+    const double z,
+    const double requested_r = 7,
+    const bool selected = false);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "draw_point.cpp"
+#endif
+
+#endif