From 786c1c197fc363e6445b49eb470217cee861e91a Mon Sep 17 00:00:00 2001 From: Tri-Thien TRUONG Date: Thu, 6 Feb 2020 18:58:02 +0100 Subject: [PATCH] =?UTF-8?q?Point=20picking=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColorimetricSegmenter.cpp | 43 +++++++++++------- ColorimetricSegmenter.h | 4 ++ RgbDialog.cpp | 91 ++++++++++++--------------------------- RgbDialog.h | 5 --- 4 files changed, 60 insertions(+), 83 deletions(-) diff --git a/ColorimetricSegmenter.cpp b/ColorimetricSegmenter.cpp index 4208012..63b940a 100644 --- a/ColorimetricSegmenter.cpp +++ b/ColorimetricSegmenter.cpp @@ -31,12 +31,12 @@ // "description" is used as a tootip if the plugin has actions and is displayed in the plugin dialog // "authors", "maintainers", and "references" show up in the plugin dialog as well +#include + #include - - #include "ColorimetricSegmenter.h" -#include "RgbDialog.h" + #include "ccPointCloud.h" #include "ccScalarField.h" @@ -209,22 +209,27 @@ void ColorimetricSegmenter::filterRgb() } // Retrieve parameters from dialog - //m_pickingHub = new ccPickingHub(m_app, m_app->getActiveGLWindow()); - m_pickingHub = new ccPickingHub(m_app, (QWidget*)m_app->getMainWindow()); + if (m_app->pickingHub()) { + m_pickingHub = m_app->pickingHub(); + } + + rgbDlg = new RgbDialog(m_pickingHub,(QWidget*)m_app->getMainWindow()); + rgbDlg->show(); - RgbDialog rgbDlg(m_pickingHub,(QWidget*)m_app->getMainWindow()); - - if (!rgbDlg.exec()) + if (!rgbDlg->exec()) return; - double marginError = static_cast(rgbDlg.margin->value()) / 100.0; + // Start timer + auto start = std::chrono::high_resolution_clock::now(); - int redInf = rgbDlg.area_red->value() - (marginError * rgbDlg.area_red->value()); - int redSup = rgbDlg.area_red->value() + marginError * rgbDlg.area_red->value(); - int greenInf = rgbDlg.area_green->value() - marginError * rgbDlg.area_green->value(); - int greenSup = rgbDlg.area_green->value() + marginError * rgbDlg.area_green->value(); - int blueInf = rgbDlg.area_blue->value() - marginError * rgbDlg.area_blue->value(); - int blueSup = rgbDlg.area_blue->value() + marginError * rgbDlg.area_blue->value(); + double marginError = static_cast(rgbDlg->margin->value()) / 100.0; + + int redInf = rgbDlg->area_red->value() - (marginError * rgbDlg->area_red->value()); + int redSup = rgbDlg->area_red->value() + marginError * rgbDlg->area_red->value(); + int greenInf = rgbDlg->area_green->value() - marginError * rgbDlg->area_green->value(); + int greenSup = rgbDlg->area_green->value() + marginError * rgbDlg->area_green->value(); + int blueInf = rgbDlg->area_blue->value() - marginError * rgbDlg->area_blue->value(); + int blueSup = rgbDlg->area_blue->value() + marginError * rgbDlg->area_blue->value(); std::vector clouds = getSelectedPointClouds(); @@ -266,5 +271,13 @@ void ColorimetricSegmenter::filterRgb() } } + + // Stop timer + auto stop = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast(stop - start).count(); + QString s = QString::number(duration); + //Print time of execution + //std::cout << duration.count() << std::endl; + ccLog::Print("Time to execute : " + s); } diff --git a/ColorimetricSegmenter.h b/ColorimetricSegmenter.h index 5595bb9..9216fa0 100644 --- a/ColorimetricSegmenter.h +++ b/ColorimetricSegmenter.h @@ -26,6 +26,8 @@ #include #include +#include "RgbDialog.h" + //! Example qCC plugin /** Replace 'ExamplePlugin' by your own plugin class name throughout and then @@ -108,6 +110,8 @@ private: //! Picking hub ccPickingHub* m_pickingHub = nullptr; + RgbDialog* rgbDlg; + //link to application windows //ccGLWindow* m_window; //QMainWindow* m_main_window; diff --git a/RgbDialog.cpp b/RgbDialog.cpp index 5e37679..1f26d9d 100644 --- a/RgbDialog.cpp +++ b/RgbDialog.cpp @@ -31,6 +31,9 @@ //common #include +#include +#include + //qCC_gl #include #include @@ -42,7 +45,6 @@ RgbDialog::RgbDialog(ccPickingHub* pickingHub, QWidget* parent) : QDialog(parent) , Ui::RgbDialog() , m_pickingWin(0) - , m_associatedPlane(0) , m_pickingHub(pickingHub) { assert(pickingHub); @@ -57,91 +59,54 @@ RgbDialog::RgbDialog(ccPickingHub* pickingHub, QWidget* parent) area_blue->setValue(rgb.b); //Link between Ui and actions - //connect(pointPickingButton, &QCheckBox::toggled, this, &RgbDialog::pickPoint); - connect(pointPickingButton, &QAbstractButton::toggled, this, &RgbDialog::pickPoint); + connect(pointPickingButton, &QCheckBox::toggled, this, &RgbDialog::pickPoint); //auto disable picking mode on quit - /*connect(this, &QDialog::finished, [&]() + connect(this, &QDialog::finished, [&]() { if (pointPickingButton->isChecked()) pointPickingButton->setChecked(false); } - );*/ + ); } void RgbDialog::pickPoint(bool state) { - if (m_pickingHub) + if (!m_pickingHub) { - ccLog::Print("pickingHub"); - if (state) + return; + } + if (state) + { + if (!m_pickingHub->addListener(this, true)) { - 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); + ccLog::Error("Can't start the picking process (another tool is using it)"); + state = false; } } - else if (m_pickingWin) + else { - ccLog::Print("pickinWin"); - if (state) - { - m_pickingWin->setPickingMode(ccGLWindow::POINT_OR_TRIANGLE_PICKING); - connect(m_pickingWin, &ccGLWindow::itemPicked, this, &RgbDialog::processPickedItem); - } - else - { - m_pickingWin->setPickingMode(ccGLWindow::DEFAULT_PICKING); - disconnect(m_pickingWin, &ccGLWindow::itemPicked, this, &RgbDialog::processPickedItem); - } + m_pickingHub->removeListener(this); } - pointPickingButton->blockSignals(true); pointPickingButton->setChecked(state); pointPickingButton->blockSignals(false); } + void RgbDialog::onItemPicked(const PickedItem& pi) { - if (!pi.entity) - { - return; - } - + ccLog::Print("Point Picked"); + assert(pi.entity); m_pickingWin = m_pickingHub->activeWindow(); - - /*if (pi.entity->isKindOf(CC_TYPES::POINT_CLOUD)) + if (pi.entity->isKindOf(CC_TYPES::POINT_CLOUD)) { - rgb = pi.entity->getTempColor; - }*/ - - area_red->setValue(10); - area_green->setValue(20); - area_blue->setValue(30); - ccLog::Print("Test"); + //Get RGB values of the picked point + ccGenericPointCloud* cloud = static_cast(pi.entity); + const ccColor::Rgb& rgb = cloud->getPointColor(pi.itemIndex); + area_red->setValue(rgb.r); + area_green->setValue(rgb.g); + area_blue->setValue(rgb.b); + } pointPickingButton->setChecked(false); -} - -void RgbDialog::processPickedItem(ccHObject* entity, unsigned, int, int, const CCVector3& P, const CCVector3d& uvw) -{ - //without picking hub (ccViewer) - if (!m_pickingWin) - { - assert(false); - return; - } - - if (!entity) - { - return; - } - - pickPoint(false); -} - +} \ No newline at end of file diff --git a/RgbDialog.h b/RgbDialog.h index 2042036..0505742 100644 --- a/RgbDialog.h +++ b/RgbDialog.h @@ -40,8 +40,6 @@ public: //! Inherited from ccPickingListener virtual void onItemPicked(const PickedItem& pi); - void processPickedItem(ccHObject* entity, unsigned, int, int, const CCVector3& P, const CCVector3d& uvw); - public slots: void pickPoint(bool); @@ -50,9 +48,6 @@ protected: //members //! Picking window (if any) ccGLWindow* m_pickingWin; - //! Associated plane (if any) - ccPlane* m_associatedPlane; - //! Picking hub ccPickingHub* m_pickingHub;