compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / guitransform.cpp
blob59d080efdf6a32d773addb7fddd28f4e2f62d2a6
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "guitransform.h"
22 #include "seedsimpleprismaticlayer.h"
23 #include "gridsmoother.h"
24 #include "createvolumemesh.h"
25 #include "swaptriangles.h"
26 #include "deletetetras.h"
27 #include "deletecells.h"
28 #include "geometrytools.h"
29 #include "guimainwindow.h"
31 #include <cmath>
33 using namespace GeometryTools;
35 /** Set default values */
36 void GuiTransform::before()
38 cout<<"======================================"<<endl;
39 cout<<"void GuiTransform::before()"<<endl;
40 cout<<"======================================"<<endl;
42 m_Ui.tabWidget->setCurrentIndex(0);
44 m_Ui.lineEdit_Translation_X->setText("0");
45 m_Ui.lineEdit_Translation_Y->setText("0");
46 m_Ui.lineEdit_Translation_Z->setText("0");
48 m_Ui.lineEdit_Rotation_Origin_X->setText("0");
49 m_Ui.lineEdit_Rotation_Origin_Y->setText("0");
50 m_Ui.lineEdit_Rotation_Origin_Z->setText("0");
51 m_Ui.lineEdit_Rotation_Direction_X->setText("1");
52 m_Ui.lineEdit_Rotation_Direction_Y->setText("0");
53 m_Ui.lineEdit_Rotation_Direction_Z->setText("0");
54 m_Ui.lineEdit_Rotation_Angle->setText("0");
55 m_Ui.AngleInDegrees->setCheckState(Qt::Checked);
57 m_Ui.lineEdit_Scaling_X->setText("1");
58 m_Ui.lineEdit_Scaling_Y->setText("1");
59 m_Ui.lineEdit_Scaling_Z->setText("1");
62 /** Apply transformations to the grid ( scaling, translation, rotation ) */
63 void GuiTransform::operate()
65 l2g_t nodes = getPartNodes();
67 cout<<"======================================"<<endl;
68 cout<<"void GuiTransform::operate()"<<endl;
69 cout<<"======================================"<<endl;
71 //Translation
72 vec3_t Translation_Vector( ( m_Ui.lineEdit_Translation_X->text()).toDouble(),
73 ( m_Ui.lineEdit_Translation_Y->text()).toDouble(),
74 ( m_Ui.lineEdit_Translation_Z->text()).toDouble());
76 //Rotation
77 vec3_t Rotation_Origin_Vector( ( m_Ui.lineEdit_Rotation_Origin_X->text()).toDouble(),
78 ( m_Ui.lineEdit_Rotation_Origin_Y->text()).toDouble(),
79 ( m_Ui.lineEdit_Rotation_Origin_Z->text()).toDouble());
80 vec3_t Rotation_Direction_Vector( ( m_Ui.lineEdit_Rotation_Direction_X->text()).toDouble(),
81 ( m_Ui.lineEdit_Rotation_Direction_Y->text()).toDouble(),
82 ( m_Ui.lineEdit_Rotation_Direction_Z->text()).toDouble());
83 double Rotation_Angle = ( m_Ui.lineEdit_Rotation_Angle->text()).toDouble();
84 if(m_Ui.AngleInDegrees->checkState()) Rotation_Angle=deg2rad(Rotation_Angle);
86 //Scaling
87 vec3_t Scaling_Vector( ( m_Ui.lineEdit_Scaling_X->text()).toDouble(),
88 ( m_Ui.lineEdit_Scaling_Y->text()).toDouble(),
89 ( m_Ui.lineEdit_Scaling_Z->text()).toDouble());
91 cout << "nodes.size()=" << nodes.size() << endl;
92 cout << "Translation_Vector=" << Translation_Vector << endl;
93 cout << "Rotation_Origin_Vector=" << Rotation_Origin_Vector << endl;
94 cout << "Rotation_Direction_Vector=" << Rotation_Direction_Vector << endl;
95 cout << "Rotation_Angle=" << Rotation_Angle << endl;
96 cout << "AngleInDegrees=" << m_Ui.AngleInDegrees->checkState() << endl;
97 cout << "Scaling_Vector=" << Scaling_Vector << endl;
99 QVector<bool> transform_node(nodes.size(), false);
100 EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
102 if (m_Ui.radioButtonNoRestriction->isChecked()) {
103 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
104 transform_node[i_nodes] = true;
108 if (m_Ui.radioButtonVolumeAreas->isChecked()) {
109 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
110 for (int j = 0; j < m_Part.n2cLSize(i_nodes); ++j) {
111 vtkIdType id_cell = m_Part.n2cLG(i_nodes, j);
112 if (isVolume(id_cell, m_Grid)) {
113 transform_node[i_nodes] = true;
114 break;
120 if (m_Ui.radioButtonVisibleBoundaries->isChecked()) {
121 QSet<int> bcs;
122 GuiMainWindow::pointer()->getDisplayBoundaryCodes(bcs);
123 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
124 for (int j = 0; j < m_Part.n2cLSize(i_nodes); ++j) {
125 vtkIdType id_cell = m_Part.n2cLG(i_nodes, j);
126 if (isSurface(id_cell, m_Grid)) {
127 if (bcs.contains(cell_code->GetValue(id_cell))) {
128 transform_node[i_nodes] = true;
129 break;
136 for (int i_nodes = 0; i_nodes < nodes.size(); ++i_nodes) {
137 if (transform_node[i_nodes]) {
138 vtkIdType id_node = nodes[i_nodes];
139 vec3_t x;
140 m_Grid->GetPoint(id_node, x.data());
142 x[0]+=Translation_Vector[0];
143 x[1]+=Translation_Vector[1];
144 x[2]+=Translation_Vector[2];
146 Rotation_Direction_Vector.normalise();
147 x = Rotation_Origin_Vector + GeometryTools::rotate(x-Rotation_Origin_Vector,Rotation_Direction_Vector,Rotation_Angle);
149 x[0]*=Scaling_Vector[0];
150 x[1]*=Scaling_Vector[1];
151 x[2]*=Scaling_Vector[2];
153 m_Grid->GetPoints()->SetPoint(id_node, x.data());
156 m_Grid->Modified();// to force a drawing update