-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsurfacegraph.cpp
More file actions
222 lines (166 loc) · 5.58 KB
/
surfacegraph.cpp
File metadata and controls
222 lines (166 loc) · 5.58 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "surfacegraph.h"
#include "def_commands.h"
#include <QtDataVisualization/QValue3DAxis>
#include <QtDataVisualization/Q3DTheme>
#include <QtGui/QImage>
#include <QtCore/qmath.h>
#include <QFileDialog>
#include <QMessageBox>
#include <QDate>
#include <QTime>
using namespace QtDataVisualization;
SurfaceGraph::SurfaceGraph(Q3DSurface *surface, QWidget *parent,QList<int> parameters)
:QObject(parent)
{
this->parameters=parameters;
m_graph=surface;
m_graph->setAxisX(new QValue3DAxis);
m_graph->setAxisY(new QValue3DAxis);
m_graph->setAxisZ(new QValue3DAxis);
AFM_Proxy=new QSurfaceDataProxy();
AFM_Series = new QSurface3DSeries(AFM_Proxy);
AFM_Series->setMeshSmooth(true);
AFM_Proxy->resetArray(NULL);
m_graph->scene()->activeCamera()->setCameraPreset(Q3DCamera::CameraPresetFront);
}
void SurfaceGraph::fillAFMProxy(QList <QByteArray> data, bool load, QTextStream *stream)
{
if(load){
int temp;
QVector3D vect;
*stream>>temp;
sampleCountX=temp;
bool addingData=true;
while(!stream->atEnd()&&addingData){
QSurfaceDataRow *newRow = new QSurfaceDataRow(sampleCountX);
for(int i=0;i<sampleCountX;++i){
*stream>>temp;
vect.setX(temp);
*stream>>temp;
vect.setY(temp);
*stream>>temp;
if(temp==0){
addingData=false;
break;
}
vect.setZ(temp);
(*newRow)[i].setPosition(vect);
}
if(addingData){AFM_Proxy->insertRow(AFM_Proxy->rowCount(),newRow);}
}
m_graph->axisZ()->setRange(0,AFM_Proxy->rowCount()+2);
}
if(!load){
float stepX = parameters[2];
qDebug()<<data.size();
qDebug()<<data;
if(!size_set){
int line_size=data.size()/2;
sampleCountX=line_size;
setAxisScaling(line_size);
size_set=true;
}
if(sampleCountX==data.size()/2){
QSurfaceDataRow *newRow = new QSurfaceDataRow(sampleCountX);
int index = 0;
for (int j = 0; j<sampleCountX; j++) {
float x = j;
float y = (data.front().toInt() + data.back().toInt())/2;
data.pop_back();
data.pop_front();
float z = AFM_Proxy->rowCount()+1;
QVector3D vect(x,y,z);
list.append(vect);
(*newRow)[index].setPosition(vect);
index++;
}
m_graph->axisZ()->setRange(0,AFM_Proxy->rowCount()+2);
qDebug()<<QTime::currentTime();
AFM_Proxy->insertRow(AFM_Proxy->rowCount(),newRow);
if(piezomove){
emit sendReady();
}
else{
emit sendReadynopiezo();
}
}
else emit scanFinished();
}
}
void SurfaceGraph::enableAFMModel()
{
AFM_Series->setDrawMode(QSurface3DSeries::DrawSurfaceAndWireframe);
AFM_Series->setFlatShadingEnabled(true);
m_graph->axisX()->setLabelFormat("%.2f");
m_graph->axisZ()->setLabelFormat("%.2f");
m_graph->axisX()->setAutoAdjustRange(true);
m_graph->axisY()->setAutoAdjustRange(true);
m_graph->axisZ()->setAutoAdjustRange(true);
m_graph->axisX()->setLabelAutoRotation(30);
m_graph->axisY()->setLabelAutoRotation(90);
m_graph->axisZ()->setLabelAutoRotation(30);
m_graph->addSeries(AFM_Series);
}
void SurfaceGraph::dataHandler(QList <QByteArray> data){
fillAFMProxy(data);
}
void SurfaceGraph::saveData(){
QString date=QDate::currentDate().toString();
QString time=QTime::currentTime().toString();
QString filepath = QFileDialog::getExistingDirectory(NULL, "Choose save path", "../../",QFileDialog::ShowDirsOnly);
if (!filepath.isNull()){
QDir dir(filepath+"/"+date+"AFM Scan");
if (!dir.exists()) {
dir.mkpath(".");
}
QFile file(dir.path()+"/AFM_Scan_surface_"+QTime::currentTime().toString());
if ( file.open(QIODevice::ReadWrite) )
{
QTextStream stream( &file );
stream<<sampleCountX<<endl;
for(QVector3D i:list){
stream<<i.x()<<" "<<i.y()<<" "<<i.z()<<endl;
}
file.close();
}
else {QMessageBox::critical(nullptr, tr("Error"), "File Can't Be Opened");}
}
}
void SurfaceGraph::adjustCameraZ(int angle)
{
this->m_graph->scene()->activeCamera()->setXRotation(angle/2);
}
void SurfaceGraph::adjustCameraY(int angle)
{
this->m_graph->scene()->activeCamera()->setYRotation(angle/2);
}
void SurfaceGraph::changeTheme(int theme)
{
m_graph->activeTheme()->setType(Q3DTheme::Theme(theme));
}
void SurfaceGraph::setBlackToYellowGradient()
{
QLinearGradient gr;
gr.setColorAt(0.0, Qt::black);
gr.setColorAt(0.33, Qt::blue);
gr.setColorAt(0.67, Qt::red);
gr.setColorAt(1.0, Qt::yellow);
m_graph->seriesList().at(0)->setBaseGradient(gr);
m_graph->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient);
}
void SurfaceGraph::setGreenToRedGradient()
{
QLinearGradient gr;
gr.setColorAt(0.0, Qt::darkGreen);
gr.setColorAt(0.5, Qt::yellow);
gr.setColorAt(0.8, Qt::red);
gr.setColorAt(1.0, Qt::darkRed);
m_graph->seriesList().at(0)->setBaseGradient(gr);
m_graph->seriesList().at(0)->setColorStyle(Q3DTheme::ColorStyleRangeGradient);
}
void SurfaceGraph::setAxisScaling(int sizeX){
m_graph->axisX()->setRange(0,sizeX);
}
SurfaceGraph::~SurfaceGraph()
{
}