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:
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 };
std::string filename
math::float4 color
math::float3 position
#define signals
Selection annotation manager.
void annotationsChanged()
Emitted when annotations change.
void annotationRemoved(const QString &id)
Emitted when annotation is removed.
int count() const
Get annotation count.
void annotationAdded(const QString &id)
Emitted when annotation is added.
void annotationUpdated(const QString &id)
Emitted when annotation is updated.
Encapsulates selection data without exposing VTK types.
constexpr Rgb yellow(MAX, MAX, 0)
#define QPCL_ENGINE_LIB_API
Definition: qPCL.h:15
Annotation for a selection.
QString fontFamily
Font family (e.g., "Arial")
QColor color
Text color.
QString id
Unique ID.
qint64 timestamp
Creation timestamp.
QString text
Annotation text.
int fontSize
Font size in points.
double opacity
Text opacity (0.0 to 1.0)
QString horizontalJustification
"Left", "Center", "Right"
bool visible
Visibility flag.
cvAnnotation(const QString &txt, const double pos[3], const QString &uid=QString())
bool shadow
Shadow flag.
bool followSelection
Auto-update position with selection.
QString verticalJustification
"Top", "Center", "Bottom"
bool italic
Italic flag.
bool bold
Bold flag.