ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvSelectionHighlighter.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 "qPCL.h"
11 
12 // LOCAL
13 #include "cvGenericSelectionTool.h"
14 #include "cvSelectionData.h"
15 
16 // Qt
17 #include <QColor>
18 #include <QObject>
19 #include <QString>
20 
21 // VTK
22 #include <vtkActor.h> // Full definition needed for vtkSmartPointer<vtkActor>
23 #include <vtkSmartPointer.h>
24 class vtkIdTypeArray;
25 class vtkPolyData;
26 class vtkDataArray;
27 class vtkFieldData;
28 class vtkDataSetMapper;
29 class vtkExtractSelection;
30 class vtkSelection;
31 class vtkSelectionNode;
32 class vtkRenderer;
33 class vtkActor2D;
34 class vtkLabeledDataMapper;
35 
36 namespace PclUtils {
37 class PCLVis;
38 }
39 
47  // General (ParaView defaults from VTK/Rendering/Core/vtkProperty.h)
48  double opacity = 1.0;
49  int pointSize = 5; // ParaView default
50  int lineWidth = 2;
51 
52  // Cell Label Font (ParaView defaults from
53  // representations_remotingviews.xml) Line 4468-4521: CellLabelColor
54  // default_values="0.0 1.0 0.0" (Green)
55  QString cellLabelFontFamily = "Arial"; // ParaView: FontFamily = 0 (Arial)
56  int cellLabelFontSize = 18; // ParaView: CellLabelFontSize = 18
57  QColor cellLabelColor = QColor(0, 255, 0); // ParaView: Green (0, 1, 0)
58  double cellLabelOpacity = 1.0;
59  bool cellLabelBold = false; // ParaView: default_values="0"
60  bool cellLabelItalic = false; // ParaView: default_values="0"
61  bool cellLabelShadow = false; // ParaView: default_values="0" (NOT true!)
62  int cellLabelHorizontalJustification = 0; // ParaView: 0=Left
63  int cellLabelVerticalJustification = 0; // ParaView: 0=Bottom
64  QString cellLabelFormat = ""; // ParaView: empty (auto-select format)
65 
66  // Point Label Font (ParaView defaults from
67  // representations_remotingviews.xml) Line 4326-4401: PointLabelColor
68  // default_values="1 1 0" (Yellow)
69  QString pointLabelFontFamily = "Arial"; // ParaView: FontFamily = 0 (Arial)
70  int pointLabelFontSize = 18; // ParaView: PointLabelFontSize = 18
71  QColor pointLabelColor = QColor(255, 255, 0); // ParaView: Yellow (1, 1, 0)
72  double pointLabelOpacity = 1.0;
73  bool pointLabelBold = false; // ParaView: default_values="0"
74  bool pointLabelItalic = false; // ParaView: default_values="0"
75  bool pointLabelShadow = false; // ParaView: default_values="0" (NOT true!)
76  int pointLabelHorizontalJustification = 0; // ParaView: 0=Left
77  int pointLabelVerticalJustification = 0; // ParaView: 0=Bottom
78  QString pointLabelFormat = ""; // ParaView: empty (auto-select format)
79 
80  // Tooltip
81  bool showTooltips = true;
82  int maxTooltipAttributes = 15;
83 };
84 
102  : public QObject,
103  public cvGenericSelectionTool {
104  Q_OBJECT
105 public:
116  HOVER,
118  PRESELECTED,
120  SELECTED,
122  BOUNDARY
124  };
125 
130 
135 
147  bool highlightSelection(const vtkSmartPointer<vtkIdTypeArray>& selection,
148  int fieldAssociation,
149  HighlightMode mode = SELECTED);
150 
161  bool highlightSelection(vtkPolyData* polyData,
162  const vtkSmartPointer<vtkIdTypeArray>& selection,
163  int fieldAssociation,
164  HighlightMode mode = SELECTED);
165 
174  bool highlightSelection(const cvSelectionData& selectionData,
175  HighlightMode mode = SELECTED);
176 
184  bool highlightElement(vtkPolyData* polyData,
185  vtkIdType elementId,
186  int fieldAssociation);
187 
191  void clearHighlights();
192 
197  void clearHoverHighlight();
198 
205  void setHighlightsVisible(bool visible);
206 
214  void setHighlightColor(double r,
215  double g,
216  double b,
217  HighlightMode mode = SELECTED);
218 
224  void setHighlightOpacity(double opacity, HighlightMode mode = SELECTED);
225 
231  const double* getHighlightColor(HighlightMode mode) const;
232 
238  double getHighlightOpacity(HighlightMode mode) const;
239 
245  void setPointSize(int size, HighlightMode mode = SELECTED);
246 
252  int getPointSize(HighlightMode mode) const;
253 
259  void setLineWidth(int width, HighlightMode mode = SELECTED);
260 
266  int getLineWidth(HighlightMode mode) const;
267 
272  void setEnabled(bool enabled);
273 
274  // =========================================================================
275  // Label Properties (Single Source of Truth)
276  // =========================================================================
277 
283  const SelectionLabelProperties& getLabelProperties(
284  bool interactive = false) const;
285 
291  void setLabelProperties(const SelectionLabelProperties& props,
292  bool interactive = false);
293 
294  // =========================================================================
295  // Selection Label Array Methods (ParaView-style)
296  // =========================================================================
297 
303  void setPointLabelArray(const QString& arrayName, bool visible = true);
304 
310  void setCellLabelArray(const QString& arrayName, bool visible = true);
311 
315  QString getPointLabelArrayName() const { return m_pointLabelArrayName; }
316 
320  QString getCellLabelArrayName() const { return m_cellLabelArrayName; }
321 
325  bool isPointLabelVisible() const { return m_pointLabelVisible; }
326 
330  bool isCellLabelVisible() const { return m_cellLabelVisible; }
331 
332  // =========================================================================
333  // QColor convenience methods (for Qt UI components)
334  // =========================================================================
335 
339  QColor getHighlightQColor(HighlightMode mode) const;
340 
344  void setHighlightQColor(const QColor& color, HighlightMode mode = SELECTED);
345 
346 signals:
351  void colorChanged(int mode);
352 
357  void opacityChanged(int mode);
358 
363  void pointSizeChanged(int mode);
364 
369  void lineWidthChanged(int mode);
370 
375  void labelPropertiesChanged(bool interactive);
376 
381 
382 private:
387  vtkSmartPointer<vtkActor> createHighlightActor(vtkPolyData* polyData,
388  vtkIdTypeArray* selection,
389  int fieldAssociation,
390  HighlightMode mode);
391 
396  vtkSmartPointer<vtkSelectionNode> createSelectionNode(
397  vtkIdTypeArray* selection, int fieldAssociation);
398 
402  void addActorToVisualizer(vtkActor* actor, const QString& id);
403 
407  void removeActorFromVisualizer(const QString& id);
408 
413  void updateLabelActor(bool isPointLabels);
414 
415  // m_viewer is inherited from cvGenericSelectionTool
416 
417  // Highlight actors (ParaView-style multi-level)
418  vtkSmartPointer<vtkActor> m_hoverActor;
419  vtkSmartPointer<vtkActor> m_preselectedActor;
420  vtkSmartPointer<vtkActor> m_selectedActor;
421  vtkSmartPointer<vtkActor> m_boundaryActor;
422 
423  // Colors for different modes (Enhanced for maximum visibility)
424  // Using bright, highly saturated colors that stand out
425  double m_hoverColor[3];
427  double m_preselectedColor[3];
429  double m_selectedColor[3];
431  double m_boundaryColor[3];
433 
434  // Opacities (Enhanced for maximum visibility)
435  double m_hoverOpacity;
436  double m_preselectedOpacity;
437  double m_selectedOpacity;
438  double m_boundaryOpacity;
439 
440  // Point sizes for different modes
441  int m_hoverPointSize;
442  int m_preselectedPointSize;
443  int m_selectedPointSize;
444  int m_boundaryPointSize;
445 
446  // Line widths for different modes
447  int m_hoverLineWidth;
448  int m_preselectedLineWidth;
449  int m_selectedLineWidth;
450  int m_boundaryLineWidth;
451 
452  bool m_enabled;
453  QString m_hoverActorId;
454  QString m_preselectedActorId;
455  QString m_selectedActorId;
456  QString m_boundaryActorId;
457 
458  // Label properties (single source of truth)
459  SelectionLabelProperties m_labelProperties;
460  SelectionLabelProperties m_interactiveLabelProperties;
461 
462  // Label array names for displaying on selected elements
463  QString m_pointLabelArrayName;
465  QString m_cellLabelArrayName;
467  bool m_pointLabelVisible;
468  bool m_cellLabelVisible;
469 
470  // Label actors for rendering labels on selected elements
471  vtkSmartPointer<vtkActor2D> m_pointLabelActor;
472  vtkSmartPointer<vtkActor2D> m_cellLabelActor;
474  m_lastSelectionPolyData;
475 };
476 
477 //=============================================================================
478 // Tooltip Formatter (merged from cvTooltipFormatter.h)
479 //=============================================================================
480 
495 public:
499  enum AssociationType { POINTS = 1, CELLS = 0 };
500 
505 
510 
519  QString getTooltipInfo(vtkPolyData* polyData,
520  vtkIdType elementId,
521  AssociationType association,
522  const QString& datasetName = QString());
523 
532  QString getPlainTooltipInfo(vtkPolyData* polyData,
533  vtkIdType elementId,
534  AssociationType association,
535  const QString& datasetName = QString());
536 
541  void setMaxAttributes(int maxAttribs);
542 
543 private:
547  QString formatPointTooltip(vtkPolyData* polyData,
548  vtkIdType pointId,
549  const QString& datasetName);
550 
554  QString formatCellTooltip(vtkPolyData* polyData,
555  vtkIdType cellId,
556  const QString& datasetName);
557 
561  void addArrayValues(QString& tooltip,
562  vtkFieldData* fieldData,
563  vtkIdType tupleIndex);
564 
568  QString formatArrayValue(vtkDataArray* array, vtkIdType tupleIndex);
569 
575  QString formatNumber(double value);
576 
577  int m_maxAttributes;
578 };
int width
int size
math::float4 color
#define signals
Base class for selection tools with picking capabilities.
Encapsulates selection data without exposing VTK types.
Helper class for highlighting selected elements in the visualizer.
QString getCellLabelArrayName() const
Get current cell label array name.
void propertiesChanged()
Emitted when any property changes (general notification)
void colorChanged(int mode)
Emitted when any highlight color changes.
void opacityChanged(int mode)
Emitted when any opacity changes.
void labelPropertiesChanged(bool interactive)
Emitted when label properties change.
HighlightMode
Highlight mode (Enhanced multi-level highlighting)
QString getPointLabelArrayName() const
Get current point label array name.
bool isCellLabelVisible() const
Check if cell labels are visible.
void pointSizeChanged(int mode)
Emitted when point size changes.
bool isPointLabelVisible() const
Check if point labels are visible.
void lineWidthChanged(int mode)
Emitted when line width changes.
Formatter class for generating tooltip text from VTK data.
AssociationType
Element association type.
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
Label properties for selection annotations.