implemented mirror mesh, still not working for vol. cells
[engrid.git] / src / guimirrormesh.cpp
blobcbd9897ea4621b8209aafe3b1be195964523e123
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2010 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 "guimirrormesh.h"
25 void GuiMirrorMesh::operate()
27 vec3_t x0, n;
28 x0[0] = ui.lineEditX0->text().toDouble();
29 x0[1] = ui.lineEditY0->text().toDouble();
30 x0[2] = ui.lineEditZ0->text().toDouble();
31 n[0] = ui.lineEditNX->text().toDouble();
32 n[1] = ui.lineEditNY->text().toDouble();
33 n[2] = ui.lineEditNZ->text().toDouble();
34 n.normalise();
35 EG_VTKSP(vtkUnstructuredGrid, mirror_grid);
36 EgVtkObject::allocateGrid(mirror_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints());
37 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
38 vec3_t x;
39 m_Grid->GetPoint(id_node, x.data());
40 double h = n*(x-x0);
41 vec3_t xm = x - 2*h*n;
42 mirror_grid->GetPoints()->SetPoint(id_node, xm.data());
43 copyNodeData(m_Grid, id_node, mirror_grid, id_node);
45 vtkIdType id_new_cell;
46 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
47 vtkIdType N_pts, *pts;
48 m_Grid->GetCellPoints(id_cell, N_pts, pts);
49 vtkIdType new_pts[N_pts];
50 vtkIdType cell_type = m_Grid->GetCellType(id_cell);
51 if (cell_type == VTK_WEDGE) {
52 new_pts[0] = pts[3];
53 new_pts[1] = pts[4];
54 new_pts[2] = pts[5];
55 new_pts[3] = pts[0];
56 new_pts[4] = pts[1];
57 new_pts[5] = pts[2];
58 } else if (cell_type == VTK_HEXAHEDRON) {
59 new_pts[0] = pts[4];
60 new_pts[1] = pts[5];
61 new_pts[2] = pts[6];
62 new_pts[3] = pts[7];
63 new_pts[4] = pts[0];
64 new_pts[5] = pts[1];
65 new_pts[6] = pts[2];
66 new_pts[7] = pts[3];
67 } else if (cell_type == VTK_PYRAMID) {
68 EG_BUG;
69 } else {
70 for (int i = 0; i < N_pts; ++i) {
71 new_pts[i] = pts[N_pts - i - 1];
74 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts);
75 copyCellData(m_Grid, id_cell, mirror_grid, id_new_cell);
77 MeshPartition part1(m_Grid, true);
78 MeshPartition part2(mirror_grid, true);
79 part1.addPartition(part2);
80 eliminateDuplicateCells();