ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ScalarDialog.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 "ScalarDialog.h"
9 
10 // common
11 #include <ecvGenericPointCloud.h>
12 #include <ecvPickingHub.h>
13 
14 // Qt
15 #include <QCheckBox>
16 
17 /*
18  Constructor
19 */
20 ScalarDialog::ScalarDialog(ccPickingHub* pickingHub, QWidget* parent)
21  : QDialog(parent),
22  Ui::ScalarDialog(),
23  m_pickingWin(0),
24  m_pickingHub(pickingHub) {
25  assert(pickingHub);
26 
27  setModal(false);
28  setupUi(this);
29 
30  // Link between Ui and actions
31  connect(pointPickingButton_first, &QCheckBox::toggled, this,
33  connect(pointPickingButton_second, &QCheckBox::toggled, this,
35 
36  // auto disable picking mode on quit
37  connect(this, &QDialog::finished, [&]() {
38  if (pointPickingButton_first->isChecked())
39  pointPickingButton_first->setChecked(false);
40  if (pointPickingButton_second->isChecked())
41  pointPickingButton_second->setChecked(false);
42  });
43 }
44 
45 /*
46  Method for the first picking point functionnality
47 */
49  if (!m_pickingHub) {
50  return;
51  }
52  if (state) {
53  if (!m_pickingHub->addListener(this, true)) {
55  "Can't start the picking process (another tool is using "
56  "it)");
57  state = false;
58  }
59  } else {
61  }
62  pointPickingButton_first->blockSignals(true);
63  pointPickingButton_first->setChecked(state);
64  pointPickingButton_first->blockSignals(false);
65 }
66 
67 /*
68  Method for the second picking point functionnality
69 */
71  if (!m_pickingHub) {
72  return;
73  }
74  if (state) {
75  if (!m_pickingHub->addListener(this, true)) {
77  "Can't start the picking process (another tool is using "
78  "it)");
79  state = false;
80  }
81  } else {
83  }
84  pointPickingButton_second->blockSignals(true);
85  pointPickingButton_second->setChecked(state);
86  pointPickingButton_second->blockSignals(false);
87 }
88 
89 /*
90  Method applied after a point is picked by picking point functionnality
91 */
93  assert(pi.entity);
95 
97  if (static_cast<ccGenericPointCloud*>(pi.entity)->hasScalarFields()) {
98  // Get RGB values of the picked point
99  ccGenericPointCloud* cloud =
100  static_cast<ccGenericPointCloud*>(pi.entity);
101  const ScalarType scalarValue =
102  cloud->getPointScalarValue(pi.itemIndex);
103  if (pointPickingButton_first->isChecked()) {
104  CVLog::Print("Point picked from first point picker");
105 
106  first->setValue(scalarValue);
107 
108  pointPickingButton_first->setChecked(false);
109  } else {
110  CVLog::Print("Point picked from second point picker");
111 
112  second->setValue(scalarValue);
113 
114  pointPickingButton_second->setChecked(false);
115  }
116  } else {
117  CVLog::Print("The point cloud hasn't any scalar field.");
118  }
119  }
120 }
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
virtual void onItemPicked(const PickedItem &pi)
Inherited from ccPickingListener.
ScalarDialog(ccPickingHub *pickingHub, QWidget *parent=nullptr)
ccPickingHub * m_pickingHub
Picking hub.
Definition: ScalarDialog.h:57
void pickPoint_first(bool)
QWidget * m_pickingWin
Picking window (if any)
Definition: ScalarDialog.h:54
void pickPoint_second(bool)
virtual bool hasScalarFields() const
Returns whether one or more scalar fields are instantiated.
A 3D cloud interface with associated features (color, normals, octree, etc.)
bool isKindOf(CV_CLASS_ENUM type) const
Definition: ecvObject.h:128
Point/triangle picking hub.
Definition: ecvPickingHub.h:29
void removeListener(ccPickingListener *listener, bool autoStopPickingIfLast=true)
Removes a listener.
bool addListener(ccPickingListener *listener, bool exclusive=false, bool autoStartPicking=true, ecvDisplayTools::PICKING_MODE mode=ecvDisplayTools::POINT_OR_TRIANGLE_PICKING)
Adds a listener.
QWidget * activeWindow() const
Returns the currently active window.
Definition: ecvPickingHub.h:74
virtual ScalarType getPointScalarValue(unsigned pointIndex) const =0
Returns the ith point associated scalar value.
@ POINT_CLOUD
Definition: CVTypes.h:104