File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
QHistogram.cpp
1
6
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "QHistogram.h"
10#include "Histogram.h"
11#include "IException.h"
12#include <QFileDialog>
13#include <QPrintDialog>
14#include <QPainter>
15#include <QPrinter>
16#include <QMessageBox>
17#include <QFileInfo>
18#include <QVBoxLayout>
19#include <QLabel>
20
21#include <qwt_plot_curve.h>
22#include <qwt_plot_zoomer.h>
23#include <qwt_text.h>
24
25using namespace std;
26namespace Isis {
27
28
36 p_zoomer = new QwtPlotZoomer(this->canvas());
37 setTitle("Histogram Plot");
38
39 QwtText *leftLabel = new QwtText("Frequency", QwtText::PlainText);
40 leftLabel->setColor(Qt::red);
41 QFont font = leftLabel->font();
42 font.setPointSize(13);
43 font.setBold(true);
44 leftLabel->setFont(font);
45 setAxisTitle(QwtPlot::yLeft, *leftLabel);
46
47 QwtText *rtLabel = new QwtText("Percentage");
48 rtLabel->setColor(Qt::blue);
49 rtLabel->setFont(font);
50 setAxisTitle(QwtPlot::yRight, *rtLabel);
51
52 setAxisTitle(QwtPlot::xBottom, "Pixel Value (DN)");
53
54 setAxisScale(QwtPlot::yRight, 0, 100);
55 enableAxis(QwtPlot::yRight, true);
56 setCanvasBackground(Qt::white);
57 }
58
59
67 p_histCurve->setStyle(QwtPlotCurve::Lines);
68
70 p_cdfCurve->setStyle(QwtPlotCurve::Lines);
71
72 //Transfer data from histogram to the plotcurve
73 QVector<QPointF> histData;
74 QVector<QPointF> cdfData;
75 double cumpct = 0.0;
76 for(int i = 0; i < hist.Bins(); i++) {
77 if(hist.BinCount(i) > 0) {
78 histData.append(QPointF(hist.BinMiddle(i), hist.BinCount(i)));
79
80 double pct = (double)hist.BinCount(i) / hist.ValidPixels() * 100.;
81 cumpct += pct;
82 cdfData.append(QPointF(hist.BinMiddle(i), cumpct));
83 }
84 }
85 QPen *pen = new QPen(Qt::red);
86 pen->setWidth(2);
87 p_histCurve->setData(new QwtPointSeriesData(histData));
88 p_histCurve->setYAxis(QwtPlot::yLeft);
89 p_histCurve->setPen(*pen);
90 p_histCurve->attach(this);
91
92 pen->setColor(Qt::blue);
93 p_cdfCurve->setData(new QwtPointSeriesData(cdfData));
94 p_cdfCurve->setYAxis(QwtPlot::yRight);
95 p_cdfCurve->setPen(*pen);
96 p_cdfCurve->attach(this);
97
98 this->replot();
99 p_zoomer->setZoomBase();
100 }
101
102
108 if(p_zoomer->trackerMode() == QwtPicker::ActiveOnly) {
109 p_zoomer->setTrackerMode(QwtPicker::AlwaysOn);
110 }
111 else {
112 p_zoomer->setTrackerMode(QwtPicker::ActiveOnly);
113 }
114 }
115
116
122 p_cdfCurve->setVisible(!p_cdfCurve->isVisible());
123 this->replot();
124 }
125
126
132 // Initialize a printer
133 static QPrinter *printer = NULL;
134 if(printer == NULL) printer = new QPrinter;
135 QPageSize pageSize(QPageSize::Letter);
136 printer->setPageSize(pageSize);
137 printer->setColorMode(QPrinter::Color);
138
139 QPrintDialog printDialog(printer, (QWidget *)parent());
140 if(printDialog.exec() == QDialog::Accepted) {
141 // Get display widget as a pixmap and convert to an image
142 QPixmap pixmap = this->grab();
143 QImage img = pixmap.toImage();
144
145 // C++ Gui Programmign with Qt, page 201
146 QPainter painter(printer);
147 QRect rect = painter.viewport();
148 QSize size = img.size();
149 size.scale(rect.size(), Qt::KeepAspectRatio);
150 painter.setViewport(rect.x(), rect.y(),
151 size.width(), size.height());
152 painter.setWindow(img.rect());
153 painter.drawImage(0, 0, img);
154 }
155
156 }
157
158
164 QString output =
165 QFileDialog::getSaveFileName((QWidget *)parent(),
166 "Choose output file",
167 "./",
168 QString("Images (*.png *.jpg *.tif)"));
169 if(output.isEmpty()) return;
170
171 QString format = QFileInfo(output).suffix();
172 QPixmap pixmap = this->grab();
173 std::string formatString = format.toStdString();
174 if(!pixmap.save(output, formatString.c_str())) {
175 QMessageBox::information((QWidget *)parent(), "Error", "Unable to save" + output);
176 return;
177 }
178 }
179
180
186 QPen *pen = new QPen(Qt::white);
187 if(canvasBackground() == Qt::white) {
188 setCanvasBackground(Qt::black);
189 p_zoomer->setRubberBandPen(*pen);
190 p_zoomer->setTrackerPen(*pen);
191 }
192 else {
193 setCanvasBackground(Qt::white);
194 pen->setColor(Qt::black);
195 p_zoomer->setRubberBandPen(*pen);
196 p_zoomer->setTrackerPen(*pen);
197 }
198 replot();
199 }
200
201
207 QDialog *d = new QDialog(this);
208 d->setWindowTitle("Basic Help");
209
210 QLabel *zoomLabel = new QLabel("Zoom Options:");
211 QLabel *zoomIn = new
212 QLabel(" <b>Left click</b> on the mouse, drag, and release to select an area to zoom in on");
213 QLabel *zoomOut = new
214 QLabel(" <b>Middle click</b> on the mouse to zoom out one level");
215 QLabel *zoomReset = new
216 QLabel(" <b>Right click</b> on the mouse to clear the zoom and return to the original plot");
217
218 QVBoxLayout *layout = new QVBoxLayout();
219 layout->addWidget(zoomLabel);
220 layout->addWidget(zoomIn);
221 layout->addWidget(zoomOut);
222 layout->addWidget(zoomReset);
223
224 d->setLayout(layout);
225 d->show();
226 }
227
228} // end namespace isis
Container of a cube histogram.
Definition Histogram.h:74
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.
QwtPlotCurve * p_cdfCurve
CDF plot curve.
Definition QHistogram.h:56
QwtPlotCurve * p_histCurve
Historgram plot curve.
Definition QHistogram.h:55
void savePlot()
Allows user to save the plot to an image file.
QHistogram(QWidget *parent=NULL)
Constructs a QHistogram object with default titles.
QwtPlotZoomer * p_zoomer
Plot Zoomer.
Definition QHistogram.h:54
void showHelp()
Provides help text in a dialog box.
void cdfCurveVisible()
Hide/show the cdf curve.
void printPlot()
Provide printing capabilities.
void switchBackground()
Switches the plot background color between black and white.
void trackerEnabled()
Enables mouse tracking on the plot.
void Load(Histogram &hist)
Plots the given Isis Histogram in the plot window.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
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
Namespace for the standard library.