2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "vtkEgExtractVolumeCells.h"
25 vtkStandardNewMacro(vtkEgExtractVolumeCells
)
27 vtkEgExtractVolumeCells::vtkEgExtractVolumeCells()
29 //SetClippingOff uses an IF to check the value first, which may have unexpected behavior in some OSes.
30 m_Clip
= false; SetClippingOff();
34 m_ExtrPyramids
= true;
39 void vtkEgExtractVolumeCells::SetX(vec3_t x
)
45 void vtkEgExtractVolumeCells::SetN(vec3_t n
)
51 void vtkEgExtractVolumeCells::SetClippingOn()
59 void vtkEgExtractVolumeCells::SetClippingOff()
68 void vtkEgExtractVolumeCells::SetAllOn()
76 void vtkEgExtractVolumeCells::SetAllOff()
84 void vtkEgExtractVolumeCells::SetTetrasOn()
92 void vtkEgExtractVolumeCells::SetTetrasOff()
100 void vtkEgExtractVolumeCells::SetPyramidsOn()
102 if (!m_ExtrPyramids
) {
103 m_ExtrPyramids
= true;
108 void vtkEgExtractVolumeCells::SetPyramidsOff()
110 if (m_ExtrPyramids
) {
111 m_ExtrPyramids
= false;
116 void vtkEgExtractVolumeCells::SetWedgesOn()
124 void vtkEgExtractVolumeCells::SetWedgesOff()
127 m_ExtrWedges
= false;
132 void vtkEgExtractVolumeCells::SetHexesOn()
140 void vtkEgExtractVolumeCells::SetHexesOff()
148 void vtkEgExtractVolumeCells::SetPolysOn()
156 void vtkEgExtractVolumeCells::SetPolysOff()
164 void vtkEgExtractVolumeCells::Setx(double x
)
170 void vtkEgExtractVolumeCells::Sety(double y
)
176 void vtkEgExtractVolumeCells::Setz(double z
)
182 void vtkEgExtractVolumeCells::Setnx(double nx
)
188 void vtkEgExtractVolumeCells::Setny(double ny
)
194 void vtkEgExtractVolumeCells::Setnz(double nz
)
201 void vtkEgExtractVolumeCells::ExecuteEg()
203 QSet
<vtkIdType
> ex_cells
;
204 for (vtkIdType id_cell
= 0; id_cell
< m_Input
->GetNumberOfCells(); ++id_cell
) {
205 if (isVolume(id_cell
, m_Input
)) {
207 vtkIdType type_cell
= m_Input
->GetCellType(id_cell
);
208 if (!m_ExtrTetras
&& type_cell
== VTK_TETRA
) {
211 if (!m_ExtrPyramids
&& type_cell
== VTK_PYRAMID
) {
214 if (!m_ExtrWedges
&& type_cell
== VTK_WEDGE
) {
217 if (!m_ExtrHexes
&& type_cell
== VTK_HEXAHEDRON
) {
220 // Polyhedron wasn't available before VTK 5.8.
221 #if ! ( VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION < 8 )
222 if (!m_ExtrPolys
&& type_cell
== VTK_POLYHEDRON
) {
226 if (m_Clip
&& select
) {
229 m_Input
->GetCellPoints(id_cell
, N_pts
, pts
);
230 for (int i_pts
= 0; i_pts
< N_pts
; ++i_pts
) {
232 m_Input
->GetPoints()->GetPoint(pts
[i_pts
],x
.data());
233 if ((x
- m_X
)*m_N
< 0) {
240 ex_cells
.insert(id_cell
);
244 QVector
<vtkIdType
> cells(ex_cells
.size());
245 qCopy(ex_cells
.begin(), ex_cells
.end(), cells
.begin());
246 QVector
<vtkIdType
> nodes
;
248 getNodesFromCells(cells
, nodes
, m_Input
);
249 createNodeMapping(nodes
, _nodes
, m_Input
);
250 allocateGrid(m_Output
, cells
.size(), nodes
.size());
251 foreach(vtkIdType id_node
, nodes
) {
253 m_Input
->GetPoints()->GetPoint(id_node
, x
.data());
254 m_Output
->GetPoints()->SetPoint(_nodes
[id_node
], x
.data());
256 foreach(vtkIdType id_cell
, cells
) {
259 m_Input
->GetCellPoints(id_cell
, Npts
, pts
);
260 vtkIdType
*new_pts
= new vtkIdType
[Npts
];
261 for (int i
= 0; i
< Npts
; ++i
) {
262 new_pts
[i
] = _nodes
[pts
[i
]];
264 vtkIdType id_new_cell
= m_Output
->InsertNextCell(m_Input
->GetCellType(id_cell
), Npts
, new_pts
);
265 copyCellData(m_Input
, id_cell
, m_Output
, id_new_cell
);