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"
63 #include "egvtkinteractorstyle.h"
65 // GuiOutputWindow::GuiOutputWindow()
70 QString
GuiMainWindow::cwd
= ".";
71 QSettings
GuiMainWindow::qset("enGits","enGrid");
72 GuiMainWindow
* GuiMainWindow::THIS
= NULL
;
73 QMutex
GuiMainWindow::mutex
;
74 vtkIdType
GuiMainWindow::PickedPoint
;
75 vtkIdType
GuiMainWindow::PickedCell
;
76 bool GuiMainWindow::m_UseVTKInteractor
;
78 GuiMainWindow::GuiMainWindow() : QMainWindow(NULL
)
83 QPoint pos
= qset
.value("pos", QPoint(200, 200)).toPoint();
84 QSize size
= qset
.value("size", QSize(400, 400)).toSize();
88 // dock_widget = new QDockWidget(tr("output"), this);
89 // dock_widget->setFeatures(QDockWidget::AllDockWidgetFeatures);
90 // output_window = new GuiOutputWindow();
91 // dock_widget->setWidget(output_window);
92 // addDockWidget(Qt::LeftDockWidgetArea, dock_widget);
93 // ui.menuView->addAction(dock_widget->toggleViewAction());
95 connect(ui
.actionImportSTL
, SIGNAL(activated()), this, SLOT(importSTL()));
96 connect(ui
.actionImportGmsh1Ascii
, SIGNAL(activated()), this, SLOT(importGmsh1Ascii()));
97 connect(ui
.actionImportGmsh2Ascii
, SIGNAL(activated()), this, SLOT(importGmsh2Ascii()));
98 connect(ui
.actionExportGmsh1Ascii
, SIGNAL(activated()), this, SLOT(exportGmsh1Ascii()));
99 connect(ui
.actionExportGmsh2Ascii
, SIGNAL(activated()), this, SLOT(exportGmsh2Ascii()));
100 connect(ui
.actionExportNeutral
, SIGNAL(activated()), this, SLOT(exportNeutral()));
101 connect(ui
.actionExportAsciiStl
, SIGNAL(activated()), this, SLOT(exportAsciiStl()));
102 connect(ui
.actionExportBinaryStl
, SIGNAL(activated()), this, SLOT(exportBinaryStl()));
103 connect(ui
.actionExit
, SIGNAL(activated()), this, SLOT(exit()));
104 connect(ui
.actionZoomAll
, SIGNAL(activated()), this, SLOT(zoomAll()));
105 connect(ui
.actionOpen
, SIGNAL(activated()), this, SLOT(open()));
106 connect(ui
.actionSave
, SIGNAL(activated()), this, SLOT(save()));
107 connect(ui
.actionSaveAs
, SIGNAL(activated()), this, SLOT(saveAs()));
108 connect(ui
.actionBoundaryCodes
, SIGNAL(activated()), this, SLOT(selectBoundaryCodes()));
109 connect(ui
.actionNormalExtrusion
, SIGNAL(activated()), this, SLOT(normalExtrusion()));
110 connect(ui
.actionViewAxes
, SIGNAL(changed()), this, SLOT(setAxesVisibility()));
111 connect(ui
.actionViewOrthogonal
, SIGNAL(changed()), this, SLOT(setViewingMode()));
112 connect(ui
.actionViewNodeIDs
, SIGNAL(changed()), this, SLOT(ViewNodeIDs()));
113 connect(ui
.actionViewCellIDs
, SIGNAL(changed()), this, SLOT(ViewCellIDs()));
114 connect(ui
.actionChangeOrientation
, SIGNAL(activated()), this, SLOT(changeSurfaceOrientation()));
115 connect(ui
.actionCheckOrientation
, SIGNAL(activated()), this, SLOT(checkSurfaceOrientation()));
116 connect(ui
.actionImproveAspectRatio
, SIGNAL(activated()), this, SLOT(improveAspectRatio()));
117 connect(ui
.actionRedraw
, SIGNAL(activated()), this, SLOT(updateActors()));
118 connect(ui
.actionScaleToData
, SIGNAL(activated()), this, SLOT(ScaleToData()));
119 connect(ui
.actionClearOutputWindow
, SIGNAL(activated()), this, SLOT(clearOutput()));
120 connect(ui
.actionEditBoundaryConditions
, SIGNAL(activated()), this, SLOT(editBoundaryConditions()));
121 connect(ui
.actionConfigure
, SIGNAL(activated()), this, SLOT(configure()));
122 connect(ui
.actionAbout
, SIGNAL(activated()), this, SLOT(about()));
124 connect(ui
.checkBox_UseVTKInteractor
, SIGNAL(stateChanged(int)), this, SLOT(setUseVTKInteractor(int)));
126 connect(ui
.actionViewXP
, SIGNAL(activated()), this, SLOT(viewXP()));
127 connect(ui
.actionViewXM
, SIGNAL(activated()), this, SLOT(viewXM()));
128 connect(ui
.actionViewYP
, SIGNAL(activated()), this, SLOT(viewYP()));
129 connect(ui
.actionViewYM
, SIGNAL(activated()), this, SLOT(viewYM()));
130 connect(ui
.actionViewZP
, SIGNAL(activated()), this, SLOT(viewZP()));
131 connect(ui
.actionViewZM
, SIGNAL(activated()), this, SLOT(viewZM()));
134 #include "std_connections.h"
136 if (qset
.contains("working_directory")) {
137 cwd
= qset
.value("working_directory").toString();
139 grid
= vtkUnstructuredGrid::New();
140 renderer
= vtkRenderer::New();
141 getRenderWindow()->AddRenderer(renderer
);
142 surface_actor
= vtkActor::New();
143 surface_wire_actor
= vtkActor::New();
145 tetra_mapper
= vtkPolyDataMapper::New();
146 pyramid_mapper
= vtkPolyDataMapper::New();
147 wedge_mapper
= vtkPolyDataMapper::New();
148 hexa_mapper
= vtkPolyDataMapper::New();
149 volume_wire_mapper
= vtkPolyDataMapper::New();
150 surface_mapper
= vtkPolyDataMapper::New();
151 surface_wire_mapper
= vtkPolyDataMapper::New();
153 backface_property
= vtkProperty::New();
156 pyramid_actor
= NULL
;
159 volume_wire_actor
= NULL
;
160 iamlegend_actor
= NULL
;
164 surface_filter
= vtkGeometryFilter::New();
165 bcodes_filter
= vtkEgBoundaryCodesFilter::New();
166 renderer
->AddActor(surface_actor
);
167 renderer
->AddActor(surface_wire_actor
);
168 pick_sphere
= vtkSphereSource::New();
169 pick_mapper
= vtkPolyDataMapper::New();
172 extr_vol
= vtkEgExtractVolumeCells::New();
173 extr_tetras
= vtkEgExtractVolumeCells::New();
174 extr_pyramids
= vtkEgExtractVolumeCells::New();
175 extr_wedges
= vtkEgExtractVolumeCells::New();
176 extr_hexas
= vtkEgExtractVolumeCells::New();
178 volume_geometry
= vtkGeometryFilter::New();
179 tetra_geometry
= vtkGeometryFilter::New();
180 pyramid_geometry
= vtkGeometryFilter::New();
181 wedge_geometry
= vtkGeometryFilter::New();
182 hexa_geometry
= vtkGeometryFilter::New();
184 extr_tetras
->SetAllOff();
185 extr_tetras
->SetTetrasOn();
186 extr_pyramids
->SetAllOff();
187 extr_pyramids
->SetPyramidsOn();
188 extr_wedges
->SetAllOff();
189 extr_wedges
->SetWedgesOn();
190 extr_hexas
->SetAllOff();
191 extr_hexas
->SetHexasOn();
193 boundary_pd
= vtkPolyData::New();
194 tetras_pd
= vtkPolyData::New();
195 wedges_pd
= vtkPolyData::New();
196 pyras_pd
= vtkPolyData::New();
197 hexas_pd
= vtkPolyData::New();
198 volume_pd
= vtkPolyData::New();
200 current_filename
= "untitled.vtu";
201 setWindowTitle(current_filename
+ " - enGrid");
203 status_bar
= new QStatusBar(this);
204 setStatusBar(status_bar
);
205 status_label
= new QLabel(this);
206 status_bar
->addWidget(status_label
);
207 QString txt
= "0 volume cells (0 tetras, 0 hexas, 0 pyramids, 0 prisms), ";
208 txt
+= "0 surface cells (0 triangles, 0 quads), 0 nodes";
209 status_label
->setText(txt
);
211 axes
= vtkCubeAxesActor2D::New();
212 axes
->SetCamera(getRenderer()->GetActiveCamera());
213 getRenderer()->AddActor(axes
);
216 CellPicker
= vtkCellPicker::New();
217 // getInteractor()->SetPicker(CellPicker);
218 PointPicker
= vtkPointPicker::New();
219 // getInteractor()->SetPicker(PointPicker);
221 pick_sphere
->SetRadius(0.25);//in case the user starts picking points instead of cells
223 vtkCallbackCommand
*cbc
= vtkCallbackCommand::New();
224 cbc
->SetCallback(pickCellCallBack
);
225 CellPicker
->AddObserver(vtkCommand::EndPickEvent
, cbc
);
226 cbc
->SetCallback(pickPointCallBack
);
227 PointPicker
->AddObserver(vtkCommand::EndPickEvent
, cbc
);
230 QString user
= QString(getenv("USER"));
231 QString basename
="enGrid_output_"+user
+".txt";
233 if (qset
.contains("tmp_directory")) {
234 log_file_name
= qset
.value("tmp_directory").toString() + "/" + basename
;
236 log_file_name
= "/tmp/" + basename
;
238 system_stdout
= stdout
;
239 freopen (log_file_name
.toAscii().data(), "w", stdout
);
244 connect(&garbage_timer
, SIGNAL(timeout()), this, SLOT(periodicUpdate()));
245 garbage_timer
.start(1000);
247 connect(&log_timer
, SIGNAL(timeout()), this, SLOT(updateOutput()));
248 log_timer
.start(1000);
253 // getSet("","enable experimental features",false,exp_features);
255 getSet("","enable undo/redo",false,undo_redo
);
257 getSet("","use RAM for undo/redo oprations",false,undo_redo_mode
);
259 ui
.actionFoamWriter
->setEnabled(exp_features
);
263 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
264 // ui.radioButton_CellPicker->setChecked(true);
265 setPickMode(true,true);
269 ui
.doubleSpinBox_HueMin
->setValue(0.667);
270 ui
.doubleSpinBox_HueMax
->setValue(0);
272 egvtkInteractorStyle
*style
= egvtkInteractorStyle::New();
273 getInteractor()->SetInteractorStyle(style
);
276 //end of GuiMainWindow::GuiMainWindow() : QMainWindow(NULL)
278 GuiMainWindow::~GuiMainWindow()
280 qset
.setValue("pos", pos());
281 qset
.setValue("size", size());
284 void GuiMainWindow::updateOutput()
286 QFile
log_file(log_file_name
);
287 log_file
.open(QIODevice::ReadOnly
);
288 QByteArray buffer
= log_file
.readAll();
289 if (buffer
.size() > N_chars
) {
290 QByteArray newchars
= buffer
.right(buffer
.size() - N_chars
);
291 N_chars
= buffer
.size();
292 QString
txt(newchars
);
293 if (txt
.right(1) == "\n") {
294 txt
= txt
.left(txt
.size()-1);
296 ui
.textEditOutput
->append(txt
);
300 void GuiMainWindow::exit()
302 QCoreApplication::exit();
305 vtkRenderWindow
* GuiMainWindow::getRenderWindow()
307 return ui
.qvtkWidget
->GetRenderWindow();
310 vtkRenderer
* GuiMainWindow::getRenderer()
315 QVTKInteractor
* GuiMainWindow::getInteractor()
317 return ui
.qvtkWidget
->GetInteractor();
320 QString
GuiMainWindow::getCwd()
325 void GuiMainWindow::setCwd(QString dir
)
328 qset
.setValue("working_directory",dir
);
331 void GuiMainWindow::ScaleToData()
333 int current_field
=ui
.comboBox_Field
->currentIndex();
337 boundary_pd
->GetPointData()->GetArray(current_field
-1)->GetRange(range
);
338 cout
<<"current_field="<<current_field
<<endl
;
339 cout
<<"range[0]="<<range
[0]<<endl
;
340 cout
<<"range[1]="<<range
[1]<<endl
;
341 ui
.doubleSpinBox_FieldMin
->setRange(range
[0],range
[1]);
342 ui
.doubleSpinBox_FieldMax
->setRange(range
[0],range
[1]);
343 ui
.doubleSpinBox_FieldMin
->setValue(range
[0]);
344 ui
.doubleSpinBox_FieldMax
->setValue(range
[1]);
348 void GuiMainWindow::updateActors()
350 if (!tryLock()) return;
354 if (!grid
->GetCellData()->GetScalars("cell_index")) {
355 EG_VTKSP(vtkLongArray_t
, cell_idx
);
356 cell_idx
->SetName("cell_index");
357 cell_idx
->SetNumberOfValues(grid
->GetNumberOfCells());
358 grid
->GetCellData()->AddArray(cell_idx
);
361 EG_VTKDCC(vtkLongArray_t
, cell_index
, grid
, "cell_index");
362 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
363 cell_index
->SetValue(cellId
, cellId
);
367 axes
->SetInput(grid
);
375 for (vtkIdType nodeId
= 0; nodeId
< grid
->GetNumberOfPoints(); ++nodeId
) {
377 grid
->GetPoints()->GetPoint(nodeId
, x
.data());
378 xmin
= min(x
[0], xmin
);
379 xmax
= max(x
[0], xmax
);
380 ymin
= min(x
[1], ymin
);
381 ymax
= max(x
[1], ymax
);
382 zmin
= min(x
[2], zmin
);
383 zmax
= max(x
[2], zmax
);
387 getRenderer()->RemoveActor(surface_actor
);
388 surface_actor
->Delete();
389 surface_actor
= NULL
;
391 if (surface_wire_actor
) {
392 getRenderer()->RemoveActor(surface_wire_actor
);
393 surface_wire_actor
->Delete();
394 surface_wire_actor
= NULL
;
397 getRenderer()->RemoveActor(tetra_actor
);
398 tetra_actor
->Delete();
402 getRenderer()->RemoveActor(pyramid_actor
);
403 pyramid_actor
->Delete();
404 pyramid_actor
= NULL
;
407 getRenderer()->RemoveActor(wedge_actor
);
408 wedge_actor
->Delete();
412 getRenderer()->RemoveActor(hexa_actor
);
413 hexa_actor
->Delete();
416 if (volume_wire_actor
) {
417 getRenderer()->RemoveActor(volume_wire_actor
);
418 volume_wire_actor
->Delete();
419 volume_wire_actor
= NULL
;
422 getRenderer()->RemoveActor(pick_actor
);
423 pick_actor
->Delete();
426 if (iamlegend_actor
) {
427 getRenderer()->RemoveActor(iamlegend_actor
);
428 iamlegend_actor
->Delete();
429 iamlegend_actor
= NULL
;
436 field_mapper
->Delete();
440 if (ui
.checkBoxSurface
->isChecked()) {
441 bcodes_filter
->SetBoundaryCodes(&display_boundary_codes
);
443 bcodes_filter
->SetInput(grid
);
445 surface_filter
->SetInput(bcodes_filter
->GetOutput());
447 surface_filter
->Update();
449 boundary_pd
->DeepCopy(surface_filter
->GetOutput());
451 surface_mapper
->SetInput(boundary_pd
);
453 surface_wire_mapper
->SetInput(boundary_pd
);
454 surface_actor
= vtkActor::New();
455 surface_actor
->GetProperty()->SetRepresentationToSurface();
457 //Fill node field combobox
458 int current_field
=ui
.comboBox_Field
->currentIndex();
459 ui
.comboBox_Field
->clear();
460 ui
.comboBox_Field
->addItem("None");
461 int N_Arrays
=boundary_pd
->GetPointData()->GetNumberOfArrays();
462 // cout<<"N_Arrays="<<N_Arrays<<endl;
463 for (int i
=0; i
<N_Arrays
; i
++)
465 ui
.comboBox_Field
->addItem(boundary_pd
->GetPointData()->GetArrayName(i
));
467 if(current_field
==-1) ui
.comboBox_Field
->setCurrentIndex(0);
468 else ui
.comboBox_Field
->setCurrentIndex(current_field
);
470 //Fill cell field combobox
471 int current_cell_field
=ui
.comboBox_CellTextField
->currentIndex();
472 ui
.comboBox_CellTextField
->clear();
473 ui
.comboBox_CellTextField
->addItem("Cell ID");
474 int N_CellArrays
=boundary_pd
->GetCellData()->GetNumberOfArrays();
475 // cout<<"N_CellArrays="<<N_CellArrays<<endl;
476 for (int i
=0; i
<N_CellArrays
; i
++)
478 ui
.comboBox_CellTextField
->addItem(grid
->GetCellData()->GetArrayName(i
));
480 if(current_cell_field
==-1) ui
.comboBox_CellTextField
->setCurrentIndex(0);
481 else ui
.comboBox_CellTextField
->setCurrentIndex(current_cell_field
);
483 // cout<<"index="<<ui.comboBox_Field->currentIndex()<<endl;
484 // cout<<"name="<<ui.comboBox_Field->currentText().toLatin1().data()<<endl;
486 current_field
=ui
.comboBox_Field
->currentIndex();
490 boundary_pd
->GetPointData()->GetArray(current_field
-1)->GetRange(range
);
491 cout
<<"current_field="<<current_field
<<endl
;
492 cout
<<"range[0]="<<range
[0]<<endl
;
493 cout
<<"range[1]="<<range
[1]<<endl
;
494 ui
.doubleSpinBox_FieldMin
->setRange(range
[0],range
[1]);
495 ui
.doubleSpinBox_FieldMax
->setRange(range
[0],range
[1]);
498 if(ui
.comboBox_Field
->currentIndex()<=0) {
499 surface_actor
->SetBackfaceProperty(backface_property
);
500 surface_actor
->GetProperty()->SetColor(0.5,1,0.5);
501 surface_actor
->GetBackfaceProperty()->SetColor(1,1,0.5);
502 surface_actor
->SetMapper(surface_mapper
);
505 lut
=vtkLookupTable::New();
506 lut
->SetNumberOfColors(ui
.spinBox_Color
->value());
507 lut
->SetHueRange(ui
.doubleSpinBox_HueMin
->value(),ui
.doubleSpinBox_HueMax
->value());
509 field_mapper
=vtkPolyDataMapper::New();
510 field_mapper
->SetLookupTable(lut
);
511 field_mapper
->SetInput(boundary_pd
);
512 field_mapper
->SetColorModeToMapScalars();
513 field_mapper
->SetScalarModeToUsePointFieldData();
514 field_mapper
->ColorByArrayComponent(ui
.comboBox_Field
->currentText().toLatin1().data(),0);
515 field_mapper
->SetScalarRange(ui
.doubleSpinBox_FieldMin
->value(),ui
.doubleSpinBox_FieldMax
->value());
516 surface_actor
->SetMapper(field_mapper
);
518 if(ui
.checkBox_Legend
->checkState()) {
519 iamlegend_actor
= vtkScalarBarActor::New();
520 iamlegend_actor
->SetLookupTable (lut
);
521 getRenderer()->AddActor(iamlegend_actor
);
525 /* vtkDoubleArray *newScalars = vtkDoubleArray::New();
527 newScalars=(vtkDoubleArray *)boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
528 cout<<"index="<<index<<endl;*/
530 /* cout<<"=========="<<endl;
531 boundary_pd->GetPointData()->GetArray("node_status",index);
532 cout<<"index="<<index<<endl;
533 boundary_pd->GetPointData()->GetArray("node_layer",index);
534 cout<<"index="<<index<<endl;
535 boundary_pd->GetPointData()->GetArray("node_index",index);
536 cout<<"index="<<index<<endl;
537 boundary_pd->GetPointData()->GetArray("node_meshdensity",index);
538 cout<<"index="<<index<<endl;
539 boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
540 cout<<"index="<<index<<endl;
541 boundary_pd->GetPointData()->GetArray("node_type",index);
542 cout<<"index="<<index<<endl;
543 cout<<"=========="<<endl;*/
545 /* int N2=newScalars->GetNumberOfComponents();
546 int N3=newScalars->GetNumberOfTuples();
547 cout<<"Number of components=N2="<<N2<<endl;
548 cout<<"Number of tuples=N3="<<N3<<endl;*/
551 /* for (int i=0; i<N3; i++)
553 double D=newScalars->GetComponent(i,0);//strange, but works. O.o
554 cout<<"D["<<i<<"]="<<D<<endl;
557 surface_wire_actor
= vtkActor::New();
558 surface_wire_actor
->GetProperty()->SetRepresentationToWireframe();
559 surface_wire_actor
->GetProperty()->SetColor(0,0,1);
561 surface_wire_actor
->SetMapper(surface_wire_mapper
);
562 getRenderer()->AddActor(surface_actor
);
563 getRenderer()->AddActor(surface_wire_actor
);
564 bcodes_filter
->Update();
566 if(m_UseVTKInteractor
)
568 if(ui
.radioButton_CellPicker
->isChecked())
570 // CellPicker->Pick(0,0,0, getRenderer());
571 getInteractor()->SetPicker(CellPicker
);
572 // CellPicker->Pick(0,0,0, getRenderer());
573 vtkIdType cellId
= getPickedCell();
578 getInteractor()->SetPicker(PointPicker
);
579 vtkIdType nodeId
= getPickedPoint();
585 if(ui
.radioButton_CellPicker
->isChecked()) pickCell(PickedCell
);
586 else pickPoint(PickedPoint
);
588 /* getInteractor()->SetPicker(CellPicker);
589 vtkIdType cellId = getPickedCell();
591 getInteractor()->SetPicker(PointPicker);
592 vtkIdType nodeId = getPickedPoint();
598 x
[0] = ui
.lineEditClipX
->text().toDouble();
599 x
[1] = ui
.lineEditClipY
->text().toDouble();
600 x
[2] = ui
.lineEditClipZ
->text().toDouble();
601 n
[0] = ui
.lineEditClipNX
->text().toDouble();
602 n
[1] = ui
.lineEditClipNY
->text().toDouble();
603 n
[2] = ui
.lineEditClipNZ
->text().toDouble();
605 x
= x
+ ui
.lineEditOffset
->text().toDouble()*n
;
606 extr_vol
->SetAllOff();
607 if (ui
.checkBoxTetra
->isChecked()) {
608 extr_vol
->SetTetrasOn();
609 extr_tetras
->SetInput(grid
);
610 if (ui
.checkBoxClip
->isChecked()) {
611 extr_tetras
->SetClippingOn();
612 extr_tetras
->SetX(x
);
613 extr_tetras
->SetN(n
);
615 extr_tetras
->SetClippingOff();
617 tetra_actor
= vtkActor::New();
618 tetra_geometry
->SetInput(extr_tetras
->GetOutput());
619 tetra_geometry
->Update();
620 tetras_pd
->DeepCopy(tetra_geometry
->GetOutput());
621 tetra_mapper
->SetInput(tetras_pd
);
622 tetra_actor
= vtkActor::New();
623 tetra_actor
->SetMapper(tetra_mapper
);
624 tetra_actor
->GetProperty()->SetColor(1,0,0);
625 getRenderer()->AddActor(tetra_actor
);
627 if (ui
.checkBoxPyramid
->isChecked()) {
628 extr_vol
->SetPyramidsOn();
629 extr_pyramids
->SetInput(grid
);
630 if (ui
.checkBoxClip
->isChecked()) {
631 extr_pyramids
->SetClippingOn();
632 extr_pyramids
->SetX(x
);
633 extr_pyramids
->SetN(n
);
635 extr_pyramids
->SetClippingOff();
637 pyramid_actor
= vtkActor::New();
638 pyramid_geometry
->SetInput(extr_pyramids
->GetOutput());
639 pyramid_geometry
->Update();
640 pyras_pd
->DeepCopy(pyramid_geometry
->GetOutput());
641 pyramid_mapper
->SetInput(pyras_pd
);
642 pyramid_actor
= vtkActor::New();
643 pyramid_actor
->SetMapper(pyramid_mapper
);
644 pyramid_actor
->GetProperty()->SetColor(1,1,0);
645 getRenderer()->AddActor(pyramid_actor
);
647 if (ui
.checkBoxWedge
->isChecked()) {
648 extr_vol
->SetWedgesOn();
649 extr_wedges
->SetInput(grid
);
650 if (ui
.checkBoxClip
->isChecked()) {
651 extr_wedges
->SetClippingOn();
652 extr_wedges
->SetX(x
);
653 extr_wedges
->SetN(n
);
655 extr_wedges
->SetClippingOff();
657 wedge_actor
= vtkActor::New();
658 wedge_geometry
->SetInput(extr_wedges
->GetOutput());
659 wedge_geometry
->Update();
660 wedges_pd
->DeepCopy(wedge_geometry
->GetOutput());
661 wedge_mapper
->SetInput(wedges_pd
);
662 wedge_actor
= vtkActor::New();
663 wedge_actor
->SetMapper(wedge_mapper
);
664 wedge_actor
->GetProperty()->SetColor(0,1,0);
665 getRenderer()->AddActor(wedge_actor
);
667 if (ui
.checkBoxHexa
->isChecked()) {
668 extr_vol
->SetHexasOn();
669 extr_hexas
->SetInput(grid
);
670 if (ui
.checkBoxClip
->isChecked()) {
671 extr_hexas
->SetClippingOn();
675 extr_hexas
->SetClippingOff();
677 hexa_actor
= vtkActor::New();
678 hexa_geometry
->SetInput(extr_hexas
->GetOutput());
679 hexa_geometry
->Update();
680 hexas_pd
->DeepCopy(hexa_geometry
->GetOutput());
681 hexa_mapper
->SetInput(hexas_pd
);
682 hexa_actor
= vtkActor::New();
683 hexa_actor
->SetMapper(hexa_mapper
);
684 hexa_actor
->GetProperty()->SetColor(0,0.7,1);
685 getRenderer()->AddActor(hexa_actor
);
689 extr_vol
->SetInput(grid
);
690 if (ui
.checkBoxClip
->isChecked()) {
691 extr_vol
->SetClippingOn();
695 extr_vol
->SetClippingOff();
697 volume_wire_actor
= vtkActor::New();
698 volume_geometry
->SetInput(extr_vol
->GetOutput());
699 volume_geometry
->Update();
700 volume_pd
->DeepCopy(volume_geometry
->GetOutput());
701 volume_wire_mapper
->SetInput(volume_pd
);
702 volume_wire_actor
->SetMapper(volume_wire_mapper
);
703 volume_wire_actor
->GetProperty()->SetRepresentationToWireframe();
704 volume_wire_actor
->GetProperty()->SetColor(0,0,1);
705 getRenderer()->AddActor(volume_wire_actor
);
709 getRenderWindow()->Render();
710 } catch (Error err
) {
716 void GuiMainWindow::setPickMode(bool a_UseVTKInteractor
,bool a_CellPickerMode
)
718 m_UseVTKInteractor
=a_UseVTKInteractor
;
719 if(a_UseVTKInteractor
) ui
.checkBox_UseVTKInteractor
->setCheckState(Qt::Checked
);
720 else ui
.checkBox_UseVTKInteractor
->setCheckState(Qt::Unchecked
);
721 if(a_CellPickerMode
) ui
.radioButton_CellPicker
->toggle();
722 else ui
.radioButton_PointPicker
->toggle();
723 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
726 void GuiMainWindow::setUseVTKInteractor(int a_UseVTKInteractor
)
728 m_UseVTKInteractor
=a_UseVTKInteractor
;
729 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
732 bool GuiMainWindow::pickPoint(vtkIdType nodeId
)
734 if (nodeId
>= 0 && nodeId
<grid
->GetNumberOfPoints()) {
736 grid
->GetPoints()->GetPoint(nodeId
, x
.data());
737 pick_sphere
->SetCenter(x
.data());
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(0,0,1);
743 getRenderer()->AddActor(pick_actor
);
750 bool GuiMainWindow::pickCell(vtkIdType cellId
)
752 if (cellId
>= 0 && cellId
<grid
->GetNumberOfCells()) {
753 vtkIdType
*pts
, Npts
;
754 grid
->GetCellPoints(cellId
, Npts
, pts
);
756 for (vtkIdType i
= 0; i
< Npts
; ++i
) {
758 grid
->GetPoints()->GetPoint(pts
[i
], xp
.data());
759 x
+= double(1)/Npts
* xp
;
761 pick_sphere
->SetCenter(x
.data());
763 for (vtkIdType i
= 0; i
< Npts
; ++i
) {
765 grid
->GetPoints()->GetPoint(pts
[i
], xp
.data());
766 R
= min(R
, 0.25*(xp
-x
).abs());
768 ReferenceSize
=R
;//Used for text annotations too!
769 pick_sphere
->SetRadius(R
);
770 pick_mapper
->SetInput(pick_sphere
->GetOutput());
771 pick_actor
= vtkActor::New();
772 pick_actor
->SetMapper(pick_mapper
);
773 pick_actor
->GetProperty()->SetRepresentationToSurface();
774 pick_actor
->GetProperty()->SetColor(1,0,0);
775 getRenderer()->AddActor(pick_actor
);
782 void GuiMainWindow::importSTL()
786 updateBoundaryCodes(true);
792 void GuiMainWindow::importGmsh1Ascii()
797 updateBoundaryCodes(true);
803 void GuiMainWindow::exportGmsh1Ascii()
810 void GuiMainWindow::importGmsh2Ascii()
815 updateBoundaryCodes(true);
821 void GuiMainWindow::exportGmsh2Ascii()
828 void GuiMainWindow::exportNeutral()
830 NeutralWriter neutral
;
834 void GuiMainWindow::zoomAll()
836 getRenderer()->ResetCamera();
837 getRenderWindow()->Render();
840 void GuiMainWindow::open()
842 current_filename
= QFileDialog::getOpenFileName
845 "open grid from file",
847 "VTK unstructured grid files (*.vtu *.VTU)"
849 if (!current_filename
.isNull()) {
850 GuiMainWindow::setCwd(QFileInfo(current_filename
).absolutePath());
851 EG_VTKSP(vtkXMLUnstructuredGridReader
,vtu
);
852 vtu
->SetFileName(current_filename
.toAscii().data());
854 grid
->DeepCopy(vtu
->GetOutput());
855 createBasicFields(grid
, grid
->GetNumberOfCells(), grid
->GetNumberOfPoints(), false);
856 setWindowTitle(current_filename
+ " - enGrid");
858 updateBoundaryCodes(true);
865 void GuiMainWindow::undo()
869 void GuiMainWindow::redo()
873 void GuiMainWindow::openBC()
875 QString bc_file
= current_filename
+ ".bcs";
879 file
.open(QIODevice::ReadOnly
| QIODevice::Text
);
880 QTextStream
f(&file
);
884 f
>> i
>> name
>> type
;
885 bcmap
[i
] = BoundaryCondition(name
,type
);
890 void GuiMainWindow::saveBC()
892 QString bc_file
= current_filename
+ ".bcs";
894 file
.open(QIODevice::WriteOnly
| QIODevice::Text
);
895 QTextStream
f(&file
);
896 foreach(int i
, all_boundary_codes
) {
897 BoundaryCondition bc
= bcmap
[i
];
898 f
<< i
<< " " << bc
.getName() << " " << bc
.getType() << "\n";
902 void GuiMainWindow::save()
904 cout
<< current_filename
.toAscii().data() << endl
;
905 if (current_filename
== "untitled.vtu") {
908 EG_VTKDCC(vtkDoubleArray
, cell_VA
, grid
, "cell_VA");
909 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
910 cell_VA
->SetValue(cellId
, GeometryTools::cellVA(grid
, cellId
, true));
912 EG_VTKSP(vtkXMLUnstructuredGridWriter
,vtu
);
915 vtu
->SetFileName(current_filename
.toAscii().data());
916 vtu
->SetDataModeToBinary();
923 void GuiMainWindow::saveAs()
925 current_filename
= QFileDialog::getSaveFileName
928 "write grid to file",
930 "VTK unstructured grid files (*.vtu *.VTU)"
932 if (!current_filename
.isNull()) {
933 if (current_filename
.right(4) != ".vtu") {
934 if (current_filename
.right(4) != ".VTU") {
935 current_filename
+= ".vtu";
938 EG_VTKDCC(vtkDoubleArray
, cell_VA
, grid
, "cell_VA");
939 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
940 cell_VA
->SetValue(cellId
, GeometryTools::cellVA(grid
, cellId
, true));
942 GuiMainWindow::setCwd(QFileInfo(current_filename
).absolutePath());
943 EG_VTKSP(vtkXMLUnstructuredGridWriter
,vtu
);
946 vtu
->SetFileName(current_filename
.toAscii().data());
947 vtu
->SetDataModeToBinary();
951 setWindowTitle(current_filename
+ " - enGrid");
955 void GuiMainWindow::QuickSave(QString a_filename
)
957 cout
<< a_filename
.toAscii().data() << endl
;
959 EG_VTKDCC(vtkDoubleArray
, cell_VA
, grid
, "cell_VA");
960 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
961 cell_VA
->SetValue(cellId
, GeometryTools::cellVA(grid
, cellId
, true));
963 EG_VTKSP(vtkXMLUnstructuredGridWriter
,vtu
);
966 vtu
->SetFileName(a_filename
.toAscii().data());
967 vtu
->SetDataModeToBinary();
974 void GuiMainWindow::updateStatusBar()
976 QString num
, txt
= "enGrid is currently busy with an operation ...";
981 status_label
->setText(txt
);
984 vtkIdType Ncells
= grid
->GetNumberOfCells();
985 vtkIdType Nnodes
= grid
->GetNumberOfPoints();
987 vtkIdType Nquads
= 0;
989 vtkIdType Npyras
= 0;
990 vtkIdType Nprism
= 0;
991 vtkIdType Nhexas
= 0;
992 for (vtkIdType i
= 0; i
< Ncells
; ++i
) {
993 int ct
= grid
->GetCellType(i
);
994 if (ct
== VTK_TRIANGLE
) ++Ntris
;
995 else if (ct
== VTK_QUAD
) ++Nquads
;
996 else if (ct
== VTK_TETRA
) ++Ntets
;
997 else if (ct
== VTK_WEDGE
) ++Nprism
;
998 else if (ct
== VTK_PYRAMID
) ++Npyras
;
999 else if (ct
== VTK_HEXAHEDRON
) ++Nhexas
;
1001 num
.setNum(Ntets
+ Npyras
+ Nprism
+ Nhexas
); txt
+= num
+ " volume cells(";
1002 num
.setNum(Ntets
); txt
+= num
+ " tetras, ";
1003 num
.setNum(Npyras
); txt
+= num
+ " pyramids, ";
1004 num
.setNum(Nprism
); txt
+= num
+ " prisms, ";
1005 num
.setNum(Nhexas
); txt
+= num
+ " hexas), ";
1006 num
.setNum(Ntris
+ Nquads
); txt
+= num
+ " surface cells(";
1007 num
.setNum(Ntris
); txt
+= num
+ " triangles, ";
1008 num
.setNum(Nquads
); txt
+= num
+ " quads), ";
1009 num
.setNum(Nnodes
); txt
+= num
+ " nodes";
1011 if(ui
.radioButton_CellPicker
->isChecked())
1013 QString pick_txt
= ", picked cell: ";
1014 vtkIdType id_cell
= getPickedCell();
1016 pick_txt
+= "no cell picked";
1018 vtkIdType type_cell
= grid
->GetCellType(id_cell
);
1019 if (type_cell
== VTK_TRIANGLE
) pick_txt
+= "triangle";
1020 else if (type_cell
== VTK_QUAD
) pick_txt
+= "quad";
1021 else if (type_cell
== VTK_TETRA
) pick_txt
+= "tetrahedron";
1022 else if (type_cell
== VTK_PYRAMID
) pick_txt
+= "pyramid";
1023 else if (type_cell
== VTK_WEDGE
) pick_txt
+= "prism";
1024 else if (type_cell
== VTK_HEXAHEDRON
) pick_txt
+= "hexahedron";
1025 vtkIdType N_pts
, *pts
;
1026 grid
->GetCellPoints(id_cell
, N_pts
, pts
);
1028 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
1030 num
.setNum(pts
[i_pts
]);
1032 if (i_pts
< N_pts
-1) {
1038 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1039 tmp
.setNum(cell_code
->GetValue(id_cell
));
1040 pick_txt
+= " cell_code=" + tmp
;
1041 tmp
.setNum(id_cell
);
1042 pick_txt
+= " id_cell=" + tmp
;
1048 QString pick_txt
= ", picked node: ";
1049 vtkIdType id_node
= getPickedPoint();
1051 pick_txt
+= "no node picked";
1054 grid
->GetPoints()->GetPoint(id_node
,x
.data());
1056 for (int i
= 0; i
< 3; i
++) {
1066 EG_VTKDCN(vtkDoubleArray
, node_meshdensity
, grid
, "node_meshdensity");
1067 tmp
.setNum(node_meshdensity
->GetValue(id_node
));
1068 pick_txt
+= " wanted density=" + tmp
;
1069 EG_VTKDCN(vtkDoubleArray
, node_meshdensity_current
, grid
, "node_meshdensity_current");
1070 tmp
.setNum(node_meshdensity_current
->GetValue(id_node
));
1071 pick_txt
+= " current density=" + tmp
;
1072 EG_VTKDCN(vtkIntArray
, node_specified_density
, grid
, "node_specified_density");
1073 tmp
.setNum(node_specified_density
->GetValue(id_node
));
1074 pick_txt
+= " node_specified_density=" + tmp
;
1075 EG_VTKDCN(vtkCharArray
, node_type
, grid
, "node_type");
1076 pick_txt
+= " type=" + QString(VertexType2Str( node_type
->GetValue(id_node
)));
1077 tmp
.setNum(id_node
);
1078 pick_txt
+= " id_node=" + tmp
;
1084 status_label
->setText(txt
);
1088 void GuiMainWindow::selectBoundaryCodes()
1090 GuiSelectBoundaryCodes bcodes
;
1091 bcodes
.setDisplayBoundaryCodes(display_boundary_codes
);
1092 bcodes
.setBoundaryCodes(all_boundary_codes
);
1094 bcodes
.getThread().wait();
1095 bcodes
.getSelectedBoundaryCodes(display_boundary_codes
);
1099 void GuiMainWindow::updateBoundaryCodes(bool all_on
)
1102 all_boundary_codes
.clear();
1103 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
1104 for (vtkIdType i
= 0; i
< grid
->GetNumberOfCells(); ++i
) {
1105 int ct
= grid
->GetCellType(i
);
1106 if ((ct
== VTK_TRIANGLE
) || (ct
== VTK_QUAD
)) {
1107 all_boundary_codes
.insert(cell_code
->GetValue(i
));
1111 display_boundary_codes
.clear();
1112 foreach (int bc
, all_boundary_codes
) {
1113 display_boundary_codes
.insert(bc
);
1117 foreach (int bc
, display_boundary_codes
) {
1118 if (all_boundary_codes
.contains(bc
)) {
1122 display_boundary_codes
.clear();
1123 foreach (int bc
, all_boundary_codes
) {
1124 if (dbcs
.contains(bc
)) {
1125 display_boundary_codes
.insert(bc
);
1129 } catch (Error err
) {
1134 void GuiMainWindow::normalExtrusion()
1136 GuiNormalExtrusion extr
;
1138 updateBoundaryCodes(false);
1142 void GuiMainWindow::setAxesVisibility()
1144 if (ui
.actionViewAxes
->isChecked()) axes
->SetVisibility(1);
1145 else axes
->SetVisibility(0);
1146 getRenderWindow()->Render();
1149 void GuiMainWindow::setViewingMode()
1151 if (ui
.actionViewOrthogonal
->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1152 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1153 getRenderWindow()->Render();
1156 void GuiMainWindow::ViewNodeIDs()
1158 int N
=grid
->GetNumberOfPoints();
1159 cout
<<"N="<<N
<<endl
;
1160 if (ui
.actionViewNodeIDs
->isChecked()) {
1161 cout
<<"Activating node ID view"<<endl
;
1162 NodeText_VectorText
.resize(N
);
1163 NodeText_PolyDataMapper
.resize(N
);
1164 NodeText_Follower
.resize(N
);
1165 for(int i
=0;i
<N
;i
++){
1166 NodeText_VectorText
[i
]=vtkVectorText::New();
1169 NodeText_VectorText
[i
]->SetText(tmp
.toLatin1().data());
1170 NodeText_PolyDataMapper
[i
]=vtkPolyDataMapper::New();
1171 NodeText_PolyDataMapper
[i
]->SetInputConnection(NodeText_VectorText
[i
]->GetOutputPort());
1172 NodeText_Follower
[i
]=vtkFollower::New();
1173 NodeText_Follower
[i
]->SetMapper(NodeText_PolyDataMapper
[i
]);
1174 NodeText_Follower
[i
]->SetScale(ReferenceSize
,ReferenceSize
,ReferenceSize
);
1176 grid
->GetPoint(i
,M
.data());
1178 vec3_t OffSet
=ReferenceSize
*tmp_M
.normalise();
1180 NodeText_Follower
[i
]->AddPosition(M
[0],M
[1],M
[2]);
1181 NodeText_Follower
[i
]->SetCamera(getRenderer()->GetActiveCamera());
1182 NodeText_Follower
[i
]->GetProperty()->SetColor(0,0,1);
1183 getRenderer()->AddActor(NodeText_Follower
[i
]);
1187 cout
<<"Deactivating node ID view"<<endl
;
1188 for(unsigned int i
=0;i
<NodeText_Follower
.size();i
++){
1189 getRenderer()->RemoveActor(NodeText_Follower
[i
]);
1190 NodeText_Follower
[i
]->Delete();
1191 NodeText_PolyDataMapper
[i
]->Delete();
1192 NodeText_VectorText
[i
]->Delete();
1194 NodeText_Follower
.clear();
1195 NodeText_PolyDataMapper
.clear();
1196 NodeText_VectorText
.clear();
1199 getRenderWindow()->Render();
1202 void GuiMainWindow::ViewCellIDs()
1204 vtkIdType N
=grid
->GetNumberOfCells();
1205 cout
<<"N="<<N
<<endl
;
1206 if (ui
.actionViewCellIDs
->isChecked()) {
1207 cout
<<"Activating cell ID view"<<endl
;
1208 CellText_VectorText
.resize(N
);
1209 CellText_PolyDataMapper
.resize(N
);
1210 CellText_Follower
.resize(N
);
1211 for(vtkIdType id_cell
=0;id_cell
<N
;id_cell
++){
1212 CellText_VectorText
[id_cell
]=vtkVectorText::New();
1216 if(ui
.comboBox_CellTextField
->currentIndex()==0) {
1217 tmp
.setNum(id_cell
);
1219 else if(ui
.comboBox_CellTextField
->currentIndex()>0) {
1220 EG_VTKDCC(vtkIntArray
, current_cell_field
, grid
, ui
.comboBox_CellTextField
->currentText().toLatin1().data());
1221 tmp
.setNum(current_cell_field
->GetValue(id_cell
));
1225 CellText_VectorText
[id_cell
]->SetText(tmp
.toLatin1().data());
1226 CellText_PolyDataMapper
[id_cell
]=vtkPolyDataMapper::New();
1227 CellText_PolyDataMapper
[id_cell
]->SetInputConnection(CellText_VectorText
[id_cell
]->GetOutputPort());
1228 CellText_Follower
[id_cell
]=vtkFollower::New();
1229 CellText_Follower
[id_cell
]->SetMapper(CellText_PolyDataMapper
[id_cell
]);
1230 CellText_Follower
[id_cell
]->SetScale(ReferenceSize
,ReferenceSize
,ReferenceSize
);
1231 vtkIdType N_pts
,*pts
;
1232 grid
->GetCellPoints(id_cell
,N_pts
,pts
);
1233 vec3_t
Center(0,0,0);
1234 for(int p
=0;p
<N_pts
;p
++)
1237 grid
->GetPoint(pts
[p
],M
.data());
1240 vec3_t OffSet
=ReferenceSize
*triNormal(grid
,pts
[0],pts
[1],pts
[2]).normalise();
1241 Center
=1.0/(double)N_pts
*Center
+OffSet
;
1242 CellText_Follower
[id_cell
]->AddPosition(Center
[0],Center
[1],Center
[2]);
1243 CellText_Follower
[id_cell
]->SetCamera(getRenderer()->GetActiveCamera());
1244 CellText_Follower
[id_cell
]->GetProperty()->SetColor(1,0,0);
1245 getRenderer()->AddActor(CellText_Follower
[id_cell
]);
1249 cout
<<"Deactivating cell ID view"<<endl
;
1250 for(vtkIdType id_cell
=0;id_cell
<CellText_Follower
.size();id_cell
++){
1251 getRenderer()->RemoveActor(CellText_Follower
[id_cell
]);
1252 CellText_Follower
[id_cell
]->Delete();
1253 CellText_PolyDataMapper
[id_cell
]->Delete();
1254 CellText_VectorText
[id_cell
]->Delete();
1256 CellText_Follower
.clear();
1257 CellText_PolyDataMapper
.clear();
1258 CellText_VectorText
.clear();
1261 getRenderWindow()->Render();
1264 void GuiMainWindow::addVtkTypeInfo()
1266 EG_VTKSP(vtkIntArray
, vtk_type
);
1267 vtk_type
->SetName("vtk_type");
1268 vtk_type
->SetNumberOfValues(grid
->GetNumberOfCells());
1269 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
1270 vtk_type
->SetValue(cellId
, grid
->GetCellType(cellId
));
1272 grid
->GetCellData()->AddArray(vtk_type
);
1275 void GuiMainWindow::pickCellCallBack
1278 unsigned long int eid
,
1285 clientdata
= clientdata
;
1286 calldata
= calldata
;
1287 THIS
->updateActors();
1288 THIS
->updateStatusBar();
1289 cout
<<"pickCellCallBack"<<endl
;
1292 void GuiMainWindow::pickPointCallBack
1295 unsigned long int eid
,
1302 clientdata
= clientdata
;
1303 calldata
= calldata
;
1304 THIS
->updateActors();
1305 THIS
->updateStatusBar();
1306 cout
<<"pickPointCallBack"<<endl
;
1309 vtkIdType
GuiMainWindow::getPickedCell()
1311 vtkIdType picked_cell
= -1;
1312 if (THIS
->grid
->GetNumberOfCells() > 0) {
1313 THIS
->bcodes_filter
->Update();
1314 EG_VTKDCC(vtkLongArray_t
, cell_index
, THIS
->bcodes_filter
->GetOutput(), "cell_index");
1317 if(m_UseVTKInteractor
) cellId
= THIS
->CellPicker
->GetCellId();
1318 else cellId
= PickedCell
;
1321 if (cellId
< THIS
->bcodes_filter
->GetOutput()->GetNumberOfCells()) {
1322 picked_cell
= cell_index
->GetValue(cellId
);
1329 vtkIdType
GuiMainWindow::getPickedPoint()
1331 vtkIdType picked_point
= -1;
1332 if (THIS
->grid
->GetNumberOfCells() > 0) {
1333 THIS
->bcodes_filter
->Update();
1336 if(m_UseVTKInteractor
) pointId
= THIS
->PointPicker
->GetPointId();
1337 else pointId
= PickedPoint
;
1340 picked_point
= pointId
;
1343 return picked_point
;
1346 void GuiMainWindow::changeSurfaceOrientation()
1348 for (vtkIdType cellId
= 0; cellId
< grid
->GetNumberOfCells(); ++cellId
) {
1349 vtkIdType Npts
, *pts
;
1350 grid
->GetCellPoints(cellId
, Npts
, pts
);
1351 QVector
<vtkIdType
> nodes(Npts
);
1352 for (vtkIdType j
= 0; j
< Npts
; ++j
) nodes
[j
] = pts
[j
];
1353 for (vtkIdType j
= 0; j
< Npts
; ++j
) pts
[Npts
- j
- 1] = nodes
[j
];
1358 void GuiMainWindow::checkSurfaceOrientation()
1360 CorrectSurfaceOrientation corr_surf
;
1361 vtkIdType picked_cell
= getPickedCell();
1362 if (picked_cell
>= 0) {
1363 corr_surf
.setStart(picked_cell
);
1369 void GuiMainWindow::improveAspectRatio()
1371 GuiImproveAspectRatio impr_ar
;
1376 void GuiMainWindow::exportAsciiStl()
1382 void GuiMainWindow::exportBinaryStl()
1386 void GuiMainWindow::periodicUpdate()
1388 Operation::collectGarbage();
1392 void GuiMainWindow::viewXP()
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::viewXM()
1407 getRenderer()->ResetCamera();
1409 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1411 getRenderer()->GetActiveCamera()->SetPosition(x
);
1412 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1413 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1414 getRenderer()->ResetCamera();
1415 getRenderWindow()->Render();
1418 void GuiMainWindow::viewYP()
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::viewYM()
1433 getRenderer()->ResetCamera();
1435 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1437 getRenderer()->GetActiveCamera()->SetPosition(x
);
1438 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1439 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1440 getRenderer()->ResetCamera();
1441 getRenderWindow()->Render();
1444 void GuiMainWindow::viewZP()
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::viewZM()
1459 getRenderer()->ResetCamera();
1461 getRenderer()->GetActiveCamera()->GetFocalPoint(x
);
1463 getRenderer()->GetActiveCamera()->SetPosition(x
);
1464 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1465 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1466 getRenderer()->ResetCamera();
1467 getRenderWindow()->Render();
1470 void GuiMainWindow::callFixSTL()
1476 updateBoundaryCodes(false);
1480 void GuiMainWindow::editBoundaryConditions()
1482 GuiEditBoundaryConditions editbcs
;
1483 editbcs
.setBoundaryCodes(all_boundary_codes
);
1484 editbcs
.setMap(&bcmap
);
1488 void GuiMainWindow::configure()
1491 // Just to create initial entries in the settings file
1492 // so that the options menu isn't empty at first start.
1494 GuiCreateBoundaryLayer tmp02
;
1496 GuiSettingsViewer
settings(&qset
);
1500 void GuiMainWindow::about()
1502 QMessageBox
box(this);
1504 QString title
="ENGRID";
1505 QString version
= QString("version ") + ENGRID_VERSION
;
1506 if (version
== "version CVS") {
1507 version
+= " build on ";
1508 version
+= QString(__DATE__
);
1510 version
+= QString(__TIME__
);
1512 QString address
= tr("ENGRID is being developed and maintained by:<br/>"
1514 "Marie-Curie-Strasse 8<br/>"
1515 "79539 Loerrach<br/>"
1518 QString mainurl
="<a href=\"http://www.engits.com\">www.engits.com</a>";
1519 QString mail
="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1520 QString gnuurl
="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1521 QString license
=tr("ENGRID is licenced under the GPL version 3.<br/>"
1522 "(see ")+gnuurl
+tr(" for details)<br/>");
1523 QString bugurl
="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1524 QString bugreporting
=tr("To submit a bug report, please use ")+bugurl
;
1525 box
.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1529 "<p>Homepage: %4</p>"
1532 "<p>%7</p></center>")
1533 .arg(title
).arg(version
).arg(address
).arg(mainurl
).arg(mail
).arg(license
).arg(bugreporting
));
1534 box
.setWindowTitle(tr("about ENGRID"));
1535 box
.setIcon(QMessageBox::NoIcon
);
1540 void GuiMainWindow::getAllBoundaryCodes(QSet
<int> &bcs
)
1543 foreach (int bc
, all_boundary_codes
) {