compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / padsurface.cpp
blob9f95eae8c451564bb4235c09256ce6ac6e89f7fd
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2016 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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "padsurface.h"
23 #include "meshpartition.h"
24 #include "geometrytools.h"
26 PadSurface::PadSurface()
28 m_Relative = true;
29 m_Distance = 1.0;
30 m_NewBC = 99;
33 void PadSurface::operate()
35 MeshPartition part(m_Grid);
36 part.setBCs(m_BCs);
37 QList<QVector<vec3_t> > quads;
38 foreach (vtkIdType id_cell, part.getCells()) {
39 vec3_t n = GeometryTools::cellNormal(m_Grid, id_cell);
40 n.normalise();
41 EG_GET_CELL(id_cell, m_Grid);
42 QVector<vec3_t> x(num_pts + 1);
43 for (int i = 0; i < num_pts; ++i) {
44 m_Grid->GetPoint(pts[i], x[i].data());
46 x[num_pts] = x[0];
47 for (int i = 0; i < num_pts; ++i) {
48 if (part.c2cGG(id_cell, i) < 0) {
49 vec3_t b = x[i+1] - x[i];
50 double L = m_Distance;
51 if (m_Relative) {
52 L = b.abs();
54 b.normalise();
55 vec3_t a = b.cross(n);
56 QVector<vec3_t> xn(4);
57 xn[0] = x[i] - L*b;
58 xn[1] = x[i] - L*b + L*a;
59 xn[2] = x[i+1] + L*b + L*a;
60 xn[3] = x[i+1] + L*b;
61 quads << xn;
65 EG_VTKSP(vtkUnstructuredGrid, grid);
66 allocateGrid(grid, quads.size(), 4*quads.size());
67 vtkIdType start_id = 0;
68 vtkIdType pts[4];
69 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
70 foreach (QVector<vec3_t> quad, quads) {
71 for (int i = 0; i < 4; ++i) {
72 grid->GetPoints()->SetPoint(start_id + i, quad[i].data());
73 pts[i] = start_id + i;
75 vtkIdType id_cell = grid->InsertNextCell(VTK_QUAD, 4, pts);
76 cell_code->SetValue(id_cell, m_NewBC);
77 start_id += 4;
79 MeshPartition new_part(grid, true);
80 part.concatenatePartition(new_part);