tychoBCG3D  0.2
 All Data Structures Namespaces Files Functions Variables
old_mainwindow.cpp
Go to the documentation of this file.
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "glwidget.h"
4 #include "help.h"
5 
6 #include <math.h>
7 #include <stdio.h>
8 #include <QFileDialog>
9 #include <QVector>
10 #include <QDebug>
11 #include <QColorDialog>
12 #include <QMessageBox>
13 
27 MainWindow::MainWindow(QWidget *parent) :
28  QMainWindow(parent),
29  ui(new Ui::MainWindow)
30 {
31 
32  ui->setupUi(this);
33 
34  ui->progressBar->setHidden(true);
35 
36  counter = 0;
37  norm_faktor = 2.0;
38 
39  //set the default colors
40  ui->glwidget->redAmbient = 0.92f;
41  ui->glwidget->greenAmbient = 0.58f;
42  ui->glwidget->blueAmbient = 0.18f;
43 
44  ui->glwidget->redModel = 0.5;
45  ui->glwidget->greenModel = 0.5;
46  ui->glwidget->blueModel = 0.5;
47 
48  ui->glwidget->backroundColor.setAlpha(1.0);
49  ui->glwidget->backroundColor.setRedF(0.2);
50  ui->glwidget->backroundColor.setGreenF(0.2);
51  ui->glwidget->backroundColor.setBlueF(0.2);
52 
53  ui->glwidget->drawer = 1;
54 
55  ui->glwidget->shininess = 50;
56  ui->glwidget->point_size = 1;
57 
58  //menu
59  connect(ui->actionOpen_Point_Data, SIGNAL(triggered()), this, SLOT(openfile_point_data()));
60  connect(ui->actionOpen_STL_Data_2, SIGNAL(triggered()), this, SLOT(openfile_stl_data()));
61  connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(on_actionQuit_triggered()));
62  connect(ui->actionReset_Boundary, SIGNAL(triggered()), this, SLOT(on_actionReset_Bounding_Box_triggered()));
63  connect(ui->actionMake_Boundary, SIGNAL(triggered()), this, SLOT(on_actionMake_Boundary_Conditions_triggered()));
64  connect(ui->actionSolid_Color, SIGNAL(triggered()), this, SLOT(modelColor()));
65  connect(ui->actionAmbient_Color, SIGNAL(triggered()), this, SLOT(ambientColor()));
66  connect(ui->actionBackground_Color, SIGNAL(triggered()), this, SLOT(setbackroundColor()));
67  connect(ui->actionCalcualte_Normal_Vectors, SIGNAL(triggered()), this, SLOT(calculateNormalVector()));
68  connect(ui->actionHelp_2, SIGNAL(triggered()), this, SLOT(showHelp()));
69 
70  //menubar
71  connect(ui->actionOpen_File_point_data, SIGNAL(triggered()), this, SLOT(openfile_point_data()));
72  connect(ui->actionOpen_STL_Data, SIGNAL(triggered()), this, SLOT(openfile_stl_data()));
73  connect(ui->actionColor_ambient_light, SIGNAL(triggered()), this, SLOT(ambientColor()));
74  connect(ui->actionColor_model, SIGNAL(triggered()), this, SLOT(modelColor()));
75  connect(ui->actionCalculate_normal_vectors, SIGNAL(triggered()), this, SLOT(calculateNormalVector()));
76  connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(on_actionQuit_triggered()));
77  connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(showHelp()));
78  connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
79 
80  //controls
81  connect(ui->edit_xmin, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
82  connect(ui->edit_ymin, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
83  connect(ui->edit_zmin, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
84  connect(ui->edit_xmax, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
85  connect(ui->edit_ymax, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
86  connect(ui->edit_zmax, SIGNAL(valueChanged(double)), this, SLOT(on_resize_bounding_box_text_lines()));
87  connect(ui->res_x,SIGNAL(editingFinished()),this, SLOT(alter_resolution_x()));
88  connect(ui->res_y,SIGNAL(editingFinished()),this, SLOT(alter_resolution_y()));
89  connect(ui->res_z,SIGNAL(editingFinished()),this, SLOT(alter_resolution_z()));
90  connect(ui->drawer_chooser, SIGNAL(currentIndexChanged(QString)), this, SLOT(set_drawer()));
91  connect(ui->dial, SIGNAL(sliderMoved(int)), this, SLOT(setShininess()));
92  connect(ui->dial_point_size, SIGNAL(sliderMoved(int)), this, SLOT(changePointSize()));
93 
94 }
95 
97 {
98  delete ui;
99 }
100 
107 {
108  FILE *fd;
109  char tmp_buffer[100];
110  float x, y, z, vx, vy, vz;
111  int res_x, res_y, res_z;
112  int counter = 0;
113  int triangular_facets = 0;
114 
115  ui->glwidget->stl_data[0].clear();
116  ui->glwidget->stl_data[1].clear();
117  ui->glwidget->stl_data[2].clear();
118 
119  ui->glwidget->coordiantes[0].clear();
120  ui->glwidget->coordiantes[1].clear();
121  ui->glwidget->coordiantes[2].clear();
122  ui->glwidget->coordiantes[3].clear();
123  ui->glwidget->coordiantes[4].clear();
124  ui->glwidget->coordiantes[5].clear();
125 
126  ui->glwidget->sampled_data[0].clear();
127  ui->glwidget->sampled_data[1].clear();
128  ui->glwidget->sampled_data[2].clear();
129 
130  ui->glwidget->x_min = ui->glwidget->x_max = ui->glwidget->y_min = ui->glwidget->y_max = ui->glwidget->z_min = ui->glwidget->z_max = 0.0;
132 
133  file = QFileDialog::getOpenFileName(this, tr("Open Point-Data File"),"",tr("FILE (*.txt)"));
134 
135  //Now we read the file
136  ui->glwidget->coordiantes[0].clear();
137  ui->glwidget->coordiantes[1].clear();
138  ui->glwidget->coordiantes[2].clear();
139 
140  if (file.length() != 0){
141 
142  fd = fopen(file.toUtf8().constData(),"r");
143 
144  ui->progressBar->setHidden(false);
145  ui->progressBar->setValue(0);
146 
147  fscanf(fd,"%f %f %f\n", &x_min_init, &y_min_init, &z_min_init);
148 
152 
153  fseek(fd,0,0);
154 
155  while(!feof(fd)){
156  fscanf(fd,"%s", &tmp_buffer);
157  if (strcmp(tmp_buffer,"\n") != 0) counter++;
158 
159  }
160 
161  triangular_facets = counter/6;
162 
163  counter = 0;
164 
165  fseek(fd,0,0);
166 
167  while(!feof(fd)){
168 
169  fscanf(fd,"%f %f %f %f %f %f\n", &x, &y, &z, &vx, &vy, &vz);
170 
171  ui->glwidget->coordiantes[0].append(x);
172  ui->glwidget->coordiantes[1].append(y);
173  ui->glwidget->coordiantes[2].append(z);
174 
175  ui->glwidget->coordiantes[3].append(vx);
176  ui->glwidget->coordiantes[4].append(vy);
177  ui->glwidget->coordiantes[5].append(vz);
178 
179  if (x < x_min_init) x_min_init = x;
180  if (x > x_max_init) x_max_init = x;
181  if (y < y_min_init) y_min_init = y;
182  if (y > y_max_init) y_max_init = y;
183  if (z < z_min_init) z_min_init = z;
184  if (z > z_max_init) z_max_init = z;
185 
186  counter++;
187 
188  ui->progressBar->setValue(100.0/triangular_facets*counter);
189 
190  }
191 
192  ui->progressBar->setHidden(true);
193 
194  fclose(fd);
195 
199 
200  for (int i = 0; i < ui->glwidget->coordiantes[0].size(); i++){
201 
202  ui->glwidget->coordiantes[0][i] = (ui->glwidget->coordiantes[0][i] - x_min_init - diameter_x/2.0) * (norm_faktor / diameter_x);
203  ui->glwidget->coordiantes[1][i] = (ui->glwidget->coordiantes[1][i] - y_min_init - diameter_y/2.0) * (norm_faktor / diameter_x);
204  ui->glwidget->coordiantes[2][i] = (ui->glwidget->coordiantes[2][i] - z_min_init - diameter_z/2.0) * (norm_faktor / diameter_x);
205  }
206 
207  ui->glwidget->x_min = x_min_init = (-diameter_x/2.0)*(norm_faktor / diameter_x);
208  ui->glwidget->y_min = y_min_init = (-diameter_y/2.0)*(norm_faktor / diameter_x);
209  ui->glwidget->z_min = z_min_init = (-diameter_z/2.0)*(norm_faktor / diameter_x);
210 
211  ui->glwidget->x_max = x_max_init = (diameter_x/2.0)*(norm_faktor / diameter_x);
212  ui->glwidget->y_max = y_max_init = (diameter_y/2.0)*(norm_faktor / diameter_x);
213  ui->glwidget->z_max = z_max_init = (diameter_z/2.0)*(norm_faktor / diameter_x);
214 
215  res_x = (int)(300.0);
216  res_y = (int)((300.0/diameter_x * diameter_y) + 0.5);
217  res_z = (int)((300.0/diameter_x * diameter_z) + 0.5);;
218 
219  ui->res_x->setValue(res_x);
220  ui->res_y->setValue(res_y);
221  ui->res_z->setValue(res_z);
222 
223  ui->edit_xmin->setValue(x_min_init);
224  ui->edit_ymin->setValue(y_min_init);
225  ui->edit_zmin->setValue(z_min_init);
226  ui->edit_xmax->setValue(x_max_init);
227  ui->edit_ymax->setValue(y_max_init);
228  ui->edit_zmax->setValue(z_max_init);
229 
230 
231  ui->glwidget->updateGL();
232  }
233 }
234 
240 {
241  FILE *fd;
242  char buffer[50];
243  char tmp_buffer[100];
244  int bin_or_string = 0;
245  float x, y, z;
246  float norm_x, norm_y, norm_z;
247  int res_x, res_y, res_z;
248  unsigned int counter = 0;
249  unsigned short attribute;
250  unsigned int triangular_facets;
251 
252  ui->glwidget->stl_data[0].clear();
253  ui->glwidget->stl_data[1].clear();
254  ui->glwidget->stl_data[2].clear();
255 
256  ui->glwidget->coordiantes[0].clear();
257  ui->glwidget->coordiantes[1].clear();
258  ui->glwidget->coordiantes[2].clear();
259  ui->glwidget->coordiantes[3].clear();
260  ui->glwidget->coordiantes[4].clear();
261  ui->glwidget->coordiantes[5].clear();
262 
263  ui->glwidget->sampled_data[0].clear();
264  ui->glwidget->sampled_data[1].clear();
265  ui->glwidget->sampled_data[2].clear();
266 
267  ui->glwidget->x_min = ui->glwidget->x_max = ui->glwidget->y_min = ui->glwidget->y_max = ui->glwidget->z_min = ui->glwidget->z_max = 0.0;
268  x_min_init = y_min_init = z_min_init = x_max_init = y_max_init = z_max_init = 0.0;
269 
270  x = y = z = 0.0;
271  //buffer .clear();
272 
273  file = QFileDialog::getOpenFileName(this, tr("Open STL-File"),"",tr("FILE (*.stl)"));
274 
275  //Now we read the file
276  ui->glwidget->stl_data[0].clear();
277  ui->glwidget->stl_data[1].clear();
278  ui->glwidget->stl_data[2].clear();
279 
280  if (file.length() != 0){
281 
282  ui->progressBar->setHidden(false);
283  ui->progressBar->setValue(0);
284 
285  fd = fopen(file.toUtf8().constData(),"r");
286 
287  //decide binary or text file
288  fread(&buffer, 6, sizeof(char), fd);
289  fseek(fd,0,0);
290 
291  QString tmp = "";
292 
293  for (int i = 0; i < 5; i++) tmp+=buffer[i];
294 
295  if (tmp == "solid") bin_or_string = 0;
296  if (tmp != "solid") bin_or_string = 1;
297 
298  fclose(fd);
299 
300  counter = 0;
301 
302  qDebug() << bin_or_string;
303 
304  //an ascii stl file
305  if (bin_or_string == 0){
306 
307  fd = fopen(file.toUtf8().constData(),"r");
308 
309  while(!feof(fd)){
310 
311  fscanf(fd,"%s", &tmp_buffer);
312  if (strcmp(tmp_buffer,"normal") == 0) counter++;
313  if (strcmp(tmp_buffer,"vertex") == 0) counter++;
314  }
315 
316  triangular_facets = counter;
317  counter = 0;
318 
319  fseek(fd,0,0);
320 
321  while(!feof(fd)){
322  fscanf(fd,"%s", &tmp_buffer);
323 
324  if (strcmp(tmp_buffer,"normal") == 0){
325 
326  fscanf(fd,"%f %f %f", &norm_x, &norm_y, &norm_z);
327 
328  ui->glwidget->stl_data[0].append(norm_x);
329  ui->glwidget->stl_data[1].append(norm_y);
330  ui->glwidget->stl_data[2].append(norm_z);
331 
332  counter++;
333  }
334 
335  if (strcmp(tmp_buffer,"vertex") == 0){
336 
337  fscanf(fd,"%f %f %f", &x, &y, &z);
338  counter++;
339 
340  if (counter == 1){
341 
342  x_max_init = x_min_init = x;
343  y_max_init = y_min_init = y;
344  z_max_init = z_min_init = z;
345  }
346 
347  ui->glwidget->stl_data[0].append(x);
348  ui->glwidget->stl_data[1].append(y);
349  ui->glwidget->stl_data[2].append(z);
350 
351  if (x < x_min_init) x_min_init = x;
352  if (x > x_max_init) x_max_init = x;
353  if (y < y_min_init) y_min_init = y;
354  if (y > y_max_init) y_max_init = y;
355  if (z < z_min_init) z_min_init = z;
356  if (z > z_max_init) z_max_init = z;
357 
358  counter++;
359 
360  }
361 
362  ui->progressBar->setValue(100.0/triangular_facets*counter);
363  }
364 
365  ui->progressBar->setHidden(true);
366 
367  fclose(fd);
368  }
369 
370  counter = 0;
371 
372  //a binary stl file
373  if (bin_or_string == 1){
374 
375  fd = fopen(file.toUtf8().constData(),"rb");
376 
377  //shift a couple of bits
378  fseek(fd,80,0);
379 
380  fread(&triangular_facets, 1, sizeof(unsigned int), fd);
381 
382  while(counter < triangular_facets){
383 
384  norm_x = norm_y = norm_z = 0.0;
385  x = y = z = 0.0;
386 
387  fread(&norm_x, 1, sizeof(float), fd);
388  fread(&norm_y, 1, sizeof(float), fd);
389  fread(&norm_z, 1, sizeof(float), fd);
390 
391  ui->glwidget->stl_data[0].append(norm_x);
392  ui->glwidget->stl_data[1].append(norm_y);
393  ui->glwidget->stl_data[2].append(norm_z);
394 
395  fread(&x, 1, sizeof(float), fd);
396  fread(&y, 1, sizeof(float), fd);
397  fread(&z, 1, sizeof(float), fd);
398 
399  ui->glwidget->stl_data[0].append(x);
400  ui->glwidget->stl_data[1].append(y);
401  ui->glwidget->stl_data[2].append(z);
402 
403  fread(&x, 1, sizeof(float), fd);
404  fread(&y, 1, sizeof(float), fd);
405  fread(&z, 1, sizeof(float), fd);
406 
407  ui->glwidget->stl_data[0].append(x);
408  ui->glwidget->stl_data[1].append(y);
409  ui->glwidget->stl_data[2].append(z);
410 
411  fread(&x, 1, sizeof(float), fd);
412  fread(&y, 1, sizeof(float), fd);
413  fread(&z, 1, sizeof(float), fd);
414 
415  ui->glwidget->stl_data[0].append(x);
416  ui->glwidget->stl_data[1].append(y);
417  ui->glwidget->stl_data[2].append(z);
418 
419  fread(&attribute, 1, sizeof(unsigned short), fd);
420 
421  counter++;
422 
423  ui->progressBar->setValue(100.0/triangular_facets*counter);
424 
425  if (counter == 1){
426 
427  x_max_init = x_min_init = x;
428  y_max_init = y_min_init = y;
429  z_max_init = z_min_init = z;
430  }
431 
432  if (x < x_min_init) x_min_init = x;
433  if (x > x_max_init) x_max_init = x;
434  if (y < y_min_init) y_min_init = y;
435  if (y > y_max_init) y_max_init = y;
436  if (z < z_min_init) z_min_init = z;
437  if (z > z_max_init) z_max_init = z;
438 
439  }
440 
441  ui->progressBar->setHidden(true);
442 
443  fclose(fd);
444  }
445 
447  diameter_y = y_max_init - y_min_init;
448  diameter_z = z_max_init - z_min_init;
449 
450  for (int i = 0; i < ui->glwidget->stl_data[0].size(); i++){
451 
452  if (i%4==0) continue;
453 
454  ui->glwidget->stl_data[0][i] = (ui->glwidget->stl_data[0][i] - x_min_init - diameter_x/2.0) * (norm_faktor / diameter_x);
455  ui->glwidget->stl_data[1][i] = (ui->glwidget->stl_data[1][i] - y_min_init - diameter_y/2.0) * (norm_faktor / diameter_x);
456  ui->glwidget->stl_data[2][i] = (ui->glwidget->stl_data[2][i] - z_min_init - diameter_z/2.0) * (norm_faktor / diameter_x);
457  }
458 
459  ui->glwidget->x_min = x_min_init = (-diameter_x/2.0)*(norm_faktor / diameter_x);
460  ui->glwidget->y_min = y_min_init = (-diameter_y/2.0)*(norm_faktor / diameter_x);
461  ui->glwidget->z_min = z_min_init = (-diameter_z/2.0)*(norm_faktor / diameter_x);
462 
463  ui->glwidget->x_max = x_max_init = (diameter_x/2.0)*(norm_faktor / diameter_x);
464  ui->glwidget->y_max = y_max_init = (diameter_y/2.0)*(norm_faktor / diameter_x);
465  ui->glwidget->z_max = z_max_init = (diameter_z/2.0)*(norm_faktor / diameter_x);
466 
467  res_x = (int)(300.0);
468  res_y = (int)((300.0/diameter_x * diameter_y) + 0.5);
469  res_z = (int)((300.0/diameter_x * diameter_z) + 0.5);;
470 
471  ui->res_x->setValue(res_x);
472  ui->res_y->setValue(res_y);
473  ui->res_z->setValue(res_z);
474 
475  ui->edit_xmin->setValue(x_min_init);
476  ui->edit_ymin->setValue(y_min_init);
477  ui->edit_zmin->setValue(z_min_init);
478  ui->edit_xmax->setValue(x_max_init);
479  ui->edit_ymax->setValue(y_max_init);
480  ui->edit_zmax->setValue(z_max_init);
481 
482  ui->glwidget->init();
483  ui->glwidget->updateGL();
484 
485  }
486 
487 }
488 
490 {
491  qApp->exit();
492 }
493 
502 
503  ui->glwidget->x_min = ui->edit_xmin->value();
504  ui->glwidget->y_min = ui->edit_ymin->value();
505  ui->glwidget->z_min = ui->edit_zmin->value();
506  ui->glwidget->x_max = ui->edit_xmax->value();
507  ui->glwidget->y_max = ui->edit_ymax->value();
508  ui->glwidget->z_max = ui->edit_zmax->value();
509 
513 
514  ui->glwidget->updateGL();
515 }
516 
522 {
523 
524  ui->glwidget->x_min = x_min_init;
525  ui->glwidget->y_min = y_min_init;
526  ui->glwidget->z_min = z_min_init;
527  ui->glwidget->x_max = x_max_init;
528  ui->glwidget->y_max = y_max_init;
529  ui->glwidget->z_max = z_max_init;
530 
531  ui->edit_xmin->setValue(x_min_init);
532  ui->edit_ymin->setValue(y_min_init);
533  ui->edit_zmin->setValue(z_min_init);
534  ui->edit_xmax->setValue(x_max_init);
535  ui->edit_ymax->setValue(y_max_init);
536  ui->edit_zmax->setValue(z_max_init);
537 
541 
542  ui->glwidget->updateGL();
543 
544 }
545 
552 {
553 
554  if ((ui->glwidget->stl_data[0].size()==0)&&(ui->glwidget->coordiantes[0].size()==0)){
555 
556  QMessageBox msgBox;
557  msgBox.setText("Please load first some data.");
558  msgBox.exec();
559  }
560 
561  if ((ui->glwidget->stl_data[0].size()!=0)||(ui->glwidget->coordiantes[0].size()!=0)){
562 
563  FILE *fd;
564  QString file_save;
565  file_save = QFileDialog::getSaveFileName(this, tr("TYCHO boundary-conditions"),"",tr("Tycho Boundary File (*.tyc)"));
566  QFileInfo file(file_save);
567 
568  if (!file_save.isEmpty()){
569 
570  if(file.suffix().isEmpty()) file_save += ".tyc";
571 
572  float sx, sy, sz;
573  int ZAX, ZAY, ZAZ;
574  int i, j, k, l;
575  int tmp;
576  int counter;
577 
578  float vertex1[3];
579  float vertex2[3];
580  float vertex3[3];
581 
582  //upper limits and values for running indices for the sample algol for stl data
583  int nu, nw;
584  int max_u, max_w, max_uw;
585  int max_ax, max_ay, max_az;
586  int max_bx, max_by, max_bz;
587 
588  //triangle distance-vectors
589  float ux, uy, uz;
590  float wx, wy, wz;
591 
592  //point on triangle
593  float px, py, pz;
594 
595  ZAX = ui->res_x->value();
596  ZAY = ui->res_y->value();
597  ZAZ = ui->res_z->value();
598 
599 
600  ui->glwidget->x_min = ui->edit_xmin->value();
601  ui->glwidget->y_min = ui->edit_ymin->value();
602  ui->glwidget->z_min = ui->edit_zmin->value();
603  ui->glwidget->x_max = ui->edit_xmax->value();
604  ui->glwidget->y_max = ui->edit_ymax->value();
605  ui->glwidget->z_max = ui->edit_zmax->value();
606 
607  diameter_x = ui->glwidget->x_max - ui->glwidget->x_min;
608  diameter_y = ui->glwidget->y_max - ui->glwidget->y_min;
609  diameter_z = ui->glwidget->z_max - ui->glwidget->z_min;
610 
611  sx = (diameter_x/(float)ZAX);
612  sy = (diameter_y/(float)ZAY);
613  sz = (diameter_z/(float)ZAZ);
614 
615  bounding = (int ***)calloc((size_t)ZAX, sizeof(int **));
616  for (k = 0; k < ZAX; k++) {
617  bounding[k] = (int **)calloc((size_t)ZAY, sizeof(int *));
618  if ( !bounding[k] ) {
619  fprintf(stderr, "Could not allocate memory.\n");
620  exit(1);
621  }
622  for (j = 0; j < ZAY; j++) {
623  bounding[k][j] = (int *)calloc((size_t)ZAZ, sizeof(int));
624  if ( !bounding[k][j] ) {
625  fprintf(stderr, "Could not allocate memory.\n");
626  exit(1);
627  }
628  }
629  }
630 
631  //Point Data sampled on a grid
632  if (ui->glwidget->coordiantes[0].size() > 0){
633 
634  ui->progressBar->setHidden(false);
635  ui->progressBar->setValue(0);
636 
637  counter = 0;
638 
639  for (l = 0; l < ui->glwidget->coordiantes[0].size(); l++) // Für jedes Partikel
640  {
641 
642  ui->glwidget->coordiantes[0][l] += -(ui->glwidget->x_min);
643  ui->glwidget->coordiantes[1][l] += -(ui->glwidget->y_min);
644  ui->glwidget->coordiantes[2][l] += -(ui->glwidget->z_min);
645 
646  i = (int)(floor(((ui->glwidget->coordiantes[0][l])/sx)));//Mit floor werden alle Partikel einer Zelle zugeordnet.Es werden also alle Partikel im selben sx der selben Zelle zugeordnet
647  j = (int)(floor(((ui->glwidget->coordiantes[1][l])/sy)));//Der nächste Gitterpunkt wird bestimmt. Mit -175 in x und y Koordinatentransformation, um Würfel ins Zentrum zu setzen.
648  k = (int)(floor(((ui->glwidget->coordiantes[2][l])/sz)));
649 
650  if ((i < 0)||(j < 0)||(k < 0)||(i > ZAX - 1)||(j > ZAY - 1)||(k > ZAZ - 1)) {
651 
652  ui->glwidget->coordiantes[0][l] += ui->glwidget->x_min;
653  ui->glwidget->coordiantes[1][l] += ui->glwidget->y_min;
654  ui->glwidget->coordiantes[2][l] += ui->glwidget->z_min;
655 
656  continue;
657  }
658 
659  bounding[i][j][k] += 1;
660 
661  ui->glwidget->coordiantes[0][l] += ui->glwidget->x_min;
662  ui->glwidget->coordiantes[1][l] += ui->glwidget->y_min;
663  ui->glwidget->coordiantes[2][l] += ui->glwidget->z_min;
664 
665  counter++;
666 
667  ui->progressBar->setValue(100.0/ui->glwidget->coordiantes[0].size()*counter);
668 
669  }
670 
671  ui->progressBar->setHidden(true);
672  }
673 
674 
675  //STL Data sampled on a grid
676  if (ui->glwidget->stl_data[0].size() > 0){
677 
678  ui->progressBar->setHidden(false);
679  ui->progressBar->setValue(0);
680 
681  counter = 0;
682 
683  // for each triangle (remember first the norm vector, then the 3 vertices
684  for (l = 0; l <= ui->glwidget->stl_data[0].size() - 4; l = l + 4)
685  {
686 
687  //just to be sure
688  vertex1[0] = ui->glwidget->stl_data[0].at(l+1)-(ui->glwidget->x_min);
689  vertex1[1] = ui->glwidget->stl_data[1].at(l+1)-(ui->glwidget->y_min);
690  vertex1[2] = ui->glwidget->stl_data[2].at(l+1)-(ui->glwidget->z_min);
691  vertex2[0] = ui->glwidget->stl_data[0].at(l+2)-(ui->glwidget->x_min);
692  vertex2[1] = ui->glwidget->stl_data[1].at(l+2)-(ui->glwidget->y_min);
693  vertex2[2] = ui->glwidget->stl_data[2].at(l+2)-(ui->glwidget->z_min);
694  vertex3[0] = ui->glwidget->stl_data[0].at(l+3)-(ui->glwidget->x_min);
695  vertex3[1] = ui->glwidget->stl_data[1].at(l+3)-(ui->glwidget->y_min);
696  vertex3[2] = ui->glwidget->stl_data[2].at(l+3)-(ui->glwidget->z_min);
697 
698  ux = vertex2[0] - vertex1[0];
699  uy = vertex2[1] - vertex1[1];
700  uz = vertex2[2] - vertex1[2];
701 
702  wx = vertex3[0] - vertex1[0];
703  wy = vertex3[1] - vertex1[1];
704  wz = vertex3[2] - vertex1[2];
705 
706  max_ax = ceil(fabs(ux/sx));
707  max_ay = ceil(fabs(uy/sy));
708  max_az = ceil(fabs(uz/sz));
709 
710  max_u = max_ax + max_ay + max_az;
711 
712  max_bx = ceil(fabs(wx/sx));
713  max_by = ceil(fabs(wy/sy));
714  max_bz = ceil(fabs(wz/sz));
715 
716  max_w = max_bx + max_by + max_bz;
717  max_uw = max_u + max_w;
718 
719  for (nu = 0; nu <= max_uw; nu++){
720  for (nw = 0; nw <= max_uw - nu; nw++){
721 
722  px = vertex1[0] + ((1.0 * nu)/max_uw) * ux + ((1.0 * nw)/max_uw) * wx;
723  py = vertex1[1] + ((1.0 * nu)/max_uw) * uy + ((1.0 * nw)/max_uw) * wy;
724  pz = vertex1[2] + ((1.0 * nu)/max_uw) * uz + ((1.0 * nw)/max_uw) * wz;
725 
726  i = (int)(floor((px/sx)));
727  j = (int)(floor((py/sy)));
728  k = (int)(floor((pz/sz)));
729 
730  if ((i < 0)||(j < 0)||(k < 0)||(i > ZAX - 1)||(j > ZAY - 1)||(k > ZAZ - 1)) continue;
731 
732  bounding[i][j][k] = 1;
733  }
734  }
735 
736  counter = counter + 4;
737 
738  ui->progressBar->setValue(100.0/ui->glwidget->stl_data[0].size()*counter);
739  }
740 
741  ui->progressBar->setHidden(true);
742  }
743 
744  //here the TYCHO boundary file is written
745  fd = fopen(file_save.toUtf8(), "w");
746  fprintf(fd,"This is a TYCHO boundary condition file.\n");
747  fprintf(fd,"X %i\n", ZAX);
748  fprintf(fd,"Y %i\n", ZAY);
749  fprintf(fd,"Z %i\n", ZAZ);
750  fseek(fd, 200, SEEK_SET);
751 
752  for (int i = 0; i < ZAX; i++) {
753  for (int j = 0; j < ZAY; j++) {
754  for (int k = 0; k < ZAZ; k++) {
755 
756  tmp = 0;
757  if (bounding[i][j][k] > 0) tmp = 1;
758  fwrite(&tmp, 1, sizeof (int), fd);
759  }
760  }
761  }
762 
763  draw_sampled_data(ZAX, ZAY, ZAZ, bounding);
764 
765  free(bounding);
766 
767  fclose(fd);
768 
769  }
770  }
771 }
772 
780 
781  int res_x;
782  int res_y;
783  int res_z;
784  double dia_x;
785  double dia_y;
786  double dia_z;
787 
788  dia_x = ui->edit_xmax->value()-ui->edit_xmin->value();
789  dia_y = ui->edit_ymax->value()-ui->edit_ymin->value();
790  dia_z = ui->edit_zmax->value()-ui->edit_zmin->value();
791 
792  res_x = ui->res_x->value();
793 
794  if (dia_x != 0.0){
795  res_y = (int)(res_x * dia_y / dia_x);
796  ui->res_y->setValue(res_y);
797  }
798  if (dia_x != 0.0){
799  res_z = (int)(res_x * dia_z / dia_x);
800  ui->res_z->setValue(res_z);
801  }
802 }
803 
811 
812  int res_x;
813  int res_y;
814  int res_z;
815  double dia_x;
816  double dia_y;
817  double dia_z;
818 
819  dia_x = ui->edit_xmax->value()-ui->edit_xmin->value();
820  dia_y = ui->edit_ymax->value()-ui->edit_ymin->value();
821  dia_z = ui->edit_zmax->value()-ui->edit_zmin->value();
822 
823  res_y = ui->res_y->value();
824 
825  if (dia_y != 0.0){
826  res_x = (int)(res_y * dia_x / dia_y);
827  ui->res_x->setValue(res_x);
828  }
829  if (dia_y != 0.0){
830  res_z = (int)(res_y * dia_z / dia_y);
831  ui->res_z->setValue(res_z);
832  }
833 }
834 
842 
843  int res_x;
844  int res_y;
845  int res_z;
846  double dia_x;
847  double dia_y;
848  double dia_z;
849 
850  dia_x = ui->edit_xmax->value()-ui->edit_xmin->value();
851  dia_y = ui->edit_ymax->value()-ui->edit_ymin->value();
852  dia_z = ui->edit_zmax->value()-ui->edit_zmin->value();
853 
854  res_z = ui->res_z->value();
855 
856  if (dia_z != 0.0){
857  res_x = (int)(res_z * dia_x / dia_z);
858  ui->res_x->setValue(res_x);
859  }
860  if (dia_z != 0.0){
861  res_y = (int)(res_z * dia_y / dia_z);
862  ui->res_y->setValue(res_y);
863  }
864 }
865 
872 {
873 
874  QColor color = QColorDialog::getColor(Qt::black, this, "Ambient Colot", QColorDialog::DontUseNativeDialog);
875  if(color.isValid())
876  {
877 
878  ui->glwidget->redAmbient = (float)color.red()/255.0;
879  ui->glwidget->greenAmbient = (float)color.green()/255.0;
880  ui->glwidget->blueAmbient = (float)color.blue()/255.0;
881 
882  ui->glwidget->init();
883  ui->glwidget->updateGL();
884  }
885 }
886 
892 {
893 
894  QColor color = QColorDialog::getColor(Qt::black, this, "Model Color", QColorDialog::DontUseNativeDialog);
895  if(color.isValid())
896  {
897 
898  ui->glwidget->redModel = (float)color.red()/255.0;
899  ui->glwidget->greenModel = (float)color.green()/255.0;
900  ui->glwidget->blueModel = (float)color.blue()/255.0;
901 
902  ui->glwidget->init();
903  ui->glwidget->updateGL();
904  }
905 }
906 
912 {
913 
914  QColor color = QColorDialog::getColor(Qt::black, this, "Baclground Color", QColorDialog::DontUseNativeDialog);
915  if(color.isValid())
916  {
917 
918  ui->glwidget->backroundColor = color;
919 
920  ui->glwidget->init();
921  ui->glwidget->updateGL();
922  }
923 }
924 
931 
932  int l;
933 
934  float vertex1[3];
935  float vertex2[3];
936  float vertex3[3];
937 
938  float ux;
939  float uy;
940  float uz;
941 
942  float wx;
943  float wy;
944  float wz;
945 
946  float xComp;
947  float yComp;
948  float zComp;
949 
950  if (ui->glwidget->stl_data[0].size()>0){
951 
952 
953  for (l = 0; l <= ui->glwidget->stl_data[0].size() - 4; l = l + 4)
954  {
955 
956  //just to be sure
957  vertex1[0] = ui->glwidget->stl_data[0].at(l+1)-(ui->glwidget->x_min);
958  vertex1[1] = ui->glwidget->stl_data[1].at(l+1)-(ui->glwidget->y_min);
959  vertex1[2] = ui->glwidget->stl_data[2].at(l+1)-(ui->glwidget->z_min);
960  vertex2[0] = ui->glwidget->stl_data[0].at(l+2)-(ui->glwidget->x_min);
961  vertex2[1] = ui->glwidget->stl_data[1].at(l+2)-(ui->glwidget->y_min);
962  vertex2[2] = ui->glwidget->stl_data[2].at(l+2)-(ui->glwidget->z_min);
963  vertex3[0] = ui->glwidget->stl_data[0].at(l+3)-(ui->glwidget->x_min);
964  vertex3[1] = ui->glwidget->stl_data[1].at(l+3)-(ui->glwidget->y_min);
965  vertex3[2] = ui->glwidget->stl_data[2].at(l+3)-(ui->glwidget->z_min);
966 
967  ux = vertex2[0] - vertex1[0];
968  uy = vertex2[1] - vertex1[1];
969  uz = vertex2[2] - vertex1[2];
970 
971  wx = vertex3[0] - vertex1[0];
972  wy = vertex3[1] - vertex1[1];
973  wz = vertex3[2] - vertex1[2];
974 
975  xComp = uy*wz - uz*wy;
976  yComp = uz*wx - ux*wz;
977  zComp = ux*wy - uy*wx;
978 
979  ui->glwidget->stl_data[0][l] = xComp;
980  ui->glwidget->stl_data[1][l] = yComp;
981  ui->glwidget->stl_data[2][l] = zComp;
982  }
983  }
984 
985  ui->glwidget->updateGL();
986 
987 }
988 
999 void MainWindow::draw_sampled_data(int ZAX, int ZAY, int ZAZ, int ***bounding){
1000 
1001  ui->glwidget->x_min = ui->edit_xmin->value();
1002  ui->glwidget->y_min = ui->edit_ymin->value();
1003  ui->glwidget->z_min = ui->edit_zmin->value();
1004  ui->glwidget->x_max = ui->edit_xmax->value();
1005  ui->glwidget->y_max = ui->edit_ymax->value();
1006  ui->glwidget->z_max = ui->edit_zmax->value();
1007 
1008  ui->glwidget->sampled_data[0].clear();
1009  ui->glwidget->sampled_data[1].clear();
1010  ui->glwidget->sampled_data[2].clear();
1011 
1012  float spacing_x = (ui->glwidget->x_max - ui->glwidget->x_min)/(float)ZAX;
1013  float spacing_y = (ui->glwidget->y_max - ui->glwidget->y_min)/(float)ZAY;
1014  float spacing_z = (ui->glwidget->z_max - ui->glwidget->z_min)/(float)ZAZ;
1015 
1016  ui->progressBar->setHidden(false);
1017 
1018  for (int l = 0; l < ZAX; l++){
1019  for (int m = 0; m < ZAY; m++){
1020  for (int n = 0; n < ZAZ; n++){
1021 
1022  if (bounding[l][m][n] != 0){
1023 
1024  ui->glwidget->sampled_data[0].append(ui->glwidget->x_min + l*spacing_x);
1025  ui->glwidget->sampled_data[1].append(ui->glwidget->y_min + m*spacing_y);
1026  ui->glwidget->sampled_data[2].append(ui->glwidget->z_min + n*spacing_z);
1027 
1028  }
1029  }
1030  }
1031  ui->progressBar->setValue(100.0/ZAX*l);
1032  }
1033 
1034  ui->progressBar->setHidden(true);
1035 
1036 }
1037 
1042 void MainWindow::set_drawer(){
1043 
1044  if (ui->drawer_chooser->currentText().compare("Raw Data")==0) ui->glwidget->drawer = 1;
1045  if (ui->drawer_chooser->currentText().compare("Sampled Data")==0) ui->glwidget->drawer = 2;
1046 
1047  ui->glwidget->updateGL();
1048 }
1049 
1055 
1056  ui->glwidget->point_size = ui->dial_point_size->value();
1057  ui->glwidget->updateGL();
1058 
1059 }
1060 
1066 
1067  ui->glwidget->shininess = 128 - ui->dial->value();
1068  ui->glwidget->updateGL();
1069 }
1070 
1075 void MainWindow::showHelp(){
1076 
1077  myhelp = new help;
1078  myhelp->setWindowModality(Qt::ApplicationModal);
1079  myhelp->setWindowFlags(Qt::WindowStaysOnTopHint);
1080  myhelp->show();
1081 
1082 }
1083 
1088 void MainWindow::showAbout(){
1089 
1090  myAbout = new about;
1091  myAbout->setWindowModality(Qt::ApplicationModal);
1092  myAbout->setWindowFlags(Qt::WindowStaysOnTopHint);
1093  myAbout->show();
1094 
1095 }