ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
RgbDialog.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 "RgbDialog.h"
9 
10 // common
11 #include <ecvGenericPointCloud.h>
12 #include <ecvPickingHub.h>
13 
14 // Qt
15 #include <QCheckBox>
16 
17 /*
18  Constructor
19 */
20 RgbDialog::RgbDialog(ccPickingHub* pickingHub, QWidget* parent)
21  : QDialog(parent),
22  Ui::RgbDialog(),
23  m_pickingWin(nullptr),
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 */
48 void RgbDialog::pickPoint_first(bool state) {
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 */
70 void RgbDialog::pickPoint_second(bool state) {
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)->hasColors()) {
98  // Get RGB values of the picked point
99  ccGenericPointCloud* cloud =
100  static_cast<ccGenericPointCloud*>(pi.entity);
101  const ecvColor::Rgb& rgb = cloud->getPointColor(pi.itemIndex);
102  if (pointPickingButton_first->isChecked()) {
103  CVLog::Print("Point picked from first point picker");
104 
105  red_first->setValue(rgb.r);
106  green_first->setValue(rgb.g);
107  blue_first->setValue(rgb.b);
108 
109  pointPickingButton_first->setChecked(false);
110  } else {
111  CVLog::Print("Point picked from second point picker");
112  red_second->setValue(rgb.r);
113  green_second->setValue(rgb.g);
114  blue_second->setValue(rgb.b);
115 
116  pointPickingButton_second->setChecked(false);
117  }
118  } else {
119  CVLog::Print("The point cloud is not with RGB values.");
120  }
121  }
122 }
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
ccPickingHub * m_pickingHub
Picking hub.
Definition: RgbDialog.h:56
virtual void onItemPicked(const PickedItem &pi)
Inherited from ccPickingListener.
Definition: RgbDialog.cpp:92
void pickPoint_second(bool)
Definition: RgbDialog.cpp:70
RgbDialog(ccPickingHub *pickingHub, QWidget *parent=nullptr)
Definition: RgbDialog.cpp:20
void pickPoint_first(bool)
Definition: RgbDialog.cpp:48
QWidget * m_pickingWin
Picking window (if any)
Definition: RgbDialog.h:53
virtual bool hasColors() const
Returns whether colors are enabled or not.
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual const ecvColor::Rgb & getPointColor(unsigned pointIndex) const =0
Returns color corresponding to a given point.
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
RGB color structure.
Definition: ecvColorTypes.h:49
@ POINT_CLOUD
Definition: CVTypes.h:104