@@ -14,6 +14,8 DESTDIR =./bin | |||||
14 | TARGET = QLop |
|
14 | TARGET = QLop | |
15 | TEMPLATE = app |
|
15 | TEMPLATE = app | |
16 |
|
16 | |||
|
17 | LIBS+=-lfftw3 | |||
|
18 | ||||
17 | INCLUDEPATH += src/QCustomPlot \ |
|
19 | INCLUDEPATH += src/QCustomPlot \ | |
18 | src src/Cassini \ |
|
20 | src src/Cassini \ | |
19 | src/Core src/Core/Widgets \ |
|
21 | src/Core src/Core/Widgets \ |
@@ -2,12 +2,14 | |||||
2 | #include <qlopplots.h> |
|
2 | #include <qlopplots.h> | |
3 | #include <QPen> |
|
3 | #include <QPen> | |
4 | #include <QAction> |
|
4 | #include <QAction> | |
|
5 | #include <fftw3.h> | |||
5 |
|
6 | |||
6 | CassiniTools* CassiniTools::_self=NULL; |
|
7 | CassiniTools* CassiniTools::_self=NULL; | |
7 | QDockWidget* CassiniTools::m_gui=NULL; |
|
8 | QDockWidget* CassiniTools::m_gui=NULL; | |
8 | CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; |
|
9 | CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; | |
9 | CassiniDataFile* CassiniTools::m_dataFile=NULL; |
|
10 | CassiniDataFile* CassiniTools::m_dataFile=NULL; | |
10 | int CassiniTools::m_defaultPlot=-1; |
|
11 | int CassiniTools::m_defaultPlot=-1; | |
|
12 | int CassiniTools::m_fftPlot=-1; | |||
11 |
|
13 | |||
12 | Qt::GlobalColor QLopColours[]= {Qt::black, |
|
14 | Qt::GlobalColor QLopColours[]= {Qt::black, | |
13 | Qt::red, |
|
15 | Qt::red, | |
@@ -48,6 +50,7 CassiniTools::~CassiniTools() | |||||
48 | void CassiniTools::makePlot() |
|
50 | void CassiniTools::makePlot() | |
49 | { |
|
51 | { | |
50 | m_defaultPlot = QLopPlots::addPlot(); |
|
52 | m_defaultPlot = QLopPlots::addPlot(); | |
|
53 | m_fftPlot = QLopPlots::addPlot(); | |||
51 | SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); |
|
54 | SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); | |
52 | if(plot) |
|
55 | if(plot) | |
53 | { |
|
56 | { | |
@@ -58,6 +61,9 void CassiniTools::makePlot() | |||||
58 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); |
|
61 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); | |
59 | plot->addAction(action); |
|
62 | plot->addAction(action); | |
60 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); |
|
63 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); | |
|
64 | action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self); | |||
|
65 | plot->addAction(action); | |||
|
66 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int))); | |||
61 | } |
|
67 | } | |
62 | } |
|
68 | } | |
63 |
|
69 | |||
@@ -83,19 +89,19 void CassiniTools::decodeFGMData(const Q | |||||
83 |
|
89 | |||
84 | void CassiniTools::plotFile(const QString &File) |
|
90 | void CassiniTools::plotFile(const QString &File) | |
85 | { |
|
91 | { | |
86 | if(!m_dataFile->isRunning()) |
|
92 | if(!m_dataFile->isRunning()) | |
87 | { |
|
93 | { | |
88 | m_dataFile->parseFile(File); |
|
94 | m_dataFile->parseFile(File); | |
89 | // TODO fixme |
|
95 | // TODO fixme | |
90 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
96 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | |
91 | if(plot==NULL) |
|
97 | if(plot==NULL) | |
92 | { |
|
98 | { | |
93 | makePlot(); |
|
99 | makePlot(); | |
94 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
100 | plot = QLopPlots::getPlot(m_defaultPlot); | |
95 | } |
|
101 | } | |
96 | if(plot) |
|
102 | if(plot) | |
97 | plot->setTitle(File); |
|
103 | plot->setTitle(File); | |
98 | } |
|
104 | } | |
99 | } |
|
105 | } | |
100 |
|
106 | |||
101 | void CassiniTools::plot_TAB_File(const QString &fileName) |
|
107 | void CassiniTools::plot_TAB_File(const QString &fileName) | |
@@ -125,6 +131,76 void CassiniTools::export_view(int PID) | |||||
125 | } |
|
131 | } | |
126 | } |
|
132 | } | |
127 |
|
133 | |||
|
134 | void CassiniTools::compute_fft_on_view(int PID) | |||
|
135 | { | |||
|
136 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); | |||
|
137 | if(plot==NULL) | |||
|
138 | return; | |||
|
139 | { | |||
|
140 | QLopDataList vectors; | |||
|
141 | for(int i=0;i<plot->graphCount();i++) | |||
|
142 | { | |||
|
143 | QLopData* vect = new QLopData(); | |||
|
144 | vect->data = plot->getVisibleData(i); | |||
|
145 | vectors.append(vect); | |||
|
146 | } | |||
|
147 | if(vectors.count()==3) | |||
|
148 | { | |||
|
149 | QLopData* ch1V=vectors.at(0); | |||
|
150 | QLopData* ch2V=vectors.at(1); | |||
|
151 | QLopData* ch3V=vectors.at(2); | |||
|
152 | QLopData* FFTout=new QLopData(); | |||
|
153 | if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count()) | |||
|
154 | { | |||
|
155 | ||||
|
156 | double* in; | |||
|
157 | fftw_complex *out; | |||
|
158 | fftw_plan p; | |||
|
159 | FFTout->data = new QVector<QCPData>(ch1V->data->count()/2); | |||
|
160 | in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count()); | |||
|
161 | out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count()); | |||
|
162 | double av=0; | |||
|
163 | for(int i=0;i<ch1V->data->count();i++) | |||
|
164 | { | |||
|
165 | in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value)); | |||
|
166 | av = av+in[i]; | |||
|
167 | } | |||
|
168 | av/=ch1V->data->count(); | |||
|
169 | for(int i=0;i<ch1V->data->count();i++) | |||
|
170 | { | |||
|
171 | in[i]=in[i]-av; | |||
|
172 | } | |||
|
173 | p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE); | |||
|
174 | fftw_execute(p); /* repeat as needed */ | |||
|
175 | fftw_destroy_plan(p); | |||
|
176 | fftw_free(in); | |||
|
177 | for(int i=0;i<ch1V->data->count()/2;i++) | |||
|
178 | { | |||
|
179 | // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count(); | |||
|
180 | (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count()); | |||
|
181 | (*FFTout->data)[i].key = i; | |||
|
182 | } | |||
|
183 | fftw_free(out); | |||
|
184 | SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot); | |||
|
185 | if(plot==NULL) | |||
|
186 | return; | |||
|
187 | plot->removeAllGraphs(); | |||
|
188 | plot->addGraph(); | |||
|
189 | plot->setXaxisLog(); | |||
|
190 | plot->setYaxisLog(); | |||
|
191 | plot->setAdaptativeSampling(0,true); | |||
|
192 | QPen pen = plot->getGraphPen(0); | |||
|
193 | pen.setColor(QLopColours[0%QLopColoursCount]); | |||
|
194 | plot->setGraphPen(0,pen); | |||
|
195 | plot->setGraphData(0,FFTout->data,false); | |||
|
196 | plot->rescaleAxis(); | |||
|
197 | plot->replot(); | |||
|
198 | ||||
|
199 | } | |||
|
200 | } | |||
|
201 | } | |||
|
202 | } | |||
|
203 | ||||
128 | QDockWidget *CassiniTools::getGUI() |
|
204 | QDockWidget *CassiniTools::getGUI() | |
129 | { |
|
205 | { | |
130 | if(!m_noGui && (m_gui==NULL)) |
|
206 | if(!m_noGui && (m_gui==NULL)) | |
@@ -148,25 +224,25 void CassiniTools::dataReady(QLopDataLis | |||||
148 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); |
|
224 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | |
149 | if(plot==NULL) |
|
225 | if(plot==NULL) | |
150 | { |
|
226 | { | |
151 | makePlot(); |
|
227 | makePlot(); | |
152 | plot = QLopPlots::getPlot(m_defaultPlot); |
|
228 | plot = QLopPlots::getPlot(m_defaultPlot); | |
153 | } |
|
229 | } | |
154 | if(plot) |
|
230 | if(plot) | |
155 | { |
|
231 | { | |
156 | plot->removeAllGraphs(); |
|
232 | plot->removeAllGraphs(); | |
157 | for(int i=0;i<data.count();i++) |
|
233 | for(int i=0;i<data.count();i++) | |
158 | { |
|
234 | { | |
159 | plot->addGraph(); |
|
235 | plot->addGraph(); | |
160 | plot->setAdaptativeSampling(i,true); |
|
236 | plot->setAdaptativeSampling(i,true); | |
161 | plot->setUseFastVector(i,true); |
|
237 | plot->setUseFastVector(i,true); | |
162 | QPen pen = plot->getGraphPen(i); |
|
238 | QPen pen = plot->getGraphPen(i); | |
163 | pen.setColor(QLopColours[i%QLopColoursCount]); |
|
239 | pen.setColor(QLopColours[i%QLopColoursCount]); | |
164 | plot->setGraphPen(i,pen); |
|
240 | plot->setGraphPen(i,pen); | |
165 | plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); |
|
241 | plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); | |
166 | plot->setGraphData(i,data.at(i)->data,false); |
|
242 | plot->setGraphData(i,data.at(i)->data,false); | |
167 | } |
|
243 | } | |
168 | plot->rescaleAxis(); |
|
244 | plot->rescaleAxis(); | |
169 | plot->replot(); |
|
245 | plot->replot(); | |
170 | } |
|
246 | } | |
171 | } |
|
247 | } | |
172 |
|
248 |
@@ -17,7 +17,7 private: | |||||
17 | static QDockWidget* m_gui; |
|
17 | static QDockWidget* m_gui; | |
18 | static CassiniToolsGUI* m_CassiniToolsGUI; |
|
18 | static CassiniToolsGUI* m_CassiniToolsGUI; | |
19 | static CassiniDataFile* m_dataFile; |
|
19 | static CassiniDataFile* m_dataFile; | |
20 | static int m_defaultPlot; |
|
20 | static int m_defaultPlot,m_fftPlot; | |
21 | CassiniTools(bool noGUI=false, QObject *parent=0); |
|
21 | CassiniTools(bool noGUI=false, QObject *parent=0); | |
22 | ~CassiniTools(); |
|
22 | ~CassiniTools(); | |
23 | static void makePlot(); |
|
23 | static void makePlot(); | |
@@ -32,6 +32,7 public: | |||||
32 | public slots: |
|
32 | public slots: | |
33 | void plot_TAB_File(const QString& fileName); |
|
33 | void plot_TAB_File(const QString& fileName); | |
34 | void export_view(int PID); |
|
34 | void export_view(int PID); | |
|
35 | void compute_fft_on_view(int PID); | |||
35 | private slots: |
|
36 | private slots: | |
36 | void dataReady(QLopDataList data); |
|
37 | void dataReady(QLopDataList data); | |
37 | }; |
|
38 | }; |
@@ -48,7 +48,7 QCPGraphVect::QCPGraphVect(QCPAxis *keyA | |||||
48 |
|
48 | |||
49 | QCPGraphVect::~QCPGraphVect() |
|
49 | QCPGraphVect::~QCPGraphVect() | |
50 | { |
|
50 | { | |
51 |
|
51 | delete mData; | ||
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void QCPGraphVect::setData(QVector<QCPData> *data) |
|
54 | void QCPGraphVect::setData(QVector<QCPData> *data) |
@@ -7,6 +7,6 QLopData::QLopData(QObject *parent) : QO | |||||
7 |
|
7 | |||
8 | QLopData::~QLopData() |
|
8 | QLopData::~QLopData() | |
9 | { |
|
9 | { | |
10 |
|
10 | delete data; | ||
11 | } |
|
11 | } | |
12 |
|
12 |
@@ -111,13 +111,23 void SocExplorerPlot::setTitle(QString t | |||||
111 | void SocExplorerPlot::setXaxisLabel(QString label) |
|
111 | void SocExplorerPlot::setXaxisLabel(QString label) | |
112 | { |
|
112 | { | |
113 | this->m_plot->xAxis->setLabel(label); |
|
113 | this->m_plot->xAxis->setLabel(label); | |
114 | this->repaint(); |
|
114 | this->repaint(); | |
|
115 | } | |||
|
116 | ||||
|
117 | void SocExplorerPlot::setXaxisLog() | |||
|
118 | { | |||
|
119 | this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic); | |||
115 | } |
|
120 | } | |
116 |
|
121 | |||
117 | void SocExplorerPlot::setYaxisLabel(QString label) |
|
122 | void SocExplorerPlot::setYaxisLabel(QString label) | |
118 | { |
|
123 | { | |
119 | this->m_plot->yAxis->setLabel(label); |
|
124 | this->m_plot->yAxis->setLabel(label); | |
120 | this->repaint(); |
|
125 | this->repaint(); | |
|
126 | } | |||
|
127 | ||||
|
128 | void SocExplorerPlot::setYaxisLog() | |||
|
129 | { | |||
|
130 | this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic); | |||
121 | } |
|
131 | } | |
122 |
|
132 | |||
123 | void SocExplorerPlot::setXaxisRange(double lower, double upper) |
|
133 | void SocExplorerPlot::setXaxisRange(double lower, double upper) |
@@ -64,8 +64,10 public: | |||||
64 | ~SocExplorerPlot(); |
|
64 | ~SocExplorerPlot(); | |
65 | void setTitle(QString title); |
|
65 | void setTitle(QString title); | |
66 | void setXaxisLabel(QString label); |
|
66 | void setXaxisLabel(QString label); | |
|
67 | void setXaxisLog(); | |||
67 | void setXaxisRange(double lower, double upper); |
|
68 | void setXaxisRange(double lower, double upper); | |
68 | void setYaxisLabel(QString label); |
|
69 | void setYaxisLabel(QString label); | |
|
70 | void setYaxisLog(); | |||
69 | void setYaxisRange(double lower, double upper); |
|
71 | void setYaxisRange(double lower, double upper); | |
70 | void rescaleAxis(); |
|
72 | void rescaleAxis(); | |
71 | void setLegendFont(QFont font); |
|
73 | void setLegendFont(QFont font); |
General Comments 0
You need to be logged in to leave comments.
Login now