got keys + clicks :)
[engrid.git] / guimainwindow.cpp
blob8cb3e8b45604288b7c9af9ce20b8f564c1bbe280
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.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();
155 tetra_actor = NULL;
156 pyramid_actor = NULL;
157 wedge_actor = NULL;
158 hexa_actor = NULL;
159 volume_wire_actor = NULL;
160 iamlegend_actor = NULL;
161 lut = NULL;
162 field_mapper = 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();
170 pick_actor = NULL;
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);
214 setAxesVisibility();
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);
228 cbc->Delete();
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;
235 } else {
236 log_file_name = "/tmp/" + basename;
238 system_stdout = stdout;
239 freopen (log_file_name.toAscii().data(), "w", stdout);
241 busy = false;
242 updateStatusBar();
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);
250 N_chars = 0;
252 bool exp_features;
253 getSet("","enable experimental features",false,exp_features);
254 ui.actionFoamWriter->setEnabled(exp_features);
256 ReferenceSize=0.2;
258 // ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
259 // ui.radioButton_CellPicker->setChecked(true);
260 setPickMode(true,true);
261 PickedPoint=-1;
262 PickedCell=-1;
264 ui.doubleSpinBox_HueMin->setValue(0.667);
265 ui.doubleSpinBox_HueMax->setValue(0);
267 egvtkInteractorStyle *style = egvtkInteractorStyle::New();
268 getInteractor()->SetInteractorStyle(style);
270 //end of GuiMainWindow::GuiMainWindow() : QMainWindow(NULL)
272 GuiMainWindow::~GuiMainWindow()
274 qset.setValue("pos", pos());
275 qset.setValue("size", size());
278 void GuiMainWindow::updateOutput()
280 QFile log_file(log_file_name);
281 log_file.open(QIODevice::ReadOnly);
282 QByteArray buffer = log_file.readAll();
283 if (buffer.size() > N_chars) {
284 QByteArray newchars = buffer.right(buffer.size() - N_chars);
285 N_chars = buffer.size();
286 QString txt(newchars);
287 if (txt.right(1) == "\n") {
288 txt = txt.left(txt.size()-1);
290 ui.textEditOutput->append(txt);
294 void GuiMainWindow::exit()
296 QCoreApplication::exit();
299 vtkRenderWindow* GuiMainWindow::getRenderWindow()
301 return ui.qvtkWidget->GetRenderWindow();
304 vtkRenderer* GuiMainWindow::getRenderer()
306 return renderer;
309 QVTKInteractor* GuiMainWindow::getInteractor()
311 return ui.qvtkWidget->GetInteractor();
314 QString GuiMainWindow::getCwd()
316 return cwd;
319 void GuiMainWindow::setCwd(QString dir)
321 cwd = dir;
322 qset.setValue("working_directory",dir);
325 void GuiMainWindow::ScaleToData()
327 int current_field=ui.comboBox_Field->currentIndex();
328 if(current_field>0)
330 double range[2];
331 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
332 cout<<"current_field="<<current_field<<endl;
333 cout<<"range[0]="<<range[0]<<endl;
334 cout<<"range[1]="<<range[1]<<endl;
335 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
336 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
337 ui.doubleSpinBox_FieldMin->setValue(range[0]);
338 ui.doubleSpinBox_FieldMax->setValue(range[1]);
342 void GuiMainWindow::updateActors()
344 if (!tryLock()) return;
345 try {
348 if (!grid->GetCellData()->GetScalars("cell_index")) {
349 EG_VTKSP(vtkLongArray_t, cell_idx);
350 cell_idx->SetName("cell_index");
351 cell_idx->SetNumberOfValues(grid->GetNumberOfCells());
352 grid->GetCellData()->AddArray(cell_idx);
355 EG_VTKDCC(vtkLongArray_t, cell_index, grid, "cell_index");
356 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
357 cell_index->SetValue(cellId, cellId);
361 axes->SetInput(grid);
363 double xmin = 1e99;
364 double xmax = -1e99;
365 double ymin = 1e99;
366 double ymax = -1e99;
367 double zmin = 1e99;
368 double zmax = -1e99;
369 for (vtkIdType nodeId = 0; nodeId < grid->GetNumberOfPoints(); ++nodeId) {
370 vec3_t x;
371 grid->GetPoints()->GetPoint(nodeId, x.data());
372 xmin = min(x[0], xmin);
373 xmax = max(x[0], xmax);
374 ymin = min(x[1], ymin);
375 ymax = max(x[1], ymax);
376 zmin = min(x[2], zmin);
377 zmax = max(x[2], zmax);
380 if (surface_actor) {
381 getRenderer()->RemoveActor(surface_actor);
382 surface_actor->Delete();
383 surface_actor = NULL;
385 if (surface_wire_actor) {
386 getRenderer()->RemoveActor(surface_wire_actor);
387 surface_wire_actor->Delete();
388 surface_wire_actor = NULL;
390 if (tetra_actor) {
391 getRenderer()->RemoveActor(tetra_actor);
392 tetra_actor->Delete();
393 tetra_actor = NULL;
395 if (pyramid_actor) {
396 getRenderer()->RemoveActor(pyramid_actor);
397 pyramid_actor->Delete();
398 pyramid_actor = NULL;
400 if (wedge_actor) {
401 getRenderer()->RemoveActor(wedge_actor);
402 wedge_actor->Delete();
403 wedge_actor = NULL;
405 if (hexa_actor) {
406 getRenderer()->RemoveActor(hexa_actor);
407 hexa_actor->Delete();
408 hexa_actor = NULL;
410 if (volume_wire_actor) {
411 getRenderer()->RemoveActor(volume_wire_actor);
412 volume_wire_actor->Delete();
413 volume_wire_actor = NULL;
415 if (pick_actor) {
416 getRenderer()->RemoveActor(pick_actor);
417 pick_actor->Delete();
418 pick_actor = NULL;
420 if (iamlegend_actor) {
421 getRenderer()->RemoveActor(iamlegend_actor);
422 iamlegend_actor->Delete();
423 iamlegend_actor = NULL;
425 if (lut) {
426 lut->Delete();
427 lut = NULL;
429 if (field_mapper) {
430 field_mapper->Delete();
431 field_mapper = NULL;
434 if (ui.checkBoxSurface->isChecked()) {
435 bcodes_filter->SetBoundaryCodes(&display_boundary_codes);
437 bcodes_filter->SetInput(grid);
439 surface_filter->SetInput(bcodes_filter->GetOutput());
441 surface_filter->Update();
443 boundary_pd->DeepCopy(surface_filter->GetOutput());
445 surface_mapper->SetInput(boundary_pd);
447 surface_wire_mapper->SetInput(boundary_pd);
448 surface_actor = vtkActor::New();
449 surface_actor->GetProperty()->SetRepresentationToSurface();
451 //Fill node field combobox
452 int current_field=ui.comboBox_Field->currentIndex();
453 ui.comboBox_Field->clear();
454 ui.comboBox_Field->addItem("None");
455 int N_Arrays=boundary_pd->GetPointData()->GetNumberOfArrays();
456 // cout<<"N_Arrays="<<N_Arrays<<endl;
457 for (int i=0; i<N_Arrays; i++)
459 ui.comboBox_Field->addItem(boundary_pd->GetPointData()->GetArrayName(i));
461 if(current_field==-1) ui.comboBox_Field->setCurrentIndex(0);
462 else ui.comboBox_Field->setCurrentIndex(current_field);
464 //Fill cell field combobox
465 int current_cell_field=ui.comboBox_CellTextField->currentIndex();
466 ui.comboBox_CellTextField->clear();
467 ui.comboBox_CellTextField->addItem("Cell ID");
468 int N_CellArrays=boundary_pd->GetCellData()->GetNumberOfArrays();
469 // cout<<"N_CellArrays="<<N_CellArrays<<endl;
470 for (int i=0; i<N_CellArrays; i++)
472 ui.comboBox_CellTextField->addItem(grid->GetCellData()->GetArrayName(i));
474 if(current_cell_field==-1) ui.comboBox_CellTextField->setCurrentIndex(0);
475 else ui.comboBox_CellTextField->setCurrentIndex(current_cell_field);
477 // cout<<"index="<<ui.comboBox_Field->currentIndex()<<endl;
478 // cout<<"name="<<ui.comboBox_Field->currentText().toLatin1().data()<<endl;
480 current_field=ui.comboBox_Field->currentIndex();
481 if(current_field>0)
483 double range[2];
484 boundary_pd->GetPointData()->GetArray(current_field-1)->GetRange(range);
485 cout<<"current_field="<<current_field<<endl;
486 cout<<"range[0]="<<range[0]<<endl;
487 cout<<"range[1]="<<range[1]<<endl;
488 ui.doubleSpinBox_FieldMin->setRange(range[0],range[1]);
489 ui.doubleSpinBox_FieldMax->setRange(range[0],range[1]);
492 if(ui.comboBox_Field->currentIndex()<=0) {
493 surface_actor->SetBackfaceProperty(backface_property);
494 surface_actor->GetProperty()->SetColor(0.5,1,0.5);
495 surface_actor->GetBackfaceProperty()->SetColor(1,1,0.5);
496 surface_actor->SetMapper(surface_mapper);
498 else {
499 lut=vtkLookupTable::New();
500 lut->SetNumberOfColors(ui.spinBox_Color->value());
501 lut->SetHueRange(ui.doubleSpinBox_HueMin->value(),ui.doubleSpinBox_HueMax->value());
502 lut->Build();
503 field_mapper=vtkPolyDataMapper::New();
504 field_mapper->SetLookupTable(lut);
505 field_mapper->SetInput(boundary_pd);
506 field_mapper->SetColorModeToMapScalars();
507 field_mapper->SetScalarModeToUsePointFieldData();
508 field_mapper->ColorByArrayComponent(ui.comboBox_Field->currentText().toLatin1().data(),0);
509 field_mapper->SetScalarRange(ui.doubleSpinBox_FieldMin->value(),ui.doubleSpinBox_FieldMax->value());
510 surface_actor->SetMapper(field_mapper);
512 if(ui.checkBox_Legend->checkState()) {
513 iamlegend_actor = vtkScalarBarActor::New();
514 iamlegend_actor->SetLookupTable (lut);
515 getRenderer()->AddActor(iamlegend_actor);
519 /* vtkDoubleArray *newScalars = vtkDoubleArray::New();
520 int index;
521 newScalars=(vtkDoubleArray *)boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
522 cout<<"index="<<index<<endl;*/
524 /* cout<<"=========="<<endl;
525 boundary_pd->GetPointData()->GetArray("node_status",index);
526 cout<<"index="<<index<<endl;
527 boundary_pd->GetPointData()->GetArray("node_layer",index);
528 cout<<"index="<<index<<endl;
529 boundary_pd->GetPointData()->GetArray("node_index",index);
530 cout<<"index="<<index<<endl;
531 boundary_pd->GetPointData()->GetArray("node_meshdensity",index);
532 cout<<"index="<<index<<endl;
533 boundary_pd->GetPointData()->GetArray("node_meshdensity_current",index);
534 cout<<"index="<<index<<endl;
535 boundary_pd->GetPointData()->GetArray("node_type",index);
536 cout<<"index="<<index<<endl;
537 cout<<"=========="<<endl;*/
539 /* int N2=newScalars->GetNumberOfComponents();
540 int N3=newScalars->GetNumberOfTuples();
541 cout<<"Number of components=N2="<<N2<<endl;
542 cout<<"Number of tuples=N3="<<N3<<endl;*/
545 /* for (int i=0; i<N3; i++)
547 double D=newScalars->GetComponent(i,0);//strange, but works. O.o
548 cout<<"D["<<i<<"]="<<D<<endl;
551 surface_wire_actor = vtkActor::New();
552 surface_wire_actor->GetProperty()->SetRepresentationToWireframe();
553 surface_wire_actor->GetProperty()->SetColor(0,0,1);
555 surface_wire_actor->SetMapper(surface_wire_mapper);
556 getRenderer()->AddActor(surface_actor);
557 getRenderer()->AddActor(surface_wire_actor);
558 bcodes_filter->Update();
560 if(m_UseVTKInteractor)
562 if(ui.radioButton_CellPicker->isChecked())
564 // CellPicker->Pick(0,0,0, getRenderer());
565 getInteractor()->SetPicker(CellPicker);
566 // CellPicker->Pick(0,0,0, getRenderer());
567 vtkIdType cellId = getPickedCell();
568 pickCell(cellId);
570 else
572 getInteractor()->SetPicker(PointPicker);
573 vtkIdType nodeId = getPickedPoint();
574 pickPoint(nodeId);
577 else
579 if(ui.radioButton_CellPicker->isChecked()) pickCell(PickedCell);
580 else pickPoint(PickedPoint);
582 /* getInteractor()->SetPicker(CellPicker);
583 vtkIdType cellId = getPickedCell();
584 pickCell(cellId);
585 getInteractor()->SetPicker(PointPicker);
586 vtkIdType nodeId = getPickedPoint();
587 pickPoint(nodeId);*/
591 vec3_t x, n;
592 x[0] = ui.lineEditClipX->text().toDouble();
593 x[1] = ui.lineEditClipY->text().toDouble();
594 x[2] = ui.lineEditClipZ->text().toDouble();
595 n[0] = ui.lineEditClipNX->text().toDouble();
596 n[1] = ui.lineEditClipNY->text().toDouble();
597 n[2] = ui.lineEditClipNZ->text().toDouble();
598 n.normalise();
599 x = x + ui.lineEditOffset->text().toDouble()*n;
600 extr_vol->SetAllOff();
601 if (ui.checkBoxTetra->isChecked()) {
602 extr_vol->SetTetrasOn();
603 extr_tetras->SetInput(grid);
604 if (ui.checkBoxClip->isChecked()) {
605 extr_tetras->SetClippingOn();
606 extr_tetras->SetX(x);
607 extr_tetras->SetN(n);
608 } else {
609 extr_tetras->SetClippingOff();
611 tetra_actor = vtkActor::New();
612 tetra_geometry->SetInput(extr_tetras->GetOutput());
613 tetra_geometry->Update();
614 tetras_pd->DeepCopy(tetra_geometry->GetOutput());
615 tetra_mapper->SetInput(tetras_pd);
616 tetra_actor = vtkActor::New();
617 tetra_actor->SetMapper(tetra_mapper);
618 tetra_actor->GetProperty()->SetColor(1,0,0);
619 getRenderer()->AddActor(tetra_actor);
621 if (ui.checkBoxPyramid->isChecked()) {
622 extr_vol->SetPyramidsOn();
623 extr_pyramids->SetInput(grid);
624 if (ui.checkBoxClip->isChecked()) {
625 extr_pyramids->SetClippingOn();
626 extr_pyramids->SetX(x);
627 extr_pyramids->SetN(n);
628 } else {
629 extr_pyramids->SetClippingOff();
631 pyramid_actor = vtkActor::New();
632 pyramid_geometry->SetInput(extr_pyramids->GetOutput());
633 pyramid_geometry->Update();
634 pyras_pd->DeepCopy(pyramid_geometry->GetOutput());
635 pyramid_mapper->SetInput(pyras_pd);
636 pyramid_actor = vtkActor::New();
637 pyramid_actor->SetMapper(pyramid_mapper);
638 pyramid_actor->GetProperty()->SetColor(1,1,0);
639 getRenderer()->AddActor(pyramid_actor);
641 if (ui.checkBoxWedge->isChecked()) {
642 extr_vol->SetWedgesOn();
643 extr_wedges->SetInput(grid);
644 if (ui.checkBoxClip->isChecked()) {
645 extr_wedges->SetClippingOn();
646 extr_wedges->SetX(x);
647 extr_wedges->SetN(n);
648 } else {
649 extr_wedges->SetClippingOff();
651 wedge_actor = vtkActor::New();
652 wedge_geometry->SetInput(extr_wedges->GetOutput());
653 wedge_geometry->Update();
654 wedges_pd->DeepCopy(wedge_geometry->GetOutput());
655 wedge_mapper->SetInput(wedges_pd);
656 wedge_actor = vtkActor::New();
657 wedge_actor->SetMapper(wedge_mapper);
658 wedge_actor->GetProperty()->SetColor(0,1,0);
659 getRenderer()->AddActor(wedge_actor);
661 if (ui.checkBoxHexa->isChecked()) {
662 extr_vol->SetHexasOn();
663 extr_hexas->SetInput(grid);
664 if (ui.checkBoxClip->isChecked()) {
665 extr_hexas->SetClippingOn();
666 extr_hexas->SetX(x);
667 extr_hexas->SetN(n);
668 } else {
669 extr_hexas->SetClippingOff();
671 hexa_actor = vtkActor::New();
672 hexa_geometry->SetInput(extr_hexas->GetOutput());
673 hexa_geometry->Update();
674 hexas_pd->DeepCopy(hexa_geometry->GetOutput());
675 hexa_mapper->SetInput(hexas_pd);
676 hexa_actor = vtkActor::New();
677 hexa_actor->SetMapper(hexa_mapper);
678 hexa_actor->GetProperty()->SetColor(0,0.7,1);
679 getRenderer()->AddActor(hexa_actor);
682 // wireframe
683 extr_vol->SetInput(grid);
684 if (ui.checkBoxClip->isChecked()) {
685 extr_vol->SetClippingOn();
686 extr_vol->SetX(x);
687 extr_vol->SetN(n);
688 } else {
689 extr_vol->SetClippingOff();
691 volume_wire_actor = vtkActor::New();
692 volume_geometry->SetInput(extr_vol->GetOutput());
693 volume_geometry->Update();
694 volume_pd->DeepCopy(volume_geometry->GetOutput());
695 volume_wire_mapper->SetInput(volume_pd);
696 volume_wire_actor->SetMapper(volume_wire_mapper);
697 volume_wire_actor->GetProperty()->SetRepresentationToWireframe();
698 volume_wire_actor->GetProperty()->SetColor(0,0,1);
699 getRenderer()->AddActor(volume_wire_actor);
702 updateStatusBar();
703 getRenderWindow()->Render();
704 } catch (Error err) {
705 err.display();
707 unlock();
710 void GuiMainWindow::setPickMode(bool a_UseVTKInteractor,bool a_CellPickerMode)
712 m_UseVTKInteractor=a_UseVTKInteractor;
713 if(a_UseVTKInteractor) ui.checkBox_UseVTKInteractor->setCheckState(Qt::Checked);
714 else ui.checkBox_UseVTKInteractor->setCheckState(Qt::Unchecked);
715 if(a_CellPickerMode) ui.radioButton_CellPicker->toggle();
716 else ui.radioButton_PointPicker->toggle();
717 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
720 void GuiMainWindow::setUseVTKInteractor(int a_UseVTKInteractor)
722 m_UseVTKInteractor=a_UseVTKInteractor;
723 // cout<<"m_UseVTKInteractor="<<m_UseVTKInteractor<<endl;
726 bool GuiMainWindow::pickPoint(vtkIdType nodeId)
728 if (nodeId >= 0 && nodeId<grid->GetNumberOfPoints()) {
729 vec3_t x(0,0,0);
730 grid->GetPoints()->GetPoint(nodeId, x.data());
731 pick_sphere->SetCenter(x.data());
732 pick_mapper->SetInput(pick_sphere->GetOutput());
733 pick_actor = vtkActor::New();
734 pick_actor->SetMapper(pick_mapper);
735 pick_actor->GetProperty()->SetRepresentationToSurface();
736 pick_actor->GetProperty()->SetColor(0,0,1);
737 getRenderer()->AddActor(pick_actor);
738 PickedPoint=nodeId;
739 return(true);
741 else return(false);
744 bool GuiMainWindow::pickCell(vtkIdType cellId)
746 if (cellId >= 0 && cellId<grid->GetNumberOfCells()) {
747 vtkIdType *pts, Npts;
748 grid->GetCellPoints(cellId, Npts, pts);
749 vec3_t x(0,0,0);
750 for (vtkIdType i = 0; i < Npts; ++i) {
751 vec3_t xp;
752 grid->GetPoints()->GetPoint(pts[i], xp.data());
753 x += double(1)/Npts * xp;
755 pick_sphere->SetCenter(x.data());
756 double R = 1e99;
757 for (vtkIdType i = 0; i < Npts; ++i) {
758 vec3_t xp;
759 grid->GetPoints()->GetPoint(pts[i], xp.data());
760 R = min(R, 0.25*(xp-x).abs());
762 ReferenceSize=R;//Used for text annotations too!
763 pick_sphere->SetRadius(R);
764 pick_mapper->SetInput(pick_sphere->GetOutput());
765 pick_actor = vtkActor::New();
766 pick_actor->SetMapper(pick_mapper);
767 pick_actor->GetProperty()->SetRepresentationToSurface();
768 pick_actor->GetProperty()->SetColor(1,0,0);
769 getRenderer()->AddActor(pick_actor);
770 PickedCell=cellId;
771 return(true);
773 else return(false);
776 void GuiMainWindow::importSTL()
778 StlReader stl;
779 stl();
780 updateBoundaryCodes(true);
781 updateActors();
782 updateStatusBar();
783 zoomAll();
786 void GuiMainWindow::importGmsh1Ascii()
788 GmshReader gmsh;
789 gmsh.setV1Ascii();
790 gmsh();
791 updateBoundaryCodes(true);
792 updateActors();
793 updateStatusBar();
794 zoomAll();
797 void GuiMainWindow::exportGmsh1Ascii()
799 GmshWriter gmsh;
800 gmsh.setV1Ascii();
801 gmsh();
804 void GuiMainWindow::importGmsh2Ascii()
806 GmshReader gmsh;
807 gmsh.setV2Ascii();
808 gmsh();
809 updateBoundaryCodes(true);
810 updateActors();
811 updateStatusBar();
812 zoomAll();
815 void GuiMainWindow::exportGmsh2Ascii()
817 GmshWriter gmsh;
818 gmsh.setV2Ascii();
819 gmsh();
822 void GuiMainWindow::exportNeutral()
824 NeutralWriter neutral;
825 neutral();
828 void GuiMainWindow::zoomAll()
830 getRenderer()->ResetCamera();
831 getRenderWindow()->Render();
834 void GuiMainWindow::open()
836 current_filename = QFileDialog::getOpenFileName
838 NULL,
839 "open grid from file",
840 getCwd(),
841 "VTK unstructured grid files (*.vtu *.VTU)"
843 if (!current_filename.isNull()) {
844 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
845 EG_VTKSP(vtkXMLUnstructuredGridReader,vtu);
846 vtu->SetFileName(current_filename.toAscii().data());
847 vtu->Update();
848 grid->DeepCopy(vtu->GetOutput());
849 createBasicFields(grid, grid->GetNumberOfCells(), grid->GetNumberOfPoints(), false);
850 setWindowTitle(current_filename + " - enGrid");
851 openBC();
852 updateBoundaryCodes(true);
853 updateActors();
854 updateStatusBar();
855 zoomAll();
859 void GuiMainWindow::undo()
863 void GuiMainWindow::redo()
867 void GuiMainWindow::openBC()
869 QString bc_file = current_filename + ".bcs";
870 QFile file(bc_file);
871 bcmap.clear();
872 if (file.exists()) {
873 file.open(QIODevice::ReadOnly | QIODevice::Text);
874 QTextStream f(&file);
875 while (!f.atEnd()) {
876 QString name, type;
877 int i;
878 f >> i >> name >> type;
879 bcmap[i] = BoundaryCondition(name,type);
884 void GuiMainWindow::saveBC()
886 QString bc_file = current_filename + ".bcs";
887 QFile file(bc_file);
888 file.open(QIODevice::WriteOnly | QIODevice::Text);
889 QTextStream f(&file);
890 foreach(int i, all_boundary_codes) {
891 BoundaryCondition bc = bcmap[i];
892 f << i << " " << bc.getName() << " " << bc.getType() << "\n";
896 void GuiMainWindow::save()
898 cout << current_filename.toAscii().data() << endl;
899 if (current_filename == "untitled.vtu") {
900 saveAs();
901 } else {
902 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
903 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
904 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
906 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
907 addVtkTypeInfo();
908 createIndices(grid);
909 vtu->SetFileName(current_filename.toAscii().data());
910 vtu->SetDataModeToBinary();
911 vtu->SetInput(grid);
912 vtu->Write();
913 saveBC();
917 void GuiMainWindow::saveAs()
919 current_filename = QFileDialog::getSaveFileName
921 NULL,
922 "write grid to file",
923 getCwd(),
924 "VTK unstructured grid files (*.vtu *.VTU)"
926 if (!current_filename.isNull()) {
927 if (current_filename.right(4) != ".vtu") {
928 if (current_filename.right(4) != ".VTU") {
929 current_filename += ".vtu";
932 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
933 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
934 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
936 GuiMainWindow::setCwd(QFileInfo(current_filename).absolutePath());
937 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
938 addVtkTypeInfo();
939 createIndices(grid);
940 vtu->SetFileName(current_filename.toAscii().data());
941 vtu->SetDataModeToBinary();
942 vtu->SetInput(grid);
943 vtu->Write();
944 saveBC();
945 setWindowTitle(current_filename + " - enGrid");
949 void GuiMainWindow::QuickSave(QString a_filename)
951 cout << a_filename.toAscii().data() << endl;
953 EG_VTKDCC(vtkDoubleArray, cell_VA, grid, "cell_VA");
954 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
955 cell_VA->SetValue(cellId, GeometryTools::cellVA(grid, cellId, true));
957 EG_VTKSP(vtkXMLUnstructuredGridWriter,vtu);
958 addVtkTypeInfo();
959 createIndices(grid);
960 vtu->SetFileName(a_filename.toAscii().data());
961 vtu->SetDataModeToBinary();
962 vtu->SetInput(grid);
963 vtu->Write();
964 saveBC();
968 void GuiMainWindow::updateStatusBar()
970 QString num, txt = "enGrid is currently busy with an operation ...";
971 if (!busy) {
972 txt = "";
974 if (!tryLock()) {
975 status_label->setText(txt);
976 return;
978 vtkIdType Ncells = grid->GetNumberOfCells();
979 vtkIdType Nnodes = grid->GetNumberOfPoints();
980 vtkIdType Ntris = 0;
981 vtkIdType Nquads = 0;
982 vtkIdType Ntets = 0;
983 vtkIdType Npyras = 0;
984 vtkIdType Nprism = 0;
985 vtkIdType Nhexas = 0;
986 for (vtkIdType i = 0; i < Ncells; ++i) {
987 int ct = grid->GetCellType(i);
988 if (ct == VTK_TRIANGLE) ++Ntris;
989 else if (ct == VTK_QUAD) ++Nquads;
990 else if (ct == VTK_TETRA) ++Ntets;
991 else if (ct == VTK_WEDGE) ++Nprism;
992 else if (ct == VTK_PYRAMID) ++Npyras;
993 else if (ct == VTK_HEXAHEDRON) ++Nhexas;
995 num.setNum(Ntets + Npyras + Nprism + Nhexas); txt += num + " volume cells(";
996 num.setNum(Ntets); txt += num + " tetras, ";
997 num.setNum(Npyras); txt += num + " pyramids, ";
998 num.setNum(Nprism); txt += num + " prisms, ";
999 num.setNum(Nhexas); txt += num + " hexas), ";
1000 num.setNum(Ntris + Nquads); txt += num + " surface cells(";
1001 num.setNum(Ntris); txt += num + " triangles, ";
1002 num.setNum(Nquads); txt += num + " quads), ";
1003 num.setNum(Nnodes); txt += num + " nodes";
1005 if(ui.radioButton_CellPicker->isChecked())
1007 QString pick_txt = ", picked cell: ";
1008 vtkIdType id_cell = getPickedCell();
1009 if (id_cell < 0) {
1010 pick_txt += "no cell picked";
1011 } else {
1012 vtkIdType type_cell = grid->GetCellType(id_cell);
1013 if (type_cell == VTK_TRIANGLE) pick_txt += "triangle";
1014 else if (type_cell == VTK_QUAD) pick_txt += "quad";
1015 else if (type_cell == VTK_TETRA) pick_txt += "tetrahedron";
1016 else if (type_cell == VTK_PYRAMID) pick_txt += "pyramid";
1017 else if (type_cell == VTK_WEDGE) pick_txt += "prism";
1018 else if (type_cell == VTK_HEXAHEDRON) pick_txt += "hexahedron";
1019 vtkIdType N_pts, *pts;
1020 grid->GetCellPoints(id_cell, N_pts, pts);
1021 pick_txt += " [";
1022 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
1023 QString num;
1024 num.setNum(pts[i_pts]);
1025 pick_txt += num;
1026 if (i_pts < N_pts-1) {
1027 pick_txt += ",";
1030 pick_txt += "]";
1031 QString tmp;
1032 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1033 tmp.setNum(cell_code->GetValue(id_cell));
1034 pick_txt += " cell_code=" + tmp;
1035 tmp.setNum(id_cell);
1036 pick_txt += " id_cell=" + tmp;
1038 txt += pick_txt;
1040 else
1042 QString pick_txt = ", picked node: ";
1043 vtkIdType id_node = getPickedPoint();
1044 if (id_node < 0) {
1045 pick_txt += "no node picked";
1046 } else {
1047 vec3_t x;
1048 grid->GetPoints()->GetPoint(id_node,x.data());
1049 pick_txt += " [";
1050 for (int i = 0; i < 3; i++) {
1051 QString num;
1052 num.setNum(x[i]);
1053 pick_txt += num;
1054 if (i < 2) {
1055 pick_txt += ",";
1058 pick_txt += "]";
1059 QString tmp;
1060 EG_VTKDCN(vtkDoubleArray, node_meshdensity, grid, "node_meshdensity");
1061 tmp.setNum(node_meshdensity->GetValue(id_node));
1062 pick_txt += " wanted density=" + tmp;
1063 EG_VTKDCN(vtkDoubleArray, node_meshdensity_current, grid, "node_meshdensity_current");
1064 tmp.setNum(node_meshdensity_current->GetValue(id_node));
1065 pick_txt += " current density=" + tmp;
1066 EG_VTKDCN(vtkIntArray, node_specified_density, grid, "node_specified_density");
1067 tmp.setNum(node_specified_density->GetValue(id_node));
1068 pick_txt += " node_specified_density=" + tmp;
1069 EG_VTKDCN(vtkCharArray, node_type, grid, "node_type");
1070 pick_txt += " type=" + QString(VertexType2Str( node_type->GetValue(id_node)));
1071 tmp.setNum(id_node);
1072 pick_txt += " id_node=" + tmp;
1075 txt += pick_txt;
1078 status_label->setText(txt);
1079 unlock();
1082 void GuiMainWindow::selectBoundaryCodes()
1084 GuiSelectBoundaryCodes bcodes;
1085 bcodes.setDisplayBoundaryCodes(display_boundary_codes);
1086 bcodes.setBoundaryCodes(all_boundary_codes);
1087 bcodes();
1088 bcodes.getThread().wait();
1089 bcodes.getSelectedBoundaryCodes(display_boundary_codes);
1090 updateActors();
1093 void GuiMainWindow::updateBoundaryCodes(bool all_on)
1095 try {
1096 all_boundary_codes.clear();
1097 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
1098 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
1099 int ct = grid->GetCellType(i);
1100 if ((ct == VTK_TRIANGLE) || (ct == VTK_QUAD)) {
1101 all_boundary_codes.insert(cell_code->GetValue(i));
1104 if (all_on) {
1105 display_boundary_codes.clear();
1106 foreach (int bc, all_boundary_codes) {
1107 display_boundary_codes.insert(bc);
1109 } else {
1110 QSet<int> dbcs;
1111 foreach (int bc, display_boundary_codes) {
1112 if (all_boundary_codes.contains(bc)) {
1113 dbcs.insert(bc);
1116 display_boundary_codes.clear();
1117 foreach (int bc, all_boundary_codes) {
1118 if (dbcs.contains(bc)) {
1119 display_boundary_codes.insert(bc);
1123 } catch (Error err) {
1124 err.display();
1128 void GuiMainWindow::normalExtrusion()
1130 GuiNormalExtrusion extr;
1131 extr();
1132 updateBoundaryCodes(false);
1133 updateActors();
1136 void GuiMainWindow::setAxesVisibility()
1138 if (ui.actionViewAxes->isChecked()) axes->SetVisibility(1);
1139 else axes->SetVisibility(0);
1140 getRenderWindow()->Render();
1143 void GuiMainWindow::setViewingMode()
1145 if (ui.actionViewOrthogonal->isChecked()) getRenderer()->GetActiveCamera()->ParallelProjectionOn();
1146 else getRenderer()->GetActiveCamera()->ParallelProjectionOff();
1147 getRenderWindow()->Render();
1150 void GuiMainWindow::ViewNodeIDs()
1152 int N=grid->GetNumberOfPoints();
1153 cout<<"N="<<N<<endl;
1154 if (ui.actionViewNodeIDs->isChecked()) {
1155 cout<<"Activating node ID view"<<endl;
1156 NodeText_VectorText.resize(N);
1157 NodeText_PolyDataMapper.resize(N);
1158 NodeText_Follower.resize(N);
1159 for(int i=0;i<N;i++){
1160 NodeText_VectorText[i]=vtkVectorText::New();
1161 QString tmp;
1162 tmp.setNum(i);
1163 NodeText_VectorText[i]->SetText(tmp.toLatin1().data());
1164 NodeText_PolyDataMapper[i]=vtkPolyDataMapper::New();
1165 NodeText_PolyDataMapper[i]->SetInputConnection(NodeText_VectorText[i]->GetOutputPort());
1166 NodeText_Follower[i]=vtkFollower::New();
1167 NodeText_Follower[i]->SetMapper(NodeText_PolyDataMapper[i]);
1168 NodeText_Follower[i]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1169 vec3_t M;
1170 grid->GetPoint(i,M.data());
1171 vec3_t tmp_M=M;
1172 vec3_t OffSet=ReferenceSize*tmp_M.normalise();
1173 M=M+OffSet;
1174 NodeText_Follower[i]->AddPosition(M[0],M[1],M[2]);
1175 NodeText_Follower[i]->SetCamera(getRenderer()->GetActiveCamera());
1176 NodeText_Follower[i]->GetProperty()->SetColor(0,0,1);
1177 getRenderer()->AddActor(NodeText_Follower[i]);
1180 else {
1181 cout<<"Deactivating node ID view"<<endl;
1182 for(unsigned int i=0;i<NodeText_Follower.size();i++){
1183 getRenderer()->RemoveActor(NodeText_Follower[i]);
1184 NodeText_Follower[i]->Delete();
1185 NodeText_PolyDataMapper[i]->Delete();
1186 NodeText_VectorText[i]->Delete();
1188 NodeText_Follower.clear();
1189 NodeText_PolyDataMapper.clear();
1190 NodeText_VectorText.clear();
1193 getRenderWindow()->Render();
1196 void GuiMainWindow::ViewCellIDs()
1198 vtkIdType N=grid->GetNumberOfCells();
1199 cout<<"N="<<N<<endl;
1200 if (ui.actionViewCellIDs->isChecked()) {
1201 cout<<"Activating cell ID view"<<endl;
1202 CellText_VectorText.resize(N);
1203 CellText_PolyDataMapper.resize(N);
1204 CellText_Follower.resize(N);
1205 for(vtkIdType id_cell=0;id_cell<N;id_cell++){
1206 CellText_VectorText[id_cell]=vtkVectorText::New();
1208 QString tmp;
1210 if(ui.comboBox_CellTextField->currentIndex()==0) {
1211 tmp.setNum(id_cell);
1213 else if(ui.comboBox_CellTextField->currentIndex()>0) {
1214 EG_VTKDCC(vtkIntArray, current_cell_field, grid, ui.comboBox_CellTextField->currentText().toLatin1().data());
1215 tmp.setNum(current_cell_field->GetValue(id_cell));
1217 else EG_BUG;
1219 CellText_VectorText[id_cell]->SetText(tmp.toLatin1().data());
1220 CellText_PolyDataMapper[id_cell]=vtkPolyDataMapper::New();
1221 CellText_PolyDataMapper[id_cell]->SetInputConnection(CellText_VectorText[id_cell]->GetOutputPort());
1222 CellText_Follower[id_cell]=vtkFollower::New();
1223 CellText_Follower[id_cell]->SetMapper(CellText_PolyDataMapper[id_cell]);
1224 CellText_Follower[id_cell]->SetScale(ReferenceSize,ReferenceSize,ReferenceSize);
1225 vtkIdType N_pts,*pts;
1226 grid->GetCellPoints(id_cell,N_pts,pts);
1227 vec3_t Center(0,0,0);
1228 for(int p=0;p<N_pts;p++)
1230 vec3_t M;
1231 grid->GetPoint(pts[p],M.data());
1232 Center+=M.data();
1234 vec3_t OffSet=ReferenceSize*triNormal(grid,pts[0],pts[1],pts[2]).normalise();
1235 Center=1.0/(double)N_pts*Center+OffSet;
1236 CellText_Follower[id_cell]->AddPosition(Center[0],Center[1],Center[2]);
1237 CellText_Follower[id_cell]->SetCamera(getRenderer()->GetActiveCamera());
1238 CellText_Follower[id_cell]->GetProperty()->SetColor(1,0,0);
1239 getRenderer()->AddActor(CellText_Follower[id_cell]);
1242 else {
1243 cout<<"Deactivating cell ID view"<<endl;
1244 for(vtkIdType id_cell=0;id_cell<CellText_Follower.size();id_cell++){
1245 getRenderer()->RemoveActor(CellText_Follower[id_cell]);
1246 CellText_Follower[id_cell]->Delete();
1247 CellText_PolyDataMapper[id_cell]->Delete();
1248 CellText_VectorText[id_cell]->Delete();
1250 CellText_Follower.clear();
1251 CellText_PolyDataMapper.clear();
1252 CellText_VectorText.clear();
1255 getRenderWindow()->Render();
1258 void GuiMainWindow::addVtkTypeInfo()
1260 EG_VTKSP(vtkIntArray, vtk_type);
1261 vtk_type->SetName("vtk_type");
1262 vtk_type->SetNumberOfValues(grid->GetNumberOfCells());
1263 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1264 vtk_type->SetValue(cellId, grid->GetCellType(cellId));
1266 grid->GetCellData()->AddArray(vtk_type);
1269 void GuiMainWindow::pickCellCallBack
1271 vtkObject *caller,
1272 unsigned long int eid,
1273 void *clientdata,
1274 void *calldata
1277 caller = caller;
1278 eid = eid;
1279 clientdata = clientdata;
1280 calldata = calldata;
1281 THIS->updateActors();
1282 THIS->updateStatusBar();
1285 void GuiMainWindow::pickPointCallBack
1287 vtkObject *caller,
1288 unsigned long int eid,
1289 void *clientdata,
1290 void *calldata
1293 caller = caller;
1294 eid = eid;
1295 clientdata = clientdata;
1296 calldata = calldata;
1297 THIS->updateActors();
1298 THIS->updateStatusBar();
1301 vtkIdType GuiMainWindow::getPickedCell()
1303 vtkIdType picked_cell = -1;
1304 if (THIS->grid->GetNumberOfCells() > 0) {
1305 THIS->bcodes_filter->Update();
1306 EG_VTKDCC(vtkLongArray_t, cell_index, THIS->bcodes_filter->GetOutput(), "cell_index");
1308 vtkIdType cellId;
1309 if(m_UseVTKInteractor) cellId = THIS->CellPicker->GetCellId();
1310 else cellId = PickedCell;
1312 if (cellId >= 0) {
1313 if (cellId < THIS->bcodes_filter->GetOutput()->GetNumberOfCells()) {
1314 picked_cell = cell_index->GetValue(cellId);
1318 return picked_cell;
1321 vtkIdType GuiMainWindow::getPickedPoint()
1323 vtkIdType picked_point = -1;
1324 if (THIS->grid->GetNumberOfCells() > 0) {
1325 THIS->bcodes_filter->Update();
1327 vtkIdType pointId;
1328 if(m_UseVTKInteractor) pointId = THIS->PointPicker->GetPointId();
1329 else pointId = PickedPoint;
1331 if (pointId >= 0) {
1332 picked_point = pointId;
1335 return picked_point;
1338 void GuiMainWindow::changeSurfaceOrientation()
1340 for (vtkIdType cellId = 0; cellId < grid->GetNumberOfCells(); ++cellId) {
1341 vtkIdType Npts, *pts;
1342 grid->GetCellPoints(cellId, Npts, pts);
1343 QVector<vtkIdType> nodes(Npts);
1344 for (vtkIdType j = 0; j < Npts; ++j) nodes[j] = pts[j];
1345 for (vtkIdType j = 0; j < Npts; ++j) pts[Npts - j - 1] = nodes[j];
1347 updateActors();
1350 void GuiMainWindow::checkSurfaceOrientation()
1352 CorrectSurfaceOrientation corr_surf;
1353 vtkIdType picked_cell = getPickedCell();
1354 if (picked_cell >= 0) {
1355 corr_surf.setStart(picked_cell);
1357 corr_surf();
1358 updateActors();
1361 void GuiMainWindow::improveAspectRatio()
1363 GuiImproveAspectRatio impr_ar;
1364 impr_ar();
1365 updateActors();
1368 void GuiMainWindow::exportAsciiStl()
1370 StlWriter stl;
1371 stl();
1374 void GuiMainWindow::exportBinaryStl()
1378 void GuiMainWindow::periodicUpdate()
1380 Operation::collectGarbage();
1381 updateStatusBar();
1384 void GuiMainWindow::viewXP()
1386 getRenderer()->ResetCamera();
1387 double x[3];
1388 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1389 x[0] += 1;
1390 getRenderer()->GetActiveCamera()->SetPosition(x);
1391 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1392 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1393 getRenderer()->ResetCamera();
1394 getRenderWindow()->Render();
1397 void GuiMainWindow::viewXM()
1399 getRenderer()->ResetCamera();
1400 double x[3];
1401 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1402 x[0] -= 1;
1403 getRenderer()->GetActiveCamera()->SetPosition(x);
1404 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1405 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1406 getRenderer()->ResetCamera();
1407 getRenderWindow()->Render();
1410 void GuiMainWindow::viewYP()
1412 getRenderer()->ResetCamera();
1413 double x[3];
1414 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1415 x[1] += 1;
1416 getRenderer()->GetActiveCamera()->SetPosition(x);
1417 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1418 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1419 getRenderer()->ResetCamera();
1420 getRenderWindow()->Render();
1423 void GuiMainWindow::viewYM()
1425 getRenderer()->ResetCamera();
1426 double x[3];
1427 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1428 x[1] -= 1;
1429 getRenderer()->GetActiveCamera()->SetPosition(x);
1430 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1431 getRenderer()->GetActiveCamera()->SetViewUp(0,0,-1);
1432 getRenderer()->ResetCamera();
1433 getRenderWindow()->Render();
1436 void GuiMainWindow::viewZP()
1438 getRenderer()->ResetCamera();
1439 double x[3];
1440 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1441 x[2] += 1;
1442 getRenderer()->GetActiveCamera()->SetPosition(x);
1443 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1444 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1445 getRenderer()->ResetCamera();
1446 getRenderWindow()->Render();
1449 void GuiMainWindow::viewZM()
1451 getRenderer()->ResetCamera();
1452 double x[3];
1453 getRenderer()->GetActiveCamera()->GetFocalPoint(x);
1454 x[2] -= 1;
1455 getRenderer()->GetActiveCamera()->SetPosition(x);
1456 getRenderer()->GetActiveCamera()->ComputeViewPlaneNormal();
1457 getRenderer()->GetActiveCamera()->SetViewUp(0,1,0);
1458 getRenderer()->ResetCamera();
1459 getRenderWindow()->Render();
1462 void GuiMainWindow::callFixSTL()
1464 FixSTL *fix;
1465 fix = new FixSTL();
1466 fix->setGui();
1467 (*fix)();
1468 updateBoundaryCodes(false);
1469 updateActors();
1472 void GuiMainWindow::editBoundaryConditions()
1474 GuiEditBoundaryConditions editbcs;
1475 editbcs.setBoundaryCodes(all_boundary_codes);
1476 editbcs.setMap(&bcmap);
1477 editbcs();
1480 void GuiMainWindow::configure()
1483 // Just to create initial entries in the settings file
1484 // so that the options menu isn't empty at first start.
1485 GridSmoother tmp01;
1486 GuiCreateBoundaryLayer tmp02;
1488 GuiSettingsViewer settings(&qset);
1489 settings.exec();
1492 void GuiMainWindow::about()
1494 QMessageBox box(this);
1496 QString title="ENGRID";
1497 QString version = QString("version ") + ENGRID_VERSION;
1498 if (version == "version CVS") {
1499 version += " build on ";
1500 version += QString(__DATE__);
1501 version += " at ";
1502 version += QString(__TIME__);
1504 QString address = tr("ENGRID is being developed and maintained by:<br/>"
1505 "enGits GmbH<br/>"
1506 "Marie-Curie-Strasse 8<br/>"
1507 "79539 Loerrach<br/>"
1508 "Germany<br/>");
1510 QString mainurl="<a href=\"http://www.engits.com\">www.engits.com</a>";
1511 QString mail="<a href=\"mailto:info@engits.com\">info@engits.com</a>";
1512 QString gnuurl="<a href=\"http://www.gnu.org/licenses\">http://www.gnu.org/licenses</a>";
1513 QString license=tr("ENGRID is licenced under the GPL version 3.<br/>"
1514 "(see ")+gnuurl+tr(" for details)<br/>");
1515 QString bugurl="<a href=\"http://sourceforge.net/tracker2/?func=add&group_id=245110&atid=1126548\">the bugtracker available on Sourceforge</a>";
1516 QString bugreporting=tr("To submit a bug report, please use ")+bugurl;
1517 box.setText(QString::fromLatin1("<center><img src=\":/icons/resources/icons/G.png\">"
1518 "<h3>%1</h3>"
1519 "<p>%2</p>"
1520 "<p>%3</p>"
1521 "<p>Homepage: %4</p>"
1522 "<p>E-mail: %5</p>"
1523 "<p>%6</p>"
1524 "<p>%7</p></center>")
1525 .arg(title).arg(version).arg(address).arg(mainurl).arg(mail).arg(license).arg(bugreporting));
1526 box.setWindowTitle(tr("about ENGRID"));
1527 box.setIcon(QMessageBox::NoIcon);
1528 box.exec();
1532 void GuiMainWindow::getAllBoundaryCodes(QSet<int> &bcs)
1534 bcs.clear();
1535 foreach (int bc, all_boundary_codes) {
1536 bcs.insert(bc);