vtk 5.2 -> 5.4 in setup_paths.sh
[engrid.git] / src / guitransform.cpp
blob21bfaa6b3450f52a9d3b960b7be8ef4c45f72786
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 "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 <cmath>
31 #include "geometrytools.h"
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 ui.tabWidget->setCurrentIndex(0);
44 ui.lineEdit_Translation_X->setText("0");
45 ui.lineEdit_Translation_Y->setText("0");
46 ui.lineEdit_Translation_Z->setText("0");
48 ui.lineEdit_Rotation_Origin_X->setText("0");
49 ui.lineEdit_Rotation_Origin_Y->setText("0");
50 ui.lineEdit_Rotation_Origin_Z->setText("0");
51 ui.lineEdit_Rotation_Direction_X->setText("1");
52 ui.lineEdit_Rotation_Direction_Y->setText("0");
53 ui.lineEdit_Rotation_Direction_Z->setText("0");
54 ui.lineEdit_Rotation_Angle->setText("0");
55 ui.AngleInDegrees->setCheckState(Qt::Checked);
57 ui.lineEdit_Scaling_X->setText("1");
58 ui.lineEdit_Scaling_Y->setText("1");
59 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( ( ui.lineEdit_Translation_X->text()).toDouble(),
73 ( ui.lineEdit_Translation_Y->text()).toDouble(),
74 ( ui.lineEdit_Translation_Z->text()).toDouble());
76 //Rotation
77 vec3_t Rotation_Origin_Vector( ( ui.lineEdit_Rotation_Origin_X->text()).toDouble(),
78 ( ui.lineEdit_Rotation_Origin_Y->text()).toDouble(),
79 ( ui.lineEdit_Rotation_Origin_Z->text()).toDouble());
80 vec3_t Rotation_Direction_Vector( ( ui.lineEdit_Rotation_Direction_X->text()).toDouble(),
81 ( ui.lineEdit_Rotation_Direction_Y->text()).toDouble(),
82 ( ui.lineEdit_Rotation_Direction_Z->text()).toDouble());
83 double Rotation_Angle = ( ui.lineEdit_Rotation_Angle->text()).toDouble();
84 if(ui.AngleInDegrees->checkState()) Rotation_Angle=deg2rad(Rotation_Angle);
86 //Scaling
87 vec3_t Scaling_Vector( ( ui.lineEdit_Scaling_X->text()).toDouble(),
88 ( ui.lineEdit_Scaling_Y->text()).toDouble(),
89 ( 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=" << ui.AngleInDegrees->checkState() << endl;
97 cout << "Scaling_Vector=" << Scaling_Vector << endl;
99 foreach(vtkIdType id_node, nodes)
101 vec3_t x;
102 m_Grid->GetPoint(id_node, x.data());
104 x[0]+=Translation_Vector[0];
105 x[1]+=Translation_Vector[1];
106 x[2]+=Translation_Vector[2];
108 Rotation_Direction_Vector.normalise();
109 x = Rotation_Origin_Vector + GeometryTools::rotate(x-Rotation_Origin_Vector,Rotation_Direction_Vector,Rotation_Angle);
111 x[0]*=Scaling_Vector[0];
112 x[1]*=Scaling_Vector[1];
113 x[2]*=Scaling_Vector[2];
115 m_Grid->GetPoints()->SetPoint(id_node, x.data());
117 m_Grid->Modified();// to force a drawing update