added nb of colors setting
[engrid.git] / guimainwindow.cpp
blob7d7a6349cfa7cb78190a3e6e4c0d2b1c61fdaf1f
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008,2009 Oliver Gloth +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guimainwindow.h"
24 #include "guiselectboundarycodes.h"
25 #include "guiimproveaspectratio.h"
26 #include "guinormalextrusion.h"
27 #include "guisetboundarycode.h"
28 #include "guipick.h"
30 #include "vtkEgPolyDataToUnstructuredGridFilter.h"
31 #include "stlreader.h"
32 #include "gmshreader.h"
33 #include "gmshwriter.h"
34 #include "neutralwriter.h"
35 #include "stlwriter.h"
36 #include "correctsurfaceorientation.h"
37 #include "guieditboundaryconditions.h"
39 #include <vtkRenderer.h>
40 #include <vtkRenderWindow.h>
41 #include <vtkXMLUnstructuredGridWriter.h>
42 #include <vtkXMLUnstructuredGridReader.h>
43 #include <vtkProperty.h>
44 #include <vtkCallbackCommand.h>
45 #include <vtkCamera.h>
46 #include <vtkCharArray.h>
47 #include <vtkTextActor.h>
48 #include <vtkVectorText.h>
49 #include <vtkFollower.h>
50 #include <vtkLookupTable.h>
51 #include <vtkScalarBarActor.h>
53 #include <QFileDialog>
54 #include <QFileSystemWatcher>
55 #include <stdlib.h>
56 #include <stdio.h>
58 #include "geometrytools.h"
59 using namespace GeometryTools;
61 #include "guisettingsviewer.h"
62 #include "guitransform.h"
64 // GuiOutputWindow::GuiOutputWindow()
65 // {
66 // ui.setupUi(this);
67 // };
69 QString GuiMainWindow::cwd = ".";
70 QSettings GuiMainWindow::qset("enGits","enGrid");
71 GuiMainWindow* GuiMainWindow::THIS = NULL;
72 QMutex GuiMainWindow::mutex;
73 vtkIdType GuiMainWindow::PickedPoint;
74 vtkIdType GuiMainWindow::PickedCell;
75 bool GuiMainWindow::m_UseVTKInteractor;
77 GuiMainWindow::GuiMainWindow() : QMainWindow(NULL)
79 ui.setupUi(this);
80 THIS = this;
82 QPoint pos = qset.value("pos", QPoint(200, 200)).toPoint();
83 QSize size = qset.value("size", QSize(400, 400)).toSize();
84 resize(size);
85 move(pos);
87 // dock_widget = new QDockWidget(tr("output"), this);
88 // dock_widget->setFeatures(QDockWidget::AllDockWidgetFeatures);
89 // output_window = new GuiOutputWindow();
90 // dock_widget->setWidget(output_window);
91 // addDockWidget(Qt::LeftDockWidgetArea, dock_widget);
92 // ui.menuView->addAction(dock_widget->toggleViewAction());
94 connect(ui.actionImportSTL, SIGNAL(activated()), this, SLOT(importSTL()));
95 connect(ui.actionImportGmsh1Ascii, SIGNAL(activated()), this, SLOT(importGmsh1Ascii()));
96 connect(ui.actionImportGmsh2Ascii, SIGNAL(activated()), this, SLOT(importGmsh2Ascii()));
97 connect(ui.actionExportGmsh1Ascii, SIGNAL(activated()), this, SLOT(exportGmsh1Ascii()));
98 connect(ui.actionExportGmsh2Ascii, SIGNAL(activated()), this, SLOT(exportGmsh2Ascii()));
99 connect(ui.actionExportNeutral, SIGNAL(activated()), this, SLOT(exportNeutral()));
100 connect(ui.actionExportAsciiStl, SIGNAL(activated()), this, SLOT(exportAsciiStl()));
101 connect(ui.actionExportBinaryStl, SIGNAL(activated()), this, SLOT(exportBinaryStl()));
102 connect(ui.actionExit, SIGNAL(activated()), this, SLOT(exit()));
103 connect(ui.actionZoomAll, SIGNAL(activated()), this, SLOT(zoomAll()));
104 connect(ui.actionOpen, SIGNAL(activated()), this, SLOT(open()));
105 connect(ui.actionSave, SIGNAL(activated()), this, SLOT(save()));
106 connect(ui.actionSaveAs, SIGNAL(activated()), this, SLOT(saveAs()));
107 connect(ui.actionBoundaryCodes, SIGNAL(activated()), this, SLOT(selectBoundaryCodes()));
108 connect(ui.actionNormalExtrusion, SIGNAL(activated()), this, SLOT(normalExtrusion()));
109 connect(ui.actionViewAxes, SIGNAL(changed()), this, SLOT(setAxesVisibility()));
110 connect(ui.actionViewOrthogonal, SIGNAL(changed()), this, SLOT(setViewingMode()));
111 connect(ui.actionViewNodeIDs, SIGNAL(changed()), this, SLOT(ViewNodeIDs()));
112 connect(ui.actionViewCellIDs, SIGNAL(changed()), this, SLOT(ViewCellIDs()));
113 connect(ui.actionChangeOrientation, SIGNAL(activated()), this, SLOT(changeSurfaceOrientation()));
114 connect(ui.actionCheckOrientation, SIGNAL(activated()), this, SLOT(checkSurfaceOrientation()));
115 connect(ui.actionImproveAspectRatio, SIGNAL(activated()), this, SLOT(improveAspectRatio()));
116 connect(ui.actionRedraw, SIGNAL(activated()), this, SLOT(updateActors()));
117 connect(ui.actionScaleToData, SIGNAL(activated()), this, SLOT(ScaleToData()));
118 connect(ui.actionClearOutputWindow, SIGNAL(activated()), this, SLOT(clearOutput()));
119 connect(ui.actionEditBoundaryConditions, SIGNAL(activated()), this, SLOT(editBoundaryConditions()));
120 connect(ui.actionConfigure, SIGNAL(activated()), this, SLOT(configure()));
121 connect(ui.actionAbout, SIGNAL(activated()), this, SLOT(about()));
123 connect(ui.checkBox_UseVTKInteractor, SIGNAL(stateChanged(int)), this, SLOT(setUseVTKInteractor(int)));
125 connect(ui.actionViewXP, SIGNAL(activated()), this, SLOT(viewXP()));
126 connect(ui.actionViewXM, SIGNAL(activated()), this, SLOT(viewXM()));
127 connect(ui.actionViewYP, SIGNAL(activated()), this, SLOT(viewYP()));
128 connect(ui.actionViewYM, SIGNAL(activated()), this, SLOT(viewYM()));
129 connect(ui.actionViewZP, SIGNAL(activated()), this, SLOT(viewZP()));
130 connect(ui.actionViewZM, SIGNAL(activated()), this, SLOT(viewZM()));
133 #include "std_connections.h"
135 if (qset.contains("working_directory")) {
136 cwd = qset.value("working_directory").toString();
138 grid = vtkUnstructuredGrid::New();
139 renderer = vtkRenderer::New();
140 getRenderWindow()->AddRenderer(renderer);
141 surface_actor = vtkActor::New();
142 surface_wire_actor = vtkActor::New();
144 tetra_mapper = vtkPolyDataMapper::New();
145 pyramid_mapper = vtkPolyDataMapper::New();
146 wedge_mapper = vtkPolyDataMapper::New();
147 hexa_mapper = vtkPolyDataMapper::New();
148 volume_wire_mapper = vtkPolyDataMapper::New();
149 surface_mapper = vtkPolyDataMapper::New();
150 surface_wire_mapper = vtkPolyDataMapper::New();
152 backface_property = vtkProperty::New();
154 tetra_actor = NULL;
155 pyramid_actor = NULL;
156 wedge_actor = NULL;
157 hexa_actor = NULL;
158 volume_wire_actor = NULL;
159 iamlegend_actor = NULL;
160 lut = NULL;
161 field_mapper = NULL;
163 surface_filter = vtkGeometryFilter::New();
164 bcodes_filter = vtkEgBoundaryCodesFilter::New();
165 renderer->AddActor(surface_actor);
166 renderer->AddActor(surface_wire_actor);
167 pick_sphere = vtkSphereSource::New();
168 pick_mapper = vtkPolyDataMapper::New();
169 pick_actor = NULL;
171 extr_vol = vtkEgExtractVolumeCells::New();
172 extr_tetras = vtkEgExtractVolumeCells::New();
173 extr_pyramids = vtkEgExtractVolumeCells::New();
174 extr_wedges = vtkEgExtractVolumeCells::New();
175 extr_hexas = vtkEgExtractVolumeCells::New();
177 volume_geometry = vtkGeometryFilter::New();
178 tetra_geometry = vtkGeometryFilter::New();
179 pyramid_geometry = vtkGeometryFilter::New();
180 wedge_geometry = vtkGeometryFilter::New();
181 hexa_geometry = vtkGeometryFilter::New();
183 extr_tetras->SetAllOff();
184 extr_tetras->SetTetrasOn();
185 extr_pyramids->SetAllOff();
186 extr_pyramids->SetPyramidsOn();
187 extr_wedges->SetAllOff();
188 extr_wedges->SetWedgesOn();
189 extr_hexas->SetAllOff();
190 extr_hexas->SetHexasOn();
192 boundary_pd = vtkPolyData::New();
193 tetras_pd = vtkPolyData::New();
194 wedges_pd = vtkPolyData::New();
195 pyras_pd = vtkPolyData::New();
196 hexas_pd = vtkPolyData::New();
197 volume_pd = vtkPolyData::New();
199 current_filename = "untitled.vtu";
200 setWindowTitle(current_filename + " - enGrid");
202 status_bar = new QStatusBar(this);
203 setStatusBar(status_bar);
204 status_label = new QLabel(this);
205 status_bar->addWidget(status_label);
206 QString txt = "0 volume cells (0 tetras, 0 hexas, 0 pyramids, 0 prisms), ";
207 txt += "0 surface cells (0 triangles, 0 quads), 0 nodes";
208 status_label->setText(txt);
210 axes = vtkCubeAxesActor2D::New();
211 axes->SetCamera(getRenderer()->GetActiveCamera());
212 getRenderer()->AddActor(axes);
213 setAxesVisibility();
215 CellPicker = vtkCellPicker::New();
216 // getInteractor()->SetPicker(CellPicker);
217 PointPicker = vtkPointPicker::New();
218 // getInteractor()->SetPicker(PointPicker);
220 pick_sphere->SetRadius(0.25);//in case the user starts picking points instead of cells
222 vtkCallbackCommand *cbc = vtkCallbackCommand::New();
223 cbc->SetCallback(pickCellCallBack);
224 CellPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
225 cbc->SetCallback(pickPointCallBack);
226 PointPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
227 cbc->Delete();
229 QString user = QString(getenv("USER"));
230 QString basename="enGrid_output_"+user+".txt";
232 if (qset.contains("tmp_directory")) {
233 log_file_name = qset.value("tmp_directory").toString() + "/" + basename;
234 } else {
235 log_file_name = "/tmp/" + basename;
237 system_stdout = stdout;
238 freopen (log_file_name.toAscii().data(), "w", stdout);
240 busy = false;
241 updateStatusBar();
243 connect(&garbage_timer, SIGNAL(timeout()), this, SLOT(periodicUpdate()));
244 garbage_timer.start(1000);
246 connect(&log_timer, SIGNAL(timeout()), this, SLOT(updateOutput()));
247 log_timer.start(1000);
249 N_chars = 0;
251 bool exp_features;
252 getSet("","enable experimental features",false,exp_features);
253 ui.actionFoamWriter->setEnabled(exp_features);
255 ReferenceSize=0.2;
257 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
258 // ui.radioButton_CellPicker->setChecked(true);
259 setPickMode(true,true);
260 PickedPoint=-1;
261 PickedCell=-1;
263 ui.doubleSpinBox_HueMin->setValue(0.667);
264 ui.doubleSpinBox_HueMax->setValue(0);
267 GuiMainWindow::~GuiMainWindow()
269 qset.setValue("pos", pos());
270 qset.setValue("size", size());
273 void GuiMainWindow::updateOutput()
275 QFile log_file(log_file_name);
276 log_file.open(QIODevice::ReadOnly);
277 QByteArray buffer = log_file.readAll();
278 if (buffer.size() > N_chars) {
279 QByteArray newchars = buffer.right(buffer.size() - N_chars);
280 N_chars = buffer.size();
281 QString txt(newchars);
282 if (txt.right(1) == "\n") {
283 txt = txt.left(txt.size()-1);
285 ui.textEditOutput->append(txt);
289 void GuiMainWindow::exit()
291 QCoreApplication::exit();
294 vtkRenderWindow* GuiMainWindow::getRenderWindow()
296 return ui.qvtkWidget->GetRenderWindow();
299 vtkRenderer* GuiMainWindow::getRenderer()
301 return renderer;
304 QVTKInteractor* GuiMainWindow::getInteractor()
306 return ui.qvtkWidget->GetInteractor();
309 QString GuiMainWindow::getCwd()
311 return cwd;
314 void GuiMainWindow::setCwd(QString dir)
316 cwd = dir;
317 qset.setValue("working_directory",dir);
320 void GuiMainWindow::ScaleToData()
322 int current_field=ui.comboBox_Field->currentIndex();
323 if(current_field>0)
325 double range[2];
326 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
327 cout<<"current_field="<<current_field<<endl;
328 cout<<"range[0]="<<range[0]<<endl;
329 cout<<"range[1]="<<range[1]<<endl;
330 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
331 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
332 ui.doubleSpinBox_FieldMin->setValue(range[0]);
333 ui.doubleSpinBox_FieldMax->setValue(range[1]);
337 void GuiMainWindow::updateActors()
339 if (!tryLock()) return;
340 try {
343 if (!grid->GetCellData()->GetScalars("cell_index")) {
344 EG_VTKSP(vtkLongArray_t, cell_idx);
345 cell_idx->SetName("cell_index");
346 cell_idx->SetNumberOfValues(grid->GetNumberOfCells());
347 grid->GetCellData()->AddArray(cell_idx);
350 EG_VTKDCC(vtkLongArray_t, cell_index, grid, "cell_index");
351 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
352 cell_index->SetValue(cellId, cellId);
356 axes->SetInput(grid);
358 double xmin = 1e99;
359 double xmax = -1e99;
360 double ymin = 1e99;
361 double ymax = -1e99;
362 double zmin = 1e99;
363 double zmax = -1e99;
364 for (vtkIdType nodeId = 0; nodeId < grid->GetNumberOfPoints(); ++nodeId) {
365 vec3_t x;
366 grid->GetPoints()->GetPoint(nodeId, x.data());
367 xmin = min(x[0], xmin);
368 xmax = max(x[0], xmax);
369 ymin = min(x[1], ymin);
370 ymax = max(x[1], ymax);
371 zmin = min(x[2], zmin);
372 zmax = max(x[2], zmax);
375 if (surface_actor) {
376 getRenderer()->RemoveActor(surface_actor);
377 surface_actor->Delete();
378 surface_actor = NULL;
380 if (surface_wire_actor) {
381 getRenderer()->RemoveActor(surface_wire_actor);
382 surface_wire_actor->Delete();
383 surface_wire_actor = NULL;
385 if (tetra_actor) {
386 getRenderer()->RemoveActor(tetra_actor);
387 tetra_actor->Delete();
388 tetra_actor = NULL;
390 if (pyramid_actor) {
391 getRenderer()->RemoveActor(pyramid_actor);
392 pyramid_actor->Delete();
393 pyramid_actor = NULL;
395 if (wedge_actor) {
396 getRenderer()->RemoveActor(wedge_actor);
397 wedge_actor->Delete();
398 wedge_actor = NULL;
400 if (hexa_actor) {
401 getRenderer()->RemoveActor(hexa_actor);
402 hexa_actor->Delete();
403 hexa_actor = NULL;
405 if (volume_wire_actor) {
406 getRenderer()->RemoveActor(volume_wire_actor);
407 volume_wire_actor->Delete();
408 volume_wire_actor = NULL;
410 if (pick_actor) {
411 getRenderer()->RemoveActor(pick_actor);
412 pick_actor->Delete();
413 pick_actor = NULL;
415 if (iamlegend_actor) {
416 getRenderer()->RemoveActor(iamlegend_actor);
417 iamlegend_actor->Delete();
418 iamlegend_actor = NULL;
420 if (lut) {
421 lut->Delete();
422 lut = NULL;
424 if (field_mapper) {
425 field_mapper->Delete();
426 field_mapper = NULL;
429 if (ui.checkBoxSurface->isChecked()) {
430 bcodes_filter->SetBoundaryCodes(&display_boundary_codes);
432 bcodes_filter->SetInput(grid);
434 surface_filter->SetInput(bcodes_filter->GetOutput());
436 surface_filter->Update();
438 boundary_pd->DeepCopy(surface_filter->GetOutput());
440 surface_mapper->SetInput(boundary_pd);
442 surface_wire_mapper->SetInput(boundary_pd);
443 surface_actor = vtkActor::New();
444 surface_actor->GetProperty()->SetRepresentationToSurface();
446 //Fill node field combobox
447 int current_field=ui.comboBox_Field->currentIndex();
448 ui.comboBox_Field->clear();
449 ui.comboBox_Field->addItem("None");
450 int N_Arrays=boundary_pd->GetPointData()->GetNumberOfArrays();
451 // cout<<"N_Arrays="<<N_Arrays<<endl;
452 for (int i=0; i<N_Arrays; i++)
454 ui.comboBox_Field->addItem(boundary_pd->GetPointData()->GetArrayName(i));
456 if(current_field==-1) ui.comboBox_Field->setCurrentIndex(0);
457 else ui.comboBox_Field->setCurrentIndex(current_field);
459 //Fill cell field combobox
460 int current_cell_field=ui.comboBox_CellTextField->currentIndex();
461 ui.comboBox_CellTextField->clear();
462 ui.comboBox_CellTextField->addItem("Cell ID");
463 int N_CellArrays=boundary_pd->GetCellData()->GetNumberOfArrays();
464 // cout<<"N_CellArrays="<<N_CellArrays<<endl;
465 for (int i=0; i<N_CellArrays; i++)
467 ui.comboBox_CellTextField->addItem(grid->GetCellData()->GetArrayName(i));
469 if(current_cell_field==-1) ui.comboBox_CellTextField->setCurrentIndex(0);
470 else ui.comboBox_CellTextField->setCurrentIndex(current_cell_field);
472 // cout<<"index="<<ui.comboBox_Field->currentIndex()<<endl;
473 // cout<<"name="<<ui.comboBox_Field->currentText().toLatin1().data()<<endl;
475 current_field=ui.comboBox_Field->currentIndex();
476 if(current_field>0)
478 double range[2];
479 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
480 cout<<"current_field="<<current_field<<endl;
481 cout<<"range[0]="<<range[0]<<endl;
482 cout<<"range[1]="<<range[1]<<endl;
483 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
484 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
487 if(ui.comboBox_Field->currentIndex()<=0) {
488 surface_actor->SetBackfaceProperty(backface_property);
489 surface_actor->GetProperty()->SetColor(0.5,1,0.5);
490 surface_actor->GetBackfaceProperty()->SetColor(1,1,0.5);
491 surface_actor->SetMapper(surface_mapper);
493 else {
494 lut=vtkLookupTable::New();
495 lut->SetNumberOfColors(ui.spinBox_Color->value());
496 lut->SetHueRange(ui.doubleSpinBox_HueMin->value(),ui.doubleSpinBox_HueMax->value());
497 lut->Build();
498 field_mapper=vtkPolyDataMapper::New();
499 field_mapper->SetLookupTable(lut);
500 field_mapper->SetInput(boundary_pd);
501 field_mapper->SetColorModeToMapScalars();
502 field_mapper->SetScalarModeToUsePointFieldData();
503 field_mapper->ColorByArrayComponent(ui.comboBox_Field->currentText().toLatin1().data(),0);
504 field_mapper->SetScalarRange(ui.doubleSpinBox_FieldMin->value(),ui.doubleSpinBox_FieldMax->value());
505 surface_actor->SetMapper(field_mapper);
507 if(ui.checkBox_Legend->checkState()) {
508 iamlegend_actor = vtkScalarBarActor::New();
509 iamlegend_actor->SetLookupTable (lut);
510 getRenderer()->AddActor(iamlegend_actor);
514 /* vtkDoubleArray *newScalars = vtkDoubleArray::New();
515 int index;
516 newScalars=(vtkDoubleArray *)boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
517 cout<<"index="<<index<<endl;*/
519 /* cout<<"=========="<<endl;
520 boundary_pd->GetPointData()->GetArray("node_status",index);
521 cout<<"index="<<index<<endl;
522 boundary_pd->GetPointData()->GetArray("node_layer",index);
523 cout<<"index="<<index<<endl;
524 boundary_pd->GetPointData()->GetArray("node_index",index);
525 cout<<"index="<<index<<endl;
526 boundary_pd->GetPointData()->GetArray("node_meshdensity",index);
527 cout<<"index="<<index<<endl;
528 boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
529 cout<<"index="<<index<<endl;
530 boundary_pd->GetPointData()->GetArray("node_type",index);
531 cout<<"index="<<index<<endl;
532 cout<<"=========="<<endl;*/
534 /* int N2=newScalars->GetNumberOfComponents();
535 int N3=newScalars->GetNumberOfTuples();
536 cout<<"Number of components=N2="<<N2<<endl;
537 cout<<"Number of tuples=N3="<<N3<<endl;*/
540 /* for (int i=0; i<N3; i++)
542 double D=newScalars->GetComponent(i,0);//strange, but works. O.o
543 cout<<"D["<<i<<"]="<<D<<endl;
546 surface_wire_actor = vtkActor::New();
547 surface_wire_actor->GetProperty()->SetRepresentationToWireframe();
548 surface_wire_actor->GetProperty()->SetColor(0,0,1);
550 surface_wire_actor->SetMapper(surface_wire_mapper);
551 getRenderer()->AddActor(surface_actor);
552 getRenderer()->AddActor(surface_wire_actor);
553 bcodes_filter->Update();
555 if(m_UseVTKInteractor)
557 if(ui.radioButton_CellPicker->isChecked())
559 // CellPicker->Pick(0,0,0, getRenderer());
560 getInteractor()->SetPicker(CellPicker);
561 // CellPicker->Pick(0,0,0, getRenderer());
562 vtkIdType cellId = getPickedCell();
563 pickCell(cellId);
565 else
567 getInteractor()->SetPicker(PointPicker);
568 vtkIdType nodeId = getPickedPoint();
569 pickPoint(nodeId);
572 else
574 if(ui.radioButton_CellPicker->isChecked()) pickCell(PickedCell);
575 else pickPoint(PickedPoint);
577 /* getInteractor()->SetPicker(CellPicker);
578 vtkIdType cellId = getPickedCell();
579 pickCell(cellId);
580 getInteractor()->SetPicker(PointPicker);
581 vtkIdType nodeId = getPickedPoint();
582 pickPoint(nodeId);*/
586 vec3_t x, n;
587 x[0] = ui.lineEditClipX->text().toDouble();
588 x[1] = ui.lineEditClipY->text().toDouble();
589 x[2] = ui.lineEditClipZ->text().toDouble();
590 n[0] = ui.lineEditClipNX->text().toDouble();
591 n[1] = ui.lineEditClipNY->text().toDouble();
592 n[2] = ui.lineEditClipNZ->text().toDouble();
593 n.normalise();
594 x = x + ui.lineEditOffset->text().toDouble()*n;
595 extr_vol->SetAllOff();
596 if (ui.checkBoxTetra->isChecked()) {
597 extr_vol->SetTetrasOn();
598 extr_tetras->SetInput(grid);
599 if (ui.checkBoxClip->isChecked()) {
600 extr_tetras->SetClippingOn();
601 extr_tetras->SetX(x);
602 extr_tetras->SetN(n);
603 } else {
604 extr_tetras->SetClippingOff();
606 tetra_actor = vtkActor::New();
607 tetra_geometry->SetInput(extr_tetras->GetOutput());
608 tetra_geometry->Update();
609 tetras_pd->DeepCopy(tetra_geometry->GetOutput());
610 tetra_mapper->SetInput(tetras_pd);
611 tetra_actor = vtkActor::New();
612 tetra_actor->SetMapper(tetra_mapper);
613 tetra_actor->GetProperty()->SetColor(1,0,0);
614 getRenderer()->AddActor(tetra_actor);
616 if (ui.checkBoxPyramid->isChecked()) {
617 extr_vol->SetPyramidsOn();
618 extr_pyramids->SetInput(grid);
619 if (ui.checkBoxClip->isChecked()) {
620 extr_pyramids->SetClippingOn();
621 extr_pyramids->SetX(x);
622 extr_pyramids->SetN(n);
623 } else {
624 extr_pyramids->SetClippingOff();
626 pyramid_actor = vtkActor::New();
627 pyramid_geometry->SetInput(extr_pyramids->GetOutput());
628 pyramid_geometry->Update();
629 pyras_pd->DeepCopy(pyramid_geometry->GetOutput());
630 pyramid_mapper->SetInput(pyras_pd);
631 pyramid_actor = vtkActor::New();
632 pyramid_actor->SetMapper(pyramid_mapper);
633 pyramid_actor->GetProperty()->SetColor(1,1,0);
634 getRenderer()->AddActor(pyramid_actor);
636 if (ui.checkBoxWedge->isChecked()) {
637 extr_vol->SetWedgesOn();
638 extr_wedges->SetInput(grid);
639 if (ui.checkBoxClip->isChecked()) {
640 extr_wedges->SetClippingOn();
641 extr_wedges->SetX(x);
642 extr_wedges->SetN(n);
643 } else {
644 extr_wedges->SetClippingOff();
646 wedge_actor = vtkActor::New();
647 wedge_geometry->SetInput(extr_wedges->GetOutput());
648 wedge_geometry->Update();
649 wedges_pd->DeepCopy(wedge_geometry->GetOutput());
650 wedge_mapper->SetInput(wedges_pd);
651 wedge_actor = vtkActor::New();
652 wedge_actor->SetMapper(wedge_mapper);
653 wedge_actor->GetProperty()->SetColor(0,1,0);
654 getRenderer()->AddActor(wedge_actor);
656 if (ui.checkBoxHexa->isChecked()) {
657 extr_vol->SetHexasOn();
658 extr_hexas->SetInput(grid);
659 if (ui.checkBoxClip->isChecked()) {
660 extr_hexas->SetClippingOn();
661 extr_hexas->SetX(x);
662 extr_hexas->SetN(n);
663 } else {
664 extr_hexas->SetClippingOff();
666 hexa_actor = vtkActor::New();
667 hexa_geometry->SetInput(extr_hexas->GetOutput());
668 hexa_geometry->Update();
669 hexas_pd->DeepCopy(hexa_geometry->GetOutput());
670 hexa_mapper->SetInput(hexas_pd);
671 hexa_actor = vtkActor::New();
672 hexa_actor->SetMapper(hexa_mapper);
673 hexa_actor->GetProperty()->SetColor(0,0.7,1);
674 getRenderer()->AddActor(hexa_actor);
677 // wireframe
678 extr_vol->SetInput(grid);
679 if (ui.checkBoxClip->isChecked()) {
680 extr_vol->SetClippingOn();
681 extr_vol->SetX(x);
682 extr_vol->SetN(n);
683 } else {
684 extr_vol->SetClippingOff();
686 volume_wire_actor = vtkActor::New();
687 volume_geometry->SetInput(extr_vol->GetOutput());
688 volume_geometry->Update();
689 volume_pd->DeepCopy(volume_geometry->GetOutput());
690 volume_wire_mapper->SetInput(volume_pd);
691 volume_wire_actor->SetMapper(volume_wire_mapper);
692 volume_wire_actor->GetProperty()->SetRepresentationToWireframe();
693 volume_wire_actor->GetProperty()->SetColor(0,0,1);
694 getRenderer()->AddActor(volume_wire_actor);
697 updateStatusBar();
698 getRenderWindow()->Render();
699 } catch (Error err) {
700 err.display();
702 unlock();
705 void GuiMainWindow::setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode)
707 m_UseVTKInteractor=a_UseVTKInteractor;
708 if(a_UseVTKInteractor) ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
709 else ui.checkBox_UseVTKInteractor->setCheckState(Qt::Unchecked);
710 if(a_CellPickerMode) ui.radioButton_CellPicker->toggle();
711 else ui.radioButton_PointPicker->toggle();
712 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
715 void GuiMainWindow::setUseVTKInteractor(int a_UseVTKInteractor)
717 m_UseVTKInteractor=a_UseVTKInteractor;
718 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
721 bool GuiMainWindow::pickPoint(vtkIdType nodeId)
723 if (nodeId >= 0 && nodeId<grid->GetNumberOfPoints()) {
724 vec3_t x(0,0,0);
725 grid->GetPoints()->GetPoint(nodeId, x.data());
726 pick_sphere->SetCenter(x.data());
727 pick_mapper->SetInput(pick_sphere->GetOutput());
728 pick_actor = vtkActor::New();
729 pick_actor->SetMapper(pick_mapper);
730 pick_actor->GetProperty()->SetRepresentationToSurface();
731 pick_actor->GetProperty()->SetColor(0,0,1);
732 getRenderer()->AddActor(pick_actor);
733 PickedPoint=nodeId;
734 return(true);
736 else return(false);
739 bool GuiMainWindow::pickCell(vtkIdType cellId)
741 if (cellId >= 0 && cellId<grid->GetNumberOfCells()) {
742 vtkIdType *pts, Npts;
743 grid->GetCellPoints(cellId, Npts, pts);
744 vec3_t x(0,0,0);
745 for (vtkIdType i = 0; i < Npts; ++i) {
746 vec3_t xp;
747 grid->GetPoints()->GetPoint(pts[i], xp.data());
748 x += double(1)/Npts * xp;
750 pick_sphere->SetCenter(x.data());
751 double R = 1e99;
752 for (vtkIdType i = 0; i < Npts; ++i) {
753 vec3_t xp;
754 grid->GetPoints()->GetPoint(pts[i], xp.data());
755 R = min(R, 0.25*(xp-x).abs());
757 ReferenceSize=R;//Used for text annotations too!
758 pick_sphere->SetRadius(R);
759 pick_mapper->SetInput(pick_sphere->GetOutput());
760 pick_actor = vtkActor::New();
761 pick_actor->SetMapper(pick_mapper);
762 pick_actor->GetProperty()->SetRepresentationToSurface();
763 pick_actor->GetProperty()->SetColor(1,0,0);
764 getRenderer()->AddActor(pick_actor);
765 PickedCell=cellId;
766 return(true);
768 else return(false);
771 void GuiMainWindow::importSTL()
773 StlReader stl;
774 stl();
775 updateBoundaryCodes(true);
776 updateActors();
777 updateStatusBar();
778 zoomAll();
781 void GuiMainWindow::importGmsh1Ascii()
783 GmshReader gmsh;
784 gmsh.setV1Ascii();
785 gmsh();
786 updateBoundaryCodes(true);
787 updateActors();
788 updateStatusBar();
789 zoomAll();
792 void GuiMainWindow::exportGmsh1Ascii()
794 GmshWriter gmsh;
795 gmsh.setV1Ascii();
796 gmsh();
799 void GuiMainWindow::importGmsh2Ascii()
801 GmshReader gmsh;
802 gmsh.setV2Ascii();
803 gmsh();
804 updateBoundaryCodes(true);
805 updateActors();
806 updateStatusBar();
807 zoomAll();
810 void GuiMainWindow::exportGmsh2Ascii()
812 GmshWriter gmsh;
813 gmsh.setV2Ascii();
814 gmsh();
817 void GuiMainWindow::exportNeutral()
819 NeutralWriter neutral;
820 neutral();
823 void GuiMainWindow::zoomAll()
825 getRenderer()->ResetCamera();
826 getRenderWindow()->Render();
829 void GuiMainWindow::open()
831 current_filename = QFileDialog::getOpenFileName
833 NULL,
834 "open grid from file",
835 getCwd(),
836 "VTK unstructured grid files (*.vtu *.VTU)"
838 if (!current_filename.isNull()) {
839 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
840 EG_VTKSP(vtkXMLUnstructuredGridReader,vtu);
841 vtu->SetFileName(current_filename.toAscii().data());
842 vtu->Update();
843 grid->DeepCopy(vtu->GetOutput());
844 createBasicFields(grid, grid->GetNumberOfCells(), grid->GetNumberOfPoints(), false);
845 setWindowTitle(current_filename + " - enGrid");
846 openBC();
847 updateBoundaryCodes(true);
848 updateActors();
849 updateStatusBar();
850 zoomAll();
854 void GuiMainWindow::undo()
858 void GuiMainWindow::redo()
862 void GuiMainWindow::openBC()
864 QString bc_file = current_filename + ".bcs";
865 QFile file(bc_file);
866 bcmap.clear();
867 if (file.exists()) {
868 file.open(QIODevice::ReadOnly | QIODevice::Text);
869 QTextStream f(&file);
870 while (!f.atEnd()) {
871 QString name, type;
872 int i;
873 f >> i >> name >> type;
874 bcmap[i] = BoundaryCondition(name,type);
879 void GuiMainWindow::saveBC()
881 QString bc_file = current_filename + ".bcs";
882 QFile file(bc_file);
883 file.open(QIODevice::WriteOnly | QIODevice::Text);
884 QTextStream f(&file);
885 foreach(int i, all_boundary_codes) {
886 BoundaryCondition bc = bcmap[i];
887 f << i << " " << bc.getName() << " " << bc.getType() << "\n";
891 void GuiMainWindow::save()
893 cout << current_filename.toAscii().data() << endl;
894 if (current_filename == "untitled.vtu") {
895 saveAs();
896 } else {
897 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
898 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
899 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
901 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
902 addVtkTypeInfo();
903 createIndices(grid);
904 vtu->SetFileName(current_filename.toAscii().data());
905 vtu->SetDataModeToBinary();
906 vtu->SetInput(grid);
907 vtu->Write();
908 saveBC();
912 void GuiMainWindow::saveAs()
914 current_filename = QFileDialog::getSaveFileName
916 NULL,
917 "write grid to file",
918 getCwd(),
919 "VTK unstructured grid files (*.vtu *.VTU)"
921 if (!current_filename.isNull()) {
922 if (current_filename.right(4) != ".vtu") {
923 if (current_filename.right(4) != ".VTU") {
924 current_filename += ".vtu";
927 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
928 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
929 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
931 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
932 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
933 addVtkTypeInfo();
934 createIndices(grid);
935 vtu->SetFileName(current_filename.toAscii().data());
936 vtu->SetDataModeToBinary();
937 vtu->SetInput(grid);
938 vtu->Write();
939 saveBC();
940 setWindowTitle(current_filename + " - enGrid");
944 void GuiMainWindow::QuickSave(QString a_filename)
946 cout << a_filename.toAscii().data() << endl;
948 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
949 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
950 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
952 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
953 addVtkTypeInfo();
954 createIndices(grid);
955 vtu->SetFileName(a_filename.toAscii().data());
956 vtu->SetDataModeToBinary();
957 vtu->SetInput(grid);
958 vtu->Write();
959 saveBC();
963 void GuiMainWindow::updateStatusBar()
965 QString num, txt = "enGrid is currently busy with an operation ...";
966 if (!busy) {
967 txt = "";
969 if (!tryLock()) {
970 status_label->setText(txt);
971 return;
973 vtkIdType Ncells = grid->GetNumberOfCells();
974 vtkIdType Nnodes = grid->GetNumberOfPoints();
975 vtkIdType Ntris = 0;
976 vtkIdType Nquads = 0;
977 vtkIdType Ntets = 0;
978 vtkIdType Npyras = 0;
979 vtkIdType Nprism = 0;
980 vtkIdType Nhexas = 0;
981 for (vtkIdType i = 0; i < Ncells; ++i) {
982 int ct = grid->GetCellType(i);
983 if (ct == VTK_TRIANGLE) ++Ntris;
984 else if (ct == VTK_QUAD) ++Nquads;
985 else if (ct == VTK_TETRA) ++Ntets;
986 else if (ct == VTK_WEDGE) ++Nprism;
987 else if (ct == VTK_PYRAMID) ++Npyras;
988 else if (ct == VTK_HEXAHEDRON) ++Nhexas;
990 num.setNum(Ntets + Npyras + Nprism + Nhexas); txt += num + " volume cells(";
991 num.setNum(Ntets); txt += num + " tetras, ";
992 num.setNum(Npyras); txt += num + " pyramids, ";
993 num.setNum(Nprism); txt += num + " prisms, ";
994 num.setNum(Nhexas); txt += num + " hexas), ";
995 num.setNum(Ntris + Nquads); txt += num + " surface cells(";
996 num.setNum(Ntris); txt += num + " triangles, ";
997 num.setNum(Nquads); txt += num + " quads), ";
998 num.setNum(Nnodes); txt += num + " nodes";
1000 if(ui.radioButton_CellPicker->isChecked())
1002 QString pick_txt = ", picked cell: ";
1003 vtkIdType id_cell = getPickedCell();
1004 if (id_cell < 0) {
1005 pick_txt += "no cell picked";
1006 } else {
1007 vtkIdType type_cell = grid->GetCellType(id_cell);
1008 if (type_cell == VTK_TRIANGLE) pick_txt += "triangle";
1009 else if (type_cell == VTK_QUAD) pick_txt += "quad";
1010 else if (type_cell == VTK_TETRA) pick_txt += "tetrahedron";
1011 else if (type_cell == VTK_PYRAMID) pick_txt += "pyramid";
1012 else if (type_cell == VTK_WEDGE) pick_txt += "prism";
1013 else if (type_cell == VTK_HEXAHEDRON) pick_txt += "hexahedron";
1014 vtkIdType N_pts, *pts;
1015 grid->GetCellPoints(id_cell, N_pts, pts);
1016 pick_txt += " [";
1017 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
1018 QString num;
1019 num.setNum(pts[i_pts]);
1020 pick_txt += num;
1021 if (i_pts < N_pts-1) {
1022 pick_txt += ",";
1025 pick_txt += "]";
1026 QString tmp;
1027 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1028 tmp.setNum(cell_code->GetValue(id_cell));
1029 pick_txt += " cell_code=" + tmp;
1030 tmp.setNum(id_cell);
1031 pick_txt += " id_cell=" + tmp;
1033 txt += pick_txt;
1035 else
1037 QString pick_txt = ", picked node: ";
1038 vtkIdType id_node = getPickedPoint();
1039 if (id_node < 0) {
1040 pick_txt += "no node picked";
1041 } else {
1042 vec3_t x;
1043 grid->GetPoints()->GetPoint(id_node,x.data());
1044 pick_txt += " [";
1045 for (int i = 0; i < 3; i++) {
1046 QString num;
1047 num.setNum(x[i]);
1048 pick_txt += num;
1049 if (i < 2) {
1050 pick_txt += ",";
1053 pick_txt += "]";
1054 QString tmp;
1055 EG_VTKDCN(vtkDoubleArray, node_meshdensity, grid, "node_meshdensity");
1056 tmp.setNum(node_meshdensity->GetValue(id_node));
1057 pick_txt += " wanted density=" + tmp;
1058 EG_VTKDCN(vtkDoubleArray, node_meshdensity_current, grid, "node_meshdensity_current");
1059 tmp.setNum(node_meshdensity_current->GetValue(id_node));
1060 pick_txt += " current density=" + tmp;
1061 EG_VTKDCN(vtkCharArray, node_type, grid, "node_type");
1062 pick_txt += " type=" + QString(VertexType2Str( node_type->GetValue(id_node)));
1063 tmp.setNum(id_node);
1064 pick_txt += " id_node=" + tmp;
1067 txt += pick_txt;
1070 status_label->setText(txt);
1071 unlock();
1074 void GuiMainWindow::selectBoundaryCodes()
1076 GuiSelectBoundaryCodes bcodes;
1077 bcodes.setDisplayBoundaryCodes(display_boundary_codes);
1078 bcodes.setBoundaryCodes(all_boundary_codes);
1079 bcodes();
1080 bcodes.getThread().wait();
1081 bcodes.getSelectedBoundaryCodes(display_boundary_codes);
1082 updateActors();
1085 void GuiMainWindow::updateBoundaryCodes(bool all_on)
1087 try {
1088 all_boundary_codes.clear();
1089 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1090 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
1091 int ct = grid->GetCellType(i);
1092 if ((ct == VTK_TRIANGLE) || (ct == VTK_QUAD)) {
1093 all_boundary_codes.insert(cell_code->GetValue(i));
1096 if (all_on) {
1097 display_boundary_codes.clear();
1098 foreach (int bc, all_boundary_codes) {
1099 display_boundary_codes.insert(bc);
1101 } else {
1102 QSet<int> dbcs;
1103 foreach (int bc, display_boundary_codes) {
1104 if (all_boundary_codes.contains(bc)) {
1105 dbcs.insert(bc);
1108 display_boundary_codes.clear();
1109 foreach (int bc, all_boundary_codes) {
1110 if (dbcs.contains(bc)) {
1111 display_boundary_codes.insert(bc);
1115 } catch (Error err) {
1116 err.display();
1120 void GuiMainWindow::normalExtrusion()
1122 GuiNormalExtrusion extr;
1123 extr();
1124 updateBoundaryCodes(false);
1125 updateActors();
1128 void GuiMainWindow::setAxesVisibility()
1130 if (ui.actionViewAxes->isChecked()) axes->SetVisibility(1);
1131 else axes->SetVisibility(0);
1132 getRenderWindow()->Render();
1135 void GuiMainWindow::setViewingMode()
1137 if (ui.actionViewOrthogonal->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1138 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1139 getRenderWindow()->Render();
1142 void GuiMainWindow::ViewNodeIDs()
1144 int N=grid->GetNumberOfPoints();
1145 cout<<"N="<<N<<endl;
1146 if (ui.actionViewNodeIDs->isChecked()) {
1147 cout<<"Activating node ID view"<<endl;
1148 NodeText_VectorText.resize(N);
1149 NodeText_PolyDataMapper.resize(N);
1150 NodeText_Follower.resize(N);
1151 for(int i=0;i<N;i++){
1152 NodeText_VectorText[i]=vtkVectorText::New();
1153 QString tmp;
1154 tmp.setNum(i);
1155 NodeText_VectorText[i]->SetText(tmp.toLatin1().data());
1156 NodeText_PolyDataMapper[i]=vtkPolyDataMapper::New();
1157 NodeText_PolyDataMapper[i]->SetInputConnection(NodeText_VectorText[i]->GetOutputPort());
1158 NodeText_Follower[i]=vtkFollower::New();
1159 NodeText_Follower[i]->SetMapper(NodeText_PolyDataMapper[i]);
1160 NodeText_Follower[i]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1161 vec3_t M;
1162 grid->GetPoint(i,M.data());
1163 vec3_t tmp_M=M;
1164 vec3_t OffSet=ReferenceSize*tmp_M.normalise();
1165 M=M+OffSet;
1166 NodeText_Follower[i]->AddPosition(M[0],M[1],M[2]);
1167 NodeText_Follower[i]->SetCamera(getRenderer()->GetActiveCamera());
1168 NodeText_Follower[i]->GetProperty()->SetColor(0,0,1);
1169 getRenderer()->AddActor(NodeText_Follower[i]);
1172 else {
1173 cout<<"Deactivating node ID view"<<endl;
1174 for(unsigned int i=0;i<NodeText_Follower.size();i++){
1175 getRenderer()->RemoveActor(NodeText_Follower[i]);
1176 NodeText_Follower[i]->Delete();
1177 NodeText_PolyDataMapper[i]->Delete();
1178 NodeText_VectorText[i]->Delete();
1180 NodeText_Follower.clear();
1181 NodeText_PolyDataMapper.clear();
1182 NodeText_VectorText.clear();
1185 getRenderWindow()->Render();
1188 void GuiMainWindow::ViewCellIDs()
1190 vtkIdType N=grid->GetNumberOfCells();
1191 cout<<"N="<<N<<endl;
1192 if (ui.actionViewCellIDs->isChecked()) {
1193 cout<<"Activating cell ID view"<<endl;
1194 CellText_VectorText.resize(N);
1195 CellText_PolyDataMapper.resize(N);
1196 CellText_Follower.resize(N);
1197 for(vtkIdType id_cell=0;id_cell<N;id_cell++){
1198 CellText_VectorText[id_cell]=vtkVectorText::New();
1200 QString tmp;
1202 if(ui.comboBox_CellTextField->currentIndex()==0) {
1203 tmp.setNum(id_cell);
1205 else if(ui.comboBox_CellTextField->currentIndex()>0) {
1206 EG_VTKDCC(vtkIntArray, current_cell_field, grid, ui.comboBox_CellTextField->currentText().toLatin1().data());
1207 tmp.setNum(current_cell_field->GetValue(id_cell));
1209 else EG_BUG;
1211 CellText_VectorText[id_cell]->SetText(tmp.toLatin1().data());
1212 CellText_PolyDataMapper[id_cell]=vtkPolyDataMapper::New();
1213 CellText_PolyDataMapper[id_cell]->SetInputConnection(CellText_VectorText[id_cell]->GetOutputPort());
1214 CellText_Follower[id_cell]=vtkFollower::New();
1215 CellText_Follower[id_cell]->SetMapper(CellText_PolyDataMapper[id_cell]);
1216 CellText_Follower[id_cell]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1217 vtkIdType N_pts,*pts;
1218 grid->GetCellPoints(id_cell,N_pts,pts);
1219 vec3_t Center(0,0,0);
1220 for(int p=0;p<N_pts;p++)
1222 vec3_t M;
1223 grid->GetPoint(pts[p],M.data());
1224 Center+=M.data();
1226 vec3_t OffSet=ReferenceSize*triNormal(grid,pts[0],pts[1],pts[2]).normalise();
1227 Center=1.0/(double)N_pts*Center+OffSet;
1228 CellText_Follower[id_cell]->AddPosition(Center[0],Center[1],Center[2]);
1229 CellText_Follower[id_cell]->SetCamera(getRenderer()->GetActiveCamera());
1230 CellText_Follower[id_cell]->GetProperty()->SetColor(1,0,0);
1231 getRenderer()->AddActor(CellText_Follower[id_cell]);
1234 else {
1235 cout<<"Deactivating cell ID view"<<endl;
1236 for(vtkIdType id_cell=0;id_cell<CellText_Follower.size();id_cell++){
1237 getRenderer()->RemoveActor(CellText_Follower[id_cell]);
1238 CellText_Follower[id_cell]->Delete();
1239 CellText_PolyDataMapper[id_cell]->Delete();
1240 CellText_VectorText[id_cell]->Delete();
1242 CellText_Follower.clear();
1243 CellText_PolyDataMapper.clear();
1244 CellText_VectorText.clear();
1247 getRenderWindow()->Render();
1250 void GuiMainWindow::addVtkTypeInfo()
1252 EG_VTKSP(vtkIntArray, vtk_type);
1253 vtk_type->SetName("vtk_type");
1254 vtk_type->SetNumberOfValues(grid->GetNumberOfCells());
1255 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1256 vtk_type->SetValue(cellId, grid->GetCellType(cellId));
1258 grid->GetCellData()->AddArray(vtk_type);
1261 void GuiMainWindow::pickCellCallBack
1263 vtkObject *caller,
1264 unsigned long int eid,
1265 void *clientdata,
1266 void *calldata
1269 caller = caller;
1270 eid = eid;
1271 clientdata = clientdata;
1272 calldata = calldata;
1273 THIS->updateActors();
1274 THIS->updateStatusBar();
1277 void GuiMainWindow::pickPointCallBack
1279 vtkObject *caller,
1280 unsigned long int eid,
1281 void *clientdata,
1282 void *calldata
1285 caller = caller;
1286 eid = eid;
1287 clientdata = clientdata;
1288 calldata = calldata;
1289 THIS->updateActors();
1290 THIS->updateStatusBar();
1293 vtkIdType GuiMainWindow::getPickedCell()
1295 vtkIdType picked_cell = -1;
1296 if (THIS->grid->GetNumberOfCells() > 0) {
1297 THIS->bcodes_filter->Update();
1298 EG_VTKDCC(vtkLongArray_t, cell_index, THIS->bcodes_filter->GetOutput(), "cell_index");
1300 vtkIdType cellId;
1301 if(m_UseVTKInteractor) cellId = THIS->CellPicker->GetCellId();
1302 else cellId = PickedCell;
1304 if (cellId >= 0) {
1305 if (cellId < THIS->bcodes_filter->GetOutput()->GetNumberOfCells()) {
1306 picked_cell = cell_index->GetValue(cellId);
1310 return picked_cell;
1313 vtkIdType GuiMainWindow::getPickedPoint()
1315 vtkIdType picked_point = -1;
1316 if (THIS->grid->GetNumberOfCells() > 0) {
1317 THIS->bcodes_filter->Update();
1319 vtkIdType pointId;
1320 if(m_UseVTKInteractor) pointId = THIS->PointPicker->GetPointId();
1321 else pointId = PickedPoint;
1323 if (pointId >= 0) {
1324 picked_point = pointId;
1327 return picked_point;
1330 void GuiMainWindow::changeSurfaceOrientation()
1332 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1333 vtkIdType Npts, *pts;
1334 grid->GetCellPoints(cellId, Npts, pts);
1335 QVector<vtkIdType> nodes(Npts);
1336 for (vtkIdType j = 0; j < Npts; ++j) nodes[j] = pts[j];
1337 for (vtkIdType j = 0; j < Npts; ++j) pts[Npts - j - 1] = nodes[j];
1339 updateActors();
1342 void GuiMainWindow::checkSurfaceOrientation()
1344 CorrectSurfaceOrientation corr_surf;
1345 vtkIdType picked_cell = getPickedCell();
1346 if (picked_cell >= 0) {
1347 corr_surf.setStart(picked_cell);
1349 corr_surf();
1350 updateActors();
1353 void GuiMainWindow::improveAspectRatio()
1355 GuiImproveAspectRatio impr_ar;
1356 impr_ar();
1357 updateActors();
1360 void GuiMainWindow::exportAsciiStl()
1362 StlWriter stl;
1363 stl();
1366 void GuiMainWindow::exportBinaryStl()
1370 void GuiMainWindow::periodicUpdate()
1372 Operation::collectGarbage();
1373 updateStatusBar();
1376 void GuiMainWindow::viewXP()
1378 getRenderer()->ResetCamera();
1379 double x[3];
1380 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1381 x[0] += 1;
1382 getRenderer()->GetActiveCamera()->SetPosition(x);
1383 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1384 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1385 getRenderer()->ResetCamera();
1386 getRenderWindow()->Render();
1389 void GuiMainWindow::viewXM()
1391 getRenderer()->ResetCamera();
1392 double x[3];
1393 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1394 x[0] -= 1;
1395 getRenderer()->GetActiveCamera()->SetPosition(x);
1396 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1397 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1398 getRenderer()->ResetCamera();
1399 getRenderWindow()->Render();
1402 void GuiMainWindow::viewYP()
1404 getRenderer()->ResetCamera();
1405 double x[3];
1406 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1407 x[1] += 1;
1408 getRenderer()->GetActiveCamera()->SetPosition(x);
1409 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1410 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1411 getRenderer()->ResetCamera();
1412 getRenderWindow()->Render();
1415 void GuiMainWindow::viewYM()
1417 getRenderer()->ResetCamera();
1418 double x[3];
1419 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1420 x[1] -= 1;
1421 getRenderer()->GetActiveCamera()->SetPosition(x);
1422 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1423 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1424 getRenderer()->ResetCamera();
1425 getRenderWindow()->Render();
1428 void GuiMainWindow::viewZP()
1430 getRenderer()->ResetCamera();
1431 double x[3];
1432 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1433 x[2] += 1;
1434 getRenderer()->GetActiveCamera()->SetPosition(x);
1435 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1436 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1437 getRenderer()->ResetCamera();
1438 getRenderWindow()->Render();
1441 void GuiMainWindow::viewZM()
1443 getRenderer()->ResetCamera();
1444 double x[3];
1445 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1446 x[2] -= 1;
1447 getRenderer()->GetActiveCamera()->SetPosition(x);
1448 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1449 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1450 getRenderer()->ResetCamera();
1451 getRenderWindow()->Render();
1454 void GuiMainWindow::callFixSTL()
1456 FixSTL *fix;
1457 fix = new FixSTL();
1458 fix->setGui();
1459 (*fix)();
1460 updateBoundaryCodes(false);
1461 updateActors();
1464 void GuiMainWindow::editBoundaryConditions()
1466 GuiEditBoundaryConditions editbcs;
1467 editbcs.setBoundaryCodes(all_boundary_codes);
1468 editbcs.setMap(&bcmap);
1469 editbcs();
1472 void GuiMainWindow::configure()
1475 // Just to create initial entries in the settings file
1476 // so that the options menu isn't empty at first start.
1477 GridSmoother tmp01;
1478 GuiCreateBoundaryLayer tmp02;
1480 GuiSettingsViewer settings(&qset);
1481 settings.exec();
1484 void GuiMainWindow::about()
1486 QMessageBox box(this);
1488 QString title="ENGRID";
1489 QString version = QString("version ") + ENGRID_VERSION;
1490 if (version == "version CVS") {
1491 version += " build on ";
1492 version += QString(__DATE__);
1493 version += " at ";
1494 version += QString(__TIME__);
1496 QString address = tr("ENGRID is being developed and maintained by:<br/>"
1497 "enGits GmbH<br/>"
1498 "Marie-Curie-Strasse 8<br/>"
1499 "79539 Loerrach<br/>"
1500 "Germany<br/>");
1502 QString mainurl="<a href=\"http://www.engits.com\">www.engits.com</a>";
1503 QString mail="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1504 QString gnuurl="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1505 QString license=tr("ENGRID is licenced under the GPL version 3.<br/>"
1506 "(see ")+gnuurl+tr(" for details)<br/>");
1507 QString bugurl="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1508 QString bugreporting=tr("To submit a bug report, please use ")+bugurl;
1509 box.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1510 "<h3>%1</h3>"
1511 "<p>%2</p>"
1512 "<p>%3</p>"
1513 "<p>Homepage: %4</p>"
1514 "<p>E-mail: %5</p>"
1515 "<p>%6</p>"
1516 "<p>%7</p></center>")
1517 .arg(title).arg(version).arg(address).arg(mainurl).arg(mail).arg(license).arg(bugreporting));
1518 box.setWindowTitle(tr("about ENGRID"));
1519 box.setIcon(QMessageBox::NoIcon);
1520 box.exec();
1524 void GuiMainWindow::getAllBoundaryCodes(QSet<int> &bcs)
1526 bcs.clear();
1527 foreach (int bc, all_boundary_codes) {
1528 bcs.insert(bc);