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 "surfacenodemovementcheck.h"
23 #include "geometrytools.h"
25 #include "vtkDelaunay3D.h"
26 #include "vtkXMLUnstructuredGridWriter.h"
27 #include "vtkKdTreePointLocator.h"
29 SurfaceNodeMovementCheck::SurfaceNodeMovementCheck()
31 m_AuxGrid
= vtkUnstructuredGrid::New();
35 SurfaceNodeMovementCheck::~SurfaceNodeMovementCheck()
40 void SurfaceNodeMovementCheck::setGrid(vtkUnstructuredGrid
*grid
)
43 EG_VTKSP(vtkUnstructuredGrid
, tmp_grid
);
44 allocateGrid(tmp_grid
, 1, m_Grid
->GetNumberOfPoints(), false);
47 EG_FORALL_NODES(id_node
, m_Grid
) {
48 m_Grid
->GetPoint(id_node
, x
.data());
49 tmp_grid
->GetPoints()->SetPoint(id_node
, x
.data());
52 EG_VTKSP(vtkDelaunay3D
, delaunay
);
53 delaunay
->SetInputData(tmp_grid
);
55 makeCopy(delaunay
->GetOutput(), m_AuxGrid
, false);
56 int N1
= m_Grid
->GetNumberOfPoints();
57 int N2
= m_AuxGrid
->GetNumberOfPoints();
61 EG_VTKSP(vtkKdTreePointLocator
, loc
);
62 loc
->SetDataSet(m_AuxGrid
);
64 m_IdMap
.resize(m_Grid
->GetNumberOfPoints());
65 EG_FORALL_NODES(id_node
, m_Grid
) {
67 m_Grid
->GetPoint(id_node
, x
.data());
68 vtkIdType id_aux_node
= id_node
;//loc->FindClosestPoint(x.data());
69 if (id_aux_node
< 0) {
72 m_IdMap
[id_node
] = id_aux_node
;
74 m_AuxPart
.setGrid(m_AuxGrid
);
75 m_AuxPart
.setAllCells();
77 QVector<vtkIdType> nodes(m_AuxGrid->GetNumberOfPoints());
78 EG_FORALL_NODES(id_aux_node, m_AuxGrid) {
79 nodes[id_aux_node] = id_aux_node;
81 m_AuxPart.setNodes(nodes);
84 EG_FORALL_NODES(id_aux_node
, m_AuxGrid
) {
85 if (m_AuxPart
.localNode(id_aux_node
) == -1) {
92 bool SurfaceNodeMovementCheck::checkNode(vtkIdType id_node
, vec3_t x
)
96 vtkIdType id_aux_node
= m_IdMap
[id_node
];
97 if (m_AuxPart
.localNode(id_aux_node
) == -1) {
100 m_AuxGrid
->GetPoints()->SetPoint(id_aux_node
, x
.data());
101 for (int i
= 0; i
< m_AuxPart
.n2cGSize(id_aux_node
); ++i
) {
102 vtkIdType id_aux_cell
= m_AuxPart
.n2cGG(id_aux_node
, i
);
103 double V
= GeometryTools::cellVA(m_AuxGrid
, id_aux_cell
);
110 m_AuxGrid
->GetPoints()->SetPoint(id_aux_node
, x_old
.data());
114 void SurfaceNodeMovementCheck::write(QString file_name
)
116 EG_VTKSP(vtkXMLUnstructuredGridWriter
, vtu
);
117 vtu
->SetFileName(qPrintable(file_name
+ ".vtu"));
118 vtu
->SetInputData(m_AuxGrid
);