tychoBCGEN  0.5
 All Data Structures Namespaces Files Functions Variables
openfile.cpp
Go to the documentation of this file.
1 
4 #include "mainwindow.h"
5 #include "ui_mainwindow.h"
6 #include "myscene.h"
7 #include <QFileDialog>
8 #include <QPixmap>
9 #include <QString>
10 #include <QGraphicsView>
11 #include <QGraphicsScene>
12 #include <QPainter>
13 
18 {
19  file = QFileDialog::getOpenFileName(this, tr("Open File"),"/home/kapf/tmp",tr("Images (*.jpeg *.jpg *.png *.bmp *.gif *.tif)"));
20 
22 
23  image.load(file);
24 
25  image = image.convertToFormat(QImage::Format_ARGB32,Qt::AutoColor);
26  image = image.mirrored(false, true);
29  wind_emitter_save.fill(Qt::white);
30 
31  imagewidth = image.width();
32  imageheight = image.height();
33 
35 
36  ui->image_width->setText(QString::number(imagewidth));
37  ui->image_height->setText(QString::number(imageheight));
38 
39  pixmap = QPixmap::fromImage(image_stack::imagestack.at(0));
40  pixmapwidth = pixmap.width();
41  pixmapheight = pixmap.height();
42 
43  scene = new myscene();
44  scene->addPixmap(pixmap);
45  ui->reset_mask->setEnabled(true);
46  ui->graphicsView->setScene(scene);
47  ui->graphicsView->rotate(180);
48  ui->graphicsView->setDragMode(ui->graphicsView->ScrollHandDrag);
49  QApplication::setOverrideCursor(Qt::ArrowCursor);
50  ui->graphicsView->setFocus();
51 
52  no_image = false;
53 
54  //now we activate the high, width and depth fields
55  ui->image_width->setEnabled(true);
56  ui->image_height->setEnabled(true);
57  ui->image_depth->setEnabled(true);
58 }
59 
64 
65  if (no_image == false){
66 
67  file_masked_image_save = QFileDialog::getSaveFileName(this, tr("Save Masked Image"),"/home/kapf/tmp",tr("Images (*.png)"));
68 
69  QFileInfo file(file_masked_image_save);
70  if(file.suffix().isEmpty()) file_masked_image_save += ".png";
71 
73  }
74 
75 }
76 
81 {
82  if(no_image == false){
83  FILE *fd;
84  QString filename;
85  QColor tmp1;
86  int tmp;
87 
89 
90  file_save = QFileDialog::getSaveFileName(this, tr("Save File"),"/home/kapf/tmp",tr("tycho IC (*.tyc)"));
91 
92  QFileInfo file(file_save);
93  if(file.suffix().isEmpty()) file_save += ".tyc";
94 
95  if ((file_save != NULL)&&(no_image == false)){
96  filename = file_save;
97 
98  fd = fopen(filename.toUtf8(), "w");
99  fprintf(fd,"This is a TYCHO boundary condition file.\n");
100  fprintf(fd,"X %i\n", image.width());
101  fprintf(fd,"Y %i\n", image.height());
102  fprintf(fd,"Z %i\n", ui->image_depth->text().toInt());
103  fseek(fd, 200, SEEK_SET);
104  for (int j = 0; j < image.width(); j++) {
105  for (int k = 0; k < image.height(); k++) {
106 
107  tmp1 = image.pixel(j,k);
108  if (tmp1 == final_mark_color.rgba()) {
109  tmp=1;
110  for (int i = 0; i < ui->image_depth->text().toInt(); i++) if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
111  }
112  else{
113  tmp=0;
114  for (int i = 0; i < ui->image_depth->text().toInt(); i++) if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
115 
116  }
117  }
118  }
119 
120 
121  fclose(fd);
122  }
123  }
124 
125 }
126 
131 {
132  if(no_image == false){
133  FILE *fd;
134  QString filename;
135  QColor tmp1;
136  int tmp;
137 
139 
140  file_save = QFileDialog::getSaveFileName(this, tr("Save File"),"/home/kapf/tmp",tr("tycho IC (*.tyc)"));
141 
142  QFileInfo file(file_save);
143  if(file.suffix().isEmpty()) file_save += ".tyc";
144 
145  if ((file_save != NULL)&&(no_image == false)){
146  filename = file_save;
147 
148  fd = fopen(filename.toUtf8(), "w");
149  fprintf(fd,"This is a TYCHO soundemitter file.\n");
150  fprintf(fd,"X %i\n", image.width());
151  fprintf(fd,"Y %i\n", image.height());
152  fprintf(fd,"Z %i\n", ui->image_depth->text().toInt());
153  fseek(fd, 200, SEEK_SET);
154  for (int j = 0; j < image.width(); j++) {
155  for (int k = 0; k < image.height(); k++) {
156 
157  tmp1 = image.pixel(j,k);
158  if (tmp1 == final_mark_color.rgba()) {
159  tmp=1;
160  for (int i = 0; i < ui->image_depth->text().toInt(); i++) if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
161  }
162  else{
163  tmp=0;
164  for (int i = 0; i < ui->image_depth->text().toInt(); i++) if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
165 
166  }
167  }
168  }
169 
170 
171  fclose(fd);
172  }
173  }
174 
175 }
176 
181 
182  if(no_image == false){
183  FILE *fd;
184  QString filename;
185  QColor tmp1;
186  int tmp;
187 
188  file_save = QFileDialog::getSaveFileName(this, tr("Save Wind - Emitter"),"/home/kapf/tmp",tr("tycho IC (*.tyc)"));
189 
190  QFileInfo file(file_save);
191  if(file.suffix().isEmpty()) file_save += ".tyc";
192 
193  if ((file_save != NULL)&&(no_image == false)){
194  filename = file_save;
195 
196  fd = fopen(filename.toUtf8(), "w");
197  fprintf(fd,"This is a TYCHO wind-emitter file.\n");
198  fprintf(fd,"X %i\n", image.width());
199  fprintf(fd,"Y %i\n", image.height());
200  fprintf(fd,"Y %i\n", ui->image_depth->text().toInt());
201  fseek(fd, 200, SEEK_SET);
202  for (int j = 0; j < image.width(); j++) {
203  for (int k = 0; k < image.height(); k++) {
204  for (int i = 0; i < ui->image_depth->text().toInt(); i++) {
205  tmp1 = wind_emitter_save.pixel(j,k);
206  if (tmp1 == emitter_color_x.rgba()) {
207  tmp=2;
208  if (!fwrite(&tmp, 1, sizeof (int), fd)) break;
209  }
210  else if (tmp1 == emitter_color_mx.rgba()) {
211  tmp=3;
212  if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
213  }
214  else if (tmp1 == emitter_color_y.rgba()) {
215  tmp=4;
216  if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
217  }
218  else if (tmp1 == emitter_color_my.rgba()) {
219  tmp=5;
220  if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
221  }
222  else{
223  tmp=0;
224  if (!fwrite(&tmp, 1, sizeof (int), fd)) break;;
225 
226  }
227  }
228  }
229  }
230 
231  fclose(fd);
232  }
233  }
234 
235 }