1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "guinormalextrusion.h"
22 #include "vtkEgNormalExtrusion.h"
23 #include "containertricks.h"
24 #include "guimainwindow.h"
26 void GuiNormalExtrusion::before()
28 populateBoundaryCodes(m_Ui
.listWidget
);
31 void GuiNormalExtrusion::operate()
34 getSelectedItems(m_Ui
.listWidget
, bcs
);
35 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
36 QSet
<int> volume_codes
;
37 EG_FORALL_CELLS(id_cell
, m_Grid
) {
38 if (isSurface(id_cell
, m_Grid
)) {
39 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
40 vtkIdType id_volume_cell
= m_Part
.getVolumeCell(id_cell
);
41 if (id_volume_cell
!= -1) {
42 volume_codes
.insert(cell_code
->GetValue(id_volume_cell
));
48 EG_VTKSP(vtkEgNormalExtrusion
, extr
);
51 if (m_Ui
.radioButtonSimple
->isChecked()) {
52 y
.resize(m_Ui
.lineEditSimpleNumLayers
->text().toInt() + 1);
53 double h
= m_Ui
.lineEditSimpleHeight
->text().toDouble();
54 double f
= m_Ui
.lineEditSimpleIncrease
->text().toDouble();
56 for (int i
= 1; i
< y
.size(); ++i
) {
60 } else if (m_Ui
.radioButtonFixedHeights
->isChecked()) {
61 y
.resize(m_Ui
.lineEditFixedHeightsNumLayers
->text().toInt() + 1);
62 QVector
<double> x(y
.size());
63 for (int i
= 0; i
< x
.size(); ++i
) {
64 x
[i
] = i
*1.0/(x
.size() - 1);
67 clinit(A
[0]) = pow(x
[1],5.0), pow(x
[1],3.0), x
[1];
68 clinit(A
[1]) = pow(x
[x
.size() - 2],5.0), pow(x
[x
.size() - 2],3.0), x
[x
.size() - 2];
69 clinit(A
[2]) = pow(x
[x
.size() - 1],5.0), pow(x
[x
.size() - 1],3.0), x
[x
.size() - 1];
71 h
[0] = m_Ui
.lineEditFixedHeightsHeightFirst
->text().toDouble();
72 h
[2] = m_Ui
.lineEditFixedHeightsTotalHeight
->text().toDouble();
73 h
[1] = h
[2] - m_Ui
.lineEditFixedHeightsHeightLast
->text().toDouble();
74 mat3_t AI
= A
.inverse();
76 for (int i
= 0; i
< y
.size(); ++i
) {
77 y
[i
] = coeff
[0]*pow(x
[i
],5.0) + coeff
[1]*pow(x
[i
],3.0) + coeff
[2]*x
[i
];
80 EG_ERR_RETURN("unable to compute layer heights");
87 if (m_Ui
.radioButtonFixed
->isChecked()) {
88 extr
->SetNormal(vec3_t(m_Ui
.lineEditFixedNX
->text().toDouble(),
89 m_Ui
.lineEditFixedNY
->text().toDouble(),
90 m_Ui
.lineEditFixedNZ
->text().toDouble()));
91 double min_dist
= m_Ui
.lineEditFixedDist
->text().toDouble();
96 extr
->SetMinDist(min_dist
);
99 if (m_Ui
.radioButtonCylinder
->isChecked()) {
100 extr
->SetCylindrical();
101 extr
->SetOrigin(vec3_t(m_Ui
.lineEditCylinderX0
->text().toDouble(),
102 m_Ui
.lineEditCylinderY0
->text().toDouble(),
103 m_Ui
.lineEditCylinderZ0
->text().toDouble()));
104 extr
->SetAxis(vec3_t(m_Ui
.lineEditCylinderNX
->text().toDouble(),
105 m_Ui
.lineEditCylinderNY
->text().toDouble(),
106 m_Ui
.lineEditCylinderNZ
->text().toDouble()));
108 if (m_Ui
.radioButtonRotation
->isChecked()) {
110 extr
->SetOrigin(vec3_t(m_Ui
.lineEditCylinderX0
->text().toDouble(),
111 m_Ui
.lineEditCylinderY0
->text().toDouble(),
112 m_Ui
.lineEditCylinderZ0
->text().toDouble()));
113 extr
->SetAxis(vec3_t(m_Ui
.lineEditCylinderNX
->text().toDouble(),
114 m_Ui
.lineEditCylinderNY
->text().toDouble(),
115 m_Ui
.lineEditCylinderNZ
->text().toDouble()));
118 if (m_Ui
.radioButtonNoRestrict
->isChecked()) {
119 extr
->SetRestrictNone();
121 if (m_Ui
.radioButtonXY
->isChecked()) {
122 extr
->SetRestrictXY();
124 if (m_Ui
.radioButtonXZ
->isChecked()) {
125 extr
->SetRestrictXZ();
127 if (m_Ui
.radioButtonYZ
->isChecked()) {
128 extr
->SetRestrictYZ();
131 if (m_Ui
.checkBoxNewVolume
->isChecked()) {
132 extr
->SetRemoveInternalFacesOff();
135 QList
<VolumeDefinition
> vols
= GuiMainWindow::pointer()->getAllVols();
137 foreach (VolumeDefinition vol
, vols
) {
138 vc
= max(vc
, vol
.getVC());
140 if (m_Ui
.checkBoxNewVolume
->isChecked()) {
141 EG_FORALL_CELLS(id_cell
, m_Grid
) {
142 if (isVolume(id_cell
, m_Grid
)) {
143 if (cell_code
->GetValue(id_cell
) == 0) {
144 cell_code
->SetValue(id_cell
, vc
);
151 QSet
<int> old_bcs
= GuiMainWindow::pointer()->getAllBoundaryCodes();
152 extr
->SetBoundaryCodes(bcs
);
153 EG_VTKSP(vtkUnstructuredGrid
,ug
);
154 makeCopy(m_Grid
, ug
);
155 extr
->SetInputData(ug
);
157 makeCopy(extr
->GetOutput(), m_Grid
);
158 QSet
<int> new_bcs
= GuiMainWindow::pointer()->getAllBoundaryCodes();
160 if (m_Ui
.checkBoxNewVolume
->isChecked()) {
162 VolumeDefinition
new_vol(m_Ui
.lineEditVolumeName
->text(), vc
);
163 foreach (int bc
, new_bcs
) {
164 if (bcs
.contains(bc
)) {
165 new_vol
.addBC(bc
, -1);
166 } else if (!old_bcs
.contains(bc
)) {
167 new_vol
.addBC(bc
, 1);
170 vols
.append(new_vol
);
171 GuiMainWindow::pointer()->setAllVols(vols
);
172 EG_FORALL_CELLS(id_cell
, m_Grid
) {
173 if (isVolume(id_cell
, m_Grid
)) {
174 if (cell_code
->GetValue(id_cell
) == 0) {
175 cell_code
->SetValue(id_cell
, vc
);
180 if (volume_codes
.size() == 1) {
181 EG_FORALL_CELLS(id_cell
, m_Grid
) {
182 if (isVolume(id_cell
, m_Grid
)) {
183 if (cell_code
->GetValue(id_cell
) == 0) {
184 cell_code
->SetValue(id_cell
, *(volume_codes
.begin()));