added sphere tutorial
[engrid.git] / src / deletestraynodes.cpp
blobf1d07f6baf5ebedc41021d283f45667c80271e6e
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2010 enGits GmbH +
7 // + +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
12 // + +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
17 // + +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "deletestraynodes.h"
25 DeleteStrayNodes::DeleteStrayNodes()
27 EG_TYPENAME;
30 void DeleteStrayNodes::operate()
32 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 vtkIdType N_pts, *pts;
36 m_Grid->GetCellPoints(id_cell, N_pts, pts);
37 for (int i = 0; i < N_pts; ++i) {
38 active[pts[i]] = true;
41 int N = 0;
42 foreach (bool is_active, active) {
43 if (!is_active) {
44 ++N;
47 if (N == 1) {
48 cout << "deleting 1 node!" << endl;
49 } else {
50 cout << "deleting " << N << " nodes!" << endl;
52 QVector<int> offset(m_Grid->GetNumberOfPoints(), 0);
53 for (vtkIdType id_node = 1; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
54 if (!active[id_node]) {
55 offset[id_node] = offset[id_node-1] + 1;
56 } else {
57 offset[id_node] = offset[id_node-1];
60 EG_VTKSP(vtkUnstructuredGrid, new_grid);
61 allocateGrid(new_grid, m_Grid->GetNumberOfCells(), m_Grid->GetNumberOfPoints()-N);
62 for (vtkIdType id_node = 0; id_node < m_Grid->GetNumberOfPoints(); ++id_node) {
63 if (active[id_node]) {
64 vec3_t x;
65 m_Grid->GetPoint(id_node, x.data());
66 new_grid->GetPoints()->SetPoint(id_node - offset[id_node], x.data());
67 copyNodeData(m_Grid, id_node, new_grid, id_node - offset[id_node]);
70 for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
71 vtkIdType N_pts, *pts, type;
72 m_Grid->GetCellPoints(id_cell, N_pts, pts);
73 type = m_Grid->GetCellType(id_cell);
74 QVector<vtkIdType> new_pts(N_pts);
75 for (int i = 0; i < N_pts; ++i) {
76 new_pts[i] = pts[i] - offset[pts[i]];
78 vtkIdType id_new_cell = new_grid->InsertNextCell(type, N_pts, new_pts.data());
79 copyCellData(m_Grid, id_cell, new_grid, id_new_cell);
81 makeCopy(new_grid, m_Grid);