Files

137 lines
3.9 KiB
C++
Raw Permalink Normal View History

2020-02-29 18:00:36 +01:00
//##########################################################################
//# #
//# CLOUDCOMPARE PLUGIN: ColorimetricSegmenter #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: Tri-Thien TRUONG, Ronan COLLIER, Mathieu LETRONE #
//# #
//##########################################################################
2020-09-13 15:47:24 +02:00
2020-02-29 18:00:36 +01:00
#include "HSVDialog.h"
2020-09-13 15:47:24 +02:00
//Local
#include "HSV.h"
2020-02-29 18:00:36 +01:00
2020-09-13 15:47:24 +02:00
//qCC
2020-02-29 18:00:36 +01:00
#include <ccPickingHub.h>
2020-09-13 15:47:24 +02:00
//qCC_db
2020-02-29 18:00:36 +01:00
#include <ccGenericPointCloud.h>
2020-09-13 15:47:24 +02:00
//Qt
#include <QCheckBox>
2020-02-29 18:00:36 +01:00
2020-03-20 16:52:31 +01:00
/*
Constructor
*/
2020-02-29 18:00:36 +01:00
HSVDialog::HSVDialog(ccPickingHub* pickingHub, QWidget* parent)
: QDialog(parent)
, Ui::HSVDialog()
, m_pickingHub(pickingHub)
{
assert(pickingHub);
setModal(false);
setupUi(this);
2020-03-20 16:52:31 +01:00
red->setValue(0);
green->setValue(0);
blue->setValue(0);
2020-02-29 18:00:36 +01:00
2020-09-13 15:47:24 +02:00
//link between Ui and actions
2020-03-20 16:52:31 +01:00
connect(pointPickingButton_first, &QCheckBox::toggled, this, &HSVDialog::pickPoint);
2020-04-16 10:20:09 +02:00
connect(red, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &HSVDialog::updateValues);
connect(green, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &HSVDialog::updateValues);
connect(blue, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &HSVDialog::updateValues);
2020-02-29 18:00:36 +01:00
//auto disable picking mode on quit
connect(this, &QDialog::finished, [&]()
{
2020-09-13 15:47:24 +02:00
//if (pointPickingButton_first->isChecked()) pointPickingButton_first->setChecked(false);
if (m_pickingHub)
m_pickingHub->removeListener(this);
2020-02-29 18:00:36 +01:00
}
);
}
2020-03-20 16:52:31 +01:00
/*
Method for the picking point functionnality
*/
void HSVDialog::pickPoint(bool state)
2020-02-29 18:00:36 +01:00
{
if (!m_pickingHub)
{
return;
}
2020-09-13 15:47:24 +02:00
2020-02-29 18:00:36 +01:00
if (state)
{
if (!m_pickingHub->addListener(this, true))
{
ccLog::Error("Can't start the picking process (another tool is using it)");
state = false;
}
}
else
{
m_pickingHub->removeListener(this);
}
2020-09-13 15:47:24 +02:00
pointPickingButton_first->blockSignals(true);
pointPickingButton_first->setChecked(state);
pointPickingButton_first->blockSignals(false);
2020-02-29 18:00:36 +01:00
}
2020-03-20 16:52:31 +01:00
/*
Method applied after a point is picked by picking point functionnality
*/
2020-02-29 18:00:36 +01:00
void HSVDialog::onItemPicked(const PickedItem& pi)
{
assert(pi.entity);
if (pi.entity->isKindOf(CC_TYPES::POINT_CLOUD))
{
//Get RGB values of the picked point
ccGenericPointCloud* cloud = static_cast<ccGenericPointCloud*>(pi.entity);
2020-09-13 15:47:24 +02:00
const ccColor::Rgba& rgb = cloud->getPointColor(pi.itemIndex);
if (pointPickingButton_first->isChecked())
{
2020-03-20 16:52:31 +01:00
ccLog::Print("Point picked");
2020-04-16 10:20:09 +02:00
//blocking signals to avoid updating 2 times hsv values for nothing
red->blockSignals(true);
green->blockSignals(true);
2020-03-20 16:52:31 +01:00
red->setValue(rgb.r);
green->setValue(rgb.g);
blue->setValue(rgb.b);
2020-02-29 18:00:36 +01:00
2020-04-16 10:20:09 +02:00
red->blockSignals(false);
green->blockSignals(false);
2020-02-29 18:00:36 +01:00
pointPickingButton_first->setChecked(false);
}
}
}
2020-04-16 10:20:09 +02:00
/*
Method applied after entering a value in RGB text fields
*/
void HSVDialog::updateValues()
{
ccColor::Rgb rgb(red->value(), green->value(), blue->value());
2020-09-13 15:47:24 +02:00
Hsv hsv_values(rgb);
2020-04-16 10:20:09 +02:00
hue_first->setValue(hsv_values.h);
sat_first->setValue(hsv_values.s);
val_first->setValue(hsv_values.v);
}