Open3D (C++ API)  0.16.0
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-2021 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
33namespace open3d {
34
35namespace geometry {
36class PointCloud;
37}
38
39namespace visualization {
40class SelectionPolygon;
41class PointCloudPicker;
42
44public:
45 enum class SelectionMode { None = 0, Point = 1, Rectangle = 2, Moving = 3 };
46
47public:
51 delete;
53 const VisualizerWithVertexSelection &) = delete;
54
55public:
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 void AddPickedPoints(const std::vector<int> indices);
73 void RemovePickedPoints(const std::vector<int> indices);
74
75 void RegisterSelectionChangedCallback(std::function<void()> f);
78 void RegisterSelectionMovingCallback(std::function<void()> f);
79 void RegisterSelectionMovedCallback(std::function<void()> f);
80
81protected:
82 bool InitViewControl() override;
83 bool InitRenderOption() override;
84 void WindowResizeCallback(GLFWwindow *window, int w, int h) override;
85 void MouseMoveCallback(GLFWwindow *window, double x, double y) override;
86 void MouseScrollCallback(GLFWwindow *window, double x, double y) override;
87 void MouseButtonCallback(GLFWwindow *window,
88 int button,
89 int action,
90 int mods) override;
91 void KeyPressCallback(GLFWwindow *window,
92 int key,
93 int scancode,
94 int action,
95 int mods) override;
97 void InvalidatePicking();
98 float GetDepth(int winX, int winY);
99 Eigen::Vector3d CalcDragDelta(double winX, double winY);
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
105protected:
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_ = 0.0f;
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
Defines rendering options for visualizer.
Definition: RenderOption.h:39
The main Visualizer class.
Definition: Visualizer.h:62
Definition: VisualizerWithVertexSelection.h:43
VisualizerWithVertexSelection & operator=(const VisualizerWithVertexSelection &)=delete
bool InitRenderOption() override
Function to initialize RenderOption.
Definition: VisualizerWithVertexSelection.cpp:441
void BuildUtilities() override
Definition: VisualizerWithVertexSelection.cpp:276
void DragSelectedPoints(const Eigen::Vector3d &delta, DragType type)
Definition: VisualizerWithVertexSelection.cpp:749
std::function< void()> on_selection_moving_
Definition: VisualizerWithVertexSelection.h:132
std::shared_ptr< glsl::SelectionPolygonRenderer > selection_polygon_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:108
void AddPickedPoints(const std::vector< int > indices)
Definition: VisualizerWithVertexSelection.cpp:708
std::shared_ptr< SelectionPolygon > selection_polygon_ptr_
Definition: VisualizerWithVertexSelection.h:106
std::unordered_map< int, Eigen::Vector3d > selected_points_before_drag_
Definition: VisualizerWithVertexSelection.h:127
std::function< void()> on_selection_changed_
Definition: VisualizerWithVertexSelection.h:131
std::shared_ptr< glsl::GeometryRenderer > ui_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:124
Eigen::Vector3d CalcDragDelta(double winX, double winY)
Definition: VisualizerWithVertexSelection.cpp:807
void WindowResizeCallback(GLFWwindow *window, int w, int h) override
Definition: VisualizerWithVertexSelection.cpp:462
void InvalidateSelectionPolygon()
Definition: VisualizerWithVertexSelection.cpp:681
void SetPointSize(double size)
Definition: VisualizerWithVertexSelection.cpp:821
std::shared_ptr< geometry::PointCloud > ui_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:123
bool InitViewControl() override
Function to initialize ViewControl.
Definition: VisualizerWithVertexSelection.cpp:434
const std::vector< Eigen::Vector3d > * GetGeometryPoints(std::shared_ptr< const geometry::Geometry > geometry)
Definition: VisualizerWithVertexSelection.cpp:769
std::vector< int > PickPoints(double x, double y, double w, double h)
Definition: VisualizerWithVertexSelection.cpp:351
std::vector< PickedPoint > GetPickedPoints() const
Definition: VisualizerWithVertexSelection.cpp:425
std::function< void()> on_selection_moved_
Definition: VisualizerWithVertexSelection.h:133
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:98
std::shared_ptr< glsl::PointCloudPickerRenderer > pointcloud_picker_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:116
SelectionMode selection_mode_
Definition: VisualizerWithVertexSelection.h:109
bool UpdateGeometry(std::shared_ptr< const geometry::Geometry > geometry_ptr=nullptr) override
Function to update geometry.
Definition: VisualizerWithVertexSelection.cpp:173
void PrintVisualizerHelp() override
Definition: VisualizerWithVertexSelection.cpp:248
std::shared_ptr< const geometry::Geometry > geometry_ptr_
Definition: VisualizerWithVertexSelection.h:118
float GetDepth(int winX, int winY)
Definition: VisualizerWithVertexSelection.cpp:311
void MouseScrollCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithVertexSelection.cpp:587
RenderOption pick_point_opts_
Definition: VisualizerWithVertexSelection.h:121
void ClearPickedPoints()
Definition: VisualizerWithVertexSelection.cpp:697
VisualizerWithVertexSelection(const VisualizerWithVertexSelection &)=delete
DragType
Definition: VisualizerWithVertexSelection.h:100
@ DRAG_END
Definition: VisualizerWithVertexSelection.h:100
@ DRAG_MOVING
Definition: VisualizerWithVertexSelection.h:100
void RegisterSelectionChangedCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:447
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) override
Definition: VisualizerWithVertexSelection.cpp:593
SelectionMode
Definition: VisualizerWithVertexSelection.h:45
std::shared_ptr< geometry::PointCloud > ui_selected_points_geometry_ptr_
Definition: VisualizerWithVertexSelection.h:128
void MouseMoveCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithVertexSelection.cpp:550
void UpdateWindowTitle() override
Definition: VisualizerWithVertexSelection.cpp:268
void InvalidatePicking()
Definition: VisualizerWithVertexSelection.cpp:690
~VisualizerWithVertexSelection() override
Definition: VisualizerWithVertexSelection.h:49
std::shared_ptr< PointCloudPicker > pointcloud_picker_ptr_
Definition: VisualizerWithVertexSelection.h:114
void RegisterSelectionMovingCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:452
void RemovePickedPoints(const std::vector< int > indices)
Definition: VisualizerWithVertexSelection.cpp:731
VisualizerWithVertexSelection()
Definition: VisualizerWithVertexSelection.h:48
std::vector< int > points_in_rect_
Definition: VisualizerWithVertexSelection.h:111
std::shared_ptr< glsl::GeometryRenderer > ui_selected_points_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:129
std::unordered_map< int, Eigen::Vector3d > selected_points_
Definition: VisualizerWithVertexSelection.h:126
float drag_depth_
Definition: VisualizerWithVertexSelection.h:112
void RegisterSelectionMovedCallback(std::function< void()> f)
Definition: VisualizerWithVertexSelection.cpp:457
std::shared_ptr< glsl::GeometryRenderer > geometry_renderer_ptr_
Definition: VisualizerWithVertexSelection.h:119
void KeyPressCallback(GLFWwindow *window, int key, int scancode, int action, int mods) override
Definition: VisualizerWithVertexSelection.cpp:469
Eigen::Vector2d mouse_down_pos_
Definition: VisualizerWithVertexSelection.h:110
int size
Definition: FilePCD.cpp:59
char type
Definition: FilePCD.cpp:60
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:269
Definition: PinholeCameraIntrinsic.cpp:35
Definition: VisualizerWithVertexSelection.h:66
Eigen::Vector3d coord
Definition: VisualizerWithVertexSelection.h:68
int index
Definition: VisualizerWithVertexSelection.h:67