Point picking terminé

This commit is contained in:
Tri-Thien TRUONG
2020-02-06 18:58:02 +01:00
parent bfbd06d044
commit 786c1c197f
4 changed files with 60 additions and 83 deletions
+28 -15
View File
@@ -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 <iostream>
#include <QtGui>
#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<double>(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<double>(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<ccPointCloud*> 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<std::chrono::milliseconds>(stop - start).count();
QString s = QString::number(duration);
//Print time of execution
//std::cout << duration.count() << std::endl;
ccLog::Print("Time to execute : " + s);
}
+4
View File
@@ -26,6 +26,8 @@
#include <ccPickingHub.h>
#include <ccGLWindow.h>
#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;
+28 -63
View File
@@ -31,6 +31,9 @@
//common
#include <ccPickingHub.h>
#include <ccGenericPointCloud.h>
#include <ccPointCloud.h>
//qCC_gl
#include <ccGLWidget.h>
#include <ccGLWindow.h>
@@ -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<ccGenericPointCloud*>(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);
}
}
-5
View File
@@ -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;