ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
WolmanCustomPlot.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "WolmanCustomPlot.h"
9 
10 #include <iostream>
11 
12 #include "ui_WolmanCustomPlot.h"
13 
14 WolmanCustomPlot::WolmanCustomPlot(const Eigen::ArrayXf& d_sample,
15  const Eigen::Array3d& dq_final,
16  const Eigen::Array3d& edq)
17  : m_dq_final(dq_final), m_edq(edq), ui(new Ui::WolmanCustomPlot) {
18  setProperty("TypeOfCustomPlot", "WolmanCustomPlot");
19 
20  ui->setupUi(this);
21 
22  setWindowTitle("Wolman");
23 
24  QPen pen;
25 
26  m_graph = this->addGraph();
27 
28  // build x_data
29  int nSamples = d_sample.size();
30  QVector<double> x_data(nSamples);
31  for (int k = 0; k < nSamples; k++) {
32  x_data[k] = d_sample(k);
33  }
34  while (x_data.contains(0.)) {
35  int index = x_data.indexOf(0.);
36  std::cout << "[WolmanCustomPlot::WolmanCustomPlot] remove null "
37  "diameter at index "
38  << QString::number(index).toStdString() << std::endl;
39  x_data.remove(index);
40  }
41  std::sort(x_data.begin(), x_data.end()); // sort diameters
42 
43  // build y_data
44  int nValidSamples = x_data.size();
45  QVector<double> y_data(nValidSamples);
46  for (int k = 0; k < nValidSamples; k++) {
47  y_data[k] =
48  (static_cast<double>(k)) / static_cast<double>(nValidSamples);
49  }
50 
51  m_graph->setData(x_data, y_data);
52  m_graph->rescaleAxes();
53  // give the axes some labels:
54  this->xAxis->setScaleType(QCPAxis::stLogarithmic);
55  this->xAxis->setLabel("Diameter [mm]");
56  this->yAxis->setLabel("CDF");
57 
58  // add error bars
59  QCPGraph* errorBarsGraph = this->addGraph();
60  errorBarsGraph->setData(
61  QVector<double>({dq_final[0], dq_final[1], dq_final[2]}),
62  QVector<double>({0.1, 0.5, 0.9}));
63  errorBarsGraph->setLineStyle(QCPGraph::lsNone);
64  errorBarsGraph->setScatterStyle(
65  QCPScatterStyle(QCPScatterStyle::ssCircle, 4));
66  QCPErrorBars* errorBars = new QCPErrorBars(xAxis, yAxis);
67  errorBars->removeFromLegend();
68  errorBars->setAntialiased(false);
69  errorBars->setDataPlottable(errorBarsGraph);
70  errorBars->setErrorType(QCPErrorBars::etKeyError);
71  // pen.setWidth(1);
72  errorBars->setPen(pen);
73  errorBars->setData(QVector<double>({edq[0], edq[1], edq[2]}));
74  errorBars->setPen(QPen(QColor(Qt::red)));
75  errorBars->rescaleAxes(true);
76 
77  setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
78 }
79 
81  // set ranges appropriate to show data
82  if (m_graph) {
83  m_graph->rescaleAxes();
84  replot();
85  }
86 }
87 
89  if (event->button() == Qt::LeftButton) {
90  rescale();
91  }
92  QCustomPlot::mouseDoubleClickEvent(event);
93 }
94 
96  if (event->button() == Qt::RightButton) {
97  QMenu* menu = new QMenu(this);
98  QAction* action = new QAction("Close tab");
99  menu->addAction(action);
100  connect(action, &QAction::triggered, this,
102  menu->popup(event->globalPos());
103  }
104  QCustomPlot::mousePressEvent(event);
105 }
MouseEvent event
void mouseDoubleClickEvent(QMouseEvent *event) override
void mousePressEvent(QMouseEvent *event) override
WolmanCustomPlot(const Eigen::ArrayXf &d_sample, const Eigen::Array3d &dq_final, const Eigen::Array3d &edq)
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
constexpr Rgb red(MAX, 0, 0)