ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvPointPickingHelper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <vtkSmartPointer.h>
11 
12 #include <QKeySequence>
13 #include <QObject>
14 #include <QPointer>
15 
16 // CV_DB_LIB
18 
19 class QWidget;
20 class vtkCell;
21 class vtkCellPicker;
22 class vtkDataSet;
23 class vtkPointPicker;
24 class vtkPropPicker;
25 class vtkHardwareSelector;
26 class vtkRenderWindowInteractor;
27 class vtkRenderer;
28 
43 class cvPointPickingHelper : public QObject {
44  Q_OBJECT
45 
46 public:
47  enum PickOption {
51  };
52 
61  cvPointPickingHelper(const QKeySequence& keySequence,
62  bool pickOnPoint,
63  QWidget* parent = nullptr,
64  PickOption pickOpt = Coordinates);
65  ~cvPointPickingHelper() override;
66 
70  bool pickOnPoint() const { return m_pickOnPoint; }
71 
75  PickOption getPickOption() const { return m_pickOption; }
76 
80  void setInteractor(vtkRenderWindowInteractor* interactor);
81 
85  void setRenderer(vtkRenderer* renderer);
86 
90  void setContextWidget(QWidget* widget);
91 
98  void setEnabled(bool enabled, bool setFocus = false);
99 
103  bool isEnabled() const;
104 
109  void clearSelectionCache();
110 
111 Q_SIGNALS:
118  void pick(double x, double y, double z);
119 
130  double px, double py, double pz, double nx, double ny, double nz);
131 
132 private Q_SLOTS:
133  void pickPoint();
134 
135 private:
136  Q_DISABLE_COPY(cvPointPickingHelper)
137 
138 
139  void getCellNormal(vtkDataSet* dataset,
140  vtkIdType cellId,
141  vtkCell* cell,
142  double normal[3]);
143 
144  QPointer<ecvModalShortcut> m_shortcut;
145  QPointer<QWidget> m_contextWidget;
146  vtkRenderWindowInteractor* m_interactor = nullptr;
147  vtkRenderer* m_renderer = nullptr;
148  bool m_pickOnPoint;
149  PickOption m_pickOption;
150 
151  // Reusable pickers to avoid creating new objects on each pick
152  vtkSmartPointer<vtkPointPicker> m_pointPicker;
153  vtkSmartPointer<vtkCellPicker> m_cellPicker;
155  m_propPicker; // Fast hardware-accelerated picker
157  m_hardwareSelector; // Ultra-fast GPU-based picking
158 
159  // Selection cache (ParaView-style optimization)
160  struct SelectionCache {
161  int displayX = -1;
162  int displayY = -1;
163  bool pickOnPoint = false;
164  double position[3] = {0, 0, 0};
165  double normal[3] = {0, 0, 1};
166  bool valid = false;
167  vtkIdType id = -1;
168  } m_selectionCache;
169 };
double normal[3]
math::float3 position
cvPointPickingHelper is a helper class for supporting keyboard shortcut-based point picking in measur...
bool isEnabled() const
Check if shortcut is enabled.
@ Coordinates
Pick point coordinates only.
@ Normal
Pick normal only.
@ CoordinatesAndNormal
Pick both coordinates and normal.
bool pickOnPoint() const
Returns whether picking snaps to mesh points.
void setEnabled(bool enabled, bool setFocus=false)
Enable or disable the shortcut.
void setContextWidget(QWidget *widget)
Set the context widget for the shortcut.
cvPointPickingHelper(const QKeySequence &keySequence, bool pickOnPoint, QWidget *parent=nullptr, PickOption pickOpt=Coordinates)
Constructor.
void setInteractor(vtkRenderWindowInteractor *interactor)
Set the VTK interactor for picking.
PickOption getPickOption() const
Returns the pick option.
void setRenderer(vtkRenderer *renderer)
Set the VTK renderer for picking.
void clearSelectionCache()
Clear the selection cache (ParaView-style optimization) Call this when the scene changes to invalidat...
void pickNormal(double px, double py, double pz, double nx, double ny, double nz)
Emitted when a point and normal are picked.
void pick(double x, double y, double z)
Emitted when a point is picked.
normal_z y
normal_z x
normal_z z