set version number back to "dev"
[engrid.git] / src / libengrid / vtkEgExtractVolumeCells.cxx
blobc0d5ed6b73e3e06e179def95a2169053319519a0
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 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;
39 void vtkEgExtractVolumeCells::SetX(vec3_t x)
41 m_X = x;
42 Modified();
45 void vtkEgExtractVolumeCells::SetN(vec3_t n)
47 m_N = n;
48 Modified();
51 void vtkEgExtractVolumeCells::SetClippingOn()
53 if (!m_Clip) {
54 m_Clip = true;
55 Modified();
59 void vtkEgExtractVolumeCells::SetClippingOff()
61 if (m_Clip) {
62 m_Clip = false;
63 Modified();
68 void vtkEgExtractVolumeCells::SetAllOn()
70 SetTetrasOn();
71 SetPyramidsOn();
72 SetWedgesOn();
73 SetHexesOn();
76 void vtkEgExtractVolumeCells::SetAllOff()
78 SetTetrasOff();
79 SetPyramidsOff();
80 SetWedgesOff();
81 SetHexesOff();
84 void vtkEgExtractVolumeCells::SetTetrasOn()
86 if (!m_ExtrTetras) {
87 m_ExtrTetras = true;
88 Modified();
92 void vtkEgExtractVolumeCells::SetTetrasOff()
94 if (m_ExtrTetras) {
95 m_ExtrTetras = false;
96 Modified();
100 void vtkEgExtractVolumeCells::SetPyramidsOn()
102 if (!m_ExtrPyramids) {
103 m_ExtrPyramids = true;
104 Modified();
108 void vtkEgExtractVolumeCells::SetPyramidsOff()
110 if (m_ExtrPyramids) {
111 m_ExtrPyramids = false;
112 Modified();
116 void vtkEgExtractVolumeCells::SetWedgesOn()
118 if (!m_ExtrWedges) {
119 m_ExtrWedges = true;
120 Modified();
124 void vtkEgExtractVolumeCells::SetWedgesOff()
126 if (m_ExtrWedges) {
127 m_ExtrWedges = false;
128 Modified();
132 void vtkEgExtractVolumeCells::SetHexesOn()
134 if (!m_ExtrHexes) {
135 m_ExtrHexes = true;
136 Modified();
140 void vtkEgExtractVolumeCells::SetHexesOff()
142 if (m_ExtrHexes) {
143 m_ExtrHexes = false;
144 Modified();
148 void vtkEgExtractVolumeCells::SetPolysOn()
150 if (!m_ExtrPolys) {
151 m_ExtrPolys = true;
152 Modified();
156 void vtkEgExtractVolumeCells::SetPolysOff()
158 if (m_ExtrPolys) {
159 m_ExtrPolys = false;
160 Modified();
164 void vtkEgExtractVolumeCells::Setx(double x)
166 m_X[0] = x;
167 Modified();
170 void vtkEgExtractVolumeCells::Sety(double y)
172 m_X[1] = y;
173 Modified();
176 void vtkEgExtractVolumeCells::Setz(double z)
178 m_X[2] = z;
179 Modified();
182 void vtkEgExtractVolumeCells::Setnx(double nx)
184 m_N[0] = nx;
185 Modified();
188 void vtkEgExtractVolumeCells::Setny(double ny)
190 m_N[1] = ny;
191 Modified();
194 void vtkEgExtractVolumeCells::Setnz(double nz)
196 m_N[2] = nz;
197 Modified();
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)) {
206 bool select = true;
207 vtkIdType type_cell = m_Input->GetCellType(id_cell);
208 if (!m_ExtrTetras && type_cell == VTK_TETRA) {
209 select = false;
211 if (!m_ExtrPyramids && type_cell == VTK_PYRAMID) {
212 select = false;
214 if (!m_ExtrWedges && type_cell == VTK_WEDGE) {
215 select = false;
217 if (!m_ExtrHexes && type_cell == VTK_HEXAHEDRON) {
218 select = false;
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) {
223 select = false;
225 #endif
226 if (m_Clip && select) {
227 vtkIdType *pts;
228 vtkIdType N_pts;
229 m_Input->GetCellPoints(id_cell, N_pts, pts);
230 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
231 vec3_t x;
232 m_Input->GetPoints()->GetPoint(pts[i_pts],x.data());
233 if ((x - m_X)*m_N < 0) {
234 select = false;
235 break;
239 if (select) {
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;
247 QVector<int> _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) {
252 vec3_t x;
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) {
257 vtkIdType Npts;
258 vtkIdType *pts;
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);
266 delete [] new_pts;