fixed edge display for volume cells
[engrid-github.git] / src / libengrid / vtkEgExtractVolumeCells.cxx
blobd788b9d5527389511b3dfa139b6dd2622473e059
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
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();
31 SetX(vec3_t(0,0,0));
32 SetN(vec3_t(1,0,0));
33 m_ExtrTetras = true;
34 m_ExtrPyramids = true;
35 m_ExtrWedges = true;
36 m_ExtrHexes = true;
37 m_ExtrPolys = true;
40 void vtkEgExtractVolumeCells::SetX(vec3_t x)
42 m_X = x;
43 Modified();
46 void vtkEgExtractVolumeCells::SetN(vec3_t n)
48 m_N = n;
49 Modified();
52 void vtkEgExtractVolumeCells::SetClippingOn()
54 if (!m_Clip) {
55 m_Clip = true;
56 Modified();
60 void vtkEgExtractVolumeCells::SetClippingOff()
62 if (m_Clip) {
63 m_Clip = false;
64 Modified();
69 void vtkEgExtractVolumeCells::SetAllOn()
71 SetTetrasOn();
72 SetPyramidsOn();
73 SetWedgesOn();
74 SetHexesOn();
75 SetPolysOn();
78 void vtkEgExtractVolumeCells::SetAllOff()
80 SetTetrasOff();
81 SetPyramidsOff();
82 SetWedgesOff();
83 SetHexesOff();
84 SetPolysOff();
87 void vtkEgExtractVolumeCells::SetTetrasOn()
89 if (!m_ExtrTetras) {
90 m_ExtrTetras = true;
91 Modified();
95 void vtkEgExtractVolumeCells::SetTetrasOff()
97 if (m_ExtrTetras) {
98 m_ExtrTetras = false;
99 Modified();
103 void vtkEgExtractVolumeCells::SetPyramidsOn()
105 if (!m_ExtrPyramids) {
106 m_ExtrPyramids = true;
107 Modified();
111 void vtkEgExtractVolumeCells::SetPyramidsOff()
113 if (m_ExtrPyramids) {
114 m_ExtrPyramids = false;
115 Modified();
119 void vtkEgExtractVolumeCells::SetWedgesOn()
121 if (!m_ExtrWedges) {
122 m_ExtrWedges = true;
123 Modified();
127 void vtkEgExtractVolumeCells::SetWedgesOff()
129 if (m_ExtrWedges) {
130 m_ExtrWedges = false;
131 Modified();
135 void vtkEgExtractVolumeCells::SetHexesOn()
137 if (!m_ExtrHexes) {
138 m_ExtrHexes = true;
139 Modified();
143 void vtkEgExtractVolumeCells::SetHexesOff()
145 if (m_ExtrHexes) {
146 m_ExtrHexes = false;
147 Modified();
151 void vtkEgExtractVolumeCells::SetPolysOn()
153 if (!m_ExtrPolys) {
154 m_ExtrPolys = true;
155 Modified();
159 void vtkEgExtractVolumeCells::SetPolysOff()
161 if (m_ExtrPolys) {
162 m_ExtrPolys = false;
163 Modified();
167 void vtkEgExtractVolumeCells::Setx(double x)
169 m_X[0] = x;
170 Modified();
173 void vtkEgExtractVolumeCells::Sety(double y)
175 m_X[1] = y;
176 Modified();
179 void vtkEgExtractVolumeCells::Setz(double z)
181 m_X[2] = z;
182 Modified();
185 void vtkEgExtractVolumeCells::Setnx(double nx)
187 m_N[0] = nx;
188 Modified();
191 void vtkEgExtractVolumeCells::Setny(double ny)
193 m_N[1] = ny;
194 Modified();
197 void vtkEgExtractVolumeCells::Setnz(double nz)
199 m_N[2] = nz;
200 Modified();
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)) {
209 bool select = true;
210 vtkIdType type_cell = m_Input->GetCellType(id_cell);
211 if (!m_ExtrTetras && type_cell == VTK_TETRA) {
212 select = false;
214 if (!m_ExtrPyramids && type_cell == VTK_PYRAMID) {
215 select = false;
217 if (!m_ExtrWedges && type_cell == VTK_WEDGE) {
218 select = false;
220 if (!m_ExtrHexes && type_cell == VTK_HEXAHEDRON) {
221 select = false;
223 if (!m_ExtrPolys && type_cell == VTK_POLYHEDRON) {
224 select = false;
226 if (m_Clip && select) {
227 QList<vtkIdType> pts;
228 getPointsOfCell(m_Input, id_cell, pts);
229 foreach (vtkIdType id_node, pts) {
230 vec3_t x;
231 m_Input->GetPoints()->GetPoint(id_node, x.data());
232 if ((x - m_X)*m_N < 0) {
233 select = false;
234 break;
238 if (select) {
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;
246 QVector<int> _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) {
251 vec3_t x;
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;
262 vtkIdType id = 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];
270 vtkIdType id = 0;
271 for (int i = 0; i < num; ++i) {
272 vtkIdType num_pts = stream[id];
273 new_stream[id] = stream[id];
274 ++id;
275 for (int j = 0; j < num_pts; ++j) {
276 new_stream[id] = _nodes[stream[id]];
277 ++id;
281 } else {
282 vtkIdType *stream;
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;