Added basic compilation instructions to README.md
[engrid-github.git] / src / libengrid / guimirrormesh.cpp
blobbe6e5211769f06b8b7bb7dd2db6a3d1c6ad2961a
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 "guimirrormesh.h"
22 #include "guimainwindow.h"
24 void GuiMirrorMesh::operate()
26 vec3_t x0, n;
27 x0[0] = m_Ui.lineEditX0->text().toDouble();
28 x0[1] = m_Ui.lineEditY0->text().toDouble();
29 x0[2] = m_Ui.lineEditZ0->text().toDouble();
30 n[0] = m_Ui.lineEditNX->text().toDouble();
31 n[1] = m_Ui.lineEditNY->text().toDouble();
32 n[2] = m_Ui.lineEditNZ->text().toDouble();
33 n.normalise();
34 EG_VTKSP(vtkUnstructuredGrid, mirror_grid);
35 EgVtkObject::allocateGrid(mirror_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints());
36 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
37 vec3_t x;
38 m_Grid->GetPoint(id_node, x.data());
39 double h = n*(x-x0);
40 vec3_t xm = x - 2*h*n;
41 mirror_grid->GetPoints()->SetPoint(id_node, xm.data());
42 copyNodeData(m_Grid, id_node, mirror_grid, id_node);
44 vtkIdType id_new_cell;
45 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
46 vtkIdType N_pts, *pts;
47 m_Grid->GetCellPoints(id_cell, N_pts, pts);
48 QVector<vtkIdType> new_pts(N_pts);
49 vtkIdType cell_type = m_Grid->GetCellType(id_cell);
50 if (cell_type == VTK_TETRA) {
51 new_pts[0] = pts[0];
52 new_pts[1] = pts[1];
53 new_pts[2] = pts[3];
54 new_pts[3] = pts[2];
55 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts.data());
56 } else if (cell_type == VTK_WEDGE) {
57 new_pts[0] = pts[3];
58 new_pts[1] = pts[4];
59 new_pts[2] = pts[5];
60 new_pts[3] = pts[0];
61 new_pts[4] = pts[1];
62 new_pts[5] = pts[2];
63 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts.data());
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 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts.data());
74 } else if (cell_type == VTK_PYRAMID) {
75 EG_BUG;
76 } else if (cell_type == VTK_POLYHEDRON) {
77 QVector<QVector<vtkIdType> > faces(m_Part.c2cGSize(id_cell));
78 int stream_length = 1;
79 for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
80 getFaceOfCell(m_Grid, id_cell, i, faces[i]);
81 stream_length += faces[i].size() + 1;
83 EG_VTKSP(vtkIdList, stream);
84 stream->SetNumberOfIds(stream_length);
85 vtkIdType id = 0;
86 stream->SetId(id++, faces.size());
87 foreach (QVector<vtkIdType> face, faces) {
88 stream->SetId(id++, face.size());
89 QVectorIterator<vtkIdType> j(face);
90 j.toBack();
91 while (j.hasPrevious()) {
92 stream->SetId(id++, j.previous());
95 id_new_cell = mirror_grid->InsertNextCell(VTK_POLYHEDRON, stream);
96 } else {
97 for (int i = 0; i < N_pts; ++i) {
98 new_pts[i] = pts[N_pts - i - 1];
100 id_new_cell = mirror_grid->InsertNextCell(m_Grid->GetCellType(id_cell), N_pts, new_pts.data());
102 copyCellData(m_Grid, id_cell, mirror_grid, id_new_cell);
104 if (m_Ui.checkBoxKeepOriginal->isChecked()) {
105 MeshPartition mirror_part(mirror_grid, true);
106 MeshPartition part(m_Grid, true);
107 double tol = m_Ui.lineEditTolerance->text().toDouble();
108 if (tol >= 0) {
109 if (m_Ui.radioButtonRelative->isChecked()) {
110 tol = -tol;
112 part.addPartition(mirror_part, tol);
113 m_Part.setAllCells();
114 eliminateDuplicateCells();
115 } else {
116 addGrid(m_Grid, mirror_grid, m_Grid->GetNumberOfPoints());
118 GuiMainWindow::pointer()->updateBoundaryCodes(false);
119 } else {
120 makeCopy(mirror_grid, m_Grid);