limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / vtkEgGridFilter.cxx
blobfa6542a1f8d5e0d339b4723439a33625dda9bd16
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 "vtkEgGridFilter.h"
22 #include "engrid.h"
23 #include "vtkInformation.h"
25 #include "guimainwindow.h"
27 vtkEgGridFilter::vtkEgGridFilter()
29 m_BoundaryCodes.clear();
30 m_Input = NULL;
31 m_Output = NULL;
32 m_LastOutput = vtkUnstructuredGrid::New();
33 m_LastRun = GetMTime();
36 vtkEgGridFilter::~vtkEgGridFilter()
38 m_LastOutput->Delete();
41 int vtkEgGridFilter::FillInputPortInformation
43 int,
44 vtkInformation* info
47 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
48 return 1;
51 int vtkEgGridFilter::FillOutputPortInformation
53 int,
54 vtkInformation* info
57 info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
58 return 1;
61 int vtkEgGridFilter::RequestData
63 vtkInformation*,
64 vtkInformationVector** m_InputVector,
65 vtkInformationVector* m_OutputVector
68 // Get m_Input and m_Output data
69 m_Input = vtkUnstructuredGrid::GetData(m_InputVector[0]);
70 m_Output = vtkUnstructuredGrid::GetData(m_OutputVector);
72 // check if we have a proper m_InputVector
73 if (!m_Input) { vtkDebugMacro("No input!"); return 1; }
74 if (!m_Input->GetPoints()) { vtkDebugMacro("No input!"); return 1; }
75 if (m_Input->GetPoints()->GetNumberOfPoints() < 1) { vtkDebugMacro("No input!"); return 1; }
77 // call the enGrid filter method
78 try {
79 bool m_Input_changed = (m_Input->GetMTime() > m_LastRun);
80 bool filter_changed = (GetMTime() > m_LastRun);
81 if (m_Input_changed || filter_changed) {
82 if (GuiMainWindow::tryLock()) {
83 ExecuteEg();
84 makeCopy(m_Output, m_LastOutput);
85 Modified();
86 m_LastRun = GetMTime();
87 GuiMainWindow::unlock();
88 } else {
89 makeCopy(m_LastOutput, m_Output);
92 } catch (Error err) {
93 GuiMainWindow::unlock();
94 err.display();
95 m_Output->DeepCopy(m_Input);
98 return 1;
102 void vtkEgGridFilter::SetBoundaryCodes(const QSet<int> &bc)
104 bool update = false;
105 if (m_BoundaryCodes.size() != bc.size()) {
106 update = true;
107 } else {
108 QSet<int> bc_inters = m_BoundaryCodes.intersect(bc);
109 if (bc_inters.size() != bc.size()) {
110 update = true;
113 if (update) {
114 m_BoundaryCodes = bc;
115 Modified();
120 void vtkEgGridFilter::ExtractBoundary(QVector<vtkIdType> &cells, QVector<vtkIdType> &nodes, QSet<int> &bc, vtkUnstructuredGrid *grid)
122 cells.clear();
123 nodes.clear();
124 QSet<vtkIdType> ex_nodes, ex_cells;
125 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
126 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
127 if (isSurface(i, grid)) {
128 if (bc.contains(cell_code->GetValue(i))) {
129 ex_cells.insert(i);
130 EG_GET_CELL(i, m_Input);
131 for (int j = 0; j < num_pts; ++j) {
132 ex_nodes.insert(pts[j]);
137 cells.resize(ex_cells.size());
138 nodes.resize(ex_nodes.size());
140 int j = 0;
141 vtkIdType i;
142 foreach(i,ex_cells) {
143 cells[j] = i;
144 ++j;
148 int j = 0;
149 vtkIdType i;
150 foreach(i,ex_nodes) {
151 nodes[j] = i;
152 ++j;