forked from Kitware/VTK
/
vtkCompositePolyDataMapper2.cxx
323 lines (291 loc) · 10.1 KB
/
vtkCompositePolyDataMapper2.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositePolyDataMapper2.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 "vtkCompositePolyDataMapper2.h"
#include "vtkBoundingBox.h"
#include "vtkCommand.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataDisplayAttributes.h"
#include "vtkCompositePainter.h"
#include "vtkDefaultPainter.h"
#include "vtkDisplayListPainter.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataPainter.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkScalarsToColors.h"
#include "vtkScalarsToColorsPainter.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedCharArray.h"
#include <algorithm>
vtkStandardNewMacro(vtkCompositePolyDataMapper2);
//----------------------------------------------------------------------------
vtkCompositePolyDataMapper2::vtkCompositePolyDataMapper2()
{
// Insert the vtkCompositePainter in the selection pipeline, so that the
// selection painter can handle composite datasets as well.
vtkCompositePainter* selectionPainter = vtkCompositePainter::New();
selectionPainter->SetDelegatePainter(this->SelectionPainter);
this->SetSelectionPainter(selectionPainter);
selectionPainter->FastDelete();
this->SelectionCompositePainter = selectionPainter;
this->LastOpaqueCheckTime = 0;
}
//----------------------------------------------------------------------------
vtkCompositePolyDataMapper2::~vtkCompositePolyDataMapper2()
{
}
//----------------------------------------------------------------------------
int vtkCompositePolyDataMapper2::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkCompositeDataSet");
return 1;
}
//----------------------------------------------------------------------------
vtkExecutive* vtkCompositePolyDataMapper2::CreateDefaultExecutive()
{
return vtkCompositeDataPipeline::New();
}
//-----------------------------------------------------------------------------
//Looks at each DataSet and finds the union of all the bounds
void vtkCompositePolyDataMapper2::ComputeBounds()
{
vtkMath::UninitializeBounds(this->Bounds);
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
this->GetInputDataObject(0, 0));
// If we don't have hierarchical data, test to see if we have
// plain old polydata. In this case, the bounds are simply
// the bounds of the input polydata.
if (!input)
{
this->Superclass::ComputeBounds();
return;
}
vtkCompositeDataIterator* iter = input->NewIterator();
vtkBoundingBox bbox;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
double bounds[6];
pd->GetBounds(bounds);
bbox.AddBounds(bounds);
}
}
iter->Delete();
bbox.GetBounds(this->Bounds);
// this->BoundsMTime.Modified();
}
//-----------------------------------------------------------------------------
bool vtkCompositePolyDataMapper2::GetIsOpaque()
{
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
this->GetInputDataObject(0, 0));
unsigned long int lastMTime = std::max(input ? input->GetMTime() : 0, this->GetMTime());
if (lastMTime <= this->LastOpaqueCheckTime)
{
return this->LastOpaqueCheckValue;
}
this->LastOpaqueCheckTime = lastMTime;
if (this->ScalarVisibility && input &&
(this->ColorMode == VTK_COLOR_MODE_DEFAULT ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS))
{
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
int cellFlag;
vtkDataArray* scalars = this->GetScalars(pd,
this->ScalarMode, this->ArrayAccessMode, this->ArrayId,
this->ArrayName, cellFlag);
if (scalars &&
(scalars->IsA("vtkUnsignedCharArray") ||
this->ColorMode == VTK_COLOR_MODE_DIRECT_SCALARS) &&
(scalars->GetNumberOfComponents() == 4 /*(RGBA)*/ ||
scalars->GetNumberOfComponents() == 2 /*(LuminanceAlpha)*/))
{
int opacityIndex = scalars->GetNumberOfComponents() - 1;
unsigned char opacity = 0;
switch (scalars->GetDataType())
{
vtkTemplateMacro(
vtkScalarsToColors::ColorToUChar(
static_cast<VTK_TT>(scalars->GetRange(opacityIndex)[0]),
&opacity));
}
if (opacity < 255)
{
// If the opacity is 255, despite the fact that the user specified
// RGBA, we know that the Alpha is 100% opaque. So treat as opaque.
this->LastOpaqueCheckValue = false;
return false;
}
}
}
}
}
else if(this->CompositeAttributes &&
this->CompositeAttributes->HasBlockOpacities())
{
this->LastOpaqueCheckValue = false;
return false;
}
this->LastOpaqueCheckValue = this->Superclass::GetIsOpaque();
return this->LastOpaqueCheckValue;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetBlockVisibility(unsigned int index, bool visible)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockVisibility(index, visible);
this->Modified();
}
}
//----------------------------------------------------------------------------
bool vtkCompositePolyDataMapper2::GetBlockVisibility(unsigned int index) const
{
if(this->CompositeAttributes)
{
return this->CompositeAttributes->GetBlockVisibility(index);
}
else
{
return true;
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockVisibility(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibility(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockVisibilites()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockVisibilites();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetBlockColor(unsigned int index, double color[3])
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockColor(index, color);
this->Modified();
}
}
//----------------------------------------------------------------------------
double* vtkCompositePolyDataMapper2::GetBlockColor(unsigned int index)
{
(void) index;
return 0;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockColor(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColor(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockColors()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockColors();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetBlockOpacity(unsigned int index, double opacity)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->SetBlockOpacity(index, opacity);
this->Modified();
}
}
//----------------------------------------------------------------------------
double vtkCompositePolyDataMapper2::GetBlockOpacity(unsigned int index)
{
if(this->CompositeAttributes)
{
return this->CompositeAttributes->GetBlockOpacity(index);
}
return 1.;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockOpacity(unsigned int index)
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockOpacity(index);
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::RemoveBlockOpacities()
{
if(this->CompositeAttributes)
{
this->CompositeAttributes->RemoveBlockOpacities();
this->Modified();
}
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::SetCompositeDataDisplayAttributes(
vtkCompositeDataDisplayAttributes *attributes)
{
if(this->CompositeAttributes != attributes)
{
this->CompositeAttributes = attributes;
this->Modified();
}
}
//----------------------------------------------------------------------------
vtkCompositeDataDisplayAttributes*
vtkCompositePolyDataMapper2::GetCompositeDataDisplayAttributes()
{
return this->CompositeAttributes;
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::UpdatePainterInformation()
{
this->Superclass::UpdatePainterInformation();
this->PainterInformation->Set(
vtkCompositePainter::DISPLAY_ATTRIBUTES(),
this->CompositeAttributes);
}
//----------------------------------------------------------------------------
void vtkCompositePolyDataMapper2::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}