1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
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. +
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. +
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/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "vtkEgGridFilter.h"
23 #include "vtkInformation.h"
25 #include "guimainwindow.h"
27 vtkEgGridFilter::vtkEgGridFilter()
29 m_BoundaryCodes
.clear();
32 m_LastOutput
= vtkUnstructuredGrid::New();
33 m_LastRun
= GetMTime();
36 vtkEgGridFilter::~vtkEgGridFilter()
38 m_LastOutput
->Delete();
41 int vtkEgGridFilter::FillInputPortInformation
47 info
->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
51 int vtkEgGridFilter::FillOutputPortInformation
57 info
->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
61 int vtkEgGridFilter::RequestData
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
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()) {
84 makeCopy(m_Output
, m_LastOutput
);
86 m_LastRun
= GetMTime();
87 GuiMainWindow::unlock();
89 makeCopy(m_LastOutput
, m_Output
);
93 GuiMainWindow::unlock();
95 m_Output
->DeepCopy(m_Input
);
102 void vtkEgGridFilter::SetBoundaryCodes(const QSet<int> &bc)
105 if (m_BoundaryCodes.size() != bc.size()) {
108 QSet<int> bc_inters = m_BoundaryCodes.intersect(bc);
109 if (bc_inters.size() != bc.size()) {
114 m_BoundaryCodes = bc;
120 void vtkEgGridFilter::ExtractBoundary(QVector
<vtkIdType
> &cells
, QVector
<vtkIdType
> &nodes
, QSet
<int> &bc
, vtkUnstructuredGrid
*grid
)
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
))) {
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());
142 foreach(i
,ex_cells
) {
150 foreach(i
,ex_nodes
) {