From 2633b8edd9ec0efb0cf0ba5c0ce5a4908664dc15 Mon Sep 17 00:00:00 2001 From: Paul Leroy Date: Fri, 22 Dec 2023 10:56:59 +0100 Subject: [PATCH] option to chose steepest slope, code cleaning --- include/ActionA.h | 4 +- include/CMakeLists.txt | 4 +- include/{G3PointPlugin.h => G3Point.h} | 0 include/{qG3PointDialog.h => G3PointDialog.h} | 7 +- src/ActionA.cpp | 77 ++++++++++++------- src/CMakeLists.txt | 4 +- src/{G3PointPlugin.cpp => G3Point.cpp} | 2 +- src/G3PointDialog.cpp | 31 ++++++++ src/qG3PointDialog.cpp | 26 ------- ui/qG3PointDialog.ui | 27 +++++-- 10 files changed, 115 insertions(+), 67 deletions(-) rename include/{G3PointPlugin.h => G3Point.h} (100%) rename include/{qG3PointDialog.h => G3PointDialog.h} (65%) rename src/{G3PointPlugin.cpp => G3Point.cpp} (99%) create mode 100644 src/G3PointDialog.cpp delete mode 100644 src/qG3PointDialog.cpp diff --git a/include/ActionA.h b/include/ActionA.h index e1ac8bf..fbf92b1 100644 --- a/include/ActionA.h +++ b/include/ActionA.h @@ -6,7 +6,7 @@ #include -#include +#include #pragma once @@ -44,7 +44,7 @@ private: CCCoreLib::DgmOctree::NearestNeighboursSearchStruct m_nNSS; ccMainAppInterface *m_app; Eigen::ArrayXi m_stack; - qG3PointDialog* m_dlg; + G3PointDialog* m_dlg; static G3PointAction* s_g3PointAction; }; diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 2d0e054..3fb9540 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -2,8 +2,8 @@ target_sources( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/ActionA.h - ${CMAKE_CURRENT_LIST_DIR}/G3PointPlugin.h - ${CMAKE_CURRENT_LIST_DIR}/qG3PointDialog.h + ${CMAKE_CURRENT_LIST_DIR}/G3Point.h + ${CMAKE_CURRENT_LIST_DIR}/G3PointDialog.h ) target_include_directories( ${PROJECT_NAME} diff --git a/include/G3PointPlugin.h b/include/G3Point.h similarity index 100% rename from include/G3PointPlugin.h rename to include/G3Point.h diff --git a/include/qG3PointDialog.h b/include/G3PointDialog.h similarity index 65% rename from include/qG3PointDialog.h rename to include/G3PointDialog.h index d04d319..d27d20f 100644 --- a/include/qG3PointDialog.h +++ b/include/G3PointDialog.h @@ -7,15 +7,16 @@ namespace Ui { class qG3PointDialog; } -class qG3PointDialog : public QDialog +class G3PointDialog : public QDialog { Q_OBJECT public: - explicit qG3PointDialog(QWidget *parent = nullptr); - ~qG3PointDialog(); + explicit G3PointDialog(QWidget *parent = nullptr); + ~G3PointDialog(); void emitRun(); int getkNN(); + bool isSteepestSlope(); signals: void run(); diff --git a/src/ActionA.cpp b/src/ActionA.cpp index 8b7a144..2d8f749 100644 --- a/src/ActionA.cpp +++ b/src/ActionA.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include namespace G3Point @@ -302,37 +302,70 @@ void G3PointAction::add_to_stack_braun_willett(int index, const Eigen::ArrayXi& int G3PointAction::segment_labels_braun_willett(bool useParallelStrategy) { - std::cout << "[segment_labels_braun_willett]" << std::endl; - // for each point, find in the neighborhood the point with the minimum slope (the receiver) - Eigen::ArrayXd min_slopes(m_neighbors_slopes.rowwise().minCoeff()); - Eigen::ArrayXi index_of_min_slope = Eigen::ArrayXi::Zero(m_cloud->size()); + std::cout << "[segment_labels]" << std::endl; + + bool steepestSlope = m_dlg->isSteepestSlope(); + + // for each point, find in the neighborhood the point with the extreme slope, depending on the mode (the receiver) + Eigen::ArrayXd extreme_slopes; + if (steepestSlope) + { + std::cout << "[segment_labels] classical steepest slope algorithm [Braun, Willett 2013]" << std::endl; + extreme_slopes = m_neighbors_slopes.rowwise().maxCoeff(); + } + else + { + std::cout << "[segment_labels] reversed version of the steepest slope algorithm [Braun, Willett 2013]" << std::endl; + extreme_slopes = m_neighbors_slopes.rowwise().minCoeff(); + } + Eigen::ArrayXi index_of_extreme_slope = Eigen::ArrayXi::Zero(m_cloud->size()); Eigen::ArrayXi receivers(m_cloud->size()); for (unsigned index = 0; index < m_cloud->size(); index++) { - double min_slope = min_slopes(index); + double extreme_slope = extreme_slopes(index); for (int k = 0; k < m_kNN; k++) { - if (m_neighbors_slopes(index, k) == min_slope) + if (m_neighbors_slopes(index, k) == extreme_slope) { - index_of_min_slope(index) = k; + index_of_extreme_slope(index) = k; break; } } - receivers(index) = m_neighbors_indexes(index, index_of_min_slope(index)); + receivers(index) = m_neighbors_indexes(index, index_of_extreme_slope(index)); } // if the minimum slope is positive, the receiver is a local maximum - int nb_maxima = (min_slopes > 0).count(); + int nb_maxima; + if (steepestSlope) + { + nb_maxima = (extreme_slopes < 0).count(); + } + else + { + nb_maxima = (extreme_slopes > 0).count(); + } Eigen::ArrayXi localMaximumIndexes = Eigen::ArrayXi::Zero(nb_maxima); int l = 0; for (unsigned int k = 0; k < m_cloud->size(); k++) { - if (min_slopes(k) > 0) + if (steepestSlope) { - localMaximumIndexes(l) = k; - receivers(k) = k; - l++; + if (extreme_slopes(k) < 0) + { + localMaximumIndexes(l) = k; + receivers(k) = k; + l++; + } + } + else + { + if (extreme_slopes(k) > 0) + { + localMaximumIndexes(l) = k; + receivers(k) = k; + l++; + } } } @@ -433,15 +466,7 @@ int G3PointAction::segment_labels_braun_willett(bool useParallelStrategy) m_cloud->showSF(false); m_cloud->redrawDisplay(); - // m_cloud->prepareDisplayForRefresh(); - - // ccHObject::Container selectedEntities; - // selectedEntities.push_back(cloud); - - // if (!sfConvertToRandomRGB(selectedEntities, m_app->getMainWindow())) - // { - // ccLog::Error("[G3Point::segment_labels] impossible to convert g3point_label to RGB colors"); - // } + m_cloud->prepareDisplayForRefresh(); if (m_app) { @@ -688,8 +713,8 @@ void G3PointAction::run() query_neighbors(m_cloud, m_app, true); // Perform initial segmentation - // int nLabels = segment_labels(); int nLabels = segment_labels_braun_willett(); + // int nLabels = segment_labels_steepest_slope(); m_app->dispToConsole( "[G3Point] initial segmentation: " + QString::number(nLabels) + " labels", ccMainAppInterface::STD_CONSOLE_MESSAGE ); @@ -733,12 +758,12 @@ void G3PointAction::createAction(ccMainAppInterface *appInterface) s_g3PointAction->m_app = appInterface; //display dialog - s_g3PointAction->m_dlg = new qG3PointDialog(); + s_g3PointAction->m_dlg = new G3PointDialog(); s_g3PointAction->m_dlg->setAttribute(Qt::WA_DeleteOnClose, true); s_g3PointAction->m_dlg->setWindowFlag(Qt::WindowStaysOnTopHint, true); s_g3PointAction->m_dlg->setWindowTitle("G3Point"); - connect(s_g3PointAction->m_dlg, &qG3PointDialog::run, s_g3PointAction, &G3PointAction::run); + connect(s_g3PointAction->m_dlg, &G3PointDialog::run, s_g3PointAction, &G3PointAction::run); s_g3PointAction->m_cloud = ccHObjectCaster::ToPointCloud(ent); s_g3PointAction->m_dlg->show(); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb9c9aa..8bc06e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,6 @@ target_sources( ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/ActionA.cpp - ${CMAKE_CURRENT_LIST_DIR}/G3PointPlugin.cpp - ${CMAKE_CURRENT_LIST_DIR}/qG3PointDialog.cpp + ${CMAKE_CURRENT_LIST_DIR}/G3Point.cpp + ${CMAKE_CURRENT_LIST_DIR}/G3PointDialog.cpp ) diff --git a/src/G3PointPlugin.cpp b/src/G3Point.cpp similarity index 99% rename from src/G3PointPlugin.cpp rename to src/G3Point.cpp index c1a64c7..d17f6ef 100644 --- a/src/G3PointPlugin.cpp +++ b/src/G3Point.cpp @@ -33,7 +33,7 @@ #include -#include "G3PointPlugin.h" +#include "G3Point.h" #include "ActionA.h" diff --git a/src/G3PointDialog.cpp b/src/G3PointDialog.cpp new file mode 100644 index 0000000..aca4845 --- /dev/null +++ b/src/G3PointDialog.cpp @@ -0,0 +1,31 @@ +#include "G3PointDialog.h" +#include "ui_qG3PointDialog.h" + +G3PointDialog::G3PointDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::qG3PointDialog) +{ + ui->setupUi(this); + + connect(this->ui->pushButtonSegment, &QPushButton::clicked, this, &G3PointDialog::emitRun); +} + +G3PointDialog::~G3PointDialog() +{ + delete ui; +} + +void G3PointDialog::emitRun() +{ + emit run(); +} + +int G3PointDialog::getkNN() +{ + return this->ui->spinBoxkNN->value(); +} + +bool G3PointDialog::isSteepestSlope() +{ + return this->ui->radioButtonSteepestSlope->isChecked(); +} diff --git a/src/qG3PointDialog.cpp b/src/qG3PointDialog.cpp deleted file mode 100644 index 71c222d..0000000 --- a/src/qG3PointDialog.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "qG3PointDialog.h" -#include "ui_qG3PointDialog.h" - -qG3PointDialog::qG3PointDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::qG3PointDialog) -{ - ui->setupUi(this); - - connect(this->ui->pushButtonSegment, &QPushButton::clicked, this, &qG3PointDialog::emitRun); -} - -qG3PointDialog::~qG3PointDialog() -{ - delete ui; -} - -void qG3PointDialog::emitRun() -{ - emit run(); -} - -int qG3PointDialog::getkNN() -{ - return this->ui->spinBoxkNN->value(); -} diff --git a/ui/qG3PointDialog.ui b/ui/qG3PointDialog.ui index f61f782..5884368 100644 --- a/ui/qG3PointDialog.ui +++ b/ui/qG3PointDialog.ui @@ -6,14 +6,21 @@ 0 0 - 157 - 73 + 190 + 101 Dialog + + + + Segment + + + @@ -34,10 +41,20 @@ - - + + - Segment + steepest slope + + + + + + + G3Point + + + true