implemented method to access individual variables from an XML section
[engrid-github.git] / src / libengrid / vtkEgGridFilter.cxx
blob3ed9d2ace9ad7d2ede0ed711989b4f06c852899e
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 "vtkInformation.h"
24 #include "guimainwindow.h"
26 vtkEgGridFilter::vtkEgGridFilter()
28 m_BoundaryCodes.clear();
29 m_Input = NULL;
30 m_Output = NULL;
31 m_LastOutput = vtkUnstructuredGrid::New();
32 m_LastRun = GetMTime();
35 vtkEgGridFilter::~vtkEgGridFilter()
37 m_LastOutput->Delete();
40 int vtkEgGridFilter::FillInputPortInformation
42 int,
43 vtkInformation* info
46 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
47 return 1;
50 int vtkEgGridFilter::FillOutputPortInformation
52 int,
53 vtkInformation* info
56 info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
57 return 1;
60 int vtkEgGridFilter::RequestData
62 vtkInformation*,
63 vtkInformationVector** m_InputVector,
64 vtkInformationVector* m_OutputVector
67 // Get m_Input and m_Output data
68 m_Input = vtkUnstructuredGrid::GetData(m_InputVector[0]);
69 m_Output = vtkUnstructuredGrid::GetData(m_OutputVector);
71 // check if we have a proper m_InputVector
72 if (!m_Input) { vtkDebugMacro("No input!"); return 1; }
73 if (!m_Input->GetPoints()) { vtkDebugMacro("No input!"); return 1; }
74 if (m_Input->GetPoints()->GetNumberOfPoints() < 1) { vtkDebugMacro("No input!"); return 1; }
76 // call the enGrid filter method
77 try {
78 bool m_Input_changed = (m_Input->GetMTime() > m_LastRun);
79 bool filter_changed = (GetMTime() > m_LastRun);
80 if (m_Input_changed || filter_changed) {
81 if (GuiMainWindow::tryLock()) {
82 ExecuteEg();
83 makeCopy(m_Output, m_LastOutput);
84 Modified();
85 m_LastRun = GetMTime();
86 GuiMainWindow::unlock();
87 } else {
88 makeCopy(m_LastOutput, m_Output);
91 } catch (Error err) {
92 GuiMainWindow::unlock();
93 err.display();
94 m_Output->DeepCopy(m_Input);
97 return 1;
100 void vtkEgGridFilter::SetBoundaryCodes(const QSet<int> &bc)
102 bool update = false;
103 if (m_BoundaryCodes.size() != bc.size()) {
104 update = true;
105 } else {
106 QSet<int> bc_inters = m_BoundaryCodes.intersect(bc);
107 if (bc_inters.size() != bc.size()) {
108 update = true;
111 if (update) {
112 m_BoundaryCodes = bc;
113 Modified();
117 void vtkEgGridFilter::ExtractBoundary(QVector<vtkIdType> &cells, QVector<vtkIdType> &nodes, QSet<int> &bc, vtkUnstructuredGrid *grid)
119 cells.clear();
120 nodes.clear();
121 QSet<vtkIdType> ex_nodes, ex_cells;
122 EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
123 for (vtkIdType i = 0; i < grid->GetNumberOfCells(); ++i) {
124 if (isSurface(i, grid)) {
125 if (bc.contains(cell_code->GetValue(i))) {
126 ex_cells.insert(i);
127 vtkIdType *pts;
128 vtkIdType npts;
129 m_Input->GetCellPoints(i,npts,pts);
130 for (int j = 0; j < npts; ++j) {
131 ex_nodes.insert(pts[j]);
136 cells.resize(ex_cells.size());
137 nodes.resize(ex_nodes.size());
139 int j = 0;
140 vtkIdType i;
141 foreach(i,ex_cells) {
142 cells[j] = i;
143 ++j;
147 int j = 0;
148 vtkIdType i;
149 foreach(i,ex_nodes) {
150 nodes[j] = i;
151 ++j;