vtkPVLODActor.cxx 9.58 KB
Newer Older
1
/*=========================================================================
2

Charles Law's avatar
Charles Law committed
3
  Program:   ParaView
4
5
  Module:    vtkPVLODActor.cxx

6
7
8
  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9

10
11
12
     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.
13
14
15

=========================================================================*/
#include "vtkPVLODActor.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
16

17
#include "vtkInformation.h"
18
#include "vtkMapper.h"
Berk Geveci's avatar
Berk Geveci committed
19
#include "vtkMath.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
20
#include "vtkMatrix4x4.h"
21
#include "vtkObjectFactory.h"
22
#include "vtkPVConfig.h"
23
#include "vtkPiecewiseFunction.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
24
25
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
Berk Geveci's avatar
Berk Geveci committed
26
#include "vtkRenderer.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
27
28
#include "vtkTexture.h"
#include "vtkTimerLog.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
29
#include "vtkTransform.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
30
31

#include <math.h>
32

33
#if VTK_MODULE_ENABLE_VTK_RenderingRayTracing
34
35
36
#include "vtkOSPRayActorNode.h"
#endif

37
//-----------------------------------------------------------------------------
38
39
40
vtkStandardNewMacro(vtkPVLODActor);

vtkCxxSetObjectMacro(vtkPVLODActor, LODMapper, vtkMapper);
41
42
43
//----------------------------------------------------------------------------
vtkPVLODActor::vtkPVLODActor()
{
Kitware Robot's avatar
Kitware Robot committed
44
  vtkMatrix4x4* m;
Ken Martin's avatar
Ken Martin committed
45

46
47
48
49
50
  // get a hardware dependent actor and mappers
  this->Device = vtkActor::New();
  m = vtkMatrix4x4::New();
  this->Device->SetUserMatrix(m);
  m->Delete();
Ken Martin's avatar
Ken Martin committed
51

52
  this->LODMapper = NULL;
53
54

  this->EnableLOD = 0;
55
56
57
58
59
60
61
62
63
64
65
}

//----------------------------------------------------------------------------
vtkPVLODActor::~vtkPVLODActor()
{
  this->SetLODMapper(NULL);
  this->Device->Delete();
  this->Device = NULL;
}

//----------------------------------------------------------------------------
66
// We use points as the size of the data, because cells cqan mislead.
67
// A good example is verts.  One cell can contain any number of vertices.
Kitware Robot's avatar
Kitware Robot committed
68
vtkMapper* vtkPVLODActor::SelectMapper()
69
{
70
  if (this->Mapper == NULL || this->Mapper->GetInputDataObject(0, 0) == NULL)
Kitware Robot's avatar
Kitware Robot committed
71
  {
72
    return this->LODMapper;
Kitware Robot's avatar
Kitware Robot committed
73
  }
74
  if (this->LODMapper == NULL || this->LODMapper->GetInputDataObject(0, 0) == NULL)
Kitware Robot's avatar
Kitware Robot committed
75
  {
76
    return this->Mapper;
Kitware Robot's avatar
Kitware Robot committed
77
  }
78

79
  if (this->EnableLOD)
Kitware Robot's avatar
Kitware Robot committed
80
  {
81
    return this->LODMapper;
Kitware Robot's avatar
Kitware Robot committed
82
  }
83

84
85
86
87
  return this->Mapper;
}

//----------------------------------------------------------------------------
Kitware Robot's avatar
Kitware Robot committed
88
void vtkPVLODActor::Render(vtkRenderer* ren, vtkMapper* vtkNotUsed(m))
89
{
Kitware Robot's avatar
Kitware Robot committed
90
91
  vtkMatrix4x4* matrix;
  vtkMapper* mapper;
Ken Martin's avatar
Ken Martin committed
92

93
  if (this->Mapper == NULL)
Kitware Robot's avatar
Kitware Robot committed
94
  {
95
96
    vtkErrorMacro("No mapper for actor.");
    return;
Kitware Robot's avatar
Kitware Robot committed
97
  }
Ken Martin's avatar
Ken Martin committed
98

99
100
101
  mapper = this->SelectMapper();

  if (mapper == NULL)
Kitware Robot's avatar
Kitware Robot committed
102
  {
103
    return;
Kitware Robot's avatar
Kitware Robot committed
104
  }
Ken Martin's avatar
Ken Martin committed
105

106
107
  /* render the property */
  if (!this->Property)
Kitware Robot's avatar
Kitware Robot committed
108
  {
109
110
    // force creation of a property
    this->GetProperty();
Kitware Robot's avatar
Kitware Robot committed
111
  }
112
113
  this->Property->Render(this, ren);
  if (this->BackfaceProperty)
Kitware Robot's avatar
Kitware Robot committed
114
  {
115
116
    this->BackfaceProperty->BackfaceRender(this, ren);
    this->Device->SetBackfaceProperty(this->BackfaceProperty);
Kitware Robot's avatar
Kitware Robot committed
117
  }
118
  this->Device->SetProperty(this->Property);
Ken Martin's avatar
Ken Martin committed
119

120
121
  /* render the texture */
  if (this->Texture)
Kitware Robot's avatar
Kitware Robot committed
122
  {
123
    this->Texture->Render(ren);
Kitware Robot's avatar
Kitware Robot committed
124
  }
125
  this->Device->SetTexture(this->Texture);
126
  this->Device->SetShaderProperty(this->ShaderProperty);
Ken Martin's avatar
Ken Martin committed
127

128
129
130
  // make sure the device has the same matrix
  matrix = this->Device->GetUserMatrix();
  this->GetMatrix(matrix);
Ken Martin's avatar
Ken Martin committed
131

132
133
  // Store information on time it takes to render.
  // We might want to estimate time from the number of polygons in mapper.
Kitware Robot's avatar
Kitware Robot committed
134
  vtkInformation* info = this->GetPropertyKeys();
Ken Martin's avatar
Ken Martin committed
135
  this->Device->SetPropertyKeys(info);
136
  this->Device->SetMapper(mapper);
Kitware Robot's avatar
Kitware Robot committed
137
  this->Device->Render(ren, mapper);
138
139
140
141
  if (this->Texture)
  {
    this->Texture->PostRender(ren);
  }
142
  this->Property->PostRender(this, ren);
143
144
145
  this->EstimatedRenderTime = mapper->GetTimeToDraw();
}

Kitware Robot's avatar
Kitware Robot committed
146
int vtkPVLODActor::RenderOpaqueGeometry(vtkViewport* vp)
147
{
Kitware Robot's avatar
Kitware Robot committed
148
149
  int renderedSomething = 0;
  vtkRenderer* ren = static_cast<vtkRenderer*>(vp);
150

Kitware Robot's avatar
Kitware Robot committed
151
152
  if (!this->Mapper)
  {
153
    return 0;
Kitware Robot's avatar
Kitware Robot committed
154
  }
155
156
157

  // make sure we have a property
  if (!this->Property)
Kitware Robot's avatar
Kitware Robot committed
158
  {
159
160
    // force creation of a property
    this->GetProperty();
Kitware Robot's avatar
Kitware Robot committed
161
  }
162
163

  // is this actor opaque ?
164
  // Do this check only when not in selection mode
Kitware Robot's avatar
Kitware Robot committed
165
166
167
  if (this->GetIsOpaque() || (ren->GetSelector() && this->Property->GetOpacity() > 0.0))
  {
    this->Render(ren, this->Mapper);
168
    renderedSomething = 1;
Kitware Robot's avatar
Kitware Robot committed
169
  }
170
171
172
173

  return renderedSomething;
}

Kitware Robot's avatar
Kitware Robot committed
174
void vtkPVLODActor::ReleaseGraphicsResources(vtkWindow* renWin)
175
176
{
  vtkActor::ReleaseGraphicsResources(renWin);
Ken Martin's avatar
Ken Martin committed
177

178
  // broadcast the message down to the individual LOD mappers
179
  if (this->LODMapper)
Kitware Robot's avatar
Kitware Robot committed
180
  {
181
    this->LODMapper->ReleaseGraphicsResources(renWin);
Kitware Robot's avatar
Kitware Robot committed
182
  }
183
184
}

Charles Law's avatar
Charles Law committed
185
// Get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
Kitware Robot's avatar
Kitware Robot committed
186
double* vtkPVLODActor::GetBounds()
Charles Law's avatar
Charles Law committed
187
{
Kitware Robot's avatar
Kitware Robot committed
188
  int i, n;
Berk Geveci's avatar
Berk Geveci committed
189
  double *bounds, bbox[24], *fptr;
Kitware Robot's avatar
Kitware Robot committed
190
  vtkMapper* mapper = this->GetMapper();
Charles Law's avatar
Charles Law committed
191

Kitware Robot's avatar
Kitware Robot committed
192
  vtkDebugMacro(<< "Getting Bounds");
Charles Law's avatar
Charles Law committed
193
194
195

  // get the bounds of the Mapper if we have one
  if (!mapper)
Kitware Robot's avatar
Kitware Robot committed
196
  {
Charles Law's avatar
Charles Law committed
197
    return this->Bounds;
Kitware Robot's avatar
Kitware Robot committed
198
  }
Charles Law's avatar
Charles Law committed
199
200
201
202

  bounds = mapper->GetBounds();
  // Check for the special case when the mapper's bounds are unknown
  if (!bounds)
Kitware Robot's avatar
Kitware Robot committed
203
  {
Charles Law's avatar
Charles Law committed
204
    return bounds;
Kitware Robot's avatar
Kitware Robot committed
205
  }
Charles Law's avatar
Charles Law committed
206
207
208

  // Check for the special case when the actor is empty.
  if (bounds[0] > bounds[1])
Kitware Robot's avatar
Kitware Robot committed
209
210
  {
    memcpy(this->MapperBounds, bounds, 6 * sizeof(double));
Berk Geveci's avatar
Berk Geveci committed
211
    vtkMath::UninitializeBounds(this->Bounds);
Charles Law's avatar
Charles Law committed
212
213
    this->BoundsMTime.Modified();
    return this->Bounds;
Kitware Robot's avatar
Kitware Robot committed
214
  }
Charles Law's avatar
Charles Law committed
215
216
217
218
219
220

  // Check if we have cached values for these bounds - we cache the
  // values returned by this->Mapper->GetBounds() and we store the time
  // of caching. If the values returned this time are different, or
  // the modified time of this class is newer than the cached time,
  // then we need to rebuild.
Kitware Robot's avatar
Kitware Robot committed
221
222
223
224
  if ((memcmp(this->MapperBounds, bounds, 6 * sizeof(double)) != 0) ||
    (this->GetMTime() > this->BoundsMTime))
  {
    vtkDebugMacro(<< "Recomputing bounds...");
Charles Law's avatar
Charles Law committed
225

Kitware Robot's avatar
Kitware Robot committed
226
    memcpy(this->MapperBounds, bounds, 6 * sizeof(double));
Charles Law's avatar
Charles Law committed
227
228

    // fill out vertices of a bounding box
Kitware Robot's avatar
Kitware Robot committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
    bbox[0] = bounds[1];
    bbox[1] = bounds[3];
    bbox[2] = bounds[5];
    bbox[3] = bounds[1];
    bbox[4] = bounds[2];
    bbox[5] = bounds[5];
    bbox[6] = bounds[0];
    bbox[7] = bounds[2];
    bbox[8] = bounds[5];
    bbox[9] = bounds[0];
    bbox[10] = bounds[3];
    bbox[11] = bounds[5];
    bbox[12] = bounds[1];
    bbox[13] = bounds[3];
    bbox[14] = bounds[4];
    bbox[15] = bounds[1];
    bbox[16] = bounds[2];
    bbox[17] = bounds[4];
    bbox[18] = bounds[0];
    bbox[19] = bounds[2];
    bbox[20] = bounds[4];
    bbox[21] = bounds[0];
    bbox[22] = bounds[3];
    bbox[23] = bounds[4];
Ken Martin's avatar
Ken Martin committed
253

Charles Law's avatar
Charles Law committed
254
    // save the old transform
Ken Martin's avatar
Ken Martin committed
255
    this->Transform->Push();
Charles Law's avatar
Charles Law committed
256
257
258
259
    this->Transform->SetMatrix(this->GetMatrix());

    // and transform into actors coordinates
    fptr = bbox;
Ken Martin's avatar
Ken Martin committed
260
    for (n = 0; n < 8; n++)
Kitware Robot's avatar
Kitware Robot committed
261
262
    {
      this->Transform->TransformPoint(fptr, fptr);
Charles Law's avatar
Charles Law committed
263
      fptr += 3;
Kitware Robot's avatar
Kitware Robot committed
264
    }
Ken Martin's avatar
Ken Martin committed
265
266
267

    this->Transform->Pop();

Charles Law's avatar
Charles Law committed
268
    // now calc the new bounds
Berk Geveci's avatar
Berk Geveci committed
269
270
    this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = VTK_DOUBLE_MAX;
    this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = -VTK_DOUBLE_MAX;
Charles Law's avatar
Charles Law committed
271
    for (i = 0; i < 8; i++)
Kitware Robot's avatar
Kitware Robot committed
272
    {
Charles Law's avatar
Charles Law committed
273
      for (n = 0; n < 3; n++)
Kitware Robot's avatar
Kitware Robot committed
274
275
      {
        if (bbox[i * 3 + n] < this->Bounds[n * 2])
Charles Law's avatar
Charles Law committed
276
        {
Kitware Robot's avatar
Kitware Robot committed
277
278
279
280
281
          this->Bounds[n * 2] = bbox[i * 3 + n];
        }
        if (bbox[i * 3 + n] > this->Bounds[n * 2 + 1])
        {
          this->Bounds[n * 2 + 1] = bbox[i * 3 + n];
Charles Law's avatar
Charles Law committed
282
283
284
        }
      }
    }
Kitware Robot's avatar
Kitware Robot committed
285
286
    this->BoundsMTime.Modified();
  }
Charles Law's avatar
Charles Law committed
287
288
289

  return this->Bounds;
}
290
291
292
293
294
295
296
297

//----------------------------------------------------------------------------
void vtkPVLODActor::Modified()
{
  this->Device->Modified();
  this->vtkActor::Modified();
}

Kitware Robot's avatar
Kitware Robot committed
298
void vtkPVLODActor::ShallowCopy(vtkProp* prop)
299
{
Kitware Robot's avatar
Kitware Robot committed
300
301
302
  vtkPVLODActor* a = vtkPVLODActor::SafeDownCast(prop);
  if (a != NULL)
  {
303
    this->SetLODMapper(a->GetLODMapper());
Kitware Robot's avatar
Kitware Robot committed
304
  }
305
306
307
308
309

  // Now do superclass
  this->vtkActor::ShallowCopy(prop);
}

Andy Cedilnik's avatar
Andy Cedilnik committed
310
311
312
//----------------------------------------------------------------------------
void vtkPVLODActor::PrintSelf(ostream& os, vtkIndent indent)
{
Kitware Robot's avatar
Kitware Robot committed
313
  this->Superclass::PrintSelf(os, indent);
314
  if (this->LODMapper)
Kitware Robot's avatar
Kitware Robot committed
315
  {
316
    os << indent << "LODMapper: " << this->GetLODMapper() << endl;
Kitware Robot's avatar
Kitware Robot committed
317
  }
318

319
  os << indent << "EnableLOD: " << this->EnableLOD << endl;
Andy Cedilnik's avatar
Andy Cedilnik committed
320
}
321
322
323
324

//----------------------------------------------------------------------------
void vtkPVLODActor::SetEnableScaling(int val)
{
325
#if VTK_MODULE_ENABLE_VTK_RenderingRayTracing
326
  if (this->Mapper)
Kitware Robot's avatar
Kitware Robot committed
327
328
  {
    vtkInformation* info = this->Mapper->GetInformation();
329
    info->Set(vtkOSPRayActorNode::ENABLE_SCALING(), val);
Kitware Robot's avatar
Kitware Robot committed
330
  }
331
  if (this->LODMapper)
Kitware Robot's avatar
Kitware Robot committed
332
333
  {
    vtkInformation* info = this->LODMapper->GetInformation();
334
    info->Set(vtkOSPRayActorNode::ENABLE_SCALING(), val);
Kitware Robot's avatar
Kitware Robot committed
335
  }
336
337
#else
  (void)val;
338
339
340
341
342
343
#endif
}

//----------------------------------------------------------------------------
void vtkPVLODActor::SetScalingArrayName(const char* val)
{
344
#if VTK_MODULE_ENABLE_VTK_RenderingRayTracing
345
  if (this->Mapper)
Kitware Robot's avatar
Kitware Robot committed
346
347
  {
    vtkInformation* mapperInfo = this->Mapper->GetInformation();
348
    mapperInfo->Set(vtkOSPRayActorNode::SCALE_ARRAY_NAME(), val);
Kitware Robot's avatar
Kitware Robot committed
349
  }
350
  if (this->LODMapper)
Kitware Robot's avatar
Kitware Robot committed
351
352
  {
    vtkInformation* mapperInfo = this->LODMapper->GetInformation();
353
    mapperInfo->Set(vtkOSPRayActorNode::SCALE_ARRAY_NAME(), val);
Kitware Robot's avatar
Kitware Robot committed
354
  }
355
356
#else
  (void)val;
357
358
359
360
361
362
#endif
}

//----------------------------------------------------------------------------
void vtkPVLODActor::SetScalingFunction(vtkPiecewiseFunction* pwf)
{
363
#if VTK_MODULE_ENABLE_VTK_RenderingRayTracing
364
  if (this->Mapper)
Kitware Robot's avatar
Kitware Robot committed
365
366
  {
    vtkInformation* mapperInfo = this->Mapper->GetInformation();
367
    mapperInfo->Set(vtkOSPRayActorNode::SCALE_FUNCTION(), pwf);
Kitware Robot's avatar
Kitware Robot committed
368
  }
369
  if (this->LODMapper)
Kitware Robot's avatar
Kitware Robot committed
370
371
  {
    vtkInformation* mapperInfo = this->LODMapper->GetInformation();
372
    mapperInfo->Set(vtkOSPRayActorNode::SCALE_FUNCTION(), pwf);
Kitware Robot's avatar
Kitware Robot committed
373
  }
374
375
#else
  (void)pwf;
376
377
#endif
}