forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkmPolyDataNormals.cxx
131 lines (108 loc) · 4.13 KB
/
vtkmPolyDataNormals.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmPolyDataNormals.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkmPolyDataNormals.h"
#include "vtkCellData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/PolyDataConverter.h"
#include "vtkmlib/Storage.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include "vtkm/filter/SurfaceNormals.h"
vtkStandardNewMacro(vtkmPolyDataNormals)
//------------------------------------------------------------------------------
void vtkmPolyDataNormals::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
vtkmPolyDataNormals::vtkmPolyDataNormals()
{
// change defaults from parent
this->Splitting = 0;
this->Consistency = 0;
this->FlipNormals = 0;
this->ComputePointNormals = 1;
this->ComputeCellNormals = 0;
this->AutoOrientNormals = 0;
}
//------------------------------------------------------------------------------
vtkmPolyDataNormals::~vtkmPolyDataNormals() = default;
//------------------------------------------------------------------------------
int vtkmPolyDataNormals::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkPolyData *input = vtkPolyData::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
try
{
// convert the input dataset to a vtkm::cont::DataSet
auto in = tovtkm::Convert(input, tovtkm::FieldsFlag::None);
vtkm::cont::DataSet result;
// check for flags that vtkm filter cannot handle
bool unsupported = this->Splitting || this->Consistency || this->FlipNormals;
if (!unsupported)
{
vtkmInputFilterPolicy policy;
vtkm::filter::SurfaceNormals filter;
filter.SetGenerateCellNormals((this->ComputeCellNormals != 0));
filter.SetCellNormalsName("Normals");
filter.SetGeneratePointNormals((this->ComputePointNormals != 0));
filter.SetPointNormalsName("Normals");
result = filter.Execute(in, policy);
}
else
{
vtkWarningMacro(<< "Unsupported options\n"
<< "Falling back to vtkPolyDataNormals.");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
if (!fromvtkm::Convert(result, output, input))
{
vtkErrorMacro(<< "Unable to convert VTKm DataSet back to VTK");
return 0;
}
}
catch (const vtkm::cont::Error& e)
{
vtkWarningMacro(<< "VTK-m error: " << e.GetMessage()
<< "Falling back to vtkPolyDataNormals");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
vtkSmartPointer<vtkDataArray> pointNormals = output->GetPointData()->GetArray("Normals");
vtkSmartPointer<vtkDataArray> cellNormals = output->GetCellData()->GetArray("Normals");
output->GetPointData()->CopyNormalsOff();
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->CopyNormalsOff();
output->GetCellData()->PassData(input->GetPointData());
if (pointNormals)
{
output->GetPointData()->SetNormals(pointNormals);
}
if (cellNormals)
{
output->GetCellData()->SetNormals(cellNormals);
}
return 1;
}