removing debug stuff
[engrid.git] / src / vtkEgExtractVolumeCells.cxx
blob15bd192875eb8bd36c1bcc5f310d0417c7d6a92f
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();
30 SetX(vec3_t(0,0,0));
31 SetN(vec3_t(1,0,0));
32 m_ExtrTetras = true;
33 m_ExtrPyramids = true;
34 m_ExtrWedges = true;
35 m_ExtrHexes = true;
38 void vtkEgExtractVolumeCells::SetX(vec3_t x)
40 m_X = x;
41 Modified();
44 void vtkEgExtractVolumeCells::SetN(vec3_t n)
46 m_N = n;
47 Modified();
50 void vtkEgExtractVolumeCells::SetClippingOn()
52 if (!m_Clip) {
53 m_Clip = true;
54 Modified();
58 void vtkEgExtractVolumeCells::SetClippingOff()
60 if (m_Clip) {
61 m_Clip = false;
62 Modified();
67 void vtkEgExtractVolumeCells::SetAllOn()
69 SetTetrasOn();
70 SetPyramidsOn();
71 SetWedgesOn();
72 SetHexesOn();
75 void vtkEgExtractVolumeCells::SetAllOff()
77 SetTetrasOff();
78 SetPyramidsOff();
79 SetWedgesOff();
80 SetHexesOff();
83 void vtkEgExtractVolumeCells::SetTetrasOn()
85 if (!m_ExtrTetras) {
86 m_ExtrTetras = true;
87 Modified();
91 void vtkEgExtractVolumeCells::SetTetrasOff()
93 if (m_ExtrTetras) {
94 m_ExtrTetras = false;
95 Modified();
99 void vtkEgExtractVolumeCells::SetPyramidsOn()
101 if (!m_ExtrPyramids) {
102 m_ExtrPyramids = true;
103 Modified();
107 void vtkEgExtractVolumeCells::SetPyramidsOff()
109 if (m_ExtrPyramids) {
110 m_ExtrPyramids = false;
111 Modified();
115 void vtkEgExtractVolumeCells::SetWedgesOn()
117 if (!m_ExtrWedges) {
118 m_ExtrWedges = true;
119 Modified();
123 void vtkEgExtractVolumeCells::SetWedgesOff()
125 if (m_ExtrWedges) {
126 m_ExtrWedges = false;
127 Modified();
131 void vtkEgExtractVolumeCells::SetHexesOn()
133 if (!m_ExtrHexes) {
134 m_ExtrHexes = true;
135 Modified();
139 void vtkEgExtractVolumeCells::SetHexesOff()
141 if (m_ExtrHexes) {
142 m_ExtrHexes = false;
143 Modified();
147 void vtkEgExtractVolumeCells::Setx(double x)
149 m_X[0] = x;
150 Modified();
153 void vtkEgExtractVolumeCells::Sety(double y)
155 m_X[1] = y;
156 Modified();
159 void vtkEgExtractVolumeCells::Setz(double z)
161 m_X[2] = z;
162 Modified();
165 void vtkEgExtractVolumeCells::Setnx(double nx)
167 m_N[0] = nx;
168 Modified();
171 void vtkEgExtractVolumeCells::Setny(double ny)
173 m_N[1] = ny;
174 Modified();
177 void vtkEgExtractVolumeCells::Setnz(double nz)
179 m_N[2] = nz;
180 Modified();
184 void vtkEgExtractVolumeCells::ExecuteEg()
186 QSet<vtkIdType> ex_cells;
187 for (vtkIdType id_cell = 0; id_cell < m_Input->GetNumberOfCells(); ++id_cell) {
188 if (isVolume(id_cell, m_Input)) {
189 bool select = true;
190 vtkIdType type_cell = m_Input->GetCellType(id_cell);
191 if (!m_ExtrTetras && type_cell == VTK_TETRA) {
192 select = false;
194 if (!m_ExtrPyramids && type_cell == VTK_PYRAMID) {
195 select = false;
197 if (!m_ExtrWedges && type_cell == VTK_WEDGE) {
198 select = false;
200 if (!m_ExtrHexes && type_cell == VTK_HEXAHEDRON) {
201 select = false;
203 if (m_Clip && select) {
204 vtkIdType *pts;
205 vtkIdType N_pts;
206 m_Input->GetCellPoints(id_cell, N_pts, pts);
207 for (int i_pts = 0; i_pts < N_pts; ++i_pts) {
208 vec3_t x;
209 m_Input->GetPoints()->GetPoint(pts[i_pts],x.data());
210 if ((x - m_X)*m_N < 0) {
211 select = false;
212 break;
216 if (select) {
217 ex_cells.insert(id_cell);
221 QVector<vtkIdType> cells(ex_cells.size());
222 qCopy(ex_cells.begin(), ex_cells.end(), cells.begin());
223 QVector<vtkIdType> nodes;
224 QVector<int> _nodes;
225 getNodesFromCells(cells, nodes, m_Input);
226 createNodeMapping(nodes, _nodes, m_Input);
227 allocateGrid(m_Output, cells.size(), nodes.size());
228 foreach(vtkIdType id_node, nodes) {
229 vec3_t x;
230 m_Input->GetPoints()->GetPoint(id_node, x.data());
231 m_Output->GetPoints()->SetPoint(_nodes[id_node], x.data());
233 foreach(vtkIdType id_cell, cells) {
234 vtkIdType Npts;
235 vtkIdType *pts;
236 m_Input->GetCellPoints(id_cell, Npts, pts);
237 vtkIdType *new_pts = new vtkIdType[Npts];
238 for (int i = 0; i < Npts; ++i) {
239 new_pts[i] = _nodes[pts[i]];
241 vtkIdType id_new_cell = m_Output->InsertNextCell(m_Input->GetCellType(id_cell), Npts, new_pts);
242 copyCellData(m_Input, id_cell, m_Output, id_new_cell);
243 delete [] new_pts;