File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
HistogramWidget.cpp
1#include "HistogramWidget.h"
2
3#include <QHBoxLayout>
4#include <QLayout>
5#include <QLabel>
6#include <QString>
7#include <QColor>
8
9#include <qwt_symbol.h>
10#include <qwt_scale_div.h>
11#include <qwt_plot_zoomer.h>
12#include <qwt_scale_engine.h>
13#include <qwt_text.h>
14
15namespace Isis {
24 HistogramWidget::HistogramWidget(const QString title, const QColor histColor, const QColor stretchColor) :
25 QwtPlot(QwtText(title)) {
26 setCanvasBackground(Qt::white);
27 enableAxis(QwtPlot::yRight);
28 setAxisScale(QwtPlot::xBottom, 0, 255);
29 setAxisLabelRotation(QwtPlot::xBottom, 45);
30 setAxisScale(QwtPlot::yRight, 0, 255);
31
32 QwtText axisTitle;
33 QFont axisFont;
34 axisFont.setBold(true);
35 axisTitle.setFont(axisFont);
36 axisTitle.setText("Frequency");
37 setAxisTitle(QwtPlot::yLeft, axisTitle);
38 axisTitle.setText("Input (Cube DN)");
39 setAxisTitle(QwtPlot::xBottom, axisTitle);
40 axisTitle.setText("Output");
41 setAxisTitle(QwtPlot::yRight, axisTitle);
42
44 p_histCurve->setColor(histColor);
45
47 p_stretchCurve->setYAxis(QwtPlot::yRight);
48 p_stretchCurve->setPen(QPen(QBrush(stretchColor), 2, Qt::DashLine));
49 p_stretchCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, QBrush(stretchColor), QPen(stretchColor), QSize(5, 5)));
50
51 p_histCurve->attach(this);
52 p_stretchCurve->attach(this);
53
54 p_zoomer = new QwtPlotZoomer(canvas());
55 p_zoomer->setZoomBase();
56 }
57
58
65 std::vector<double> xarray, yarray;
66 for(int i = 0; i < hist.Bins(); i++) {
67 if(hist.BinCount(i) > 0) {
68 xarray.push_back(hist.BinMiddle(i));
69
70 double freq = (double)hist.BinCount(i) / (double)hist.MaxBinCount();
71 yarray.push_back(freq * 100.0);
72 }
73 }
74
75 //These are all variables needed in the following for loop.
76 //----------------------------------------------
77 QVector<QwtIntervalSample> intervals(xarray.size());
78 double maxYValue = DBL_MIN;
79 double minYValue = DBL_MAX;
80 // ---------------------------------------------
81
82 for(unsigned int y = 0; y < yarray.size(); y++) {
83 intervals[y].interval = QwtInterval(xarray[y], xarray[y] + hist.BinSize());
84
85 intervals[y].value = yarray[y];
86 if(yarray[y] > maxYValue)
87 maxYValue = yarray[y];
88 if(yarray[y] < minYValue)
89 minYValue = yarray[y];
90 }
91
92 QwtScaleDiv scaleDiv;
93
94 p_histCurve->setData(QwtIntervalSeriesData(intervals));
95
96 double min = hist.Minimum();
97 double max = hist.Maximum();
98 int maxMajor = 5;
99 int maxMinor = 20;
100
101 // Find a good, fixed, axis scale
102 QwtScaleEngine *engine = axisScaleEngine(QwtPlot::xBottom);
103 QwtScaleDiv scale = engine->divideScale(min, max, maxMajor, maxMinor);
104 QwtInterval interval = scale.interval();
105 setAxisScale(QwtPlot::xBottom,
106 interval.minValue() - hist.BinSize(),
107 interval.maxValue() + hist.BinSize());
108 p_zoomer->setZoomBase();
109 }
110
117 QVector<QPointF> curvePoints(stretch.Pairs());
118 for(int i = 0; i < stretch.Pairs(); i++) {
119 curvePoints[i] = QPointF(stretch.Input(i), stretch.Output(i));
120 }
121
122 p_stretchCurve->setData(new QwtPointSeriesData(curvePoints));
123 replot();
124 }
125
131 p_stretchCurve->setData(new QwtPointSeriesData());
132 replot();
133 }
134}
Container of a cube histogram.
Definition Histogram.h:74
double BinSize() const
Returns the size of an individual bin.
BigInt BinCount(const int index) const
Returns the count at a bin position in the histogram.
double BinMiddle(const int index) const
Returns the value represented by a bin.
int Bins() const
Returns the number of bins in the histogram.
BigInt MaxBinCount() const
Returns the highest bin count.
This is the (qwt) plot item for a histogram.
void clearStretch()
Clears the stretch curve from the plot.
QwtPlotZoomer * p_zoomer
This allows for zooming in/out.
QwtPlotCurve * p_stretchCurve
The stretch curve.
void setStretch(Stretch stretch)
Creates a stretch curbe from the given stretch and plots it.
HistogramWidget(const QString title, const QColor histColor=Qt::gray, const QColor stretchColor=Qt::darkGray)
HistogramWidget constructor.
void setHistogram(const Histogram &hist)
Creates a histogram curve from the given histogram and plots it.
HistogramItem * p_histCurve
The histogram curve.
double Minimum() const
Returns the absolute minimum double found in all data passed through the AddData method.
double Maximum() const
Returns the absolute maximum double found in all data passed through the AddData method.
Pixel value mapper.
Definition Stretch.h:58
double Output(const int index) const
Returns the value of the output side of the stretch pair at the specified index.
Definition Stretch.cpp:302
double Input(const int index) const
Returns the value of the input side of the stretch pair at the specified index.
Definition Stretch.cpp:287
int Pairs() const
Returns the number of stretch pairs.
Definition Stretch.h:162
This is free and unencumbered software released into the public domain.
Definition Calculator.h:18
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16