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);
53  // give the axes some labels:
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(
66  QCPErrorBars* errorBars = new QCPErrorBars(xAxis, yAxis);
67  errorBars->removeFromLegend();
68  errorBars->setAntialiased(false);
69  errorBars->setDataPlottable(errorBarsGraph);
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 
78 }
79 
81  // set ranges appropriate to show data
82  if (m_graph) {
84  replot();
85  }
86 }
87 
89  if (event->button() == Qt::LeftButton) {
90  rescale();
91  }
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  }
105 }
MouseEvent event
void rescaleAxes(bool onlyEnlarge=false) const
bool removeFromLegend(QCPLegend *legend) const
void setPen(const QPen &pen)
void setLabel(const QString &str)
@ stLogarithmic
Definition: qcustomplot.h:2359
Q_SLOT void setScaleType(QCPAxis::ScaleType type)
A plottable that adds a set of error bars to other plottables.
Definition: qcustomplot.h:7096
void setData(QSharedPointer< QCPErrorBarsDataContainer > data)
void setDataPlottable(QCPAbstractPlottable *plottable)
void setErrorType(ErrorType type)
A plottable representing a graph in a plot.
Definition: qcustomplot.h:5996
void setScatterStyle(const QCPScatterStyle &style)
void setData(QSharedPointer< QCPGraphDataContainer > data)
void setLineStyle(LineStyle ls)
void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const
void setAntialiased(bool enabled)
Represents the visual appearance of scatter points.
Definition: qcustomplot.h:2695
@ ssCircle
\enumimage{ssCircle.png} a circle
Definition: qcustomplot.h:2744
void setInteractions(const QCP::Interactions &interactions)
QCPGraph * addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0)
virtual void mouseDoubleClickEvent(QMouseEvent *event)
QCPAxis * xAxis
Definition: qcustomplot.h:4393
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
virtual void mousePressEvent(QMouseEvent *event)
QCPAxis * yAxis
Definition: qcustomplot.h:4393
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)
@ iRangeDrag
Definition: qcustomplot.h:321
@ iRangeZoom
Definition: qcustomplot.h:325
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
Definition: sfEditDlg.h:16
constexpr Rgb red(MAX, 0, 0)