ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvSelectionAnnotation.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 <QtGui/QColor>
13 #include <QtCore/QDateTime>
14 #include <QtGui/QFont>
15 #include <QtCore/QList>
16 #include <QtCore/QMap>
17 #include <QtCore/QObject>
18 #include <QtCore/QString>
19 // clang-format on
20 
21 #include "qPCL.h"
22 
23 // LOCAL
24 #include "cvSelectionData.h"
25 
26 // Forward declarations
27 class vtkActor2D;
28 class vtkPolyData;
29 class vtkTextActor;
30 namespace PclUtils {
31 class PCLVis;
32 }
33 
34 // Include for LabelProperties struct (nested type requires full definition)
36 
43  QString text;
44  QString id;
45  double position[3];
46  QColor color;
47  int fontSize;
48  QString fontFamily;
49  bool bold;
50  bool italic;
51  bool shadow;
52  double opacity;
55  bool visible;
57  qint64 timestamp;
58 
60  : fontSize(12),
61  fontFamily("Arial"),
62  bold(false),
63  italic(false),
64  shadow(true),
65  opacity(1.0),
66  horizontalJustification("Left"),
67  verticalJustification("Bottom"),
68  visible(true),
69  followSelection(false),
70  timestamp(0) {
71  position[0] = position[1] = position[2] = 0.0;
72  color = Qt::yellow;
73  }
74 
75  cvAnnotation(const QString& txt,
76  const double pos[3],
77  const QString& uid = QString())
78  : text(txt),
79  id(uid.isEmpty()
80  ? QString::number(QDateTime::currentMSecsSinceEpoch())
81  : uid),
82  fontSize(12),
83  fontFamily("Arial"),
84  bold(false),
85  italic(false),
86  shadow(true),
87  opacity(1.0),
88  horizontalJustification("Left"),
89  verticalJustification("Bottom"),
90  visible(true),
91  followSelection(false),
92  timestamp(QDateTime::currentMSecsSinceEpoch()) {
93  position[0] = pos[0];
94  position[1] = pos[1];
95  position[2] = pos[2];
96  color = Qt::yellow;
97  }
98 };
99 
113  Q_OBJECT
114 
115 public:
116  explicit cvSelectionAnnotationManager(QObject* parent = nullptr);
117  ~cvSelectionAnnotationManager() override;
118 
122  void setVisualizer(PclUtils::PCLVis* viewer);
123 
131  QString addAnnotation(const cvSelectionData& selection,
132  const QString& text,
133  bool autoPosition = true);
134 
142  QString addAnnotationAt(const QString& text,
143  const double position[3],
144  const QString& id = QString());
145 
151  bool removeAnnotation(const QString& id);
152 
159  bool updateAnnotationText(const QString& id, const QString& text);
160 
167  bool updateAnnotationPosition(const QString& id, const double position[3]);
168 
175  bool setAnnotationVisible(const QString& id, bool visible);
176 
183  bool setAnnotationColor(const QString& id, const QColor& color);
184 
191  bool setAnnotationFontSize(const QString& id, int fontSize);
192 
200  void applyLabelProperties(
202  bool isCellLabel);
203 
210  void setDefaultLabelProperties(
212  bool isCellLabel);
213 
219  cvAnnotation getAnnotation(const QString& id) const;
220 
224  QList<cvAnnotation> allAnnotations() const;
225 
229  QStringList annotationIds() const;
230 
234  int count() const { return m_annotations.size(); }
235 
239  void clearAll();
240 
244  void showAll();
245 
249  void hideAll();
250 
256  bool exportToFile(const QString& filename) const;
257 
264  bool importFromFile(const QString& filename, bool merge = true);
265 
266 signals:
270  void annotationsChanged();
271 
275  void annotationAdded(const QString& id);
276 
280  void annotationRemoved(const QString& id);
281 
285  void annotationUpdated(const QString& id);
286 
287 private:
288  void createTextActor(const cvAnnotation& annotation);
289  void updateTextActor(const QString& id);
290  void removeTextActor(const QString& id);
291  double* computeSelectionCenter(const cvSelectionData& selection,
292  vtkPolyData* polyData);
293 
300  bool worldToDisplay(const double worldPos[3], double displayPos[2]);
301 
302  PclUtils::PCLVis* m_viewer;
303  QMap<QString, cvAnnotation> m_annotations;
304  QMap<QString, vtkSmartPointer<vtkTextActor>> m_textActors;
305 
306  // Default label properties for new annotations (applied from dialog)
308  cvSelectionLabelPropertiesDialog::LabelProperties m_defaultPointLabelProps;
309 };
filename
std::string filename
Definition: PointCloudIO.cpp:47
cvAnnotation::italic
bool italic
Italic flag.
Definition: cvSelectionAnnotation.h:50
cvSelectionAnnotationManager::hideAll
void hideAll()
Hide all annotations.
Definition: cvSelectionAnnotation.cpp:367
cvSelectionAnnotationManager::applyLabelProperties
void applyLabelProperties(const cvSelectionLabelPropertiesDialog::LabelProperties &props, bool isCellLabel)
Apply label properties to all annotations (for cell or point labels)
Definition: cvSelectionAnnotation.cpp:266
cvSelectionAnnotationManager::count
int count() const
Get annotation count.
Definition: cvSelectionAnnotation.h:234
cvSelectionData::fieldAssociation
FieldAssociation fieldAssociation() const
Get field association.
Definition: cvSelectionData.h:193
data
GraphType data
Definition: graph_cut.cc:138
cvSelectionAnnotationManager::~cvSelectionAnnotationManager
~cvSelectionAnnotationManager() override
Definition: cvSelectionAnnotation.cpp:43
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelFontSize
int pointLabelFontSize
Definition: cvSelectionLabelPropertiesDialog.h:71
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelColor
QColor pointLabelColor
Definition: cvSelectionLabelPropertiesDialog.h:72
CVLog::PrintVerbose
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
Definition: CVLog.cpp:103
position
math::float3 position
Definition: LineSetBuffers.cpp:44
PclUtils::PCLVis::getCurrentRenderer
vtkRenderer * getCurrentRenderer(int viewport=0)
Definition: PCLVis.cpp:2924
signals
#define signals
Definition: PythonPlugin.cpp:26
cvAnnotation::color
QColor color
Text color.
Definition: cvSelectionAnnotation.h:46
cvSelectionAnnotationManager::clearAll
void clearAll()
Clear all annotations.
Definition: cvSelectionAnnotation.cpp:342
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelShadow
bool cellLabelShadow
Definition: cvSelectionLabelPropertiesDialog.h:61
cvSelectionAnnotationManager::removeAnnotation
bool removeAnnotation(const QString &id)
Remove annotation.
Definition: cvSelectionAnnotation.cpp:166
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelHorizontalJustification
QString cellLabelHorizontalJustification
Definition: cvSelectionLabelPropertiesDialog.h:63
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelItalic
bool cellLabelItalic
Definition: cvSelectionLabelPropertiesDialog.h:60
CVLog.h
vtkSmartPointer
Definition: WidgetMap.h:20
PclUtils
Definition: CustomContextItem.cpp:18
cvAnnotation::visible
bool visible
Visibility flag.
Definition: cvSelectionAnnotation.h:55
color
math::float4 color
Definition: LineSetBuffers.cpp:46
cvAnnotation::opacity
double opacity
Text opacity (0.0 to 1.0)
Definition: cvSelectionAnnotation.h:52
cvSelectionLabelPropertiesDialog::LabelProperties
Label properties structure.
Definition: cvSelectionLabelPropertiesDialog.h:49
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelHorizontalJustification
QString pointLabelHorizontalJustification
Definition: cvSelectionLabelPropertiesDialog.h:77
cvAnnotation::cvAnnotation
cvAnnotation(const QString &txt, const double pos[3], const QString &uid=QString())
Definition: cvSelectionAnnotation.h:75
cvAnnotation::timestamp
qint64 timestamp
Creation timestamp.
Definition: cvSelectionAnnotation.h:57
cvSelectionAnnotationManager::setDefaultLabelProperties
void setDefaultLabelProperties(const cvSelectionLabelPropertiesDialog::LabelProperties &props, bool isCellLabel)
Set default label properties for new annotations.
Definition: cvSelectionAnnotation.cpp:305
cvAnnotation::position
double position[3]
3D position
Definition: cvSelectionAnnotation.h:45
cvSelectionAnnotationManager::importFromFile
bool importFromFile(const QString &filename, bool merge=true)
Import annotations from JSON file.
Definition: cvSelectionAnnotation.cpp:439
CVLog::Error
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
cvSelectionAnnotationManager::getAnnotation
cvAnnotation getAnnotation(const QString &id) const
Get annotation.
Definition: cvSelectionAnnotation.cpp:326
cvAnnotation::verticalJustification
QString verticalJustification
"Top", "Center", "Bottom"
Definition: cvSelectionAnnotation.h:54
qPCL.h
cvAnnotation::horizontalJustification
QString horizontalJustification
"Left", "Center", "Right"
Definition: cvSelectionAnnotation.h:53
cvSelectionAnnotationManager::allAnnotations
QList< cvAnnotation > allAnnotations() const
Get all annotations.
Definition: cvSelectionAnnotation.cpp:332
cvAnnotation::followSelection
bool followSelection
Auto-update position with selection.
Definition: cvSelectionAnnotation.h:56
cvAnnotation::shadow
bool shadow
Shadow flag.
Definition: cvSelectionAnnotation.h:51
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelBold
bool pointLabelBold
Definition: cvSelectionLabelPropertiesDialog.h:73
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelFontSize
int cellLabelFontSize
Definition: cvSelectionLabelPropertiesDialog.h:57
cvSelectionAnnotationManager::updateAnnotationPosition
bool updateAnnotationPosition(const QString &id, const double position[3])
Update annotation position.
Definition: cvSelectionAnnotation.cpp:204
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelBold
bool cellLabelBold
Definition: cvSelectionLabelPropertiesDialog.h:59
cvSelectionData::isEmpty
bool isEmpty() const
Check if selection is empty.
Definition: cvSelectionData.cpp:114
ecvColor::yellow
constexpr Rgb yellow(MAX, MAX, 0)
cvAnnotation::fontFamily
QString fontFamily
Font family (e.g., "Arial")
Definition: cvSelectionAnnotation.h:48
cvSelectionAnnotationManager::exportToFile
bool exportToFile(const QString &filename) const
Export annotations to JSON file.
Definition: cvSelectionAnnotation.cpp:377
cvSelectionAnnotationManager::annotationRemoved
void annotationRemoved(const QString &id)
Emitted when annotation is removed.
cvSelectionAnnotationManager::annotationIds
QStringList annotationIds() const
Get annotation IDs.
Definition: cvSelectionAnnotation.cpp:337
cvSelectionAnnotationManager::showAll
void showAll()
Show all annotations.
Definition: cvSelectionAnnotation.cpp:357
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelItalic
bool pointLabelItalic
Definition: cvSelectionLabelPropertiesDialog.h:74
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelShadow
bool pointLabelShadow
Definition: cvSelectionLabelPropertiesDialog.h:75
cvSelectionAnnotationManager::setVisualizer
void setVisualizer(PclUtils::PCLVis *viewer)
Set the visualizer.
Definition: cvSelectionAnnotation.cpp:46
cvSelectionAnnotationManager::updateAnnotationText
bool updateAnnotationText(const QString &id, const QString &text)
Update annotation text.
Definition: cvSelectionAnnotation.cpp:188
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelVerticalJustification
QString pointLabelVerticalJustification
Definition: cvSelectionLabelPropertiesDialog.h:79
cvSelectionData::ids
QVector< qint64 > ids() const
Get selected IDs as a vector (copy)
Definition: cvSelectionData.cpp:124
cvSelectionAnnotationManager::setAnnotationColor
bool setAnnotationColor(const QString &id, const QColor &color)
Set annotation color.
Definition: cvSelectionAnnotation.cpp:236
cvAnnotation::fontSize
int fontSize
Font size in points.
Definition: cvSelectionAnnotation.h:47
cvSelectionData::POINTS
@ POINTS
Selection applies to points.
Definition: cvSelectionData.h:143
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelFontFamily
QString pointLabelFontFamily
Definition: cvSelectionLabelPropertiesDialog.h:70
cvSelectionAnnotationManager::setAnnotationVisible
bool setAnnotationVisible(const QString &id, bool visible)
Set annotation visibility.
Definition: cvSelectionAnnotation.cpp:221
cvAnnotation::cvAnnotation
cvAnnotation()
Definition: cvSelectionAnnotation.h:59
cvSelectionLabelPropertiesDialog::LabelProperties::pointLabelOpacity
double pointLabelOpacity
Definition: cvSelectionLabelPropertiesDialog.h:76
cvAnnotation::bold
bool bold
Bold flag.
Definition: cvSelectionAnnotation.h:49
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
cvSelectionAnnotationManager::annotationAdded
void annotationAdded(const QString &id)
Emitted when annotation is added.
QPCL_ENGINE_LIB_API
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
cvAnnotation
Annotation for a selection.
Definition: cvSelectionAnnotation.h:42
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelFontFamily
QString cellLabelFontFamily
Definition: cvSelectionLabelPropertiesDialog.h:56
cvSelectionAnnotationManager
Selection annotation manager.
Definition: cvSelectionAnnotation.h:112
cvAnnotation::id
QString id
Unique ID.
Definition: cvSelectionAnnotation.h:44
cvSelectionLabelPropertiesDialog.h
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelVerticalJustification
QString cellLabelVerticalJustification
Definition: cvSelectionLabelPropertiesDialog.h:65
cvAnnotation::text
QString text
Annotation text.
Definition: cvSelectionAnnotation.h:43
cvSelectionData.h
cvSelectionAnnotationManager::cvSelectionAnnotationManager
cvSelectionAnnotationManager(QObject *parent=nullptr)
Definition: cvSelectionAnnotation.cpp:37
cvSelectionAnnotationManager::annotationUpdated
void annotationUpdated(const QString &id)
Emitted when annotation is updated.
cvSelectionAnnotation.h
PclUtils::PCLVis
Definition: PCLVis.h:80
cvSelectionAnnotationManager::setAnnotationFontSize
bool setAnnotationFontSize(const QString &id, int fontSize)
Set annotation font size.
Definition: cvSelectionAnnotation.cpp:251
cvSelectionAnnotationManager::annotationsChanged
void annotationsChanged()
Emitted when annotations change.
cvSelectionAnnotationManager::addAnnotationAt
QString addAnnotationAt(const QString &text, const double position[3], const QString &id=QString())
Add annotation at specific position.
Definition: cvSelectionAnnotation.cpp:126
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelOpacity
double cellLabelOpacity
Definition: cvSelectionLabelPropertiesDialog.h:62
cvSelectionLabelPropertiesDialog::LabelProperties::cellLabelColor
QColor cellLabelColor
Definition: cvSelectionLabelPropertiesDialog.h:58
cvSelectionAnnotationManager::addAnnotation
QString addAnnotation(const cvSelectionData &selection, const QString &text, bool autoPosition=true)
Add annotation for a selection.
Definition: cvSelectionAnnotation.cpp:51