Open3D (C++ API)  0.17.0
VisualizerWithVertexSelection.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <unordered_map>
11 
13 
14 namespace open3d {
15 
16 namespace geometry {
17 class PointCloud;
18 }
19 
20 namespace visualization {
21 class SelectionPolygon;
22 class PointCloudPicker;
23 
25 public:
26  enum class SelectionMode { None = 0, Point = 1, Rectangle = 2, Moving = 3 };
27 
28 public:
32  delete;
34  const VisualizerWithVertexSelection &) = delete;
35 
36 public:
37  bool AddGeometry(std::shared_ptr<const geometry::Geometry> geometry_ptr,
38  bool reset_bounding_box = true) override;
39  bool UpdateGeometry(std::shared_ptr<const geometry::Geometry> geometry_ptr =
40  nullptr) override;
41  void PrintVisualizerHelp() override;
42  void UpdateWindowTitle() override;
43  void BuildUtilities() override;
44  void SetPointSize(double size);
45  std::vector<int> PickPoints(double x, double y, double w, double h);
46 
47  struct PickedPoint {
48  int index;
49  Eigen::Vector3d coord;
50  };
51  std::vector<PickedPoint> GetPickedPoints() const;
52  void ClearPickedPoints();
53  void AddPickedPoints(const std::vector<int> indices);
54  void RemovePickedPoints(const std::vector<int> indices);
55 
56  void RegisterSelectionChangedCallback(std::function<void()> f);
59  void RegisterSelectionMovingCallback(std::function<void()> f);
60  void RegisterSelectionMovedCallback(std::function<void()> f);
61 
62 protected:
63  bool InitViewControl() override;
64  bool InitRenderOption() override;
65  void WindowResizeCallback(GLFWwindow *window, int w, int h) override;
66  void MouseMoveCallback(GLFWwindow *window, double x, double y) override;
67  void MouseScrollCallback(GLFWwindow *window, double x, double y) override;
68  void MouseButtonCallback(GLFWwindow *window,
69  int button,
70  int action,
71  int mods) override;
72  void KeyPressCallback(GLFWwindow *window,
73  int key,
74  int scancode,
75  int action,
76  int mods) override;
78  void InvalidatePicking();
79  float GetDepth(int winX, int winY);
80  Eigen::Vector3d CalcDragDelta(double winX, double winY);
82  void DragSelectedPoints(const Eigen::Vector3d &delta, DragType type);
83  const std::vector<Eigen::Vector3d> *GetGeometryPoints(
84  std::shared_ptr<const geometry::Geometry> geometry);
85 
86 protected:
87  std::shared_ptr<SelectionPolygon> selection_polygon_ptr_;
88  std::shared_ptr<glsl::SelectionPolygonRenderer>
91  Eigen::Vector2d mouse_down_pos_;
92  std::vector<int> points_in_rect_;
93  float drag_depth_ = 0.0f;
94 
95  std::shared_ptr<PointCloudPicker> pointcloud_picker_ptr_;
96  std::shared_ptr<glsl::PointCloudPickerRenderer>
98 
99  std::shared_ptr<const geometry::Geometry> geometry_ptr_;
100  std::shared_ptr<glsl::GeometryRenderer> geometry_renderer_ptr_;
101 
103 
104  std::shared_ptr<geometry::PointCloud> ui_points_geometry_ptr_;
105  std::shared_ptr<glsl::GeometryRenderer> ui_points_renderer_ptr_;
106 
107  std::unordered_map<int, Eigen::Vector3d> selected_points_;
108  std::unordered_map<int, Eigen::Vector3d> selected_points_before_drag_;
109  std::shared_ptr<geometry::PointCloud> ui_selected_points_geometry_ptr_;
110  std::shared_ptr<glsl::GeometryRenderer> ui_selected_points_renderer_ptr_;
111 
112  std::function<void()> on_selection_changed_;
113  std::function<void()> on_selection_moving_;
114  std::function<void()> on_selection_moved_;
115 };
116 
117 } // namespace visualization
118 } // namespace open3d
Defines rendering options for visualizer.
Definition: RenderOption.h:20
The main Visualizer class.
Definition: Visualizer.h:43
Definition: VisualizerWithVertexSelection.h:24
bool InitRenderOption() override
Function to initialize RenderOption.
Definition: VisualizerWithVertexSelection.cpp:422
void BuildUtilities() override
Definition: VisualizerWithVertexSelection.cpp:257
void DragSelectedPoints(const Eigen::Vector3d &delta, DragType type)
Definition: VisualizerWithVertexSelection.cpp:738
std::function< void()> on_selection_moving_
Definition: VisualizerWithVertexSelection.h:113
std::shared_ptr< glsl::SelectionPolygonRenderer > selection_polygon_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:89
void AddPickedPoints(const std::vector< int > indices)
Definition: VisualizerWithVertexSelection.cpp:697
std::shared_ptr< SelectionPolygon > selection_polygon_ptr_
Definition: VisualizerWithVertexSelection.h:87
std::unordered_map< int, Eigen::Vector3d > selected_points_before_drag_
Definition: VisualizerWithVertexSelection.h:108
std::function< void()> on_selection_changed_
Definition: VisualizerWithVertexSelection.h:112
std::shared_ptr< glsl::GeometryRenderer > ui_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:105
Eigen::Vector3d CalcDragDelta(double winX, double winY)
Definition: VisualizerWithVertexSelection.cpp:796
void WindowResizeCallback(GLFWwindow *window, int w, int h) override
Definition: VisualizerWithVertexSelection.cpp:443
void InvalidateSelectionPolygon()
Definition: VisualizerWithVertexSelection.cpp:666
void SetPointSize(double size)
Definition: VisualizerWithVertexSelection.cpp:810
std::shared_ptr< geometry::PointCloud > ui_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:104
bool InitViewControl() override
Function to initialize ViewControl.
Definition: VisualizerWithVertexSelection.cpp:415
const std::vector< Eigen::Vector3d > * GetGeometryPoints(std::shared_ptr< const geometry::Geometry > geometry)
Definition: VisualizerWithVertexSelection.cpp:758
std::vector< int > PickPoints(double x, double y, double w, double h)
Definition: VisualizerWithVertexSelection.cpp:332
std::vector< PickedPoint > GetPickedPoints() const
Definition: VisualizerWithVertexSelection.cpp:406
std::function< void()> on_selection_moved_
Definition: VisualizerWithVertexSelection.h:114
bool AddGeometry(std::shared_ptr< const geometry::Geometry > geometry_ptr, bool reset_bounding_box=true) override
Function to add geometry to the scene and create corresponding shaders.
Definition: VisualizerWithVertexSelection.cpp:79
std::shared_ptr< glsl::PointCloudPickerRenderer > pointcloud_picker_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:97
SelectionMode selection_mode_
Definition: VisualizerWithVertexSelection.h:90
bool UpdateGeometry(std::shared_ptr< const geometry::Geometry > geometry_ptr=nullptr) override
Function to update geometry.
Definition: VisualizerWithVertexSelection.cpp:154
void PrintVisualizerHelp() override
Definition: VisualizerWithVertexSelection.cpp:229
std::shared_ptr< const geometry::Geometry > geometry_ptr_
Definition: VisualizerWithVertexSelection.h:99
float GetDepth(int winX, int winY)
Definition: VisualizerWithVertexSelection.cpp:292
void MouseScrollCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithVertexSelection.cpp:572
RenderOption pick_point_opts_
Definition: VisualizerWithVertexSelection.h:102
void ClearPickedPoints()
Definition: VisualizerWithVertexSelection.cpp:682
VisualizerWithVertexSelection(const VisualizerWithVertexSelection &)=delete
DragType
Definition: VisualizerWithVertexSelection.h:81
@ DRAG_END
Definition: VisualizerWithVertexSelection.h:81
@ DRAG_MOVING
Definition: VisualizerWithVertexSelection.h:81
void RegisterSelectionChangedCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:428
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) override
Definition: VisualizerWithVertexSelection.cpp:578
SelectionMode
Definition: VisualizerWithVertexSelection.h:26
VisualizerWithVertexSelection & operator=(const VisualizerWithVertexSelection &)=delete
std::shared_ptr< geometry::PointCloud > ui_selected_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:109
void MouseMoveCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithVertexSelection.cpp:535
void UpdateWindowTitle() override
Definition: VisualizerWithVertexSelection.cpp:249
void InvalidatePicking()
Definition: VisualizerWithVertexSelection.cpp:675
~VisualizerWithVertexSelection() override
Definition: VisualizerWithVertexSelection.h:30
std::shared_ptr< PointCloudPicker > pointcloud_picker_ptr_
Definition: VisualizerWithVertexSelection.h:95
void RegisterSelectionMovingCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:433
void RemovePickedPoints(const std::vector< int > indices)
Definition: VisualizerWithVertexSelection.cpp:720
VisualizerWithVertexSelection()
Definition: VisualizerWithVertexSelection.h:29
std::vector< int > points_in_rect_
Definition: VisualizerWithVertexSelection.h:92
std::shared_ptr< glsl::GeometryRenderer > ui_selected_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:110
std::unordered_map< int, Eigen::Vector3d > selected_points_
Definition: VisualizerWithVertexSelection.h:107
float drag_depth_
Definition: VisualizerWithVertexSelection.h:93
void RegisterSelectionMovedCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:438
std::shared_ptr< glsl::GeometryRenderer > geometry_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:100
void KeyPressCallback(GLFWwindow *window, int key, int scancode, int action, int mods) override
Definition: VisualizerWithVertexSelection.cpp:450
Eigen::Vector2d mouse_down_pos_
Definition: VisualizerWithVertexSelection.h:91
int size
Definition: FilePCD.cpp:40
char type
Definition: FilePCD.cpp:41
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:250
Definition: PinholeCameraIntrinsic.cpp:16
Definition: VisualizerWithVertexSelection.h:47
Eigen::Vector3d coord
Definition: VisualizerWithVertexSelection.h:49
int index
Definition: VisualizerWithVertexSelection.h:48