limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / guimirrormesh.cpp
blobb05ecdb930ffecb561f94d363857d45ae163a42c
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 "engrid.h"
23 #include "guimainwindow.h"
24 #include <vtkIdList.h>
25 #include <vtkSmartPointer.h>
27 void GuiMirrorMesh::operate()
29 vec3_t x0, n;
30 x0[0] = m_Ui.lineEditX0->text().toDouble();
31 x0[1] = m_Ui.lineEditY0->text().toDouble();
32 x0[2] = m_Ui.lineEditZ0->text().toDouble();
33 n[0] = m_Ui.lineEditNX->text().toDouble();
34 n[1] = m_Ui.lineEditNY->text().toDouble();
35 n[2] = m_Ui.lineEditNZ->text().toDouble();
36 n.normalise();
37 EG_VTKSP(vtkUnstructuredGrid, mirror_grid);
38 EgVtkObject::allocateGrid(mirror_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints());
39 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
40 vec3_t x;
41 m_Grid->GetPoint(id_node, x.data());
42 double h = n*(x-x0);
43 vec3_t xm = x - 2*h*n;
44 mirror_grid->GetPoints()->SetPoint(id_node, xm.data());
45 copyNodeData(m_Grid, id_node, mirror_grid, id_node);
47 vtkIdType id_new_cell;
48 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
49 EG_GET_CELL(id_cell, m_Grid);
50 vtkSmartPointer<vtkIdList> new_pts = vtkSmartPointer<vtkIdList>::New();
51 new_pts->SetNumberOfIds(num_pts);
52 if (type_cell == VTK_TETRA) {
53 new_pts->SetId(0, pts[0]);
54 new_pts->SetId(1, pts[1]);
55 new_pts->SetId(2, pts[3]);
56 new_pts->SetId(3, pts[2]);
57 id_new_cell = mirror_grid->InsertNextCell(type_cell, new_pts);
58 } else if (type_cell == VTK_WEDGE) {
59 new_pts->SetId(0, pts[3]);
60 new_pts->SetId(1, pts[4]);
61 new_pts->SetId(2, pts[5]);
62 new_pts->SetId(3, pts[0]);
63 new_pts->SetId(4, pts[1]);
64 new_pts->SetId(5, pts[2]);
65 id_new_cell = mirror_grid->InsertNextCell(type_cell, new_pts);
66 } else if (type_cell == VTK_HEXAHEDRON) {
67 new_pts->SetId(0, pts[4]);
68 new_pts->SetId(1, pts[5]);
69 new_pts->SetId(2, pts[6]);
70 new_pts->SetId(3, pts[7]);
71 new_pts->SetId(4, pts[0]);
72 new_pts->SetId(5, pts[1]);
73 new_pts->SetId(6, pts[2]);
74 new_pts->SetId(7, pts[3]);
75 id_new_cell = mirror_grid->InsertNextCell(type_cell, new_pts);
76 } else if (type_cell == VTK_PYRAMID) {
77 EG_BUG;
78 } else if (type_cell == VTK_POLYHEDRON) {
79 QVector<QVector<vtkIdType> > faces(m_Part.c2cGSize(id_cell));
80 int stream_length = 1;
81 for (int i = 0; i < m_Part.c2cGSize(id_cell); ++i) {
82 getFaceOfCell(m_Grid, id_cell, i, faces[i]);
83 stream_length += faces[i].size() + 1;
85 EG_VTKSP(vtkIdList, stream);
86 stream->SetNumberOfIds(stream_length);
87 vtkIdType id = 0;
88 stream->SetId(id++, faces.size());
89 foreach (QVector<vtkIdType> face, faces) {
90 stream->SetId(id++, face.size());
91 QVectorIterator<vtkIdType> j(face);
92 j.toBack();
93 while (j.hasPrevious()) {
94 stream->SetId(id++, j.previous());
97 id_new_cell = mirror_grid->InsertNextCell(VTK_POLYHEDRON, stream);
98 } else {
99 for (int i = 0; i < num_pts; ++i) {
100 new_pts->SetId(i, num_pts - i - 1);
102 id_new_cell = mirror_grid->InsertNextCell(type_cell, new_pts);
104 copyCellData(m_Grid, id_cell, mirror_grid, id_new_cell);
106 if (m_Ui.checkBoxKeepOriginal->isChecked()) {
107 MeshPartition mirror_part(mirror_grid, true);
108 MeshPartition part(m_Grid, true);
109 double tol = m_Ui.lineEditTolerance->text().toDouble();
110 if (tol >= 0) {
111 if (m_Ui.radioButtonRelative->isChecked()) {
112 tol = -tol;
114 part.addPartition(mirror_part, tol);
115 m_Part.setAllCells();
116 eliminateDuplicateCells();
117 } else {
118 addGrid(m_Grid, mirror_grid, m_Grid->GetNumberOfPoints());
120 GuiMainWindow::pointer()->updateBoundaryCodes(false);
121 } else {
122 makeCopy(mirror_grid, m_Grid);