2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2013 enGits GmbH +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "guitransform.h"
24 #include "seedsimpleprismaticlayer.h"
25 #include "gridsmoother.h"
26 #include "createvolumemesh.h"
27 #include "swaptriangles.h"
28 #include "deletetetras.h"
29 #include "deletecells.h"
30 #include "geometrytools.h"
31 #include "guimainwindow.h"
35 using namespace GeometryTools
;
37 /** Set default values */
38 void GuiTransform::before()
40 cout
<<"======================================"<<endl
;
41 cout
<<"void GuiTransform::before()"<<endl
;
42 cout
<<"======================================"<<endl
;
44 m_Ui
.tabWidget
->setCurrentIndex(0);
46 m_Ui
.lineEdit_Translation_X
->setText("0");
47 m_Ui
.lineEdit_Translation_Y
->setText("0");
48 m_Ui
.lineEdit_Translation_Z
->setText("0");
50 m_Ui
.lineEdit_Rotation_Origin_X
->setText("0");
51 m_Ui
.lineEdit_Rotation_Origin_Y
->setText("0");
52 m_Ui
.lineEdit_Rotation_Origin_Z
->setText("0");
53 m_Ui
.lineEdit_Rotation_Direction_X
->setText("1");
54 m_Ui
.lineEdit_Rotation_Direction_Y
->setText("0");
55 m_Ui
.lineEdit_Rotation_Direction_Z
->setText("0");
56 m_Ui
.lineEdit_Rotation_Angle
->setText("0");
57 m_Ui
.AngleInDegrees
->setCheckState(Qt::Checked
);
59 m_Ui
.lineEdit_Scaling_X
->setText("1");
60 m_Ui
.lineEdit_Scaling_Y
->setText("1");
61 m_Ui
.lineEdit_Scaling_Z
->setText("1");
64 /** Apply transformations to the grid ( scaling, translation, rotation ) */
65 void GuiTransform::operate()
67 l2g_t nodes
= getPartNodes();
69 cout
<<"======================================"<<endl
;
70 cout
<<"void GuiTransform::operate()"<<endl
;
71 cout
<<"======================================"<<endl
;
74 vec3_t
Translation_Vector( ( m_Ui
.lineEdit_Translation_X
->text()).toDouble(),
75 ( m_Ui
.lineEdit_Translation_Y
->text()).toDouble(),
76 ( m_Ui
.lineEdit_Translation_Z
->text()).toDouble());
79 vec3_t
Rotation_Origin_Vector( ( m_Ui
.lineEdit_Rotation_Origin_X
->text()).toDouble(),
80 ( m_Ui
.lineEdit_Rotation_Origin_Y
->text()).toDouble(),
81 ( m_Ui
.lineEdit_Rotation_Origin_Z
->text()).toDouble());
82 vec3_t
Rotation_Direction_Vector( ( m_Ui
.lineEdit_Rotation_Direction_X
->text()).toDouble(),
83 ( m_Ui
.lineEdit_Rotation_Direction_Y
->text()).toDouble(),
84 ( m_Ui
.lineEdit_Rotation_Direction_Z
->text()).toDouble());
85 double Rotation_Angle
= ( m_Ui
.lineEdit_Rotation_Angle
->text()).toDouble();
86 if(m_Ui
.AngleInDegrees
->checkState()) Rotation_Angle
=deg2rad(Rotation_Angle
);
89 vec3_t
Scaling_Vector( ( m_Ui
.lineEdit_Scaling_X
->text()).toDouble(),
90 ( m_Ui
.lineEdit_Scaling_Y
->text()).toDouble(),
91 ( m_Ui
.lineEdit_Scaling_Z
->text()).toDouble());
93 cout
<< "nodes.size()=" << nodes
.size() << endl
;
94 cout
<< "Translation_Vector=" << Translation_Vector
<< endl
;
95 cout
<< "Rotation_Origin_Vector=" << Rotation_Origin_Vector
<< endl
;
96 cout
<< "Rotation_Direction_Vector=" << Rotation_Direction_Vector
<< endl
;
97 cout
<< "Rotation_Angle=" << Rotation_Angle
<< endl
;
98 cout
<< "AngleInDegrees=" << m_Ui
.AngleInDegrees
->checkState() << endl
;
99 cout
<< "Scaling_Vector=" << Scaling_Vector
<< endl
;
101 QVector
<bool> transform_node(nodes
.size(), false);
102 EG_VTKDCC(vtkIntArray
, cell_code
, m_Grid
, "cell_code");
104 if (m_Ui
.radioButtonNoRestriction
->isChecked()) {
105 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
106 transform_node
[i_nodes
] = true;
110 if (m_Ui
.radioButtonVolumeAreas
->isChecked()) {
111 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
112 for (int j
= 0; j
< m_Part
.n2cLSize(i_nodes
); ++j
) {
113 vtkIdType id_cell
= m_Part
.n2cLG(i_nodes
, j
);
114 if (isVolume(id_cell
, m_Grid
)) {
115 transform_node
[i_nodes
] = true;
122 if (m_Ui
.radioButtonVisibleBoundaries
->isChecked()) {
124 GuiMainWindow::pointer()->getDisplayBoundaryCodes(bcs
);
125 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
126 for (int j
= 0; j
< m_Part
.n2cLSize(i_nodes
); ++j
) {
127 vtkIdType id_cell
= m_Part
.n2cLG(i_nodes
, j
);
128 if (isSurface(id_cell
, m_Grid
)) {
129 if (bcs
.contains(cell_code
->GetValue(id_cell
))) {
130 transform_node
[i_nodes
] = true;
138 for (int i_nodes
= 0; i_nodes
< nodes
.size(); ++i_nodes
) {
139 if (transform_node
[i_nodes
]) {
140 vtkIdType id_node
= nodes
[i_nodes
];
142 m_Grid
->GetPoint(id_node
, x
.data());
144 x
[0]+=Translation_Vector
[0];
145 x
[1]+=Translation_Vector
[1];
146 x
[2]+=Translation_Vector
[2];
148 Rotation_Direction_Vector
.normalise();
149 x
= Rotation_Origin_Vector
+ GeometryTools::rotate(x
-Rotation_Origin_Vector
,Rotation_Direction_Vector
,Rotation_Angle
);
151 x
[0]*=Scaling_Vector
[0];
152 x
[1]*=Scaling_Vector
[1];
153 x
[2]*=Scaling_Vector
[2];
155 m_Grid
->GetPoints()->SetPoint(id_node
, x
.data());
158 m_Grid
->Modified();// to force a drawing update