ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cvGenericMeasurementTool.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 "ui_cvGenericMeasurementToolDlg.h"
11 
12 // CV_CORE_LIB
13 #include <CVGeom.h>
14 #include <CVLog.h>
15 #include <CVTools.h>
16 
17 // VTK
18 #include <vtkSmartPointer.h>
19 
20 // QT
21 #include <QList>
22 #include <QObject>
23 #include <QString>
24 #include <QWidget>
25 
26 namespace PclUtils {
27 class PCLVis;
28 }
31 
32 class vtkActor;
33 class vtkProp;
34 class vtkRenderWindowInteractor;
35 class vtkRenderer;
36 class vtkAbstractWidget;
37 
38 class ccHObject;
39 
40 class cvGenericMeasurementTool : public QWidget {
41  Q_OBJECT
42 signals:
45 
48  void pointPickingRequested(int pointIndex);
49 
52 
53 public:
54  explicit cvGenericMeasurementTool(QWidget* parent = nullptr);
55  virtual ~cvGenericMeasurementTool();
56 
57  virtual void start();
58  virtual void update();
59  virtual void reset();
60  virtual ccHObject* getOutput();
61 
62  virtual bool initModel();
63  virtual bool setInput(ccHObject* obj);
64 
65  virtual void showWidget(bool state) { /* not impl */ }
66  virtual void clearAllActor();
67 
69  virtual double getMeasurementValue() const { return 0.0; }
70 
72  virtual void getPoint1(double pos[3]) const {
73  if (pos) {
74  pos[0] = pos[1] = pos[2] = 0.0;
75  }
76  }
77 
79  virtual void getPoint2(double pos[3]) const {
80  if (pos) {
81  pos[0] = pos[1] = pos[2] = 0.0;
82  }
83  }
84 
86  virtual void getCenter(double pos[3]) const {
87  if (pos) {
88  pos[0] = pos[1] = pos[2] = 0.0;
89  }
90  }
91 
93  virtual void setPoint1(double pos[3]) { /* not impl */ }
94 
96  virtual void setPoint2(double pos[3]) { /* not impl */ }
97 
99  virtual void setCenter(double pos[3]) { /* not impl */ }
100 
102  virtual void setColor(double r, double g, double b) { /* not impl */ }
103 
106  virtual bool getColor(double& r, double& g, double& b) const {
107  Q_UNUSED(r);
108  Q_UNUSED(g);
109  Q_UNUSED(b);
110  return false;
111  }
112 
114  virtual void lockInteraction() { /* not impl */ }
115 
117  virtual void unlockInteraction() { /* not impl */ }
118 
120  virtual void setInstanceLabel(const QString& label) { /* not impl */ }
121 
124  virtual void setFontFamily(const QString& family);
125 
127  virtual void setFontSize(int size);
128 
130  virtual void setBold(bool bold);
131 
133  virtual void setItalic(bool italic);
134 
136  virtual void setShadow(bool shadow);
137 
139  virtual void setFontOpacity(double opacity);
140 
142  virtual void setFontColor(double r, double g, double b);
143 
146  virtual void setHorizontalJustification(const QString& justification);
147 
150  virtual void setVerticalJustification(const QString& justification);
151 
153  QString getFontFamily() const { return m_fontFamily; }
154  int getFontSize() const { return m_fontSize; }
155  void getFontColor(double& r, double& g, double& b) const {
156  r = m_fontColor[0];
157  g = m_fontColor[1];
158  b = m_fontColor[2];
159  }
160  bool getFontBold() const { return m_fontBold; }
161  bool getFontItalic() const { return m_fontItalic; }
162  bool getFontShadow() const { return m_fontShadow; }
163  double getFontOpacity() const { return m_fontOpacity; }
164  QString getHorizontalJustification() const {
166  }
168 
169 protected:
173  virtual void applyFontProperties() = 0;
174 
175 public:
176  void setUpViewer(PclUtils::PCLVis* viewer);
177  void setInteractor(vtkRenderWindowInteractor* interactor);
178  inline vtkRenderWindowInteractor* getInteractor() { return m_interactor; }
179  inline vtkRenderer* getRenderer() { return m_renderer; }
180 
183  void setupShortcuts(QWidget* vtkWidget);
184 
186  void disableShortcuts();
187 
190  void clearPickingCache();
191 
192 protected:
193  virtual void modelReady();
194  virtual void dataChanged() { /* not impl */ }
195 
196  void safeOff(vtkAbstractWidget* widget);
197 
198  virtual void initTool() { /* not impl */ }
199  virtual void createUi() { /* not impl */ }
200 
204  virtual void setupPointPickingShortcuts(QWidget* vtkWidget) {
205  Q_UNUSED(vtkWidget);
206  }
207 
209  void updatePickingHelpers();
210 
211  void addActor(const vtkSmartPointer<vtkProp> actor);
212  void removeActor(const vtkSmartPointer<vtkProp> actor);
213 
214 protected:
215  Ui::GenericMeasurementToolDlg* m_ui = nullptr;
216 
217  std::string m_id;
218  ccHObject* m_entity = nullptr;
220  vtkRenderWindowInteractor* m_interactor = nullptr;
221  vtkRenderer* m_renderer = nullptr;
222 
224 
226  QList<cvPointPickingHelper*> m_pickingHelpers;
227 
229  QWidget* m_vtkWidget = nullptr;
230 
232  QString m_fontFamily = "Arial";
233  int m_fontSize = 6; // Default font size for better readability
234  double m_fontColor[3] = {1.0, 1.0, 1.0}; // White by default
235  bool m_fontBold = false;
236  bool m_fontItalic = false;
237  bool m_fontShadow = true;
238  double m_fontOpacity = 1.0;
239  QString m_horizontalJustification = "Left";
240  QString m_verticalJustification = "Bottom";
241 };
int size
#define signals
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
QWidget * m_vtkWidget
VTK widget reference for creating shortcuts (saved from linkWith)
virtual void applyFontProperties()=0
void pointPickingCancelled()
Signal sent when point picking is cancelled.
virtual void setItalic(bool italic)
Set font italic state for measurement labels.
virtual void setColor(double r, double g, double b)
Set measurement color (RGB values in range [0.0, 1.0])
void addActor(const vtkSmartPointer< vtkProp > actor)
vtkRenderWindowInteractor * m_interactor
virtual void setPoint1(double pos[3])
Set point 1 coordinates.
virtual void showWidget(bool state)
QList< cvPointPickingHelper * > m_pickingHelpers
List of point picking helpers for keyboard shortcuts.
void removeActor(const vtkSmartPointer< vtkProp > actor)
virtual void setVerticalJustification(const QString &justification)
void setUpViewer(PclUtils::PCLVis *viewer)
QString m_fontFamily
Font properties for measurement labels (shared by all tools)
cvGenericMeasurementTool(QWidget *parent=nullptr)
virtual void setPoint2(double pos[3])
Set point 2 coordinates.
virtual void getCenter(double pos[3]) const
Get center point coordinates (for angle/protractor)
void pointPickingRequested(int pointIndex)
void disableShortcuts()
Disable all keyboard shortcuts (call before tool destruction)
QString getFontFamily() const
Get font properties (for UI synchronization)
virtual void setHorizontalJustification(const QString &justification)
virtual void getPoint2(double pos[3]) const
Get point 2 coordinates.
virtual bool getColor(double &r, double &g, double &b) const
vtkRenderWindowInteractor * getInteractor()
virtual void setBold(bool bold)
Set font bold state for measurement labels.
void setupShortcuts(QWidget *vtkWidget)
virtual double getMeasurementValue() const
Get measurement value (distance or angle)
virtual void setShadow(bool shadow)
Set font shadow state for measurement labels.
virtual void setInstanceLabel(const QString &label)
Set instance label suffix (e.g., "#1", "#2") for display in 3D view.
virtual void setupPointPickingShortcuts(QWidget *vtkWidget)
void safeOff(vtkAbstractWidget *widget)
void setInteractor(vtkRenderWindowInteractor *interactor)
virtual void lockInteraction()
Lock tool interaction (disable VTK widget interaction and UI controls)
void updatePickingHelpers()
Update point picking helpers with current interactor/renderer.
virtual void setCenter(double pos[3])
Set center point coordinates (for angle/protractor)
virtual void unlockInteraction()
Unlock tool interaction (enable VTK widget interaction and UI controls)
virtual bool setInput(ccHObject *obj)
virtual void setFontSize(int size)
Set font size for measurement labels.
vtkSmartPointer< vtkActor > m_modelActor
virtual void setFontFamily(const QString &family)
virtual void setFontColor(double r, double g, double b)
Set font color for measurement labels (RGB values 0.0-1.0)
Ui::GenericMeasurementToolDlg * m_ui
void measurementValueChanged()
Signal sent when the measurement value changes.
void getFontColor(double &r, double &g, double &b) const
virtual void getPoint1(double pos[3]) const
Get point 1 coordinates.
virtual void setFontOpacity(double opacity)
Set font opacity for measurement labels (0.0 to 1.0)
cvPointPickingHelper is a helper class for supporting keyboard shortcut-based point picking in measur...
Generic visualizer 3D interface.