added deselect all button
[engrid.git] / src / guimainwindow.cpp
blob09c2b9de5c5c74bf55728c8e4246f9e456d380d0
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"
63 #include "egvtkinteractorstyle.h"
65 // GuiOutputWindow::GuiOutputWindow()
66 // {
67 // ui.setupUi(this);
68 // };
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)
80 ui.setupUi(this);
81 THIS = this;
83 QPoint pos = qset.value("pos", QPoint(200, 200)).toPoint();
84 QSize size = qset.value("size", QSize(400, 400)).toSize();
85 resize(size);
86 move(pos);
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.actionZoomOnPickedObject, SIGNAL(activated()), this, SLOT(ZoomOnPickedObject()));
106 connect(ui.actionDeselectAll, SIGNAL(activated()), this, SLOT(DeselectAll()));
107 connect(ui.actionOpen, SIGNAL(activated()), this, SLOT(open()));
108 connect(ui.actionSave, SIGNAL(activated()), this, SLOT(save()));
109 connect(ui.actionSaveAs, SIGNAL(activated()), this, SLOT(saveAs()));
110 connect(ui.actionBoundaryCodes, SIGNAL(activated()), this, SLOT(selectBoundaryCodes()));
111 connect(ui.actionNormalExtrusion, SIGNAL(activated()), this, SLOT(normalExtrusion()));
112 connect(ui.actionViewAxes, SIGNAL(changed()), this, SLOT(setAxesVisibility()));
113 connect(ui.actionViewOrthogonal, SIGNAL(changed()), this, SLOT(setViewingMode()));
114 connect(ui.actionViewNodeIDs, SIGNAL(changed()), this, SLOT(ViewNodeIDs()));
115 connect(ui.actionViewCellIDs, SIGNAL(changed()), this, SLOT(ViewCellIDs()));
116 connect(ui.actionChangeOrientation, SIGNAL(activated()), this, SLOT(changeSurfaceOrientation()));
117 connect(ui.actionCheckOrientation, SIGNAL(activated()), this, SLOT(checkSurfaceOrientation()));
118 connect(ui.actionImproveAspectRatio, SIGNAL(activated()), this, SLOT(improveAspectRatio()));
119 connect(ui.actionRedraw, SIGNAL(activated()), this, SLOT(updateActors()));
120 connect(ui.actionScaleToData, SIGNAL(activated()), this, SLOT(ScaleToData()));
121 connect(ui.actionClearOutputWindow, SIGNAL(activated()), this, SLOT(clearOutput()));
122 connect(ui.actionEditBoundaryConditions, SIGNAL(activated()), this, SLOT(editBoundaryConditions()));
123 connect(ui.actionConfigure, SIGNAL(activated()), this, SLOT(configure()));
124 connect(ui.actionAbout, SIGNAL(activated()), this, SLOT(about()));
126 connect(ui.checkBox_UseVTKInteractor, SIGNAL(stateChanged(int)), this, SLOT(setUseVTKInteractor(int)));
128 connect(ui.actionViewXP, SIGNAL(activated()), this, SLOT(viewXP()));
129 connect(ui.actionViewXM, SIGNAL(activated()), this, SLOT(viewXM()));
130 connect(ui.actionViewYP, SIGNAL(activated()), this, SLOT(viewYP()));
131 connect(ui.actionViewYM, SIGNAL(activated()), this, SLOT(viewYM()));
132 connect(ui.actionViewZP, SIGNAL(activated()), this, SLOT(viewZP()));
133 connect(ui.actionViewZM, SIGNAL(activated()), this, SLOT(viewZM()));
136 #include "std_connections.h"
138 if (qset.contains("working_directory")) {
139 cwd = qset.value("working_directory").toString();
141 grid = vtkUnstructuredGrid::New();
142 renderer = vtkRenderer::New();
143 getRenderWindow()->AddRenderer(renderer);
144 surface_actor = vtkActor::New();
145 surface_wire_actor = vtkActor::New();
147 tetra_mapper = vtkPolyDataMapper::New();
148 pyramid_mapper = vtkPolyDataMapper::New();
149 wedge_mapper = vtkPolyDataMapper::New();
150 hexa_mapper = vtkPolyDataMapper::New();
151 volume_wire_mapper = vtkPolyDataMapper::New();
152 surface_mapper = vtkPolyDataMapper::New();
153 surface_wire_mapper = vtkPolyDataMapper::New();
155 backface_property = vtkProperty::New();
157 tetra_actor = NULL;
158 pyramid_actor = NULL;
159 wedge_actor = NULL;
160 hexa_actor = NULL;
161 volume_wire_actor = NULL;
162 iamlegend_actor = NULL;
163 lut = NULL;
164 field_mapper = NULL;
166 surface_filter = vtkGeometryFilter::New();
167 bcodes_filter = vtkEgBoundaryCodesFilter::New();
168 renderer->AddActor(surface_actor);
169 renderer->AddActor(surface_wire_actor);
170 pick_sphere = vtkSphereSource::New();
171 pick_mapper = vtkPolyDataMapper::New();
172 pick_actor = NULL;
174 extr_vol = vtkEgExtractVolumeCells::New();
175 extr_tetras = vtkEgExtractVolumeCells::New();
176 extr_pyramids = vtkEgExtractVolumeCells::New();
177 extr_wedges = vtkEgExtractVolumeCells::New();
178 extr_hexas = vtkEgExtractVolumeCells::New();
180 volume_geometry = vtkGeometryFilter::New();
181 tetra_geometry = vtkGeometryFilter::New();
182 pyramid_geometry = vtkGeometryFilter::New();
183 wedge_geometry = vtkGeometryFilter::New();
184 hexa_geometry = vtkGeometryFilter::New();
186 extr_tetras->SetAllOff();
187 extr_tetras->SetTetrasOn();
188 extr_pyramids->SetAllOff();
189 extr_pyramids->SetPyramidsOn();
190 extr_wedges->SetAllOff();
191 extr_wedges->SetWedgesOn();
192 extr_hexas->SetAllOff();
193 extr_hexas->SetHexasOn();
195 boundary_pd = vtkPolyData::New();
196 tetras_pd = vtkPolyData::New();
197 wedges_pd = vtkPolyData::New();
198 pyras_pd = vtkPolyData::New();
199 hexas_pd = vtkPolyData::New();
200 volume_pd = vtkPolyData::New();
202 current_filename = "untitled.vtu";
203 ResetOperationCounter();//clears undo/redo list and disables undo/redo
204 setWindowTitle(current_filename + " - enGrid - " + QString("%1").arg(current_operation) );
206 status_bar = new QStatusBar(this);
207 setStatusBar(status_bar);
208 status_label = new QLabel(this);
209 status_bar->addWidget(status_label);
210 QString txt = "0 volume cells (0 tetras, 0 hexas, 0 pyramids, 0 prisms), ";
211 txt += "0 surface cells (0 triangles, 0 quads), 0 nodes";
212 status_label->setText(txt);
214 axes = vtkCubeAxesActor2D::New();
215 axes->SetCamera(getRenderer()->GetActiveCamera());
216 getRenderer()->AddActor(axes);
217 setAxesVisibility();
219 CellPicker = vtkCellPicker::New();
220 // getInteractor()->SetPicker(CellPicker);
221 PointPicker = vtkPointPicker::New();
222 // getInteractor()->SetPicker(PointPicker);
224 pick_sphere->SetRadius(0.25);//in case the user starts picking points instead of cells
226 vtkCallbackCommand *cbc = vtkCallbackCommand::New();
227 cbc->SetCallback(pickCellCallBack);
228 CellPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
229 cbc->SetCallback(pickPointCallBack);
230 PointPicker->AddObserver(vtkCommand::EndPickEvent, cbc);
231 cbc->Delete();
233 QString user = QString(getenv("USER"));
234 QString basename="enGrid_output.txt";
236 // define temporary path
237 QDir dir("/");
238 if (qset.contains("tmp_directory")) {
239 m_tmpdir=qset.value("tmp_directory").toString();
240 } else {
241 m_tmpdir=dir.tempPath();
243 m_tmpdir = m_tmpdir + "/" + "enGrid_"+user + "/";
244 dir.mkpath(m_tmpdir);
246 log_file_name = m_tmpdir + basename;
247 cout<<"log_file_name="<<log_file_name.toLatin1().data()<<endl;
249 system_stdout = stdout;
250 freopen (log_file_name.toAscii().data(), "w", stdout);
252 busy = false;
253 updateStatusBar();
255 connect(&garbage_timer, SIGNAL(timeout()), this, SLOT(periodicUpdate()));
256 garbage_timer.start(1000);
258 connect(&log_timer, SIGNAL(timeout()), this, SLOT(updateOutput()));
259 log_timer.start(1000);
261 N_chars = 0;
263 bool exp_features;
264 // getSet("","enable experimental features",false,exp_features);
265 bool undo_redo;
266 getSet("","enable undo/redo",false,undo_redo);
267 bool undo_redo_mode;
268 getSet("","use RAM for undo/redo oprations",false,undo_redo_mode);
270 ui.actionFoamWriter->setEnabled(exp_features);
272 ReferenceSize=0.2;
274 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
275 // ui.radioButton_CellPicker->setChecked(true);
276 setPickMode(true,true);
277 PickedPoint=-1;
278 PickedCell=-1;
280 ui.doubleSpinBox_HueMin->setValue(0.667);
281 ui.doubleSpinBox_HueMax->setValue(0);
283 egvtkInteractorStyle *style = egvtkInteractorStyle::New();
284 getInteractor()->SetInteractorStyle(style);
285 style->Delete();
287 //end of GuiMainWindow::GuiMainWindow() : QMainWindow(NULL)
289 GuiMainWindow::~GuiMainWindow()
291 qset.setValue("pos", pos());
292 qset.setValue("size", size());
295 void GuiMainWindow::updateOutput()
297 QFile log_file(log_file_name);
298 log_file.open(QIODevice::ReadOnly);
299 QByteArray buffer = log_file.readAll();
300 if (buffer.size() > N_chars) {
301 QByteArray newchars = buffer.right(buffer.size() - N_chars);
302 N_chars = buffer.size();
303 QString txt(newchars);
304 if (txt.right(1) == "\n") {
305 txt = txt.left(txt.size()-1);
307 ui.textEditOutput->append(txt);
311 void GuiMainWindow::exit()
313 QCoreApplication::exit();
316 vtkRenderWindow* GuiMainWindow::getRenderWindow()
318 return ui.qvtkWidget->GetRenderWindow();
321 vtkRenderer* GuiMainWindow::getRenderer()
323 return renderer;
326 QVTKInteractor* GuiMainWindow::getInteractor()
328 return ui.qvtkWidget->GetInteractor();
331 QString GuiMainWindow::getCwd()
333 return cwd;
336 void GuiMainWindow::setCwd(QString dir)
338 cwd = dir;
339 qset.setValue("working_directory",dir);
342 void GuiMainWindow::ScaleToData()
344 int current_field=ui.comboBox_Field->currentIndex();
345 if(current_field>0)
347 double range[2];
348 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
349 cout<<"current_field="<<current_field<<endl;
350 cout<<"range[0]="<<range[0]<<endl;
351 cout<<"range[1]="<<range[1]<<endl;
352 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
353 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
354 ui.doubleSpinBox_FieldMin->setValue(range[0]);
355 ui.doubleSpinBox_FieldMax->setValue(range[1]);
359 void GuiMainWindow::updateActors()
361 if (!tryLock()) return;
362 try {
365 if (!grid->GetCellData()->GetScalars("cell_index")) {
366 EG_VTKSP(vtkLongArray_t, cell_idx);
367 cell_idx->SetName("cell_index");
368 cell_idx->SetNumberOfValues(grid->GetNumberOfCells());
369 grid->GetCellData()->AddArray(cell_idx);
372 EG_VTKDCC(vtkLongArray_t, cell_index, grid, "cell_index");
373 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
374 cell_index->SetValue(cellId, cellId);
378 axes->SetInput(grid);
380 double xmin = 1e99;
381 double xmax = -1e99;
382 double ymin = 1e99;
383 double ymax = -1e99;
384 double zmin = 1e99;
385 double zmax = -1e99;
386 for (vtkIdType nodeId = 0; nodeId < grid->GetNumberOfPoints(); ++nodeId) {
387 vec3_t x;
388 grid->GetPoints()->GetPoint(nodeId, x.data());
389 xmin = min(x[0], xmin);
390 xmax = max(x[0], xmax);
391 ymin = min(x[1], ymin);
392 ymax = max(x[1], ymax);
393 zmin = min(x[2], zmin);
394 zmax = max(x[2], zmax);
397 if (surface_actor) {
398 getRenderer()->RemoveActor(surface_actor);
399 surface_actor->Delete();
400 surface_actor = NULL;
402 if (surface_wire_actor) {
403 getRenderer()->RemoveActor(surface_wire_actor);
404 surface_wire_actor->Delete();
405 surface_wire_actor = NULL;
407 if (tetra_actor) {
408 getRenderer()->RemoveActor(tetra_actor);
409 tetra_actor->Delete();
410 tetra_actor = NULL;
412 if (pyramid_actor) {
413 getRenderer()->RemoveActor(pyramid_actor);
414 pyramid_actor->Delete();
415 pyramid_actor = NULL;
417 if (wedge_actor) {
418 getRenderer()->RemoveActor(wedge_actor);
419 wedge_actor->Delete();
420 wedge_actor = NULL;
422 if (hexa_actor) {
423 getRenderer()->RemoveActor(hexa_actor);
424 hexa_actor->Delete();
425 hexa_actor = NULL;
427 if (volume_wire_actor) {
428 getRenderer()->RemoveActor(volume_wire_actor);
429 volume_wire_actor->Delete();
430 volume_wire_actor = NULL;
432 if (pick_actor) {
433 getRenderer()->RemoveActor(pick_actor);
434 pick_actor->Delete();
435 pick_actor = NULL;
437 if (iamlegend_actor) {
438 getRenderer()->RemoveActor(iamlegend_actor);
439 iamlegend_actor->Delete();
440 iamlegend_actor = NULL;
442 if (lut) {
443 lut->Delete();
444 lut = NULL;
446 if (field_mapper) {
447 field_mapper->Delete();
448 field_mapper = NULL;
451 if (ui.checkBoxSurface->isChecked()) {
452 bcodes_filter->SetBoundaryCodes(&display_boundary_codes);
454 bcodes_filter->SetInput(grid);
456 surface_filter->SetInput(bcodes_filter->GetOutput());
458 surface_filter->Update();
460 boundary_pd->DeepCopy(surface_filter->GetOutput());
462 surface_mapper->SetInput(boundary_pd);
464 surface_wire_mapper->SetInput(boundary_pd);
465 surface_actor = vtkActor::New();
466 surface_actor->GetProperty()->SetRepresentationToSurface();
468 //Fill node field combobox
469 int current_field=ui.comboBox_Field->currentIndex();
470 ui.comboBox_Field->clear();
471 ui.comboBox_Field->addItem("None");
472 int N_Arrays=boundary_pd->GetPointData()->GetNumberOfArrays();
473 // cout<<"N_Arrays="<<N_Arrays<<endl;
474 for (int i=0; i<N_Arrays; i++)
476 ui.comboBox_Field->addItem(boundary_pd->GetPointData()->GetArrayName(i));
478 if(current_field==-1) ui.comboBox_Field->setCurrentIndex(0);
479 else ui.comboBox_Field->setCurrentIndex(current_field);
481 //Fill cell field combobox
482 int current_cell_field=ui.comboBox_CellTextField->currentIndex();
483 ui.comboBox_CellTextField->clear();
484 ui.comboBox_CellTextField->addItem("Cell ID");
485 int N_CellArrays=boundary_pd->GetCellData()->GetNumberOfArrays();
486 // cout<<"N_CellArrays="<<N_CellArrays<<endl;
487 for (int i=0; i<N_CellArrays; i++)
489 ui.comboBox_CellTextField->addItem(grid->GetCellData()->GetArrayName(i));
491 if(current_cell_field==-1) ui.comboBox_CellTextField->setCurrentIndex(0);
492 else ui.comboBox_CellTextField->setCurrentIndex(current_cell_field);
494 // cout<<"index="<<ui.comboBox_Field->currentIndex()<<endl;
495 // cout<<"name="<<ui.comboBox_Field->currentText().toLatin1().data()<<endl;
497 current_field=ui.comboBox_Field->currentIndex();
498 if(current_field>0)
500 double range[2];
501 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
502 cout<<"current_field="<<current_field<<endl;
503 cout<<"range[0]="<<range[0]<<endl;
504 cout<<"range[1]="<<range[1]<<endl;
505 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
506 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
509 if(ui.comboBox_Field->currentIndex()<=0) {
510 surface_actor->SetBackfaceProperty(backface_property);
511 surface_actor->GetProperty()->SetColor(0.5,1,0.5);
512 surface_actor->GetBackfaceProperty()->SetColor(1,1,0.5);
513 surface_actor->SetMapper(surface_mapper);
515 else {
516 lut=vtkLookupTable::New();
517 lut->SetNumberOfColors(ui.spinBox_Color->value());
518 lut->SetHueRange(ui.doubleSpinBox_HueMin->value(),ui.doubleSpinBox_HueMax->value());
519 lut->Build();
520 field_mapper=vtkPolyDataMapper::New();
521 field_mapper->SetLookupTable(lut);
522 field_mapper->SetInput(boundary_pd);
523 field_mapper->SetColorModeToMapScalars();
524 field_mapper->SetScalarModeToUsePointFieldData();
525 field_mapper->ColorByArrayComponent(ui.comboBox_Field->currentText().toLatin1().data(),0);
526 field_mapper->SetScalarRange(ui.doubleSpinBox_FieldMin->value(),ui.doubleSpinBox_FieldMax->value());
527 surface_actor->SetMapper(field_mapper);
529 if(ui.checkBox_Legend->checkState()) {
530 iamlegend_actor = vtkScalarBarActor::New();
531 iamlegend_actor->SetLookupTable (lut);
532 getRenderer()->AddActor(iamlegend_actor);
536 /* vtkDoubleArray *newScalars = vtkDoubleArray::New();
537 int index;
538 newScalars=(vtkDoubleArray *)boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
539 cout<<"index="<<index<<endl;*/
541 /* cout<<"=========="<<endl;
542 boundary_pd->GetPointData()->GetArray("node_status",index);
543 cout<<"index="<<index<<endl;
544 boundary_pd->GetPointData()->GetArray("node_layer",index);
545 cout<<"index="<<index<<endl;
546 boundary_pd->GetPointData()->GetArray("node_index",index);
547 cout<<"index="<<index<<endl;
548 boundary_pd->GetPointData()->GetArray("node_meshdensity",index);
549 cout<<"index="<<index<<endl;
550 boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
551 cout<<"index="<<index<<endl;
552 boundary_pd->GetPointData()->GetArray("node_type",index);
553 cout<<"index="<<index<<endl;
554 cout<<"=========="<<endl;*/
556 /* int N2=newScalars->GetNumberOfComponents();
557 int N3=newScalars->GetNumberOfTuples();
558 cout<<"Number of components=N2="<<N2<<endl;
559 cout<<"Number of tuples=N3="<<N3<<endl;*/
562 /* for (int i=0; i<N3; i++)
564 double D=newScalars->GetComponent(i,0);//strange, but works. O.o
565 cout<<"D["<<i<<"]="<<D<<endl;
568 surface_wire_actor = vtkActor::New();
569 surface_wire_actor->GetProperty()->SetRepresentationToWireframe();
570 surface_wire_actor->GetProperty()->SetColor(0,0,1);
572 surface_wire_actor->SetMapper(surface_wire_mapper);
573 getRenderer()->AddActor(surface_actor);
574 getRenderer()->AddActor(surface_wire_actor);
575 bcodes_filter->Update();
577 if(m_UseVTKInteractor)
579 if(ui.radioButton_CellPicker->isChecked())
581 // CellPicker->Pick(0,0,0, getRenderer());
582 getInteractor()->SetPicker(CellPicker);
583 // CellPicker->Pick(0,0,0, getRenderer());
584 vtkIdType cellId = getPickedCell();
585 pickCell(cellId);
587 else
589 getInteractor()->SetPicker(PointPicker);
590 vtkIdType nodeId = getPickedPoint();
591 pickPoint(nodeId);
594 else
596 if(ui.radioButton_CellPicker->isChecked()) pickCell(PickedCell);
597 else pickPoint(PickedPoint);
599 /* getInteractor()->SetPicker(CellPicker);
600 vtkIdType cellId = getPickedCell();
601 pickCell(cellId);
602 getInteractor()->SetPicker(PointPicker);
603 vtkIdType nodeId = getPickedPoint();
604 pickPoint(nodeId);*/
608 vec3_t x, n;
609 x[0] = ui.lineEditClipX->text().toDouble();
610 x[1] = ui.lineEditClipY->text().toDouble();
611 x[2] = ui.lineEditClipZ->text().toDouble();
612 n[0] = ui.lineEditClipNX->text().toDouble();
613 n[1] = ui.lineEditClipNY->text().toDouble();
614 n[2] = ui.lineEditClipNZ->text().toDouble();
615 n.normalise();
616 x = x + ui.lineEditOffset->text().toDouble()*n;
617 extr_vol->SetAllOff();
618 if (ui.checkBoxTetra->isChecked()) {
619 extr_vol->SetTetrasOn();
620 extr_tetras->SetInput(grid);
621 if (ui.checkBoxClip->isChecked()) {
622 extr_tetras->SetClippingOn();
623 extr_tetras->SetX(x);
624 extr_tetras->SetN(n);
625 } else {
626 extr_tetras->SetClippingOff();
628 tetra_actor = vtkActor::New();
629 tetra_geometry->SetInput(extr_tetras->GetOutput());
630 tetra_geometry->Update();
631 tetras_pd->DeepCopy(tetra_geometry->GetOutput());
632 tetra_mapper->SetInput(tetras_pd);
633 tetra_actor = vtkActor::New();
634 tetra_actor->SetMapper(tetra_mapper);
635 tetra_actor->GetProperty()->SetColor(1,0,0);
636 getRenderer()->AddActor(tetra_actor);
638 if (ui.checkBoxPyramid->isChecked()) {
639 extr_vol->SetPyramidsOn();
640 extr_pyramids->SetInput(grid);
641 if (ui.checkBoxClip->isChecked()) {
642 extr_pyramids->SetClippingOn();
643 extr_pyramids->SetX(x);
644 extr_pyramids->SetN(n);
645 } else {
646 extr_pyramids->SetClippingOff();
648 pyramid_actor = vtkActor::New();
649 pyramid_geometry->SetInput(extr_pyramids->GetOutput());
650 pyramid_geometry->Update();
651 pyras_pd->DeepCopy(pyramid_geometry->GetOutput());
652 pyramid_mapper->SetInput(pyras_pd);
653 pyramid_actor = vtkActor::New();
654 pyramid_actor->SetMapper(pyramid_mapper);
655 pyramid_actor->GetProperty()->SetColor(1,1,0);
656 getRenderer()->AddActor(pyramid_actor);
658 if (ui.checkBoxWedge->isChecked()) {
659 extr_vol->SetWedgesOn();
660 extr_wedges->SetInput(grid);
661 if (ui.checkBoxClip->isChecked()) {
662 extr_wedges->SetClippingOn();
663 extr_wedges->SetX(x);
664 extr_wedges->SetN(n);
665 } else {
666 extr_wedges->SetClippingOff();
668 wedge_actor = vtkActor::New();
669 wedge_geometry->SetInput(extr_wedges->GetOutput());
670 wedge_geometry->Update();
671 wedges_pd->DeepCopy(wedge_geometry->GetOutput());
672 wedge_mapper->SetInput(wedges_pd);
673 wedge_actor = vtkActor::New();
674 wedge_actor->SetMapper(wedge_mapper);
675 wedge_actor->GetProperty()->SetColor(0,1,0);
676 getRenderer()->AddActor(wedge_actor);
678 if (ui.checkBoxHexa->isChecked()) {
679 extr_vol->SetHexasOn();
680 extr_hexas->SetInput(grid);
681 if (ui.checkBoxClip->isChecked()) {
682 extr_hexas->SetClippingOn();
683 extr_hexas->SetX(x);
684 extr_hexas->SetN(n);
685 } else {
686 extr_hexas->SetClippingOff();
688 hexa_actor = vtkActor::New();
689 hexa_geometry->SetInput(extr_hexas->GetOutput());
690 hexa_geometry->Update();
691 hexas_pd->DeepCopy(hexa_geometry->GetOutput());
692 hexa_mapper->SetInput(hexas_pd);
693 hexa_actor = vtkActor::New();
694 hexa_actor->SetMapper(hexa_mapper);
695 hexa_actor->GetProperty()->SetColor(0,0.7,1);
696 getRenderer()->AddActor(hexa_actor);
699 // wireframe
700 extr_vol->SetInput(grid);
701 if (ui.checkBoxClip->isChecked()) {
702 extr_vol->SetClippingOn();
703 extr_vol->SetX(x);
704 extr_vol->SetN(n);
705 } else {
706 extr_vol->SetClippingOff();
708 volume_wire_actor = vtkActor::New();
709 volume_geometry->SetInput(extr_vol->GetOutput());
710 volume_geometry->Update();
711 volume_pd->DeepCopy(volume_geometry->GetOutput());
712 volume_wire_mapper->SetInput(volume_pd);
713 volume_wire_actor->SetMapper(volume_wire_mapper);
714 volume_wire_actor->GetProperty()->SetRepresentationToWireframe();
715 volume_wire_actor->GetProperty()->SetColor(0,0,1);
716 getRenderer()->AddActor(volume_wire_actor);
719 updateStatusBar();
720 getRenderWindow()->Render();
721 } catch (Error err) {
722 err.display();
724 unlock();
727 void GuiMainWindow::setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode)
729 m_UseVTKInteractor=a_UseVTKInteractor;
730 if(a_UseVTKInteractor) ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
731 else ui.checkBox_UseVTKInteractor->setCheckState(Qt::Unchecked);
732 if(a_CellPickerMode) ui.radioButton_CellPicker->toggle();
733 else ui.radioButton_PointPicker->toggle();
734 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
737 void GuiMainWindow::setUseVTKInteractor(int a_UseVTKInteractor)
739 m_UseVTKInteractor=a_UseVTKInteractor;
740 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
743 bool GuiMainWindow::pickPoint(vtkIdType nodeId)
745 cout<<"pickPoint called with =nodeId"<<nodeId<<endl;
746 if (nodeId >= 0 && nodeId<grid->GetNumberOfPoints()) {
747 vec3_t x(0,0,0);
748 grid->GetPoints()->GetPoint(nodeId, x.data());
749 pick_sphere->SetCenter(x.data());
750 pick_mapper->SetInput(pick_sphere->GetOutput());
751 pick_actor = vtkActor::New();
752 pick_actor->SetMapper(pick_mapper);
753 pick_actor->GetProperty()->SetRepresentationToSurface();
754 pick_actor->GetProperty()->SetColor(0,0,1);
755 getRenderer()->AddActor(pick_actor);
756 PickedPoint=nodeId;
757 return(true);
759 else return(false);
762 bool GuiMainWindow::pickCell(vtkIdType cellId)
764 cout<<"pickCell called with cellId="<<cellId<<endl;
765 if (cellId >= 0 && cellId<grid->GetNumberOfCells()) {
766 vtkIdType *pts, Npts;
767 grid->GetCellPoints(cellId, Npts, pts);
768 vec3_t x(0,0,0);
769 for (vtkIdType i = 0; i < Npts; ++i) {
770 vec3_t xp;
771 grid->GetPoints()->GetPoint(pts[i], xp.data());
772 x += double(1)/Npts * xp;
774 pick_sphere->SetCenter(x.data());
775 double R = 1e99;
776 // for (vtkIdType i = 0; i < Npts; ++i) {
777 // vec3_t xp;
778 // grid->GetPoints()->GetPoint(pts[i], xp.data());
779 // R = min(R, 0.25*(xp-x).abs());
780 // };
781 for (vtkIdType i = 0; i < Npts; ++i) {
782 vec3_t xp;
783 grid->GetPoints()->GetPoint(pts[i], xp.data());
784 R = min(R, 0.25*(xp-x).abs());
786 // R=getShortestSide(cellId,grid);
787 ReferenceSize=R;//Used for text annotations too!
788 pick_sphere->SetRadius(R);
789 pick_mapper->SetInput(pick_sphere->GetOutput());
790 pick_actor = vtkActor::New();
791 pick_actor->SetMapper(pick_mapper);
792 pick_actor->GetProperty()->SetRepresentationToSurface();
793 pick_actor->GetProperty()->SetColor(1,0,0);
794 getRenderer()->AddActor(pick_actor);
795 PickedCell=cellId;
796 return(true);
798 else return(false);
801 void GuiMainWindow::importSTL()
803 StlReader stl;
804 stl();
805 updateBoundaryCodes(true);
806 updateActors();
807 updateStatusBar();
808 zoomAll();
811 void GuiMainWindow::importGmsh1Ascii()
813 GmshReader gmsh;
814 gmsh.setV1Ascii();
815 gmsh();
816 updateBoundaryCodes(true);
817 updateActors();
818 updateStatusBar();
819 zoomAll();
822 void GuiMainWindow::exportGmsh1Ascii()
824 GmshWriter gmsh;
825 gmsh.setV1Ascii();
826 gmsh();
829 void GuiMainWindow::importGmsh2Ascii()
831 GmshReader gmsh;
832 gmsh.setV2Ascii();
833 gmsh();
834 updateBoundaryCodes(true);
835 updateActors();
836 updateStatusBar();
837 zoomAll();
840 void GuiMainWindow::exportGmsh2Ascii()
842 GmshWriter gmsh;
843 gmsh.setV2Ascii();
844 gmsh();
847 void GuiMainWindow::exportNeutral()
849 NeutralWriter neutral;
850 neutral();
853 void GuiMainWindow::zoomAll()
855 getRenderer()->ResetCamera();
856 getRenderWindow()->Render();
859 void GuiMainWindow::ZoomOnPickedObject()
861 if(pick_actor!=NULL)
863 getRenderer()->ResetCamera(pick_actor->GetBounds());
864 getRenderWindow()->Render();
868 void GuiMainWindow::DeselectAll()
870 cout<<"void GuiMainWindow::DeselectAll()"<<endl;
871 // goo;
872 setPickMode(false,true);
873 PickedCell=-1;
874 PickedPoint=-1;
875 updateActors();
878 void GuiMainWindow::QuickSave()
880 current_operation++;
881 QFileInfo fileinfo(current_filename);
882 QString l_filename = m_tmpdir + fileinfo.completeBaseName() + "_" + QString("%1").arg(current_operation);
883 last_operation=current_operation;
884 cout<<"Operation "<<current_operation<<endl;//" : Saving as l_filename="<<l_filename.toLatin1().data()<<endl;
885 QuickSave(l_filename);
886 setWindowTitle(current_filename + " - enGrid - " + QString("%1").arg(current_operation) );
887 if(current_operation>0) ui.actionUndo->setEnabled(true);
888 ui.actionRedo->setEnabled(false);
891 void GuiMainWindow::QuickLoad(int a_operation)
893 QFileInfo fileinfo(current_filename);
894 QString l_filename = m_tmpdir + fileinfo.completeBaseName() + "_" + QString("%1").arg(a_operation) + ".vtu";
895 // cout<<"Loading l_filename="<<l_filename.toLatin1().data()<<endl;
896 QuickLoad(l_filename);
897 setWindowTitle(current_filename + " - enGrid - " + QString("%1").arg(current_operation) );
900 void GuiMainWindow::Undo()
902 cout << "Undoing operation " << current_operation << endl;
903 current_operation--;
904 QuickLoad(current_operation);
905 ui.actionRedo->setEnabled(true);
906 if(current_operation<=0) ui.actionUndo->setEnabled(false);
909 void GuiMainWindow::Redo()
911 current_operation++;
912 cout << "Redoing operation " << current_operation << endl;
913 QuickLoad(current_operation);
914 ui.actionUndo->setEnabled(true);
915 if(current_operation>=last_operation) ui.actionRedo->setEnabled(false);
918 void GuiMainWindow::ResetOperationCounter()
920 current_operation=-1;
921 last_operation=current_operation;
922 ui.actionUndo->setEnabled(false);
923 ui.actionRedo->setEnabled(false);
926 void GuiMainWindow::openBC()
928 openBC(current_filename);
931 void GuiMainWindow::saveBC()
933 saveBC(current_filename);
936 void GuiMainWindow::openBC(QString a_file)
938 QString bc_file = a_file + ".bcs";
939 QFile file(bc_file);
940 bcmap.clear();
941 if (file.exists()) {
942 file.open(QIODevice::ReadOnly | QIODevice::Text);
943 QTextStream f(&file);
944 while (!f.atEnd()) {
945 QString name, type;
946 int i;
947 f >> i >> name >> type;
948 bcmap[i] = BoundaryCondition(name,type);
953 void GuiMainWindow::saveBC(QString a_file)
955 QString bc_file = a_file + ".bcs";
956 QFile file(bc_file);
957 file.open(QIODevice::WriteOnly | QIODevice::Text);
958 QTextStream f(&file);
959 foreach(int i, all_boundary_codes) {
960 BoundaryCondition bc = bcmap[i];
961 f << i << " " << bc.getName() << " " << bc.getType() << "\n";
965 //TODO: I think this should also be a done by a subclass of IOOperation just like for import operations
966 void GuiMainWindow::open()
968 current_filename = QFileDialog::getOpenFileName
970 NULL,
971 "open grid from file",
972 getCwd(),
973 "VTK unstructured grid files (*.vtu *.VTU)"
975 if (!current_filename.isNull()) {
976 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
977 EG_VTKSP(vtkXMLUnstructuredGridReader,vtu);
978 vtu->SetFileName(current_filename.toAscii().data());
979 vtu->Update();
980 grid->DeepCopy(vtu->GetOutput());
981 createBasicFields(grid, grid->GetNumberOfCells(), grid->GetNumberOfPoints(), false);
982 setWindowTitle(current_filename + " - enGrid - " + QString("%1").arg(current_operation) );
983 openBC();
984 updateBoundaryCodes(true);
985 updateActors();
986 updateStatusBar();
987 zoomAll();
988 ResetOperationCounter();
989 QuickSave();
993 void GuiMainWindow::save()
995 cout << current_filename.toAscii().data() << endl;
996 if (current_filename == "untitled.vtu") {
997 saveAs();
998 } else {
999 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
1000 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1001 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
1003 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
1004 addVtkTypeInfo();
1005 createIndices(grid);
1006 vtu->SetFileName(current_filename.toAscii().data());
1007 vtu->SetDataModeToBinary();
1008 vtu->SetInput(grid);
1009 vtu->Write();
1010 saveBC();
1014 void GuiMainWindow::saveAs()
1016 current_filename = QFileDialog::getSaveFileName
1018 NULL,
1019 "write grid to file",
1020 getCwd(),
1021 "VTK unstructured grid files (*.vtu *.VTU)"
1023 if (!current_filename.isNull()) {
1024 if (current_filename.right(4) != ".vtu") {
1025 if (current_filename.right(4) != ".VTU") {
1026 current_filename += ".vtu";
1029 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
1030 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1031 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
1033 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
1034 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
1035 addVtkTypeInfo();
1036 createIndices(grid);
1037 vtu->SetFileName(current_filename.toAscii().data());
1038 vtu->SetDataModeToBinary();
1039 vtu->SetInput(grid);
1040 vtu->Write();
1041 saveBC();
1042 //for the undo/redo operations
1043 setWindowTitle(current_filename + " - enGrid - " + QString("%1").arg(current_operation) );
1044 ResetOperationCounter();
1045 QuickSave();
1049 void GuiMainWindow::QuickSave(QString a_filename)
1051 QFileInfo fileinfo(a_filename);
1052 cout<<"a_filename="<<a_filename.toLatin1().data()<<endl;
1053 cout<<"fileinfo.suffix()="<<fileinfo.suffix().toLatin1().data()<<endl;
1054 if(fileinfo.suffix()!="vtu") a_filename=a_filename + ".vtu";
1056 cout << "Saving as " << a_filename.toAscii().data() << endl;
1058 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
1059 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1060 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
1062 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
1063 addVtkTypeInfo();
1064 createIndices(grid);
1065 vtu->SetFileName(a_filename.toAscii().data());
1066 vtu->SetDataModeToBinary();
1067 vtu->SetInput(grid);
1068 vtu->Write();
1069 saveBC(a_filename);
1072 void GuiMainWindow::QuickLoad(QString a_filename)
1074 cout << "Loading " << a_filename.toAscii().data() << endl;
1076 if (!a_filename.isNull()) {
1077 // GuiMainWindow::setCwd(QFileInfo(a_filename).absolutePath());
1078 EG_VTKSP(vtkXMLUnstructuredGridReader,vtu);
1079 vtu->SetFileName(a_filename.toAscii().data());
1080 vtu->Update();
1081 grid->DeepCopy(vtu->GetOutput());
1082 createBasicFields(grid, grid->GetNumberOfCells(), grid->GetNumberOfPoints(), false);
1083 setWindowTitle(a_filename + " - enGrid - " + QString("%1").arg(current_operation) );
1084 openBC(a_filename);
1085 updateBoundaryCodes(true);
1086 updateActors();
1087 updateStatusBar();
1088 zoomAll();
1093 void GuiMainWindow::updateStatusBar()
1095 QString num, txt = "enGrid is currently busy with an operation ...";
1096 if (!busy) {
1097 txt = "";
1099 if (!tryLock()) {
1100 status_label->setText(txt);
1101 return;
1103 vtkIdType Ncells = grid->GetNumberOfCells();
1104 vtkIdType Nnodes = grid->GetNumberOfPoints();
1105 vtkIdType Ntris = 0;
1106 vtkIdType Nquads = 0;
1107 vtkIdType Ntets = 0;
1108 vtkIdType Npyras = 0;
1109 vtkIdType Nprism = 0;
1110 vtkIdType Nhexas = 0;
1111 for (vtkIdType i = 0; i < Ncells; ++i) {
1112 int ct = grid->GetCellType(i);
1113 if (ct == VTK_TRIANGLE) ++Ntris;
1114 else if (ct == VTK_QUAD) ++Nquads;
1115 else if (ct == VTK_TETRA) ++Ntets;
1116 else if (ct == VTK_WEDGE) ++Nprism;
1117 else if (ct == VTK_PYRAMID) ++Npyras;
1118 else if (ct == VTK_HEXAHEDRON) ++Nhexas;
1120 num.setNum(Ntets + Npyras + Nprism + Nhexas); txt += num + " volume cells(";
1121 num.setNum(Ntets); txt += num + " tetras, ";
1122 num.setNum(Npyras); txt += num + " pyramids, ";
1123 num.setNum(Nprism); txt += num + " prisms, ";
1124 num.setNum(Nhexas); txt += num + " hexas), ";
1125 num.setNum(Ntris + Nquads); txt += num + " surface cells(";
1126 num.setNum(Ntris); txt += num + " triangles, ";
1127 num.setNum(Nquads); txt += num + " quads), ";
1128 num.setNum(Nnodes); txt += num + " nodes";
1130 if(ui.radioButton_CellPicker->isChecked())
1132 QString pick_txt = ", picked cell: ";
1133 vtkIdType id_cell = getPickedCell();
1134 if (id_cell < 0) {
1135 pick_txt += "no cell picked";
1136 } else {
1137 vtkIdType type_cell = grid->GetCellType(id_cell);
1138 if (type_cell == VTK_TRIANGLE) pick_txt += "triangle";
1139 else if (type_cell == VTK_QUAD) pick_txt += "quad";
1140 else if (type_cell == VTK_TETRA) pick_txt += "tetrahedron";
1141 else if (type_cell == VTK_PYRAMID) pick_txt += "pyramid";
1142 else if (type_cell == VTK_WEDGE) pick_txt += "prism";
1143 else if (type_cell == VTK_HEXAHEDRON) pick_txt += "hexahedron";
1144 vtkIdType N_pts, *pts;
1145 grid->GetCellPoints(id_cell, N_pts, pts);
1146 pick_txt += " [";
1147 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
1148 QString num;
1149 num.setNum(pts[i_pts]);
1150 pick_txt += num;
1151 if (i_pts < N_pts-1) {
1152 pick_txt += ",";
1155 pick_txt += "]";
1156 QString tmp;
1157 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1158 tmp.setNum(cell_code->GetValue(id_cell));
1159 pick_txt += " cell_code=" + tmp;
1160 tmp.setNum(id_cell);
1161 pick_txt += " id_cell=" + tmp;
1163 txt += pick_txt;
1165 else
1167 QString pick_txt = ", picked node: ";
1168 vtkIdType id_node = getPickedPoint();
1169 if (id_node < 0) {
1170 pick_txt += "no node picked";
1171 } else {
1172 vec3_t x;
1173 grid->GetPoints()->GetPoint(id_node,x.data());
1174 pick_txt += " [";
1175 for (int i = 0; i < 3; i++) {
1176 QString num;
1177 num.setNum(x[i]);
1178 pick_txt += num;
1179 if (i < 2) {
1180 pick_txt += ",";
1183 pick_txt += "]";
1184 QString tmp;
1185 EG_VTKDCN(vtkDoubleArray, node_meshdensity, grid, "node_meshdensity");
1186 tmp.setNum(node_meshdensity->GetValue(id_node));
1187 pick_txt += " wanted density=" + tmp;
1188 EG_VTKDCN(vtkDoubleArray, node_meshdensity_current, grid, "node_meshdensity_current");
1189 tmp.setNum(node_meshdensity_current->GetValue(id_node));
1190 pick_txt += " current density=" + tmp;
1191 EG_VTKDCN(vtkIntArray, node_specified_density, grid, "node_specified_density");
1192 tmp.setNum(node_specified_density->GetValue(id_node));
1193 pick_txt += " node_specified_density=" + tmp;
1194 EG_VTKDCN(vtkCharArray, node_type, grid, "node_type");
1195 pick_txt += " type=" + QString(VertexType2Str( node_type->GetValue(id_node)));
1196 tmp.setNum(id_node);
1197 pick_txt += " id_node=" + tmp;
1200 txt += pick_txt;
1203 status_label->setText(txt);
1204 unlock();
1207 void GuiMainWindow::selectBoundaryCodes()
1209 GuiSelectBoundaryCodes bcodes;
1210 bcodes.setDisplayBoundaryCodes(display_boundary_codes);
1211 cout<<"void GuiMainWindow::selectBoundaryCodes(): all_boundary_codes="<<all_boundary_codes<<endl;
1213 bcodes.setBoundaryCodes(all_boundary_codes);
1214 bcodes();
1215 bcodes.getThread().wait();
1216 bcodes.getSelectedBoundaryCodes(display_boundary_codes);
1217 updateActors();
1220 void GuiMainWindow::updateBoundaryCodes(bool all_on)
1222 cout<<"void GuiMainWindow::updateBoundaryCodes(bool all_on)"<<endl;
1223 try {
1224 all_boundary_codes.clear();
1225 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1226 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
1227 int ct = grid->GetCellType(i);
1228 if ((ct == VTK_TRIANGLE) || (ct == VTK_QUAD)) {
1229 all_boundary_codes.insert(cell_code->GetValue(i));
1232 if (all_on) {
1233 display_boundary_codes.clear();
1234 foreach (int bc, all_boundary_codes) {
1235 display_boundary_codes.insert(bc);
1237 } else {
1238 QSet<int> dbcs;
1239 foreach (int bc, display_boundary_codes) {
1240 if (all_boundary_codes.contains(bc)) {
1241 dbcs.insert(bc);
1244 display_boundary_codes.clear();
1245 foreach (int bc, all_boundary_codes) {
1246 if (dbcs.contains(bc)) {
1247 display_boundary_codes.insert(bc);
1251 } catch (Error err) {
1252 err.display();
1254 cout<<"void GuiMainWindow::updateBoundaryCodes(bool all_on): all_boundary_codes="<<all_boundary_codes<<endl;
1257 void GuiMainWindow::normalExtrusion()
1259 GuiNormalExtrusion extr;
1260 extr();
1261 updateBoundaryCodes(false);
1262 updateActors();
1265 void GuiMainWindow::setAxesVisibility()
1267 if (ui.actionViewAxes->isChecked()) axes->SetVisibility(1);
1268 else axes->SetVisibility(0);
1269 getRenderWindow()->Render();
1272 void GuiMainWindow::setViewingMode()
1274 if (ui.actionViewOrthogonal->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1275 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1276 getRenderWindow()->Render();
1279 void GuiMainWindow::ViewNodeIDs()
1281 int N=grid->GetNumberOfPoints();
1282 cout<<"N="<<N<<endl;
1283 if (ui.actionViewNodeIDs->isChecked()) {
1284 cout<<"Activating node ID view"<<endl;
1285 NodeText_VectorText.resize(N);
1286 NodeText_PolyDataMapper.resize(N);
1287 NodeText_Follower.resize(N);
1288 for(int i=0;i<N;i++){
1289 NodeText_VectorText[i]=vtkVectorText::New();
1290 QString tmp;
1291 tmp.setNum(i);
1292 NodeText_VectorText[i]->SetText(tmp.toLatin1().data());
1293 NodeText_PolyDataMapper[i]=vtkPolyDataMapper::New();
1294 NodeText_PolyDataMapper[i]->SetInputConnection(NodeText_VectorText[i]->GetOutputPort());
1295 NodeText_Follower[i]=vtkFollower::New();
1296 NodeText_Follower[i]->SetMapper(NodeText_PolyDataMapper[i]);
1297 NodeText_Follower[i]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1298 vec3_t M;
1299 grid->GetPoint(i,M.data());
1300 vec3_t tmp_M=M;
1301 vec3_t OffSet=ReferenceSize*tmp_M.normalise();
1302 M=M+OffSet;
1303 NodeText_Follower[i]->AddPosition(M[0],M[1],M[2]);
1304 NodeText_Follower[i]->SetCamera(getRenderer()->GetActiveCamera());
1305 NodeText_Follower[i]->GetProperty()->SetColor(0,0,1);
1306 getRenderer()->AddActor(NodeText_Follower[i]);
1309 else {
1310 cout<<"Deactivating node ID view"<<endl;
1311 for(unsigned int i=0;i<NodeText_Follower.size();i++){
1312 getRenderer()->RemoveActor(NodeText_Follower[i]);
1313 NodeText_Follower[i]->Delete();
1314 NodeText_PolyDataMapper[i]->Delete();
1315 NodeText_VectorText[i]->Delete();
1317 NodeText_Follower.clear();
1318 NodeText_PolyDataMapper.clear();
1319 NodeText_VectorText.clear();
1322 getRenderWindow()->Render();
1325 void GuiMainWindow::ViewCellIDs()
1327 vtkIdType N=grid->GetNumberOfCells();
1328 cout<<"N="<<N<<endl;
1329 if (ui.actionViewCellIDs->isChecked()) {
1330 cout<<"Activating cell ID view"<<endl;
1331 CellText_VectorText.resize(N);
1332 CellText_PolyDataMapper.resize(N);
1333 CellText_Follower.resize(N);
1334 for(vtkIdType id_cell=0;id_cell<N;id_cell++){
1335 CellText_VectorText[id_cell]=vtkVectorText::New();
1337 QString tmp;
1339 if(ui.comboBox_CellTextField->currentIndex()==0) {
1340 tmp.setNum(id_cell);
1342 else if(ui.comboBox_CellTextField->currentIndex()>0) {
1343 EG_VTKDCC(vtkIntArray, current_cell_field, grid, ui.comboBox_CellTextField->currentText().toLatin1().data());
1344 tmp.setNum(current_cell_field->GetValue(id_cell));
1346 else EG_BUG;
1348 CellText_VectorText[id_cell]->SetText(tmp.toLatin1().data());
1349 CellText_PolyDataMapper[id_cell]=vtkPolyDataMapper::New();
1350 CellText_PolyDataMapper[id_cell]->SetInputConnection(CellText_VectorText[id_cell]->GetOutputPort());
1351 CellText_Follower[id_cell]=vtkFollower::New();
1352 CellText_Follower[id_cell]->SetMapper(CellText_PolyDataMapper[id_cell]);
1353 CellText_Follower[id_cell]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1354 vtkIdType N_pts,*pts;
1355 grid->GetCellPoints(id_cell,N_pts,pts);
1356 vec3_t Center(0,0,0);
1357 for(int p=0;p<N_pts;p++)
1359 vec3_t M;
1360 grid->GetPoint(pts[p],M.data());
1361 Center+=M.data();
1363 vec3_t OffSet=ReferenceSize*triNormal(grid,pts[0],pts[1],pts[2]).normalise();
1364 Center=1.0/(double)N_pts*Center+OffSet;
1365 CellText_Follower[id_cell]->AddPosition(Center[0],Center[1],Center[2]);
1366 CellText_Follower[id_cell]->SetCamera(getRenderer()->GetActiveCamera());
1367 CellText_Follower[id_cell]->GetProperty()->SetColor(1,0,0);
1368 getRenderer()->AddActor(CellText_Follower[id_cell]);
1371 else {
1372 cout<<"Deactivating cell ID view"<<endl;
1373 for(vtkIdType id_cell=0;id_cell<CellText_Follower.size();id_cell++){
1374 getRenderer()->RemoveActor(CellText_Follower[id_cell]);
1375 CellText_Follower[id_cell]->Delete();
1376 CellText_PolyDataMapper[id_cell]->Delete();
1377 CellText_VectorText[id_cell]->Delete();
1379 CellText_Follower.clear();
1380 CellText_PolyDataMapper.clear();
1381 CellText_VectorText.clear();
1384 getRenderWindow()->Render();
1387 void GuiMainWindow::addVtkTypeInfo()
1389 EG_VTKSP(vtkIntArray, vtk_type);
1390 vtk_type->SetName("vtk_type");
1391 vtk_type->SetNumberOfValues(grid->GetNumberOfCells());
1392 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1393 vtk_type->SetValue(cellId, grid->GetCellType(cellId));
1395 grid->GetCellData()->AddArray(vtk_type);
1398 void GuiMainWindow::pickCellCallBack
1400 vtkObject *caller,
1401 unsigned long int eid,
1402 void *clientdata,
1403 void *calldata
1406 caller = caller;
1407 eid = eid;
1408 clientdata = clientdata;
1409 calldata = calldata;
1410 THIS->updateActors();
1411 THIS->updateStatusBar();
1412 cout<<"pickCellCallBack"<<endl;
1415 void GuiMainWindow::pickPointCallBack
1417 vtkObject *caller,
1418 unsigned long int eid,
1419 void *clientdata,
1420 void *calldata
1423 caller = caller;
1424 eid = eid;
1425 clientdata = clientdata;
1426 calldata = calldata;
1427 THIS->updateActors();
1428 THIS->updateStatusBar();
1429 cout<<"pickPointCallBack"<<endl;
1432 vtkIdType GuiMainWindow::getPickedCell()
1434 vtkIdType picked_cell = -1;
1435 if (THIS->grid->GetNumberOfCells() > 0) {
1436 THIS->bcodes_filter->Update();
1437 EG_VTKDCC(vtkLongArray_t, cell_index, THIS->bcodes_filter->GetOutput(), "cell_index");
1439 vtkIdType cellId;
1440 if(m_UseVTKInteractor) cellId = THIS->CellPicker->GetCellId();
1441 else cellId = PickedCell;
1443 if (cellId >= 0) {
1444 if (cellId < THIS->bcodes_filter->GetOutput()->GetNumberOfCells()) {
1445 picked_cell = cell_index->GetValue(cellId);
1449 return picked_cell;
1452 vtkIdType GuiMainWindow::getPickedPoint()
1454 vtkIdType picked_point = -1;
1455 if (THIS->grid->GetNumberOfCells() > 0) {
1456 THIS->bcodes_filter->Update();
1458 vtkIdType pointId;
1459 if(m_UseVTKInteractor) pointId = THIS->PointPicker->GetPointId();
1460 else pointId = PickedPoint;
1462 if (pointId >= 0) {
1463 picked_point = pointId;
1466 return picked_point;
1469 void GuiMainWindow::changeSurfaceOrientation()
1471 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1472 vtkIdType Npts, *pts;
1473 grid->GetCellPoints(cellId, Npts, pts);
1474 QVector<vtkIdType> nodes(Npts);
1475 for (vtkIdType j = 0; j < Npts; ++j) nodes[j] = pts[j];
1476 for (vtkIdType j = 0; j < Npts; ++j) pts[Npts - j - 1] = nodes[j];
1478 updateActors();
1481 void GuiMainWindow::checkSurfaceOrientation()
1483 CorrectSurfaceOrientation corr_surf;
1484 vtkIdType picked_cell = getPickedCell();
1485 if (picked_cell >= 0) {
1486 corr_surf.setStart(picked_cell);
1488 corr_surf();
1489 updateActors();
1492 void GuiMainWindow::improveAspectRatio()
1494 GuiImproveAspectRatio impr_ar;
1495 impr_ar();
1496 updateActors();
1499 void GuiMainWindow::exportAsciiStl()
1501 StlWriter stl;
1502 stl();
1505 void GuiMainWindow::exportBinaryStl()
1509 void GuiMainWindow::periodicUpdate()
1511 Operation::collectGarbage();
1512 updateStatusBar();
1515 void GuiMainWindow::viewXP()
1517 getRenderer()->ResetCamera();
1518 double x[3];
1519 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1520 x[0] += 1;
1521 getRenderer()->GetActiveCamera()->SetPosition(x);
1522 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1523 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1524 getRenderer()->ResetCamera();
1525 getRenderWindow()->Render();
1528 void GuiMainWindow::viewXM()
1530 getRenderer()->ResetCamera();
1531 double x[3];
1532 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1533 x[0] -= 1;
1534 getRenderer()->GetActiveCamera()->SetPosition(x);
1535 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1536 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1537 getRenderer()->ResetCamera();
1538 getRenderWindow()->Render();
1541 void GuiMainWindow::viewYP()
1543 getRenderer()->ResetCamera();
1544 double x[3];
1545 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1546 x[1] += 1;
1547 getRenderer()->GetActiveCamera()->SetPosition(x);
1548 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1549 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1550 getRenderer()->ResetCamera();
1551 getRenderWindow()->Render();
1554 void GuiMainWindow::viewYM()
1556 getRenderer()->ResetCamera();
1557 double x[3];
1558 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1559 x[1] -= 1;
1560 getRenderer()->GetActiveCamera()->SetPosition(x);
1561 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1562 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1563 getRenderer()->ResetCamera();
1564 getRenderWindow()->Render();
1567 void GuiMainWindow::viewZP()
1569 getRenderer()->ResetCamera();
1570 double x[3];
1571 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1572 x[2] += 1;
1573 getRenderer()->GetActiveCamera()->SetPosition(x);
1574 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1575 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1576 getRenderer()->ResetCamera();
1577 getRenderWindow()->Render();
1580 void GuiMainWindow::viewZM()
1582 getRenderer()->ResetCamera();
1583 double x[3];
1584 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1585 x[2] -= 1;
1586 getRenderer()->GetActiveCamera()->SetPosition(x);
1587 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1588 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1589 getRenderer()->ResetCamera();
1590 getRenderWindow()->Render();
1593 void GuiMainWindow::callFixSTL()
1595 FixSTL *fix;
1596 fix = new FixSTL();
1597 fix->setGui();
1598 (*fix)();
1599 updateBoundaryCodes(false);
1600 updateActors();
1603 void GuiMainWindow::editBoundaryConditions()
1605 GuiEditBoundaryConditions editbcs;
1606 editbcs.setBoundaryCodes(all_boundary_codes);
1607 editbcs.setMap(&bcmap);
1608 editbcs();
1611 void GuiMainWindow::configure()
1614 // Just to create initial entries in the settings file
1615 // so that the options menu isn't empty at first start.
1616 GridSmoother tmp01;
1617 GuiCreateBoundaryLayer tmp02;
1619 GuiSettingsViewer settings(&qset);
1620 settings.exec();
1623 void GuiMainWindow::about()
1625 QMessageBox box(this);
1627 QString title="ENGRID";
1628 QString version = QString("version ") + ENGRID_VERSION;
1629 if (version == "version CVS") {
1630 version += " build on ";
1631 version += QString(__DATE__);
1632 version += " at ";
1633 version += QString(__TIME__);
1635 QString address = tr("ENGRID is being developed and maintained by:<br/>"
1636 "enGits GmbH<br/>"
1637 "Marie-Curie-Strasse 8<br/>"
1638 "79539 Loerrach<br/>"
1639 "Germany<br/>");
1641 QString mainurl="<a href=\"http://www.engits.com\">www.engits.com</a>";
1642 QString mail="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1643 QString gnuurl="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1644 QString license=tr("ENGRID is licenced under the GPL version 3.<br/>"
1645 "(see ")+gnuurl+tr(" for details)<br/>");
1646 QString bugurl="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1647 QString bugreporting=tr("To submit a bug report, please use ")+bugurl;
1648 box.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1649 "<h3>%1</h3>"
1650 "<p>%2</p>"
1651 "<p>%3</p>"
1652 "<p>Homepage: %4</p>"
1653 "<p>E-mail: %5</p>"
1654 "<p>%6</p>"
1655 "<p>%7</p></center>")
1656 .arg(title).arg(version).arg(address).arg(mainurl).arg(mail).arg(license).arg(bugreporting));
1657 box.setWindowTitle(tr("about ENGRID"));
1658 box.setIcon(QMessageBox::NoIcon);
1659 box.exec();
1663 void GuiMainWindow::getAllBoundaryCodes(QSet<int> &bcs)
1665 bcs.clear();
1666 foreach (int bc, all_boundary_codes) {
1667 bcs.insert(bc);
1671 void GuiMainWindow::getDisplayBoundaryCodes(QSet<int> &bcs)
1673 bcs.clear();
1674 foreach (int bc, display_boundary_codes) {
1675 bcs.insert(bc);