Open3D (C++ API)
VisualizerWithVertexSelection.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <unordered_map>
30 
32 
33 namespace open3d {
34 
35 namespace geometry {
36 class PointCloud;
37 }
38 
39 namespace visualization {
40 class SelectionPolygon;
41 class PointCloudPicker;
42 
44 public:
45  enum class SelectionMode { None = 0, Point = 1, Rectangle = 2, Moving = 3 };
46 
47 public:
51  delete;
53  const VisualizerWithVertexSelection &) = delete;
54 
55 public:
56  bool AddGeometry(std::shared_ptr<const geometry::Geometry> geometry_ptr,
57  bool reset_bounding_box = true) override;
58  bool UpdateGeometry(std::shared_ptr<const geometry::Geometry> geometry_ptr =
59  nullptr) override;
60  void PrintVisualizerHelp() override;
61  void UpdateWindowTitle() override;
62  void BuildUtilities() override;
63  void SetPointSize(double size);
64  std::vector<int> PickPoints(double x, double y, double w, double h);
65 
66  struct PickedPoint {
67  int index;
68  Eigen::Vector3d coord;
69  };
70  std::vector<PickedPoint> GetPickedPoints() const;
71  void ClearPickedPoints();
72 
73  void RegisterSelectionChangedCallback(std::function<void()> f);
76  void RegisterSelectionMovingCallback(std::function<void()> f);
77  void RegisterSelectionMovedCallback(std::function<void()> f);
78 
79 protected:
80  bool InitViewControl() override;
81  bool InitRenderOption() override;
82  void WindowResizeCallback(GLFWwindow *window, int w, int h) override;
83  void MouseMoveCallback(GLFWwindow *window, double x, double y) override;
84  void MouseScrollCallback(GLFWwindow *window, double x, double y) override;
85  void MouseButtonCallback(GLFWwindow *window,
86  int button,
87  int action,
88  int mods) override;
89  void KeyPressCallback(GLFWwindow *window,
90  int key,
91  int scancode,
92  int action,
93  int mods) override;
94  void InvalidateSelectionPolygon();
95  void InvalidatePicking();
96  void AddPickedPoints(const std::vector<int> indices);
97  void RemovePickedPoints(const std::vector<int> indices);
98  float GetDepth(int winX, int winY);
99  Eigen::Vector3d CalcDragDelta(double winX, double winY);
100  enum DragType { DRAG_MOVING, DRAG_END };
101  void DragSelectedPoints(const Eigen::Vector3d &delta, DragType type);
102  const std::vector<Eigen::Vector3d> *GetGeometryPoints(
103  std::shared_ptr<const geometry::Geometry> geometry);
104 
105 protected:
106  std::shared_ptr<SelectionPolygon> selection_polygon_ptr_;
107  std::shared_ptr<glsl::SelectionPolygonRenderer>
110  Eigen::Vector2d mouse_down_pos_;
111  std::vector<int> points_in_rect_;
112  float drag_depth_;
113 
114  std::shared_ptr<PointCloudPicker> pointcloud_picker_ptr_;
115  std::shared_ptr<glsl::PointCloudPickerRenderer>
117 
118  std::shared_ptr<const geometry::Geometry> geometry_ptr_;
119  std::shared_ptr<glsl::GeometryRenderer> geometry_renderer_ptr_;
120 
122 
123  std::shared_ptr<geometry::PointCloud> ui_points_geometry_ptr_;
124  std::shared_ptr<glsl::GeometryRenderer> ui_points_renderer_ptr_;
125 
126  std::unordered_map<int, Eigen::Vector3d> selected_points_;
127  std::unordered_map<int, Eigen::Vector3d> selected_points_before_drag_;
128  std::shared_ptr<geometry::PointCloud> ui_selected_points_geometry_ptr_;
129  std::shared_ptr<glsl::GeometryRenderer> ui_selected_points_renderer_ptr_;
130 
131  std::function<void()> on_selection_changed_;
132  std::function<void()> on_selection_moving_;
133  std::function<void()> on_selection_moved_;
134 };
135 
136 } // namespace visualization
137 } // namespace open3d
Eigen::Vector3d coord
Definition: VisualizerWithVertexSelection.h:68
float drag_depth_
Definition: VisualizerWithVertexSelection.h:112
std::shared_ptr< glsl::GeometryRenderer > ui_selected_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:129
std::function< void()> on_selection_moved_
Definition: VisualizerWithVertexSelection.h:133
std::function< void()> on_selection_changed_
Definition: VisualizerWithVertexSelection.h:131
std::unordered_map< int, Eigen::Vector3d > selected_points_before_drag_
Definition: VisualizerWithVertexSelection.h:127
std::shared_ptr< geometry::PointCloud > ui_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:123
std::unordered_map< int, Eigen::Vector3d > selected_points_
Definition: VisualizerWithVertexSelection.h:126
VisualizerWithVertexSelection()
Definition: VisualizerWithVertexSelection.h:48
int size
Definition: FilePCD.cpp:57
Eigen::Vector2d mouse_down_pos_
Definition: VisualizerWithVertexSelection.h:110
RenderOption pick_point_opts_
Definition: VisualizerWithVertexSelection.h:121
~VisualizerWithVertexSelection() override
Definition: VisualizerWithVertexSelection.h:49
Defines rendering options for visualizer.
Definition: RenderOption.h:39
std::shared_ptr< SelectionPolygon > selection_polygon_ptr_
Definition: VisualizerWithVertexSelection.h:106
std::function< void()> on_selection_moving_
Definition: VisualizerWithVertexSelection.h:132
std::vector< int > points_in_rect_
Definition: VisualizerWithVertexSelection.h:111
std::shared_ptr< glsl::GeometryRenderer > ui_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:124
char type
Definition: FilePCD.cpp:58
int index
Definition: VisualizerWithVertexSelection.h:67
std::shared_ptr< glsl::PointCloudPickerRenderer > pointcloud_picker_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:116
Definition: Open3DViewer.h:29
The main Visualizer class.
Definition: Visualizer.h:60
DragType
Definition: VisualizerWithVertexSelection.h:100
SelectionMode
Definition: VisualizerWithVertexSelection.h:45
Definition: VisualizerWithVertexSelection.h:66
std::shared_ptr< glsl::GeometryRenderer > geometry_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:119
NoneType None
Definition: TensorKey.cpp:33
Definition: VisualizerWithVertexSelection.h:43
std::shared_ptr< PointCloudPicker > pointcloud_picker_ptr_
Definition: VisualizerWithVertexSelection.h:114
std::shared_ptr< geometry::PointCloud > ui_selected_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:128
std::shared_ptr< glsl::SelectionPolygonRenderer > selection_polygon_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:108
std::shared_ptr< const geometry::Geometry > geometry_ptr_
Definition: VisualizerWithVertexSelection.h:118