feature magic defaults to 1 now
[engrid.git] / src / libengrid / guimirrormesh.cpp
blob28caffb9fdff6ac0aad3015edbf1d2182c881a5c
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2013 enGits GmbH +
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "guimirrormesh.h"
24 #include "guimainwindow.h"
26 void GuiMirrorMesh::operate()
28 vec3_t x0, n;
29 x0[0] = m_Ui.lineEditX0->text().toDouble();
30 x0[1] = m_Ui.lineEditY0->text().toDouble();
31 x0[2] = m_Ui.lineEditZ0->text().toDouble();
32 n[0] = m_Ui.lineEditNX->text().toDouble();
33 n[1] = m_Ui.lineEditNY->text().toDouble();
34 n[2] = m_Ui.lineEditNZ->text().toDouble();
35 n.normalise();
36 EG_VTKSP(vtkUnstructuredGrid, mirror_grid);
37 EgVtkObject::allocateGrid(mirror_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints());
38 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
39 vec3_t x;
40 m_Grid->GetPoint(id_node, x.data());
41 double h = n*(x-x0);
42 vec3_t xm = x - 2*h*n;
43 mirror_grid->GetPoints()->SetPoint(id_node, xm.data());
44 copyNodeData(m_Grid, id_node, mirror_grid, id_node);
46 vtkIdType id_new_cell;
47 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
48 vtkIdType N_pts, *pts;
49 m_Grid->GetCellPoints(id_cell, N_pts, pts);
50 QVector<vtkIdType> new_pts(N_pts);
51 vtkIdType cell_type = m_Grid->GetCellType(id_cell);
52 if (cell_type == VTK_TETRA) {
53 new_pts[0] = pts[0];
54 new_pts[1] = pts[1];
55 new_pts[2] = pts[3];
56 new_pts[3] = pts[2];
57 } else if (cell_type == VTK_WEDGE) {
58 new_pts[0] = pts[3];
59 new_pts[1] = pts[4];
60 new_pts[2] = pts[5];
61 new_pts[3] = pts[0];
62 new_pts[4] = pts[1];
63 new_pts[5] = pts[2];
64 } else if (cell_type == VTK_HEXAHEDRON) {
65 new_pts[0] = pts[4];
66 new_pts[1] = pts[5];
67 new_pts[2] = pts[6];
68 new_pts[3] = pts[7];
69 new_pts[4] = pts[0];
70 new_pts[5] = pts[1];
71 new_pts[6] = pts[2];
72 new_pts[7] = pts[3];
73 } else if (cell_type == VTK_PYRAMID) {
74 EG_BUG;
75 } else {
76 for (int i = 0; i < N_pts; ++i) {
77 new_pts[i] = pts[N_pts - i - 1];
80 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts.data());
81 copyCellData(m_Grid, id_cell, mirror_grid, id_new_cell);
83 MeshPartition part1(m_Grid, true);
84 MeshPartition part2(mirror_grid, true);
85 double tol = m_Ui.lineEditTolerance->text().toDouble();
86 if (m_Ui.radioButtonRelative->isChecked()) {
87 tol = -tol;
89 part1.addPartition(part2, tol);
90 m_Part.setAllCells();
91 eliminateDuplicateCells();
92 GuiMainWindow::pointer()->updateBoundaryCodes(false);