updated to modern VTK
[engrid-github.git] / src / libengrid / deletestraynodes.cpp
blob2d7590a4da55babb2176bc22e76c5717264a3110
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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "deletestraynodes.h"
23 DeleteStrayNodes::DeleteStrayNodes()
25 EG_TYPENAME;
28 void DeleteStrayNodes::operate()
30 if (m_Verbose) {
31 cout << "removing 'stray' nodes" << endl;
33 QVector<bool> active(m_Grid->GetNumberOfPoints(), false);
34 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
35 EG_GET_CELL(id_cell, m_Grid);
36 for (int i = 0; i < num_pts; ++i) {
37 active[pts[i]] = true;
40 int N = 0;
41 foreach (bool is_active, active) {
42 if (!is_active) {
43 ++N;
46 if (m_Verbose) {
47 if (N == 1) {
48 cout << "deleting 1 node!" << endl;
49 } else {
50 cout << "deleting " << N << " nodes!" << endl;
53 QVector<int> offset(m_Grid->GetNumberOfPoints(), 0);
54 for (vtkIdType id_node = 1; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
55 if (!active[id_node]) {
56 offset[id_node] = offset[id_node-1] + 1;
57 } else {
58 offset[id_node] = offset[id_node-1];
61 EG_VTKSP(vtkUnstructuredGrid, new_grid);
62 allocateGrid(new_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints()-N);
63 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
64 if (active[id_node]) {
65 vec3_t x;
66 m_Grid->GetPoint(id_node, x.data());
67 new_grid->GetPoints()->SetPoint(id_node - offset[id_node], x.data());
68 copyNodeData(m_Grid, id_node, new_grid, id_node - offset[id_node]);
71 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
72 EG_GET_CELL(id_cell, m_Grid);
73 QVector<vtkIdType> new_pts(num_pts);
74 for (int i = 0; i < num_pts; ++i) {
75 new_pts[i] = pts[i] - offset[pts[i]];
77 vtkIdType id_new_cell = new_grid->InsertNextCell(type_cell, num_pts, new_pts.data());
78 copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
80 makeCopy(new_grid, m_Grid);