Browse Source

Add a function to set labels collectively, and clear function for points/lines. (#1196)

* fix issue for octree.

For translating centre, the distance should be the half of width of the sub cell instead of the width h.

* add collective label set method and point/edge clear function.
X.ZhaoMa 6 years ago
parent
commit
cdd8971d1d

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

@@ -26,6 +26,7 @@ IGL_INLINE igl::opengl::ViewerData::ViewerData()
   show_overlay_depth(true),
   show_vertid(false),
   show_faceid(false),
+  show_labels(false),
   show_texture(false),
   point_size(30),
   line_width(0.5f),
@@ -288,6 +289,11 @@ IGL_INLINE void igl::opengl::ViewerData::add_points(const Eigen::MatrixXd& P,  c
   dirty |= MeshGL::DIRTY_OVERLAY_POINTS;
 }
 
+IGL_INLINE void igl::opengl::ViewerData::clear_points()
+{
+  points.resize(0, 6);
+}
+
 IGL_INLINE void igl::opengl::ViewerData::set_edges(
   const Eigen::MatrixXd& P,
   const Eigen::MatrixXi& E,
@@ -337,6 +343,11 @@ IGL_INLINE void igl::opengl::ViewerData::add_edges(const Eigen::MatrixXd& P1, co
   dirty |= MeshGL::DIRTY_OVERLAY_LINES;
 }
 
+IGL_INLINE void igl::opengl::ViewerData::clear_edges()
+{
+  lines.resize(0, 9);
+}
+
 IGL_INLINE void igl::opengl::ViewerData::add_label(const Eigen::VectorXd& P,  const std::string& str)
 {
   Eigen::RowVectorXd P_temp;
@@ -356,6 +367,14 @@ IGL_INLINE void igl::opengl::ViewerData::add_label(const Eigen::VectorXd& P,  co
   labels_strings.push_back(str);
 }
 
+IGL_INLINE void igl::opengl::ViewerData::set_labels(const Eigen::MatrixXd& P, const std::vector<std::string>& str)
+{
+  assert(P.rows() == str.size() && "position # and label # do not match!");
+  assert(P.cols() == 3 && "dimension of label positions incorrect!");
+  labels_positions = P;
+  labels_strings = str;
+}
+
 IGL_INLINE void igl::opengl::ViewerData::clear_labels()
 {
   labels_positions.resize(0,3);

+ 13 - 1
include/igl/opengl/ViewerData.h

@@ -107,6 +107,10 @@ public:
     const Eigen::MatrixXd& P,
     const Eigen::MatrixXd& C);
   IGL_INLINE void add_points(const Eigen::MatrixXd& P,  const Eigen::MatrixXd& C);
+
+  // Clear the point data
+  IGL_INLINE void clear_points();
+
   // Sets edges given a list of edge vertices and edge indices. In constrast
   // to `add_edges` this will (purposefully) clober existing edges.
   //
@@ -114,14 +118,20 @@ public:
   //   P  #P by 3 list of vertex positions
   //   E  #E by 2 list of edge indices into P
   //   C  #E|1 by 3 color(s)
+
   IGL_INLINE void set_edges (const Eigen::MatrixXd& P, const Eigen::MatrixXi& E, const Eigen::MatrixXd& C);
   // Alec: This is very confusing. Why does add_edges have a different API from
   // set_edges?
   IGL_INLINE void add_edges (const Eigen::MatrixXd& P1, const Eigen::MatrixXd& P2, const Eigen::MatrixXd& C);
 
-  // Adds text labels at the given positions in 3D.
+  // Clear the edge data
+  IGL_INLINE void clear_edges();
+
+  // Sets / 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);
+  IGL_INLINE void set_labels (const Eigen::MatrixXd& P,  const std::vector<std::string>& str);
+
   // Clear the label data
   IGL_INLINE void clear_labels ();
 
@@ -211,6 +221,7 @@ public:
   unsigned int show_lines;
   bool show_vertid; // shared across viewports for now
   bool show_faceid; // shared across viewports for now
+  bool show_labels; // shared across viewports for now
 
   // Point size / line width
   float point_size;
@@ -275,6 +286,7 @@ namespace igl
       SERIALIZE_MEMBER(show_overlay_depth);
       SERIALIZE_MEMBER(show_vertid);
       SERIALIZE_MEMBER(show_faceid);
+      SERIALIZE_MEMBER(show_labels);
       SERIALIZE_MEMBER(show_texture);
       SERIALIZE_MEMBER(point_size);
       SERIALIZE_MEMBER(line_width);

+ 2 - 1
include/igl/opengl/glfw/imgui/ImGuiMenu.cpp

@@ -303,6 +303,7 @@ IGL_INLINE void ImGuiMenu::draw_viewer_menu()
     make_checkbox("Fill", viewer->data().show_faces);
     ImGui::Checkbox("Show vertex labels", &(viewer->data().show_vertid));
     ImGui::Checkbox("Show faces labels", &(viewer->data().show_faceid));
+    ImGui::Checkbox("Show extra labels", &(viewer->data().show_labels));
   }
 }
 
@@ -365,7 +366,7 @@ IGL_INLINE void ImGuiMenu::draw_labels(const igl::opengl::ViewerData &data)
     }
   }
 
-  if (data.labels_positions.rows() > 0)
+  if (data.show_labels)
   {
     for (int i = 0; i < data.labels_positions.rows(); ++i)
     {