forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkCompositePolyDataMapper.cxx
312 lines (277 loc) · 9.24 KB
/
vtkCompositePolyDataMapper.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositePolyDataMapper.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 "vtkCompositePolyDataMapper.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkCompositeDataSet.h"
#include "vtkExecutive.h"
#include "vtkGarbageCollector.h"
#include "vtkInformation.h"
#include "vtkMapper.h"
#include "vtkMath.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include <vector>
vtkStandardNewMacro(vtkCompositePolyDataMapper);
class vtkCompositePolyDataMapperInternals
{
public:
std::vector<vtkPolyDataMapper*> Mappers;
};
vtkCompositePolyDataMapper::vtkCompositePolyDataMapper()
{
this->Internal = new vtkCompositePolyDataMapperInternals;
}
vtkCompositePolyDataMapper::~vtkCompositePolyDataMapper()
{
for(unsigned int i=0;i<this->Internal->Mappers.size();i++)
{
this->Internal->Mappers[i]->UnRegister(this);
}
this->Internal->Mappers.clear();
delete this->Internal;
}
// Specify the type of data this mapper can handle. If we are
// working with a regular (not hierarchical) pipeline, then we
// need vtkPolyData. For composite data pipelines, then
// vtkCompositeDataSet is required, and we'll check when
// building our structure whether all the part of the composite
// data set are polydata.
int vtkCompositePolyDataMapper::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkDataObject");
return 1;
}
// When the structure is out-of-date, recreate it by
// creating a mapper for each input data.
void vtkCompositePolyDataMapper::BuildPolyDataMapper()
{
int warnOnce = 0;
//Delete pdmappers if they already exist.
for(unsigned int i=0;i<this->Internal->Mappers.size();i++)
{
this->Internal->Mappers[i]->UnRegister(this);
}
this->Internal->Mappers.clear();
//Get the composite dataset from the input
vtkInformation* inInfo = this->GetExecutive()->GetInputInformation(0,0);
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
// If it isn't hierarchical, maybe it is just a plain vtkPolyData
if(!input)
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(
this->GetExecutive()->GetInputData(0, 0));
if ( pd )
{
// Make a copy of the data to break the pipeline here
vtkPolyData *newpd = vtkPolyData::New();
newpd->ShallowCopy(pd);
vtkPolyDataMapper *pdmapper = this->MakeAMapper();
pdmapper->Register( this );
pdmapper->SetInputData(newpd);
this->Internal->Mappers.push_back(pdmapper);
newpd->Delete();
pdmapper->Delete();
}
else
{
vtkDataObject* tmpInp = this->GetExecutive()->GetInputData(0, 0);
vtkErrorMacro("This mapper cannot handle input of type: "
<< (tmpInp?tmpInp->GetClassName():"(none)"));
}
}
else
{
//for each data set build a vtkPolyDataMapper
vtkCompositeDataIterator* iter = input->NewIterator();
iter->GoToFirstItem();
while (!iter->IsDoneWithTraversal())
{
vtkPolyData* pd =
vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
// Make a copy of the data to break the pipeline here
vtkPolyData *newpd = vtkPolyData::New();
newpd->ShallowCopy(pd);
vtkPolyDataMapper *pdmapper = this->MakeAMapper();
pdmapper->Register(this);
pdmapper->SetInputData(newpd);
this->Internal->Mappers.push_back(pdmapper);
newpd->Delete();
pdmapper->Delete();
}
// This is not polydata - warn the user that there are non-polydata
// parts to this data set which will not be rendered by this mapper
else
{
if ( !warnOnce )
{
vtkErrorMacro("All data in the hierarchical dataset must be polydata.");
warnOnce = 1;
}
}
iter->GoToNextItem();
}
iter->Delete();
}
this->InternalMappersBuildTime.Modified();
}
void vtkCompositePolyDataMapper::Render(vtkRenderer *ren, vtkActor *a)
{
//If the PolyDataMappers are not up-to-date then rebuild them
vtkCompositeDataPipeline * executive =
vtkCompositeDataPipeline::SafeDownCast(this->GetExecutive());
if(executive->GetPipelineMTime() > this->InternalMappersBuildTime.GetMTime())
{
this->BuildPolyDataMapper();
}
this->TimeToDraw = 0;
//Call Render() on each of the PolyDataMappers
for(unsigned int i=0;i<this->Internal->Mappers.size();i++)
{
if ( this->ClippingPlanes !=
this->Internal->Mappers[i]->GetClippingPlanes() )
{
this->Internal->Mappers[i]->SetClippingPlanes( this->ClippingPlanes );
}
this->Internal->Mappers[i]->SetLookupTable(
this->GetLookupTable());
this->Internal->Mappers[i]->SetScalarVisibility(
this->GetScalarVisibility());
this->Internal->Mappers[i]->SetUseLookupTableScalarRange(
this->GetUseLookupTableScalarRange());
this->Internal->Mappers[i]->SetScalarRange(
this->GetScalarRange());
this->Internal->Mappers[i]->SetImmediateModeRendering(
this->GetImmediateModeRendering());
this->Internal->Mappers[i]->SetColorMode(this->GetColorMode());
this->Internal->Mappers[i]->SetInterpolateScalarsBeforeMapping(
this->GetInterpolateScalarsBeforeMapping());
this->Internal->Mappers[i]->SetScalarMode(this->GetScalarMode());
if ( this->ScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA ||
this->ScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA )
{
if ( this->ArrayAccessMode == VTK_GET_ARRAY_BY_ID )
{
this->Internal->Mappers[i]->ColorByArrayComponent(
this->ArrayId,ArrayComponent);
}
else
{
this->Internal->Mappers[i]->ColorByArrayComponent(
this->ArrayName,ArrayComponent);
}
}
this->Internal->Mappers[i]->Render(ren,a);
this->TimeToDraw += this->Internal->Mappers[i]->GetTimeToDraw();
}
}
vtkExecutive* vtkCompositePolyDataMapper::CreateDefaultExecutive()
{
return vtkCompositeDataPipeline::New();
}
//Looks at each DataSet and finds the union of all the bounds
void vtkCompositePolyDataMapper::ComputeBounds()
{
vtkMath::UninitializeBounds(this->Bounds);
vtkInformation* inInfo = this->GetExecutive()->GetInputInformation(0,0);
vtkCompositeDataSet *input = vtkCompositeDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
// 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)
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(
this->GetExecutive()->GetInputData(0, 0));
if ( pd )
{
pd->GetBounds( this->Bounds );
}
return;
}
// We do have hierarchical data - so we need to loop over
// it and get the total bounds.
vtkCompositeDataIterator* iter = input->NewIterator();
iter->GoToFirstItem();
double bounds[6];
int i;
while (!iter->IsDoneWithTraversal())
{
vtkPolyData *pd = vtkPolyData::SafeDownCast(iter->GetCurrentDataObject());
if (pd)
{
// If this isn't the first time through, expand bounds
// we've compute so far based on the bounds of this
// block
if ( vtkMath::AreBoundsInitialized(this->Bounds) )
{
pd->GetBounds(bounds);
for(i=0; i<3; i++)
{
this->Bounds[i*2] =
(bounds[i*2]<this->Bounds[i*2])?
(bounds[i*2]):(this->Bounds[i*2]);
this->Bounds[i*2+1] =
(bounds[i*2+1]>this->Bounds[i*2+1])?
(bounds[i*2+1]):(this->Bounds[i*2+1]);
}
}
// If this is our first time through, just get the bounds
// of the data as the initial bounds
else
{
pd->GetBounds(this->Bounds);
}
}
iter->GoToNextItem();
}
iter->Delete();
this->BoundsMTime.Modified();
}
double *vtkCompositePolyDataMapper::GetBounds()
{
if ( ! this->GetExecutive()->GetInputData(0, 0) )
{
vtkMath::UninitializeBounds(this->Bounds);
return this->Bounds;
}
else
{
this->Update();
//only compute bounds when the input data has changed
vtkCompositeDataPipeline * executive = vtkCompositeDataPipeline::SafeDownCast(this->GetExecutive());
if( executive->GetPipelineMTime() > this->BoundsMTime.GetMTime() )
{
this->ComputeBounds();
}
return this->Bounds;
}
}
void vtkCompositePolyDataMapper::ReleaseGraphicsResources( vtkWindow *win )
{
for(unsigned int i=0;i<this->Internal->Mappers.size();i++)
{
this->Internal->Mappers[i]->ReleaseGraphicsResources( win );
}
}
void vtkCompositePolyDataMapper::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
vtkPolyDataMapper *vtkCompositePolyDataMapper::MakeAMapper()
{
return vtkPolyDataMapper::New();
}