vtkPVView.cxx 21.2 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   ParaView
Sebastien Jourdain's avatar
Sebastien Jourdain committed
4
  Module:    vtkPVView.cxx
5 6 7 8 9 10 11 12 13 14 15 16

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkPVView.h"

17
#include "vtkBoundingBox.h"
18
#include "vtkCacheSizeKeeper.h"
19 20
#include "vtkCommunicator.h"
#include "vtkGenericOpenGLRenderWindow.h"
21
#include "vtkInformation.h"
22
#include "vtkInformationObjectBaseKey.h"
23 24
#include "vtkInformationRequestKey.h"
#include "vtkInformationVector.h"
25
#include "vtkMultiProcessController.h"
26 27
#include "vtkObjectFactory.h"
#include "vtkPVDataRepresentation.h"
28
#include "vtkPVLogger.h"
29
#include "vtkPVOptions.h"
30 31 32
#include "vtkPVProcessWindow.h"
#include "vtkPVRenderingCapabilitiesInformation.h"
#include "vtkPVServerInformation.h"
33
#include "vtkPVSession.h"
34
#include "vtkPVStreamingMacros.h"
35
#include "vtkProcessModule.h"
36
#include "vtkRenderWindow.h"
37
#include "vtkRendererCollection.h"
38
#include "vtkTimerLog.h"
39

40
#include <cassert>
41
#include <map>
42
#include <sstream>
43

44 45 46
namespace
{
class vtkOffscreenOpenGLRenderWindow : public vtkGenericOpenGLRenderWindow
47 48
{
public:
49 50 51 52
  static vtkOffscreenOpenGLRenderWindow* New();
  vtkTypeMacro(vtkOffscreenOpenGLRenderWindow, vtkGenericOpenGLRenderWindow);

  void SetContext(vtkOpenGLRenderWindow* cntxt)
53
  {
54 55 56 57 58 59
    if (cntxt == this->Context)
    {
      return;
    }

    if (this->Context)
60
    {
61 62
      this->MakeCurrent();
      this->Finalize();
63
    }
64 65 66 67

    this->SetReadyForRendering(false);
    this->Context = cntxt;
    if (cntxt)
68
    {
69 70 71
      this->SetForceMaximumHardwareLineWidth(1);
      this->SetReadyForRendering(true);
      this->SetOwnContext(0);
72
    }
73
  }
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  vtkOpenGLRenderWindow* GetContext() { return this->Context; }

  void MakeCurrent() override
  {
    if (this->Context)
    {
      this->Context->MakeCurrent();
      this->Superclass::MakeCurrent();
    }
  }

  bool IsCurrent() override { return this->Context ? this->Context->IsCurrent() : false; }

  void SetUseOffScreenBuffers(bool) override {}
  void SetShowWindow(bool) override {}

  void Render() override
  {
    if (this->Context && this->GetReadyForRendering())
    {
      if (!this->Initialized)
      {
96 97
        // ensures that context is created.
        vtkPVProcessWindow::PrepareForRendering();
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
        this->Context->MakeCurrent();
        this->OpenGLInit();
      }
      this->Superclass::Render();
    }
  }

  vtkOpenGLState* GetState() override
  {
    return this->Context ? this->Context->GetState() : this->Superclass::GetState();
  }

protected:
  vtkOffscreenOpenGLRenderWindow()
  {
    this->SetReadyForRendering(false);
    this->Superclass::SetShowWindow(false);
    this->Superclass::SetUseOffScreenBuffers(true);
  }

private:
  vtkOffscreenOpenGLRenderWindow(const vtkOffscreenOpenGLRenderWindow&) = delete;
  void operator=(const vtkOffscreenOpenGLRenderWindow&) = delete;

  vtkSmartPointer<vtkOpenGLRenderWindow> Context;
123 124
};

125 126
vtkStandardNewMacro(vtkOffscreenOpenGLRenderWindow);
}
127 128

vtkInformationKeyMacro(vtkPVView, REQUEST_RENDER, Request);
129 130 131
vtkInformationKeyMacro(vtkPVView, REQUEST_UPDATE_LOD, Request);
vtkInformationKeyMacro(vtkPVView, REQUEST_UPDATE, Request);
vtkInformationKeyRestrictedMacro(vtkPVView, VIEW, ObjectBase, "vtkPVView");
132
//----------------------------------------------------------------------------
133
bool vtkPVView::EnableStreaming = false;
134 135 136 137
//----------------------------------------------------------------------------
void vtkPVView::SetEnableStreaming(bool val)
{
  vtkPVView::EnableStreaming = val;
138
  vtkStreamingStatusMacro("Setting streaming status: " << val);
139 140 141 142 143 144 145 146
}

//----------------------------------------------------------------------------
bool vtkPVView::GetEnableStreaming()
{
  return vtkPVView::EnableStreaming;
}

147
//----------------------------------------------------------------------------
148 149 150
bool vtkPVView::UseGenericOpenGLRenderWindow = false;
//----------------------------------------------------------------------------
void vtkPVView::SetUseGenericOpenGLRenderWindow(bool val)
151
{
152 153 154 155 156 157 158 159
  vtkPVView::UseGenericOpenGLRenderWindow = val;
}

//----------------------------------------------------------------------------
bool vtkPVView::GetUseGenericOpenGLRenderWindow()
{
  return vtkPVView::UseGenericOpenGLRenderWindow;
}
160

161 162 163 164 165
//----------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkPVView, RenderWindow, vtkRenderWindow);
//----------------------------------------------------------------------------
vtkPVView::vtkPVView(bool create_render_window)
{
166 167 168
  // Ensure vtkProcessModule is setup correctly.
  vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
  if (!pm)
169
  {
170 171
    vtkErrorMacro("vtkProcessModule not initialized. Aborting.");
    abort();
172
  }
173

174 175 176 177 178 179 180 181 182
  // enable/disable streaming. This doesn't need to done on every constructor
  // call, but no harm even if it is done.
  if (auto options = pm->GetOptions())
  {
    vtkPVView::SetEnableStreaming(options->GetEnableStreaming() != 0);
  }

  vtkStreamingStatusMacro("View Streaming  Status: " << vtkPVView::GetEnableStreaming());

183 184
  vtkPVSession* activeSession = vtkPVSession::SafeDownCast(pm->GetActiveSession());
  if (!activeSession)
185
  {
186 187
    vtkErrorMacro("Could not find any active session. Aborting.");
    abort();
188
  }
189

190
  this->Session = activeSession;
191 192 193 194 195 196 197
  this->ViewTime = 0.0;
  this->CacheKey = 0.0;
  this->UseCache = false;

  this->RequestInformation = vtkInformation::New();
  this->ReplyInformationVector = vtkInformationVector::New();

198
  this->ViewTimeValid = false;
199 200 201

  this->Size[1] = this->Size[0] = 300;
  this->Position[0] = this->Position[1] = 0;
202
  this->PPI = 96;
203

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
204 205
  this->InCaptureScreenshot = false;

206 207 208 209 210 211 212 213
  // Create render window, if requested.
  this->RenderWindow = create_render_window ? this->NewRenderWindow() : nullptr;
  if (this->RenderWindow)
  {
    this->RenderWindow->SetSize(this->Size);
    this->RenderWindow->SetPosition(this->Position);
    this->RenderWindow->SetDPI(this->PPI);
  }
214 215 216 217 218 219 220
}

//----------------------------------------------------------------------------
vtkPVView::~vtkPVView()
{
  this->RequestInformation->Delete();
  this->ReplyInformationVector->Delete();
221
  this->SetRenderWindow(nullptr);
222 223 224
}

//----------------------------------------------------------------------------
225
vtkRenderWindow* vtkPVView::NewRenderWindow()
226
{
227 228 229 230 231
  auto pm = vtkProcessModule::GetProcessModule();
  auto options = pm->GetOptions();

  vtkSmartPointer<vtkRenderWindow> window;
  switch (pm->GetProcessType())
232
  {
233 234 235
    case vtkProcessModule::PROCESS_DATA_SERVER:
      window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
      break;
236

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    case vtkProcessModule::PROCESS_CLIENT:
      if (vtkPVView::GetUseGenericOpenGLRenderWindow())
      {
        window = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
      }
      else if (options->GetForceOffscreenRendering())
      {
        // this may be a headless window if ParaView was built with headless
        // capabilities.
        window = vtkPVRenderingCapabilitiesInformation::NewOffscreenRenderWindow();
      }
      else
      {
        window = vtkSmartPointer<vtkRenderWindow>::New();
      }
      break;
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    case vtkProcessModule::PROCESS_SERVER:
    case vtkProcessModule::PROCESS_RENDER_SERVER:
    case vtkProcessModule::PROCESS_BATCH:
      if (auto processWindow = vtkPVProcessWindow::GetRenderWindow())
      {
        auto owindow = vtkSmartPointer<vtkOffscreenOpenGLRenderWindow>::New();
        owindow->SetContext(vtkOpenGLRenderWindow::SafeDownCast(processWindow));
        owindow->DoubleBufferOff();
        window = owindow;
      }
      else
      {
        vtkErrorMacro(
          "Expecting a process window, which is missing. Aborting for debugging purposes.");
        abort();
      }
      break;

    default:
      vtkErrorMacro("Invalid process type. Aborting for debugging purposes.");
      abort();
275
  }
276

277
  if (window)
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
    vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(),
      "created a `%s` as a new render window for view %s", vtkLogIdentifier(window),
      vtkLogIdentifier(this));

    window->AlphaBitPlanesOn();

    std::ostringstream str;
    switch (pm->GetProcessType())
    {
      case vtkProcessModule::PROCESS_DATA_SERVER:
        str << "ParaView Data-Server";
        break;
      case vtkProcessModule::PROCESS_SERVER:
        str << "ParaView Server";
        break;
      case vtkProcessModule::PROCESS_RENDER_SERVER:
        str << "ParaView Render-Server";
        break;
      case vtkProcessModule::PROCESS_CLIENT:
      case vtkProcessModule::PROCESS_BATCH:
      default:
        str << "ParaView";
        break;
    }
    if (pm->GetNumberOfLocalPartitions() > 1)
    {
      str << pm->GetPartitionId();
    }
    window->SetWindowName(str.str().c_str());
    window->Register(this);
    return window;
310 311
  }

312 313 314
  vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(),
    "created `nullptr` as a new render window for view %s", vtkLogIdentifier(this));
  return nullptr;
315 316
}

317 318 319
//----------------------------------------------------------------------------
void vtkPVView::SetPosition(int x, int y)
{
320 321
  this->Position[0] = x;
  this->Position[1] = y;
322 323 324 325 326
}

//----------------------------------------------------------------------------
void vtkPVView::SetSize(int x, int y)
{
327
  if (this->InTileDisplayMode() || this->InCaveDisplayMode())
328
  {
329 330 331 332 333 334 335 336 337
    // the size request is ignored.
  }
  else if (auto window = this->GetRenderWindow())
  {
    const auto cur_size = window->GetActualSize();
    if (cur_size[0] != x || cur_size[1] != y)
    {
      window->SetSize(x, y);
    }
338
  }
339 340
  this->Size[0] = x;
  this->Size[1] = y;
341 342 343
}

//----------------------------------------------------------------------------
344 345 346
void vtkPVView::SetPPI(int ppi)
{
  this->PPI = ppi;
347
  if (auto window = this->GetRenderWindow())
348
  {
349
    window->SetDPI(ppi);
350 351 352 353 354
  }
  this->Modified();
}

//----------------------------------------------------------------------------
355 356
void vtkPVView::SetViewTime(double time)
{
357
  if (!this->ViewTimeValid || this->ViewTime != time)
358
  {
359
    this->ViewTime = time;
360
    this->ViewTimeValid = true;
361 362
    this->InvokeEvent(ViewTimeChangedEvent);
    this->Modified();
363
  }
364 365 366 367 368
}

//----------------------------------------------------------------------------
bool vtkPVView::InTileDisplayMode()
{
369 370
  auto serverInfo = this->Session->GetServerInformation();
  return (serverInfo->GetTileDimensions()[0] > 0 || serverInfo->GetTileDimensions()[1] > 0);
371 372
}

373 374 375
//----------------------------------------------------------------------------
bool vtkPVView::InCaveDisplayMode()
{
376 377
  auto serverInfo = this->Session->GetServerInformation();
  return (serverInfo->GetNumberOfMachines() > 0) && !this->InTileDisplayMode();
378 379
}

380 381 382
//----------------------------------------------------------------------------
bool vtkPVView::GetLocalProcessSupportsInteraction()
{
383 384
  auto pm = vtkProcessModule::GetProcessModule();
  switch (pm->GetProcessType())
385
  {
386 387 388 389 390 391 392 393 394 395 396 397
    case vtkProcessModule::PROCESS_CLIENT:
      assert(pm->GetPartitionId() == 0);
      return true;

    case vtkProcessModule::PROCESS_BATCH:
      return (pm->GetPartitionId() == 0);

    case vtkProcessModule::PROCESS_DATA_SERVER:
    case vtkProcessModule::PROCESS_SERVER:
    case vtkProcessModule::PROCESS_RENDER_SERVER:
    default:
      return false;
398
  }
399 400
}

401 402 403 404 405 406 407 408 409 410 411 412
//----------------------------------------------------------------------------
void vtkPVView::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "ViewTime: " << this->ViewTime << endl;
  os << indent << "CacheKey: " << this->CacheKey << endl;
  os << indent << "UseCache: " << this->UseCache << endl;
}

//----------------------------------------------------------------------------
void vtkPVView::PrepareForScreenshot()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
413
  this->InCaptureScreenshot = true;
414 415 416 417 418
}

//----------------------------------------------------------------------------
void vtkPVView::CleanupAfterScreenshot()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
419
  this->InCaptureScreenshot = false;
420 421 422 423 424
}

//----------------------------------------------------------------------------
void vtkPVView::Update()
{
425 426
  vtkVLogScopeF(PARAVIEW_LOG_RENDERING_VERBOSITY(), "%s: update view", this->GetLogName().c_str());

427
  vtkTimerLog::MarkStartEvent("vtkPVView::Update");
428 429
  // Ensure that cache size if synchronized among the processes.
  if (this->GetUseCache())
430
  {
431
    vtkCacheSizeKeeper* cacheSizeKeeper = vtkCacheSizeKeeper::GetInstance();
432
    vtkTypeUInt64 cache_full = 0;
433
    if (cacheSizeKeeper->GetCacheSize() > cacheSizeKeeper->GetCacheLimit())
434
    {
435
      cache_full = 1;
436
    }
437
    this->AllReduce(cache_full, cache_full, vtkCommunicator::MAX_OP);
438
    cacheSizeKeeper->SetCacheFull(cache_full > 0);
439
  }
440

441 442
  this->CallProcessViewRequest(
    vtkPVView::REQUEST_UPDATE(), this->RequestInformation, this->ReplyInformationVector);
443
  vtkTimerLog::MarkEndEvent("vtkPVView::Update");
444 445 446 447 448 449 450 451 452 453
}

//----------------------------------------------------------------------------
void vtkPVView::CallProcessViewRequest(
  vtkInformationRequestKey* type, vtkInformation* inInfo, vtkInformationVector* outVec)
{
  int num_reprs = this->GetNumberOfRepresentations();
  outVec->SetNumberOfInformationObjects(num_reprs);

  if (type == REQUEST_UPDATE())
454
  {
455
    // Pass the view time before updating the representations.
456 457
    for (int cc = 0; cc < num_reprs; cc++)
    {
458 459 460
      vtkDataRepresentation* repr = this->GetRepresentation(cc);
      vtkPVDataRepresentation* pvrepr = vtkPVDataRepresentation::SafeDownCast(repr);
      if (pvrepr)
461
      {
462
        // Pass the view time information to the representation
463 464
        if (this->ViewTimeValid)
        {
465
          pvrepr->SetUpdateTime(this->GetViewTime());
466 467 468
        }
      }
    }
469
  }
470

471 472 473 474 475
  // NOTE: This will create a reference loop (depending on what inInfo is). If
  // it's this->RequestInformation, then we have a loop and hence it's
  // essential to call vtkInformation::Clear() before this method returns.
  inInfo->Set(VIEW(), this);

476 477
  for (int cc = 0; cc < num_reprs; cc++)
  {
478 479 480 481 482
    vtkInformation* outInfo = outVec->GetInformationObject(cc);
    outInfo->Clear();
    vtkDataRepresentation* repr = this->GetRepresentation(cc);
    vtkPVDataRepresentation* pvrepr = vtkPVDataRepresentation::SafeDownCast(repr);
    if (pvrepr)
483
    {
484
      pvrepr->ProcessViewRequest(type, inInfo, outInfo);
485
    }
486
    else if (repr && type == REQUEST_UPDATE())
487
    {
488 489
      repr->Update();
    }
490
  }
491 492 493 494 495

  // Clear input information since we are done with the pass. This avoids any
  // need for garbage collection.
  inInfo->Clear();
}
496 497 498 499 500

//-----------------------------------------------------------------------------
void vtkPVView::AddRepresentationInternal(vtkDataRepresentation* rep)
{
  if (vtkPVDataRepresentation* drep = vtkPVDataRepresentation::SafeDownCast(rep))
501
  {
502
    if (drep->GetView() != this)
503 504 505 506 507
    {
      vtkErrorMacro(<< drep->GetClassName()
                    << " may not be calling this->Superclass::AddToView(...) in its "
                    << "AddToView implementation. Please fix that. "
                    << "Also check the same for RemoveFromView(..).");
508
    }
509
  }
510 511
  this->Superclass::AddRepresentationInternal(rep);
}
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643

//-----------------------------------------------------------------------------
void vtkPVView::ScaleRendererViewports(const double viewport[4])
{
  auto window = this->GetRenderWindow();
  if (!window)
  {
    return;
  }

  assert(viewport[0] >= 0 && viewport[0] <= 1.0);
  assert(viewport[1] >= 0 && viewport[1] <= 1.0);
  assert(viewport[2] >= 0 && viewport[2] <= 1.0);
  assert(viewport[3] >= 0 && viewport[3] <= 1.0);

  auto collection = window->GetRenderers();
  collection->InitTraversal();
  while (auto renderer = collection->GetNextItem())
  {
    renderer->SetViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
  }
}

//-----------------------------------------------------------------------------
void vtkPVView::AllReduce(const vtkBoundingBox& arg_source, vtkBoundingBox& dest)
{
  assert(this->Session);

  vtkVLogScopeF(PARAVIEW_LOG_RENDERING_VERBOSITY(), "all-reduce-bounds");

  vtkBoundingBox source = arg_source;
  if (!arg_source.IsValid())
  {
    source.Reset(); // need to make sure the min and max values are set to fixed ones.
  }

  auto pController = vtkMultiProcessController::GetGlobalController();
  if (pController)
  {
    pController->Reduce(source, dest, 0);
    source = dest;
  }

  auto cController = this->Session->GetController(vtkPVSession::CLIENT);
  if (cController)
  {
    assert(pController == nullptr || pController->GetLocalProcessId() == 0);
    double bds[6];
    source.GetBounds(bds);
    cController->Send(bds, 6, 1, 41232);
    cController->Receive(bds, 6, 1, 41233);
    source.SetBounds(bds);
  }

  auto crController = this->Session->GetController(vtkPVSession::RENDER_SERVER_ROOT);
  auto cdController = this->Session->GetController(vtkPVSession::DATA_SERVER_ROOT);
  if (crController == cdController)
  {
    cdController = nullptr;
  }

  if (crController)
  {
    double bds[6];
    crController->Receive(bds, 6, 1, 41232);
    source.AddBounds(bds);
  }

  if (cdController)
  {
    double bds[6];
    cdController->Receive(bds, 6, 1, 41232);
    source.AddBounds(bds);
  }

  if (crController)
  {
    double bds[6];
    source.GetBounds(bds);
    crController->Send(bds, 6, 1, 41233);
  }

  if (cdController)
  {
    double bds[6];
    source.GetBounds(bds);
    cdController->Send(bds, 6, 1, 41233);
  }

  if (pController)
  {
    double bds[6];
    source.GetBounds(bds);
    pController->Broadcast(bds, 6, 0);
    source.SetBounds(bds);
  }

  dest = source;

  if (arg_source.IsValid() && dest.IsValid())
  {
    double src_bds[6], dest_bds[6];
    arg_source.GetBounds(src_bds);
    dest.GetBounds(dest_bds);
    vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(),
      "source=(%g, %g, %g, %g, %g, %g), result=(%g, %g, %g, %g, %g, %g)", src_bds[0], src_bds[1],
      src_bds[2], src_bds[3], src_bds[4], src_bds[5], dest_bds[0], dest_bds[1], dest_bds[2],
      dest_bds[3], dest_bds[4], dest_bds[5]);
  }
  else if (arg_source.IsValid())
  {
    double src_bds[6];
    arg_source.GetBounds(src_bds);
    vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(),
      "source=(%g, %g, %g, %g, %g, %g), result=(invalid)", src_bds[0], src_bds[1], src_bds[2],
      src_bds[3], src_bds[4], src_bds[5]);
  }
  else if (dest.IsValid())
  {
    double dest_bds[6];
    dest.GetBounds(dest_bds);
    vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(),
      "source=(invalid), result=(%g, %g, %g, %g, %g, %g)", dest_bds[0], dest_bds[1], dest_bds[2],
      dest_bds[3], dest_bds[4], dest_bds[5]);
  }
  else
  {
    vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(), "source=(invalid), result=(invalid)");
  }
}

//-----------------------------------------------------------------------------
644 645
void vtkPVView::AllReduce(
  const vtkTypeUInt64 arg_source, vtkTypeUInt64& dest, int operation, bool skip_data_server)
646 647
{
  assert(this->Session);
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
  vtkVLogScopeF(PARAVIEW_LOG_RENDERING_VERBOSITY(), "all-reduce (op=%d)", operation);

  auto evaluator = [operation](vtkTypeUInt64 a, vtkTypeUInt64 b) {
    switch (operation)
    {
      case vtkCommunicator::MAX_OP:
        return std::max(a, b);
      case vtkCommunicator::MIN_OP:
        return std::min(a, b);
      case vtkCommunicator::SUM_OP:
        return a + b;
      default:
        abort();
    }
  };
663 664 665 666 667

  vtkTypeUInt64 source = arg_source;
  auto pController = vtkMultiProcessController::GetGlobalController();
  if (pController)
  {
668
    pController->Reduce(&source, &dest, 1, operation, 0);
669 670 671 672 673 674 675 676 677 678 679 680 681
    source = dest;
  }

  auto cController = this->Session->GetController(vtkPVSession::CLIENT);
  if (cController)
  {
    assert(pController == nullptr || pController->GetLocalProcessId() == 0);
    cController->Send(&source, 1, 1, 41234);
    cController->Receive(&source, 1, 1, 41235);
  }

  auto crController = this->Session->GetController(vtkPVSession::RENDER_SERVER_ROOT);
  auto cdController = this->Session->GetController(vtkPVSession::DATA_SERVER_ROOT);
682
  if (skip_data_server || (crController == cdController))
683 684 685 686 687 688 689 690
  {
    cdController = nullptr;
  }

  if (crController)
  {
    vtkTypeUInt64 val;
    crController->Receive(&val, 1, 1, 41234);
691
    source = evaluator(source, val);
692 693 694 695 696 697
  }

  if (cdController)
  {
    vtkTypeUInt64 val;
    cdController->Receive(&val, 1, 1, 41234);
698
    source = evaluator(source, val);
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
  }

  if (crController)
  {
    crController->Send(&source, 1, 1, 41235);
  }

  if (cdController)
  {
    cdController->Send(&source, 1, 1, 41235);
  }

  if (pController)
  {
    pController->Broadcast(&source, 1, 0);
  }

  dest = source;
  vtkVLogF(PARAVIEW_LOG_RENDERING_VERBOSITY(), "source=%llu, result=%llu", arg_source, dest);
}

//-----------------------------------------------------------------------------
void vtkPVView::SetTileScale(int x, int y)
{
  auto window = this->GetRenderWindow();
  if (window && !this->InTileDisplayMode() && !this->InCaveDisplayMode())
  {
    window->SetTileScale(x, y);
  }
}

//-----------------------------------------------------------------------------
void vtkPVView::SetTileViewport(double x0, double y0, double x1, double y1)
{
  auto window = this->GetRenderWindow();
  if (window && !this->InTileDisplayMode() && !this->InCaveDisplayMode())
  {
    window->SetTileViewport(x0, y0, x1, y1);
  }
}

//-----------------------------------------------------------------------------
vtkPVSession* vtkPVView::GetSession()
{
  return this->Session;
}