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 "vtkEgPolyDataToUnstructuredGridFilter.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
49 info
->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkPolyData");
53 int vtkEgPolyDataToUnstructuredGridFilter::FillOutputPortInformation
59 info
->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
63 int vtkEgPolyDataToUnstructuredGridFilter::RequestData
66 vtkInformationVector
** inputVector
,
67 vtkInformationVector
* outputVector
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
) {
81 input
->GetPoints()->GetPoint(vertId
,x
);
82 points
->SetPoint(vertId
,x
);
84 output
->SetPoints(points
);
88 output
->Allocate(input
->GetNumberOfPolys(),input
->GetNumberOfPolys());
89 for (vtkIdType cellId
= 0; cellId
< input
->GetNumberOfPolys(); ++cellId
) {
90 EG_GET_CELL(cellId
, input
);
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
) {