-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
vtkTransformPolyDataFilter.cxx
231 lines (194 loc) · 6.09 KB
/
vtkTransformPolyDataFilter.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTransformPolyDataFilter.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 "vtkTransformPolyDataFilter.h"
#include "vtkAbstractTransform.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkLinearTransform.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
vtkStandardNewMacro(vtkTransformPolyDataFilter);
vtkCxxSetObjectMacro(vtkTransformPolyDataFilter,
Transform,vtkAbstractTransform);
vtkTransformPolyDataFilter::vtkTransformPolyDataFilter()
{
this->Transform = nullptr;
this->OutputPointsPrecision = vtkAlgorithm::DEFAULT_PRECISION;
}
vtkTransformPolyDataFilter::~vtkTransformPolyDataFilter()
{
this->SetTransform(nullptr);
}
int vtkTransformPolyDataFilter::RequestData(
vtkInformation *vtkNotUsed(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()));
vtkPoints *inPts;
vtkPoints *newPts;
vtkDataArray *inVectors, *inCellVectors;
vtkFloatArray *newVectors=nullptr, *newCellVectors=nullptr;
vtkDataArray *inNormals, *inCellNormals;
vtkFloatArray *newNormals=nullptr, *newCellNormals=nullptr;
vtkIdType numPts, numCells;
vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData();
vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData();
vtkDebugMacro(<<"Executing polygonal transformation");
// Check input
//
if ( this->Transform == nullptr )
{
vtkErrorMacro(<<"No transform defined!");
return 1;
}
inPts = input->GetPoints();
inVectors = pd->GetVectors();
inNormals = pd->GetNormals();
inCellVectors = cd->GetVectors();
inCellNormals = cd->GetNormals();
if ( !inPts )
{
vtkErrorMacro(<<"No input data");
return 1;
}
numPts = inPts->GetNumberOfPoints();
numCells = input->GetNumberOfCells();
newPts = vtkPoints::New();
// Set the desired precision for the points in the output.
if(this->OutputPointsPrecision == vtkAlgorithm::DEFAULT_PRECISION)
{
newPts->SetDataType(inPts->GetDataType());
}
else if(this->OutputPointsPrecision == vtkAlgorithm::SINGLE_PRECISION)
{
newPts->SetDataType(VTK_FLOAT);
}
else if(this->OutputPointsPrecision == vtkAlgorithm::DOUBLE_PRECISION)
{
newPts->SetDataType(VTK_DOUBLE);
}
newPts->Allocate(numPts);
if ( inVectors )
{
newVectors = vtkFloatArray::New();
newVectors->SetNumberOfComponents(3);
newVectors->Allocate(3*numPts);
newVectors->SetName(inVectors->GetName());
}
if ( inNormals )
{
newNormals = vtkFloatArray::New();
newNormals->SetNumberOfComponents(3);
newNormals->Allocate(3*numPts);
newNormals->SetName(inNormals->GetName());
}
this->UpdateProgress (.2);
// Loop over all points, updating position
//
if ( inVectors || inNormals )
{
this->Transform->TransformPointsNormalsVectors(inPts,newPts,
inNormals,newNormals,
inVectors,newVectors);
}
else
{
this->Transform->TransformPoints(inPts,newPts);
}
this->UpdateProgress (.6);
// Can only transform cell normals/vectors if the transform
// is linear.
vtkLinearTransform* lt = vtkLinearTransform::SafeDownCast(this->Transform);
if (lt)
{
if ( inCellVectors )
{
newCellVectors = vtkFloatArray::New();
newCellVectors->SetNumberOfComponents(3);
newCellVectors->Allocate(3*numCells);
newCellVectors->SetName( inCellVectors->GetName() );
lt->TransformVectors(inCellVectors,newCellVectors);
}
if ( inCellNormals )
{
newCellNormals = vtkFloatArray::New();
newCellNormals->SetNumberOfComponents(3);
newCellNormals->Allocate(3*numCells);
newCellNormals->SetName( inCellNormals->GetName() );
lt->TransformNormals(inCellNormals,newCellNormals);
}
}
this->UpdateProgress (.8);
// Update ourselves and release memory
//
output->SetPoints(newPts);
newPts->Delete();
output->SetVerts(input->GetVerts());
output->SetLines(input->GetLines());
output->SetPolys(input->GetPolys());
output->SetStrips(input->GetStrips());
if (newNormals)
{
outPD->SetNormals(newNormals);
newNormals->Delete();
outPD->CopyNormalsOff();
}
if (newVectors)
{
outPD->SetVectors(newVectors);
newVectors->Delete();
outPD->CopyVectorsOff();
}
if (newCellNormals)
{
outCD->SetNormals(newCellNormals);
newCellNormals->Delete();
outCD->CopyNormalsOff();
}
if (newCellVectors)
{
outCD->SetVectors(newCellVectors);
newCellVectors->Delete();
outCD->CopyVectorsOff();
}
outPD->PassData(pd);
outCD->PassData(cd);
return 1;
}
vtkMTimeType vtkTransformPolyDataFilter::GetMTime()
{
vtkMTimeType mTime=this->MTime.GetMTime();
vtkMTimeType transMTime;
if ( this->Transform )
{
transMTime = this->Transform->GetMTime();
mTime = ( transMTime > mTime ? transMTime : mTime );
}
return mTime;
}
void vtkTransformPolyDataFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Transform: " << this->Transform << "\n";
os << indent << "Output Points Precision: " << this->OutputPointsPrecision
<< "\n";
}