-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidget.cpp
157 lines (123 loc) · 4.16 KB
/
widget.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
#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QTextStream>
#include <QProgressDialog>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowTitle("Heightmap Clipper v0.1.4");
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_openASC_clicked()
{
// input ASC
QString fileName = QFileDialog::getOpenFileName(this,
tr("ASC"), "",
tr("ASC files (*.asc)"));
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
// new clipped ASC
QFile outFile(fileName + "_my_clipped.asc");
outFile.open(QIODevice::WriteOnly);
QTextStream out(&outFile);
QString line;
bool ok;
float xllcorner,yllcorner;
int cellsize,ncols,nrows;
QStringList list;
/*
ncols 205
nrows 205
xllcorner 392984.672
yllcorner 3617867.273
cellsize 10
*/
// ncols 512
line = in.readLine();
list = line.split(" ", Qt::SkipEmptyParts);
ncols = list[1].toInt(&ok);
// out file
out << line << Qt::endl;
// nrows 512
line = in.readLine();
list = line.split(" ", Qt::SkipEmptyParts);
nrows = list[1].toInt(&ok);
out << line << Qt::endl;
// xllcorner 200000.000000
line = in.readLine();
list = line.split(" ", Qt::SkipEmptyParts);
xllcorner = list[1].toFloat(&ok);
line = "xllcorner 200000";
out << line << Qt::endl;
// yllcorner 0.000000
line = in.readLine();
list = line.split(" ", Qt::SkipEmptyParts);
yllcorner = list[1].toFloat(&ok);
line = "yllcorner 0";
out << line << Qt::endl;
// cellsize 10.000000
line = in.readLine();
list = line.split(" ", Qt::SkipEmptyParts);
cellsize = list[1].toInt(&ok);
out << line << Qt::endl;
// NODATA_value -9999
line = in.readLine();
out << line << Qt::endl;
ui->textEdit->append("ncols: " + QString::number(ncols) + "\nnrows: " + QString::number(nrows)
+ "\nxllcorner: " + QString::number(xllcorner) + "\nyllcorner: " + QString::number(yllcorner) + "\ncellsize: " + QString::number(cellsize));
ui->textEdit->append("ocean_level: " + QString::number(ui->ocean_level->value()) + "\nocean_clip: " + QString::number(ui->ocean_clip->value()));
QProgressDialog progressDialog(this);
progressDialog.setRange(0, (ncols * nrows));
progressDialog.setWindowTitle(tr("Heightmap Grid Points"));
// total count for the progressdialog value
int wholeGrid = 0;
while (!in.atEnd())
{
line = in.readLine();
list = line.split(" ");
//ui->textEdit->append(list[0]);
// loop all the ncols through
for (int i=0; i<ncols; i++)
{
wholeGrid++;
float fnumbah = list[i].toFloat(&ok);
//ui->textEdit->append("list[" + QString::number(i) + "]: " + list[i] + ", fnumbah: " + QString::number(fnumbah));
// clip below 0 meters to 0.25 meter as thats how arma3 works :)
if (fnumbah > ui->aboveGround_low->value() && fnumbah < ui->aboveGround_high->value())
{
// change the elevation value to one in clipped setting
fnumbah = ui->aboveGround_clip->value();
//ui->textEdit->append("Yippy the clip! new fnumbah: " + QString::number(fnumbah));
// put the modified number back to qstringlist
list[i] = QString::number(fnumbah);
}
// if our elevation value matches ocean value
if (fnumbah == ui->ocean_level->value())
{
// change the elevation value to one in clipped setting
fnumbah = ui->ocean_clip->value();
//ui->textEdit->append("Yippy the clip! new fnumbah: " + QString::number(fnumbah));
// put the modified number back to qstringlist
list[i] = QString::number(fnumbah);
}
// write to outFile individual grid point in THIS LINE
out << list[i] << " ";
}
// update progressdialog, do not update this too ofte or it will slow your program down
progressDialog.setValue(wholeGrid);
progressDialog.setLabelText(tr("Processing grid point %1 of %2...").arg(wholeGrid).arg(ncols * nrows));
qApp->processEvents();
// write to outFile end of line
out << Qt::endl;
}
ui->textEdit->append("All done, exit.");
file.close();
outFile.close();
}