Skip to content

Commit 470001a

Browse files
authored
Merge pull request #263 from githubdoe/JST/squareContourview
merging this because it's a great feature and also because I think I want to look into fixing issue #302 and I want to do that with this code included as it might be related to issue #302.
2 parents eb57e02 + 8ad3499 commit 470001a

File tree

9 files changed

+260
-83
lines changed

9 files changed

+260
-83
lines changed

contourplot.cpp

Lines changed: 211 additions & 35 deletions
Large diffs are not rendered by default.

contourplot.h

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,11 @@
2727
#include "wavefront.h"
2828
#include <qwt_picker.h>
2929
#include <qwt_plot_picker.h>
30+
#include <qwt_plot_rescaler.h>
3031
#include <qwt_interval.h>
3132

3233
class MyZoomer;
33-
class SpectrogramData: public QwtRasterData
34-
{
35-
public:
36-
SpectrogramData();
37-
wavefront *m_wf;
38-
void setSurface(wavefront *surface);
39-
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
40-
// keep compatibility with newer version of QWT used in QT6
41-
QwtInterval interval(Qt::Axis axis) const override;
42-
void setInterval(Qt::Axis axis, const QwtInterval &interval);
43-
#endif
44-
virtual double value( double x, double y ) const override;
4534

46-
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
47-
// keep compatibility with newer version of QWT used in QT6
48-
private:
49-
QwtInterval m_xInterval;
50-
QwtInterval m_yInterval;
51-
QwtInterval m_zInterval;
52-
#endif
53-
};
5435
class ContourPlot: public QwtPlot
5536
{
5637
Q_OBJECT
@@ -60,26 +41,29 @@ class ContourPlot: public QwtPlot
6041

6142
public:
6243
QwtPlotSpectrogram *d_spectrogram;
63-
wavefront* m_wf;
44+
const wavefront* m_wf;
6445
ContourTools *m_tools;
6546
static bool m_useMiddleOffset;
6647
static int m_colorMapNdx;
6748
static double m_zOffset;
6849
static double m_waveRange;
6950
double contourRange;
7051
static QString m_zRangeMode;
71-
ContourPlot(QWidget * = NULL, ContourTools *tools = 0, bool minimal = false);
72-
void setSurface(wavefront * mat);
52+
ContourPlot(QWidget *parent = NULL, ContourTools *tools = 0, bool minimal = false);
53+
void setSurface(const wavefront * wft);
7354
void applyZeroOffset(bool useMiddle);
7455
void setZRange();
7556
void setColorMap(int ndx);
7657
void setTool(ContourTools* tool);
77-
bool m_autoInterval;
78-
bool m_minimal;
58+
QRectF adjustRectToAspectRatio(double baseWidth, double baseHeight,
59+
double canvasWidth, double canvasHeight) const;
60+
void updateAspectRatio();
61+
bool m_minimal; // when true, hide axes and colorbar
7962
bool m_linkProfile;
8063
QPen m_rulerPen;
8164
int m_radialDeg;
8265
bool m_do_fill;
66+
bool m_inZoomOperation;
8367

8468

8569
signals:
@@ -102,14 +86,15 @@ public slots:
10286
void contourFillChanged(int);
10387
void newDisplayErrorRange(double min, double max);
10488
void drawProfileLine(const double ang);
89+
void clearZoomFlag();
10590
#ifndef QT_NO_PRINTER
10691
void printPlot();
10792
#endif
10893

10994
private:
11095
void drawCanvas(QPainter* p);
11196
void initPlot();
112-
97+
bool eventFilter(QObject *obj, QEvent *event);
11398

11499
QColor m_contourPen;
115100

contourview.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ QImage contourView::getPixstatsImage(){
6363
}
6464

6565

66-
void contourView::setSurface(wavefront *wf){
66+
void contourView::setSurface(const wavefront *wf){
6767
getPlot()->setSurface(wf);
6868
ps->setData(wf);
6969
}
@@ -81,6 +81,7 @@ void contourView::showContextMenu(QPoint pos)
8181
// Show context menu at handling position
8282
myMenu.exec(globalPos);
8383
}
84+
8485
ContourPlot *contourView::getPlot(){
8586
return ui->widget;
8687
}

contourview.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ class contourView : public QWidget
3434
explicit contourView(QWidget *parent = 0, ContourTools *tools = 0);
3535
~contourView();
3636
ContourPlot *getPlot();
37-
void setSurface(wavefront * wf);
38-
bool zoomed;
37+
void setSurface(const wavefront * wf);
38+
bool zoomed; // this is not about zooming in the plot, but zooming the contour view to full screen
3939
QImage getPixstatsImage();
4040
pixelStats *getPixelstats(){ return ps;}
4141
signals:
4242
void lineSpacingChanged(double);
4343
void showAllContours();
44-
void zoomMe(bool);
44+
void zoomMe(bool); // full screen related
4545
private slots:
4646
void on_doubleSpinBox_valueChanged(double arg1);
4747
void showContextMenu(QPoint pos);
4848
void on_pushButton_pressed();
49-
void zoom();
49+
void zoom(); // full screen related
5050

5151
void on_histogram_clicked();
5252

dftcolormap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ QList<colorStop> dftColorMap::userStops;
2626

2727

2828

29-
dftColorMap::dftColorMap(int type, wavefront *wf, bool zeroBased, double errorMargin, double scale,
29+
dftColorMap::dftColorMap(int type, const wavefront *wf, bool zeroBased, double errorMargin, double scale,
3030
QColor less, QColor more):
3131
QwtLinearColorMap( less, more ),m_wf(wf)
3232
{

dftcolormap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
class dftColorMap: public QwtLinearColorMap
2525
{
2626
public:
27-
dftColorMap(int type = 0, wavefront *wf= 0, bool zeroBased = true,
27+
dftColorMap(int type = 0, const wavefront *wf= 0, bool zeroBased = true,
2828
double errorMargin = .125, double scale = 1., QColor less = Qt::black,
2929
QColor more = Qt::white);
3030
void setRange(double low, double high);
31-
wavefront *m_wf;
31+
const wavefront *m_wf;
3232
static QList<colorStop> userStops;
3333
};
3434
#endif // DFTCOLORMAP_H

pixelstats.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <opencv2/core/core.hpp>
2121
#include <opencv2/highgui/highgui.hpp>
2222
#include <opencv2/imgproc/imgproc.hpp>
23-
#include "contourplot.h"
2423
#include "wavefront.h"
2524
#include "math.h"
2625
#include "utils.h"
@@ -296,7 +295,7 @@ pixelStats::~pixelStats()
296295

297296
}
298297

299-
void pixelStats::setData(wavefront *w){
298+
void pixelStats::setData(const wavefront *w){
300299
m_wf = w;
301300
g_ub = m_wf->min + (m_wf->max-m_wf->min) * .9;
302301
g_lb = m_wf->min + (m_wf->max-m_wf->min) * .1;
@@ -312,7 +311,7 @@ cv::Mat mat2gray(const cv::Mat& src)
312311
return dst;
313312
}
314313

315-
cv::Mat slope(wavefront * wf){
314+
cv::Mat slope(const wavefront * wf){
316315
int half = wf->data.cols/2;
317316
cv::Mat gradx = cv::Mat::zeros(wf->data.rows,wf->data.cols, CV_64FC1);
318317
cv::Mat grady = cv::Mat::zeros(wf->data.rows,wf->data.cols, CV_64FC1);
@@ -406,7 +405,7 @@ cv::Mat slope(wavefront * wf){
406405
*/
407406
return mag;
408407
}
409-
#include "dftarea.h"
408+
410409
void pixelStats::updateSurface(){
411410
try {
412411
cv::Mat sur = cv::Mat::zeros(m_wf->data.rows, m_wf->data.cols, CV_8UC3);

pixelstats.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class pixelStats : public QWidget
1919
public:
2020
explicit pixelStats(QWidget *parent = 0);
2121
~pixelStats();
22-
void setData(wavefront *w);
22+
void setData(const wavefront *w);
2323
private slots:
2424
void bounds_valueChanged();
2525

@@ -33,7 +33,7 @@ private slots:
3333

3434
private:
3535
Ui::pixelStats *ui;
36-
wavefront *m_wf;
36+
const wavefront *m_wf;
3737
cv::Mat mask;
3838
void updateHisto();
3939
void updateSurface();

surfacemanager.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,24 +2738,24 @@ void SurfaceManager::saveAllContours(){
27382738
m_allContours.save( fName );
27392739
}
27402740

2741-
#include "showallcontoursdlg.h"
2742-
void SurfaceManager::showAllContours(){
2743-
showAllContoursDlg dlg;
2741+
#include "showallcontoursdlg.h" //TODO move
2742+
void SurfaceManager::showAllContours(){ //TODO move to contourview would make more sense as use only there
2743+
showAllContoursDlg dlg; //TODO not closing on app close
27442744
if (!dlg.exec()) {
27452745
return;
27462746
}
27472747
QRect rec = QGuiApplication::primaryScreen()->geometry();
27482748
QApplication::setOverrideCursor(Qt::WaitCursor);
2749-
ContourPlot *plot =new ContourPlot(0,0);//m_contourPlot;
2750-
//plot->m_minimal = true;
2751-
int cols = dlg.getColumns();
2749+
ContourPlot *plot =new ContourPlot(0,0);//m_contourPlot; //TODO leaking ?
2750+
//plot->m_minimal = true;
2751+
int cols = dlg.getColumns(); //TODO parameter number of pixels unused here. update the dlg ui
27522752
int width = rec.width()/cols;
27532753
int height = width * .82;
27542754
surfaceAnalysisTools *saTools = surfaceAnalysisTools::get_Instance();
27552755
QList<int> list = saTools->SelectedWaveFronts();
27562756

2757-
int rows = ceil((double)list.size()/cols);
2758-
int columns = std::min((int)list.size(),int(ceil((double)list.size()/rows)));
2757+
int rows = ceil((float)list.size()/cols);
2758+
int columns = std::min((int)list.size(),int(ceil((float)list.size()/rows)));
27592759
const QSizeF size(columns * (width + 10), rows * (height + 10));
27602760
const QRect imageRect = QRect(0,0,size.width(),size.height());
27612761
qDebug() << "save all" << imageRect;
@@ -2774,11 +2774,27 @@ void SurfaceManager::showAllContours(){
27742774
{
27752775
wavefront * wf = m_wavefronts[list[i]];
27762776
plot->setSurface(wf);
2777+
2778+
//All these replots and updates are necessary to get the canvas updateAspectRatio to work properly.
2779+
2780+
// Resize the outer plot so its internal canvas area will match
2781+
// the requested image size.
2782+
plot->resize(width, height);
2783+
QCoreApplication::processEvents();
2784+
// Now ensure the canvas is the target size
2785+
if (plot->canvas())
2786+
plot->canvas()->resize(width, height);
2787+
plot->updateAspectRatio();
2788+
plot->replot();
2789+
plot->updateAspectRatio();
27772790
plot->replot();
2791+
2792+
27782793
int y_offset = height * (i/columns) + 10;
27792794
int x_offset = width * (i%columns) + 10;
27802795
const QRectF topRect( x_offset, y_offset, width, height );
27812796
renderer.render( plot, &painter, topRect );
2797+
27822798
}
27832799
painter.end();
27842800

0 commit comments

Comments
 (0)