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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "deletestraynodes.h"
23 DeleteStrayNodes::DeleteStrayNodes()
28 void DeleteStrayNodes::operate()
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 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;
42 foreach (bool is_active
, active
) {
49 cout
<< "deleting 1 node!" << endl
;
51 cout
<< "deleting " << N
<< " nodes!" << endl
;
54 QVector
<int> offset(m_Grid
->GetNumberOfPoints(), 0);
55 for (vtkIdType id_node
= 1; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
56 if (!active
[id_node
]) {
57 offset
[id_node
] = offset
[id_node
-1] + 1;
59 offset
[id_node
] = offset
[id_node
-1];
62 EG_VTKSP(vtkUnstructuredGrid
, new_grid
);
63 allocateGrid(new_grid
, m_Grid
->GetNumberOfCells(), m_Grid
->GetNumberOfPoints()-N
);
64 for (vtkIdType id_node
= 0; id_node
< m_Grid
->GetNumberOfPoints(); ++id_node
) {
65 if (active
[id_node
]) {
67 m_Grid
->GetPoint(id_node
, x
.data());
68 new_grid
->GetPoints()->SetPoint(id_node
- offset
[id_node
], x
.data());
69 copyNodeData(m_Grid
, id_node
, new_grid
, id_node
- offset
[id_node
]);
72 for (vtkIdType id_cell
= 0; id_cell
< m_Grid
->GetNumberOfCells(); ++id_cell
) {
73 vtkIdType N_pts
, *pts
, type
;
74 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
75 type
= m_Grid
->GetCellType(id_cell
);
76 QVector
<vtkIdType
> new_pts(N_pts
);
77 for (int i
= 0; i
< N_pts
; ++i
) {
78 new_pts
[i
] = pts
[i
] - offset
[pts
[i
]];
80 vtkIdType id_new_cell
= new_grid
->InsertNextCell(type
, N_pts
, new_pts
.data());
81 copyCellData(m_Grid
, id_cell
, new_grid
, id_new_cell
);
83 makeCopy(new_grid
, m_Grid
);