simplified
[engrid-github.git] / src / libengrid / vtkEgPolyDataToUnstructuredGridFilter.cxx
blob90d50b6e893e77a38637dd38e58a53c394a02a57
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 "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
46 int,
47 vtkInformation* info
50 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkPolyData");
51 return 1;
54 int vtkEgPolyDataToUnstructuredGridFilter::FillOutputPortInformation
56 int,
57 vtkInformation* info
60 info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkUnstructuredGrid");
61 return 1;
64 int vtkEgPolyDataToUnstructuredGridFilter::RequestData
66 vtkInformation*,
67 vtkInformationVector** inputVector,
68 vtkInformationVector* outputVector
71 try {
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) {
81 double x[3];
82 input->GetPoints()->GetPoint(vertId,x);
83 points->SetPoint(vertId,x);
85 output->SetPoints(points);
87 // the cells
88 input->BuildCells();
89 output->Allocate(input->GetNumberOfPolys(),input->GetNumberOfPolys());
90 for (vtkIdType cellId = 0; cellId < input->GetNumberOfPolys(); ++cellId) {
91 vtkIdType *pts;
92 vtkIdType npts;
93 input->GetCellPoints(cellId,npts,pts);
94 if (npts == 3) {
95 output->InsertNextCell(VTK_TRIANGLE,3,pts);
96 } else if (npts == 4) {
97 output->InsertNextCell(VTK_QUAD,4,pts);
98 } else if (npts > 4) {
99 output->InsertNextCell(VTK_POLYGON, npts, pts);
103 } catch (Error err) {
104 err.display();
107 return 1;