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>
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;
40 void vtkEgExtractVolumeCells::SetX(vec3_t x
)
46 void vtkEgExtractVolumeCells::SetN(vec3_t n
)
52 void vtkEgExtractVolumeCells::SetClippingOn()
60 void vtkEgExtractVolumeCells::SetClippingOff()
69 void vtkEgExtractVolumeCells::SetAllOn()
78 void vtkEgExtractVolumeCells::SetAllOff()
87 void vtkEgExtractVolumeCells::SetTetrasOn()
95 void vtkEgExtractVolumeCells::SetTetrasOff()
103 void vtkEgExtractVolumeCells::SetPyramidsOn()
105 if (!m_ExtrPyramids
) {
106 m_ExtrPyramids
= true;
111 void vtkEgExtractVolumeCells::SetPyramidsOff()
113 if (m_ExtrPyramids
) {
114 m_ExtrPyramids
= false;
119 void vtkEgExtractVolumeCells::SetWedgesOn()
127 void vtkEgExtractVolumeCells::SetWedgesOff()
130 m_ExtrWedges
= false;
135 void vtkEgExtractVolumeCells::SetHexesOn()
143 void vtkEgExtractVolumeCells::SetHexesOff()
151 void vtkEgExtractVolumeCells::SetPolysOn()
159 void vtkEgExtractVolumeCells::SetPolysOff()
167 void vtkEgExtractVolumeCells::Setx(double x
)
173 void vtkEgExtractVolumeCells::Sety(double y
)
179 void vtkEgExtractVolumeCells::Setz(double z
)
185 void vtkEgExtractVolumeCells::Setnx(double nx
)
191 void vtkEgExtractVolumeCells::Setny(double ny
)
197 void vtkEgExtractVolumeCells::Setnz(double nz
)
204 void vtkEgExtractVolumeCells::ExecuteEg()
206 QSet
<vtkIdType
> ex_cells
;
207 for (vtkIdType id_cell
= 0; id_cell
< m_Input
->GetNumberOfCells(); ++id_cell
) {
208 if (isVolume(id_cell
, m_Input
)) {
210 vtkIdType type_cell
= m_Input
->GetCellType(id_cell
);
211 if (!m_ExtrTetras
&& type_cell
== VTK_TETRA
) {
214 if (!m_ExtrPyramids
&& type_cell
== VTK_PYRAMID
) {
217 if (!m_ExtrWedges
&& type_cell
== VTK_WEDGE
) {
220 if (!m_ExtrHexes
&& type_cell
== VTK_HEXAHEDRON
) {
223 if (!m_ExtrPolys
&& type_cell
== VTK_POLYHEDRON
) {
226 if (m_Clip
&& select
) {
227 QList
<vtkIdType
> pts
;
228 getPointsOfCell(m_Input
, id_cell
, pts
);
229 foreach (vtkIdType id_node
, pts
) {
231 m_Input
->GetPoints()->GetPoint(id_node
, x
.data());
232 if ((x
- m_X
)*m_N
< 0) {
239 ex_cells
.insert(id_cell
);
243 QVector
<vtkIdType
> cells(ex_cells
.size());
244 qCopy(ex_cells
.begin(), ex_cells
.end(), cells
.begin());
245 QVector
<vtkIdType
> nodes
;
247 getNodesFromCells(cells
, nodes
, m_Input
);
248 createNodeMapping(nodes
, _nodes
, m_Input
);
249 allocateGrid(m_Output
, cells
.size(), nodes
.size());
250 foreach(vtkIdType id_node
, nodes
) {
252 m_Input
->GetPoints()->GetPoint(id_node
, x
.data());
253 m_Output
->GetPoints()->SetPoint(_nodes
[id_node
], x
.data());
255 foreach(vtkIdType id_cell
, cells
) {
256 vtkIdType num
, *stream
, *new_stream
;
257 vtkIdType type_cell
= m_Input
->GetCellType(id_cell
);
258 if (type_cell
== VTK_POLYHEDRON
) {
259 m_Input
->GetFaceStream(id_cell
, num
, stream
);
260 int stream_length
= 0;
263 for (int i
= 0; i
< num
; ++i
) {
264 stream_length
+= stream
[id
] + 1;
265 id
+= stream
[id
] + 1;
268 new_stream
= new vtkIdType
[stream_length
];
271 for (int i
= 0; i
< num
; ++i
) {
272 vtkIdType num_pts
= stream
[id
];
273 new_stream
[id
] = stream
[id
];
275 for (int j
= 0; j
< num_pts
; ++j
) {
276 new_stream
[id
] = _nodes
[stream
[id
]];
283 m_Input
->GetCellPoints(id_cell
, num
, stream
);
284 new_stream
= new vtkIdType
[num
];
285 for (vtkIdType i
= 0; i
< num
; ++i
) {
286 new_stream
[i
] = _nodes
[stream
[i
]];
290 vtkIdType id_new_cell
= m_Output
->InsertNextCell(type_cell
, num
, new_stream
);
291 copyCellData(m_Input
, id_cell
, m_Output
, id_new_cell
);
292 delete [] new_stream
;