2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guimainwindow.h"
24 #include "guiselectboundarycodes.h"
25 #include "guiimproveaspectratio.h"
26 #include "guinormalextrusion.h"
27 #include "guisetboundarycode.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>
58 #include "geometrytools.h"
59 using namespace GeometryTools
;
61 #include "guisettingsviewer.h"
62 #include "guitransform.h"
64 // GuiOutputWindow::GuiOutputWindow()
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
)
82 QPoint pos
= qset
.value("pos", QPoint(200, 200)).toPoint();
83 QSize size
= qset
.value("size", QSize(400, 400)).toSize();
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();
155 pyramid_actor
= NULL
;
158 volume_wire_actor
= NULL
;
159 iamlegend_actor
= 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();
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
);
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
);
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
;
235 log_file_name
= "/tmp/" + basename
;
237 system_stdout
= stdout
;
238 freopen (log_file_name
.toAscii().data(), "w", stdout
);
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);
252 getSet("","enable experimental features",false,exp_features
);
253 ui
.actionFoamWriter
->setEnabled(exp_features
);
257 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
258 // ui.radioButton_CellPicker->setChecked(true);
259 setPickMode(true,true);
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()
304 QVTKInteractor
* GuiMainWindow::getInteractor()
306 return ui
.qvtkWidget
->GetInteractor();
309 QString
GuiMainWindow::getCwd()
314 void GuiMainWindow::setCwd(QString dir
)
317 qset
.setValue("working_directory",dir
);
320 void GuiMainWindow::ScaleToData()
322 int current_field
=ui
.comboBox_Field
->currentIndex();
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;
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
);
364 for (vtkIdType nodeId
= 0; nodeId
< grid
->GetNumberOfPoints(); ++nodeId
) {
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
);
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
;
386 getRenderer()->RemoveActor(tetra_actor
);
387 tetra_actor
->Delete();
391 getRenderer()->RemoveActor(pyramid_actor
);
392 pyramid_actor
->Delete();
393 pyramid_actor
= NULL
;
396 getRenderer()->RemoveActor(wedge_actor
);
397 wedge_actor
->Delete();
401 getRenderer()->RemoveActor(hexa_actor
);
402 hexa_actor
->Delete();
405 if (volume_wire_actor
) {
406 getRenderer()->RemoveActor(volume_wire_actor
);
407 volume_wire_actor
->Delete();
408 volume_wire_actor
= NULL
;
411 getRenderer()->RemoveActor(pick_actor
);
412 pick_actor
->Delete();
415 if (iamlegend_actor
) {
416 getRenderer()->RemoveActor(iamlegend_actor
);
417 iamlegend_actor
->Delete();
418 iamlegend_actor
= NULL
;
425 field_mapper
->Delete();
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();
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
);
494 lut
=vtkLookupTable::New();
495 lut
->SetNumberOfColors(ui
.spinBox_Color
->value());
496 lut
->SetHueRange(ui
.doubleSpinBox_HueMin
->value(),ui
.doubleSpinBox_HueMax
->value());
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();
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();
567 getInteractor()->SetPicker(PointPicker
);
568 vtkIdType nodeId
= getPickedPoint();
574 if(ui
.radioButton_CellPicker
->isChecked()) pickCell(PickedCell
);
575 else pickPoint(PickedPoint
);
577 /* getInteractor()->SetPicker(CellPicker);
578 vtkIdType cellId = getPickedCell();
580 getInteractor()->SetPicker(PointPicker);
581 vtkIdType nodeId = getPickedPoint();
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();
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
);
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
);
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
);
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();
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
);
678 extr_vol
->SetInput(grid
);
679 if (ui
.checkBoxClip
->isChecked()) {
680 extr_vol
->SetClippingOn();
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
);
698 getRenderWindow()->Render();
699 } catch (Error err
) {
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()) {
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
);
739 bool GuiMainWindow::pickCell(vtkIdType cellId
)
741 if (cellId
>= 0 && cellId
<grid
->GetNumberOfCells()) {
742 vtkIdType
*pts
, Npts
;
743 grid
->GetCellPoints(cellId
, Npts
, pts
);
745 for (vtkIdType i
= 0; i
< Npts
; ++i
) {
747 grid
->GetPoints()->GetPoint(pts
[i
], xp
.data());
748 x
+= double(1)/Npts
* xp
;
750 pick_sphere
->SetCenter(x
.data());
752 for (vtkIdType i
= 0; i
< Npts
; ++i
) {
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
);
771 void GuiMainWindow::importSTL()
775 updateBoundaryCodes(true);
781 void GuiMainWindow::importGmsh1Ascii()
786 updateBoundaryCodes(true);
792 void GuiMainWindow::exportGmsh1Ascii()
799 void GuiMainWindow::importGmsh2Ascii()
804 updateBoundaryCodes(true);
810 void GuiMainWindow::exportGmsh2Ascii()
817 void GuiMainWindow::exportNeutral()
819 NeutralWriter neutral
;
823 void GuiMainWindow::zoomAll()
825 getRenderer()->ResetCamera();
826 getRenderWindow()->Render();
829 void GuiMainWindow::open()
831 current_filename
= QFileDialog::getOpenFileName
834 "open grid from file",
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());
843 grid
->DeepCopy(vtu
->GetOutput());
844 createBasicFields(grid
, grid
->GetNumberOfCells(), grid
->GetNumberOfPoints(), false);
845 setWindowTitle(current_filename
+ " - enGrid");
847 updateBoundaryCodes(true);
854 void GuiMainWindow::undo()
858 void GuiMainWindow::redo()
862 void GuiMainWindow::openBC()
864 QString bc_file
= current_filename
+ ".bcs";
868 file
.open(QIODevice::ReadOnly
| QIODevice::Text
);
869 QTextStream
f(&file
);
873 f
>> i
>> name
>> type
;
874 bcmap
[i
] = BoundaryCondition(name
,type
);
879 void GuiMainWindow::saveBC()
881 QString bc_file
= current_filename
+ ".bcs";
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") {
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
);
904 vtu
->SetFileName(current_filename
.toAscii().data());
905 vtu
->SetDataModeToBinary();
912 void GuiMainWindow::saveAs()
914 current_filename
= QFileDialog::getSaveFileName
917 "write grid to file",
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
);
935 vtu
->SetFileName(current_filename
.toAscii().data());
936 vtu
->SetDataModeToBinary();
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
);
955 vtu
->SetFileName(a_filename
.toAscii().data());
956 vtu
->SetDataModeToBinary();
963 void GuiMainWindow::updateStatusBar()
965 QString num
, txt
= "enGrid is currently busy with an operation ...";
970 status_label
->setText(txt
);
973 vtkIdType Ncells
= grid
->GetNumberOfCells();
974 vtkIdType Nnodes
= grid
->GetNumberOfPoints();
976 vtkIdType Nquads
= 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();
1005 pick_txt
+= "no cell picked";
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
);
1017 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
1019 num
.setNum(pts
[i_pts
]);
1021 if (i_pts
< N_pts
-1) {
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
;
1037 QString pick_txt
= ", picked node: ";
1038 vtkIdType id_node
= getPickedPoint();
1040 pick_txt
+= "no node picked";
1043 grid
->GetPoints()->GetPoint(id_node
,x
.data());
1045 for (int i
= 0; i
< 3; i
++) {
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(vtkIntArray
, node_specified_density
, grid
, "node_specified_density");
1062 tmp
.setNum(node_specified_density
->GetValue(id_node
));
1063 pick_txt
+= " node_specified_density=" + tmp
;
1064 EG_VTKDCN(vtkCharArray
, node_type
, grid
, "node_type");
1065 pick_txt
+= " type=" + QString(VertexType2Str( node_type
->GetValue(id_node
)));
1066 tmp
.setNum(id_node
);
1067 pick_txt
+= " id_node=" + tmp
;
1073 status_label
->setText(txt
);
1077 void GuiMainWindow::selectBoundaryCodes()
1079 GuiSelectBoundaryCodes bcodes
;
1080 bcodes
.setDisplayBoundaryCodes(display_boundary_codes
);
1081 bcodes
.setBoundaryCodes(all_boundary_codes
);
1083 bcodes
.getThread().wait();
1084 bcodes
.getSelectedBoundaryCodes(display_boundary_codes
);
1088 void GuiMainWindow::updateBoundaryCodes(bool all_on
)
1091 all_boundary_codes
.clear();
1092 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1093 for (vtkIdType i
= 0; i
< grid
->GetNumberOfCells(); ++i
) {
1094 int ct
= grid
->GetCellType(i
);
1095 if ((ct
== VTK_TRIANGLE
) || (ct
== VTK_QUAD
)) {
1096 all_boundary_codes
.insert(cell_code
->GetValue(i
));
1100 display_boundary_codes
.clear();
1101 foreach (int bc
, all_boundary_codes
) {
1102 display_boundary_codes
.insert(bc
);
1106 foreach (int bc
, display_boundary_codes
) {
1107 if (all_boundary_codes
.contains(bc
)) {
1111 display_boundary_codes
.clear();
1112 foreach (int bc
, all_boundary_codes
) {
1113 if (dbcs
.contains(bc
)) {
1114 display_boundary_codes
.insert(bc
);
1118 } catch (Error err
) {
1123 void GuiMainWindow::normalExtrusion()
1125 GuiNormalExtrusion extr
;
1127 updateBoundaryCodes(false);
1131 void GuiMainWindow::setAxesVisibility()
1133 if (ui
.actionViewAxes
->isChecked()) axes
->SetVisibility(1);
1134 else axes
->SetVisibility(0);
1135 getRenderWindow()->Render();
1138 void GuiMainWindow::setViewingMode()
1140 if (ui
.actionViewOrthogonal
->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1141 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1142 getRenderWindow()->Render();
1145 void GuiMainWindow::ViewNodeIDs()
1147 int N
=grid
->GetNumberOfPoints();
1148 cout
<<"N="<<N
<<endl
;
1149 if (ui
.actionViewNodeIDs
->isChecked()) {
1150 cout
<<"Activating node ID view"<<endl
;
1151 NodeText_VectorText
.resize(N
);
1152 NodeText_PolyDataMapper
.resize(N
);
1153 NodeText_Follower
.resize(N
);
1154 for(int i
=0;i
<N
;i
++){
1155 NodeText_VectorText
[i
]=vtkVectorText::New();
1158 NodeText_VectorText
[i
]->SetText(tmp
.toLatin1().data());
1159 NodeText_PolyDataMapper
[i
]=vtkPolyDataMapper::New();
1160 NodeText_PolyDataMapper
[i
]->SetInputConnection(NodeText_VectorText
[i
]->GetOutputPort());
1161 NodeText_Follower
[i
]=vtkFollower::New();
1162 NodeText_Follower
[i
]->SetMapper(NodeText_PolyDataMapper
[i
]);
1163 NodeText_Follower
[i
]->SetScale(ReferenceSize
,ReferenceSize
,ReferenceSize
);
1165 grid
->GetPoint(i
,M
.data());
1167 vec3_t OffSet
=ReferenceSize
*tmp_M
.normalise();
1169 NodeText_Follower
[i
]->AddPosition(M
[0],M
[1],M
[2]);
1170 NodeText_Follower
[i
]->SetCamera(getRenderer()->GetActiveCamera());
1171 NodeText_Follower
[i
]->GetProperty()->SetColor(0,0,1);
1172 getRenderer()->AddActor(NodeText_Follower
[i
]);
1176 cout
<<"Deactivating node ID view"<<endl
;
1177 for(unsigned int i
=0;i
<NodeText_Follower
.size();i
++){
1178 getRenderer()->RemoveActor(NodeText_Follower
[i
]);
1179 NodeText_Follower
[i
]->Delete();
1180 NodeText_PolyDataMapper
[i
]->Delete();
1181 NodeText_VectorText
[i
]->Delete();
1183 NodeText_Follower
.clear();
1184 NodeText_PolyDataMapper
.clear();
1185 NodeText_VectorText
.clear();
1188 getRenderWindow()->Render();
1191 void GuiMainWindow::ViewCellIDs()
1193 vtkIdType N
=grid
->GetNumberOfCells();
1194 cout
<<"N="<<N
<<endl
;
1195 if (ui
.actionViewCellIDs
->isChecked()) {
1196 cout
<<"Activating cell ID view"<<endl
;
1197 CellText_VectorText
.resize(N
);
1198 CellText_PolyDataMapper
.resize(N
);
1199 CellText_Follower
.resize(N
);
1200 for(vtkIdType id_cell
=0;id_cell
<N
;id_cell
++){
1201 CellText_VectorText
[id_cell
]=vtkVectorText::New();
1205 if(ui
.comboBox_CellTextField
->currentIndex()==0) {
1206 tmp
.setNum(id_cell
);
1208 else if(ui
.comboBox_CellTextField
->currentIndex()>0) {
1209 EG_VTKDCC(vtkIntArray
, current_cell_field
, grid
, ui
.comboBox_CellTextField
->currentText().toLatin1().data());
1210 tmp
.setNum(current_cell_field
->GetValue(id_cell
));
1214 CellText_VectorText
[id_cell
]->SetText(tmp
.toLatin1().data());
1215 CellText_PolyDataMapper
[id_cell
]=vtkPolyDataMapper::New();
1216 CellText_PolyDataMapper
[id_cell
]->SetInputConnection(CellText_VectorText
[id_cell
]->GetOutputPort());
1217 CellText_Follower
[id_cell
]=vtkFollower::New();
1218 CellText_Follower
[id_cell
]->SetMapper(CellText_PolyDataMapper
[id_cell
]);
1219 CellText_Follower
[id_cell
]->SetScale(ReferenceSize
,ReferenceSize
,ReferenceSize
);
1220 vtkIdType N_pts
,*pts
;
1221 grid
->GetCellPoints(id_cell
,N_pts
,pts
);
1222 vec3_t
Center(0,0,0);
1223 for(int p
=0;p
<N_pts
;p
++)
1226 grid
->GetPoint(pts
[p
],M
.data());
1229 vec3_t OffSet
=ReferenceSize
*triNormal(grid
,pts
[0],pts
[1],pts
[2]).normalise();
1230 Center
=1.0/(double)N_pts
*Center
+OffSet
;
1231 CellText_Follower
[id_cell
]->AddPosition(Center
[0],Center
[1],Center
[2]);
1232 CellText_Follower
[id_cell
]->SetCamera(getRenderer()->GetActiveCamera());
1233 CellText_Follower
[id_cell
]->GetProperty()->SetColor(1,0,0);
1234 getRenderer()->AddActor(CellText_Follower
[id_cell
]);
1238 cout
<<"Deactivating cell ID view"<<endl
;
1239 for(vtkIdType id_cell
=0;id_cell
<CellText_Follower
.size();id_cell
++){
1240 getRenderer()->RemoveActor(CellText_Follower
[id_cell
]);
1241 CellText_Follower
[id_cell
]->Delete();
1242 CellText_PolyDataMapper
[id_cell
]->Delete();
1243 CellText_VectorText
[id_cell
]->Delete();
1245 CellText_Follower
.clear();
1246 CellText_PolyDataMapper
.clear();
1247 CellText_VectorText
.clear();
1250 getRenderWindow()->Render();
1253 void GuiMainWindow::addVtkTypeInfo()
1255 EG_VTKSP(vtkIntArray
, vtk_type
);
1256 vtk_type
->SetName("vtk_type");
1257 vtk_type
->SetNumberOfValues(grid
->GetNumberOfCells());
1258 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
1259 vtk_type
->SetValue(cellId
, grid
->GetCellType(cellId
));
1261 grid
->GetCellData()->AddArray(vtk_type
);
1264 void GuiMainWindow::pickCellCallBack
1267 unsigned long int eid
,
1274 clientdata
= clientdata
;
1275 calldata
= calldata
;
1276 THIS
->updateActors();
1277 THIS
->updateStatusBar();
1280 void GuiMainWindow::pickPointCallBack
1283 unsigned long int eid
,
1290 clientdata
= clientdata
;
1291 calldata
= calldata
;
1292 THIS
->updateActors();
1293 THIS
->updateStatusBar();
1296 vtkIdType
GuiMainWindow::getPickedCell()
1298 vtkIdType picked_cell
= -1;
1299 if (THIS
->grid
->GetNumberOfCells() > 0) {
1300 THIS
->bcodes_filter
->Update();
1301 EG_VTKDCC(vtkLongArray_t
, cell_index
, THIS
->bcodes_filter
->GetOutput(), "cell_index");
1304 if(m_UseVTKInteractor
) cellId
= THIS
->CellPicker
->GetCellId();
1305 else cellId
= PickedCell
;
1308 if (cellId
< THIS
->bcodes_filter
->GetOutput()->GetNumberOfCells()) {
1309 picked_cell
= cell_index
->GetValue(cellId
);
1316 vtkIdType
GuiMainWindow::getPickedPoint()
1318 vtkIdType picked_point
= -1;
1319 if (THIS
->grid
->GetNumberOfCells() > 0) {
1320 THIS
->bcodes_filter
->Update();
1323 if(m_UseVTKInteractor
) pointId
= THIS
->PointPicker
->GetPointId();
1324 else pointId
= PickedPoint
;
1327 picked_point
= pointId
;
1330 return picked_point
;
1333 void GuiMainWindow::changeSurfaceOrientation()
1335 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
1336 vtkIdType Npts
, *pts
;
1337 grid
->GetCellPoints(cellId
, Npts
, pts
);
1338 QVector
<vtkIdType
> nodes(Npts
);
1339 for (vtkIdType j
= 0; j
< Npts
; ++j
) nodes
[j
] = pts
[j
];
1340 for (vtkIdType j
= 0; j
< Npts
; ++j
) pts
[Npts
- j
- 1] = nodes
[j
];
1345 void GuiMainWindow::checkSurfaceOrientation()
1347 CorrectSurfaceOrientation corr_surf
;
1348 vtkIdType picked_cell
= getPickedCell();
1349 if (picked_cell
>= 0) {
1350 corr_surf
.setStart(picked_cell
);
1356 void GuiMainWindow::improveAspectRatio()
1358 GuiImproveAspectRatio impr_ar
;
1363 void GuiMainWindow::exportAsciiStl()
1369 void GuiMainWindow::exportBinaryStl()
1373 void GuiMainWindow::periodicUpdate()
1375 Operation::collectGarbage();
1379 void GuiMainWindow::viewXP()
1381 getRenderer()->ResetCamera();
1383 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1385 getRenderer()->GetActiveCamera()->SetPosition(x
);
1386 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1387 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1388 getRenderer()->ResetCamera();
1389 getRenderWindow()->Render();
1392 void GuiMainWindow::viewXM()
1394 getRenderer()->ResetCamera();
1396 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1398 getRenderer()->GetActiveCamera()->SetPosition(x
);
1399 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1400 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1401 getRenderer()->ResetCamera();
1402 getRenderWindow()->Render();
1405 void GuiMainWindow::viewYP()
1407 getRenderer()->ResetCamera();
1409 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1411 getRenderer()->GetActiveCamera()->SetPosition(x
);
1412 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1413 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1414 getRenderer()->ResetCamera();
1415 getRenderWindow()->Render();
1418 void GuiMainWindow::viewYM()
1420 getRenderer()->ResetCamera();
1422 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1424 getRenderer()->GetActiveCamera()->SetPosition(x
);
1425 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1426 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1427 getRenderer()->ResetCamera();
1428 getRenderWindow()->Render();
1431 void GuiMainWindow::viewZP()
1433 getRenderer()->ResetCamera();
1435 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1437 getRenderer()->GetActiveCamera()->SetPosition(x
);
1438 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1439 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1440 getRenderer()->ResetCamera();
1441 getRenderWindow()->Render();
1444 void GuiMainWindow::viewZM()
1446 getRenderer()->ResetCamera();
1448 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1450 getRenderer()->GetActiveCamera()->SetPosition(x
);
1451 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1452 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1453 getRenderer()->ResetCamera();
1454 getRenderWindow()->Render();
1457 void GuiMainWindow::callFixSTL()
1463 updateBoundaryCodes(false);
1467 void GuiMainWindow::editBoundaryConditions()
1469 GuiEditBoundaryConditions editbcs
;
1470 editbcs
.setBoundaryCodes(all_boundary_codes
);
1471 editbcs
.setMap(&bcmap
);
1475 void GuiMainWindow::configure()
1478 // Just to create initial entries in the settings file
1479 // so that the options menu isn't empty at first start.
1481 GuiCreateBoundaryLayer tmp02
;
1483 GuiSettingsViewer
settings(&qset
);
1487 void GuiMainWindow::about()
1489 QMessageBox
box(this);
1491 QString title
="ENGRID";
1492 QString version
= QString("version ") + ENGRID_VERSION
;
1493 if (version
== "version CVS") {
1494 version
+= " build on ";
1495 version
+= QString(__DATE__
);
1497 version
+= QString(__TIME__
);
1499 QString address
= tr("ENGRID is being developed and maintained by:<br/>"
1501 "Marie-Curie-Strasse 8<br/>"
1502 "79539 Loerrach<br/>"
1505 QString mainurl
="<a href=\"http://www.engits.com\">www.engits.com</a>";
1506 QString mail
="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1507 QString gnuurl
="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1508 QString license
=tr("ENGRID is licenced under the GPL version 3.<br/>"
1509 "(see ")+gnuurl
+tr(" for details)<br/>");
1510 QString bugurl
="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1511 QString bugreporting
=tr("To submit a bug report, please use ")+bugurl
;
1512 box
.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1516 "<p>Homepage: %4</p>"
1519 "<p>%7</p></center>")
1520 .arg(title
).arg(version
).arg(address
).arg(mainurl
).arg(mail
).arg(license
).arg(bugreporting
));
1521 box
.setWindowTitle(tr("about ENGRID"));
1522 box
.setIcon(QMessageBox::NoIcon
);
1527 void GuiMainWindow::getAllBoundaryCodes(QSet
<int> &bcs
)
1530 foreach (int bc
, all_boundary_codes
) {