forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkProp.cxx
355 lines (318 loc) · 9.72 KB
/
vtkProp.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*=========================================================================
Program: Visualization Toolkit
Module: vtkProp.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 "vtkProp.h"
#include "vtkObjectFactory.h"
#include "vtkAssemblyPaths.h"
#include "vtkCommand.h"
#include "vtkInformation.h"
#include "vtkInformationIterator.h"
#include "vtkInformationKey.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationDoubleVectorKey.h"
#include <cassert>
vtkCxxSetObjectMacro(vtkProp,PropertyKeys,vtkInformation);
vtkInformationKeyMacro(vtkProp,GeneralTextureUnit,Integer);
vtkInformationKeyMacro(vtkProp,GeneralTextureTransform,DoubleVector);
//----------------------------------------------------------------------------
// Creates an Prop with the following defaults: visibility on.
vtkProp::vtkProp()
{
this->Visibility = 1; // ON
this->Pickable = 1;
this->Dragable = 1;
this->UseBounds=true;
this->AllocatedRenderTime = 10.0;
this->EstimatedRenderTime = 0.0;
this->RenderTimeMultiplier = 1.0;
this->Paths = NULL;
this->NumberOfConsumers = 0;
this->Consumers = 0;
this->PropertyKeys=0;
}
//----------------------------------------------------------------------------
vtkProp::~vtkProp()
{
if ( this->Paths )
{
this->Paths->Delete();
}
delete [] this->Consumers;
if(this->PropertyKeys!=0)
{
this->PropertyKeys->Delete();
}
}
//----------------------------------------------------------------------------
// This method is invoked if the prop is picked.
void vtkProp::Pick()
{
this->InvokeEvent(vtkCommand::PickEvent,NULL);
}
//----------------------------------------------------------------------------
// Shallow copy of vtkProp.
void vtkProp::ShallowCopy(vtkProp *prop)
{
this->Visibility = prop->GetVisibility();
this->Pickable = prop->GetPickable();
this->Dragable = prop->GetDragable();
}
//----------------------------------------------------------------------------
void vtkProp::InitPathTraversal()
{
if ( this->Paths == NULL )
{
this->Paths = vtkAssemblyPaths::New();
vtkAssemblyPath *path = vtkAssemblyPath::New();
path->AddNode(this,NULL);
this->BuildPaths(this->Paths,path);
path->Delete();
}
this->Paths->InitTraversal();
}
//----------------------------------------------------------------------------
vtkAssemblyPath *vtkProp::GetNextPath()
{
if ( ! this->Paths)
{
return NULL;
}
return this->Paths->GetNextItem();
}
//----------------------------------------------------------------------------
// This method is used in conjunction with the assembly object to build a copy
// of the assembly hierarchy. This hierarchy can then be traversed for
// rendering, picking or other operations.
void vtkProp::BuildPaths(vtkAssemblyPaths *paths, vtkAssemblyPath *path)
{
// This is a leaf node in the assembly hierarchy so we
// copy the path in preparation to assingning it to paths.
vtkAssemblyPath *childPath = vtkAssemblyPath::New();
childPath->ShallowCopy(path);
// We can add this path to the list of paths
paths->AddItem(childPath);
childPath->Delete(); //okay, reference counting
}
//----------------------------------------------------------------------------
void vtkProp::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Dragable: " << (this->Dragable ? "On\n" : "Off\n");
os << indent << "Pickable: " << (this->Pickable ? "On\n" : "Off\n");
os << indent << "AllocatedRenderTime: "
<< this->AllocatedRenderTime << endl;
os << indent << "EstimatedRenderTime: "
<< this->EstimatedRenderTime << endl;
os << indent << "NumberOfConsumers: " << this->NumberOfConsumers << endl;
os << indent << "RenderTimeMultiplier: "
<< this->RenderTimeMultiplier << endl;
os << indent << "Visibility: " << (this->Visibility ? "On\n" : "Off\n");
os << indent << "PropertyKeys: ";
if(this->PropertyKeys!=0)
{
this->PropertyKeys->PrintSelf(os,indent);
os << endl;
}
else
{
os << "none." << endl;
}
os << indent << "useBounds: " << this->UseBounds <<endl;
}
//----------------------------------------------------------------------------
void vtkProp::AddConsumer(vtkObject *c)
{
// make sure it isn't already there
if (this->IsConsumer(c))
{
return;
}
// add it to the list, reallocate memory
vtkObject **tmp = this->Consumers;
this->NumberOfConsumers++;
this->Consumers = new vtkObject* [this->NumberOfConsumers];
for (int i = 0; i < (this->NumberOfConsumers-1); i++)
{
this->Consumers[i] = tmp[i];
}
this->Consumers[this->NumberOfConsumers-1] = c;
// free old memory
delete [] tmp;
}
//----------------------------------------------------------------------------
void vtkProp::RemoveConsumer(vtkObject *c)
{
// make sure it is already there
if (!this->IsConsumer(c))
{
return;
}
// remove it from the list, reallocate memory
vtkObject **tmp = this->Consumers;
this->NumberOfConsumers--;
this->Consumers = new vtkObject* [this->NumberOfConsumers];
int cnt = 0;
int i;
for (i = 0; i <= this->NumberOfConsumers; i++)
{
if (tmp[i] != c)
{
this->Consumers[cnt] = tmp[i];
cnt++;
}
}
// free old memory
delete [] tmp;
}
//----------------------------------------------------------------------------
int vtkProp::IsConsumer(vtkObject *c)
{
int i;
for (i = 0; i < this->NumberOfConsumers; i++)
{
if (this->Consumers[i] == c)
{
return 1;
}
}
return 0;
}
//----------------------------------------------------------------------------
vtkObject *vtkProp::GetConsumer(int i)
{
if (i >= this->NumberOfConsumers)
{
return 0;
}
return this->Consumers[i];
}
// ----------------------------------------------------------------------------
// Description:
// Tells if the prop has all the required keys.
// \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
bool vtkProp::HasKeys(vtkInformation *requiredKeys)
{
bool result=requiredKeys==0;
if(!result)
{
vtkInformationIterator *it=vtkInformationIterator::New();
it->SetInformation(requiredKeys);
it->GoToFirstItem();
result=true;
while(result && !it->IsDoneWithTraversal())
{
vtkInformationKey *k=it->GetCurrentKey();
result=this->PropertyKeys!=0 && this->PropertyKeys->Has(k);
it->GoToNextItem();
}
it->Delete();
}
return result;
}
// ----------------------------------------------------------------------------
// Description:
// Render the opaque geometry only if the prop has all the requiredKeys.
// This is recursive for composite props like vtkAssembly.
// An implementation is provided in vtkProp but each composite prop
// must override it.
// It returns if the rendering was performed.
// \pre v_exists: v!=0
// \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
bool vtkProp::RenderFilteredOpaqueGeometry(vtkViewport *v,
vtkInformation *requiredKeys)
{
assert("pre: v_exists" && v!=0);
bool result;
if(this->HasKeys(requiredKeys))
{
result=this->RenderOpaqueGeometry(v)==1;
}
else
{
result=false;
}
return result;
}
// ----------------------------------------------------------------------------
// Description:
// Render the translucent polygonal geometry only if the prop has all the
// requiredKeys.
// This is recursive for composite props like vtkAssembly.
// An implementation is provided in vtkProp but each composite prop
// must override it.
// It returns if the rendering was performed.
// \pre v_exists: v!=0
// \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
bool vtkProp::RenderFilteredTranslucentPolygonalGeometry(
vtkViewport *v,
vtkInformation *requiredKeys)
{
assert("pre: v_exists" && v!=0);
bool result;
if(this->HasKeys(requiredKeys))
{
result=this->RenderTranslucentPolygonalGeometry(v)==1;
}
else
{
result=false;
}
return result;
}
// ----------------------------------------------------------------------------
// Description:
// Render the volumetric geometry only if the prop has all the
// requiredKeys.
// This is recursive for composite props like vtkAssembly.
// An implementation is provided in vtkProp but each composite prop
// must override it.
// It returns if the rendering was performed.
// \pre v_exists: v!=0
// \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
bool vtkProp::RenderFilteredVolumetricGeometry(vtkViewport *v,
vtkInformation *requiredKeys)
{
assert("pre: v_exists" && v!=0);
bool result;
if(this->HasKeys(requiredKeys))
{
result=this->RenderVolumetricGeometry(v)==1;
}
else
{
result=false;
}
return result;
}
// ----------------------------------------------------------------------------
// Description:
// Render in the overlay of the viewport only if the prop has all the
// requiredKeys.
// This is recursive for composite props like vtkAssembly.
// An implementation is provided in vtkProp but each composite prop
// must override it.
// It returns if the rendering was performed.
// \pre v_exists: v!=0
// \pre keys_can_be_null: requiredKeys==0 || requiredKeys!=0
bool vtkProp::RenderFilteredOverlay(vtkViewport *v,
vtkInformation *requiredKeys)
{
assert("pre: v_exists" && v!=0);
bool result;
if(this->HasKeys(requiredKeys))
{
result=this->RenderOverlay(v)==1;
}
else
{
result=false;
}
return result;
}