ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
HSVDialog.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 "HSVDialog.h"
9 
10 // Local
11 #include "HSV.h"
12 
13 // CV_CORE_LIB
14 #include <ecvPickingHub.h>
15 
16 // CV_DB_LIB
17 #include <ecvGenericPointCloud.h>
18 
19 // Qt
20 #include <QCheckBox>
21 
22 /*
23  Constructor
24 */
25 HSVDialog::HSVDialog(ccPickingHub* pickingHub, QWidget* parent)
26  : QDialog(parent), Ui::HSVDialog(), m_pickingHub(pickingHub) {
27  assert(pickingHub);
28 
29  setModal(false);
30  setupUi(this);
31 
32  red->setValue(0);
33  green->setValue(0);
34  blue->setValue(0);
35 
36  // link between Ui and actions
37  connect(pointPickingButton_first, &QCheckBox::toggled, this,
39  connect(red,
40  static_cast<void (QDoubleSpinBox::*)(double)>(
41  &QDoubleSpinBox::valueChanged),
43  connect(green,
44  static_cast<void (QDoubleSpinBox::*)(double)>(
45  &QDoubleSpinBox::valueChanged),
47  connect(blue,
48  static_cast<void (QDoubleSpinBox::*)(double)>(
49  &QDoubleSpinBox::valueChanged),
51 
52  // auto disable picking mode on quit
53  connect(this, &QDialog::finished, [&]() {
54  // if (pointPickingButton_first->isChecked())
55  // pointPickingButton_first->setChecked(false);
57  });
58 }
59 
60 /*
61  Method for the picking point functionnality
62 */
63 void HSVDialog::pickPoint(bool state) {
64  if (!m_pickingHub) {
65  return;
66  }
67 
68  if (state) {
69  if (!m_pickingHub->addListener(this, true)) {
71  "Can't start the picking process (another tool is using "
72  "it)");
73  state = false;
74  }
75  } else {
77  }
78 
79  pointPickingButton_first->blockSignals(true);
80  pointPickingButton_first->setChecked(state);
81  pointPickingButton_first->blockSignals(false);
82 }
83 
84 /*
85  Method applied after a point is picked by picking point functionnality
86 */
88  assert(pi.entity);
89 
91  // Get RGB values of the picked point
92  ccGenericPointCloud* cloud =
93  static_cast<ccGenericPointCloud*>(pi.entity);
94  const ecvColor::Rgb& rgb = cloud->getPointColor(pi.itemIndex);
95  if (pointPickingButton_first->isChecked()) {
96  CVLog::Print("Point picked");
97 
98  // blocking signals to avoid updating 2 times hsv values for nothing
99  red->blockSignals(true);
100  green->blockSignals(true);
101 
102  red->setValue(rgb.r);
103  green->setValue(rgb.g);
104  blue->setValue(rgb.b);
105 
106  red->blockSignals(false);
107  green->blockSignals(false);
108 
109  pointPickingButton_first->setChecked(false);
110  }
111  }
112 }
113 
114 /*
115  Method applied after entering a value in RGB text fields
116 */
118  ecvColor::Rgb rgb(red->value(), green->value(), blue->value());
119 
120  Hsv hsv_values(rgb);
121  hue_first->setValue(hsv_values.h);
122  sat_first->setValue(hsv_values.s);
123  val_first->setValue(hsv_values.v);
124 }
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.
Definition: HSVDialog.cpp:87
HSVDialog(ccPickingHub *pickingHub, QWidget *parent=nullptr)
Definition: HSVDialog.cpp:25
void updateValues()
Definition: HSVDialog.cpp:117
ccPickingHub * m_pickingHub
Picking hub.
Definition: HSVDialog.h:54
void pickPoint(bool)
Definition: HSVDialog.cpp:63
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.
RGB color structure.
Definition: ecvColorTypes.h:49
@ POINT_CLOUD
Definition: CVTypes.h:104
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb blue(0, 0, MAX)
constexpr Rgb green(0, MAX, 0)
HSV color.
Definition: HSV.h:31
uint16_t v
Definition: HSV.h:66
uint16_t s
Definition: HSV.h:66
uint16_t h
Definition: HSV.h:66