ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvViewSelectionManager.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 // clang-format off
11 // Qt - must be included before qPCL.h for MOC to work correctly
12 #include <QtCore/QMap>
13 #include <QtCore/QObject>
14 // clang-format on
15 
16 // LOCAL
17 #include "cvGenericSelectionTool.h"
18 #include "cvSelectionData.h" // Contains SelectionMode, SelectionModifier enums // For SelectionMode and SelectionModifier enums
19 #include "qPCL.h"
20 
21 // CV_DB_LIB
22 #include <ecvHObject.h>
23 
24 // Forward declarations
25 class cvSelectionData;
26 class cvSelectionAlgebra;
28 class cvSelectionFilter;
31 class vtkIntArray;
32 class vtkIdTypeArray;
33 class vtkPolyData;
34 class ccHObject;
35 class ccPointCloud;
36 class ccMesh;
37 
38 namespace PclUtils {
39 class PCLVis;
40 }
41 
53  : public QObject,
54  public cvGenericSelectionTool {
55  Q_OBJECT
56 
57 public:
58  // SelectionMode and SelectionModifier are now defined in cvSelectionTypes.h
59  // to avoid circular dependency with cvRenderViewSelectionTool
60  // Use type aliases for backward compatibility
63 
68  static cvViewSelectionManager* instance();
69 
77  void setVisualizer(ecvGenericVisualizer3D* viewer) override;
78 
79  // Inherited from cvGenericSelectionTool:
80  // ecvGenericVisualizer3D* getVisualizer() const;
81 
90  void enableSelection(SelectionMode mode);
91 
99  void disableSelection();
100 
104  bool isSelectionActive() const;
105 
110  SelectionMode getCurrentMode() const { return m_currentMode; }
111 
119  void setSelectionModifier(SelectionModifier modifier);
120 
124  SelectionModifier getCurrentModifier() const { return m_currentModifier; }
125 
131  void clearSelection();
132 
139  void clearCurrentSelection();
140 
146  void growSelection();
147 
153  void shrinkSelection();
154 
164  bool isCompatible(SelectionMode mode1, SelectionMode mode2) const;
165 
170  const cvSelectionData& currentSelection() const;
171 
178  void setCurrentSelection(const cvSelectionData& selectionData,
179  bool resetLayers = true);
180 
188  void setCurrentSelection(const vtkSmartPointer<vtkIdTypeArray>& selection,
189  int fieldAssociation,
190  bool resetLayers = true);
191 
196  bool hasSelection() const;
197 
198  //-------------------------------------------------------------------------
199  // Utility module accessors (ParaView-style integration)
200  //-------------------------------------------------------------------------
201 
202  // History (undo/redo) removed - UI not implemented
203 
208  cvSelectionAlgebra* getAlgebra() { return m_algebra; }
209 
214  cvSelectionPipeline* getPipeline() { return m_pipeline; }
215 
220  cvSelectionFilter* getFilter() { return m_filter; }
221 
222  // Bookmarks removed - UI not implemented
223 
228  cvSelectionAnnotationManager* getAnnotations() { return m_annotations; }
229 
238  cvSelectionHighlighter* getHighlighter() { return m_highlighter; }
239 
240  //-------------------------------------------------------------------------
241  // Advanced selection operations (using utility modules)
242  //-------------------------------------------------------------------------
243 
244  // Undo/Redo removed - UI not implemented
245 
253  cvSelectionData performAlgebraOperation(
254  int op,
255  const cvSelectionData& selectionA,
256  const cvSelectionData& selectionB = cvSelectionData());
257 
262  vtkPolyData* getPolyData() const;
263 
273  void setSourceObject(ccHObject* obj);
274 
279  ccHObject* getSourceObject() const;
280 
285  ccPointCloud* getSourcePointCloud() const;
286 
291  ccMesh* getSourceMesh() const;
292 
297  bool isSourceObjectValid() const;
298 
308  void notifyDataUpdated();
309 
318  void setPointPickingRadius(unsigned int radius);
319 
323  unsigned int getPointPickingRadius() const;
324 
326 
336  void setGrowSelectionRemoveSeed(bool remove);
337  bool getGrowSelectionRemoveSeed() const { return m_growRemoveSeed; }
338 
342  void setGrowSelectionRemoveIntermediateLayers(bool remove);
344  return m_growRemoveIntermediateLayers;
345  }
346 
356  void expandSelection(int layers,
357  bool removeSeed = false,
358  bool removeIntermediateLayers = false);
359 
368  bool canShrinkSelection() const { return m_numberOfLayers >= 1; }
369 
375  int getNumberOfLayers() const { return m_numberOfLayers; }
377 
378 signals:
383 
388  void selectionChanged(const cvSelectionData& selectionData);
389 
395 
401 
407 
414  void customBoxSelected(int region[4]);
415  void customBoxSelected(int xmin, int ymin, int xmax, int ymax);
416 
423  void customPolygonSelected(vtkIntArray* polygon);
424 
431  void zoomToBoxRequested(int region[4]);
432  void zoomToBoxRequested(int xmin, int ymin, int xmax, int ymax);
433 
434 private:
435  // Singleton constructor/destructor
436  explicit cvViewSelectionManager(QObject* parent = nullptr);
437  ~cvViewSelectionManager() override;
438 
439  // Disable copy
440  Q_DISABLE_COPY(cvViewSelectionManager)
441 
442  // m_viewer is inherited from cvGenericSelectionTool
443 
444  // Current state
445  SelectionMode m_currentMode;
446  SelectionModifier m_currentModifier;
447  bool m_isActive;
448 
449  // Selection state (encapsulated - no VTK exposure in MainWindow)
450  // Note: Stored as VTK array + field association for backward compatibility
451  // Consider migrating to cvSelectionData in future major version
453  int m_currentSelectionFieldAssociation; // 0=cells, 1=points
454 
455  //-------------------------------------------------------------------------
456  // Utility modules (ParaView-style architecture)
457  //-------------------------------------------------------------------------
458  // Note: m_history and m_bookmarks removed - UI not implemented
460  m_algebra;
461  cvSelectionPipeline* m_pipeline;
462  cvSelectionFilter* m_filter;
463  cvSelectionAnnotationManager* m_annotations;
465  m_highlighter;
466 
467  // Grow selection settings (ParaView-style)
468  bool m_growRemoveSeed = false;
469  bool m_growRemoveIntermediateLayers = false;
470 
471  // Track number of layers for grow/shrink operations (ParaView-style)
472  // This allows us to determine when shrink should be disabled
473  int m_numberOfLayers = 0;
474 
475  // Store the original selection (seed) for ParaView-style grow/shrink
476  // ParaView always expands/shrinks from the original selection, not from the
477  // current one Reference: vtkSelector.cxx line 139-148,
478  // vtkSMSelectionHelper::ExpandSelection
479  cvSelectionData m_originalSelection;
480 
481  // Source object for direct extraction (avoid VTK→ccHObject conversion)
482  // Note: ccHObject is not a QObject, so we use a raw pointer
483  ccHObject* m_sourceObject;
484 };
#define signals
boost::geometry::model::polygon< point_xy > polygon
Definition: TreeIso.cpp:37
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Triangular mesh.
Definition: ecvMesh.h:35
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Base class for selection tools with picking capabilities.
::SelectionMode SelectionMode
Selection mode Now using global SelectionMode enum from cvSelectionTypes.h.
::SelectionModifier SelectionModifier
Selection modifier (for multi-selection) Now using global SelectionModifier enum from cvSelectionType...
cvSelectionData m_currentSelection
Current selection (for modifiers)
Selection algebra operations.
Selection annotation manager.
virtual void setVisualizer(ecvGenericVisualizer3D *viewer)
Set the visualizer instance.
Encapsulates selection data without exposing VTK types.
Advanced selection filtering system.
Helper class for highlighting selected elements in the visualizer.
Selection pipeline abstraction layer.
Central manager for all selection operations in the view.
cvSelectionFilter * getFilter()
Get the selection filter.
bool canShrinkSelection() const
Check if the selection can be shrunk.
cvSelectionAlgebra * getAlgebra()
Get the selection algebra utility.
void customBoxSelected(int region[4])
Emitted for custom box selection.
void customPolygonSelected(vtkIntArray *polygon)
Emitted for custom polygon selection.
void modeChanged(SelectionMode mode)
Emitted when the selection mode changes.
void modifierChanged(SelectionModifier modifier)
Emitted when selection modifier changes.
cvSelectionPipeline * getPipeline()
Get the selection pipeline.
int getNumberOfLayers() const
Get the current number of layers.
void selectionChanged(const cvSelectionData &selectionData)
Emitted when the selection has changed (VTK-independent)
void selectionCompleted()
Emitted when a selection operation is completed.
bool getGrowSelectionRemoveIntermediateLayers() const
void customBoxSelected(int xmin, int ymin, int xmax, int ymax)
SelectionModifier getCurrentModifier() const
Get the current selection modifier.
void zoomToBoxRequested(int xmin, int ymin, int xmax, int ymax)
void zoomToBoxRequested(int region[4])
Emitted for zoom to box.
cvSelectionAnnotationManager * getAnnotations()
Get the annotation manager.
cvSelectionHighlighter * getHighlighter()
Get the shared highlighter.
SelectionMode getCurrentMode() const
Get the current active selection mode.
void selectionChanged()
Emitted when the selection has changed (legacy - for backward compatibility)
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