compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / snaptofeatures.cpp
blobb4db10d49f0017478733aeab3c981e56b6f4b965
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 #include "snaptofeatures.h"
23 #include "guimainwindow.h"
25 SnapToFeatures::SnapToFeatures()
29 void SnapToFeatures::snapIteration()
31 EG_VTKDCN(vtkCharArray, node_type, m_Grid, "node_type");
32 QVector<bool> node_blocked = m_NodeSnapped;
33 foreach (vtkIdType id_node, m_Part.getNodes()) {
34 if (!node_blocked[id_node]) {
35 --m_NodesToSnap;
36 if (node_type->GetValue(id_node) == EG_SIMPLE_VERTEX && m_Part.n2bcGSize(id_node) == 1) {
37 CadInterface *cad = GuiMainWindow::pointer()->getCadInterface(m_Part.n2bcG(id_node, 0));
38 vec3_t x;
39 m_Grid->GetPoint(id_node, x.data());
40 vec3_t x_snap = cad->snapToEdge(x);
41 QVector<vec3_t> normals(m_Part.n2cGSize(id_node));
42 for (int i = 0; i < m_Part.n2cGSize(id_node); ++i) {
43 normals[i] = cellNormal(m_Grid, m_Part.n2cGG(id_node, i));
45 m_Grid->GetPoints()->SetPoint(id_node, x_snap.data());
46 bool no_feature = false;
47 for (int i = 0; i < m_Part.n2cGSize(id_node); ++i) {
48 vec3_t n = cellNormal(m_Grid, m_Part.n2cGG(id_node, i));
49 if (GeometryTools::angle(normals[i], n) > 0.5*M_PI) {
50 no_feature = true;
51 break;
54 node_blocked[id_node] = true;
55 m_NodeSnapped[id_node] = true;
56 if (no_feature) {
57 m_Grid->GetPoints()->SetPoint(id_node, x.data());
58 } else {
59 for (int i = 0; i < m_Part.n2nGSize(id_node); ++i) {
60 vtkIdType id_neigh = m_Part.n2nGSize(id_node);
61 node_blocked[id_neigh] = true;
62 m_NodeSnapped[id_neigh] = true;
63 --m_NodesToSnap;
71 void SnapToFeatures::operate()
73 m_NodeSnapped.fill(false, m_Grid->GetNumberOfPoints());
74 m_NodesToSnap = m_Part.getNumberOfNodes();
75 while (m_NodesToSnap > 0) {
76 snapIteration();