-
Notifications
You must be signed in to change notification settings - Fork 0
/
column1D.cpp
591 lines (504 loc) · 18.5 KB
/
column1D.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
#include "column1D.h"
#include "ui_column1D.h"
#include <QDebug>
#include <iostream>
#include <QFileInfo>
#include <QFileDialog>
#include <fstream>
#include <sstream>
column1D::column1D(QWidget *parent) :
QWidget(parent),
ui(new Ui::column1D)
{
ui->setupUi(this);
// connect(this->ui->load1DFile_PB, SIGNAL(clicked()), this, SLOT(on_load1DFile_PB_clicked()));
scatterStyleList<<QCPScatterStyle::ssNone<<QCPScatterStyle::ssDot <<QCPScatterStyle::ssCross<<QCPScatterStyle::ssPlus<<QCPScatterStyle::ssCircle<<QCPScatterStyle::ssDisc<<QCPScatterStyle::ssSquare<<QCPScatterStyle::ssDiamond<<QCPScatterStyle::ssStar<<QCPScatterStyle::ssTriangle<<QCPScatterStyle::ssTriangleInverted<<QCPScatterStyle::ssCrossSquare<<QCPScatterStyle::ssPlusSquare<<QCPScatterStyle::ssCrossCircle<<QCPScatterStyle::ssPlusCircle;
lineStyleList<<Qt::PenStyle::SolidLine<<Qt::PenStyle::DashLine<<Qt::PenStyle::DotLine<<Qt::PenStyle::DashDotLine<<Qt::PenStyle::DashDotDotLine;
this->ui->plot1DFileX_Combo->setView(new QListView);
this->ui->plot1DFile_Table->setColumnWidth(0, 60);
this->ui->plot1DFile_Table->setColumnWidth(1, 60);
this->ui->plot1DFile_Table->setColumnWidth(2, 60);
this->ui->plot1DRelationFile_Table->setColumnWidth(0, 60);
this->ui->plot1DRelationFile_Table->setColumnWidth(1, 60);
this->ui->plot1DRelationFile_Table->setColumnWidth(2, 60);
}
column1D::~column1D()
{
delete ui;
}
int column1D::getColumns(){
return columns;
}
QVector<double> column1D::returnX(){
int dataRows=dataFiltered.count();
int colX=this->ui->plot1DFileX_Combo->currentIndex();
QVector<double> x(dataRows);
qDebug()<<xmin1D<<xmax1D<<dataRows<<"xminmax"<<colX;
if (dataRows>0) {
xmin1D=dataFiltered[0][colX];
xmax1D=dataFiltered[0][colX];
}
qDebug()<<xmin1D<<xmax1D<<dataRows<<"xminmax";
for (int i=0; i<dataRows; i++) {
x[i]=dataFiltered[i][colX];
if(x[i]<=xmin1D) xmin1D=x[i];
if(x[i]>=xmax1D) xmax1D=x[i];
}
qDebug()<<xmin1D<<xmax1D<<dataRows<<"xminmax";
return x;
}
double column1D::returnXMin(){
return xmin1D;
}
double column1D::returnXMax(){
return xmax1D;
}
QVector<double> column1D::returnY(int colY){
int dataRows=dataFiltered.count();
QVector<double> y(dataRows);
qDebug()<<ymin1D<<ymax1D<<dataRows<<"yminmax"<<colY;
if (dataRows>0) {
ymin1D=dataFiltered[0][colY];
ymax1D=dataFiltered[0][colY];
}
qDebug()<<ymin1D<<ymax1D<<dataRows<<"yminmax";
for (int i=0; i<dataRows; i++) {
y[i]=dataFiltered[i][colY];
if(y[i]<=ymin1D) ymin1D=y[i];
if(y[i]>=ymax1D) {ymax1D=y[i];qDebug()<<y[i];}
}
qDebug()<<ymin1D<<ymax1D<<dataRows<<"yminmax";
// qDebug()<<xmin1D<<xmax1D<<dataRows<<"yminmax";
return y;
}
double column1D::returnYMin(){
return ymin1D;
}
double column1D::returnYMax(){
return ymax1D;
}
int column1D::filter(){
if(dataFiltered.count()!=0){
dataFiltered.clear();
}
std::ofstream output1;
std::ofstream output2;
std::ofstream output3;
std::string str;
//str="filter_before.txt";
//const char *outdir1=str.c_str();
//output1.open(outdir1);
//output1 << "size" << "\n";
//output1 << sizeof(vtkData)<<"\n";
//for(int i=0;i<rows;i++){
//output1 << "i:" << i << ", vtkData:"<<vtkData[i][0] << "\n";
//}
//output1.close();
//str="filter.txt";
//const char *outdir=str.c_str();
//output2.open(outdir);
for(int i=0;i<rows;i++){
//output2 << "i:" << i << ", vtkData:"<<vtkData[i][1] << "\n";
if(filter1DData(vtkData[i])){
dataFiltered.append(vtkData[i]);
}
}
//output2.close();
qDebug()<<"rows:"<<rows;
return dataFiltered.count();
}
int column1D::getFilteredCount(){
if (loaded) {
filter();
return dataFiltered.count();
}
return 0;
}
void column1D::on_load1DFile_PB_clicked(){
QFileDialog filedialog;
filedialog.setFileMode(QFileDialog::AnyFile);
filedialog.setNameFilter(tr("Input (*.*)"));
filedialog.setOption(QFileDialog::ReadOnly);
QString load=filedialog.getOpenFileName();
qDebug()<<"Filename:"<<load;
if (!load.isEmpty()) {
columns=loadData1D(load);
loaded = true;
double *dataHold= new double[rows];
QFileInfo filehold(load);
// outputScalar(0,xmax,ymax,zmax);
while(this->ui->plot1DFileX_Combo->count()>0){
this->ui->plot1DFileX_Combo->removeItem(0);
}
for (int i=0; i<columns; i++) {
this->ui->plot1DFileX_Combo->addItem(QString::fromStdString(std::to_string(i+1)));
}
while(this->ui->plot1DFileY_LW->count()>0){
this->ui->plot1DFileY_LW->takeItem(0);
}
for (int i = 0; i < columns; ++i)
{
this->ui->plot1DFileY_LW->addItem(QString::fromStdString(std::to_string(i+1)));
this->ui->plot1DFileY_LW->item(i)->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable );
this->ui->plot1DFileY_LW->item(i)->setCheckState(Qt::Unchecked);
}
this->ui->plot1DFileY_LW->sortItems();
this->ui->plot1DRelationFile_Combo->setEnabled(true);
this->ui->plot1DRelationValueFile_LE->setEnabled(true);
while(this->ui->plot1DColFile_Combo->count()>0){
this->ui->plot1DColFile_Combo->removeItem(0);
}
for (int i = 0; i < columns; ++i)
{
this->ui->plot1DColFile_Combo->addItem(QString::fromStdString(std::to_string(i+1)));
}
while (this->ui->plot1DLines_LW->count() > 0) {
this->ui->plot1DLines_LW->takeItem(0);
}
while (this->ui->plot1DRelationFile_Table->rowCount() > 0) {
this->ui->plot1DRelationFile_Table->removeRow(0);
}
this->ui->plot1DFileName_LE->setText(filehold.fileName());
printstatus = QString::fromStdString(std::to_string(columns));
this->ui->plot1DFileColNum_LE->setText(printstatus);
// printstatus = QString::fromStdString("0 - "+std::to_string(xmax));
// this->ui->plot1Dxminxmax_LE->setText(printstatus);
//
// printstatus = QString::fromStdString("0 - "+std::to_string(ymax));
// this->ui->plot1Dyminymax_LE->setText(printstatus);
//
// printstatus = QString::fromStdString("0 - "+std::to_string(zmax));
// this->ui->plot1Dzminzmax_LE->setText(printstatus);
//
this->ui->plot1DFile_Table->clearContents();
while(this->ui->plot1DFile_Table->rowCount()>0) {
this->ui->plot1DFile_Table->removeRow(0);
}
for(int i=0;i<columns;++i){
for (int j=0;j<rows;++j){
dataHold[j]=vtkData[j][i];
}
this->ui->plot1DFile_Table->insertRow(this->ui->plot1DFile_Table->rowCount());
printstatus = QString::fromStdString(std::to_string(getMin(dataHold,rows)));
qDebug()<<"column:"<<i<<rows<<this->ui->plot1DFile_Table->rowCount();
qDebug()<<"min:"<<printstatus;
this->ui->plot1DFile_Table->setItem(this->ui->plot1DFile_Table->rowCount()-1,0,new QTableWidgetItem(printstatus));
printstatus = QString::fromStdString(std::to_string(getMax(dataHold,rows)));
qDebug()<<"max:"<<printstatus;
this->ui->plot1DFile_Table->setItem(this->ui->plot1DFile_Table->rowCount()-1,1,new QTableWidgetItem(printstatus));
printstatus = QString::fromStdString(std::to_string(getAvg(dataHold,rows)));
qDebug()<<"avg:"<<printstatus;
this->ui->plot1DFile_Table->setItem(this->ui->plot1DFile_Table->rowCount()-1,2,new QTableWidgetItem(printstatus));
}
// this->ui->plot1DFile_Table->sortItems(0);
delete[] dataHold;
}
}
int column1D::loadData1D(QString filedir){
//First we need to decide whether the first line of the file needs to be kept
std::ifstream input;
std::ofstream output;
std::string a;
int i=0,x=0,y=0,z=0,columnNumber=0;
float test=0;
long rowNumber=0;
int count1=0;
int count2=0;
QFileInfo filehold(filedir);
QByteArray dir1=filedir.toLatin1();
const char *dir=dir1.data();
qDebug()<<dir;
input.open(dir);
std::string str,line,line1,line2;
std::getline(input,line1);
std::getline(input,line2);
std::istringstream iss1(line1);
std::istringstream iss2(line2);
input.close();
while(iss1 >> a){
count1++;
}
while(iss2 >> a){
qDebug()<<QString::fromStdString(a);
count2++;
}
columnNumber=count2;
for (int k=0;k<columnNumber;++k){
iss2 >> std::scientific;
iss2 >> test;
qDebug()<< "test:"<<test;
}
input.open(dir);
for (rowNumber=0; std::getline(input, line); rowNumber++) {
}
input.close();
qDebug()<<"Rownumber"<<rowNumber<<count1<<count2;
if (count1!=count2){
// input.open(dir);
// std::getline(input,line1);
// std::istringstream iss1(line1);
// iss1 >> x >> y >> z;
//
// input.close();
rowNumber--;
}else{
iss1 >> x;
qDebug()<<"x:"<<x;
if(x==0){
rowNumber--;
}
// std::ifstream read(dir, std::ios_base::ate );//open file
// int length = 0;
//
// char c = '\0';
//
// if( read )
// {
// length = read.tellg();//Get file size
//
// // loop backward over the file
//
// for(int i = length-2; i > 0; i-- )
// {
// read.seekg(i);
// c = read.get();
// if( c == '\r' || c == '\n' )//new line?
// break;
// }
// std::getline(read, line1);//read last line
// std::istringstream iss1(line1);
// iss1 >> x >> y >> z;
// read.close();
//
// }
}
vtkData= new double*[rowNumber];
for (i=0;i<rowNumber;++i){
vtkData[i] = new double[columnNumber];
}
input.open(dir);
if (count1!=count2){
std::getline(input,line1);
std::istringstream iss1(line1);
}else{
iss1 >> x;
qDebug()<<"x:"<<x;
// if(isnan(x)){
// std::getline(input,line1);
// std::istringstream iss1(line1);
// }
}
for (int j=0;j<rowNumber;++j){
std::getline(input,line);
std::istringstream iss(line);
std::cout << line <<"\n";
for (int k=0;k<columnNumber;++k){
iss >> a;
std::istringstream iss1(a);
iss1 >> std::scientific;
iss1 >> vtkData[j][k];
if(iss1.fail()){
std::cout << "fail,";
// iss.ignore(256,' ');
}else{
//std::cout << vtkData[j][k] <<",";
}
}
std::cout<<"\n";
}
input.close();
//str="load.txt";
//const char *outdir=str.c_str();
//
//output.open(outdir);
//for(int i=0;i<rowNumber;i++){
// output << "i:" << i << ", vtkData:";
// for(int j=0;j<columnNumber;j++){
// output<<vtkData[i][j] << " ";
// }
// output << "\n";
//}
//output.close();
// xmax=x;
// ymax=y;
// zmax=z;
rows = rowNumber;
return columnNumber;
}
bool column1D::filter1DData(double *data){
bool flagHolder=true;
qDebug()<<"data:"<<*data<<data[0]<<data[1]<<data[2];
for(int i=0;i<this->ui->plot1DRelationFile_Table->rowCount();i++){
int relationCol=this->ui->plot1DRelationFile_Table->item(i, 0)->text().toInt()-1;
double value=this->ui->plot1DRelationFile_Table->item(i, 2)->text().toDouble();
std::string relation=this->ui->plot1DRelationFile_Table->item(i,1)->text().toStdString();
// qDebug()<<"relation:"<<relationCol<<relation.c_str()<<value;
if(relation=="="){
if (data[relationCol]==value) {
// flagHolder*=true;
}else{
flagHolder=false;
}
}else if(relation==">"){
if (data[relationCol]>value) {
// flagHolder*=true;
}else{
flagHolder=false;
}
}else if(relation==">="){
if (data[relationCol]>=value) {
// flagHolder*=true;
}else{
flagHolder=false;
}
}else if(relation=="<"){
if (data[relationCol]<value) {
// flagHolder*=true;
}else{
flagHolder=false;
}
}else if(relation=="<="){
if (data[relationCol]<=value) {
// flagHolder*=true;
}else{
flagHolder=false;
}
}
}
return flagHolder;
}
void column1D::on_plot1DAddRelationFile_PB_released(){
QString item;
int row;
qDebug()<<"Add button pushed";
if ((this->ui->plot1DColFile_Combo->count()==0) |
this->ui->plot1DRelationValueFile_LE->text().isEmpty()){
}else{
this->ui->plot1DRelationFile_Table->setEnabled(true);
row=this->ui->plot1DRelationFile_Table->rowCount();
qDebug()<<row;
this->ui->plot1DRelationFile_Table->insertRow(row);
// row=row;
item=this->ui->plot1DColFile_Combo->currentText();
this->ui->plot1DRelationFile_Table->setItem(row,0,new QTableWidgetItem(item));
item=this->ui->plot1DRelationFile_Combo->currentText();
this->ui->plot1DRelationFile_Table->setItem(row,1,new QTableWidgetItem(item));
item=this->ui->plot1DRelationValueFile_LE->text();
this->ui->plot1DRelationFile_Table->setItem(row,2,new QTableWidgetItem(item));
// item=this->ui->RGBA_LE->text();
// this->ui->RGBScalar_Table->setItem(row,4,new QTableWidgetItem(item));
this->ui->plot1DRelationFile_Table->sortItems(0,Qt::AscendingOrder);
}
}
void column1D::on_plot1DFileY_LW_itemClicked(QListWidgetItem* item){
if(item->checkState()){
this->ui->plot1DLines_LW->addItem(item->text());
// this->ui->plot1DLines_LW->sortItems();
lineStyle.push_back(QPen());
scatterStyle.push_back(int());
lineName.push_back(QString());
this->ui->plot1DLines_LW->setCurrentItem(this->ui->plot1DLines_LW->findItems(item->text(), Qt::MatchExactly).first());
this->ui->plot1DLineRGBR_LE->setText("0");
this->ui->plot1DLineRGBG_LE->setText("0");
this->ui->plot1DLineRGBB_LE->setText("0");
this->ui->plot1DLineWeight_LE->setText("2");
this->ui->plot1DScatterStyle_Combo->setCurrentIndex(0);
this->ui->plot1DLineStyle_Combo->setCurrentIndex(0);
this->ui->plot1DLineName_LE->setText(QString::fromStdString("line"+std::to_string(lineStyle.count())));
on_plot1DSetLine_PB_released();
}else{
if(!(this->ui->plot1DLines_LW->findItems(item->text(), Qt::MatchExactly).isEmpty())){
int rownum=this->ui->plot1DLines_LW->row(this->ui->plot1DLines_LW->findItems(item->text(), Qt::MatchExactly).first());
this->ui->plot1DLines_LW->takeItem(rownum);
lineName.remove(rownum);
lineStyle.remove(rownum);
scatterStyle.remove(rownum);
qDebug()<<"rownum" << rownum;
}
}
if (this->ui->plot1DLines_LW->count()==0) {
this->ui->plot1DSetLine_PB->setEnabled(false);
}else{
this->ui->plot1DSetLine_PB->setEnabled(true);
}
qDebug()<<"check:"<<item->checkState();
// emit figureReplot();
}
void column1D::on_plot1DSetLine_PB_released(){
int R=this->ui->plot1DLineRGBR_LE->text().toDouble();
int G=this->ui->plot1DLineRGBG_LE->text().toDouble();
int B=this->ui->plot1DLineRGBB_LE->text().toDouble();
int weight=this->ui->plot1DLineWeight_LE->text().toDouble();
int index=this->ui->plot1DLines_LW->currentRow();
int psIndex=this->ui->plot1DLineStyle_Combo->currentIndex();
int sIndex=this->ui->plot1DScatterStyle_Combo->currentIndex();
QString name=this->ui->plot1DLineName_LE->text();
lineStyle[index].setBrush(QColor(R,G,B));
lineStyle[index].setWidth(weight);
lineStyle[index].setStyle(lineStyleList[psIndex]);
scatterStyle[index]=sIndex;
lineName[index]=name;
qDebug()<< "index:" << index << weight << R << G << B << name;
}
void column1D::on_plot1DLines_LW_currentRowChanged(int rowNum){
if(rowNum!=-1){
this->ui->plot1DLineRGBR_LE->setText(QString::fromStdString(std::to_string(lineStyle[rowNum].color().red())));
this->ui->plot1DLineRGBG_LE->setText(QString::fromStdString(std::to_string(lineStyle[rowNum].color().green())));
this->ui->plot1DLineRGBB_LE->setText(QString::fromStdString(std::to_string(lineStyle[rowNum].color().blue())));
this->ui->plot1DLineWeight_LE->setText(QString::fromStdString(std::to_string(lineStyle[rowNum].width())));
this->ui->plot1DScatterStyle_Combo->setCurrentIndex(scatterStyle[rowNum]);
this->ui->plot1DLineStyle_Combo->setCurrentIndex(lineStyleList.indexOf(lineStyle[rowNum].style()));
this->ui->plot1DLineName_LE->setText(lineName[rowNum]);
}
}
void column1D::on_plot1DRemoveRelationFile_PB_released(){
if(this->ui->plot1DRelationFile_Table->rowCount()>0){
this->ui->plot1DRelationFile_Table->removeRow(this->ui->plot1DRelationFile_Table->currentRow());
}
}
QPen column1D::getLineStyle(int rowNumber){
return lineStyle[rowNumber];
}
QCPScatterStyle column1D::getScatterStyle(int rowNumber){
return scatterStyleList[scatterStyle[rowNumber]];
}
QString column1D::getLineName(int rowNumber){
return lineName[rowNumber];
}
double column1D::getMin(double *list,int length){
double minValue;
minValue=list[0];
for(int i=0;i<length;++i){
if(list[i]<minValue){
minValue=list[i];
}
}
return minValue;
}
double column1D::getMax(double *list,int length){
double maxValue;
maxValue=list[0];
for(int i=0;i<length;++i){
if(list[i]>maxValue){
maxValue=list[i];
}
}
return maxValue;
}
double column1D::getAvg(double *list,int length){
double avgValue;
avgValue=0;
for(int i=0;i<length;++i){
avgValue=avgValue+list[i];
}
avgValue=avgValue/length;
return avgValue;
}
void column1D::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
// qDebug()<<"painting border";
}