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 "vtkEgExtractVolumeCells.h"
23 #include <vtkIdList.h>
24 #include <vtkSmartPointer.h>
27 vtkStandardNewMacro(vtkEgExtractVolumeCells
)
29 vtkEgExtractVolumeCells::vtkEgExtractVolumeCells()
31 //SetClippingOff uses an IF to check the value first, which may have unexpected behavior in some OSes.
32 m_Clip
= false; SetClippingOff();
36 m_ExtrPyramids
= true;
42 void vtkEgExtractVolumeCells::SetX(vec3_t x
)
48 void vtkEgExtractVolumeCells::SetN(vec3_t n
)
54 void vtkEgExtractVolumeCells::SetClippingOn()
62 void vtkEgExtractVolumeCells::SetClippingOff()
71 void vtkEgExtractVolumeCells::SetAllOn()
80 void vtkEgExtractVolumeCells::SetAllOff()
89 void vtkEgExtractVolumeCells::SetTetrasOn()
97 void vtkEgExtractVolumeCells::SetTetrasOff()
100 m_ExtrTetras
= false;
105 void vtkEgExtractVolumeCells::SetPyramidsOn()
107 if (!m_ExtrPyramids
) {
108 m_ExtrPyramids
= true;
113 void vtkEgExtractVolumeCells::SetPyramidsOff()
115 if (m_ExtrPyramids
) {
116 m_ExtrPyramids
= false;
121 void vtkEgExtractVolumeCells::SetWedgesOn()
129 void vtkEgExtractVolumeCells::SetWedgesOff()
132 m_ExtrWedges
= false;
137 void vtkEgExtractVolumeCells::SetHexesOn()
145 void vtkEgExtractVolumeCells::SetHexesOff()
153 void vtkEgExtractVolumeCells::SetPolysOn()
161 void vtkEgExtractVolumeCells::SetPolysOff()
169 void vtkEgExtractVolumeCells::Setx(double x
)
175 void vtkEgExtractVolumeCells::Sety(double y
)
181 void vtkEgExtractVolumeCells::Setz(double z
)
187 void vtkEgExtractVolumeCells::Setnx(double nx
)
193 void vtkEgExtractVolumeCells::Setny(double ny
)
199 void vtkEgExtractVolumeCells::Setnz(double nz
)
206 void vtkEgExtractVolumeCells::ExecuteEg()
208 QSet
<vtkIdType
> ex_cells
;
209 for (vtkIdType id_cell
= 0; id_cell
< m_Input
->GetNumberOfCells(); ++id_cell
) {
210 if (isVolume(id_cell
, m_Input
)) {
212 vtkIdType type_cell
= m_Input
->GetCellType(id_cell
);
213 if (!m_ExtrTetras
&& type_cell
== VTK_TETRA
) {
216 if (!m_ExtrPyramids
&& type_cell
== VTK_PYRAMID
) {
219 if (!m_ExtrWedges
&& type_cell
== VTK_WEDGE
) {
222 if (!m_ExtrHexes
&& type_cell
== VTK_HEXAHEDRON
) {
225 if (!m_ExtrPolys
&& type_cell
== VTK_POLYHEDRON
) {
228 if (m_Clip
&& select
) {
229 QList
<vtkIdType
> pts
;
230 getPointsOfCell(m_Input
, id_cell
, pts
);
231 foreach (vtkIdType id_node
, pts
) {
233 m_Input
->GetPoints()->GetPoint(id_node
, x
.data());
234 if ((x
- m_X
)*m_N
< 0) {
241 ex_cells
.insert(id_cell
);
245 QVector
<vtkIdType
> cells(ex_cells
.size());
246 qCopy(ex_cells
.begin(), ex_cells
.end(), cells
.begin());
247 QVector
<vtkIdType
> nodes
;
249 getNodesFromCells(cells
, nodes
, m_Input
);
250 createNodeMapping(nodes
, _nodes
, m_Input
);
251 allocateGrid(m_Output
, cells
.size(), nodes
.size());
252 foreach(vtkIdType id_node
, nodes
) {
254 m_Input
->GetPoints()->GetPoint(id_node
, x
.data());
255 m_Output
->GetPoints()->SetPoint(_nodes
[id_node
], x
.data());
257 foreach(vtkIdType id_cell
, cells
) {
258 vtkSmartPointer
<vtkIdList
> stream
= vtkSmartPointer
<vtkIdList
>::New();
259 vtkSmartPointer
<vtkIdList
> new_stream
= vtkSmartPointer
<vtkIdList
>::New();
260 vtkIdType type_cell
= m_Input
->GetCellType(id_cell
);
261 m_Input
->GetFaceStream(id_cell
, stream
);
262 new_stream
->SetNumberOfIds(stream
->GetNumberOfIds());
263 if (type_cell
== VTK_POLYHEDRON
) {
264 vtkIdType num
= stream
->GetId(0);
266 new_stream
->SetId(0, stream
->GetId(0));
268 for (int i
= 0; i
< num
; ++i
) {
269 vtkIdType num_pts
= stream
->GetId(id
);
270 new_stream
->SetId(id
, stream
->GetId(id
));
272 for (int j
= 0; j
< num_pts
; ++j
) {
273 new_stream
->SetId(id
, _nodes
[stream
->GetId(id
)]);
279 for (vtkIdType i
= 0; i
< stream
->GetNumberOfIds(); ++i
) {
280 new_stream
->SetId(i
, _nodes
[stream
->GetId(i
)]);
284 vtkIdType id_new_cell
= m_Output
->InsertNextCell(type_cell
, new_stream
);
285 copyCellData(m_Input
, id_cell
, m_Output
, id_new_cell
);