Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | Werner | 1 | #include "mainwindow.h" |
2 | #include "ui_mainwindow.h" |
||
3 | |||
259 | werner | 4 | #include <QtGui> |
5 | #include <QtXml> |
||
30 | Werner | 6 | #include <imagestamp.h> |
19 | Werner | 7 | #include "lightroom.h" |
105 | Werner | 8 | #include "stampcontainer.h" |
9 | #include "speciesset.h" |
||
10 | #include "exception.h" |
||
39 | Werner | 11 | #include "paintarea.h" |
400 | werner | 12 | #include "globalsettings.h" |
772 | werner | 13 | //GlobalSettings *GlobalSettings::mInstance = 0; |
39 | Werner | 14 | |
9 | Werner | 15 | // global settings |
16 | QDomDocument xmldoc; |
||
17 | QDomNode xmlparams; |
||
20 | Werner | 18 | |
19 | // global Object pointers |
||
20 | LightRoom *lightroom = 0; |
||
39 | Werner | 21 | StampContainer *stamp_container=0; |
40 | Werner | 22 | StampContainer *reader_stamp_container=0; |
90 | Werner | 23 | QList<Species*> tree_species; |
20 | Werner | 24 | |
40 | Werner | 25 | double distance(const QPointF &a, const QPointF &b) |
26 | { |
||
27 | return sqrt( (a.x()-b.x())*(a.x()-b.x()) + (a.y()-b.y())*(a.y()-b.y()) ); |
||
28 | } |
||
39 | Werner | 29 | |
9 | Werner | 30 | QString setting(const QString& paramname) |
31 | { |
||
32 | if (!xmlparams.isNull()) |
||
33 | return xmlparams.firstChildElement(paramname).text(); |
||
34 | else |
||
35 | return "ERROR"; |
||
36 | } |
||
30 | Werner | 37 | |
31 | Werner | 38 | |
6 | Werner | 39 | double nrandom(const float& p1, const float& p2) |
40 | { |
||
41 | return p1 + (p2-p1)*(rand()/float(RAND_MAX)); |
||
42 | } |
||
43 | |||
7 | Werner | 44 | void myMessageOutput(QtMsgType type, const char *msg) |
45 | { |
||
40 | Werner | 46 | switch (type) { |
7 | Werner | 47 | case QtDebugMsg: |
40 | Werner | 48 | MainWindow::logSpace()->appendPlainText(QString(msg)); |
49 | MainWindow::logSpace()->ensureCursorVisible(); |
||
7 | Werner | 50 | break; |
51 | case QtWarningMsg: |
||
87 | Werner | 52 | MainWindow::logSpace()->appendPlainText(QString("WARNING: %1").arg(msg)); |
53 | MainWindow::logSpace()->ensureCursorVisible(); |
||
54 | fprintf(stderr, "WARNING: %s\n", msg); |
||
7 | Werner | 55 | break; |
56 | case QtCriticalMsg: |
||
57 | fprintf(stderr, "Critical: %s\n", msg); |
||
58 | break; |
||
59 | case QtFatalMsg: |
||
60 | fprintf(stderr, "Fatal: %s\n", msg); |
||
61 | abort(); |
||
40 | Werner | 62 | } |
7 | Werner | 63 | |
40 | Werner | 64 | |
7 | Werner | 65 | } |
66 | |||
67 | QPlainTextEdit *MainWindow::mLogSpace=NULL; |
||
68 | |||
69 | QPlainTextEdit* MainWindow::logSpace() |
||
70 | { |
||
71 | return mLogSpace; |
||
72 | } |
||
73 | |||
3 | Werner | 74 | MainWindow::MainWindow(QWidget *parent) |
75 | : QMainWindow(parent), ui(new Ui::MainWindowClass) |
||
76 | { |
||
77 | ui->setupUi(this); |
||
259 | werner | 78 | |
3 | Werner | 79 | connect( ui->PaintWidget, SIGNAL(needsPainting(QPainter&)), |
80 | this, SLOT(repaintArea(QPainter&)) ); |
||
40 | Werner | 81 | |
113 | Werner | 82 | |
7 | Werner | 83 | mLogSpace = ui->logOutput; |
409 | werner | 84 | qInstallMsgHandler(myMessageOutput); |
19 | Werner | 85 | // load xml file |
86 | xmldoc.clear(); |
||
119 | Werner | 87 | QString argText = QApplication::arguments().last(); |
200 | werner | 88 | if (QApplication::arguments().count()>1 && !argText.isEmpty()) |
119 | Werner | 89 | ui->initFileName->setText(argText); |
90 | |||
19 | Werner | 91 | QString xmlFile = Helper::loadTextFile(ui->initFileName->text()); |
3 | Werner | 92 | |
65 | Werner | 93 | if (!xmlFile.isEmpty()) { |
94 | ui->iniEdit->setPlainText(xmlFile); |
||
19 | Werner | 95 | |
65 | Werner | 96 | if (!xmldoc.setContent(xmlFile)) { |
97 | QMessageBox::information(this, "title text", "Cannot set content of XML file " + ui->initFileName->text()); |
||
98 | return; |
||
99 | } |
||
19 | Werner | 100 | } |
101 | |||
20 | Werner | 102 | on_actionEdit_XML_settings_triggered(); |
72 | Werner | 103 | // update |
19 | Werner | 104 | |
118 | Werner | 105 | qDebug() << "threadcount: " << QThread::idealThreadCount(); |
106 | |||
3 | Werner | 107 | } |
108 | |||
109 | MainWindow::~MainWindow() |
||
110 | { |
||
111 | delete ui; |
||
20 | Werner | 112 | if (lightroom) |
113 | delete lightroom; |
||
3 | Werner | 114 | } |
115 | |||
116 | void MainWindow::on_applyXML_clicked() |
||
117 | { |
||
9 | Werner | 118 | xmldoc.clear(); |
3 | Werner | 119 | // load for edit |
28 | Werner | 120 | QString xml = ui->iniEdit->toPlainText(); |
121 | QString errMsg; |
||
122 | int errLine, errCol; |
||
123 | if (!xmldoc.setContent(xml, &errMsg, &errLine, &errCol)) { |
||
124 | QMessageBox::information(this, "Error applying XML", |
||
125 | QString("Error applying xml line %1, col %2.\nMessage: %3").arg(errLine).arg(errCol).arg(errMsg)); |
||
3 | Werner | 126 | return; |
127 | } |
||
259 | werner | 128 | qDebug() << "XML file read."; |
28 | Werner | 129 | } |
3 | Werner | 130 | |
131 | |||
132 | void MainWindow::on_saveFile_clicked() |
||
133 | { |
||
134 | QString content = ui->iniEdit->toPlainText(); |
||
135 | if (!content.isEmpty()) |
||
16 | Werner | 136 | Helper::saveToTextFile(ui->initFileName->text(), content); |
3 | Werner | 137 | |
138 | } |
||
139 | |||
72 | Werner | 140 | |
772 | werner | 141 | void MainWindow::repaintArea(QPainter &) |
20 | Werner | 142 | { |
143 | // select drawing type... |
||
144 | switch (m_gfxtype) { |
||
145 | case 0: // paint FON cells |
||
259 | werner | 146 | return; |
25 | Werner | 147 | case 1: // paint Lightroom - studio --- painting is done on the background image of PaintArea |
20 | Werner | 148 | break; |
149 | case 2: // paint Lightroom |
||
150 | default: break; // no painting |
||
151 | } |
||
49 | Werner | 152 | // fix viewpoint |
153 | vp.setScreenRect(ui->PaintWidget->rect()); |
||
20 | Werner | 154 | } |
155 | |||
19 | Werner | 156 | void MainWindow::on_actionLightroom_triggered() |
157 | { |
||
158 | ui->editStack->setCurrentIndex(1); |
||
159 | ui->headerCaption->setText("Lightroom"); |
||
20 | Werner | 160 | m_gfxtype = 1; |
161 | ui->PaintWidget->update(); |
||
19 | Werner | 162 | } |
163 | |||
164 | void MainWindow::on_actionEdit_XML_settings_triggered() |
||
165 | { |
||
129 | Werner | 166 | |
19 | Werner | 167 | ui->editStack->setCurrentIndex(0); |
129 | Werner | 168 | |
20 | Werner | 169 | ui->PaintWidget->update(); |
19 | Werner | 170 | } |
171 | |||
172 | void MainWindow::on_actionFON_action_triggered() |
||
173 | { |
||
174 | ui->editStack->setCurrentIndex(2); |
||
175 | ui->headerCaption->setText("Field Of Neighborhood test environment"); |
||
20 | Werner | 176 | m_gfxtype = 0; |
177 | ui->PaintWidget->update(); |
||
19 | Werner | 178 | |
179 | } |
||
180 | |||
181 | void MainWindow::on_pbCreateLightroom_clicked() |
||
182 | { |
||
259 | werner | 183 | if (xmldoc.isNull()) { |
184 | Helper::msg("!!XML not loaded!!"); |
||
185 | return; |
||
186 | } |
||
187 | QDomElement docLightroom = xmldoc.documentElement(); // top element |
||
188 | |||
19 | Werner | 189 | if (docLightroom.isNull()) MSGRETURN("cant find node 'lightroom' in xml"); |
190 | int x,y,z; |
||
191 | x = docLightroom.firstChildElement("size").attribute("x").toInt(); |
||
192 | y = docLightroom.firstChildElement("size").attribute("y").toInt(); |
||
193 | z = docLightroom.firstChildElement("size").attribute("z").toInt(); |
||
32 | Werner | 194 | double cellsize = docLightroom.firstChildElement("size").attribute("cellsize").toDouble(); |
19 | Werner | 195 | |
196 | int hemisize = docLightroom.firstChildElement("hemigrid").attribute("size").toInt(); |
||
197 | double lat = docLightroom.firstChildElement("hemigrid").attribute("latitude").toFloat(); |
||
198 | double diffus = docLightroom.firstChildElement("hemigrid").attribute("diffus").toFloat(); |
||
199 | |||
200 | // create a lightroom object... |
||
20 | Werner | 201 | if (!lightroom) |
202 | lightroom = new LightRoom(); |
||
203 | |||
21 | Werner | 204 | lightroom->setup(x,y,z,cellsize, |
19 | Werner | 205 | hemisize,lat,diffus); |
25 | Werner | 206 | LightRoomObject *lro = new LightRoomObject(); |
28 | Werner | 207 | lro->setuptree(40., 20., "5*(1-x*x)"); |
25 | Werner | 208 | lightroom->setLightRoomObject(lro); |
23 | Werner | 209 | |
19 | Werner | 210 | qDebug() << "Lightroom setup complete"; |
211 | } |
||
23 | Werner | 212 | |
213 | void MainWindow::on_testLRO_clicked() |
||
214 | { |
||
24 | Werner | 215 | // setup a lightroom object, and do some tests... |
26 | Werner | 216 | double x = ui->lr_x->text().toDouble(); |
217 | double y = ui->lr_y->text().toDouble(); |
||
218 | double z = ui->lr_z->text().toDouble(); |
||
219 | double azi = ui->lrAzim->text().toDouble(); |
||
220 | double elev = ui->lrElevation->text().toDouble(); |
||
221 | |||
23 | Werner | 222 | LightRoomObject lro; |
25 | Werner | 223 | lro.setuptree(40., 10., "5*(1-x*x)"); |
26 | Werner | 224 | qDebug()<<"x:"<<x<<"y:"<<y<<"z:"<<z<<"azimuth:"<<azi<<"elevation:"<<elev << lro.hittest(x,y,z,RAD(azi), RAD(elev)); |
225 | //qDebug()<<"-10,-10,0 - azimuth 42, elev: 45:" << lro.hittest(-10,-10,0,RAD(42), RAD(45)); |
||
23 | Werner | 226 | } |
25 | Werner | 227 | |
228 | void MainWindow::on_lroTestHemi_clicked() |
||
229 | { |
||
230 | double x = double(ui->lrSliderX->value());// ui->lr_x->text().toDouble(); |
||
231 | double y = ui->lrSliderY->value(); |
||
232 | double z = ui->lrSliderZ->value(); |
||
233 | ui->lr_x->setText(QString::number(x)); |
||
234 | ui->lr_y->setText(QString::number(y)); |
||
235 | ui->lr_z->setText(QString::number(z)); |
||
236 | if (!lightroom) |
||
237 | MSGRETURN("Lightroom NULL!"); |
||
238 | DebugTimer t("single point"); |
||
31 | Werner | 239 | double res = lightroom->calculateGridAtPoint(x,y,z); |
240 | ui->lrHemiValue->setText(QString::number(res)); |
||
25 | Werner | 241 | // now paint... |
242 | //ui->PaintWidget->drawImage(); |
||
243 | lightroom->shadowGrid().paintGrid(ui->PaintWidget->drawImage()); |
||
244 | ui->PaintWidget->update(); // repaint |
||
245 | //qDebug() << lightroom->shadowGrid().dumpGrid(); |
||
246 | |||
247 | } |
||
248 | void MainWindow::on_lrLightGrid_clicked() |
||
249 | { |
||
250 | lightroom->solarGrid().paintGrid(ui->PaintWidget->drawImage()); |
||
251 | ui->PaintWidget->update(); // repaint |
||
252 | qDebug() << lightroom->solarGrid().dumpGrid(); |
||
253 | } |
||
254 | |||
255 | void MainWindow::on_lrCalcFullGrid_clicked() |
||
256 | { |
||
257 | if (!lightroom) |
||
258 | MSGRETURN("Lightroom NULL!"); |
||
259 | lightroom->calculateFullGrid(); |
||
27 | Werner | 260 | float maxvalue = lightroom->result().max(); |
261 | qDebug() << "maxvalue" << maxvalue; |
||
262 | const FloatGrid &result = lightroom->result(); |
||
263 | QString res; |
||
264 | for (int x=0;x<result.sizeX();x++){ |
||
265 | for (int y=0;y<result.sizeY();y++) { |
||
266 | res+=QString::number(result.constValueAtIndex(QPoint(x,y))) + ";"; |
||
267 | } |
||
268 | res+="\n"; |
||
269 | } |
||
270 | qDebug()<< res; |
||
25 | Werner | 271 | } |
272 | |||
273 | |||
259 | werner | 274 | void MainWindow::on_lrProcess_clicked() |
104 | Werner | 275 | { |
259 | werner | 276 | if (xmldoc.isNull()) { |
277 | Helper::msg("!!XML not loaded!!"); |
||
278 | return; |
||
121 | Werner | 279 | } |
104 | Werner | 280 | |
31 | Werner | 281 | QDomElement docElem = xmldoc.documentElement(); |
400 | werner | 282 | |
259 | werner | 283 | QString output_file = docElem.firstChildElement("outputStamp").text(); |
284 | QDomElement tree = docElem.firstChildElement("trees").firstChildElement("tree"); |
||
35 | Werner | 285 | |
259 | werner | 286 | double cut_threshold = docElem.firstChildElement("cutvalue").text().toDouble(); |
412 | werner | 287 | QString cut_mode = docElem.firstChildElement("cutoffMode").text(); |
404 | werner | 288 | QString agg_mode = docElem.firstChildElement("aggregationMode").text(); |
289 | int mode=-1; |
||
290 | if (agg_mode=="sum") { |
||
291 | mode=1; |
||
292 | qDebug() << "aggregation mode set to 'sum'"; |
||
293 | } |
||
294 | if (agg_mode=="mean") { |
||
295 | qDebug() << "aggregation mode set to 'mean'"; |
||
296 | mode=0; |
||
297 | } |
||
298 | if (mode==-1) { |
||
299 | Helper::msg("Error: invalid or no aggregationMode specified!"); |
||
300 | return; |
||
301 | } |
||
302 | |||
259 | werner | 303 | QString stamp_desc = docElem.firstChildElement("desc").text(); |
304 | QString binaryReaderStampFile = docElem.firstChildElement("readerStamp").text(); |
||
44 | Werner | 305 | qDebug() << "cutting stamps when averaged absoulte value of rings is below"<<cut_threshold; |
259 | werner | 306 | qDebug() << "reading binary stamp reader file" << binaryReaderStampFile; |
307 | |||
400 | werner | 308 | if (!Helper::question(QString("Create writer stamps?\ntarget=%1, \nreader stamps=%2").arg(output_file, binaryReaderStampFile))) |
259 | werner | 309 | return; |
64 | Werner | 310 | float crown, height, bhd; |
400 | werner | 311 | QString formula, name; |
31 | Werner | 312 | |
313 | LightRoomObject *lro = new LightRoomObject(); |
||
314 | lightroom->setLightRoomObject(lro); |
||
404 | werner | 315 | lightroom->setAggregationMode(mode); |
31 | Werner | 316 | |
42 | Werner | 317 | StampContainer readers; |
259 | werner | 318 | |
42 | Werner | 319 | QFile infile(binaryReaderStampFile); |
320 | infile.open(QIODevice::ReadOnly); |
||
321 | QDataStream in(&infile); |
||
322 | readers.load(in); |
||
323 | infile.close(); |
||
324 | |||
34 | Werner | 325 | StampContainer container; |
326 | container.useLookup(false); // disable lookup table (not necessary for creation) |
||
327 | |||
50 | Werner | 328 | DebugTimer creation_time("total creation of stamps"); |
329 | |||
30 | Werner | 330 | while (!tree.isNull()) { |
31 | Werner | 331 | name = tree.attribute("name"); |
332 | height = tree.attribute("h").toDouble(); |
||
333 | crown = tree.attribute("crown").toDouble(); |
||
34 | Werner | 334 | bhd = tree.attribute("bhd").toDouble(); |
31 | Werner | 335 | formula = tree.attribute("formula"); |
336 | /////////////////////////// |
||
337 | lro->setuptree(height, crown, formula); |
||
338 | qDebug() << "start" << name; |
||
339 | lightroom->calculateFullGrid(); |
||
35 | Werner | 340 | |
52 | Werner | 341 | // store as textfile: |
342 | //result = gridToString( lightroom->result() ); |
||
343 | //Helper::saveToTextFile(path + "\\ " + name + ".txt", result); |
||
344 | |||
345 | // save stamp as image: |
||
346 | //QImage img = gridToImage( lightroom->result() ); |
||
347 | //img.save(path + "\\ " + name + ".jpg", "JPG", 100); |
||
348 | |||
38 | Werner | 349 | // averaged copy: FloatGrid gr = lightroom->result().averaged(avg_cells); |
350 | const FloatGrid &gr = lightroom->result(); |
||
37 | Werner | 351 | // calculate sums... |
38 | Werner | 352 | QVector<double> sums; // stores sum per ring (rectangle) |
353 | QVector<double> rel_sum; // stores sum/px |
||
412 | werner | 354 | QVector<double> max_vals; // stores values in north direction |
37 | Werner | 355 | double sum; |
38 | Werner | 356 | int ring_count; |
132 | Werner | 357 | double total_sum = 0.; |
37 | Werner | 358 | for (int o=0; o<gr.sizeX()/2; o++) { |
38 | Werner | 359 | sum = 0; ring_count=0; |
37 | Werner | 360 | // top and bottom |
361 | for (int i=o; i<gr.sizeX()-o; i++) { |
||
362 | sum += gr(i, o); |
||
363 | sum += gr(i, gr.sizeX()-1-o); |
||
38 | Werner | 364 | ring_count+=2; |
37 | Werner | 365 | } |
366 | // left, right :: do not calculate the edges two times.... |
||
367 | for (int i=o+1; i<gr.sizeX()-o-1; i++) { |
||
368 | sum += gr(o, i); |
||
369 | sum += gr(gr.sizeX()-1-o, i); |
||
38 | Werner | 370 | ring_count+=2; |
37 | Werner | 371 | } |
132 | Werner | 372 | total_sum += sum; |
37 | Werner | 373 | sums.push_back(sum); |
38 | Werner | 374 | rel_sum.push_back(sum / double(ring_count) ); |
412 | werner | 375 | max_vals.push_back(gr(gr.sizeX()/2, gr.sizeX()-1-o)); // bottom.... |
37 | Werner | 376 | } |
38 | Werner | 377 | if (gr.sizeX()% 2) { |
132 | Werner | 378 | total_sum += gr(gr.sizeX()/2, gr.sizeX()/2); // center pixel for unevenly sized grids |
37 | Werner | 379 | sums.push_back(gr(gr.sizeX()/2, gr.sizeX()/2)); // center pixel for unevenly sized grids |
38 | Werner | 380 | rel_sum.push_back(gr(gr.sizeX()/2, gr.sizeX()/2)); // center pixel for unevenly sized grids |
412 | werner | 381 | max_vals.push_back(gr(gr.sizeX()/2, gr.sizeX()/2)); // center pixel |
38 | Werner | 382 | } |
383 | int end_ring, target_grid_size; |
||
132 | Werner | 384 | /* version < 20090905: average ring value |
38 | Werner | 385 | for (end_ring=0;end_ring<rel_sum.count();end_ring++) |
44 | Werner | 386 | if (rel_sum[end_ring]>cut_threshold) |
38 | Werner | 387 | break; |
132 | Werner | 388 | end_ring = rel_sum.count() - end_ring; // */ |
389 | |||
390 | // version > 20090905: based on total area |
||
412 | werner | 391 | if (cut_mode == "sum") { |
392 | double rsum = 0; |
||
393 | for (end_ring=0;end_ring<sums.count();end_ring++) { |
||
394 | rsum += sums[end_ring]; |
||
395 | // threshold: sum of influence > threshold |
||
396 | if (rsum>cut_threshold*total_sum) |
||
397 | break; |
||
398 | } |
||
399 | } else if (cut_mode == "north") { |
||
400 | // 20100527: based on direction with maximum values |
||
401 | for (end_ring=0;end_ring<sums.count();end_ring++) { |
||
402 | if (max_vals[end_ring]>cut_threshold) |
||
403 | break; |
||
404 | } |
||
405 | |||
406 | } else { |
||
407 | qDebug() << "ERROR: invalid cutoffMode (possible values: sum, north)!!! Exiting."; |
||
408 | return; |
||
132 | Werner | 409 | } |
410 | end_ring = sums.count() - end_ring; |
||
411 | if (end_ring<2) // minimum ring-count=2 (i.e. 9pixel) |
||
412 | end_ring=2; |
||
413 | |||
38 | Werner | 414 | target_grid_size = 2*end_ring - 1; // e.g. 3rd ring -> 5x5-matrix |
412 | werner | 415 | qDebug() << "break at ring" << end_ring << "with cutoff mode" << cut_mode; |
416 | qDebug() << "circle sum relsum maxvals"; |
||
37 | Werner | 417 | for (int i=0;i<sums.count();i++) |
412 | werner | 418 | qDebug() << i << sums[i] << rel_sum[i] << max_vals[i]; |
35 | Werner | 419 | |
37 | Werner | 420 | |
34 | Werner | 421 | // test: use subpixel averages .... |
422 | /* |
||
33 | Werner | 423 | FloatGrid gr3x3 = lightroom->result().averaged(3); |
32 | Werner | 424 | QImage img3x3 = gridToImage( gr3x3 ); |
425 | img3x3.save(path + "\\ " + name + "_3x3.jpg", "JPG", 100); |
||
426 | Helper::saveToTextFile(path + "\\ " + name + "_3x3.txt", gridToString(gr3x3)); |
||
427 | result=""; |
||
428 | for (int x=0;x<3;x++) |
||
429 | for (int y=0;y<3;y++) { |
||
33 | Werner | 430 | FloatGrid gr3x3 = lightroom->result().averaged(3,x,y); |
32 | Werner | 431 | result+="\r\n" + gridToString(gr3x3); |
432 | |||
433 | } |
||
34 | Werner | 434 | Helper::saveToTextFile(QString("%1\\%2_shift.txt").arg(path, name), result); */ |
435 | |||
436 | // store to container |
||
38 | Werner | 437 | Stamp *stamp = stampFromGrid(gr, target_grid_size); |
438 | if (!stamp) |
||
439 | return; |
||
40 | Werner | 440 | qDebug() << "created stamp with size (n x n)" << stamp->size() << "in an data-block of:" << stamp->dataSize(); |
42 | Werner | 441 | // process reading area |
442 | double maxradius = lro->maxRadius(); |
||
443 | const Stamp *readerstamp = readers.readerStamp(maxradius); |
||
444 | if (readerstamp) { |
||
445 | int offset = stamp->offset() - readerstamp->offset(); |
||
446 | qDebug() << "fetching read-sum. offset stamp" << stamp->offset() << "offset readerstamp" << readerstamp->offset(); |
||
447 | double sum = 0; |
||
448 | for (int x=0;x<readerstamp->size();x++) |
||
449 | for (int y=0;y<readerstamp->size(); y++) |
||
450 | sum += *(readerstamp->data(x,y)) * *(stamp->data(x+offset, y+offset)); |
||
451 | qDebug() << "sum of reader-area over stamp" << sum; |
||
452 | } else qDebug() << "!!! no readerstamp available!!!"; |
||
43 | Werner | 453 | |
35 | Werner | 454 | double hd = qRound( height*100 / bhd ); |
65 | Werner | 455 | container.addStamp(stamp,bhd, hd, lro->maxRadius()); // 3rd param was: , |
31 | Werner | 456 | /////////////////////////// |
30 | Werner | 457 | tree = tree.nextSiblingElement("tree"); |
458 | } |
||
31 | Werner | 459 | qDebug() << "finished!!!"; |
34 | Werner | 460 | // write container to a file.... |
259 | werner | 461 | QFile file(output_file); |
34 | Werner | 462 | file.open(QIODevice::WriteOnly); |
63 | Werner | 463 | container.setDescription(stamp_desc); // provided in xml... |
34 | Werner | 464 | QDataStream out(&file); // we will serialize the data into the file |
465 | container.save(out); |
||
466 | file.close(); |
||
35 | Werner | 467 | qDebug() << "current content of the container:"; |
468 | qDebug() << container.dump(); |
||
469 | } |
||
34 | Werner | 470 | |
259 | werner | 471 | |
35 | Werner | 472 | void MainWindow::on_lrLoadStamps_clicked() |
473 | { |
||
40 | Werner | 474 | { |
54 | Werner | 475 | QString fileName = Helper::fileDialog("Name for binary stamp file"); |
476 | if (fileName.isEmpty()) |
||
477 | return; |
||
478 | QFile infile(fileName); |
||
41 | Werner | 479 | infile.open(QIODevice::ReadOnly); |
480 | QDataStream in(&infile); |
||
481 | StampContainer container; |
||
482 | container.load(in); |
||
483 | infile.close(); |
||
54 | Werner | 484 | qDebug() << "Dumping content of Stamp-container" << fileName; |
41 | Werner | 485 | qDebug() << container.dump(); |
486 | // and the reader-stamps.... |
||
487 | } |
||
40 | Werner | 488 | } |
489 | |||
490 | |||
491 | // create "reader" stamps.... |
||
492 | void MainWindow::on_lrReadStamps_clicked() |
||
493 | { |
||
494 | FloatGrid grid; // use copy ctor |
||
802 | werner | 495 | grid.setup(QRectF(-21., -21, 42, 42),2.); // 0/0 is the center of the center cell |
35 | Werner | 496 | StampContainer container; |
40 | Werner | 497 | int totcount=0; |
498 | DebugTimer t; |
||
309 | werner | 499 | for (double radius=0.5; radius<=15; radius+=0.1) { |
40 | Werner | 500 | qDebug() << "creation of reader stamp for radius" << radius; |
501 | grid.initialize(0.); |
||
502 | float x,y; |
||
503 | int tested=0, yes=0; |
||
802 | werner | 504 | // the center point of the cell where the center of the tree is, |
505 | // is at 1m/1m (at a cell width of 2m) |
||
40 | Werner | 506 | for (x=-radius;x<=radius;x+=0.01) |
507 | for (y=-radius;y<=radius;y+=0.01) { |
||
508 | tested++; |
||
509 | if ( x*x + y*y < radius*radius) { |
||
510 | grid.valueAt(x,y)++; yes++; |
||
511 | } |
||
512 | } |
||
802 | werner | 513 | qDebug() << "tested" << tested << "hit" << yes << "ratio" << 4.*yes/double(tested); // that should be pi, right? |
40 | Werner | 514 | totcount+=tested; |
515 | FloatGrid ngrid = grid.normalized(1.); // normalize with 1 |
||
516 | // create a stamp with a fitting size |
||
517 | Stamp *stamp; |
||
54 | Werner | 518 | int width=11; |
802 | werner | 519 | // radius: 0..<1: 1, >=1 <3: 3, >=3 < 5: 5, ... |
520 | width = (((int)radius+1)/2)*2 + 1; |
||
521 | |||
40 | Werner | 522 | stamp = stampFromGrid(ngrid,width); |
523 | // save stamp |
||
524 | container.addReaderStamp(stamp, radius); |
||
525 | |||
526 | } // for (radius) |
||
527 | qDebug() << "tested a total of" << totcount; |
||
259 | werner | 528 | QString targetFile = xmldoc.documentElement().firstChildElement("readerStamp").text(); |
802 | werner | 529 | if (!Helper::question(QString("Save readerfile to %1?").arg(targetFile))) { |
530 | qDebug() << container.dump(); |
||
259 | werner | 531 | return; |
802 | werner | 532 | } |
259 | werner | 533 | QFile file(targetFile); |
400 | werner | 534 | if (!file.open(QIODevice::WriteOnly)) { |
535 | qDebug() << "Error opening reader file" << targetFile << "with error:" << file.errorString(); |
||
536 | } |
||
40 | Werner | 537 | QDataStream out(&file); // we will serialize the data into the file |
309 | werner | 538 | container.setDescription("Reader-stamps for crown-radii ranging from 0.5m to 15m, stepwidth is 0.1m."); |
40 | Werner | 539 | container.save(out); |
400 | werner | 540 | file.close(); |
35 | Werner | 541 | qDebug() << container.dump(); |
40 | Werner | 542 | |
543 | |||
30 | Werner | 544 | } |
58 | Werner | 545 | |
546 | |||
65 | Werner | 547 | |
548 | void MainWindow::on_openFile_clicked() |
||
549 | { |
||
550 | QString fileName = Helper::fileDialog("select XML-ini file for FonStudio..."); |
||
551 | if (fileName.isEmpty()) |
||
552 | return; |
||
553 | ui->initFileName->setText(fileName); |
||
554 | QString xmlFile = Helper::loadTextFile(ui->initFileName->text()); |
||
555 | ui->iniEdit->setPlainText(xmlFile); |
||
556 | } |
||
67 | Werner | 557 | |
400 | werner | 558 | |
559 | void MainWindow::on_reloadFile_clicked() |
||
560 | { |
||
561 | QString xmlFile = Helper::loadTextFile(ui->initFileName->text()); |
||
562 | ui->iniEdit->setPlainText(xmlFile); |
||
563 | } |