-
Notifications
You must be signed in to change notification settings - Fork 1
/
Histogram_Plot.hh
292 lines (218 loc) · 8.36 KB
/
Histogram_Plot.hh
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* Histogram_Plot
HiROC CVS ID: $Id: Histogram_Plot.hh,v 1.5 2012/07/21 22:34:32 castalia Exp $
Copyright (C) 2010-2011 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#ifndef HiView_Histogram_Plot_hh
#define HiView_Histogram_Plot_hh
// Qwt
#include "qwt_plot_item.h"
// Qt
#include <QColor>
// Forward references.
class QString;
template<typename T> class QVector;
namespace UA::HiRISE
{
// Forward reference.
class Count_Sequence;
/** A <i>Histogram_Plot</i> is a QwtPlotItem that produces a histogram
style plot for a graph (QwtPlot) widget.
Data, in the form of a Count_Sequence, is provided for histogram
plotting. Methods are provided to manage the color of the bars,
in addition to the QwtPlotItem controls.
@author Bradford Castalia, UA/HiROC
@version $Revision: 1.5 $
*/
class Histogram_Plot
: public QwtPlotItem
{
public:
/*==============================================================================
Constants
*/
//! Class identification name with source code version and date.
static const char* const
ID;
//! Histogram plotting attributes.
enum Attribute
{
VERTICAL_BARS = 0,
HORIZONTAL_BARS = (1 << 0)
};
/*==============================================================================
Defaults
*/
//! Default {@link bar_color(const QColor&) bar color}.
static QColor
Default_Bar_Color;
//! Default layering depth of the plot relative to other plotting layers.
static double
Default_Plot_Z;
/*==============================================================================
Constructors
*/
/** Construct a Histogram_Plot with an optional title.
The initial {@link #Attribute} setting is {@link #VERTICAL_BARS}.
The initial {@link bar_color(const QColor&) bar color} is gray.
@param title A QString providing the title of the plot.
*/
explicit Histogram_Plot (const QString& title = QString::null);
/** Construct a Histogram_Plot with a title.
The inititial {@link #Attribute} setting is {@link #VERTICAL_BARS}.
The initial {@link bar_color(const QColor&) bar color} is gray.
@param title A QwtText providing the title of the plot.
*/
explicit Histogram_Plot (const QwtText& title);
//! Destructor.
virtual ~Histogram_Plot ();
/*==============================================================================
Accessors
*/
/** Assigns a data Count_Sequence to the Histogram_Plot.
This method will result in a change to the item that may cause the
parent plot to be refreshed.
@param count_sequence A Count_Sequence to provide data content. The
Count_Sequence that is assigned is used to replace the current data
content.
@return This Histogram_Plot.
*/
Histogram_Plot& data (const Count_Sequence& count_sequence);
/** Assigns a data Count_Sequence to the Histogram_Plot.
If the specified Count_Sequence is NULL or identical to the
current Count_Sequence data content nothing is done.
If the data content Count_Sequence changes the base class is notified
that a change to the item occurred which may cause the parent plot to
be refreshed.
<b>WARNING</b>: The ownership of the assigned Count_Sequence
is transferred to this Histogram_Plot. The assigned Count_Sequence will
be deleted if this method is used with a different Count_Sequence
@param count_sequence A Count_Sequence to provide data content.
<b>N.B.</b>: The ownership of the Count_Sequence is transferred
to this Histogram_Plot. Any previous data content is deleted.
@return This Histogram_Plot.
@see data(const Count_Sequence&)
*/
Histogram_Plot& data (Count_Sequence* count_sequence);
/** Assigns a data vector to the Histogram_Plot.
The data vector is assigned to the data content Count_Sequence
which replace its data values.
This method will result in a change to the item that may cause the
parent plot to be refreshed.
@param count_sequence A QVector of unsigned long long values that
will replace the current data content.
@return This Histogram_Plot.
*/
Histogram_Plot& data (QVector<unsigned long long>& data_sequence);
/** Gets a reference to the Count_Sequence data content.
@return A Count_Sequence reference to data content.
*/
inline Count_Sequence& data ()
{return *Data;}
/** Gets a pointer to the data content vector.
<b>WARNING</b>: Direct writable access is provided to the data
content of the Histogram_Plot.
@return A QVector<unsigned long long> pointer to data content of this
Count_Sequence. <b>N.B.</b>: The data content can be externally
modified; however, unless the {@link data() data Count_Sequence}
has its {@link Count_Sequence::calculate_max_count() max count
value updated} the {@link Count_Sequence::max_count() reported
max count value} may be incorrect.
*/
QVector<unsigned long long>* data_vector ();
/** Sets the default color to use for histogram bars.
@param color The default bar color.
*/
inline static void default_bar_color (const QColor& color)
{Default_Bar_Color = color;}
/** Gets the default color to use for histogram bars.
@return The default bar color.
*/
inline static QColor default_bar_color ()
{return Default_Bar_Color;}
/** Sets the color to use for the bars of this Histogram_Plot.
@param color The bar color.
*/
Histogram_Plot& bar_color (const QColor& color);
/** Gets the color being uses for the bars of this Histogram_Plot.
@return The bar color.
*/
inline QColor bar_color () const
{return Bar_Color;}
/** Sets the default plot depth for histogram bars.
@param z_depth The default plotting depth for histogram bars.
*/
inline static void default_plot_z (double z_depth)
{Default_Plot_Z = z_depth;}
/** Gets the default plot depth for histogram bars.
@return The default plotting depth for histogram bars.
*/
inline static double default_plot_z ()
{return Default_Plot_Z;}
/** Sets an attribute of the Histogram_Plot.
@param attribute The Attribute to be set.
@param enabled Whether to enable or disable the attribute.
@return This Histogram_Plot.
*/
Histogram_Plot& attribute_set (Attribute attribute, bool enabled = true);
/** Tests the setting of a Histogram_Plot attribute.
@param attribute The Attribute to be tested.
@return Whether the attribute is enabled (true) or disabled (false).
*/
bool attribute_is_set (Attribute attribute) const;
/*==============================================================================
QwtPlotItem virtual methods implementations
*/
/** Gets the run time type information code for a Histogram_Plot.
@return QwtPlotItem::Rtti_PlotHistogram
*/
virtual int rtti () const;
/** Gets the rectange that bounds the data content.
The data content {@link Count_Sequence::boundingRect() bounding box}
is reoriented if the {@link #HORIZONTAL_BARS} attribute is set.
@return A QRectF that describes the bounding box of the
data content.
*/
virtual QRectF boundingRect () const;
/** Paints the histogram bars on a canvas region using horizontal
and vertical scaling maps.
@param painter The QPainter to use for painting the histogram
bars.
@param x_scale_map A QwtScaleMap to use for mapping horizontal (x)
postions to painter positions.
@param y_scale_map A QwtScaleMap to use for mapping vertical (y)
data content values to painter positions.
@param canvas_region A QRect specifying the limits of the
painter canvas to use.
*/
virtual void draw (QPainter* painter,
const QwtScaleMap& x_scale_map, const QwtScaleMap& y_scale_map,
const QRectF& canvas_region) const;
/*==============================================================================
Helpers
*/
private:
void initialize ();
/*==============================================================================
Data
*/
Count_Sequence
*Data;
int
Attributes;
QColor
Bar_Color;
};
} // namespace UA::HiRISE
#endif // HISTOGRAM_PLOT_HH