Open3D (C++ API)  0.18.0+5c982c7
O3DVisualizerSelections.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 <Eigen/Core>
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <vector>
15 
17 
18 namespace open3d {
19 
20 namespace geometry {
21 class Geometry3D;
22 } // namespace geometry
23 
24 namespace t {
25 namespace geometry {
26 class Geometry;
27 } // namespace geometry
28 } // namespace t
29 
30 namespace visualization {
31 namespace visualizer {
32 
36 public:
37  struct SelectedIndex {
38  size_t index;
39  size_t order;
41  Eigen::Vector3d point;
42 
43  bool operator!=(const SelectedIndex& rhs) const {
44  return index != rhs.index;
45  }
46  bool operator<(const SelectedIndex& rhs) const {
47  return index < rhs.index;
48  }
49  };
50  using SelectionSet = std::map<std::string, // name of object
51  std::set<SelectedIndex>>;
52 
53 public:
56 
57  void NewSet();
58  void RemoveSet(int index);
59  void SelectSet(int index);
60  size_t GetNumberOfSets() const;
61 
62  void SelectIndices(
63  const std::map<std::string,
64  std::vector<std::pair<size_t, Eigen::Vector3d>>>&
65  indices);
66  void UnselectIndices(
67  const std::map<std::string,
68  std::vector<std::pair<size_t, Eigen::Vector3d>>>&
69  indices);
70  std::vector<SelectionSet> GetSets();
71 
72  // Since the points are spheres, the radius is in world coordinates
73  void SetPointSize(double radius_world);
74 
75  void MakeActive();
76  void MakeInactive();
77  bool IsActive() const;
78 
80  const std::vector<gui::SceneWidget::PickableGeometry>& geometry);
81 
82 private:
83  void UpdatePointSize();
84  void UpdateSelectionGeometry();
85 
86 private:
87  gui::SceneWidget& widget3d_;
88  int next_id_ = 1;
89 
90  struct SelectedPoints {
91  std::string name;
92  SelectionSet indices;
93  };
94 
95  double point_size_ = 3.0;
96  bool is_active_ = false;
97  size_t pick_order_ = 0;
98  std::vector<SelectedPoints> sets_;
99  int current_set_index_ = -1;
100 
101  bool point_size_changed_ = false;
102 };
103 
104 } // namespace visualizer
105 } // namespace visualization
106 } // namespace open3d
Definition: SceneWidget.h:49
Definition: O3DVisualizerSelections.h:35
void RemoveSet(int index)
Definition: O3DVisualizerSelections.cpp:46
void NewSet()
Definition: O3DVisualizerSelections.cpp:38
void MakeActive()
Definition: O3DVisualizerSelections.cpp:161
void SelectIndices(const std::map< std::string, std::vector< std::pair< size_t, Eigen::Vector3d >>> &indices)
Definition: O3DVisualizerSelections.cpp:74
void SelectSet(int index)
Definition: O3DVisualizerSelections.cpp:59
void MakeInactive()
Definition: O3DVisualizerSelections.cpp:183
std::map< std::string, std::set< SelectedIndex > > SelectionSet
Definition: O3DVisualizerSelections.h:51
~O3DVisualizerSelections()
Definition: O3DVisualizerSelections.cpp:36
void UnselectIndices(const std::map< std::string, std::vector< std::pair< size_t, Eigen::Vector3d >>> &indices)
Definition: O3DVisualizerSelections.cpp:94
void SetSelectableGeometry(const std::vector< gui::SceneWidget::PickableGeometry > &geometry)
Definition: O3DVisualizerSelections.cpp:194
size_t GetNumberOfSets() const
Definition: O3DVisualizerSelections.cpp:72
std::vector< SelectionSet > GetSets()
Definition: O3DVisualizerSelections.cpp:143
O3DVisualizerSelections(gui::SceneWidget &widget3d)
Definition: O3DVisualizerSelections.cpp:33
bool IsActive() const
Definition: O3DVisualizerSelections.cpp:181
void SetPointSize(double radius_world)
Definition: O3DVisualizerSelections.cpp:152
std::string name
Definition: FilePCD.cpp:39
Definition: PinholeCameraIntrinsic.cpp:16
size_t order
the index of the point within the object
Definition: O3DVisualizerSelections.h:39
bool operator!=(const SelectedIndex &rhs) const
the point in R^3 (for convenience)
Definition: O3DVisualizerSelections.h:43
Eigen::Vector3d point
Definition: O3DVisualizerSelections.h:41
bool operator<(const SelectedIndex &rhs) const
Definition: O3DVisualizerSelections.h:46