forked from githubdoe/DFTFringe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontourview.cpp
169 lines (145 loc) · 4.9 KB
/
contourview.cpp
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
/******************************************************************************
**
** Copyright 2016 Dale Eason
** This file is part of DFTFringe
** is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation version 3 of the License
** DFTFringe 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with DFTFringe. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "contourview.h"
#include "ui_contourview.h"
#include <QMenu>
#include "math.h"
#include "pixelstats.h"
#include <QSettings>
#include <QGuiApplication>
#include <QScreen>
contourView::contourView(QWidget *parent, ContourTools *tools) :
QWidget(parent),
zoomed(false), ui(new Ui::contourView), tools(tools)
{
ui->setupUi(this);
ui->widget->setTool(tools);
QSettings set;
ui->doubleSpinBox->setValue(set.value("contourRange", .100).toDouble());
ui->fillContourCB->setChecked(set.value("contourShowFill", true).toBool());
ui->showRuler->setChecked(set.value("contourShowRuler",false).toBool());
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this,
SLOT(showContextMenu(QPoint)));
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
ps = new pixelStats;
ui->LinkProfileCB->setChecked(set.value("linkProfilePlot", true).toBool());
}
contourView::~contourView()
{
delete ui;
}
void contourView::zoom(){
zoomed = !zoomed;
emit zoomMe(zoomed);
}
QImage contourView::getPixstatsImage(){
//resize(3000,2000);
int height = QGuiApplication::primaryScreen()->geometry().height() * .75;
QImage psImage = QImage(height, height,QImage::Format_ARGB32 );
QPainter p3(&psImage);
ps->resize(height * .7, height);
ps->render(&p3);
return psImage;
}
void contourView::setSurface(wavefront *wf){
getPlot()->setSurface(wf);
ps->setData(wf);
}
void contourView::showContextMenu(const QPoint &pos)
{
// Handle global position
QPoint globalPos = mapToGlobal(pos);
// Create menu and insert some actions
QMenu myMenu;
QString txt = (zoomed)? tr("Restore to MainWindow") : tr("FullScreen");
myMenu.addAction(txt, this, SLOT(zoom()));
// Show context menu at handling position
myMenu.exec(globalPos);
}
ContourPlot *contourView::getPlot(){
return ui->widget;
}
void contourView::on_doubleSpinBox_valueChanged(double arg1)
{
ui->widget->showContoursChanged(arg1);
if (arg1 == 0.){
ui->fillContourCB->setChecked(true);
on_fillContourCB_clicked(true);
}
}
void contourView::on_pushButton_pressed()
{
emit showAllContours();
}
#include <qwt_plot_histogram.h>
#include <opencv2/highgui/highgui.hpp>
cv::Mat orientationMap(const cv::Mat& mag, const cv::Mat& ori, double thresh = 1.0)
{
cv::Mat oriMap = cv::Mat::zeros(ori.size(), CV_8UC3);
cv::Vec3b red(0, 0, 255);
cv::Vec3b cyan(255, 255, 0);
cv::Vec3b green(0, 255, 0);
cv::Vec3b yellow(0, 255, 255);
for(int i = 0; i < mag.rows*mag.cols; i++)
{
float* magPixel = reinterpret_cast<float*>(mag.data + i*sizeof(float));
if(*magPixel > thresh)
{
float* oriPixel = reinterpret_cast<float*>(ori.data + i*sizeof(float));
cv::Vec3b* mapPixel = reinterpret_cast<cv::Vec3b*>(oriMap.data + i*3*sizeof(char));
if(*oriPixel < 90.0)
*mapPixel = red;
else if(*oriPixel >= 90.0 && *oriPixel < 180.0)
*mapPixel = cyan;
else if(*oriPixel >= 180.0 && *oriPixel < 270.0)
*mapPixel = green;
else if(*oriPixel >= 270.0 && *oriPixel < 360.0)
*mapPixel = yellow;
}
}
return oriMap;
}
void contourView::on_histogram_clicked()
{
ps->show();
}
void contourView::on_fillContourCB_clicked(bool checked)
{
QSettings set;
ui->widget->showSpectrogram(checked);
}
void contourView::updateRuler(){
if (getPlot()->m_wf){
QSettings settings;
getPlot()->m_rulerPen = QPen(QColor(settings.value("ContourRulerColor", "grey").toString()));
getPlot()->m_radialDeg = settings.value("contourRulerRadialDeg",30).toInt();
setSurface(getPlot()->m_wf);
}
}
void contourView::on_showRuler_clicked(bool checked)
{
QSettings set;
set.setValue("contourShowRuler", checked);
if (getPlot()->m_wf)
setSurface(getPlot()->m_wf);
}
void contourView::on_LinkProfileCB_clicked(bool checked)
{
QSettings set;
set.setValue("linkProfilePlot", checked);
getPlot()->m_linkProfile = checked;
}