some gui changes
[engrid.git] / guimainwindow.cpp
blobfaa43cc744ff57ae896174b7d2694c17e4247ff5
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()
66 ui.setupUi(this);
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;
81 dock_widget = new QDockWidget(tr("output"), this);
82 dock_widget->setFeatures(QDockWidget::AllDockWidgetFeatures);
83 output_window = new GuiOutputWindow();
84 dock_widget->setWidget(output_window);
85 addDockWidget(Qt::LeftDockWidgetArea, dock_widget);
86 ui.menuView->addAction(dock_widget->toggleViewAction());
88 connect(ui.actionImportSTL, SIGNAL(activated()), this, SLOT(importSTL()));
89 connect(ui.actionImportGmsh1Ascii, SIGNAL(activated()), this, SLOT(importGmsh1Ascii()));
90 connect(ui.actionImportGmsh2Ascii, SIGNAL(activated()), this, SLOT(importGmsh2Ascii()));
91 connect(ui.actionExportGmsh1Ascii, SIGNAL(activated()), this, SLOT(exportGmsh1Ascii()));
92 connect(ui.actionExportGmsh2Ascii, SIGNAL(activated()), this, SLOT(exportGmsh2Ascii()));
93 connect(ui.actionExportNeutral, SIGNAL(activated()), this, SLOT(exportNeutral()));
94 connect(ui.actionExportAsciiStl, SIGNAL(activated()), this, SLOT(exportAsciiStl()));
95 connect(ui.actionExportBinaryStl, SIGNAL(activated()), this, SLOT(exportBinaryStl()));
96 connect(ui.actionExit, SIGNAL(activated()), this, SLOT(exit()));
97 connect(ui.actionZoomAll, SIGNAL(activated()), this, SLOT(zoomAll()));
98 connect(ui.actionOpen, SIGNAL(activated()), this, SLOT(open()));
99 connect(ui.actionSave, SIGNAL(activated()), this, SLOT(save()));
100 connect(ui.actionSaveAs, SIGNAL(activated()), this, SLOT(saveAs()));
101 connect(ui.actionBoundaryCodes, SIGNAL(activated()), this, SLOT(selectBoundaryCodes()));
102 connect(ui.actionNormalExtrusion, SIGNAL(activated()), this, SLOT(normalExtrusion()));
103 connect(ui.actionViewAxes, SIGNAL(changed()), this, SLOT(setAxesVisibility()));
104 connect(ui.actionViewOrthogonal, SIGNAL(changed()), this, SLOT(setViewingMode()));
105 connect(ui.actionViewNodeIDs, SIGNAL(changed()), this, SLOT(ViewNodeIDs()));
106 connect(ui.actionViewCellIDs, SIGNAL(changed()), this, SLOT(ViewCellIDs()));
107 connect(ui.actionChangeOrientation, SIGNAL(activated()), this, SLOT(changeSurfaceOrientation()));
108 connect(ui.actionCheckOrientation, SIGNAL(activated()), this, SLOT(checkSurfaceOrientation()));
109 connect(ui.actionImproveAspectRatio, SIGNAL(activated()), this, SLOT(improveAspectRatio()));
110 connect(ui.actionRedraw, SIGNAL(activated()), this, SLOT(updateActors()));
111 connect(ui.actionScaleToData, SIGNAL(activated()), this, SLOT(ScaleToData()));
112 connect(ui.actionClearOutputWindow, SIGNAL(activated()), this, SLOT(clearOutput()));
113 connect(ui.actionEditBoundaryConditions, SIGNAL(activated()), this, SLOT(editBoundaryConditions()));
114 connect(ui.actionConfigure, SIGNAL(activated()), this, SLOT(configure()));
115 connect(ui.actionAbout, SIGNAL(activated()), this, SLOT(about()));
117 connect(ui.checkBox_UseVTKInteractor, SIGNAL(stateChanged(int)), this, SLOT(setUseVTKInteractor(int)));
119 connect(ui.actionViewXP, SIGNAL(activated()), this, SLOT(viewXP()));
120 connect(ui.actionViewXM, SIGNAL(activated()), this, SLOT(viewXM()));
121 connect(ui.actionViewYP, SIGNAL(activated()), this, SLOT(viewYP()));
122 connect(ui.actionViewYM, SIGNAL(activated()), this, SLOT(viewYM()));
123 connect(ui.actionViewZP, SIGNAL(activated()), this, SLOT(viewZP()));
124 connect(ui.actionViewZM, SIGNAL(activated()), this, SLOT(viewZM()));
127 #include "std_connections.h"
129 if (qset.contains("working_directory")) {
130 cwd = qset.value("working_directory").toString();
132 grid = vtkUnstructuredGrid::New();
133 renderer = vtkRenderer::New();
134 getRenderWindow()->AddRenderer(renderer);
135 surface_actor = vtkActor::New();
136 surface_wire_actor = vtkActor::New();
138 tetra_mapper = vtkPolyDataMapper::New();
139 pyramid_mapper = vtkPolyDataMapper::New();
140 wedge_mapper = vtkPolyDataMapper::New();
141 hexa_mapper = vtkPolyDataMapper::New();
142 volume_wire_mapper = vtkPolyDataMapper::New();
143 surface_mapper = vtkPolyDataMapper::New();
144 surface_wire_mapper = vtkPolyDataMapper::New();
146 backface_property = vtkProperty::New();
148 tetra_actor = NULL;
149 pyramid_actor = NULL;
150 wedge_actor = NULL;
151 hexa_actor = NULL;
152 volume_wire_actor = NULL;
153 iamlegend_actor = NULL;
154 lut = NULL;
155 field_mapper = NULL;
157 surface_filter = vtkGeometryFilter::New();
158 bcodes_filter = vtkEgBoundaryCodesFilter::New();
159 renderer->AddActor(surface_actor);
160 renderer->AddActor(surface_wire_actor);
161 pick_sphere = vtkSphereSource::New();
162 pick_mapper = vtkPolyDataMapper::New();
163 pick_actor = NULL;
165 extr_vol = vtkEgExtractVolumeCells::New();
166 extr_tetras = vtkEgExtractVolumeCells::New();
167 extr_pyramids = vtkEgExtractVolumeCells::New();
168 extr_wedges = vtkEgExtractVolumeCells::New();
169 extr_hexas = vtkEgExtractVolumeCells::New();
171 volume_geometry = vtkGeometryFilter::New();
172 tetra_geometry = vtkGeometryFilter::New();
173 pyramid_geometry = vtkGeometryFilter::New();
174 wedge_geometry = vtkGeometryFilter::New();
175 hexa_geometry = vtkGeometryFilter::New();
177 extr_tetras->SetAllOff();
178 extr_tetras->SetTetrasOn();
179 extr_pyramids->SetAllOff();
180 extr_pyramids->SetPyramidsOn();
181 extr_wedges->SetAllOff();
182 extr_wedges->SetWedgesOn();
183 extr_hexas->SetAllOff();
184 extr_hexas->SetHexasOn();
186 boundary_pd = vtkPolyData::New();
187 tetras_pd = vtkPolyData::New();
188 wedges_pd = vtkPolyData::New();
189 pyras_pd = vtkPolyData::New();
190 hexas_pd = vtkPolyData::New();
191 volume_pd = vtkPolyData::New();
193 current_filename = "untitled.vtu";
194 setWindowTitle(current_filename + " - enGrid");
196 status_bar = new QStatusBar(this);
197 setStatusBar(status_bar);
198 status_label = new QLabel(this);
199 status_bar->addWidget(status_label);
200 QString txt = "0 volume cells (0 tetras, 0 hexas, 0 pyramids, 0 prisms), ";
201 txt += "0 surface cells (0 triangles, 0 quads), 0 nodes";
202 status_label->setText(txt);
204 axes = vtkCubeAxesActor2D::New();
205 axes->SetCamera(getRenderer()->GetActiveCamera());
206 getRenderer()->AddActor(axes);
207 setAxesVisibility();
209 CellPicker = vtkCellPicker::New();
210 // getInteractor()->SetPicker(CellPicker);
211 PointPicker = vtkPointPicker::New();
212 // getInteractor()->SetPicker(PointPicker);
214 pick_sphere->SetRadius(0.25);//in case the user starts picking points instead of cells
216 vtkCallbackCommand *cbc = vtkCallbackCommand::New();
217 cbc->SetCallback(pickCellCallBack);
218 CellPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
219 cbc->SetCallback(pickPointCallBack);
220 PointPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
221 cbc->Delete();
223 QString user = QString(getenv("USER"));
224 QString basename="enGrid_output_"+user+".txt";
226 if (qset.contains("tmp_directory")) {
227 log_file_name = qset.value("tmp_directory").toString() + "/" + basename;
228 } else {
229 log_file_name = "/tmp/" + basename;
231 system_stdout = stdout;
232 freopen (log_file_name.toAscii().data(), "w", stdout);
234 busy = false;
235 updateStatusBar();
237 connect(&garbage_timer, SIGNAL(timeout()), this, SLOT(periodicUpdate()));
238 garbage_timer.start(1000);
240 connect(&log_timer, SIGNAL(timeout()), this, SLOT(updateOutput()));
241 log_timer.start(1000);
243 N_chars = 0;
245 bool exp_features;
246 getSet("","enable experimental features",false,exp_features);
247 ui.actionFoamWriter->setEnabled(exp_features);
249 ReferenceSize=0.2;
251 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
252 // ui.radioButton_CellPicker->setChecked(true);
253 setPickMode(true,true);
254 PickedPoint=-1;
255 PickedCell=-1;
257 ui.doubleSpinBox_HueMin->setValue(0.667);
258 ui.doubleSpinBox_HueMax->setValue(0);
261 GuiMainWindow::~GuiMainWindow()
265 void GuiMainWindow::updateOutput()
267 QFile log_file(log_file_name);
268 log_file.open(QIODevice::ReadOnly);
269 QByteArray buffer = log_file.readAll();
270 if (buffer.size() > N_chars) {
271 QByteArray newchars = buffer.right(buffer.size() - N_chars);
272 N_chars = buffer.size();
273 QString txt(newchars);
274 if (txt.right(1) == "\n") {
275 txt = txt.left(txt.size()-1);
277 output_window->ui.textEditOutput->append(txt);
281 void GuiMainWindow::exit()
283 QCoreApplication::exit();
286 vtkRenderWindow* GuiMainWindow::getRenderWindow()
288 return ui.qvtkWidget->GetRenderWindow();
291 vtkRenderer* GuiMainWindow::getRenderer()
293 return renderer;
296 QVTKInteractor* GuiMainWindow::getInteractor()
298 return ui.qvtkWidget->GetInteractor();
301 QString GuiMainWindow::getCwd()
303 return cwd;
306 void GuiMainWindow::setCwd(QString dir)
308 cwd = dir;
309 qset.setValue("working_directory",dir);
312 void GuiMainWindow::ScaleToData()
314 int current_field=ui.comboBox_Field->currentIndex();
315 if(current_field>0)
317 double range[2];
318 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
319 cout<<"current_field="<<current_field<<endl;
320 cout<<"range[0]="<<range[0]<<endl;
321 cout<<"range[1]="<<range[1]<<endl;
322 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
323 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
324 ui.doubleSpinBox_FieldMin->setValue(range[0]);
325 ui.doubleSpinBox_FieldMax->setValue(range[1]);
329 void GuiMainWindow::updateActors()
331 if (!tryLock()) return;
332 try {
335 if (!grid->GetCellData()->GetScalars("cell_index")) {
336 EG_VTKSP(vtkLongArray_t, cell_idx);
337 cell_idx->SetName("cell_index");
338 cell_idx->SetNumberOfValues(grid->GetNumberOfCells());
339 grid->GetCellData()->AddArray(cell_idx);
342 EG_VTKDCC(vtkLongArray_t, cell_index, grid, "cell_index");
343 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
344 cell_index->SetValue(cellId, cellId);
348 axes->SetInput(grid);
350 double xmin = 1e99;
351 double xmax = -1e99;
352 double ymin = 1e99;
353 double ymax = -1e99;
354 double zmin = 1e99;
355 double zmax = -1e99;
356 for (vtkIdType nodeId = 0; nodeId < grid->GetNumberOfPoints(); ++nodeId) {
357 vec3_t x;
358 grid->GetPoints()->GetPoint(nodeId, x.data());
359 xmin = min(x[0], xmin);
360 xmax = max(x[0], xmax);
361 ymin = min(x[1], ymin);
362 ymax = max(x[1], ymax);
363 zmin = min(x[2], zmin);
364 zmax = max(x[2], zmax);
367 if (surface_actor) {
368 getRenderer()->RemoveActor(surface_actor);
369 surface_actor->Delete();
370 surface_actor = NULL;
372 if (surface_wire_actor) {
373 getRenderer()->RemoveActor(surface_wire_actor);
374 surface_wire_actor->Delete();
375 surface_wire_actor = NULL;
377 if (tetra_actor) {
378 getRenderer()->RemoveActor(tetra_actor);
379 tetra_actor->Delete();
380 tetra_actor = NULL;
382 if (pyramid_actor) {
383 getRenderer()->RemoveActor(pyramid_actor);
384 pyramid_actor->Delete();
385 pyramid_actor = NULL;
387 if (wedge_actor) {
388 getRenderer()->RemoveActor(wedge_actor);
389 wedge_actor->Delete();
390 wedge_actor = NULL;
392 if (hexa_actor) {
393 getRenderer()->RemoveActor(hexa_actor);
394 hexa_actor->Delete();
395 hexa_actor = NULL;
397 if (volume_wire_actor) {
398 getRenderer()->RemoveActor(volume_wire_actor);
399 volume_wire_actor->Delete();
400 volume_wire_actor = NULL;
402 if (pick_actor) {
403 getRenderer()->RemoveActor(pick_actor);
404 pick_actor->Delete();
405 pick_actor = NULL;
407 if (iamlegend_actor) {
408 getRenderer()->RemoveActor(iamlegend_actor);
409 iamlegend_actor->Delete();
410 iamlegend_actor = NULL;
412 if (lut) {
413 lut->Delete();
414 lut = NULL;
416 if (field_mapper) {
417 field_mapper->Delete();
418 field_mapper = NULL;
421 if (ui.checkBoxSurface->isChecked()) {
422 bcodes_filter->SetBoundaryCodes(&display_boundary_codes);
424 bcodes_filter->SetInput(grid);
426 surface_filter->SetInput(bcodes_filter->GetOutput());
428 surface_filter->Update();
430 boundary_pd->DeepCopy(surface_filter->GetOutput());
432 surface_mapper->SetInput(boundary_pd);
434 surface_wire_mapper->SetInput(boundary_pd);
435 surface_actor = vtkActor::New();
436 surface_actor->GetProperty()->SetRepresentationToSurface();
438 int current_field=ui.comboBox_Field->currentIndex();
439 ui.comboBox_Field->clear();
440 ui.comboBox_Field->addItem("None");
441 int N_Arrays=boundary_pd->GetPointData()->GetNumberOfArrays();
442 cout<<"N_Arrays="<<N_Arrays<<endl;
443 for (int i=0; i<N_Arrays; i++)
445 ui.comboBox_Field->addItem(boundary_pd->GetPointData()->GetArrayName(i));
448 if(current_field==-1) ui.comboBox_Field->setCurrentIndex(0);
449 else ui.comboBox_Field->setCurrentIndex(current_field);
451 cout<<"index="<<ui.comboBox_Field->currentIndex()<<endl;
452 cout<<"name="<<ui.comboBox_Field->currentText().toLatin1().data()<<endl;
454 current_field=ui.comboBox_Field->currentIndex();
455 if(current_field>0)
457 double range[2];
458 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
459 cout<<"current_field="<<current_field<<endl;
460 cout<<"range[0]="<<range[0]<<endl;
461 cout<<"range[1]="<<range[1]<<endl;
462 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
463 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
466 if(ui.comboBox_Field->currentIndex()<=0) {
467 surface_actor->SetBackfaceProperty(backface_property);
468 surface_actor->GetProperty()->SetColor(0.5,1,0.5);
469 surface_actor->GetBackfaceProperty()->SetColor(1,1,0.5);
470 surface_actor->SetMapper(surface_mapper);
472 else {
473 lut=vtkLookupTable::New();
474 lut->SetNumberOfColors(256);
475 lut->SetHueRange(ui.doubleSpinBox_HueMin->value(),ui.doubleSpinBox_HueMax->value());
476 lut->Build();
477 field_mapper=vtkPolyDataMapper::New();
478 field_mapper->SetLookupTable(lut);
479 field_mapper->SetInput(boundary_pd);
480 field_mapper->SetColorModeToMapScalars();
481 field_mapper->SetScalarModeToUsePointFieldData();
482 field_mapper->ColorByArrayComponent(ui.comboBox_Field->currentText().toLatin1().data(),0);
483 field_mapper->SetScalarRange(ui.doubleSpinBox_FieldMin->value(),ui.doubleSpinBox_FieldMax->value());
484 surface_actor->SetMapper(field_mapper);
486 if(ui.checkBox_Legend->checkState()) {
487 iamlegend_actor = vtkScalarBarActor::New();
488 iamlegend_actor->SetLookupTable (lut);
489 getRenderer()->AddActor(iamlegend_actor);
493 vtkDoubleArray *newScalars = vtkDoubleArray::New();
494 int index;
495 newScalars=(vtkDoubleArray *)boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
496 cout<<"index="<<index<<endl;
498 cout<<"=========="<<endl;
499 boundary_pd->GetPointData()->GetArray("node_status",index);
500 cout<<"index="<<index<<endl;
501 boundary_pd->GetPointData()->GetArray("node_layer",index);
502 cout<<"index="<<index<<endl;
503 boundary_pd->GetPointData()->GetArray("node_index",index);
504 cout<<"index="<<index<<endl;
505 boundary_pd->GetPointData()->GetArray("node_meshdensity",index);
506 cout<<"index="<<index<<endl;
507 boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
508 cout<<"index="<<index<<endl;
509 boundary_pd->GetPointData()->GetArray("node_type",index);
510 cout<<"index="<<index<<endl;
511 cout<<"=========="<<endl;
513 int N2=newScalars->GetNumberOfComponents();
514 int N3=newScalars->GetNumberOfTuples();
515 cout<<"Number of components=N2="<<N2<<endl;
516 cout<<"Number of tuples=N3="<<N3<<endl;
519 /* for (int i=0; i<N3; i++)
521 double D=newScalars->GetComponent(i,0);//strange, but works. O.o
522 cout<<"D["<<i<<"]="<<D<<endl;
525 surface_wire_actor = vtkActor::New();
526 surface_wire_actor->GetProperty()->SetRepresentationToWireframe();
527 surface_wire_actor->GetProperty()->SetColor(0,0,1);
529 surface_wire_actor->SetMapper(surface_wire_mapper);
530 getRenderer()->AddActor(surface_actor);
531 getRenderer()->AddActor(surface_wire_actor);
532 bcodes_filter->Update();
534 if(m_UseVTKInteractor)
536 if(ui.radioButton_CellPicker->isChecked())
538 // CellPicker->Pick(0,0,0, getRenderer());
539 getInteractor()->SetPicker(CellPicker);
540 // CellPicker->Pick(0,0,0, getRenderer());
541 vtkIdType cellId = getPickedCell();
542 pickCell(cellId);
544 else
546 getInteractor()->SetPicker(PointPicker);
547 vtkIdType nodeId = getPickedPoint();
548 pickPoint(nodeId);
551 else
553 if(ui.radioButton_CellPicker->isChecked()) pickCell(PickedCell);
554 else pickPoint(PickedPoint);
556 /* getInteractor()->SetPicker(CellPicker);
557 vtkIdType cellId = getPickedCell();
558 pickCell(cellId);
559 getInteractor()->SetPicker(PointPicker);
560 vtkIdType nodeId = getPickedPoint();
561 pickPoint(nodeId);*/
565 vec3_t x, n;
566 x[0] = ui.lineEditClipX->text().toDouble();
567 x[1] = ui.lineEditClipY->text().toDouble();
568 x[2] = ui.lineEditClipZ->text().toDouble();
569 n[0] = ui.lineEditClipNX->text().toDouble();
570 n[1] = ui.lineEditClipNY->text().toDouble();
571 n[2] = ui.lineEditClipNZ->text().toDouble();
572 n.normalise();
573 x = x + ui.lineEditOffset->text().toDouble()*n;
574 extr_vol->SetAllOff();
575 if (ui.checkBoxTetra->isChecked()) {
576 extr_vol->SetTetrasOn();
577 extr_tetras->SetInput(grid);
578 if (ui.checkBoxClip->isChecked()) {
579 extr_tetras->SetClippingOn();
580 extr_tetras->SetX(x);
581 extr_tetras->SetN(n);
582 } else {
583 extr_tetras->SetClippingOff();
585 tetra_actor = vtkActor::New();
586 tetra_geometry->SetInput(extr_tetras->GetOutput());
587 tetra_geometry->Update();
588 tetras_pd->DeepCopy(tetra_geometry->GetOutput());
589 tetra_mapper->SetInput(tetras_pd);
590 tetra_actor = vtkActor::New();
591 tetra_actor->SetMapper(tetra_mapper);
592 tetra_actor->GetProperty()->SetColor(1,0,0);
593 getRenderer()->AddActor(tetra_actor);
595 if (ui.checkBoxPyramid->isChecked()) {
596 extr_vol->SetPyramidsOn();
597 extr_pyramids->SetInput(grid);
598 if (ui.checkBoxClip->isChecked()) {
599 extr_pyramids->SetClippingOn();
600 extr_pyramids->SetX(x);
601 extr_pyramids->SetN(n);
602 } else {
603 extr_pyramids->SetClippingOff();
605 pyramid_actor = vtkActor::New();
606 pyramid_geometry->SetInput(extr_pyramids->GetOutput());
607 pyramid_geometry->Update();
608 pyras_pd->DeepCopy(pyramid_geometry->GetOutput());
609 pyramid_mapper->SetInput(pyras_pd);
610 pyramid_actor = vtkActor::New();
611 pyramid_actor->SetMapper(pyramid_mapper);
612 pyramid_actor->GetProperty()->SetColor(1,1,0);
613 getRenderer()->AddActor(pyramid_actor);
615 if (ui.checkBoxWedge->isChecked()) {
616 extr_vol->SetWedgesOn();
617 extr_wedges->SetInput(grid);
618 if (ui.checkBoxClip->isChecked()) {
619 extr_wedges->SetClippingOn();
620 extr_wedges->SetX(x);
621 extr_wedges->SetN(n);
622 } else {
623 extr_wedges->SetClippingOff();
625 wedge_actor = vtkActor::New();
626 wedge_geometry->SetInput(extr_wedges->GetOutput());
627 wedge_geometry->Update();
628 wedges_pd->DeepCopy(wedge_geometry->GetOutput());
629 wedge_mapper->SetInput(wedges_pd);
630 wedge_actor = vtkActor::New();
631 wedge_actor->SetMapper(wedge_mapper);
632 wedge_actor->GetProperty()->SetColor(0,1,0);
633 getRenderer()->AddActor(wedge_actor);
635 if (ui.checkBoxHexa->isChecked()) {
636 extr_vol->SetHexasOn();
637 extr_hexas->SetInput(grid);
638 if (ui.checkBoxClip->isChecked()) {
639 extr_hexas->SetClippingOn();
640 extr_hexas->SetX(x);
641 extr_hexas->SetN(n);
642 } else {
643 extr_hexas->SetClippingOff();
645 hexa_actor = vtkActor::New();
646 hexa_geometry->SetInput(extr_hexas->GetOutput());
647 hexa_geometry->Update();
648 hexas_pd->DeepCopy(hexa_geometry->GetOutput());
649 hexa_mapper->SetInput(hexas_pd);
650 hexa_actor = vtkActor::New();
651 hexa_actor->SetMapper(hexa_mapper);
652 hexa_actor->GetProperty()->SetColor(0,0.7,1);
653 getRenderer()->AddActor(hexa_actor);
656 // wireframe
657 extr_vol->SetInput(grid);
658 if (ui.checkBoxClip->isChecked()) {
659 extr_vol->SetClippingOn();
660 extr_vol->SetX(x);
661 extr_vol->SetN(n);
662 } else {
663 extr_vol->SetClippingOff();
665 volume_wire_actor = vtkActor::New();
666 volume_geometry->SetInput(extr_vol->GetOutput());
667 volume_geometry->Update();
668 volume_pd->DeepCopy(volume_geometry->GetOutput());
669 volume_wire_mapper->SetInput(volume_pd);
670 volume_wire_actor->SetMapper(volume_wire_mapper);
671 volume_wire_actor->GetProperty()->SetRepresentationToWireframe();
672 volume_wire_actor->GetProperty()->SetColor(0,0,1);
673 getRenderer()->AddActor(volume_wire_actor);
676 updateStatusBar();
677 getRenderWindow()->Render();
678 } catch (Error err) {
679 err.display();
681 unlock();
684 void GuiMainWindow::setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode)
686 m_UseVTKInteractor=a_UseVTKInteractor;
687 if(a_UseVTKInteractor) ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
688 else ui.checkBox_UseVTKInteractor->setCheckState(Qt::Unchecked);
689 if(a_CellPickerMode) ui.radioButton_CellPicker->toggle();
690 else ui.radioButton_PointPicker->toggle();
691 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
694 void GuiMainWindow::setUseVTKInteractor(int a_UseVTKInteractor)
696 m_UseVTKInteractor=a_UseVTKInteractor;
697 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
700 bool GuiMainWindow::pickPoint(vtkIdType nodeId)
702 if (nodeId >= 0 && nodeId<grid->GetNumberOfPoints()) {
703 vec3_t x(0,0,0);
704 grid->GetPoints()->GetPoint(nodeId, x.data());
705 pick_sphere->SetCenter(x.data());
706 pick_mapper->SetInput(pick_sphere->GetOutput());
707 pick_actor = vtkActor::New();
708 pick_actor->SetMapper(pick_mapper);
709 pick_actor->GetProperty()->SetRepresentationToSurface();
710 pick_actor->GetProperty()->SetColor(0,0,1);
711 getRenderer()->AddActor(pick_actor);
712 PickedPoint=nodeId;
713 return(true);
715 else return(false);
718 bool GuiMainWindow::pickCell(vtkIdType cellId)
720 if (cellId >= 0 && cellId<grid->GetNumberOfCells()) {
721 vtkIdType *pts, Npts;
722 grid->GetCellPoints(cellId, Npts, pts);
723 vec3_t x(0,0,0);
724 for (vtkIdType i = 0; i < Npts; ++i) {
725 vec3_t xp;
726 grid->GetPoints()->GetPoint(pts[i], xp.data());
727 x += double(1)/Npts * xp;
729 pick_sphere->SetCenter(x.data());
730 double R = 1e99;
731 for (vtkIdType i = 0; i < Npts; ++i) {
732 vec3_t xp;
733 grid->GetPoints()->GetPoint(pts[i], xp.data());
734 R = min(R, 0.25*(xp-x).abs());
736 ReferenceSize=R;//Used for text annotations too!
737 pick_sphere->SetRadius(R);
738 pick_mapper->SetInput(pick_sphere->GetOutput());
739 pick_actor = vtkActor::New();
740 pick_actor->SetMapper(pick_mapper);
741 pick_actor->GetProperty()->SetRepresentationToSurface();
742 pick_actor->GetProperty()->SetColor(1,0,0);
743 getRenderer()->AddActor(pick_actor);
744 PickedCell=cellId;
745 return(true);
747 else return(false);
750 void GuiMainWindow::importSTL()
752 StlReader stl;
753 stl();
754 updateBoundaryCodes(true);
755 updateActors();
756 updateStatusBar();
757 zoomAll();
760 void GuiMainWindow::importGmsh1Ascii()
762 GmshReader gmsh;
763 gmsh.setV1Ascii();
764 gmsh();
765 updateBoundaryCodes(true);
766 updateActors();
767 updateStatusBar();
768 zoomAll();
771 void GuiMainWindow::exportGmsh1Ascii()
773 GmshWriter gmsh;
774 gmsh.setV1Ascii();
775 gmsh();
778 void GuiMainWindow::importGmsh2Ascii()
780 GmshReader gmsh;
781 gmsh.setV2Ascii();
782 gmsh();
783 updateBoundaryCodes(true);
784 updateActors();
785 updateStatusBar();
786 zoomAll();
789 void GuiMainWindow::exportGmsh2Ascii()
791 GmshWriter gmsh;
792 gmsh.setV2Ascii();
793 gmsh();
796 void GuiMainWindow::exportNeutral()
798 NeutralWriter neutral;
799 neutral();
802 void GuiMainWindow::zoomAll()
804 getRenderer()->ResetCamera();
805 getRenderWindow()->Render();
808 void GuiMainWindow::open()
810 current_filename = QFileDialog::getOpenFileName
812 NULL,
813 "open grid from file",
814 getCwd(),
815 "VTK unstructured grid files (*.vtu *.VTU)"
817 if (!current_filename.isNull()) {
818 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
819 EG_VTKSP(vtkXMLUnstructuredGridReader,vtu);
820 vtu->SetFileName(current_filename.toAscii().data());
821 vtu->Update();
822 grid->DeepCopy(vtu->GetOutput());
823 createBasicFields(grid, grid->GetNumberOfCells(), grid->GetNumberOfPoints(), false);
824 setWindowTitle(current_filename + " - enGrid");
825 openBC();
826 updateBoundaryCodes(true);
827 updateActors();
828 updateStatusBar();
829 zoomAll();
833 void GuiMainWindow::undo()
837 void GuiMainWindow::redo()
841 void GuiMainWindow::openBC()
843 QString bc_file = current_filename + ".bcs";
844 QFile file(bc_file);
845 bcmap.clear();
846 if (file.exists()) {
847 file.open(QIODevice::ReadOnly | QIODevice::Text);
848 QTextStream f(&file);
849 while (!f.atEnd()) {
850 QString name, type;
851 int i;
852 f >> i >> name >> type;
853 bcmap[i] = BoundaryCondition(name,type);
858 void GuiMainWindow::saveBC()
860 QString bc_file = current_filename + ".bcs";
861 QFile file(bc_file);
862 file.open(QIODevice::WriteOnly | QIODevice::Text);
863 QTextStream f(&file);
864 foreach(int i, all_boundary_codes) {
865 BoundaryCondition bc = bcmap[i];
866 f << i << " " << bc.getName() << " " << bc.getType() << "\n";
870 void GuiMainWindow::save()
872 cout << current_filename.toAscii().data() << endl;
873 if (current_filename == "untitled.vtu") {
874 saveAs();
875 } else {
876 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
877 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
878 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
880 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
881 addVtkTypeInfo();
882 createIndices(grid);
883 vtu->SetFileName(current_filename.toAscii().data());
884 vtu->SetDataModeToBinary();
885 vtu->SetInput(grid);
886 vtu->Write();
887 saveBC();
891 void GuiMainWindow::saveAs()
893 current_filename = QFileDialog::getSaveFileName
895 NULL,
896 "write grid to file",
897 getCwd(),
898 "VTK unstructured grid files (*.vtu *.VTU)"
900 if (!current_filename.isNull()) {
901 if (current_filename.right(4) != ".vtu") {
902 if (current_filename.right(4) != ".VTU") {
903 current_filename += ".vtu";
906 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
907 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
908 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
910 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
911 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
912 addVtkTypeInfo();
913 createIndices(grid);
914 vtu->SetFileName(current_filename.toAscii().data());
915 vtu->SetDataModeToBinary();
916 vtu->SetInput(grid);
917 vtu->Write();
918 saveBC();
919 setWindowTitle(current_filename + " - enGrid");
923 void GuiMainWindow::QuickSave(QString a_filename)
925 cout << a_filename.toAscii().data() << endl;
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 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
932 addVtkTypeInfo();
933 createIndices(grid);
934 vtu->SetFileName(a_filename.toAscii().data());
935 vtu->SetDataModeToBinary();
936 vtu->SetInput(grid);
937 vtu->Write();
938 saveBC();
942 void GuiMainWindow::updateStatusBar()
944 QString num, txt = "enGrid is currently busy with an operation ...";
945 if (!busy) {
946 txt = "";
948 if (!tryLock()) {
949 status_label->setText(txt);
950 return;
952 vtkIdType Ncells = grid->GetNumberOfCells();
953 vtkIdType Nnodes = grid->GetNumberOfPoints();
954 vtkIdType Ntris = 0;
955 vtkIdType Nquads = 0;
956 vtkIdType Ntets = 0;
957 vtkIdType Npyras = 0;
958 vtkIdType Nprism = 0;
959 vtkIdType Nhexas = 0;
960 for (vtkIdType i = 0; i < Ncells; ++i) {
961 int ct = grid->GetCellType(i);
962 if (ct == VTK_TRIANGLE) ++Ntris;
963 else if (ct == VTK_QUAD) ++Nquads;
964 else if (ct == VTK_TETRA) ++Ntets;
965 else if (ct == VTK_WEDGE) ++Nprism;
966 else if (ct == VTK_PYRAMID) ++Npyras;
967 else if (ct == VTK_HEXAHEDRON) ++Nhexas;
969 num.setNum(Ntets + Npyras + Nprism + Nhexas); txt += num + " volume cells(";
970 num.setNum(Ntets); txt += num + " tetras, ";
971 num.setNum(Npyras); txt += num + " pyramids, ";
972 num.setNum(Nprism); txt += num + " prisms, ";
973 num.setNum(Nhexas); txt += num + " hexas), ";
974 num.setNum(Ntris + Nquads); txt += num + " surface cells(";
975 num.setNum(Ntris); txt += num + " triangles, ";
976 num.setNum(Nquads); txt += num + " quads), ";
977 num.setNum(Nnodes); txt += num + " nodes";
979 if(ui.radioButton_CellPicker->isChecked())
981 QString pick_txt = ", picked cell: ";
982 vtkIdType id_cell = getPickedCell();
983 if (id_cell < 0) {
984 pick_txt += "no cell picked";
985 } else {
986 vtkIdType type_cell = grid->GetCellType(id_cell);
987 if (type_cell == VTK_TRIANGLE) pick_txt += "triangle";
988 else if (type_cell == VTK_QUAD) pick_txt += "quad";
989 else if (type_cell == VTK_TETRA) pick_txt += "tetrahedron";
990 else if (type_cell == VTK_PYRAMID) pick_txt += "pyramid";
991 else if (type_cell == VTK_WEDGE) pick_txt += "prism";
992 else if (type_cell == VTK_HEXAHEDRON) pick_txt += "hexahedron";
993 vtkIdType N_pts, *pts;
994 grid->GetCellPoints(id_cell, N_pts, pts);
995 pick_txt += " [";
996 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
997 QString num;
998 num.setNum(pts[i_pts]);
999 pick_txt += num;
1000 if (i_pts < N_pts-1) {
1001 pick_txt += ",";
1004 pick_txt += "]";
1005 QString tmp;
1006 tmp.setNum(id_cell);
1007 pick_txt += " id_cell=" + tmp;
1009 txt += pick_txt;
1011 else
1013 QString pick_txt = ", picked node: ";
1014 vtkIdType id_node = getPickedPoint();
1015 if (id_node < 0) {
1016 pick_txt += "no node picked";
1017 } else {
1018 vec3_t x;
1019 grid->GetPoints()->GetPoint(id_node,x.data());
1020 pick_txt += " [";
1021 for (int i = 0; i < 3; i++) {
1022 QString num;
1023 num.setNum(x[i]);
1024 pick_txt += num;
1025 if (i < 2) {
1026 pick_txt += ",";
1029 pick_txt += "]";
1030 QString tmp;
1031 tmp.setNum(id_node);
1032 pick_txt += " id_node=" + tmp;
1033 EG_VTKDCN(vtkDoubleArray, node_meshdensity, grid, "node_meshdensity");
1034 tmp.setNum(node_meshdensity->GetValue(id_node));
1035 pick_txt += " wanted density=" + tmp;
1036 EG_VTKDCN(vtkDoubleArray, node_meshdensity_current, grid, "node_meshdensity_current");
1037 tmp.setNum(node_meshdensity_current->GetValue(id_node));
1038 pick_txt += " current density=" + tmp;
1039 EG_VTKDCN(vtkCharArray, node_type, grid, "node_type");
1040 pick_txt += " type=" + QString(VertexType2Str( node_type->GetValue(id_node)));
1043 txt += pick_txt;
1046 status_label->setText(txt);
1047 unlock();
1050 void GuiMainWindow::selectBoundaryCodes()
1052 GuiSelectBoundaryCodes bcodes;
1053 bcodes.setDisplayBoundaryCodes(display_boundary_codes);
1054 bcodes.setBoundaryCodes(all_boundary_codes);
1055 bcodes();
1056 bcodes.getThread().wait();
1057 bcodes.getSelectedBoundaryCodes(display_boundary_codes);
1058 updateActors();
1061 void GuiMainWindow::updateBoundaryCodes(bool all_on)
1063 try {
1064 all_boundary_codes.clear();
1065 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1066 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
1067 int ct = grid->GetCellType(i);
1068 if ((ct == VTK_TRIANGLE) || (ct == VTK_QUAD)) {
1069 all_boundary_codes.insert(cell_code->GetValue(i));
1072 if (all_on) {
1073 display_boundary_codes.clear();
1074 foreach (int bc, all_boundary_codes) {
1075 display_boundary_codes.insert(bc);
1077 } else {
1078 QSet<int> dbcs;
1079 foreach (int bc, display_boundary_codes) {
1080 if (all_boundary_codes.contains(bc)) {
1081 dbcs.insert(bc);
1084 display_boundary_codes.clear();
1085 foreach (int bc, all_boundary_codes) {
1086 if (dbcs.contains(bc)) {
1087 display_boundary_codes.insert(bc);
1091 } catch (Error err) {
1092 err.display();
1096 void GuiMainWindow::normalExtrusion()
1098 GuiNormalExtrusion extr;
1099 extr();
1100 updateBoundaryCodes(false);
1101 updateActors();
1104 void GuiMainWindow::setAxesVisibility()
1106 if (ui.actionViewAxes->isChecked()) axes->SetVisibility(1);
1107 else axes->SetVisibility(0);
1108 getRenderWindow()->Render();
1111 void GuiMainWindow::setViewingMode()
1113 if (ui.actionViewOrthogonal->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1114 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1115 getRenderWindow()->Render();
1118 void GuiMainWindow::ViewNodeIDs()
1120 int N=grid->GetNumberOfPoints();
1121 cout<<"N="<<N<<endl;
1122 if (ui.actionViewNodeIDs->isChecked()) {
1123 cout<<"Activating node ID view"<<endl;
1124 NodeText_VectorText.resize(N);
1125 NodeText_PolyDataMapper.resize(N);
1126 NodeText_Follower.resize(N);
1127 for(int i=0;i<N;i++){
1128 NodeText_VectorText[i]=vtkVectorText::New();
1129 QString tmp;
1130 tmp.setNum(i);
1131 NodeText_VectorText[i]->SetText(tmp.toLatin1().data());
1132 NodeText_PolyDataMapper[i]=vtkPolyDataMapper::New();
1133 NodeText_PolyDataMapper[i]->SetInputConnection(NodeText_VectorText[i]->GetOutputPort());
1134 NodeText_Follower[i]=vtkFollower::New();
1135 NodeText_Follower[i]->SetMapper(NodeText_PolyDataMapper[i]);
1136 NodeText_Follower[i]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1137 vec3_t M;
1138 grid->GetPoint(i,M.data());
1139 vec3_t tmp_M=M;
1140 vec3_t OffSet=ReferenceSize*tmp_M.normalise();
1141 M=M+OffSet;
1142 NodeText_Follower[i]->AddPosition(M[0],M[1],M[2]);
1143 NodeText_Follower[i]->SetCamera(getRenderer()->GetActiveCamera());
1144 NodeText_Follower[i]->GetProperty()->SetColor(0,0,1);
1145 getRenderer()->AddActor(NodeText_Follower[i]);
1148 else {
1149 cout<<"Deactivating node ID view"<<endl;
1150 for(unsigned int i=0;i<NodeText_Follower.size();i++){
1151 getRenderer()->RemoveActor(NodeText_Follower[i]);
1152 NodeText_Follower[i]->Delete();
1153 NodeText_PolyDataMapper[i]->Delete();
1154 NodeText_VectorText[i]->Delete();
1156 NodeText_Follower.clear();
1157 NodeText_PolyDataMapper.clear();
1158 NodeText_VectorText.clear();
1161 getRenderWindow()->Render();
1164 void GuiMainWindow::ViewCellIDs()
1166 int N=grid->GetNumberOfCells();
1167 cout<<"N="<<N<<endl;
1168 if (ui.actionViewCellIDs->isChecked()) {
1169 cout<<"Activating cell ID view"<<endl;
1170 CellText_VectorText.resize(N);
1171 CellText_PolyDataMapper.resize(N);
1172 CellText_Follower.resize(N);
1173 for(int i=0;i<N;i++){
1174 CellText_VectorText[i]=vtkVectorText::New();
1175 QString tmp;
1176 tmp.setNum(i);
1177 CellText_VectorText[i]->SetText(tmp.toLatin1().data());
1178 CellText_PolyDataMapper[i]=vtkPolyDataMapper::New();
1179 CellText_PolyDataMapper[i]->SetInputConnection(CellText_VectorText[i]->GetOutputPort());
1180 CellText_Follower[i]=vtkFollower::New();
1181 CellText_Follower[i]->SetMapper(CellText_PolyDataMapper[i]);
1182 CellText_Follower[i]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1183 vtkIdType N_pts,*pts;
1184 grid->GetCellPoints(i,N_pts,pts);
1185 vec3_t Center(0,0,0);
1186 for(int p=0;p<N_pts;p++)
1188 vec3_t M;
1189 grid->GetPoint(pts[p],M.data());
1190 Center+=M.data();
1192 vec3_t OffSet=ReferenceSize*triNormal(grid,pts[0],pts[1],pts[2]).normalise();
1193 Center=1.0/(double)N_pts*Center+OffSet;
1194 CellText_Follower[i]->AddPosition(Center[0],Center[1],Center[2]);
1195 CellText_Follower[i]->SetCamera(getRenderer()->GetActiveCamera());
1196 CellText_Follower[i]->GetProperty()->SetColor(1,0,0);
1197 getRenderer()->AddActor(CellText_Follower[i]);
1200 else {
1201 cout<<"Deactivating cell ID view"<<endl;
1202 for(unsigned int i=0;i<CellText_Follower.size();i++){
1203 getRenderer()->RemoveActor(CellText_Follower[i]);
1204 CellText_Follower[i]->Delete();
1205 CellText_PolyDataMapper[i]->Delete();
1206 CellText_VectorText[i]->Delete();
1208 CellText_Follower.clear();
1209 CellText_PolyDataMapper.clear();
1210 CellText_VectorText.clear();
1213 getRenderWindow()->Render();
1216 void GuiMainWindow::addVtkTypeInfo()
1218 EG_VTKSP(vtkIntArray, vtk_type);
1219 vtk_type->SetName("vtk_type");
1220 vtk_type->SetNumberOfValues(grid->GetNumberOfCells());
1221 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1222 vtk_type->SetValue(cellId, grid->GetCellType(cellId));
1224 grid->GetCellData()->AddArray(vtk_type);
1227 void GuiMainWindow::pickCellCallBack
1229 vtkObject *caller,
1230 unsigned long int eid,
1231 void *clientdata,
1232 void *calldata
1235 caller = caller;
1236 eid = eid;
1237 clientdata = clientdata;
1238 calldata = calldata;
1239 THIS->updateActors();
1240 THIS->updateStatusBar();
1243 void GuiMainWindow::pickPointCallBack
1245 vtkObject *caller,
1246 unsigned long int eid,
1247 void *clientdata,
1248 void *calldata
1251 caller = caller;
1252 eid = eid;
1253 clientdata = clientdata;
1254 calldata = calldata;
1255 THIS->updateActors();
1256 THIS->updateStatusBar();
1259 vtkIdType GuiMainWindow::getPickedCell()
1261 vtkIdType picked_cell = -1;
1262 if (THIS->grid->GetNumberOfCells() > 0) {
1263 THIS->bcodes_filter->Update();
1264 EG_VTKDCC(vtkLongArray_t, cell_index, THIS->bcodes_filter->GetOutput(), "cell_index");
1266 vtkIdType cellId;
1267 if(m_UseVTKInteractor) cellId = THIS->CellPicker->GetCellId();
1268 else cellId = PickedCell;
1270 if (cellId >= 0) {
1271 if (cellId < THIS->bcodes_filter->GetOutput()->GetNumberOfCells()) {
1272 picked_cell = cell_index->GetValue(cellId);
1276 return picked_cell;
1279 vtkIdType GuiMainWindow::getPickedPoint()
1281 vtkIdType picked_point = -1;
1282 if (THIS->grid->GetNumberOfCells() > 0) {
1283 THIS->bcodes_filter->Update();
1285 vtkIdType pointId;
1286 if(m_UseVTKInteractor) pointId = THIS->PointPicker->GetPointId();
1287 else pointId = PickedPoint;
1289 if (pointId >= 0) {
1290 picked_point = pointId;
1293 return picked_point;
1296 void GuiMainWindow::changeSurfaceOrientation()
1298 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1299 vtkIdType Npts, *pts;
1300 grid->GetCellPoints(cellId, Npts, pts);
1301 QVector<vtkIdType> nodes(Npts);
1302 for (vtkIdType j = 0; j < Npts; ++j) nodes[j] = pts[j];
1303 for (vtkIdType j = 0; j < Npts; ++j) pts[Npts - j - 1] = nodes[j];
1305 updateActors();
1308 void GuiMainWindow::checkSurfaceOrientation()
1310 CorrectSurfaceOrientation corr_surf;
1311 vtkIdType picked_cell = getPickedCell();
1312 if (picked_cell >= 0) {
1313 corr_surf.setStart(picked_cell);
1315 corr_surf();
1316 updateActors();
1319 void GuiMainWindow::improveAspectRatio()
1321 GuiImproveAspectRatio impr_ar;
1322 impr_ar();
1323 updateActors();
1326 void GuiMainWindow::exportAsciiStl()
1328 StlWriter stl;
1329 stl();
1332 void GuiMainWindow::exportBinaryStl()
1336 void GuiMainWindow::periodicUpdate()
1338 Operation::collectGarbage();
1339 updateStatusBar();
1342 void GuiMainWindow::viewXP()
1344 getRenderer()->ResetCamera();
1345 double x[3];
1346 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1347 x[0] += 1;
1348 getRenderer()->GetActiveCamera()->SetPosition(x);
1349 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1350 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1351 getRenderer()->ResetCamera();
1352 getRenderWindow()->Render();
1355 void GuiMainWindow::viewXM()
1357 getRenderer()->ResetCamera();
1358 double x[3];
1359 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1360 x[0] -= 1;
1361 getRenderer()->GetActiveCamera()->SetPosition(x);
1362 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1363 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1364 getRenderer()->ResetCamera();
1365 getRenderWindow()->Render();
1368 void GuiMainWindow::viewYP()
1370 getRenderer()->ResetCamera();
1371 double x[3];
1372 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1373 x[1] += 1;
1374 getRenderer()->GetActiveCamera()->SetPosition(x);
1375 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1376 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1377 getRenderer()->ResetCamera();
1378 getRenderWindow()->Render();
1381 void GuiMainWindow::viewYM()
1383 getRenderer()->ResetCamera();
1384 double x[3];
1385 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1386 x[1] -= 1;
1387 getRenderer()->GetActiveCamera()->SetPosition(x);
1388 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1389 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1390 getRenderer()->ResetCamera();
1391 getRenderWindow()->Render();
1394 void GuiMainWindow::viewZP()
1396 getRenderer()->ResetCamera();
1397 double x[3];
1398 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1399 x[2] += 1;
1400 getRenderer()->GetActiveCamera()->SetPosition(x);
1401 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1402 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1403 getRenderer()->ResetCamera();
1404 getRenderWindow()->Render();
1407 void GuiMainWindow::viewZM()
1409 getRenderer()->ResetCamera();
1410 double x[3];
1411 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1412 x[2] -= 1;
1413 getRenderer()->GetActiveCamera()->SetPosition(x);
1414 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1415 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1416 getRenderer()->ResetCamera();
1417 getRenderWindow()->Render();
1420 void GuiMainWindow::callFixSTL()
1422 FixSTL *fix;
1423 fix = new FixSTL();
1424 fix->setGui();
1425 (*fix)();
1426 updateBoundaryCodes(false);
1427 updateActors();
1430 void GuiMainWindow::editBoundaryConditions()
1432 GuiEditBoundaryConditions editbcs;
1433 editbcs.setBoundaryCodes(all_boundary_codes);
1434 editbcs.setMap(&bcmap);
1435 editbcs();
1438 void GuiMainWindow::configure()
1441 // Just to create initial entries in the settings file
1442 // so that the options menu isn't empty at first start.
1443 GridSmoother tmp01;
1444 GuiCreateBoundaryLayer tmp02;
1446 GuiSettingsViewer settings(&qset);
1447 settings.exec();
1450 void GuiMainWindow::about()
1452 QMessageBox box(this);
1454 QString title="ENGRID";
1455 QString version = QString("version ") + ENGRID_VERSION;
1456 if (version == "version CVS") {
1457 version += " build on ";
1458 version += QString(__DATE__);
1459 version += " at ";
1460 version += QString(__TIME__);
1462 QString address = tr("ENGRID is being developed and maintained by:<br/>"
1463 "enGits GmbH<br/>"
1464 "Marie-Curie-Strasse 8<br/>"
1465 "79539 Loerrach<br/>"
1466 "Germany<br/>");
1468 QString mainurl="<a href=\"http://www.engits.com\">www.engits.com</a>";
1469 QString mail="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1470 QString gnuurl="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1471 QString license=tr("ENGRID is licenced under the GPL version 3.<br/>"
1472 "(see ")+gnuurl+tr(" for details)<br/>");
1473 QString bugurl="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1474 QString bugreporting=tr("To submit a bug report, please use ")+bugurl;
1475 box.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1476 "<h3>%1</h3>"
1477 "<p>%2</p>"
1478 "<p>%3</p>"
1479 "<p>Homepage: %4</p>"
1480 "<p>E-mail: %5</p>"
1481 "<p>%6</p>"
1482 "<p>%7</p></center>")
1483 .arg(title).arg(version).arg(address).arg(mainurl).arg(mail).arg(license).arg(bugreporting));
1484 box.setWindowTitle(tr("about ENGRID"));
1485 box.setIcon(QMessageBox::NoIcon);
1486 box.exec();
1490 void GuiMainWindow::getAllBoundaryCodes(QSet<int> &bcs)
1492 bcs.clear();
1493 foreach (int bc, all_boundary_codes) {
1494 bcs.insert(bc);