Files
ptrans/RgbDialog.cpp
T

154 lines
4.1 KiB
C++
Raw Normal View History

//##########################################################################
//# #
//# 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 #
//# #
//##########################################################################
#include "RgbDialog.h"
2020-02-01 03:59:24 +01:00
//local
#include "mainwindow.h"
//Qt
#include <QVariant>
2020-02-01 03:59:24 +01:00
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
//common
#include <ccPickingHub.h>
2020-02-06 18:58:02 +01:00
#include <ccGenericPointCloud.h>
#include <ccPointCloud.h>
2020-02-01 03:59:24 +01:00
//qCC_gl
#include <ccGLWidget.h>
#include <ccGLWindow.h>
2020-03-20 16:52:31 +01:00
/*
Constructor
*/
2020-02-01 03:59:24 +01:00
RgbDialog::RgbDialog(ccPickingHub* pickingHub, QWidget* parent)
: QDialog(parent)
, Ui::RgbDialog()
2020-02-01 03:59:24 +01:00
, m_pickingWin(0)
, m_pickingHub(pickingHub)
{
2020-02-01 03:59:24 +01:00
assert(pickingHub);
setModal(false);
setupUi(this);
2020-02-01 03:59:24 +01:00
//Link between Ui and actions
2020-02-29 18:00:36 +01:00
connect(pointPickingButton_first, &QCheckBox::toggled, this, &RgbDialog::pickPoint_first);
connect(pointPickingButton_second, &QCheckBox::toggled, this, &RgbDialog::pickPoint_second);
2020-02-01 03:59:24 +01:00
//auto disable picking mode on quit
2020-02-06 18:58:02 +01:00
connect(this, &QDialog::finished, [&]()
2020-02-01 03:59:24 +01:00
{
2020-02-29 18:00:36 +01:00
if (pointPickingButton_first->isChecked()) pointPickingButton_first->setChecked(false);
if (pointPickingButton_second->isChecked()) pointPickingButton_second->setChecked(false);
}
2020-02-06 18:58:02 +01:00
);
2020-02-01 03:59:24 +01:00
}
2020-03-20 16:52:31 +01:00
/*
Method for the first picking point functionnality
*/
2020-02-29 18:00:36 +01:00
void RgbDialog::pickPoint_first(bool state)
2020-02-01 03:59:24 +01:00
{
2020-02-06 18:58:02 +01:00
if (!m_pickingHub)
2020-02-01 03:59:24 +01:00
{
2020-02-06 18:58:02 +01:00
return;
2020-02-01 03:59:24 +01:00
}
2020-02-06 18:58:02 +01:00
if (state)
2020-02-01 03:59:24 +01:00
{
2020-02-06 18:58:02 +01:00
if (!m_pickingHub->addListener(this, true))
2020-02-01 03:59:24 +01:00
{
2020-02-06 18:58:02 +01:00
ccLog::Error("Can't start the picking process (another tool is using it)");
state = false;
2020-02-01 03:59:24 +01:00
}
}
2020-02-06 18:58:02 +01:00
else
{
m_pickingHub->removeListener(this);
}
2020-02-29 18:00:36 +01:00
pointPickingButton_first->blockSignals(true);
pointPickingButton_first->setChecked(state);
pointPickingButton_first->blockSignals(false);
}
2020-03-20 16:52:31 +01:00
/*
Method for the second picking point functionnality
*/
2020-02-29 18:00:36 +01:00
void RgbDialog::pickPoint_second(bool state)
{
if (!m_pickingHub)
{
return;
}
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);
}
pointPickingButton_second->blockSignals(true);
pointPickingButton_second->setChecked(state);
pointPickingButton_second->blockSignals(false);
2020-02-01 03:59:24 +01:00
}
2020-03-20 16:52:31 +01:00
/*
Method applied after a point is picked by picking point functionnality
*/
2020-02-01 03:59:24 +01:00
void RgbDialog::onItemPicked(const PickedItem& pi)
{
2020-02-06 18:58:02 +01:00
assert(pi.entity);
2020-02-01 03:59:24 +01:00
m_pickingWin = m_pickingHub->activeWindow();
2020-02-06 18:58:02 +01:00
if (pi.entity->isKindOf(CC_TYPES::POINT_CLOUD))
2020-02-01 03:59:24 +01:00
{
2020-02-29 18:00:36 +01:00
2020-02-06 18:58:02 +01:00
//Get RGB values of the picked point
ccGenericPointCloud* cloud = static_cast<ccGenericPointCloud*>(pi.entity);
const ccColor::Rgb& rgb = cloud->getPointColor(pi.itemIndex);
2020-02-29 18:00:36 +01:00
if (pointPickingButton_first->isChecked()) {
ccLog::Print("Point picked from first point picker");
red_first->setValue(rgb.r);
green_first->setValue(rgb.g);
blue_first->setValue(rgb.b);
pointPickingButton_first->setChecked(false);
}
else {
ccLog::Print("Point picked from second point picker");
red_second->setValue(rgb.r);
green_second->setValue(rgb.g);
blue_second->setValue(rgb.b);
pointPickingButton_second->setChecked(false);
}
2020-02-01 03:59:24 +01:00
}
2020-02-29 18:00:36 +01:00
2020-02-06 18:58:02 +01:00
}