1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "guimirrormesh.h"
22 #include "guimainwindow.h"
24 void GuiMirrorMesh::operate()
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();
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
) {
38 m_Grid
->GetPoint(id_node
, x
.data());
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
) {
55 id_new_cell
= mirror_grid
->InsertNextCell(m_Grid
->GetCellType(id_cell
), N_pts
, new_pts
.data());
56 } else if (cell_type
== VTK_WEDGE
) {
63 id_new_cell
= mirror_grid
->InsertNextCell(m_Grid
->GetCellType(id_cell
), N_pts
, new_pts
.data());
64 } else if (cell_type
== VTK_HEXAHEDRON
) {
73 id_new_cell
= mirror_grid
->InsertNextCell(m_Grid
->GetCellType(id_cell
), N_pts
, new_pts
.data());
74 } else if (cell_type
== VTK_PYRAMID
) {
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
);
86 stream
->SetId(id
++, faces
.size());
87 foreach (QVector
<vtkIdType
> face
, faces
) {
88 stream
->SetId(id
++, face
.size());
89 QVectorIterator
<vtkIdType
> j(face
);
91 while (j
.hasPrevious()) {
92 stream
->SetId(id
++, j
.previous());
95 id_new_cell
= mirror_grid
->InsertNextCell(VTK_POLYHEDRON
, stream
);
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();
109 if (m_Ui
.radioButtonRelative
->isChecked()) {
112 part
.addPartition(mirror_part
, tol
);
113 m_Part
.setAllCells();
114 eliminateDuplicateCells();
116 addGrid(m_Grid
, mirror_grid
, m_Grid
->GetNumberOfPoints());
118 GuiMainWindow::pointer()->updateBoundaryCodes(false);
120 makeCopy(mirror_grid
, m_Grid
);