ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvRenderViewSelectionReaction.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 
27 // clang-format off
28 // Qt - must be included before other headers for MOC to work correctly
29 #include <QtGlobal>
30 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
31 #include <QAction>
32 #include <QCursor>
33 #include <QObject>
34 #include <QPointer>
35 #include <QShortcut>
36 #include <QTimer>
37 #else
38 #include <QtWidgets/QAction>
39 #include <QtGui/QCursor>
40 #include <QtCore/QObject>
41 #include <QtCore/QPointer>
42 #include <QtWidgets/QShortcut>
43 #include <QtCore/QTimer>
44 #endif
45 // clang-format on
46 
47 #include "cvSelectionData.h"
48 #include "cvSelectionData.h" // Contains SelectionMode, SelectionModifier enums
49 #include "qPCL.h"
50 
51 // VTK
52 #include <vtkSmartPointer.h>
53 #include <vtkWeakPointer.h>
54 
55 // Forward declarations
56 class QActionGroup;
60 class vtkObject;
61 class vtkRenderWindowInteractor;
62 class vtkRenderer;
63 class vtkInteractorStyle;
64 class vtkIntArray;
65 class vtkPolyData;
66 
67 namespace PclUtils {
68 class PCLVis;
69 }
70 
90  Q_OBJECT
91 
92 public:
95 
102  cvRenderViewSelectionReaction(QAction* parentAction,
103  SelectionMode mode,
104  QActionGroup* modifierGroup = nullptr);
105 
106  ~cvRenderViewSelectionReaction() override;
107 
111  QAction* parentAction() const { return m_parentAction; }
112 
116  SelectionMode mode() const { return m_mode; }
117 
124  void setVisualizer(ecvGenericVisualizer3D* viewer);
125 
129  ecvGenericVisualizer3D* getVisualizer() const { return m_viewer; }
130 
134  bool isActive() const;
135 
143  return ActiveReaction;
144  }
145 
152  static void endActiveSelection();
153 
154  //-------------------------------------------------------------------------
155  // Public event handlers (called by VTK callbacks)
156  //-------------------------------------------------------------------------
157 
162  void handleSelectionChanged(vtkObject* caller,
163  unsigned long eventId,
164  void* callData);
165 
169  Q_INVOKABLE void handleMouseMove();
170 
174  Q_INVOKABLE void handleLeftButtonPress();
175 
179  Q_INVOKABLE void handleLeftButtonRelease();
180 
184  Q_INVOKABLE void handleWheelRotate();
185 
189  Q_INVOKABLE void handleRightButtonPressed();
190 
194  Q_INVOKABLE void handleRightButtonRelease();
195 
196 protected:
198 
207  void vtkOnSelectionChanged(vtkObject* caller,
208  unsigned long eventId,
209  void* callData);
210  void vtkOnMouseMove(vtkObject* caller,
211  unsigned long eventId,
212  void* callData);
213  void vtkOnLeftButtonPress(vtkObject* caller,
214  unsigned long eventId,
215  void* callData);
216  void vtkOnLeftButtonRelease(vtkObject* caller,
217  unsigned long eventId,
218  void* callData);
219  void vtkOnWheelRotate(vtkObject* caller,
220  unsigned long eventId,
221  void* callData);
222  void vtkOnRightButtonPressed(vtkObject* caller,
223  unsigned long eventId,
224  void* callData);
225  void vtkOnRightButtonRelease(vtkObject* caller,
226  unsigned long eventId,
227  void* callData);
228  void vtkOnMiddleButtonPressed(vtkObject* caller,
229  unsigned long eventId,
230  void* callData);
231  void vtkOnMiddleButtonRelease(vtkObject* caller,
232  unsigned long eventId,
233  void* callData);
235 
236 signals:
241  void selectionFinished(const cvSelectionData& selectionData);
242 
247  void selectedCustomBox(int xmin, int ymin, int xmax, int ymax);
248  void selectedCustomBox(const int region[4]);
249 
254  void selectedCustomPolygon(vtkIntArray* polygon);
255 
259  void zoomToBoxCompleted(int xmin, int ymin, int xmax, int ymax);
260 
261 public slots:
270  virtual void actionTriggered(bool val);
271 
280  virtual void updateEnableState();
281 
282 protected slots:
296  virtual void beginSelection();
297 
310  virtual void endSelection();
311 
317  virtual void onMouseStop();
318 
324  virtual void clearSelectionCache();
325 
326 protected:
338  virtual void selectionChanged(vtkObject* caller,
339  unsigned long eventId,
340  void* callData);
341 
347  virtual void onMouseMove();
348 
352  virtual void onLeftButtonPress();
353 
359  virtual void onLeftButtonRelease();
360 
366  virtual void onWheelRotate();
367 
371  virtual void onRightButtonPressed();
372 
376  virtual void onRightButtonRelease();
377 
381  virtual void onMiddleButtonPressed();
382 
387  virtual void onMiddleButtonRelease();
388 
394  virtual void preSelection();
395 
401  virtual void fastPreSelection();
402 
408  virtual void updateTooltip();
409 
418  virtual int getSelectionModifier();
419 
427  virtual bool isCompatible(SelectionMode mode);
428 
434  virtual void cleanupObservers();
435 
439  void uncheckSelectionModifiers();
440 
441  //-------------------------------------------------------------------------
442  // Selection execution methods
443  //-------------------------------------------------------------------------
444 
450  void selectCellsOnSurface(int region[4], int selectionModifier);
451 
457  void selectPointsOnSurface(int region[4], int selectionModifier);
458 
464  void selectFrustumCells(int region[4], int selectionModifier);
465 
471  void selectFrustumPoints(int region[4], int selectionModifier);
472 
481  void finalizeSelection(const cvSelectionData& newSelection,
482  int selectionModifier,
483  const QString& description);
484 
490  void selectPolygonCells(vtkIntArray* polygon, int selectionModifier);
491 
497  void selectPolygonPoints(vtkIntArray* polygon, int selectionModifier);
498 
504  void selectBlock(int region[4], int selectionModifier);
505 
506  //-------------------------------------------------------------------------
507  // Internal helpers
508  //-------------------------------------------------------------------------
509 
513  PclUtils::PCLVis* getPCLVis() const;
514 
518  cvSelectionPipeline* getSelectionPipeline() const;
519 
523  cvSelectionHighlighter* getSelectionHighlighter() const;
524 
528  bool isSelectingCells() const;
529 
533  bool isInteractiveMode() const;
534 
538  bool isTooltipMode() const;
539 
543  void setCursor(const QCursor& cursor);
544 
548  void unsetCursor();
549 
553  void storeCurrentStyle();
554 
558  void restoreStyle();
559 
563  void setupInteractorStyle();
564 
568  void setupObservers();
569 
577  void addCameraMovementObservers(int startIndex);
578 
585  void setRubberBand3DStyle(bool renderOnMouseMove);
586 
590  void showInstructionDialog();
591 
592 private:
593  // Qt objects
594  QPointer<QAction> m_parentAction;
595  QPointer<QActionGroup> m_modifierGroup;
596 
597  // Selection mode
598  SelectionMode m_mode;
599 
600  // Visualizer reference (not owned)
601  ecvGenericVisualizer3D* m_viewer = nullptr;
602 
603  // VTK objects
604  vtkRenderWindowInteractor* m_interactor = nullptr;
605  vtkRenderer* m_renderer = nullptr;
606  vtkSmartPointer<vtkInteractorStyle> m_previousStyle;
607  vtkSmartPointer<vtkInteractorStyle> m_selectionStyle;
608 
609  // Previous render view mode (for restoration)
610  int m_previousRenderViewMode = -1;
611 
612  // Event observer IDs for interactor events (increased to 8 for pan/zoom)
613  unsigned long m_observerIds[8] = {0, 0, 0, 0, 0, 0, 0, 0};
614  vtkWeakPointer<vtkObject> m_observedObject;
615 
616  // Separate observer ID for selection style (SelectionChangedEvent)
617  unsigned long m_styleObserverId = 0;
618 
619  // Cursor
620  QCursor m_zoomCursor;
621 
622  // Mouse move state (for tooltip timing)
623  QTimer m_mouseMovingTimer;
624  bool m_mouseMoving = false;
625  int m_mousePosition[2] = {0, 0};
626 
627  // Zoom box tracking (for zoomToBoxCompleted signal)
628  int m_zoomStartPosition[2] = {0, 0};
629  bool m_zoomTracking = false;
630 
631  // Pre-selection state
632  bool m_disablePreSelection = false;
633 
634  // Tooltip state
635  QString m_plainTooltipText;
636  QShortcut* m_copyTooltipShortcut = nullptr;
637 
638  // Current highlight state (for interactive modes)
639  vtkIdType m_hoveredId = -1;
640  vtkPolyData* m_currentPolyData = nullptr;
641 
642  // Current selection data
643  cvSelectionData m_currentSelection;
644 
645  // Static: only one reaction can be active at a time
646  // Reference: pqRenderViewSelectionReaction::ActiveReaction
647  static QPointer<cvRenderViewSelectionReaction> ActiveReaction;
648 
649  // Tooltip display wait time (ms)
650  static const int TOOLTIP_WAITING_TIME = 400;
651 };
#define slots
#define signals
boost::geometry::model::polygon< point_xy > polygon
Definition: TreeIso.cpp:37
cvRenderViewSelectionReaction handles all selection modes in a single class
static cvRenderViewSelectionReaction * activeReaction()
Get the currently active reaction (static)
void zoomToBoxCompleted(int xmin, int ymin, int xmax, int ymax)
Emitted when zoom to box is completed.
void selectedCustomPolygon(vtkIntArray *polygon)
Emitted for custom polygon selection.
ecvGenericVisualizer3D * getVisualizer() const
Get the current visualizer.
QAction * parentAction() const
Get the parent action.
SelectionMode mode() const
Get the selection mode.
void selectionFinished(const cvSelectionData &selectionData)
Emitted when selection is finished.
void selectedCustomBox(int xmin, int ymin, int xmax, int ymax)
Emitted for custom box selection.
void selectedCustomBox(const int region[4])
Encapsulates selection data without exposing VTK types.
Helper class for highlighting selected elements in the visualizer.
Selection pipeline abstraction layer.
Generic visualizer 3D interface.
SelectionMode
Selection modes matching ParaView's SelectionMode enum.
SelectionModifier
Selection modifiers for combining selections.
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15