vtkOSPRayRendererNode.cxx 53.4 KB
Newer Older
1
2
3
/*=========================================================================

  Program:   Visualization Toolkit
David DeMarle's avatar
David DeMarle committed
4
  Module:    vtkOSPRayRendererNode.cxx
5
6
7
8
9
10
11
12
13
14

  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.

=========================================================================*/
15
16
17
18
19

#ifdef _WIN32
#define _USE_MATH_DEFINES
#endif

David DeMarle's avatar
David DeMarle committed
20
#include "vtkOSPRayRendererNode.h"
21

22
#include "vtkAbstractVolumeMapper.h"
23
#include "vtkBoundingBox.h"
24
25
#include "vtkCamera.h"
#include "vtkCollectionIterator.h"
26
#include "vtkImageData.h"
27
#include "vtkInformation.h"
28
#include "vtkInformationDoubleKey.h"
29
#include "vtkInformationDoubleVectorKey.h"
30
#include "vtkInformationIntegerKey.h"
31
#include "vtkInformationObjectBaseKey.h"
32
#include "vtkInformationStringKey.h"
33
#include "vtkLight.h"
34
#include "vtkMapper.h"
Michael Fogleman's avatar
Michael Fogleman committed
35
#include "vtkMath.h"
36
#include "vtkMatrix4x4.h"
David DeMarle's avatar
David DeMarle committed
37
38
39
#include "vtkOSPRayActorNode.h"
#include "vtkOSPRayCameraNode.h"
#include "vtkOSPRayLightNode.h"
40
#include "vtkOSPRayMaterialHelpers.h"
41
#include "vtkOSPRayMaterialLibrary.h"
42
43
44
#include "vtkOSPRayVolumeNode.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderWindow.h"
45
#include "vtkRenderWindow.h"
46
#include "vtkRenderer.h"
47
#include "vtkTexture.h"
48
#include "vtkTransform.h"
49
#include "vtkViewNodeCollection.h"
50
51
#include "vtkVolume.h"
#include "vtkVolumeCollection.h"
52
#include "vtkWeakPointer.h"
53

Tim Biedert's avatar
Tim Biedert committed
54
55
#include "RTWrapper/RTWrapper.h"

56
#include <algorithm>
57
#include <cmath>
58
#include <map>
59

60
61
62
63
namespace ospray
{
namespace opengl
{
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
// code borrowed from ospray::modules::opengl to facilitate updating
// and linking
// todo: use ospray's copy instead of this
inline osp::vec3f operator*(const osp::vec3f& a, const osp::vec3f& b)
{
  return osp::vec3f{ a.x * b.x, a.y * b.y, a.z * b.z };
}
inline osp::vec3f operator*(const osp::vec3f& a, float b)
{
  return osp::vec3f{ a.x * b, a.y * b, a.z * b };
}
inline osp::vec3f operator/(const osp::vec3f& a, float b)
{
  return osp::vec3f{ a.x / b, a.y / b, a.z / b };
}
inline osp::vec3f operator*(float b, const osp::vec3f& a)
{
  return osp::vec3f{ a.x * b, a.y * b, a.z * b };
}
inline osp::vec3f operator*=(osp::vec3f a, float b)
{
  return osp::vec3f{ a.x * b, a.y * b, a.z * b };
}
inline osp::vec3f operator-(const osp::vec3f& a, const osp::vec3f& b)
{
  return osp::vec3f{ a.x - b.x, a.y - b.y, a.z - b.z };
}
inline osp::vec3f operator+(const osp::vec3f& a, const osp::vec3f& b)
{
  return osp::vec3f{ a.x + b.x, a.y + b.y, a.z + b.z };
}
inline osp::vec3f cross(const osp::vec3f& a, const osp::vec3f& b)
{
  return osp::vec3f{ a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x };
}
100

101
102
103
104
105
106
107
108
inline float dot(const osp::vec3f& a, const osp::vec3f& b)
{
  return a.x * b.x + a.y * b.y + a.z * b.z;
}
inline osp::vec3f normalize(const osp::vec3f& v)
{
  return v / sqrtf(dot(v, v));
}
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*! \brief Compute and return OpenGL depth values from the depth component of the given
  OSPRay framebuffer, using parameters of the current OpenGL context and assuming a
  perspective projection.

  This function automatically determines the parameters of the OpenGL perspective
  projection and camera direction / up vectors. It assumes these values match those
  provided to OSPRay (fovy, aspect, camera direction / up vectors). It then maps the
  OSPRay depth buffer and transforms it to OpenGL depth values according to the OpenGL
  perspective projection.

  The OSPRay frame buffer object must have been constructed with the OSP_FB_DEPTH flag.
*/
OSPTexture getOSPDepthTextureFromOpenGLPerspective(const double& fovy, const double& aspect,
  const double& zNear, const double& zFar, const osp::vec3f& _cameraDir,
  const osp::vec3f& _cameraUp, const float* glDepthBuffer, float* ospDepthBuffer,
  const size_t& glDepthBufferWidth, const size_t& glDepthBufferHeight, RTW::Backend* backend)
{
  osp::vec3f cameraDir = (osp::vec3f&)_cameraDir;
  osp::vec3f cameraUp = (osp::vec3f&)_cameraUp;
  // this should later be done in ISPC...
130

131
132
133
134
135
136
137
138
139
140
  // transform OpenGL depth to linear depth
  for (size_t i = 0; i < glDepthBufferWidth * glDepthBufferHeight; i++)
  {
    const double z_n = 2.0 * glDepthBuffer[i] - 1.0;
    ospDepthBuffer[i] = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear));
    if (vtkMath::IsNan(ospDepthBuffer[i]))
    {
      ospDepthBuffer[i] = FLT_MAX;
    }
  }
141

142
143
144
  // transform from orthogonal Z depth to ray distance t
  osp::vec3f dir_du = normalize(cross(cameraDir, cameraUp));
  osp::vec3f dir_dv = normalize(cross(dir_du, cameraDir));
145

146
147
  const float imagePlaneSizeY = 2.f * tanf(fovy / 2.f * M_PI / 180.f);
  const float imagePlaneSizeX = imagePlaneSizeY * aspect;
148

149
150
  dir_du *= imagePlaneSizeX;
  dir_dv *= imagePlaneSizeY;
151

152
  const osp::vec3f dir_00 = cameraDir - .5f * dir_du - .5f * dir_dv;
153

154
155
156
157
158
159
160
  for (size_t j = 0; j < glDepthBufferHeight; j++)
  {
    for (size_t i = 0; i < glDepthBufferWidth; i++)
    {
      const osp::vec3f dir_ij =
        normalize(dir_00 + float(i) / float(glDepthBufferWidth - 1) * dir_du +
          float(j) / float(glDepthBufferHeight - 1) * dir_dv);
161

162
163
      const float t = ospDepthBuffer[j * glDepthBufferWidth + i] / dot(cameraDir, dir_ij);
      ospDepthBuffer[j * glDepthBufferWidth + i] = t;
164
165
    }
  }
166
167
168
169
170
171
172
173
174
175
176

  // nearest texture filtering required for depth textures -- we don't want interpolation of depth
  // values...
  osp::vec2i texSize = { static_cast<int>(glDepthBufferWidth),
    static_cast<int>(glDepthBufferHeight) };
  OSPTexture depthTexture = vtkOSPRayMaterialHelpers::NewTexture2D(backend, (osp::vec2i&)texSize,
    OSP_TEXTURE_R32F, ospDepthBuffer, OSP_TEXTURE_FILTER_NEAREST, sizeof(float));

  return depthTexture;
}
}
177
}
178

David DeMarle's avatar
David DeMarle committed
179
vtkInformationKeyMacro(vtkOSPRayRendererNode, SAMPLES_PER_PIXEL, Integer);
180
181
182
183
vtkInformationKeyMacro(vtkOSPRayRendererNode, MAX_CONTRIBUTION, Double);
vtkInformationKeyMacro(vtkOSPRayRendererNode, MAX_DEPTH, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, MIN_CONTRIBUTION, Double);
vtkInformationKeyMacro(vtkOSPRayRendererNode, ROULETTE_DEPTH, Integer);
Carson Brownlee's avatar
Carson Brownlee committed
184
vtkInformationKeyMacro(vtkOSPRayRendererNode, VOLUME_ANISOTROPY, Double);
185
vtkInformationKeyMacro(vtkOSPRayRendererNode, VARIANCE_THRESHOLD, Double);
David DeMarle's avatar
David DeMarle committed
186
187
vtkInformationKeyMacro(vtkOSPRayRendererNode, MAX_FRAMES, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, AMBIENT_SAMPLES, Integer);
188
vtkInformationKeyMacro(vtkOSPRayRendererNode, COMPOSITE_ON_GL, Integer);
189
vtkInformationKeyMacro(vtkOSPRayRendererNode, RENDERER_TYPE, String);
190
191
vtkInformationKeyMacro(vtkOSPRayRendererNode, NORTH_POLE, DoubleVector);
vtkInformationKeyMacro(vtkOSPRayRendererNode, EAST_POLE, DoubleVector);
192
vtkInformationKeyMacro(vtkOSPRayRendererNode, MATERIAL_LIBRARY, ObjectBase);
193
194
vtkInformationKeyMacro(vtkOSPRayRendererNode, VIEW_TIME, Double);
vtkInformationKeyMacro(vtkOSPRayRendererNode, TIME_CACHE_SIZE, Integer);
195
196
vtkInformationKeyMacro(vtkOSPRayRendererNode, DENOISER_THRESHOLD, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, ENABLE_DENOISER, Integer);
197
198
199

class vtkOSPRayRendererNodeInternals
{
200
  // todo: move the rest of the internal data here too
201
public:
202
  vtkOSPRayRendererNodeInternals(vtkOSPRayRendererNode* _owner)
203
204
    : Owner(_owner)
  {
205
206
    // grumble!
    // vs2013 error C2536:...: cannot specify explicit initializer for arrays
207
208
209
210
211
212
213
214
215
216
217
218
    this->lbgcolor1[0] = 0.;
    this->lbgcolor1[1] = 0.;
    this->lbgcolor1[2] = 0.;
    this->lbgcolor2[0] = 0.;
    this->lbgcolor2[1] = 0.;
    this->lbgcolor2[2] = 0.;
    this->lup[0] = 1.;
    this->lup[1] = 0.;
    this->lup[2] = 0.;
    this->least[0] = 0.;
    this->least[1] = 1.;
    this->least[2] = 0.;
219
220
    this->LastViewPort[0] = 0.;
    this->LastViewPort[1] = 0.;
221
    this->LastParallelScale = 0.0;
Tim Biedert's avatar
Tim Biedert committed
222
    this->Backend = nullptr;
223
  };
224

225
  ~vtkOSPRayRendererNodeInternals() {}
226

227
228
229
230
  bool CanReuseBG()
  {
    bool retval = true;

231
232
    vtkRenderer* ren = vtkRenderer::SafeDownCast(this->Owner->GetRenderable());
    double* up = vtkOSPRayRendererNode::GetNorthPole(ren);
233
234
    if (up)
    {
235
      if (this->lup[0] != up[0] || this->lup[1] != up[1] || this->lup[2] != up[2])
236
237
238
239
240
241
242
      {
        this->lup[0] = up[0];
        this->lup[1] = up[1];
        this->lup[2] = up[2];
        retval = false;
      }
    }
243
    double* east = vtkOSPRayRendererNode::GetEastPole(ren);
244
245
    if (east)
    {
246
      if (this->least[0] != east[0] || this->least[1] != east[1] || this->least[2] != east[2])
247
248
249
250
251
252
253
254
      {
        this->least[0] = east[0];
        this->least[1] = east[1];
        this->least[2] = east[2];
        retval = false;
      }
    }
    bool usebgtexture = ren->GetTexturedBackground();
255
    if (this->lusebgtexture != usebgtexture)
256
    {
257
      this->lusebgtexture = usebgtexture;
258
259
      retval = false;
    }
260
    vtkTexture* bgtexture = ren->GetBackgroundTexture();
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    vtkMTimeType bgttime = 0;
    if (bgtexture)
    {
      bgttime = bgtexture->GetMTime();
    }
    if (this->lbgtexture != bgtexture || bgttime > this->lbgttime)
    {
      this->lbgtexture = bgtexture;
      this->lbgttime = bgttime;
      retval = false;
    }
    bool usegradient = ren->GetGradientBackground();
    if (this->lusegradient != usegradient)
    {
      this->lusegradient = usegradient;
      retval = false;
    }
278
279
280
281
282
    double* nbgcolor1 = ren->GetBackground();
    double* nbgcolor2 = ren->GetBackground2();
    if (this->lbgcolor1[0] != nbgcolor1[0] || this->lbgcolor1[1] != nbgcolor1[1] ||
      this->lbgcolor1[2] != nbgcolor1[2] || this->lbgcolor2[0] != nbgcolor2[0] ||
      this->lbgcolor2[1] != nbgcolor2[1] || this->lbgcolor2[2] != nbgcolor2[2])
283
    {
284
285
286
287
288
289
      this->lbgcolor1[0] = nbgcolor1[0];
      this->lbgcolor1[1] = nbgcolor1[1];
      this->lbgcolor1[2] = nbgcolor1[2];
      this->lbgcolor2[0] = nbgcolor2[0];
      this->lbgcolor2[1] = nbgcolor2[1];
      this->lbgcolor2[2] = nbgcolor2[2];
290
291
292
293
294
      retval = false;
    }
    return retval;
  }

295
  bool SetupPathTraceBackground(RTW::Backend* backend, OSPRenderer renderer)
296
  {
297
298
299
    vtkRenderer* ren = vtkRenderer::SafeDownCast(this->Owner->GetRenderable());
    if (std::string(this->Owner->GetRendererType(ren)).find(std::string("pathtracer")) ==
      std::string::npos)
300
    {
301
      return true;
302
    }
303
    bool reuseable = this->CanReuseBG();
304
    if (!reuseable)
305
    {
306
307
      double* bg1 = ren->GetBackground();
      unsigned char* ochars;
308
309
      int isize = 1;
      int jsize = 1;
310
      vtkTexture* text = ren->GetBackgroundTexture();
311
      if (text && (ren->GetTexturedBackground() || ren->GetUseImageBasedLighting()))
312
      {
313
314
315
316
        vtkImageData* vColorTextureMap = text->GetInput();
        // todo, fallback to gradient when either of above return nullptr
        // otherwise can't load texture in PV when in OSP::PT mode
        // todo: this code is duplicated from vtkOSPRayPolyDataMapperNode
317
318
        jsize = vColorTextureMap->GetExtent()[1];
        isize = vColorTextureMap->GetExtent()[3];
319
320
321
        unsigned char* ichars = (unsigned char*)vColorTextureMap->GetScalarPointer();
        ochars = new unsigned char[(isize + 1) * (jsize + 1) * 3];
        unsigned char* oc = ochars;
322
        int comps = vColorTextureMap->GetNumberOfScalarComponents();
323
        for (int i = 0; i < isize + 1; i++)
324
        {
325
          for (int j = 0; j < jsize + 1; j++)
326
327
328
329
          {
            oc[0] = ichars[0];
            oc[1] = ichars[1];
            oc[2] = ichars[2];
330
331
            oc += 3;
            ichars += comps;
332
333
334
335
336
337
338
          }
        }
        isize++;
        jsize++;
      }
      else if (ren->GetGradientBackground())
      {
339
340
341
342
343
        double* bg2 = ren->GetBackground2();
        isize = 256; // todo: configurable
        jsize = 2;
        ochars = new unsigned char[isize * jsize * 3];
        unsigned char* oc = ochars;
344
345
        for (int i = 0; i < isize; i++)
        {
346
347
348
349
350
351
352
353
          double frac = (double)i / (double)isize;
          *(oc + 0) = (bg1[0] * (1.0 - frac) + bg2[0] * frac) * 255;
          *(oc + 1) = (bg1[1] * (1.0 - frac) + bg2[1] * frac) * 255;
          *(oc + 2) = (bg1[2] * (1.0 - frac) + bg2[2] * frac) * 255;
          *(oc + 3) = (bg1[0] * (1.0 - frac) + bg2[0] * frac) * 255;
          *(oc + 4) = (bg1[1] * (1.0 - frac) + bg2[1] * frac) * 255;
          *(oc + 5) = (bg1[2] * (1.0 - frac) + bg2[2] * frac) * 255;
          oc += 6;
354
355
356
357
        }
      }
      else
      {
358
        return true;
359
      }
Tim Biedert's avatar
Tim Biedert committed
360

361
362
      OSPTexture t2d = vtkOSPRayMaterialHelpers::NewTexture2D(
        backend, osp::vec2i{ jsize, isize }, OSP_TEXTURE_RGB8, ochars, 0, 3 * sizeof(char));
363
      ospCommit(t2d);
364

365
      OSPLight ospLight = ospNewLight("hdri");
366
      ospSetObject(ospLight, "map", t2d);
Tim Biedert's avatar
Tim Biedert committed
367

368
      double* up = vtkOSPRayRendererNode::GetNorthPole(ren);
369
      if (up)
370
      {
371
        ospSetVec3f(ospLight, "up", (float)up[0], (float)up[1], (float)up[2]);
372
      }
373
      else
374
      {
375
        ospSetVec3f(ospLight, "up", 1.0f, 0.0f, 0.0f); // todo: configurable
376
377
      }
      double* east = vtkOSPRayRendererNode::GetEastPole(ren);
378
      if (east)
379
      {
380
        ospSetVec3f(ospLight, "direction", (float)east[0], (float)east[1], (float)east[2]);
381
      }
382
      else
383
      {
384
        ospSetVec3f(ospLight, "direction", 0.0f, 1.0f, 0.0f); // todo: configurable
385
386
      }
      ospCommit(ospLight); // todo: make sure osp frees its side
387
      this->BGLight = ospLight;
388
389
390
391
      this->Owner->AddLight(this->BGLight);

      delete[] ochars;
      ospRelease(t2d);
392
    }
393
    // TODO: hdri light tex is broken in ospray 2.0
394
    return reuseable;
395
396
  }

397
398
  std::map<vtkProp3D*, vtkAbstractMapper3D*> LastMapperFor;
  vtkOSPRayRendererNode* Owner;
399
400
401
402
403

  bool lusebgtexture = false;
  vtkWeakPointer<vtkTexture> lbgtexture = nullptr;
  vtkMTimeType lbgttime = 0;
  bool lusegradient = false;
404
  double lbgcolor1[3]; // not initializing here bc visstudio2013
405
406
407
  double lbgcolor2[3];
  double lup[3];
  double least[3];
408
  double LastViewPort[2];
409
  double LastParallelScale;
410
  double LastFocalDisk = -1.0;
411
  double LastFocalDistance = -1.0;
412

413
  OSPLight BGLight{ nullptr };
414
  RTW::Backend* Backend;
415
416
};

417
//============================================================================
David DeMarle's avatar
David DeMarle committed
418
vtkStandardNewMacro(vtkOSPRayRendererNode);
419
420

//----------------------------------------------------------------------------
David DeMarle's avatar
David DeMarle committed
421
vtkOSPRayRendererNode::vtkOSPRayRendererNode()
422
{
Tim Biedert's avatar
Tim Biedert committed
423
424
  this->ColorBufferTex = 0;
  this->DepthBufferTex = 0;
425
  this->OWorld = nullptr;
426
  this->ORenderer = nullptr;
427
  this->OLightArray = nullptr;
428
  this->NumActors = 0;
429
430
431
432
  this->ComputeDepth = true;
  this->OFrameBuffer = nullptr;
  this->ImageX = this->ImageY = -1;
  this->CompositeOnGL = false;
433
434
  this->Accumulate = true;
  this->AccumulateCount = 0;
435
  this->ActorCount = 0;
436
437
  this->AccumulateTime = 0;
  this->AccumulateMatrix = vtkMatrix4x4::New();
438
  this->Internal = new vtkOSPRayRendererNodeInternals(this);
Tim Biedert's avatar
Tim Biedert committed
439
  this->PreviousType = "none";
440
441

#ifdef VTKOSPRAY_ENABLE_DENOISER
442
443
444
  this->DenoiserDevice = oidn::newDevice();
  this->DenoiserDevice.commit();
  this->DenoiserFilter = this->DenoiserDevice.newFilter("RT");
445
#endif
446
447
448
}

//----------------------------------------------------------------------------
David DeMarle's avatar
David DeMarle committed
449
vtkOSPRayRendererNode::~vtkOSPRayRendererNode()
450
{
Tim Biedert's avatar
Tim Biedert committed
451
452
  if (this->Internal->Backend != nullptr)
  {
453
    RTW::Backend* backend = this->Internal->Backend;
454
455
456
457
458
459
    ospRelease(this->ODummyInstanceData);
    ospRelease(this->OWorld);
    ospRelease(this->ORenderer);
    ospRelease(this->OFrameBuffer);
    ospRelease(this->OLightArray);
    ospRelease(this->OCamera);
Tim Biedert's avatar
Tim Biedert committed
460
  }
461
  this->AccumulateMatrix->Delete();
462
  delete this->Internal;
463
464
465
}

//----------------------------------------------------------------------------
466
void vtkOSPRayRendererNode::SetSamplesPerPixel(int value, vtkRenderer* renderer)
467
{
468
  if (!renderer)
469
  {
470
    return;
471
  }
472
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
473
  info->Set(vtkOSPRayRendererNode::SAMPLES_PER_PIXEL(), value);
474
475
476
}

//----------------------------------------------------------------------------
477
int vtkOSPRayRendererNode::GetSamplesPerPixel(vtkRenderer* renderer)
478
{
479
  if (!renderer)
480
  {
481
    return 1;
482
  }
483
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
484
  if (info && info->Has(vtkOSPRayRendererNode::SAMPLES_PER_PIXEL()))
485
  {
David DeMarle's avatar
David DeMarle committed
486
    return (info->Get(vtkOSPRayRendererNode::SAMPLES_PER_PIXEL()));
487
  }
488
489
  return 1;
}
490

491
//----------------------------------------------------------------------------
492
void vtkOSPRayRendererNode::SetMaxContribution(double value, vtkRenderer* renderer)
493
494
495
496
497
{
  if (!renderer)
  {
    return;
  }
498
  vtkInformation* info = renderer->GetInformation();
499
500
501
502
  info->Set(vtkOSPRayRendererNode::MAX_CONTRIBUTION(), value);
}

//----------------------------------------------------------------------------
503
double vtkOSPRayRendererNode::GetMaxContribution(vtkRenderer* renderer)
504
505
506
507
508
509
{
  constexpr double DEFAULT_MAX_CONTRIBUTION = 2.0;
  if (!renderer)
  {
    return DEFAULT_MAX_CONTRIBUTION;
  }
510
  vtkInformation* info = renderer->GetInformation();
511
512
513
514
515
516
517
518
  if (info && info->Has(vtkOSPRayRendererNode::MAX_CONTRIBUTION()))
  {
    return (info->Get(vtkOSPRayRendererNode::MAX_CONTRIBUTION()));
  }
  return DEFAULT_MAX_CONTRIBUTION;
}

//----------------------------------------------------------------------------
519
void vtkOSPRayRendererNode::SetMaxDepth(int value, vtkRenderer* renderer)
520
521
522
523
524
{
  if (!renderer)
  {
    return;
  }
525
  vtkInformation* info = renderer->GetInformation();
526
527
528
529
  info->Set(vtkOSPRayRendererNode::MAX_DEPTH(), value);
}

//----------------------------------------------------------------------------
530
int vtkOSPRayRendererNode::GetMaxDepth(vtkRenderer* renderer)
531
532
533
534
535
536
{
  constexpr int DEFAULT_MAX_DEPTH = 20;
  if (!renderer)
  {
    return DEFAULT_MAX_DEPTH;
  }
537
  vtkInformation* info = renderer->GetInformation();
538
539
540
541
542
543
544
545
  if (info && info->Has(vtkOSPRayRendererNode::MAX_DEPTH()))
  {
    return (info->Get(vtkOSPRayRendererNode::MAX_DEPTH()));
  }
  return DEFAULT_MAX_DEPTH;
}

//----------------------------------------------------------------------------
546
void vtkOSPRayRendererNode::SetMinContribution(double value, vtkRenderer* renderer)
547
548
549
550
551
{
  if (!renderer)
  {
    return;
  }
552
  vtkInformation* info = renderer->GetInformation();
553
554
555
556
  info->Set(vtkOSPRayRendererNode::MIN_CONTRIBUTION(), value);
}

//----------------------------------------------------------------------------
557
double vtkOSPRayRendererNode::GetMinContribution(vtkRenderer* renderer)
558
559
560
561
562
563
{
  constexpr double DEFAULT_MIN_CONTRIBUTION = 0.01;
  if (!renderer)
  {
    return DEFAULT_MIN_CONTRIBUTION;
  }
564
  vtkInformation* info = renderer->GetInformation();
565
566
567
568
569
570
571
572
  if (info && info->Has(vtkOSPRayRendererNode::MIN_CONTRIBUTION()))
  {
    return (info->Get(vtkOSPRayRendererNode::MIN_CONTRIBUTION()));
  }
  return DEFAULT_MIN_CONTRIBUTION;
}

//----------------------------------------------------------------------------
573
void vtkOSPRayRendererNode::SetRouletteDepth(int value, vtkRenderer* renderer)
574
575
576
577
578
{
  if (!renderer)
  {
    return;
  }
579
  vtkInformation* info = renderer->GetInformation();
580
581
582
583
  info->Set(vtkOSPRayRendererNode::ROULETTE_DEPTH(), value);
}

//----------------------------------------------------------------------------
584
int vtkOSPRayRendererNode::GetRouletteDepth(vtkRenderer* renderer)
585
586
587
588
589
590
{
  constexpr int DEFAULT_ROULETTE_DEPTH = 5;
  if (!renderer)
  {
    return DEFAULT_ROULETTE_DEPTH;
  }
591
  vtkInformation* info = renderer->GetInformation();
592
593
594
595
596
597
598
  if (info && info->Has(vtkOSPRayRendererNode::ROULETTE_DEPTH()))
  {
    return (info->Get(vtkOSPRayRendererNode::ROULETTE_DEPTH()));
  }
  return DEFAULT_ROULETTE_DEPTH;
}

Carson Brownlee's avatar
Carson Brownlee committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::SetVolumeAnisotropy(double value, vtkRenderer* renderer)
{
  if (!renderer)
  {
    return;
  }
  vtkInformation* info = renderer->GetInformation();
  info->Set(vtkOSPRayRendererNode::VOLUME_ANISOTROPY(), value);
}

//----------------------------------------------------------------------------
double vtkOSPRayRendererNode::GetVolumeAnisotropy(vtkRenderer* renderer)
{
  constexpr double DEFAULT_VOLUME_ANISOTROPY = 0.0;
  if (!renderer)
  {
    return DEFAULT_VOLUME_ANISOTROPY;
  }
  vtkInformation* info = renderer->GetInformation();
  if (info && info->Has(vtkOSPRayRendererNode::VOLUME_ANISOTROPY()))
  {
    return (info->Get(vtkOSPRayRendererNode::VOLUME_ANISOTROPY()));
  }
  return DEFAULT_VOLUME_ANISOTROPY;
}

626
//----------------------------------------------------------------------------
627
void vtkOSPRayRendererNode::SetVarianceThreshold(double value, vtkRenderer* renderer)
628
629
630
631
632
{
  if (!renderer)
  {
    return;
  }
633
  vtkInformation* info = renderer->GetInformation();
634
635
636
637
  info->Set(vtkOSPRayRendererNode::VARIANCE_THRESHOLD(), value);
}

//----------------------------------------------------------------------------
638
double vtkOSPRayRendererNode::GetVarianceThreshold(vtkRenderer* renderer)
639
{
640
  constexpr double DEFAULT_VARIANCE_THRESHOLD = 0.3;
641
642
643
644
  if (!renderer)
  {
    return DEFAULT_VARIANCE_THRESHOLD;
  }
645
  vtkInformation* info = renderer->GetInformation();
646
647
648
649
650
651
652
  if (info && info->Has(vtkOSPRayRendererNode::VARIANCE_THRESHOLD()))
  {
    return (info->Get(vtkOSPRayRendererNode::VARIANCE_THRESHOLD()));
  }
  return DEFAULT_VARIANCE_THRESHOLD;
}

653
//----------------------------------------------------------------------------
654
655
void vtkOSPRayRendererNode::SetMaterialLibrary(
  vtkOSPRayMaterialLibrary* value, vtkRenderer* renderer)
656
657
658
659
660
{
  if (!renderer)
  {
    return;
  }
661
  vtkInformation* info = renderer->GetInformation();
662
663
664
665
  info->Set(vtkOSPRayRendererNode::MATERIAL_LIBRARY(), value);
}

//----------------------------------------------------------------------------
666
vtkOSPRayMaterialLibrary* vtkOSPRayRendererNode::GetMaterialLibrary(vtkRenderer* renderer)
667
668
669
670
671
{
  if (!renderer)
  {
    return nullptr;
  }
672
  vtkInformation* info = renderer->GetInformation();
673
674
  if (info && info->Has(vtkOSPRayRendererNode::MATERIAL_LIBRARY()))
  {
675
    vtkObjectBase* obj = info->Get(vtkOSPRayRendererNode::MATERIAL_LIBRARY());
676
677
678
679
680
    return (vtkOSPRayMaterialLibrary::SafeDownCast(obj));
  }
  return nullptr;
}

681
//----------------------------------------------------------------------------
682
void vtkOSPRayRendererNode::SetMaxFrames(int value, vtkRenderer* renderer)
683
684
{
  if (!renderer)
685
  {
686
    return;
687
  }
688
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
689
  info->Set(vtkOSPRayRendererNode::MAX_FRAMES(), value);
690
691
692
}

//----------------------------------------------------------------------------
693
int vtkOSPRayRendererNode::GetMaxFrames(vtkRenderer* renderer)
694
695
{
  if (!renderer)
696
  {
697
    return 1;
698
  }
699
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
700
  if (info && info->Has(vtkOSPRayRendererNode::MAX_FRAMES()))
701
  {
David DeMarle's avatar
David DeMarle committed
702
    return (info->Get(vtkOSPRayRendererNode::MAX_FRAMES()));
703
  }
704
705
706
  return 1;
}

707
//----------------------------------------------------------------------------
708
void vtkOSPRayRendererNode::SetRendererType(std::string name, vtkRenderer* renderer)
709
710
{
  if (!renderer)
711
  {
712
    return;
713
  }
714
  vtkInformation* info = renderer->GetInformation();
Tim Biedert's avatar
Tim Biedert committed
715
716

#ifdef VTK_ENABLE_OSPRAY
717
  if ("scivis" == name || "OSPRay raycaster" == name)
Tim Biedert's avatar
Tim Biedert committed
718
  {
719
720
721
722
723
    info->Set(vtkOSPRayRendererNode::RENDERER_TYPE(), "scivis");
  }
  if ("pathtracer" == name || "OSPRay pathtracer" == name)
  {
    info->Set(vtkOSPRayRendererNode::RENDERER_TYPE(), "pathtracer");
Tim Biedert's avatar
Tim Biedert committed
724
725
726
727
  }
#endif

#ifdef VTK_ENABLE_VISRTX
728
  if ("optix pathtracer" == name || "OptiX pathtracer" == name)
Tim Biedert's avatar
Tim Biedert committed
729
  {
730
    info->Set(vtkOSPRayRendererNode::RENDERER_TYPE(), "optix pathtracer");
Tim Biedert's avatar
Tim Biedert committed
731
732
  }
#endif
733
734
735
}

//----------------------------------------------------------------------------
736
std::string vtkOSPRayRendererNode::GetRendererType(vtkRenderer* renderer)
737
738
{
  if (!renderer)
739
  {
Tim Biedert's avatar
Tim Biedert committed
740
#ifdef VTK_ENABLE_OSPRAY
741
    return std::string("scivis");
Tim Biedert's avatar
Tim Biedert committed
742
743
744
#else
    return std::string("optix pathtracer");
#endif
745
  }
746
  vtkInformation* info = renderer->GetInformation();
747
  if (info && info->Has(vtkOSPRayRendererNode::RENDERER_TYPE()))
748
  {
749
    return (info->Get(vtkOSPRayRendererNode::RENDERER_TYPE()));
750
  }
Tim Biedert's avatar
Tim Biedert committed
751
#ifdef VTK_ENABLE_OSPRAY
752
  return std::string("scivis");
Tim Biedert's avatar
Tim Biedert committed
753
#else
754
  return std::string("optix pathtracer");
Tim Biedert's avatar
Tim Biedert committed
755
#endif
756
757
}

758
//----------------------------------------------------------------------------
759
void vtkOSPRayRendererNode::SetAmbientSamples(int value, vtkRenderer* renderer)
760
761
{
  if (!renderer)
762
  {
763
    return;
764
  }
765
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
766
  info->Set(vtkOSPRayRendererNode::AMBIENT_SAMPLES(), value);
767
768
769
}

//----------------------------------------------------------------------------
770
int vtkOSPRayRendererNode::GetAmbientSamples(vtkRenderer* renderer)
771
772
{
  if (!renderer)
773
  {
774
    return 0;
775
  }
776
  vtkInformation* info = renderer->GetInformation();
David DeMarle's avatar
David DeMarle committed
777
  if (info && info->Has(vtkOSPRayRendererNode::AMBIENT_SAMPLES()))
778
  {
David DeMarle's avatar
David DeMarle committed
779
    return (info->Get(vtkOSPRayRendererNode::AMBIENT_SAMPLES()));
780
  }
781
  return 0;
782
783
}

784
//----------------------------------------------------------------------------
785
void vtkOSPRayRendererNode::SetCompositeOnGL(int value, vtkRenderer* renderer)
786
787
{
  if (!renderer)
788
  {
789
    return;
790
  }
791
  vtkInformation* info = renderer->GetInformation();
792
793
794
795
  info->Set(vtkOSPRayRendererNode::COMPOSITE_ON_GL(), value);
}

//----------------------------------------------------------------------------
796
int vtkOSPRayRendererNode::GetCompositeOnGL(vtkRenderer* renderer)
797
798
{
  if (!renderer)
799
  {
800
    return 0;
801
  }
802
  vtkInformation* info = renderer->GetInformation();
803
  if (info && info->Has(vtkOSPRayRendererNode::COMPOSITE_ON_GL()))
804
  {
805
    return (info->Get(vtkOSPRayRendererNode::COMPOSITE_ON_GL()));
806
  }
807
808
809
  return 0;
}

810
//----------------------------------------------------------------------------
811
void vtkOSPRayRendererNode::SetNorthPole(double* value, vtkRenderer* renderer)
812
813
814
815
816
{
  if (!renderer)
  {
    return;
  }
817
  vtkInformation* info = renderer->GetInformation();
818
819
820
821
  info->Set(vtkOSPRayRendererNode::NORTH_POLE(), value, 3);
}

//----------------------------------------------------------------------------
822
double* vtkOSPRayRendererNode::GetNorthPole(vtkRenderer* renderer)
823
824
825
826
827
{
  if (!renderer)
  {
    return nullptr;
  }
828
  vtkInformation* info = renderer->GetInformation();
829
830
831
832
833
834
835
836
  if (info && info->Has(vtkOSPRayRendererNode::NORTH_POLE()))
  {
    return (info->Get(vtkOSPRayRendererNode::NORTH_POLE()));
  }
  return nullptr;
}

//----------------------------------------------------------------------------
837
void vtkOSPRayRendererNode::SetEastPole(double* value, vtkRenderer* renderer)
838
839
840
841
842
{
  if (!renderer)
  {
    return;
  }
843
  vtkInformation* info = renderer->GetInformation();
844
845
846
847
  info->Set(vtkOSPRayRendererNode::EAST_POLE(), value, 3);
}

//----------------------------------------------------------------------------
848
double* vtkOSPRayRendererNode::GetEastPole(vtkRenderer* renderer)
849
850
851
852
853
{
  if (!renderer)
  {
    return nullptr;
  }
854
  vtkInformation* info = renderer->GetInformation();
855
856
857
858
859
860
861
  if (info && info->Has(vtkOSPRayRendererNode::EAST_POLE()))
  {
    return (info->Get(vtkOSPRayRendererNode::EAST_POLE()));
  }
  return nullptr;
}

862
//----------------------------------------------------------------------------
863
void vtkOSPRayRendererNode::SetViewTime(double value, vtkRenderer* renderer)
864
865
866
867
868
{
  if (!renderer)
  {
    return;
  }
869
  vtkInformation* info = renderer->GetInformation();
870
871
872
873
  info->Set(vtkOSPRayRendererNode::VIEW_TIME(), value);
}

//----------------------------------------------------------------------------
874
double vtkOSPRayRendererNode::GetViewTime(vtkRenderer* renderer)
875
876
877
878
879
{
  if (!renderer)
  {
    return 0;
  }
880
  vtkInformation* info = renderer->GetInformation();
881
882
883
884
885
886
887
888
  if (info && info->Has(vtkOSPRayRendererNode::VIEW_TIME()))
  {
    return (info->Get(vtkOSPRayRendererNode::VIEW_TIME()));
  }
  return 0;
}

//----------------------------------------------------------------------------
889
void vtkOSPRayRendererNode::SetTimeCacheSize(int value, vtkRenderer* renderer)
890
891
892
893
894
{
  if (!renderer)
  {
    return;
  }
895
  vtkInformation* info = renderer->GetInformation();
896
897
898
899
  info->Set(vtkOSPRayRendererNode::TIME_CACHE_SIZE(), value);
}

//----------------------------------------------------------------------------
900
int vtkOSPRayRendererNode::GetTimeCacheSize(vtkRenderer* renderer)
901
902
903
904
905
{
  if (!renderer)
  {
    return 0;
  }
906
  vtkInformation* info = renderer->GetInformation();
907
908
909
910
911
912
913
  if (info && info->Has(vtkOSPRayRendererNode::TIME_CACHE_SIZE()))
  {
    return (info->Get(vtkOSPRayRendererNode::TIME_CACHE_SIZE()));
  }
  return 0;
}

914
//----------------------------------------------------------------------------
915
void vtkOSPRayRendererNode::SetDenoiserThreshold(int value, vtkRenderer* renderer)
916
917
918
919
920
{
  if (!renderer)
  {
    return;
  }
921
  vtkInformation* info = renderer->GetInformation();
922
923
924
925
  info->Set(vtkOSPRayRendererNode::DENOISER_THRESHOLD(), value);
}

//----------------------------------------------------------------------------
926
int vtkOSPRayRendererNode::GetDenoiserThreshold(vtkRenderer* renderer)
927
928
929
930
931
{
  if (!renderer)
  {
    return 4;
  }
932
  vtkInformation* info = renderer->GetInformation();
933
934
935
936
937
938
939
940
  if (info && info->Has(vtkOSPRayRendererNode::DENOISER_THRESHOLD()))
  {
    return (info->Get(vtkOSPRayRendererNode::DENOISER_THRESHOLD()));
  }
  return 4;
}

//----------------------------------------------------------------------------
941
void vtkOSPRayRendererNode::SetEnableDenoiser(int value, vtkRenderer* renderer)
942
943
944
945
946
{
  if (!renderer)
  {
    return;
  }
947
  vtkInformation* info = renderer->GetInformation();
948
949
950
951
  info->Set(vtkOSPRayRendererNode::ENABLE_DENOISER(), value);
}

//----------------------------------------------------------------------------
952
int vtkOSPRayRendererNode::GetEnableDenoiser(vtkRenderer* renderer)
953
954
955
{
  if (!renderer)
  {
Tim Biedert's avatar
Tim Biedert committed
956
    return 0;
957
  }