Added getNeighbours functions to class Operation + moved UpdateMeshDensity to class...
[engrid.git] / guinormalextrusion.cpp
blob3c8b398c2fd559119577f6630fc4e2f752f80616
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 "guinormalextrusion.h"
24 #include "vtkEgNormalExtrusion.h"
25 #include "containertricks.h"
27 void GuiNormalExtrusion::before()
29 populateBoundaryCodes(ui.listWidget);
32 void GuiNormalExtrusion::operate()
34 EG_VTKSP(vtkEgNormalExtrusion, extr);
35 QVector<double> y;
37 if (ui.radioButtonSimple->isChecked()) {
38 y.resize(ui.lineEditSimpleNumLayers->text().toInt() + 1);
39 double h = ui.lineEditSimpleHeight->text().toDouble();
40 double f = ui.lineEditSimpleIncrease->text().toDouble();
41 y[0] = 0.0;
42 for (int i = 1; i < y.size(); ++i) {
43 y[i] = y[i-1] + h;
44 h *= f;
46 } else if (ui.radioButtonFixedHeights->isChecked()) {
47 y.resize(ui.lineEditFixedHeightsNumLayers->text().toInt() + 1);
48 QVector<double> x(y.size());
49 for (int i = 0; i < x.size(); ++i) {
50 x[i] = i*1.0/(x.size() - 1);
52 mat3_t A;
53 clinit(A[0]) = pow(x[1],5.0), pow(x[1],3.0), x[1];
54 clinit(A[1]) = pow(x[x.size() - 2],5.0), pow(x[x.size() - 2],3.0), x[x.size() - 2];
55 clinit(A[2]) = pow(x[x.size() - 1],5.0), pow(x[x.size() - 1],3.0), x[x.size() - 1];
56 vec3_t h;
57 h[0] = ui.lineEditFixedHeightsHeightFirst->text().toDouble();
58 h[2] = ui.lineEditFixedHeightsTotalHeight->text().toDouble();
59 h[1] = h[2] - ui.lineEditFixedHeightsHeightLast->text().toDouble();
60 mat3_t AI = A.inverse();
61 vec3_t coeff = AI*h;
62 for (int i = 0; i < y.size(); ++i) {
63 y[i] = coeff[0]*pow(x[i],5.0) + coeff[1]*pow(x[i],3.0) + coeff[2]*x[i];
64 if (i > 0) {
65 if (y[i] < y[i-1]) {
66 EG_ERR_RETURN("unable to compute layer heights");
71 extr->SetLayers(y);
73 if (ui.radioButtonFixed->isChecked()) {
74 extr->SetNormal(vec3_t(ui.lineEditFixedNX->text().toDouble(),
75 ui.lineEditFixedNY->text().toDouble(),
76 ui.lineEditFixedNZ->text().toDouble()));
77 double min_dist = ui.lineEditFixedDist->text().toDouble();
78 if (min_dist <= 0) {
79 extr->SetFixed();
80 } else {
81 extr->SetPlanar();
82 extr->SetMinDist(min_dist);
85 if (ui.radioButtonCylinder->isChecked()) {
86 extr->SetCylindrical();
87 extr->SetOrigin(vec3_t(ui.lineEditCylinderX0->text().toDouble(),
88 ui.lineEditCylinderY0->text().toDouble(),
89 ui.lineEditCylinderZ0->text().toDouble()));
90 extr->SetAxis(vec3_t(ui.lineEditCylinderNX->text().toDouble(),
91 ui.lineEditCylinderNY->text().toDouble(),
92 ui.lineEditCylinderNZ->text().toDouble()));
94 if (ui.radioButtonRotation->isChecked()) {
95 extr->SetRotation();
96 extr->SetOrigin(vec3_t(ui.lineEditCylinderX0->text().toDouble(),
97 ui.lineEditCylinderY0->text().toDouble(),
98 ui.lineEditCylinderZ0->text().toDouble()));
99 extr->SetAxis(vec3_t(ui.lineEditCylinderNX->text().toDouble(),
100 ui.lineEditCylinderNY->text().toDouble(),
101 ui.lineEditCylinderNZ->text().toDouble()));
104 QSet<int> bcs;
105 getSelectedItems(ui.listWidget, bcs);
106 extr->SetBoundaryCodes(&bcs);
107 EG_VTKSP(vtkUnstructuredGrid,ug);
108 makeCopy(grid, ug);
109 extr->SetInput(ug);
110 extr->Update();
111 makeCopy(extr->GetOutput(), grid);