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 
41 public:
42  enum class SelectionMode {
43  None = 0,
44  Rectangle = 1,
45  Polygon = 2,
46  };
47 
48 public:
50  bool use_dialog = true,
51  const std::string &directory = "")
53  use_dialog_(use_dialog),
54  default_directory_(directory) {}
55  ~VisualizerWithEditing() override {}
58 
59 public:
63  bool AddGeometry(std::shared_ptr<const geometry::Geometry> geometry_ptr,
64  bool reset_bounding_box = true) override;
65  void PrintVisualizerHelp() override;
66  void UpdateWindowTitle() override;
67  void BuildUtilities() override;
68  int PickPoint(double x, double y);
69  std::vector<size_t> &GetPickedPoints();
70 
71 protected:
72  bool InitViewControl() override;
73  bool InitRenderOption() override;
74  void WindowResizeCallback(GLFWwindow *window, int w, int h) override;
75  void MouseMoveCallback(GLFWwindow *window, double x, double y) override;
76  void MouseScrollCallback(GLFWwindow *window, double x, double y) override;
77  void MouseButtonCallback(GLFWwindow *window,
78  int button,
79  int action,
80  int mods) override;
81  void KeyPressCallback(GLFWwindow *window,
82  int key,
83  int scancode,
84  int action,
85  int mods) override;
87  void InvalidatePicking();
88  void SaveCroppingResult(const std::string &filename = "");
89 
90 protected:
91  std::shared_ptr<SelectionPolygon> selection_polygon_ptr_;
92  std::shared_ptr<glsl::SelectionPolygonRenderer>
95 
96  std::shared_ptr<PointCloudPicker> pointcloud_picker_ptr_;
97  std::shared_ptr<glsl::PointCloudPickerRenderer>
99 
100  std::shared_ptr<const geometry::Geometry> original_geometry_ptr_;
101  std::shared_ptr<geometry::Geometry> editing_geometry_ptr_;
102  std::shared_ptr<glsl::GeometryRenderer> editing_geometry_renderer_ptr_;
103 
104  double voxel_size_ = -1.0;
105  bool use_dialog_ = true;
106  std::string default_directory_;
107  unsigned int crop_action_count_ = 0;
108 };
109 
110 } // namespace visualization
111 } // namespace open3d
void WindowResizeCallback(GLFWwindow *window, int w, int h) override
Definition: VisualizerWithEditing.cpp:476
std::shared_ptr< geometry::Geometry > editing_geometry_ptr_
Definition: VisualizerWithEditing.h:101
void InvalidatePicking()
Definition: VisualizerWithEditing.cpp:645
VisualizerWithEditing & operator=(const VisualizerWithEditing &)=delete
std::vector< size_t > & GetPickedPoints()
Definition: VisualizerWithEditing.cpp:258
void UpdateWindowTitle() override
Definition: VisualizerWithEditing.cpp:146
bool AddGeometry(std::shared_ptr< const geometry::Geometry > geometry_ptr, bool reset_bounding_box=true) override
Definition: VisualizerWithEditing.cpp:49
void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods) override
Definition: VisualizerWithEditing.cpp:521
SelectionMode selection_mode_
Definition: VisualizerWithEditing.h:94
double voxel_size
Definition: FilePLY.cpp:286
void BuildUtilities() override
Definition: VisualizerWithEditing.cpp:155
std::shared_ptr< PointCloudPicker > pointcloud_picker_ptr_
Definition: VisualizerWithEditing.h:96
std::string default_directory_
Definition: VisualizerWithEditing.h:106
unsigned int crop_action_count_
Definition: VisualizerWithEditing.h:107
SelectionMode
Definition: VisualizerWithEditing.h:42
~VisualizerWithEditing() override
Definition: VisualizerWithEditing.h:55
bool use_dialog_
Definition: VisualizerWithEditing.h:105
void SaveCroppingResult(const std::string &filename="")
Definition: VisualizerWithEditing.cpp:652
void MouseScrollCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithEditing.cpp:511
VisualizerWithEditing(double voxel_size=-1.0, bool use_dialog=true, const std::string &directory="")
Definition: VisualizerWithEditing.h:49
void PrintVisualizerHelp() override
Definition: VisualizerWithEditing.cpp:120
Definition: Open3DViewer.h:29
std::shared_ptr< glsl::PointCloudPickerRenderer > pointcloud_picker_renderer_ptr_
Definition: VisualizerWithEditing.h:98
The main Visualizer class.
Definition: Visualizer.h:60
bool InitRenderOption() override
Function to initialize RenderOption.
Definition: VisualizerWithEditing.cpp:269
std::shared_ptr< SelectionPolygon > selection_polygon_ptr_
Definition: VisualizerWithEditing.h:91
std::shared_ptr< glsl::GeometryRenderer > editing_geometry_renderer_ptr_
Definition: VisualizerWithEditing.h:102
std::shared_ptr< const geometry::Geometry > original_geometry_ptr_
Definition: VisualizerWithEditing.h:100
std::shared_ptr< glsl::SelectionPolygonRenderer > selection_polygon_renderer_ptr_
Definition: VisualizerWithEditing.h:93
Visualizer with editing capabilities.
Definition: VisualizerWithEditing.h:40
void InvalidateSelectionPolygon()
Definition: VisualizerWithEditing.cpp:637
int PickPoint(double x, double y)
Definition: VisualizerWithEditing.cpp:192
double voxel_size_
Definition: VisualizerWithEditing.h:104
void KeyPressCallback(GLFWwindow *window, int key, int scancode, int action, int mods) override
Definition: VisualizerWithEditing.cpp:275
void MouseMoveCallback(GLFWwindow *window, double x, double y) override
Definition: VisualizerWithEditing.cpp:483
bool InitViewControl() override
Function to initialize ViewControl.
Definition: VisualizerWithEditing.cpp:262