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,
117  PRESELECTED,
119  SELECTED,
121  BOUNDARY
123  };
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 
380  void propertiesChanged();
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];
426  double m_preselectedColor[3];
428  double m_selectedColor[3];
430  double m_boundaryColor[3];
432 
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;
464  QString m_cellLabelArrayName;
466  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 };
ecvGenericVisualizer3D.h
cvSelectionHighlighter::labelPropertiesChanged
void labelPropertiesChanged(bool interactive)
Emitted when label properties change.
SelectionLabelProperties::cellLabelBold
bool cellLabelBold
Definition: cvSelectionHighlighter.h:59
cvGenericSelectionTool::getPolyDataForSelection
vtkPolyData * getPolyDataForSelection(const cvSelectionData *selectionData=nullptr) override
Get polyData for a selection using ParaView-style priority (override)
Definition: cvGenericSelectionTool.cpp:64
cvTooltipFormatter::~cvTooltipFormatter
~cvTooltipFormatter()
Destructor.
Definition: cvSelectionHighlighter.cpp:1250
cvSelectionHighlighter::opacityChanged
void opacityChanged(int mode)
Emitted when any opacity changes.
cvSelectionHighlighter::setHighlightOpacity
void setHighlightOpacity(double opacity, HighlightMode mode=SELECTED)
Set highlight opacity.
Definition: cvSelectionHighlighter.cpp:171
QtCompat.h
normal
double normal[3]
Definition: FileIOFactory.cpp:53
cvSelectionHighlighter::highlightSelection
bool highlightSelection(const vtkSmartPointer< vtkIdTypeArray > &selection, int fieldAssociation, HighlightMode mode=SELECTED)
Highlight selected elements (automatically gets polyData from visualizer)
Definition: cvSelectionHighlighter.cpp:268
cvSelectionData::fieldAssociation
FieldAssociation fieldAssociation() const
Get field association.
Definition: cvSelectionData.h:193
cvSelectionHighlighter::HighlightMode
HighlightMode
Highlight mode (Enhanced multi-level highlighting)
Definition: cvSelectionHighlighter.h:115
data
GraphType data
Definition: graph_cut.cc:138
CVLog::PrintVerbose
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
Definition: CVLog.cpp:103
SelectionLabelProperties::cellLabelFontSize
int cellLabelFontSize
Definition: cvSelectionHighlighter.h:56
PclUtils::PCLVis::getCurrentRenderer
vtkRenderer * getCurrentRenderer(int viewport=0)
Definition: PCLVis.cpp:2924
signals
#define signals
Definition: PythonPlugin.cpp:26
cvSelectionHighlighter::SELECTED
@ SELECTED
Definition: cvSelectionHighlighter.h:120
SelectionLabelProperties::maxTooltipAttributes
int maxTooltipAttributes
Definition: cvSelectionHighlighter.h:82
cvSelectionHighlighter::clearHoverHighlight
void clearHoverHighlight()
Clear only hover highlight (keep selected/preselected)
Definition: cvSelectionHighlighter.cpp:452
CVLog.h
cvSelectionHighlighter::setLineWidth
void setLineWidth(int width, HighlightMode mode=SELECTED)
Set line width for highlight rendering.
Definition: cvSelectionHighlighter.cpp:856
QtCompatRegExp
QRegularExpression QtCompatRegExp
Definition: QtCompat.h:170
vtkSmartPointer< vtkActor >
PclUtils
Definition: CustomContextItem.cpp:18
color
math::float4 color
Definition: LineSetBuffers.cpp:46
cvSelectionHighlighter::getPointLabelArrayName
QString getPointLabelArrayName() const
Get current point label array name.
Definition: cvSelectionHighlighter.h:315
cvSelectionBase::getPCLVis
PclUtils::PCLVis * getPCLVis() const
Get PCLVis instance (for VTK-specific operations)
Definition: cvSelectionBase.cpp:33
cvSelectionHighlighter::lineWidthChanged
void lineWidthChanged(int mode)
Emitted when line width changes.
result
core::Tensor result
Definition: VtkUtils.cpp:76
cvTooltipFormatter
Formatter class for generating tooltip text from VTK data.
Definition: cvSelectionHighlighter.h:494
width
int width
Definition: FileIOFactory.cpp:142
QtCompatRegExpOption::CaseInsensitive
constexpr QRegularExpression::PatternOption CaseInsensitive
Definition: QtCompat.h:174
CVLog::Error
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
qPCL.h
size
int size
Definition: FileIOFactory.cpp:130
cvTooltipFormatter::AssociationType
AssociationType
Element association type.
Definition: cvSelectionHighlighter.h:499
cvSelectionHighlighter::pointSizeChanged
void pointSizeChanged(int mode)
Emitted when point size changes.
cvSelectionHighlighter::isPointLabelVisible
bool isPointLabelVisible() const
Check if point labels are visible.
Definition: cvSelectionHighlighter.h:325
cvSelectionHighlighter::highlightElement
bool highlightElement(vtkPolyData *polyData, vtkIdType elementId, int fieldAssociation)
Highlight a single element (for hover preview)
Definition: cvSelectionHighlighter.cpp:394
SelectionLabelProperties::pointLabelBold
bool pointLabelBold
Definition: cvSelectionHighlighter.h:73
cvSelectionData::isEmpty
bool isEmpty() const
Check if selection is empty.
Definition: cvSelectionData.cpp:114
cvSelectionHighlighter::getHighlightQColor
QColor getHighlightQColor(HighlightMode mode) const
Get highlight color as QColor.
Definition: cvSelectionHighlighter.cpp:1218
SelectionLabelProperties::pointLabelOpacity
double pointLabelOpacity
Definition: cvSelectionHighlighter.h:72
cvSelectionHighlighter::getCellLabelArrayName
QString getCellLabelArrayName() const
Get current cell label array name.
Definition: cvSelectionHighlighter.h:320
scalar
normal_z scalar
Definition: my_point_types.h:169
cvSelectionHighlighter::clearHighlights
void clearHighlights()
Clear all highlights.
Definition: cvSelectionHighlighter.cpp:430
cvGenericSelectionTool.h
SelectionLabelProperties::lineWidth
int lineWidth
Definition: cvSelectionHighlighter.h:50
SelectionLabelProperties::pointLabelItalic
bool pointLabelItalic
Definition: cvSelectionHighlighter.h:74
cvSelectionHighlighter::PRESELECTED
@ PRESELECTED
Definition: cvSelectionHighlighter.h:118
cvSelectionHighlighter::HOVER
@ HOVER
Definition: cvSelectionHighlighter.h:116
SelectionLabelProperties::opacity
double opacity
Definition: cvSelectionHighlighter.h:48
cvSelectionHighlighter::setHighlightQColor
void setHighlightQColor(const QColor &color, HighlightMode mode=SELECTED)
Set highlight color from QColor.
Definition: cvSelectionHighlighter.cpp:1227
cvSelectionData::count
int count() const
Get number of selected items.
Definition: cvSelectionData.cpp:119
cvSelectionHighlighter::getLineWidth
int getLineWidth(HighlightMode mode) const
Get line width for a specific mode.
Definition: cvSelectionHighlighter.cpp:901
cvSelectionHighlighter::propertiesChanged
void propertiesChanged()
Emitted when any property changes (general notification)
SelectionLabelProperties::cellLabelOpacity
double cellLabelOpacity
Definition: cvSelectionHighlighter.h:58
SelectionLabelProperties::pointLabelColor
QColor pointLabelColor
Definition: cvSelectionHighlighter.h:71
cvGenericSelectionTool
Base class for selection tools with picking capabilities.
Definition: cvGenericSelectionTool.h:47
SelectionLabelProperties::pointLabelFontSize
int pointLabelFontSize
Definition: cvSelectionHighlighter.h:70
cvSelectionHighlighter::isCellLabelVisible
bool isCellLabelVisible() const
Check if cell labels are visible.
Definition: cvSelectionHighlighter.h:330
cvSelectionHighlighter::setLabelProperties
void setLabelProperties(const SelectionLabelProperties &props, bool interactive=false)
Set label properties for selection mode.
Definition: cvSelectionHighlighter.cpp:923
SelectionLabelProperties::cellLabelShadow
bool cellLabelShadow
Definition: cvSelectionHighlighter.h:61
cvSelectionHighlighter::setEnabled
void setEnabled(bool enabled)
Enable/disable highlight.
Definition: cvSelectionHighlighter.cpp:260
cvSelectionHighlighter::getPointSize
int getPointSize(HighlightMode mode) const
Get point size for a specific mode.
Definition: cvSelectionHighlighter.cpp:840
cvSelectionData::fieldTypeString
QString fieldTypeString() const
Get human-readable field type string.
Definition: cvSelectionData.cpp:143
SelectionLabelProperties::pointSize
int pointSize
Definition: cvSelectionHighlighter.h:49
cvSelectionHighlighter::setPointLabelArray
void setPointLabelArray(const QString &arrayName, bool visible=true)
Set the point label array name.
Definition: cvSelectionHighlighter.cpp:984
cvSelectionHighlighter::getHighlightOpacity
double getHighlightOpacity(HighlightMode mode) const
Get highlight opacity for a specific mode.
Definition: cvSelectionHighlighter.cpp:244
cvSelectionHighlighter::setPointSize
void setPointSize(int size, HighlightMode mode=SELECTED)
Set point size for highlight rendering.
Definition: cvSelectionHighlighter.cpp:795
cvSelectionHighlighter::~cvSelectionHighlighter
~cvSelectionHighlighter()
Destructor.
Definition: cvSelectionHighlighter.cpp:100
cvTooltipFormatter::POINTS
@ POINTS
Definition: cvSelectionHighlighter.h:499
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
QPCL_ENGINE_LIB_API
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
cvTooltipFormatter::getTooltipInfo
QString getTooltipInfo(vtkPolyData *polyData, vtkIdType elementId, AssociationType association, const QString &datasetName=QString())
Generate tooltip information for a selected element.
Definition: cvSelectionHighlighter.cpp:1258
cvSelectionHighlighter::setHighlightColor
void setHighlightColor(double r, double g, double b, HighlightMode mode=SELECTED)
Set highlight color.
Definition: cvSelectionHighlighter.cpp:105
cvSelectionHighlighter.h
cvSelectionHighlighter::setCellLabelArray
void setCellLabelArray(const QString &arrayName, bool visible=true)
Set the cell label array name.
Definition: cvSelectionHighlighter.cpp:1003
cvTooltipFormatter::getPlainTooltipInfo
QString getPlainTooltipInfo(vtkPolyData *polyData, vtkIdType elementId, AssociationType association, const QString &datasetName=QString())
Generate plain text tooltip (no HTML formatting)
Definition: cvSelectionHighlighter.cpp:1275
cvTooltipFormatter::setMaxAttributes
void setMaxAttributes(int maxAttribs)
Set maximum number of attributes to display.
Definition: cvSelectionHighlighter.cpp:1253
cvSelectionHighlighter::colorChanged
void colorChanged(int mode)
Emitted when any highlight color changes.
cvSelectionData::vtkArray
vtkSmartPointer< vtkIdTypeArray > vtkArray() const
Get the underlying VTK array (for internal use only)
Definition: cvSelectionData.h:204
cvSelectionData.h
cvSelectionHighlighter::setHighlightsVisible
void setHighlightsVisible(bool visible)
Set visibility of all highlight actors.
Definition: cvSelectionHighlighter.cpp:460
SelectionLabelProperties::cellLabelItalic
bool cellLabelItalic
Definition: cvSelectionHighlighter.h:60
cvSelectionHighlighter::getHighlightColor
const double * getHighlightColor(HighlightMode mode) const
Get highlight color for a specific mode.
Definition: cvSelectionHighlighter.cpp:227
cvSelectionHighlighter::cvSelectionHighlighter
cvSelectionHighlighter()
Constructor.
Definition: cvSelectionHighlighter.cpp:45
cvSelectionBase::m_viewer
ecvGenericVisualizer3D * m_viewer
Visualizer instance (abstract interface)
Definition: cvSelectionBase.h:129
SelectionLabelProperties
Label properties for selection annotations.
Definition: cvSelectionHighlighter.h:46
PclUtils::PCLVis
Definition: PCLVis.h:80
SelectionLabelProperties::cellLabelColor
QColor cellLabelColor
Definition: cvSelectionHighlighter.h:57
cvSelectionHighlighter
Helper class for highlighting selected elements in the visualizer.
Definition: cvSelectionHighlighter.h:101
cvSelectionHighlighter::getLabelProperties
const SelectionLabelProperties & getLabelProperties(bool interactive=false) const
Get label properties for selection mode.
Definition: cvSelectionHighlighter.cpp:917
SelectionLabelProperties::pointLabelShadow
bool pointLabelShadow
Definition: cvSelectionHighlighter.h:75
cvTooltipFormatter::cvTooltipFormatter
cvTooltipFormatter()
Constructor.
Definition: cvSelectionHighlighter.cpp:1247
name
std::string name
Definition: FileIOFactory.cpp:129
cvSelectionHighlighter::BOUNDARY
@ BOUNDARY
Definition: cvSelectionHighlighter.h:122