Open3D (C++ API)
VisualizerWithEditing.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 
30 
31 namespace open3d {
32 
33 namespace visualization {
34 class SelectionPolygon;
35 class PointCloudPicker;
36 
38 public:
39  enum class SelectionMode {
40  None = 0,
41  Rectangle = 1,
42  Polygon = 2,
43  };
44 
45 public:
46  VisualizerWithEditing(double voxel_size = -1.0,
47  bool use_dialog = true,
48  const std::string &directory = "")
49  : voxel_size_(voxel_size),
50  use_dialog_(use_dialog),
51  default_directory_(directory) {}
52  ~VisualizerWithEditing() override {}
55 
56 public:
57  bool AddGeometry(
58  std::shared_ptr<const geometry::Geometry> geometry_ptr) override;
59  void PrintVisualizerHelp() override;
60  void UpdateWindowTitle() override;
61  void BuildUtilities() override;
62  int PickPoint(double x, double y);
63  std::vector<size_t> &GetPickedPoints();
64 
65 protected:
66  bool InitViewControl() override;
67  bool InitRenderOption() override;
68  void WindowResizeCallback(GLFWwindow *window, int w, int h) override;
69  void MouseMoveCallback(GLFWwindow *window, double x, double y) override;
70  void MouseScrollCallback(GLFWwindow *window, double x, double y) override;
71  void MouseButtonCallback(GLFWwindow *window,
72  int button,
73  int action,
74  int mods) override;
75  void KeyPressCallback(GLFWwindow *window,
76  int key,
77  int scancode,
78  int action,
79  int mods) override;
81  void InvalidatePicking();
82  void SaveCroppingResult(const std::string &filename = "");
83 
84 protected:
85  std::shared_ptr<SelectionPolygon> selection_polygon_ptr_;
86  std::shared_ptr<glsl::SelectionPolygonRenderer>
89 
90  std::shared_ptr<PointCloudPicker> pointcloud_picker_ptr_;
91  std::shared_ptr<glsl::PointCloudPickerRenderer>
93 
94  std::shared_ptr<const geometry::Geometry> original_geometry_ptr_;
95  std::shared_ptr<geometry::Geometry> editing_geometry_ptr_;
96  std::shared_ptr<glsl::GeometryRenderer> editing_geometry_renderer_ptr_;
97 
98  double voxel_size_ = -1.0;
99  bool use_dialog_ = true;
100  std::string default_directory_;
101  unsigned int crop_action_count_ = 0;
102 };
103 
104 } // namespace visualization
105 } // namespace open3d
void WindowResizeCallback(GLFWwindow *window, int w, int h) override
Definition: VisualizerWithEditing.cpp:474
std::shared_ptr< geometry::Geometry > editing_geometry_ptr_
Definition: VisualizerWithEditing.h:95
void InvalidatePicking()
Definition: VisualizerWithEditing.cpp:643
VisualizerWithEditing & operator=(const VisualizerWithEditing &)=delete
bool AddGeometry(std::shared_ptr< const geometry::Geometry > geometry_ptr) override
Definition: VisualizerWithEditing.cpp:48
std::vector< size_t > & GetPickedPoints()
Definition: VisualizerWithEditing.cpp:253
void UpdateWindowTitle() override
Definition: VisualizerWithEditing.cpp:142
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) override
Definition: VisualizerWithEditing.cpp:519
SelectionMode selection_mode_
Definition: VisualizerWithEditing.h:88
void BuildUtilities() override
Definition: VisualizerWithEditing.cpp:151
std::shared_ptr< PointCloudPicker > pointcloud_picker_ptr_
Definition: VisualizerWithEditing.h:90
std::string default_directory_
Definition: VisualizerWithEditing.h:100
unsigned int crop_action_count_
Definition: VisualizerWithEditing.h:101
SelectionMode
Definition: VisualizerWithEditing.h:39
~VisualizerWithEditing() override
Definition: VisualizerWithEditing.h:52
bool use_dialog_
Definition: VisualizerWithEditing.h:99
void SaveCroppingResult(const std::string &filename="")
Definition: VisualizerWithEditing.cpp:650
void MouseScrollCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithEditing.cpp:509
VisualizerWithEditing(double voxel_size=-1.0, bool use_dialog=true, const std::string &directory="")
Definition: VisualizerWithEditing.h:46
void PrintVisualizerHelp() override
Definition: VisualizerWithEditing.cpp:116
Definition: PinholeCameraIntrinsic.cpp:33
std::shared_ptr< glsl::PointCloudPickerRenderer > pointcloud_picker_renderer_ptr_
Definition: VisualizerWithEditing.h:92
Definition: Visualizer.h:50
bool InitRenderOption() override
Function to initialize RenderOption.
Definition: VisualizerWithEditing.cpp:264
std::shared_ptr< SelectionPolygon > selection_polygon_ptr_
Definition: VisualizerWithEditing.h:85
std::shared_ptr< glsl::GeometryRenderer > editing_geometry_renderer_ptr_
Definition: VisualizerWithEditing.h:96
std::shared_ptr< const geometry::Geometry > original_geometry_ptr_
Definition: VisualizerWithEditing.h:94
std::shared_ptr< glsl::SelectionPolygonRenderer > selection_polygon_renderer_ptr_
Definition: VisualizerWithEditing.h:87
Definition: VisualizerWithEditing.h:37
void InvalidateSelectionPolygon()
Definition: VisualizerWithEditing.cpp:635
int PickPoint(double x, double y)
Definition: VisualizerWithEditing.cpp:188
double voxel_size_
Definition: VisualizerWithEditing.h:98
void KeyPressCallback(GLFWwindow *window, int key, int scancode, int action, int mods) override
Definition: VisualizerWithEditing.cpp:270
void MouseMoveCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithEditing.cpp:481
bool InitViewControl() override
Function to initialize ViewControl.
Definition: VisualizerWithEditing.cpp:257