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 "vtkEgPolyDataToUnstructuredGridFilter.h"
25 #include <vtkObjectFactory.h>
26 #include <vtkInformation.h>
27 #include <vtkDataObject.h>
28 #include <vtkPolyData.h>
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkSmartPointer.h>
32 vtkStandardNewMacro(vtkEgPolyDataToUnstructuredGridFilter
);
34 vtkEgPolyDataToUnstructuredGridFilter::vtkEgPolyDataToUnstructuredGridFilter()
35 : vtkUnstructuredGridAlgorithm()
37 this->SetNumberOfInputPorts(1);
40 vtkEgPolyDataToUnstructuredGridFilter::~vtkEgPolyDataToUnstructuredGridFilter()
44 int vtkEgPolyDataToUnstructuredGridFilter::FillInputPortInformation
50 info
->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkPolyData");
54 int vtkEgPolyDataToUnstructuredGridFilter::FillOutputPortInformation
60 info
->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
64 int vtkEgPolyDataToUnstructuredGridFilter::RequestData
67 vtkInformationVector
** inputVector
,
68 vtkInformationVector
* outputVector
73 // Get input and output data
74 vtkPolyData
* input
= vtkPolyData::GetData(inputVector
[0]);
75 vtkUnstructuredGrid
* output
= vtkUnstructuredGrid::GetData(outputVector
);
77 // the coordinates of the nodes
78 vtkSmartPointer
<vtkPoints
> points
= vtkSmartPointer
<vtkPoints
>::New();
79 points
->SetNumberOfPoints(input
->GetPoints()->GetNumberOfPoints());
80 for (vtkIdType vertId
= 0; vertId
< input
->GetPoints()->GetNumberOfPoints(); ++vertId
) {
82 input
->GetPoints()->GetPoint(vertId
,x
);
83 points
->SetPoint(vertId
,x
);
85 output
->SetPoints(points
);
89 output
->Allocate(input
->GetNumberOfPolys(),input
->GetNumberOfPolys());
90 for (vtkIdType cellId
= 0; cellId
< input
->GetNumberOfPolys(); ++cellId
) {
93 input
->GetCellPoints(cellId
,npts
,pts
);
95 output
->InsertNextCell(VTK_TRIANGLE
,3,pts
);
96 } else if (npts
== 4) {
97 output
->InsertNextCell(VTK_QUAD
,4,pts
);
101 } catch (Error err
) {