some gui changes
[engrid.git] / vtkEgGridFilter.cxx
blob2beac753d6351f69b17fb0f725959df6a260c06f
1 //
2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + +
4 // + This file is part of enGrid. +
5 // + +
6 // + Copyright 2008 Oliver Gloth +
7 // + +
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. +
12 // + +
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. +
17 // + +
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/>. +
20 // + +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "vtkEgGridFilter.h"
24 #include "vtkInformation.h"
26 vtkEgGridFilter::vtkEgGridFilter()
28 BoundaryCodes = NULL;
29 input = NULL;
30 output = NULL;
33 int vtkEgGridFilter::FillInputPortInformation
35 int,
36 vtkInformation* info
39 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
40 return 1;
43 int vtkEgGridFilter::FillOutputPortInformation
45 int,
46 vtkInformation* info
49 info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
50 return 1;
53 int vtkEgGridFilter::RequestData
55 vtkInformation*,
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
70 try {
71 ExecuteEg();
72 } catch (Error err) {
73 err.display();
74 output->DeepCopy(input);
77 return 1;
80 void vtkEgGridFilter::SetBoundaryCodes(QSet<int> *bc)
82 BoundaryCodes = bc;
83 Modified();
86 void vtkEgGridFilter::ExtractBoundary
88 QVector<vtkIdType> &cells,
89 QVector<vtkIdType> &nodes,
90 QSet<int> &bc,
91 vtkUnstructuredGrid *grid
94 cells.clear();
95 nodes.clear();
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))) {
101 ex_cells.insert(i);
102 vtkIdType *pts;
103 vtkIdType npts;
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());
114 int j = 0;
115 vtkIdType i;
116 foreach(i,ex_cells) {
117 cells[j] = i;
118 ++j;
122 int j = 0;
123 vtkIdType i;
124 foreach(i,ex_nodes) {
125 nodes[j] = i;
126 ++j;
132 void vtkEgGridFilter::CreateBasicFields(vtkIdType Ncells, vtkIdType Nnodes)
134 Nnodes = 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);
140 } else {
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);
149 } else {
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);