ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PclMeasurementTools.cpp
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 #include "PclMeasurementTools.h"
9 
10 #include <CVLog.h>
11 #include <PclUtils/PCLVis.h>
12 #include <ecvDisplayTools.h>
13 
14 #include "cvContourTool.h"
15 #include "cvDistanceTool.h"
17 #include "cvProtractorTool.h"
18 
20  : ecvGenericMeasurementTools(type), m_viewer(nullptr), m_tool(nullptr) {
21  initialize();
22 }
23 
26  : ecvGenericMeasurementTools(type), m_viewer(nullptr), m_tool(nullptr) {
27  setVisualizer(viewer);
28  initialize();
29 }
30 
32  if (m_tool) {
33  delete m_tool;
34  m_tool = nullptr;
35  }
36 }
37 
39  switch (m_measurementType) {
40  case MeasurementType::PROTRACTOR_WIDGET:
41  m_tool = new cvProtractorTool();
42  break;
43  case MeasurementType::DISTANCE_WIDGET:
44  m_tool = new cvDistanceTool();
45  break;
46  case MeasurementType::CONTOUR_WIDGET:
47  m_tool = new cvContourTool();
48  break;
49  default:
50  CVLog::Error(QString("Unknown measurement type"));
51  break;
52  }
53 
54  if (m_tool && m_viewer) {
55  m_tool->setUpViewer(m_viewer);
56  if (m_viewer->getRenderWindow() &&
57  m_viewer->getRenderWindow()->GetInteractor()) {
58  m_tool->setInteractor(m_viewer->getRenderWindow()->GetInteractor());
59  }
60  // Connect measurement value changed signal
63 
64  // Connect point picking signals - forward from cvGenericMeasurementTool
65  // to ecvGenericMeasurementTools
70  }
71 }
72 
74  if (viewer) {
75  m_viewer = reinterpret_cast<PclUtils::PCLVis*>(viewer);
76  if (!m_viewer) {
78  "[PclMeasurementTools::setVisualizer] viewer is Null!");
79  return;
80  }
81  if (m_tool) {
82  m_tool->setUpViewer(m_viewer);
83  if (m_viewer->getRenderWindowInteractor()) {
84  m_tool->setInteractor(m_viewer->getRenderWindowInteractor());
85  }
86  }
87  } else {
88  CVLog::Warning("[PclMeasurementTools::setVisualizer] viewer is Null!");
89  }
90 }
91 
93  m_associatedEntity = entity;
94  if (!m_viewer) {
95  // Try to get viewer from display tools
97  if (viewer) {
98  setVisualizer(viewer);
99  }
100  }
101  if (m_tool) {
102  return m_tool->setInput(entity);
103  }
104  return false;
105 }
106 
108  if (!m_viewer) {
109  // Try to get viewer from display tools
111  if (viewer) {
112  setVisualizer(viewer);
113  }
114  }
115  if (m_tool && m_viewer) {
116  // Ensure interactor is set
117  if (m_viewer->getRenderWindowInteractor()) {
118  m_tool->setInteractor(m_viewer->getRenderWindowInteractor());
119  }
120  m_tool->start();
121  return true;
122  }
123  return false;
124 }
125 
127  if (m_tool) {
128  m_tool->reset();
129  }
130 }
131 
133  if (m_tool) {
134  m_tool->clearAllActor();
135  }
136 }
137 
138 QWidget* PclMeasurementTools::getMeasurementWidget() { return m_tool; }
139 
141  if (m_tool) {
142  return m_tool->getOutput();
143  }
144  return nullptr;
145 }
146 
148  if (m_tool) {
149  return m_tool->getMeasurementValue();
150  }
151  return 0.0;
152 }
153 
154 void PclMeasurementTools::getPoint1(double pos[3]) const {
155  if (m_tool) {
156  m_tool->getPoint1(pos);
157  } else if (pos) {
158  pos[0] = pos[1] = pos[2] = 0.0;
159  }
160 }
161 
162 void PclMeasurementTools::getPoint2(double pos[3]) const {
163  if (m_tool) {
164  m_tool->getPoint2(pos);
165  } else if (pos) {
166  pos[0] = pos[1] = pos[2] = 0.0;
167  }
168 }
169 
170 void PclMeasurementTools::getCenter(double pos[3]) const {
171  if (m_tool) {
172  m_tool->getCenter(pos);
173  } else if (pos) {
174  pos[0] = pos[1] = pos[2] = 0.0;
175  }
176 }
177 
178 void PclMeasurementTools::setPoint1(double pos[3]) {
179  if (m_tool && pos) {
180  m_tool->setPoint1(pos);
181  }
182 }
183 
184 void PclMeasurementTools::setPoint2(double pos[3]) {
185  if (m_tool && pos) {
186  m_tool->setPoint2(pos);
187  }
188 }
189 
190 void PclMeasurementTools::setCenter(double pos[3]) {
191  if (m_tool && pos) {
192  m_tool->setCenter(pos);
193  }
194 }
195 
196 void PclMeasurementTools::setColor(double r, double g, double b) {
197  if (m_tool) {
198  m_tool->setColor(r, g, b);
199  }
200 }
201 
202 bool PclMeasurementTools::getColor(double& r, double& g, double& b) const {
203  if (m_tool) {
204  return m_tool->getColor(r, g, b);
205  }
206  return false;
207 }
208 
210  if (m_tool) {
211  m_tool->lockInteraction();
212  }
213 }
214 
216  if (m_tool) {
217  m_tool->unlockInteraction();
218  }
219 }
220 
221 void PclMeasurementTools::setInstanceLabel(const QString& label) {
222  if (m_tool) {
223  m_tool->setInstanceLabel(label);
224  }
225 }
226 
227 void PclMeasurementTools::setFontFamily(const QString& family) {
228  if (m_tool) {
229  m_tool->setFontFamily(family);
230  }
231 }
232 
234  if (m_tool) {
235  m_tool->setFontSize(size);
236  }
237 }
238 
240  if (m_tool) {
241  m_tool->setBold(bold);
242  }
243 }
244 
246  if (m_tool) {
247  m_tool->setItalic(italic);
248  }
249 }
250 
252  if (m_tool) {
253  m_tool->setShadow(shadow);
254  }
255 }
256 
258  if (m_tool) {
259  m_tool->setFontOpacity(opacity);
260  }
261 }
262 
263 void PclMeasurementTools::setFontColor(double r, double g, double b) {
264  if (m_tool) {
265  m_tool->setFontColor(r, g, b);
266  }
267 }
268 
270  return m_tool ? m_tool->getFontFamily() : QString("Arial");
271 }
272 
274  return m_tool ? m_tool->getFontSize() : 6;
275 }
276 
277 void PclMeasurementTools::getFontColor(double& r, double& g, double& b) const {
278  if (m_tool) {
279  m_tool->getFontColor(r, g, b);
280  } else {
281  r = g = b = 1.0; // Default white
282  }
283 }
284 
286  return m_tool ? m_tool->getFontBold() : false;
287 }
288 
290  return m_tool ? m_tool->getFontItalic() : false;
291 }
292 
294  return m_tool ? m_tool->getFontShadow() : true;
295 }
296 
298  return m_tool ? m_tool->getFontOpacity() : 1.0;
299 }
300 
302  return m_tool ? m_tool->getHorizontalJustification() : QString("Left");
303 }
304 
306  return m_tool ? m_tool->getVerticalJustification() : QString("Bottom");
307 }
308 
310  const QString& justification) {
311  if (m_tool) {
312  m_tool->setHorizontalJustification(justification);
313  }
314 }
315 
317  const QString& justification) {
318  if (m_tool) {
319  m_tool->setVerticalJustification(justification);
320  }
321 }
322 
324  if (m_tool && win) {
325  m_tool->setupShortcuts(win);
326  } else {
328  "[PclMeasurementTools::setupShortcuts] tool or win is Null!");
329  }
330 }
331 
333  if (m_tool) {
334  m_tool->disableShortcuts();
335  }
336 }
337 
339  if (m_tool) {
340  m_tool->clearPickingCache();
341  }
342 }
int size
char type
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
virtual void disableShortcuts() override
Disable keyboard shortcuts (called before tool destruction)
PclMeasurementTools(MeasurementType type=MeasurementType::DISTANCE_WIDGET)
virtual ccHObject * getOutput() const override
Returns the output (if any)
virtual void clear() override
Clears the measurement tool.
virtual void reset() override
Resets the measurement tool.
virtual void lockInteraction() override
Lock tool interaction (disable VTK widget and UI controls)
virtual void setFontColor(double r, double g, double b) override
Set font color for measurement labels (RGB values 0.0-1.0)
virtual QWidget * getMeasurementWidget() override
Returns the measurement widget.
virtual void initialize() override
virtual bool setInputData(ccHObject *entity) override
Sets the input entity.
virtual void setVerticalJustification(const QString &justification) override
void setVisualizer(ecvGenericVisualizer3D *viewer=nullptr)
virtual bool start() override
Starts the measurement tool.
virtual void getCenter(double pos[3]) const override
Get center point coordinates (for angle/protractor)
QString getVerticalJustification() const
QString getHorizontalJustification() const
virtual ~PclMeasurementTools() override
virtual void setupShortcuts(QWidget *win) override
Setup keyboard shortcuts bound to the render window widget.
virtual void setPoint1(double pos[3]) override
Set point 1 coordinates.
virtual void setFontOpacity(double opacity) override
Set font opacity for measurement labels (0.0 to 1.0)
virtual void setFontSize(int size) override
Set font size for measurement labels.
virtual void setCenter(double pos[3]) override
Set center point coordinates (for angle/protractor)
virtual void setShadow(bool shadow) override
Set font shadow state for measurement labels.
void getFontColor(double &r, double &g, double &b) const
virtual void setItalic(bool italic) override
Set font italic state for measurement labels.
virtual void clearPickingCache() override
Clear picking cache (called when scene/camera changes)
virtual bool getColor(double &r, double &g, double &b) const
virtual void setFontFamily(const QString &family) override
virtual void setPoint2(double pos[3]) override
Set point 2 coordinates.
virtual void setColor(double r, double g, double b) override
Set measurement color (RGB values in range [0.0, 1.0])
QString getFontFamily() const
Get font properties (for UI synchronization)
virtual void getPoint2(double pos[3]) const override
Get point 2 coordinates.
virtual void setBold(bool bold) override
Set font bold state for measurement labels.
virtual void setHorizontalJustification(const QString &justification) override
virtual void unlockInteraction() override
Unlock tool interaction (enable VTK widget and UI controls)
virtual double getMeasurementValue() const override
Get measurement value (distance or angle)
virtual void setInstanceLabel(const QString &label) override
Set instance label suffix (e.g., "#1", "#2") for display in 3D view.
virtual void getPoint1(double pos[3]) const override
Get point 1 coordinates.
vtkSmartPointer< vtkRenderWindowInteractor > getRenderWindowInteractor()
Get a pointer to the current interactor style used.
Definition: PCLVis.h:148
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
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])
virtual void setPoint1(double pos[3])
Set point 1 coordinates.
virtual void setVerticalJustification(const QString &justification)
void setUpViewer(PclUtils::PCLVis *viewer)
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
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.
void setInteractor(vtkRenderWindowInteractor *interactor)
virtual void lockInteraction()
Lock tool interaction (disable VTK widget interaction and UI controls)
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.
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)
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)
static ecvGenericVisualizer3D * GetVisualizer3D()
Generic Measurement Tools interface.
void pointPickingCancelled()
Signal sent when point picking is cancelled.
void pointPickingRequested(int pointIndex)
void measurementChanged()
Signal sent when the measurement changes.
Generic visualizer 3D interface.