ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvHistogramWindow.h
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 #pragma once
9 
10 // Qt
11 #include <QDialog>
12 
13 // CV_DB_LIB
14 #include <ecvScalarField.h>
15 
16 // QCustomPlot
17 #include <qcustomplot.h>
18 
19 class QCPArrow;
20 class QCPBarsWithText;
21 class QCPColoredBars;
22 class QCPHiddenArea;
23 class QCPTextElement;
24 
25 class Ui_HistogramDialog;
26 
28 class ccHistogramWindow : public QCustomPlot {
29  Q_OBJECT
30 
31 public:
33  explicit ccHistogramWindow(QWidget* parent = 0);
34 
36  virtual ~ccHistogramWindow();
37 
39  void setTitle(const QString& str);
41  void setAxisLabels(const QString& xLabel, const QString& yLabel);
42 
44 
51  void fromSF(ccScalarField* sf,
52  unsigned initialNumberOfClasses = 0,
53  bool numberOfClassesCanBeChanged = true,
54  bool showNaNValuesInGrey = true);
55 
58 
64  void fromBinArray(const std::vector<unsigned>& histoValues,
65  double minVal,
66  double maxVal);
67 
69 
73  void setCurveValues(const std::vector<double>& curveValues);
74 
79  };
82  m_colorScheme = scheme;
83  }
84 
86 
87  void setSolidColor(QColor color) { m_solidColor = color; }
89 
91 
93  void clear();
95  void refresh();
97 
99  void refreshBars();
100 
102  inline const std::vector<unsigned>& histoValues() const {
103  return m_histoValues;
104  }
106  inline double minVal() const { return m_minVal; }
108  inline double maxVal() const { return m_maxVal; }
109 
110 public: // Axis label display Options
111  enum class AxisDisplayOption {
112  None = 0x0,
113  XAxis = 0x01,
114  YAxis = 0x02,
115  All = XAxis | YAxis
116  };
117  Q_DECLARE_FLAGS(AxisDisplayOptions, AxisDisplayOption)
118 
119  // SF interactor mode
120  enum class SFInteractionMode {
121  None = 0x0,
122  DisplayRange = 0x01,
123  SaturationRange = 0x02,
124  All = DisplayRange | SaturationRange
125  };
126  Q_DECLARE_FLAGS(SFInteractionModes, SFInteractionMode)
127 
128 
129  void setSFInteractionMode(SFInteractionModes modes);
130  void setAxisDisplayOption(AxisDisplayOptions axisOptions);
131  // Used to disable automatic refresh after resize event
132  // Must refresh manually from client code if this is set to false
133  void setRefreshAfterResize(bool refreshAfterResize);
134 
135  void setMinDispValue(double);
136  void setMaxDispValue(double);
137  void setMinSatValue(double);
138  void setMaxSatValue(double);
139 
140 signals:
141 
142  void sfMinDispValChanged(double);
143  void sfMaxDispValChanged(double);
144  void sfMinSatValChanged(double);
145  void sfMaxSatValChanged(double);
146 
147 protected: // methods
149 
151  void setNumberOfClasses(size_t n);
152 
153  // mouse events handling
154  void mousePressEvent(QMouseEvent* event);
155  void mouseMoveEvent(QMouseEvent* event);
156  void wheelEvent(QWheelEvent* event);
157  void resizeEvent(QResizeEvent* event);
158 
160  unsigned getMaxHistoVal();
161 
163  void clearInternal();
164 
166  bool computeBinArrayFromSF(size_t binCount);
167 
169  void updateOverlayCurveWidth(int w, int h);
170 
171 protected: // attributes
172  // Title
173  QString m_titleStr;
174  QCPTextElement* m_titlePlot;
175 
179  QColor m_solidColor;
182 
185  // Whether the number of classes can be changed or not
189 
191 
192  // histogram data
194  std::vector<unsigned> m_histoValues;
195  double m_minVal;
196  double m_maxVal;
197  unsigned m_maxHistoVal;
198 
200  QCPGraph* m_overlayCurve;
201  std::vector<double> m_curveValues;
202 
203  // vertical indicator
207 
210 
211  AxisDisplayOptions m_axisDisplayOptions;
212 
213 protected: // SF interactor mode
215  SFInteractionModes m_sfInteractionModes;
216 
226  };
229 
236 
243 
246 };
247 
249 class ccHistogramWindowDlg : public QDialog {
250  Q_OBJECT
251 
252 public:
254  explicit ccHistogramWindowDlg(QWidget* parent = 0);
256  virtual ~ccHistogramWindowDlg();
257 
259  inline ccHistogramWindow* window() { return m_win; }
260 
262  bool exportToCSV(QString filename) const;
263 
264 protected:
266  void onExportToCSV();
267 
269  void onExportToImage();
270 
271 protected:
272  // Associated histogram window
274 
276  Ui_HistogramDialog* m_gui;
277 };
MouseEvent event
std::string filename
math::float4 color
#define signals
QCustomPlot: small arrows at the bottom.
QCustomPlot: vertical bar with text along side.
QCustomPlot: colored histogram.
QCustomPlot: greyed areas.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
Definition: ecvColorScale.h:74
Encapsulating dialog for ccHistogramWindow.
virtual ~ccHistogramWindowDlg()
Destructor.
void onExportToImage()
When the export to Image file button is pressed.
ccHistogramWindow * window()
Returns encapsulated ccHistogramWindow.
ccHistogramWindowDlg(QWidget *parent=0)
Default constructor.
ccHistogramWindow * m_win
void onExportToCSV()
When the export to CSV file button is pressed.
bool exportToCSV(QString filename) const
Exports histogram to a CSV file.
Ui_HistogramDialog * m_gui
Associated widgets.
Histogram widget.
HISTOGRAM_COLOR_SCHEME m_colorScheme
Color scheme.
void refreshBars()
Updates the histogram bars only.
void setMinDispValue(double)
void setTitle(const QString &str)
Sets title.
void setCurveValues(const std::vector< double > &curveValues)
Sets overlay curve values.
void sfMaxSatValChanged(double)
const std::vector< unsigned > & histoValues() const
Returns the current histogram bins.
virtual ~ccHistogramWindow()
Destructor.
void setColorScale(ccColorScale::Shared scale)
Sets gradient color scale.
double minVal() const
Returns the current histogram min value.
void resizeEvent(QResizeEvent *event)
QCPHiddenArea * m_areaRight
Right greyed area.
unsigned getMaxHistoVal()
Returns current maximum bin size.
void sfMinSatValChanged(double)
void wheelEvent(QWheelEvent *event)
QPoint m_lastMouseClick
Last mouse click.
QCPBarsWithText * m_vertBar
ccHistogramWindow(QWidget *parent=0)
Default constructor.
void refresh()
Updates the display.
void setColorScheme(HISTOGRAM_COLOR_SCHEME scheme)
Sets how the gradient bars should be colored.
void fromSF(ccScalarField *sf, unsigned initialNumberOfClasses=0, bool numberOfClassesCanBeChanged=true, bool showNaNValuesInGrey=true)
Computes histogram from a scalar field.
ccScalarField * m_associatedSF
Associated scalar field.
ccColorScale::Shared m_colorScale
Gradient color scale.
void sfMinDispValChanged(double)
AxisDisplayOptions m_axisDisplayOptions
void fromBinArray(const std::vector< unsigned > &histoValues, double minVal, double maxVal)
void setAxisDisplayOption(AxisDisplayOptions axisOptions)
void setRefreshAfterResize(bool refreshAfterResize)
void setSolidColor(QColor color)
Sets solid color.
SELECTABLE_ITEMS m_selectedItem
Currently selected item.
QCPHiddenArea * m_areaLeft
Left greyed area.
void setNumberOfClasses(size_t n)
Changes the current number of classes.
SELECTABLE_ITEMS
Selectable items in "SF interaction" mode.
double m_verticalIndicatorPositionPercent
QCPGraph * m_overlayCurve
Overlay curve.
void mouseMoveEvent(QMouseEvent *event)
void setSFInteractionMode(SFInteractionModes modes)
Enables SF interaction mode.
QCPArrow * m_arrowRight
Right arrow.
void sfMaxDispValChanged(double)
bool computeBinArrayFromSF(size_t binCount)
Dynamically computes histogram bins from scalar field.
QCPColoredBars * m_histogram
std::vector< double > m_curveValues
void mousePressEvent(QMouseEvent *event)
double maxVal() const
Returns the current histogram max value.
QFont m_renderingFont
Rendering font.
QColor m_solidColor
Solid color.
void setMaxDispValue(double)
SFInteractionModes m_sfInteractionModes
Which SF interaction modes are enabled.
void clear()
Clears the display.
QCPArrow * m_arrowLeft
Left arrow.
std::vector< unsigned > m_histoValues
void setAxisLabels(const QString &xLabel, const QString &yLabel)
Sets axis labels.
QCPTextElement * m_titlePlot
void updateOverlayCurveWidth(int w, int h)
Updates overlay curve width depending on the widget display size.
A scalar field associated to display-related parameters.