added methods to convert between Cartesian and spherical coordinates
[engrid-github.git] / src / libengrid / deletecells.cpp
blob12fcd3898d74e04ac2b3b43f9d30f08d1cac3502
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008-2012 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 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 //
23 #include "deletecells.h"
25 void DeleteCells::setTraceCells(const QVector<vtkIdType> &cells)
27 trace_cells.resize(cells.size());
28 qCopy(cells.begin(), cells.end(), trace_cells.begin());
31 void DeleteCells::getTraceCells(QVector<vtkIdType> &cells)
33 cells.resize(trace_cells.size());
34 qCopy(trace_cells.begin(), trace_cells.end(), cells.begin());
37 void DeleteCells::operate()
39 EG_VTKSP(vtkUnstructuredGrid, new_grid);
40 QVector<vtkIdType> new_cells;
41 QVector<vtkIdType> new_nodes;
42 getRestCells(m_Grid, del_cells, new_cells);
43 getNodesFromCells(new_cells, new_nodes, m_Grid);
44 allocateGrid(new_grid, new_cells.size(), new_nodes.size());
45 QVector<vtkIdType> old2new_nodes(m_Grid->GetNumberOfPoints(), -1);
46 QVector<vtkIdType> old2new_cells(m_Grid->GetNumberOfCells(), -1);
48 vtkIdType id_new = 0;
49 foreach (vtkIdType id_node, new_nodes) {
50 vec3_t x;
51 m_Grid->GetPoints()->GetPoint(id_node, x.data());
52 new_grid ->GetPoints()->SetPoint(id_new, x.data());
53 copyNodeData(m_Grid, id_node, new_grid, id_new);
54 old2new_nodes[id_node] = id_new;
55 ++id_new;
59 foreach (vtkIdType id_cell, new_cells) {
60 vtkIdType *pts, N_pts;
61 m_Grid->GetCellPoints(id_cell, N_pts, pts);
62 QVector<vtkIdType> new_pts(N_pts);
63 for (int i = 0; i < N_pts; ++i) {
64 new_pts[i] = old2new_nodes[pts[i]];
66 vtkIdType cellType = m_Grid->GetCellType(id_cell);
67 vtkIdType id_new = new_grid->InsertNextCell(cellType, N_pts, new_pts.data());
68 copyCellData(m_Grid, id_cell, new_grid, id_new);
69 old2new_cells[id_cell] = id_new;
71 QList<vtkIdType> new_trace_cells;
72 foreach (vtkIdType id_cell, trace_cells) {
73 if (old2new_cells[id_cell] != -1) {
74 new_trace_cells.append(old2new_cells[id_cell]);
77 trace_cells.resize(new_trace_cells.size());
78 qCopy(new_trace_cells.begin(), new_trace_cells.end(), trace_cells.begin());
80 makeCopy(new_grid, m_Grid);