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

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:35