updated to modern VTK
[engrid-github.git] / src / libengrid / surfacenodemovementcheck.cpp
blob3a754ca4bad517b8d36974d9e63dfdbab3bc9840
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 "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();
32 m_Grid = NULL;
35 SurfaceNodeMovementCheck::~SurfaceNodeMovementCheck()
37 m_AuxGrid->Delete();
40 void SurfaceNodeMovementCheck::setGrid(vtkUnstructuredGrid *grid)
42 m_Grid = grid;
43 EG_VTKSP(vtkUnstructuredGrid, tmp_grid);
44 allocateGrid(tmp_grid, 1, m_Grid->GetNumberOfPoints(), false);
46 vec3_t x;
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);
54 delaunay->Update();
55 makeCopy(delaunay->GetOutput(), m_AuxGrid, false);
56 int N1 = m_Grid->GetNumberOfPoints();
57 int N2 = m_AuxGrid->GetNumberOfPoints();
58 if (N1 != N2) {
59 EG_BUG;
61 EG_VTKSP(vtkKdTreePointLocator, loc);
62 loc->SetDataSet(m_AuxGrid);
63 loc->BuildLocator();
64 m_IdMap.resize(m_Grid->GetNumberOfPoints());
65 EG_FORALL_NODES(id_node, m_Grid) {
66 vec3_t x;
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) {
70 EG_BUG;
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);
83 int N3 = 0;
84 EG_FORALL_NODES(id_aux_node, m_AuxGrid) {
85 if (m_AuxPart.localNode(id_aux_node) == -1) {
86 ++N3;
89 cout << N3 << endl;
92 bool SurfaceNodeMovementCheck::checkNode(vtkIdType id_node, vec3_t x)
94 bool good = true;
95 vec3_t x_old = x;
96 vtkIdType id_aux_node = m_IdMap[id_node];
97 if (m_AuxPart.localNode(id_aux_node) == -1) {
98 good = false;
99 } else {
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);
104 if (V < 0) {
105 good = false;
106 break;
110 m_AuxGrid->GetPoints()->SetPoint(id_aux_node, x_old.data());
111 return good;
114 void SurfaceNodeMovementCheck::write(QString file_name)
116 EG_VTKSP(vtkXMLUnstructuredGridWriter, vtu);
117 vtu->SetFileName(qPrintable(file_name + ".vtu"));
118 vtu->SetInputData(m_AuxGrid);
119 vtu->Write();