ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvGenericSelectionTool.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 <vector>
11 
12 #include "cvSelectionBase.h"
13 #include "cvSelectionData.h"
14 // cvSelectionTypes.h merged into cvSelectionData.h
15 
16 // VTK includes (need full definitions for template instantiation)
17 #include <vtkCellPicker.h> // Full definition needed for vtkSmartPointer<vtkCellPicker>
18 #include <vtkHardwareSelector.h> // Full definition needed for vtkSmartPointer<vtkHardwareSelector>
19 #include <vtkPointPicker.h> // Full definition needed for vtkSmartPointer<vtkPointPicker>
20 #include <vtkSmartPointer.h> // For vtkSmartPointer template
21 #include <vtkType.h> // For vtkIdType
22 
23 // Forward declarations
24 class vtkRenderer;
25 class vtkSelection;
26 class vtkRenderWindowInteractor;
29 
48 public:
54 
60 
62  : cvSelectionBase(),
63  m_manager(nullptr),
64  m_useHardwareSelection(false),
65  m_captureZValues(true),
66  m_multipleSelectionMode(false),
67  m_interactor(nullptr),
68  m_renderer(nullptr) {}
69 
70  ~cvGenericSelectionTool() override = default;
71 
77  m_manager = manager;
78  }
79 
84  cvViewSelectionManager* getSelectionManager() const { return m_manager; }
85 
90  cvSelectionPipeline* getSelectionPipeline() const;
91 
111  vtkPolyData* getPolyDataForSelection(
112  const cvSelectionData* selectionData = nullptr) override;
113 
114 protected:
115  // Note: Visualizer access methods (setVisualizer, getVisualizer, getPCLVis,
116  // hasValidPCLVis, getAllPolyDataFromVisualizer)
117  // are inherited from cvSelectionBase
118 
120 
139  cvSelectionData hardwareSelectAtPoint(
140  int x,
141  int y,
144 
152  cvSelectionData hardwareSelectInRegion(
153  const int region[4],
156 
166  QVector<cvActorSelectionInfo> getActorsAtPoint(int x, int y);
167 
169 
171 
183  void setUseHardwareSelection(bool enable) {
184  m_useHardwareSelection = enable;
185  }
186 
190  bool useHardwareSelection() const { return m_useHardwareSelection; }
191 
196  void setCaptureZValues(bool capture) { m_captureZValues = capture; }
197 
202  void setMultipleSelectionMode(bool enable) {
203  m_multipleSelectionMode = enable;
204  }
205 
209  bool multipleSelectionMode() const { return m_multipleSelectionMode; }
210 
212 
214 
231  void initializePickers();
232 
243  vtkIdType pickAtPosition(int x, int y, bool selectCells);
244 
253  vtkIdType pickAtCursor(bool selectCells);
254 
259  void setInteractor(vtkRenderWindowInteractor* interactor) {
260  m_interactor = interactor;
261  }
262 
266  vtkRenderWindowInteractor* getInteractor() const { return m_interactor; }
267 
272  void setRenderer(vtkRenderer* renderer) { m_renderer = renderer; }
273 
277  vtkRenderer* getPickingRenderer() const { return m_renderer; }
278 
284  void setPickerTolerance(double cellTolerance, double pointTolerance);
285 
296  vtkActor* getPickedActor(bool selectCells);
297 
306  vtkPolyData* getPickedPolyData(bool selectCells);
307 
315  bool getPickedPosition(bool selectCells, double position[3]);
316 
327  cvSelectionData createSelectionFromPick(vtkIdType pickedId,
328  bool selectCells);
329 
341  cvSelectionData applySelectionModifierUnified(
342  const cvSelectionData& newSelection,
343  const cvSelectionData& currentSelection,
344  int modifier,
345  int fieldAssociation);
346 
348 
349 private:
354  vtkHardwareSelector* getHardwareSelector();
355 
362  vtkHardwareSelector* configureHardwareSelector(const int region[4],
363  int fieldAssociation);
364 
368  QVector<cvActorSelectionInfo> extractActorInfo(
369  vtkHardwareSelector* selector, vtkSelection* vtkSel);
370 
374  cvSelectionData convertSelection(
375  vtkSelection* vtkSel,
376  const QVector<cvActorSelectionInfo>& actorInfos);
377 
381  cvSelectionData applyModifier(const cvSelectionData& newSelection,
382  const cvSelectionData& currentSelection,
383  SelectionModifier modifier);
384 
388  vtkRenderer* getRenderer();
389 
390 protected:
391  // Note: m_viewer is inherited from cvSelectionBase
392 
395 
399  vtkRenderWindowInteractor* m_interactor;
400  vtkRenderer* m_renderer;
401 
409 };
cvSelectionData::addActorInfo
void addActorInfo(const cvActorSelectionInfo &info)
Actor/Representation information (ParaView-style)
Definition: cvSelectionData.cpp:148
SelectionModifier::SELECTION_SUBTRACTION
@ SELECTION_SUBTRACTION
Subtract from selection (Shift)
cvGenericSelectionTool::getPolyDataForSelection
vtkPolyData * getPolyDataForSelection(const cvSelectionData *selectionData=nullptr) override
Get polyData for a selection using ParaView-style priority (override)
Definition: cvGenericSelectionTool.cpp:64
cvGenericSelectionTool::initializePickers
void initializePickers()
Software picking methods (unified from subclasses)
Definition: cvGenericSelectionTool.cpp:553
cvGenericSelectionTool::setCaptureZValues
void setCaptureZValues(bool capture)
Set whether to capture Z-buffer values.
Definition: cvGenericSelectionTool.h:196
cvGenericSelectionTool::cvGenericSelectionTool
cvGenericSelectionTool()
Definition: cvGenericSelectionTool.h:61
cvGenericSelectionTool::getActorsAtPoint
QVector< cvActorSelectionInfo > getActorsAtPoint(int x, int y)
Get all actors at a screen location (without full selection)
Definition: cvGenericSelectionTool.cpp:245
QtCompat.h
cvSelectionData::actorCount
int actorCount() const
Get number of actors in this selection.
Definition: cvSelectionData.h:248
x
normal_z x
Definition: my_point_types.h:165
SelectionMode::SELECT_FRUSTUM_POINTS
@ SELECT_FRUSTUM_POINTS
Select points in frustum.
cvSelectionData::hasActorInfo
bool hasActorInfo() const
Check if actor information is available.
Definition: cvSelectionData.h:253
cvGenericSelectionTool::pickAtPosition
vtkIdType pickAtPosition(int x, int y, bool selectCells)
Pick element at screen position.
Definition: cvGenericSelectionTool.cpp:568
SelectionModifier
SelectionModifier
Selection modifiers for combining selections.
Definition: cvSelectionData.h:80
cvSelectionData::fieldAssociation
FieldAssociation fieldAssociation() const
Get field association.
Definition: cvSelectionData.h:193
cvActorSelectionInfo::blockIndex
unsigned int blockIndex
Block index for composite datasets.
Definition: cvSelectionData.h:114
qSetFromVector
QSet< T > qSetFromVector(const QVector< T > &vec)
Definition: QtCompat.h:1073
cvSelectionPipeline::FRUSTUM_CELLS
@ FRUSTUM_CELLS
Frustum cells.
Definition: cvSelectionPipeline.h:63
CVLog::PrintVerbose
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
Definition: CVLog.cpp:103
cvGenericSelectionTool::SelectionMode
::SelectionMode SelectionMode
Selection mode Now using global SelectionMode enum from cvSelectionTypes.h.
Definition: cvGenericSelectionTool.h:53
position
math::float3 position
Definition: LineSetBuffers.cpp:44
PclUtils::PCLVis::getCurrentRenderer
vtkRenderer * getCurrentRenderer(int viewport=0)
Definition: PCLVis.cpp:2924
cvSelectionPipeline::FieldAssociation
FieldAssociation
Field association type.
Definition: cvSelectionPipeline.h:72
CVLog.h
cvSelectionPipeline::SelectionType
SelectionType
Selection type.
Definition: cvSelectionPipeline.h:60
vtkSmartPointer< vtkSelection >
cvGenericSelectionTool::m_renderer
vtkRenderer * m_renderer
Renderer (weak pointer)
Definition: cvGenericSelectionTool.h:400
cvSelectionPipeline::FRUSTUM_POINTS
@ FRUSTUM_POINTS
Frustum points.
Definition: cvSelectionPipeline.h:64
cvSelectionBase::getPCLVis
PclUtils::PCLVis * getPCLVis() const
Get PCLVis instance (for VTK-specific operations)
Definition: cvSelectionBase.cpp:33
cvGenericSelectionTool::setMultipleSelectionMode
void setMultipleSelectionMode(bool enable)
Enable/disable multi-selection mode.
Definition: cvGenericSelectionTool.h:202
cvSelectionBase::getPolyDataForSelection
virtual vtkPolyData * getPolyDataForSelection(const cvSelectionData *selectionData=nullptr)
Get polyData using ParaView-style priority (centralized method)
Definition: cvSelectionBase.cpp:72
result
core::Tensor result
Definition: VtkUtils.cpp:76
cvGenericSelectionTool::setRenderer
void setRenderer(vtkRenderer *renderer)
Set the renderer for picking.
Definition: cvGenericSelectionTool.h:272
SelectionModifier::SELECTION_ADDITION
@ SELECTION_ADDITION
Add to selection (Ctrl)
cvGenericSelectionTool::setUseHardwareSelection
void setUseHardwareSelection(bool enable)
Hardware selection configuration.
Definition: cvGenericSelectionTool.h:183
cvGenericSelectionTool::multipleSelectionMode
bool multipleSelectionMode() const
Check if multi-selection is enabled.
Definition: cvGenericSelectionTool.h:209
cvSelectionPipeline::CombineOperation
CombineOperation
Selection combination methods (ParaView-style)
Definition: cvSelectionPipeline.h:389
cvGenericSelectionTool::pickAtCursor
vtkIdType pickAtCursor(bool selectCells)
Pick element at current cursor position.
Definition: cvGenericSelectionTool.cpp:619
cvGenericSelectionTool::m_useHardwareSelection
bool m_useHardwareSelection
Hardware selection components (reused for performance)
Definition: cvGenericSelectionTool.h:403
cvSelectionBase.h
y
normal_z y
Definition: my_point_types.h:168
cvActorSelectionInfo::zValue
double zValue
Z-buffer depth value (for front-to-back ordering)
Definition: cvSelectionData.h:112
cvActorSelectionInfo::propId
int propId
Unique prop ID (from hardware selector)
Definition: cvSelectionData.h:113
SelectionMode::SELECT_SURFACE_CELLS
@ SELECT_SURFACE_CELLS
Select cells on surface (rectangle)
cvGenericSelectionTool::getSelectionManager
cvViewSelectionManager * getSelectionManager() const
Get the selection manager.
Definition: cvGenericSelectionTool.h:84
cvSelectionPipeline::OPERATION_ADDITION
@ OPERATION_ADDITION
Union (sel1 | sel2)
Definition: cvSelectionPipeline.h:391
cvSelectionData::isEmpty
bool isEmpty() const
Check if selection is empty.
Definition: cvSelectionData.cpp:114
SelectionModifier::SELECTION_DEFAULT
@ SELECTION_DEFAULT
Replace selection (default)
cvGenericSelectionTool::setSelectionManager
void setSelectionManager(cvViewSelectionManager *manager)
Set the selection manager (to access pipeline)
Definition: cvGenericSelectionTool.h:76
cvSelectionData::actorInfo
cvActorSelectionInfo actorInfo(int index=0) const
Get actor info at index.
Definition: cvSelectionData.cpp:173
cvSelectionData::CELLS
@ CELLS
Selection applies to cells.
Definition: cvSelectionData.h:142
cvSelectionPipeline::executeRectangleSelection
vtkSmartPointer< vtkSelection > executeRectangleSelection(int region[4], SelectionType type)
Execute a rectangular selection.
Definition: cvSelectionPipeline.cpp:94
cvGenericSelectionTool.h
cvViewSelectionManager.h
cvGenericSelectionTool::getInteractor
vtkRenderWindowInteractor * getInteractor() const
Get the interactor.
Definition: cvGenericSelectionTool.h:266
cvSelectionPipeline
Selection pipeline abstraction layer.
Definition: cvSelectionPipeline.h:53
cvGenericSelectionTool::m_interactor
vtkRenderWindowInteractor * m_interactor
Interactor (weak pointer)
Definition: cvGenericSelectionTool.h:399
cvSelectionPipeline::FIELD_ASSOCIATION_CELLS
@ FIELD_ASSOCIATION_CELLS
Definition: cvSelectionPipeline.h:73
cvViewSelectionManager
Central manager for all selection operations in the view.
Definition: cvViewSelectionManager.h:52
cvSelectionPipeline::combineSelections
static cvSelectionData combineSelections(const cvSelectionData &sel1, const cvSelectionData &sel2, CombineOperation operation)
Combine two selections.
Definition: cvSelectionPipeline.cpp:983
cvSelectionData::count
int count() const
Get number of selected items.
Definition: cvSelectionData.cpp:119
cvActorSelectionInfo::polyData
vtkPolyData * polyData
The associated polyData (weak pointer)
Definition: cvSelectionData.h:111
cvViewSelectionManager::getPipeline
cvSelectionPipeline * getPipeline()
Get the selection pipeline.
Definition: cvViewSelectionManager.h:214
cvGenericSelectionTool::hardwareSelectAtPoint
cvSelectionData hardwareSelectAtPoint(int x, int y, SelectionMode mode=SelectionMode::SELECT_SURFACE_CELLS, SelectionModifier modifier=SelectionModifier::SELECTION_DEFAULT)
Hardware-accelerated selection (ParaView-aligned)
Definition: cvGenericSelectionTool.cpp:97
cvGenericSelectionTool
Base class for selection tools with picking capabilities.
Definition: cvGenericSelectionTool.h:47
a
a[190]
Definition: essential_matrix_poly.h:19
cvGenericSelectionTool::m_hardwareSelector
vtkSmartPointer< vtkHardwareSelector > m_hardwareSelector
Hardware selector (reused)
Definition: cvGenericSelectionTool.h:408
cvGenericSelectionTool::m_manager
cvViewSelectionManager * m_manager
Manager reference (for pipeline access)
Definition: cvGenericSelectionTool.h:394
SelectionModifier::SELECTION_TOGGLE
@ SELECTION_TOGGLE
Toggle selection (Ctrl+Shift)
cvGenericSelectionTool::getPickedPosition
bool getPickedPosition(bool selectCells, double position[3])
Get pick position in world coordinates.
Definition: cvGenericSelectionTool.cpp:687
cvSelectionData::ids
QVector< qint64 > ids() const
Get selected IDs as a vector (copy)
Definition: cvSelectionData.cpp:124
cvGenericSelectionTool::getPickedActor
vtkActor * getPickedActor(bool selectCells)
Get the last picked actor.
Definition: cvGenericSelectionTool.cpp:649
cvGenericSelectionTool::useHardwareSelection
bool useHardwareSelection() const
Check if hardware selection is enabled.
Definition: cvGenericSelectionTool.h:190
cvSelectionData::POINTS
@ POINTS
Selection applies to points.
Definition: cvSelectionData.h:143
cvGenericSelectionTool::setPickerTolerance
void setPickerTolerance(double cellTolerance, double pointTolerance)
Set picker tolerance.
Definition: cvGenericSelectionTool.cpp:631
cvSelectionBase::hasValidPCLVis
bool hasValidPCLVis() const
Check if visualizer is valid and is PCLVis.
Definition: cvSelectionBase.cpp:41
cvGenericSelectionTool::m_pointPicker
vtkSmartPointer< vtkPointPicker > m_pointPicker
Point picker.
Definition: cvGenericSelectionTool.h:398
cvSelectionPipeline::convertToCvSelectionData
static cvSelectionData convertToCvSelectionData(vtkSelection *selection, FieldAssociation fieldAssociation)
Convert vtkSelection to cvSelectionData with actor info (ParaView-style)
Definition: cvSelectionPipeline.cpp:804
cvSelectionPipeline::OPERATION_TOGGLE
@ OPERATION_TOGGLE
XOR (sel1 ^ sel2)
Definition: cvSelectionPipeline.h:393
cvSelectionPipeline::OPERATION_DEFAULT
@ OPERATION_DEFAULT
Replace (sel2 only)
Definition: cvSelectionPipeline.h:390
cvGenericSelectionTool::getPickingRenderer
vtkRenderer * getPickingRenderer() const
Get the renderer (for picking)
Definition: cvGenericSelectionTool.h:277
PCLVis.h
cvSelectionData
Encapsulates selection data without exposing VTK types.
Definition: cvSelectionData.h:136
CVLog::Warning
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
cvSelectionBase
Lightweight base class for all selection-related components.
Definition: cvSelectionBase.h:44
QPCL_ENGINE_LIB_API
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
cvGenericSelectionTool::hardwareSelectInRegion
cvSelectionData hardwareSelectInRegion(const int region[4], SelectionMode mode=SelectionMode::SELECT_SURFACE_CELLS, SelectionModifier modifier=SelectionModifier::SELECTION_DEFAULT)
Perform hardware selection in a region.
Definition: cvGenericSelectionTool.cpp:104
SelectionMode::SELECT_FRUSTUM_CELLS
@ SELECT_FRUSTUM_CELLS
Select cells in frustum.
cvGenericSelectionTool::m_currentSelection
cvSelectionData m_currentSelection
Current selection (for modifiers)
Definition: cvGenericSelectionTool.h:406
cvGenericSelectionTool::getPickedPolyData
vtkPolyData * getPickedPolyData(bool selectCells)
Get the last picked polyData.
Definition: cvGenericSelectionTool.cpp:659
SelectionMode
SelectionMode
Selection modes matching ParaView's SelectionMode enum.
Definition: cvSelectionData.h:36
cvGenericSelectionTool::m_captureZValues
bool m_captureZValues
Capture Z-buffer values.
Definition: cvGenericSelectionTool.h:404
qVectorFromSet
QVector< T > qVectorFromSet(const QSet< T > &set)
Definition: QtCompat.h:1078
cvSelectionPipeline::OPERATION_SUBTRACTION
@ OPERATION_SUBTRACTION
Difference (sel1 & !sel2)
Definition: cvSelectionPipeline.h:392
cvSelectionData.h
cvGenericSelectionTool::m_multipleSelectionMode
bool m_multipleSelectionMode
Allow multiple selections.
Definition: cvGenericSelectionTool.h:405
cvSelectionPipeline::SURFACE_CELLS
@ SURFACE_CELLS
Surface cells (rectangle)
Definition: cvSelectionPipeline.h:61
cvGenericSelectionTool::SelectionModifier
::SelectionModifier SelectionModifier
Selection modifier (for multi-selection) Now using global SelectionModifier enum from cvSelectionType...
Definition: cvGenericSelectionTool.h:59
cvSelectionData::FieldAssociation
FieldAssociation
Field association for selection.
Definition: cvSelectionData.h:141
PclUtils::PCLVis
Definition: PCLVis.h:80
SelectionMode::SELECT_SURFACE_POINTS
@ SELECT_SURFACE_POINTS
Select points on surface (rectangle)
cvSelectionData::primaryPolyData
vtkPolyData * primaryPolyData() const
Get the primary (front-most) polyData.
Definition: cvSelectionData.cpp:186
cvSelectionPipeline::SURFACE_POINTS
@ SURFACE_POINTS
Surface points (rectangle)
Definition: cvSelectionPipeline.h:62
cvGenericSelectionTool::m_cellPicker
vtkSmartPointer< vtkCellPicker > m_cellPicker
Software picking components (unified from subclasses)
Definition: cvGenericSelectionTool.h:397
cvSelectionPipeline::FIELD_ASSOCIATION_POINTS
@ FIELD_ASSOCIATION_POINTS
Definition: cvSelectionPipeline.h:74
cvGenericSelectionTool::setInteractor
void setInteractor(vtkRenderWindowInteractor *interactor)
Set the interactor for picking.
Definition: cvGenericSelectionTool.h:259
cvActorSelectionInfo
Information about a selected actor/representation.
Definition: cvSelectionData.h:109
cvActorSelectionInfo::actor
vtkActor * actor
The selected actor (weak pointer)
Definition: cvSelectionData.h:110
cvGenericSelectionTool::createSelectionFromPick
cvSelectionData createSelectionFromPick(vtkIdType pickedId, bool selectCells)
Create cvSelectionData from software picking result.
Definition: cvGenericSelectionTool.cpp:700
cvGenericSelectionTool::applySelectionModifierUnified
cvSelectionData applySelectionModifierUnified(const cvSelectionData &newSelection, const cvSelectionData &currentSelection, int modifier, int fieldAssociation)
Apply selection modifier to combine selections.
Definition: cvGenericSelectionTool.cpp:746
cvGenericSelectionTool::getSelectionPipeline
cvSelectionPipeline * getSelectionPipeline() const
Get the selection pipeline from manager.
Definition: cvGenericSelectionTool.cpp:56
cvSelectionPipeline.h