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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
]) {
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));
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
) {
54 node_blocked
[id_node
] = true;
55 m_NodeSnapped
[id_node
] = true;
57 m_Grid
->GetPoints()->SetPoint(id_node
, x
.data());
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;
71 void SnapToFeatures::operate()
73 m_NodeSnapped
.fill(false, m_Grid
->GetNumberOfPoints());
74 m_NodesToSnap
= m_Part
.getNumberOfNodes();
75 while (m_NodesToSnap
> 0) {