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 "deletecells.h"
23 void DeleteCells::setTraceCells(const QVector
<vtkIdType
> &cells
)
25 m_TraceCells
.resize(cells
.size());
26 qCopy(cells
.begin(), cells
.end(), m_TraceCells
.begin());
29 void DeleteCells::getTraceCells(QVector
<vtkIdType
> &cells
)
31 cells
.resize(m_TraceCells
.size());
32 qCopy(m_TraceCells
.begin(), m_TraceCells
.end(), cells
.begin());
35 void DeleteCells::operate()
37 EG_VTKSP(vtkUnstructuredGrid
, new_grid
);
38 QVector
<vtkIdType
> new_cells
;
39 QVector
<vtkIdType
> new_nodes
;
40 getRestCells(m_Grid
, m_DelCells
, new_cells
);
41 getNodesFromCells(new_cells
, new_nodes
, m_Grid
);
42 allocateGrid(new_grid
, new_cells
.size(), new_nodes
.size());
43 QVector
<vtkIdType
> old2new_nodes(m_Grid
->GetNumberOfPoints(), -1);
44 QVector
<vtkIdType
> old2new_cells(m_Grid
->GetNumberOfCells(), -1);
47 foreach (vtkIdType id_node
, new_nodes
) {
49 m_Grid
->GetPoints()->GetPoint(id_node
, x
.data());
50 new_grid
->GetPoints()->SetPoint(id_new
, x
.data());
51 copyNodeData(m_Grid
, id_node
, new_grid
, id_new
);
52 old2new_nodes
[id_node
] = id_new
;
57 foreach (vtkIdType id_cell
, new_cells
) {
58 vtkIdType
*pts
, N_pts
;
59 m_Grid
->GetCellPoints(id_cell
, N_pts
, pts
);
60 QVector
<vtkIdType
> new_pts(N_pts
);
61 for (int i
= 0; i
< N_pts
; ++i
) {
62 new_pts
[i
] = old2new_nodes
[pts
[i
]];
64 vtkIdType id_new
= copyCell(m_Grid
, id_cell
, new_grid
);
65 copyCellData(m_Grid
, id_cell
, new_grid
, id_new
);
66 old2new_cells
[id_cell
] = id_new
;
68 QList
<vtkIdType
> new_trace_cells
;
69 foreach (vtkIdType id_cell
, m_TraceCells
) {
70 if (old2new_cells
[id_cell
] != -1) {
71 new_trace_cells
.append(old2new_cells
[id_cell
]);
74 m_TraceCells
.resize(new_trace_cells
.size());
75 qCopy(new_trace_cells
.begin(), new_trace_cells
.end(), m_TraceCells
.begin());
77 makeCopy(new_grid
, m_Grid
);