Преглед изворни кода

Merge pull request #1132 from libigl/viewer-label-colors

expose label color
Alec Jacobson пре 6 година
родитељ
комит
9230cc8b83

+ 7 - 0
include/igl/opengl/ViewerData.cpp

@@ -30,6 +30,7 @@ IGL_INLINE igl::opengl::ViewerData::ViewerData()
   point_size(30),
   line_width(0.5f),
   line_color(0,0,0,1),
+  label_color(0,0,0.04,1),
   shininess(35.0f),
   id(-1),
   is_visible(1)
@@ -355,6 +356,12 @@ IGL_INLINE void igl::opengl::ViewerData::add_label(const Eigen::VectorXd& P,  co
   labels_strings.push_back(str);
 }
 
+IGL_INLINE void igl::opengl::ViewerData::clear_labels()
+{
+  labels_positions.resize(0,3);
+  labels_strings.clear();
+}
+
 IGL_INLINE void igl::opengl::ViewerData::clear()
 {
   V                       = Eigen::MatrixXd (0,3);

+ 3 - 0
include/igl/opengl/ViewerData.h

@@ -122,6 +122,8 @@ public:
   // Adds text labels at the given positions in 3D.
   // Note: This requires the ImGui viewer plugin to display text labels.
   IGL_INLINE void add_label (const Eigen::VectorXd& P,  const std::string& str);
+  // Clear the label data
+  IGL_INLINE void clear_labels ();
 
   // Computes the normals of the mesh
   IGL_INLINE void compute_normals();
@@ -214,6 +216,7 @@ public:
   float point_size;
   float line_width;
   Eigen::Matrix<float, 4, 1, Eigen::DontAlign> line_color;
+  Eigen::Matrix<float, 4, 1, Eigen::DontAlign> label_color;
 
   // Shape material
   float shininess;

+ 28 - 7
include/igl/opengl/glfw/imgui/ImGuiMenu.cpp

@@ -114,7 +114,9 @@ IGL_INLINE bool ImGuiMenu::mouse_down(int button, int modifier)
 
 IGL_INLINE bool ImGuiMenu::mouse_up(int button, int modifier)
 {
-  return ImGui::GetIO().WantCaptureMouse;
+  //return ImGui::GetIO().WantCaptureMouse;
+  // !! Should not steal mouse up
+  return false;
 }
 
 IGL_INLINE bool ImGuiMenu::mouse_move(int mouse_x, int mouse_y)
@@ -336,7 +338,11 @@ IGL_INLINE void ImGuiMenu::draw_labels(const igl::opengl::ViewerData &data)
   {
     for (int i = 0; i < data.V.rows(); ++i)
     {
-      draw_text(data.V.row(i), data.V_normals.row(i), std::to_string(i));
+      draw_text(
+        data.V.row(i), 
+        data.V_normals.row(i), 
+        std::to_string(i),
+        data.label_color);
     }
   }
 
@@ -351,7 +357,11 @@ IGL_INLINE void ImGuiMenu::draw_labels(const igl::opengl::ViewerData &data)
       }
       p /= (double) data.F.cols();
 
-      draw_text(p, data.F_normals.row(i), std::to_string(i));
+      draw_text(
+        p, 
+        data.F_normals.row(i), 
+        std::to_string(i),
+        data.label_color);
     }
   }
 
@@ -359,13 +369,20 @@ IGL_INLINE void ImGuiMenu::draw_labels(const igl::opengl::ViewerData &data)
   {
     for (int i = 0; i < data.labels_positions.rows(); ++i)
     {
-      draw_text(data.labels_positions.row(i), Eigen::Vector3d(0.0,0.0,0.0),
-        data.labels_strings[i]);
+      draw_text(
+        data.labels_positions.row(i), 
+        Eigen::Vector3d(0.0,0.0,0.0),
+        data.labels_strings[i],
+        data.label_color);
     }
   }
 }
 
-IGL_INLINE void ImGuiMenu::draw_text(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text)
+IGL_INLINE void ImGuiMenu::draw_text(
+  Eigen::Vector3d pos, 
+  Eigen::Vector3d normal, 
+  const std::string &text,
+  const Eigen::Vector4f color)
 {
   pos += normal * 0.005f * viewer->core().object_scale;
   Eigen::Vector3f coord = igl::project(Eigen::Vector3f(pos.cast<float>()),
@@ -375,7 +392,11 @@ IGL_INLINE void ImGuiMenu::draw_text(Eigen::Vector3d pos, Eigen::Vector3d normal
   ImDrawList* drawList = ImGui::GetWindowDrawList();
   drawList->AddText(ImGui::GetFont(), ImGui::GetFontSize() * 1.2,
       ImVec2(coord[0]/pixel_ratio_, (viewer->core().viewport[3] - coord[1])/pixel_ratio_),
-      ImGui::GetColorU32(ImVec4(0, 0, 10, 255)),
+      ImGui::GetColorU32(ImVec4(
+        color(0),
+        color(1),
+        color(2),
+        color(3))),
       &text[0], &text[0] + text.size());
 }
 

+ 5 - 1
include/igl/opengl/glfw/imgui/ImGuiMenu.h

@@ -90,7 +90,11 @@ public:
 
   IGL_INLINE void draw_labels(const igl::opengl::ViewerData &data);
 
-  IGL_INLINE void draw_text(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text);
+  IGL_INLINE void draw_text(
+    Eigen::Vector3d pos, 
+    Eigen::Vector3d normal, 
+    const std::string &text,
+    const Eigen::Vector4f color = Eigen::Vector4f(0,0,0.04,1)); // old default color
 
   IGL_INLINE float pixel_ratio();