diff --git a/CMakeLists.txt b/CMakeLists.txt index 204d976..354f2b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,13 @@ option( PLUGIN_COLORIMETRIC_SEGMENTER "Check to install segmenter plugin" OFF ) if ( PLUGIN_COLORIMETRIC_SEGMENTER ) # Name the plugin project( ColorimetricSegmenter ) + + # we need includes from the main CC source dir + include_directories( ${CloudCompare_SOURCE_DIR} ) + + list( APPEND CC_PLUGIN_CUSTOM_HEADER_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingListener.h ) + list( APPEND CC_PLUGIN_CUSTOM_HEADER_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingHub.h ) + list( APPEND CC_PLUGIN_CUSTOM_SOURCE_LIST ${CloudCompare_SOURCE_DIR}/../common/ccPickingHub.cpp ) # load any subdirectories (see qAdditionalIO for an example) # add_subdirectory( LIB1 ) diff --git a/ColorimetricSegmenter.cpp b/ColorimetricSegmenter.cpp index f80210f..4208012 100644 --- a/ColorimetricSegmenter.cpp +++ b/ColorimetricSegmenter.cpp @@ -33,6 +33,8 @@ #include + + #include "ColorimetricSegmenter.h" #include "RgbDialog.h" @@ -72,7 +74,6 @@ void ColorimetricSegmenter::handleErrorMessage(QString message) m_app->dispToConsole(message, ccMainAppInterface::ERR_CONSOLE_MESSAGE); } - // This method should enable or disable your plugin actions // depending on the currently selected entities ('selectedEntities'). void ColorimetricSegmenter::onNewSelection( const ccHObject::Container &selectedEntities ) @@ -106,6 +107,7 @@ void ColorimetricSegmenter::onNewSelection( const ccHObject::Container &selected // getActions() will be called only once, when plugin is loaded. QList ColorimetricSegmenter::getActions() { + // default action (if it has not been already created, this is the moment to do it) if ( !m_action_filterScalar ) { @@ -137,6 +139,7 @@ QList ColorimetricSegmenter::getActions() connect(m_action_filterRgb, SIGNAL(newEntity(ccHObject*)), this, SLOT(handleNewEntity(ccHObject*))); connect(m_action_filterRgb, SIGNAL(entityHasChanged(ccHObject*)), this, SLOT(handleEntityChange(ccHObject*))); connect(m_action_filterRgb, SIGNAL(newErrorMessage(QString)), this, SLOT(handleErrorMessage(QString))); + } return { m_action_filterScalar, m_action_filterRgb }; @@ -198,8 +201,18 @@ void ColorimetricSegmenter::filterRgb() return; } + //check valid window + if (!m_app->getActiveGLWindow()) + { + m_app->dispToConsole("[ccCompass] Could not find valid 3D window.", ccMainAppInterface::ERR_CONSOLE_MESSAGE); + return; + } + // Retrieve parameters from dialog - RgbDialog rgbDlg((QWidget*)m_app->getMainWindow()); + //m_pickingHub = new ccPickingHub(m_app, m_app->getActiveGLWindow()); + m_pickingHub = new ccPickingHub(m_app, (QWidget*)m_app->getMainWindow()); + + RgbDialog rgbDlg(m_pickingHub,(QWidget*)m_app->getMainWindow()); if (!rgbDlg.exec()) return; @@ -254,3 +267,4 @@ void ColorimetricSegmenter::filterRgb() } } } + diff --git a/ColorimetricSegmenter.h b/ColorimetricSegmenter.h index 911f82d..5595bb9 100644 --- a/ColorimetricSegmenter.h +++ b/ColorimetricSegmenter.h @@ -22,6 +22,10 @@ #include #include +#include +#include +#include + //! Example qCC plugin /** Replace 'ExamplePlugin' by your own plugin class name throughout and then @@ -88,6 +92,10 @@ private: //! Filter a cloud with RGB color void filterRgb(); + + //picked point callbacks + //void pointPicked(ccHObject* entity, unsigned itemIdx, int x, int y, const CCVector3& P); + //virtual void onItemPicked(const ccPickingListener::PickedItem& pi); //inherited from ccPickingListener //! Default action /** You can add as many actions as you want in a plugin. @@ -97,6 +105,13 @@ private: QAction* m_action_filterScalar; QAction* m_action_filterRgb; + //! Picking hub + ccPickingHub* m_pickingHub = nullptr; + + //link to application windows + //ccGLWindow* m_window; + //QMainWindow* m_main_window; + }; #endif diff --git a/RgbDialog.cpp b/RgbDialog.cpp index 8e00401..5e37679 100644 --- a/RgbDialog.cpp +++ b/RgbDialog.cpp @@ -15,11 +15,133 @@ //# # //########################################################################## #include "RgbDialog.h" + +//local +#include "mainwindow.h" + //Qt #include -RgbDialog::RgbDialog(QWidget* parent) +#include +#include +#include +#include +#include +#include + +//common +#include + +//qCC_gl +#include +#include + +//semi-persistent parameters +static ccColor::Rgb rgb(0,0,0); + +RgbDialog::RgbDialog(ccPickingHub* pickingHub, QWidget* parent) : QDialog(parent) , Ui::RgbDialog() + , m_pickingWin(0) + , m_associatedPlane(0) + , m_pickingHub(pickingHub) { + assert(pickingHub); + + setModal(false); setupUi(this); -} \ No newline at end of file + + + //restore semi-persistent parameters + area_red->setValue(rgb.r); + area_green->setValue(rgb.g); + area_blue->setValue(rgb.b); + + //Link between Ui and actions + //connect(pointPickingButton, &QCheckBox::toggled, this, &RgbDialog::pickPoint); + connect(pointPickingButton, &QAbstractButton::toggled, this, &RgbDialog::pickPoint); + + //auto disable picking mode on quit + /*connect(this, &QDialog::finished, [&]() + { + if (pointPickingButton->isChecked()) pointPickingButton->setChecked(false); } + );*/ +} + +void RgbDialog::pickPoint(bool state) +{ + if (m_pickingHub) + { + ccLog::Print("pickingHub"); + 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); + } + } + else if (m_pickingWin) + { + 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); + } + } + + pointPickingButton->blockSignals(true); + pointPickingButton->setChecked(state); + pointPickingButton->blockSignals(false); +} + +void RgbDialog::onItemPicked(const PickedItem& pi) +{ + if (!pi.entity) + { + return; + } + + m_pickingWin = m_pickingHub->activeWindow(); + + + /*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"); + + 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); +} + diff --git a/RgbDialog.h b/RgbDialog.h index 837673a..2042036 100644 --- a/RgbDialog.h +++ b/RgbDialog.h @@ -19,14 +19,42 @@ #define RgbDialog_H #include +#include "ccPickingListener.h" //Qt +#include #include +#include -class RgbDialog : public QDialog, public Ui::RgbDialog +class ccGLWindow; +class ccPlane; +class ccHObject; +class ccPickingHub; + +class RgbDialog : public QDialog, public ccPickingListener, public Ui::RgbDialog { + Q_OBJECT public: - explicit RgbDialog(QWidget* parent = 0); + explicit RgbDialog(ccPickingHub* pickingHub, QWidget* parent = 0); + + //! 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); + +protected: //members + + //! Picking window (if any) + ccGLWindow* m_pickingWin; + + //! Associated plane (if any) + ccPlane* m_associatedPlane; + + //! Picking hub + ccPickingHub* m_pickingHub; }; diff --git a/RgbDialog.ui b/RgbDialog.ui index 662eb5d..00c088c 100644 --- a/RgbDialog.ui +++ b/RgbDialog.ui @@ -7,7 +7,7 @@ 0 0 350 - 173 + 162 @@ -21,126 +21,131 @@ - - - - - Red - - - Qt::AlignCenter - - - - - - - 255 - - - - - - - - - - - Green - - - Qt::AlignCenter - - - - - - - 255 - - - - - - - - - - - Blue - - - Qt::AlignCenter - - - - - - - 255 - - - - - - - - - ArrowCursor - - - Use PointPicking - + + + + + 0 + 0 + 331 + 107 + + + + Point Selected + + + true + + + + + + RED : + + + 0 + + + 0.000000000000000 + + + 255.000000000000000 + + + + + + + Pick the plane center (click again to cancel) + + + + :/CC/images/ccPointPicking.png:/CC/images/ccPointPicking.png + + + true + + + + + + + GREEN : + + + 0 + + + 0.000000000000000 + + + 255.000000000000000 + + + + + + + BLUE : + + + 0 + + + 0.000000000000000 + + + 255.000000000000000 + + + + + + + + + 0 + 110 + 332 + 31 + + + + + + + Margin of error (%) : + + + + + + + 100 + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + - - - - - - Margin of erreur (%) : - - - - - - - 100 - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - + + + - - buttonBox - rejected() - RgbDialog - reject() - - - 260 - 120 - - - 280 - 118 - - - buttonBox accepted() @@ -157,5 +162,21 @@ + + buttonBox + rejected() + RgbDialog + reject() + + + 260 + 120 + + + 280 + 118 + + +