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"
22 #include "vtkInformation.h"
24 #include "guimainwindow.h"
26 vtkEgGridFilter::vtkEgGridFilter()
28 m_BoundaryCodes
.clear();
31 m_LastOutput
= vtkUnstructuredGrid::New();
32 m_LastRun
= GetMTime();
35 vtkEgGridFilter::~vtkEgGridFilter()
37 m_LastOutput
->Delete();
40 int vtkEgGridFilter::FillInputPortInformation
46 info
->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
50 int vtkEgGridFilter::FillOutputPortInformation
56 info
->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
60 int vtkEgGridFilter::RequestData
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
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()) {
83 makeCopy(m_Output
, m_LastOutput
);
85 m_LastRun
= GetMTime();
86 GuiMainWindow::unlock();
88 makeCopy(m_LastOutput
, m_Output
);
92 GuiMainWindow::unlock();
94 m_Output
->DeepCopy(m_Input
);
100 void vtkEgGridFilter::SetBoundaryCodes(const QSet
<int> &bc
)
103 if (m_BoundaryCodes
.size() != bc
.size()) {
106 QSet
<int> bc_inters
= m_BoundaryCodes
.intersect(bc
);
107 if (bc_inters
.size() != bc
.size()) {
112 m_BoundaryCodes
= bc
;
117 void vtkEgGridFilter::ExtractBoundary(QVector
<vtkIdType
> &cells
, QVector
<vtkIdType
> &nodes
, QSet
<int> &bc
, vtkUnstructuredGrid
*grid
)
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
))) {
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());
141 foreach(i
,ex_cells
) {
149 foreach(i
,ex_nodes
) {