Pick point/cell by ID functions working. :)
[engrid.git] / vtkEgExtractVolumeCells.cxx
blob5864dd93e188362ea2d30fd75f89a981295b6e40
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008 Oliver Gloth +
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 "vtkEgExtractVolumeCells.h"
25 vtkStandardNewMacro(vtkEgExtractVolumeCells);
27 vtkEgExtractVolumeCells::vtkEgExtractVolumeCells()
29 SetClippingOff();
30 SetX(vec3_t(0,0,0));
31 SetN(vec3_t(0,0,1));
32 tetra = true;
33 pyramid = true;
34 wedge = true;
35 hexa = true;
38 void vtkEgExtractVolumeCells::ExecuteEg()
40 QSet<vtkIdType> ex_cells;
41 for (vtkIdType id_cell = 0; id_cell < input->GetNumberOfCells(); ++id_cell) {
42 if (isVolume(id_cell, input)) {
43 bool select = true;
44 vtkIdType type_cell = input->GetCellType(id_cell);
45 if (!tetra && type_cell == VTK_TETRA) select = false;
46 if (!pyramid && type_cell == VTK_PYRAMID) select = false;
47 if (!wedge && type_cell == VTK_WEDGE) select = false;
48 if (!hexa && type_cell == VTK_HEXAHEDRON) select = false;
49 if (Clip && select) {
50 vtkIdType *pts;
51 vtkIdType N_pts;
52 input->GetCellPoints(id_cell, N_pts, pts);
53 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
54 vec3_t x;
55 input->GetPoints()->GetPoint(pts[i_pts],x.data());
56 if ((x-X)*N < 0) {
57 select = false;
58 break;
62 if (select) {
63 ex_cells.insert(id_cell);
67 QVector<vtkIdType> cells(ex_cells.size());
68 qCopy(ex_cells.begin(), ex_cells.end(), cells.begin());
69 QVector<vtkIdType> nodes;
70 QVector<int> _nodes;
71 getNodesFromCells(cells, nodes, input);
72 createNodeMapping(nodes, _nodes, input);
73 allocateGrid(output, cells.size(), nodes.size());
74 vtkIdType cellId, nodeId;
75 foreach(nodeId, nodes) {
76 vec3_t x;
77 input->GetPoints()->GetPoint(nodeId, x.data());
78 output->GetPoints()->SetPoint(_nodes[nodeId], x.data());
80 foreach(cellId, cells) {
81 vtkIdType Npts;
82 vtkIdType *pts;
83 input->GetCellPoints(cellId, Npts, pts);
84 vtkIdType *new_pts = new vtkIdType[Npts];
85 for (int i = 0; i < Npts; ++i) {
86 new_pts[i] = _nodes[pts[i]];
88 vtkIdType newId = output->InsertNextCell(input->GetCellType(cellId), Npts, new_pts);
89 copyCellData(input, cellId, output, newId);
90 delete [] new_pts;