diff --git a/include/AnglesCustomPlot.h b/include/AnglesCustomPlot.h index f487340..2f56799 100644 --- a/include/AnglesCustomPlot.h +++ b/include/AnglesCustomPlot.h @@ -3,7 +3,7 @@ #include -#include .h> +#include namespace Ui { class AnglesCustomPlot; @@ -11,7 +11,7 @@ class AnglesCustomPlot; class AnglesCustomPlot : public QCustomPlot { - + Q_OBJECT public: explicit AnglesCustomPlot(const QVector& data, const QString& xLabel, int nbBins, QWidget *parent = nullptr); @@ -23,10 +23,17 @@ public: void rescale(); - void mouseDoubleClickEvent(QMouseEvent *event) override; - QSharedPointer dataContainer(){return m_bars->data();} + void emitCloseTab(){emit closeTab();} + + void mouseDoubleClickEvent(QMouseEvent* event) override; + + void mousePressEvent(QMouseEvent* event) override; + +signals: + void closeTab(); + private: Ui::AnglesCustomPlot *ui; diff --git a/include/G3PointAction.h b/include/G3PointAction.h index ae9fb5b..a3e0981 100644 --- a/include/G3PointAction.h +++ b/include/G3PointAction.h @@ -113,8 +113,12 @@ private: static std::shared_ptr s_g3PointAction; - static std::shared_ptr s_g3PointPlots; + static QPointer s_g3PointPlots; GrainsAsEllipsoids* m_grainsAsEllipsoids; + + std::unique_ptr m_progress; + + int m_currentNumberOfSteps; }; } diff --git a/include/G3PointPlots.h b/include/G3PointPlots.h index 217475f..04f479e 100644 --- a/include/G3PointPlots.h +++ b/include/G3PointPlots.h @@ -21,6 +21,8 @@ public: void addToTabWidget(QWidget* widget); + void closeCurrentWidget(); + template bool exportToCSV(QString filename, SharedDataContainer container) const; diff --git a/include/WolmanCustomPlot.h b/include/WolmanCustomPlot.h index ec7489c..d59c21c 100644 --- a/include/WolmanCustomPlot.h +++ b/include/WolmanCustomPlot.h @@ -64,8 +64,9 @@ protected: }; -class WolmanCustomPlot : public QWidget +class WolmanCustomPlot : public QCustomPlot { + Q_OBJECT public: WolmanCustomPlot(const Eigen::ArrayXf& d_sample); @@ -73,6 +74,13 @@ public: QCPGraph* m_graph; + void emitCloseTab(){emit closeTab();} + + void mousePressEvent(QMouseEvent* event) override; + +signals: + void closeTab(); + private: Ui::WolmanCustomPlot *ui; }; diff --git a/src/AnglesCustomPlot.cpp b/src/AnglesCustomPlot.cpp index ea4a2da..a00894b 100644 --- a/src/AnglesCustomPlot.cpp +++ b/src/AnglesCustomPlot.cpp @@ -129,3 +129,16 @@ void AnglesCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) } QCustomPlot::mouseDoubleClickEvent(event); } + +void AnglesCustomPlot::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) + { + QMenu* menu = new QMenu(this); + QAction* action = new QAction("Close tab"); + menu->addAction(action); + connect(action, &QAction::triggered, this, &AnglesCustomPlot::emitCloseTab); + menu->popup(event->globalPos()); + } + QCustomPlot::mousePressEvent(event); +} diff --git a/src/G3PointAction.cpp b/src/G3PointAction.cpp index 0cfcfbe..8e07196 100644 --- a/src/G3PointAction.cpp +++ b/src/G3PointAction.cpp @@ -49,11 +49,12 @@ namespace G3Point { std::shared_ptr G3PointAction::s_g3PointAction; -std::shared_ptr G3PointAction::s_g3PointPlots; +QPointer G3PointAction::s_g3PointPlots; G3PointAction::G3PointAction(ccPointCloud *cloud, ccMainAppInterface *app) : m_app(app) , m_dlg(nullptr) + , m_grainsAsEllipsoids(nullptr) { assert(cloud); setCloud(cloud); @@ -76,7 +77,7 @@ void G3PointAction::GetG3PointAction(ccPointCloud *cloud, ccMainAppInterface *ap if (!G3PointDisclaimer::show(app)) return; - s_g3PointPlots.reset(new G3PointPlots(cloud->getName())); + s_g3PointPlots = new G3PointPlots(cloud->getName()); if (!s_g3PointAction) // create the singleton if needed { @@ -99,7 +100,7 @@ void G3PointAction::GetG3PointAction(ccPointCloud *cloud, ccMainAppInterface *ap s_g3PointAction->showDlg(); } -RGBAColorsTableType getRandomColors(int randomColorsNumber) +RGBAColorsTableType getRandomColors(size_t randomColorsNumber) { Q_ASSERT(randomColorsNumber > 1); @@ -532,12 +533,13 @@ bool G3PointAction::updateLabelsAndColors() return false; } - for (int index = 0; index < m_cloud->size(); index++) // points which are not in the stacks will have the label -1 + for (unsigned index = 0; index < m_cloud->size(); index++) // points which are not in the stacks will have the label -1 { g3point_label->setValue(index, -1); - m_labels = -1; } + m_labels = -1; + for (int k = 0; k < m_stacks.size(); k++) { const std::vector& stack = m_stacks[k]; @@ -1103,7 +1105,7 @@ void G3PointAction::showWolman(const Eigen::ArrayXf& d_sample) { // QCustomPlot if (!s_g3PointPlots) - s_g3PointPlots.reset(new G3PointPlots(m_cloud->getName())); + s_g3PointPlots = new G3PointPlots(m_cloud->getName()); s_g3PointPlots->addToTabWidget(new WolmanCustomPlot(d_sample)); s_g3PointPlots->show(); } @@ -1300,7 +1302,7 @@ bool G3PointAction::angles() // QCustomPlot if (!s_g3PointPlots) - s_g3PointPlots.reset(new G3PointPlots(m_cloud->getName())); + s_g3PointPlots = new G3PointPlots(m_cloud->getName()); int nbBins = m_dlg->getAnglesNbBins(); s_g3PointPlots->addToTabWidget(new AnglesCustomPlot(granuloAngleMView, "Azimut", nbBins)); s_g3PointPlots->addToTabWidget(new AnglesCustomPlot(granuloAngleXView, "Dip", nbBins)); @@ -2008,42 +2010,57 @@ bool G3PointAction::setCloud(ccPointCloud *cloud) CCCoreLib::ScalarField* g3PointLabelBackupSF = m_cloud->getScalarField(sfIdxBackup); // get the set of labels - std::set labels; + std::set labelsSet; for (unsigned int index = 0; index < m_cloud->size(); index++) { - labels.insert(g3PointLabelSF->getValue(index)); + labelsSet.insert(g3PointLabelSF->getValue(index)); + } + // remove -1 from the set + labelsSet.erase(-1); + // build a map to handle cases were g3point_label is not a regular range with step 1 + // keys = labels + // values = index + std::map labelsMap; + int index = 0; + for (auto label : labelsSet) + { + labelsMap[label] = index; + index++; } // build stacks from g3point_index - std::map> labelStackMap; int nPointsInGrains = 0; + m_progress.reset(new QProgressBar()); + m_progress->setRange(0, m_cloud->size()); + m_progress->setWindowTitle("Processing g3point_label"); + m_progress->show(); + + std::vector> newStacks(labelsSet.size()); + for (unsigned int index = 0; index < m_cloud->size(); index++) { ScalarType label = g3PointLabelSF->getValue(index); g3PointLabelBackupSF->setValue(index, label); // save the originale G3Point label if (label != -1) // -1 is a generic index corresponding to all points which do not belong to valid grains { - labelStackMap[label].push_back(index); + newStacks[labelsMap[label]].push_back(index); nPointsInGrains++; } + if (index % 20 == 0) + { + m_progress->setValue(index); + QApplication::processEvents(); + } } - // initialize m_stacks - std::vector> newStacks; - for (const auto& item : labelStackMap) - { - newStacks.push_back(item.second); - } + m_progress->hide(); + QApplication::processEvents(); ccLog::Print("[G3PointAction::setCloud] g3point_label available, found " + QString::number(nPointsInGrains) + "/" + QString::number(cloud->size()) + " points belonging to " + QString::number(newStacks.size()) + " grains"); - std::cout << "[d] processNewStacks" << std::endl; - processNewStacks(newStacks, nPointsInGrains); - - std::cout << "[e]" << std::endl; } return true; diff --git a/src/G3PointPlots.cpp b/src/G3PointPlots.cpp index c322745..dc1b88a 100644 --- a/src/G3PointPlots.cpp +++ b/src/G3PointPlots.cpp @@ -55,6 +55,20 @@ void G3PointPlots::addToTabWidget(QWidget* widget) { this->ui->tabWidget->addTab(widget, widget->windowTitle()); this->ui->tabWidget->setCurrentWidget(widget); + + if (widget->property("TypeOfCustomPlot").toString() == "AnglesCustomPlot") + { + connect(static_cast(widget), &AnglesCustomPlot::closeTab, this, &G3PointPlots::closeCurrentWidget); + } + else if (widget->property("TypeOfCustomPlot").toString() == "WolmanCustomPlot") + { + connect(static_cast(widget), &WolmanCustomPlot::closeTab, this, &G3PointPlots::closeCurrentWidget); + } +} + +void G3PointPlots::closeCurrentWidget() +{ + this->ui->tabWidget->currentWidget()->deleteLater(); } template diff --git a/src/WolmanCustomPlot.cpp b/src/WolmanCustomPlot.cpp index 2899c85..a44cddf 100644 --- a/src/WolmanCustomPlot.cpp +++ b/src/WolmanCustomPlot.cpp @@ -10,7 +10,7 @@ WolmanCustomPlot::WolmanCustomPlot(const Eigen::ArrayXf &d_sample): setWindowTitle("Wolman"); - m_graph = this->ui->customPlot->addGraph(); + m_graph = this->addGraph(); QVector x_data(d_sample.size()); QVector y_data(d_sample.size()); for (int k = 0; k < d_sample.size(); k++) @@ -22,7 +22,20 @@ WolmanCustomPlot::WolmanCustomPlot(const Eigen::ArrayXf &d_sample): m_graph->setData(x_data, y_data); m_graph->rescaleAxes(); // give the axes some labels: - this->ui->customPlot->xAxis->setScaleType(QCPAxis::stLogarithmic); - this->ui->customPlot->xAxis->setLabel("Diameter [mm]"); - this->ui->customPlot->yAxis->setLabel("CDF"); + this->xAxis->setScaleType(QCPAxis::stLogarithmic); + this->xAxis->setLabel("Diameter [mm]"); + this->yAxis->setLabel("CDF"); +} + +void WolmanCustomPlot::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::RightButton) + { + QMenu* menu = new QMenu(this); + QAction* action = new QAction("Close tab"); + menu->addAction(action); + connect(action, &QAction::triggered, this, &WolmanCustomPlot::emitCloseTab); + menu->popup(event->globalPos()); + } + QCustomPlot::mousePressEvent(event); } diff --git a/ui/WolmanCustomPlot.ui b/ui/WolmanCustomPlot.ui index e9c3c00..6d1db30 100644 --- a/ui/WolmanCustomPlot.ui +++ b/ui/WolmanCustomPlot.ui @@ -13,20 +13,7 @@ Form - - - - - - - - QCustomPlot - QWidget -
qcustomplot.h
- 1 -
-