-
Notifications
You must be signed in to change notification settings - Fork 4
/
ccHistogramWindow.h
253 lines (199 loc) · 7.13 KB
/
ccHistogramWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
//# #
//##########################################################################
#ifndef CC_HISTOGRAM_WINDOW_HEADER
#define CC_HISTOGRAM_WINDOW_HEADER
//Always first
#include <ccIncludeGL.h>
//Qt
#include <QGLWidget>
#include <QDialog>
#include <QHBoxLayout>
#include <QFont>
#include <QString>
//qCC_db
#include <ccScalarField.h>
#include <ccColorScale.h>
//QCustomPlot
#include <qcustomplot.h>
class QCPColoredBars;
class QCPBarsWithText;
class QCPHiddenArea;
class QCPArrow;
class Ui_HistogramDialog;
//! Histogram widget
class ccHistogramWindow : public QCustomPlot
{
Q_OBJECT
public:
//! Default constructor
ccHistogramWindow(QWidget *parent = 0);
//! Destructor
virtual ~ccHistogramWindow();
//! Sets title
void setTitle(const QString& str);
//! Sets axis labels
void setAxisLabels(const QString& xLabel, const QString& yLabel);
//! Computes histogram from a scalar field
/** Number of classes can be freely modified afterwards (if enabled).
\param sf associated scalar field
\param initialNumberOfClasses initial number of classes
\param numberOfClassesCanBeChanged whether to allow the user to modify the number of classes
\return success
**/
void fromSF(ccScalarField* sf,
unsigned initialNumberOfClasses = 0,
bool numberOfClassesCanBeChanged = true);
//! Creates histogram from a bin array (each bin = number of elements per class)
/** Number of classes can't be modified.
\param histoValues array of bins
\param minVal minimum value
\param maxVal maximum value
\return success
**/
void fromBinArray( const std::vector<unsigned>& histoValues,
double minVal,
double maxVal);
//! Sets overlay curve values
/** The curve will only appear over an histogram
\param curveValues curve points 'Y' coordinates only (regularly sampled between the min and max histogram values)
**/
void setCurveValues(const std::vector<double>& curveValues);
enum HISTOGRAM_COLOR_SCHEME { USE_SOLID_COLOR, USE_CUSTOM_COLOR_SCALE, USE_SF_SCALE };
//! Sets how the gradient bars should be colored
void setColorScheme(HISTOGRAM_COLOR_SCHEME scheme) { m_colorScheme = scheme; }
//! Sets solid color
/** Only used if color scheme is set to USE_SOLID_COLOR. **/
void setSolidColor(QColor color) { m_solidColor = color; }
//! Sets gradient color scale
/** Only used if color scheme is set to USE_CUSTOM_COLOR_SCALE. **/
void setColorScale(ccColorScale::Shared scale) { m_colorScale = scale; }
//! Clears the display
void clear();
//! Updates the display
void refresh();
//! Updates the histogram bars only
/** Only works if a SF is associated and color scheme is USE_SF_SCALE.
**/
void refreshBars();
//! Returns the current histogram bins
inline const std::vector<unsigned>& histoValues() const { return m_histoValues; }
//! Returns the current histogram min value
inline double minVal() const { return m_minVal; }
//! Returns the current histogram max value
inline double maxVal() const { return m_maxVal; }
public: //SF interactor mode
//! Enables SF interaction mode
void enableSFInteractionMode(bool state) { m_sfInteractionMode = state; }
void setMinDispValue(double);
void setMaxDispValue(double);
void setMinSatValue(double);
void setMaxSatValue(double);
signals:
void sfMinDispValChanged(double);
void sfMaxDispValChanged(double);
void sfMinSatValChanged(double);
void sfMaxSatValChanged(double);
protected: //methods
//! Changes the current number of classes
/** Warning: n should be a multiple of 4.
**/
void setNumberOfClasses(size_t n);
//mouse events handling
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent* event);
void resizeEvent(QResizeEvent * event);
//! Returns current maximum bin size
unsigned getMaxHistoVal();
//! Clears internal structures
void clearInternal();
//! Dynamically computes histogram bins from scalar field
bool computeBinArrayFromSF(size_t binCount);
//! Updates overlay curve width depending on the widget display size
void updateOverlayCurveWidth(int w, int h);
protected: //attributes
//Title
QString m_titleStr;
QCPPlotTitle* m_titlePlot;
//! Color scheme
HISTOGRAM_COLOR_SCHEME m_colorScheme;
//! Solid color
QColor m_solidColor;
//! Gradient color scale
ccColorScale::Shared m_colorScale;
//! Associated scalar field
ccScalarField* m_associatedSF;
//Whether the number of classes can be changed or not
/** Only possible with an associated scalar field.
**/
bool m_numberOfClassesCanBeChanged;
//histogram data
QCPColoredBars* m_histogram;
std::vector<unsigned> m_histoValues;
double m_minVal;
double m_maxVal;
unsigned m_maxHistoVal;
//! Overlay curve
QCPGraph* m_overlayCurve;
std::vector<double> m_curveValues;
//vertical indicator
QCPBarsWithText* m_vertBar;
bool m_drawVerticalIndicator;
double m_verticalIndicatorPositionPercent;
//! Rendering font
QFont m_renderingFont;
protected: //SF interactor mode
//! Whether SF interaction mode is enabled or not
bool m_sfInteractionMode;
//! Selectable items in "SF interaction" mode
enum SELECTABLE_ITEMS { NONE, LEFT_AREA, RIGHT_AREA, BOTH_AREAS, LEFT_ARROW, RIGHT_ARROW, BOTH_ARROWS };
//! Currently selected item
SELECTABLE_ITEMS m_selectedItem;
//! Left greyed area
QCPHiddenArea* m_areaLeft;
//! Right greyed area
QCPHiddenArea* m_areaRight;
//! Left arrow
QCPArrow* m_arrowLeft;
//! Right arrow
QCPArrow* m_arrowRight;
//! Last mouse click
QPoint m_lastMouseClick;
};
//! Encapsulating dialog for ccHistogramWindow
class ccHistogramWindowDlg : public QDialog
{
Q_OBJECT
public:
//! Default constructor
ccHistogramWindowDlg(QWidget* parent = 0);
//! Destructor
virtual ~ccHistogramWindowDlg();
//! Returns encapsulated ccHistogramWindow
inline ccHistogramWindow* window() { return m_win; }
//! Exports histogram to a CSV file
bool exportToCSV(QString filename) const;
protected slots:
//! When the export to CSV file button is pressed
void onExportToCSV();
protected:
//Associated histogram window
ccHistogramWindow* m_win;
//! Associated widgets
Ui_HistogramDialog* m_gui;
};
#endif