compiles on openSUSE 15.4 part 2
[engrid-github.git] / src / libengrid / vtkEgPolyDataToUnstructuredGridFilter.cxx
blob8cafe1a0f86f40cc04832f38d48ed34a30a10f7b
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 "vtkEgPolyDataToUnstructuredGridFilter.h"
22 #include "engrid.h"
24 #include <vtkObjectFactory.h>
25 #include <vtkInformation.h>
26 #include <vtkDataObject.h>
27 #include <vtkPolyData.h>
28 #include <vtkUnstructuredGrid.h>
29 #include <vtkSmartPointer.h>
31 vtkStandardNewMacro(vtkEgPolyDataToUnstructuredGridFilter);
33 vtkEgPolyDataToUnstructuredGridFilter::vtkEgPolyDataToUnstructuredGridFilter()
34 : vtkUnstructuredGridAlgorithm()
36 this->SetNumberOfInputPorts(1);
39 vtkEgPolyDataToUnstructuredGridFilter::~vtkEgPolyDataToUnstructuredGridFilter()
43 int vtkEgPolyDataToUnstructuredGridFilter::FillInputPortInformation
45 int,
46 vtkInformation* info
49 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkPolyData");
50 return 1;
53 int vtkEgPolyDataToUnstructuredGridFilter::FillOutputPortInformation
55 int,
56 vtkInformation* info
59 info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
60 return 1;
63 int vtkEgPolyDataToUnstructuredGridFilter::RequestData
65 vtkInformation*,
66 vtkInformationVector** inputVector,
67 vtkInformationVector* outputVector
70 try {
72 // Get input and output data
73 vtkPolyData* input = vtkPolyData::GetData(inputVector[0]);
74 vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
76 // the coordinates of the nodes
77 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
78 points->SetNumberOfPoints(input->GetPoints()->GetNumberOfPoints());
79 for (vtkIdType vertId = 0; vertId < input->GetPoints()->GetNumberOfPoints(); ++vertId) {
80 double x[3];
81 input->GetPoints()->GetPoint(vertId,x);
82 points->SetPoint(vertId,x);
84 output->SetPoints(points);
86 // the cells
87 input->BuildCells();
88 output->Allocate(input->GetNumberOfPolys(),input->GetNumberOfPolys());
89 for (vtkIdType cellId = 0; cellId < input->GetNumberOfPolys(); ++cellId) {
90 EG_GET_CELL(cellId, input);
91 if (num_pts == 3) {
92 output->InsertNextCell(VTK_TRIANGLE, ptIds);
93 } else if (num_pts == 4) {
94 output->InsertNextCell(VTK_QUAD, ptIds);
95 } else if (num_pts > 4) {
96 output->InsertNextCell(VTK_POLYGON, ptIds);
100 } catch (Error err) {
101 err.display();
104 return 1;