2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008 Oliver Gloth +
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. +
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. +
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/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "vtkEgGridFilter.h"
24 #include "vtkInformation.h"
26 vtkEgGridFilter::vtkEgGridFilter()
33 int vtkEgGridFilter::FillInputPortInformation
39 info
->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
43 int vtkEgGridFilter::FillOutputPortInformation
49 info
->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
53 int vtkEgGridFilter::RequestData
56 vtkInformationVector
** inputVector
,
57 vtkInformationVector
* outputVector
60 // Get input and output data
61 input
= vtkUnstructuredGrid::GetData(inputVector
[0]);
62 output
= vtkUnstructuredGrid::GetData(outputVector
);
64 // check if we have a proper inputVector
65 if (!input
) { vtkDebugMacro("No input!"); return 1; };
66 if (!input
->GetPoints()) { vtkDebugMacro("No input!"); return 1; };
67 if (input
->GetPoints()->GetNumberOfPoints() < 1) { vtkDebugMacro("No input!"); return 1; };
69 // call the enGrid filter method
74 output
->DeepCopy(input
);
80 void vtkEgGridFilter::SetBoundaryCodes(QSet
<int> *bc
)
86 void vtkEgGridFilter::ExtractBoundary
88 QVector
<vtkIdType
> &cells
,
89 QVector
<vtkIdType
> &nodes
,
91 vtkUnstructuredGrid
*grid
96 QSet
<vtkIdType
> ex_nodes
, ex_cells
;
97 EG_VTKDCC(vtkIntArray
, cell_code
, grid
, "cell_code");
98 for (vtkIdType i
= 0; i
< grid
->GetNumberOfCells(); ++i
) {
99 if ((grid
->GetCellType(i
) == VTK_TRIANGLE
) || (grid
->GetCellType(i
) == VTK_QUAD
)){
100 if (bc
.contains(cell_code
->GetValue(i
))) {
104 input
->GetCellPoints(i
,npts
,pts
);
105 for (int j
= 0; j
< npts
; ++j
) {
106 ex_nodes
.insert(pts
[j
]);
111 cells
.resize(ex_cells
.size());
112 nodes
.resize(ex_nodes
.size());
116 foreach(i
,ex_cells
) {
124 foreach(i
,ex_nodes
) {
132 void vtkEgGridFilter::CreateBasicFields(vtkIdType Ncells, vtkIdType Nnodes)
135 if (!output->GetCellData()->GetArray("cell_code")) {
136 EG_VTKSP(vtkIntArray, cell_code);
137 cell_code->SetName("cell_code");
138 cell_code->SetNumberOfValues(Ncells);
139 output->GetCellData()->AddArray(cell_code);
141 EG_VTKDCC(vtkIntArray, cell_code, output, "cell_code");
142 cell_code->SetNumberOfValues(Ncells);
144 if (!output->GetCellData()->GetArray("cell_index")) {
145 EG_VTKSP(vtkLongArray_t, cell_index);
146 cell_index->SetName("cell_index");
147 cell_index->SetNumberOfValues(Ncells);
148 output->GetCellData()->AddArray(cell_index);
150 EG_VTKDCC(vtkLongArray_t, cell_index, output, "cell_index");
151 cell_index->SetNumberOfValues(Ncells);
155 void vtkEgGridFilter::CopyCellData(vtkIdType oldId, vtkIdType newId)
157 EG_VTKDCC(vtkIntArray, cell_code1, input, "cell_code");
158 EG_VTKDCC(vtkIntArray, cell_code2, output, "cell_code");
159 cell_code2->SetValue(newId, cell_code1->GetValue(oldId));
160 EG_VTKDCC(vtkLongArray_t, cell_index1, input, "cell_index");
161 EG_VTKDCC(vtkLongArray_t, cell_index2, output, "cell_index");
162 cell_index2->SetValue(newId, cell_index1->GetValue(oldId));
163 //qDebug() << oldId << newId;
166 void vtkEgGridFilter::AllocateOutput(vtkIdType Ncells, vtkIdType Nnodes)
168 EG_VTKSP(vtkPoints,points);
169 points->SetNumberOfPoints(Nnodes);
170 output->SetPoints(points);
171 output->Allocate(Ncells,max(1,Ncells/10));
172 CreateBasicFields(Ncells, Nnodes);