vtkPVRenderView.cxx 57.1 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   ParaView
Sebastien Jourdain's avatar
Sebastien Jourdain committed
4
  Module:    vtkPVRenderView.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 "vtkPVRenderView.h"

17
#include "vtk3DWidgetRepresentation.h"
18
#include "vtkAlgorithmOutput.h"
19 20 21 22 23
#include "vtkBoundingBox.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkDataRepresentation.h"
#include "vtkInformationDoubleKey.h"
24
#include "vtkInformationDoubleVectorKey.h"
25 26 27 28 29 30
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationObjectBaseKey.h"
#include "vtkInformationRequestKey.h"
#include "vtkInformationVector.h"
#include "vtkInteractorStyleRubberBand3D.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
31
#include "vtkInteractorStyleRubberBandZoom.h"
32 33 34
#include "vtkLight.h"
#include "vtkLightKit.h"
#include "vtkMath.h"
35
#include "vtkMatrix4x4.h"
36 37 38
#include "vtkMemberFunctionCommand.h"
#include "vtkMPIMoveData.h"
#include "vtkMultiProcessController.h"
39
#include "vtkMultiProcessStream.h"
40
#include "vtkNew.h"
41 42
#include "vtkObjectFactory.h"
#include "vtkPKdTree.h"
43
#include "vtkProcessModule.h"
44 45
#include "vtkPVAxesWidget.h"
#include "vtkPVCenterAxesActor.h"
46 47
#include "vtkPVDataRepresentation.h"
#include "vtkPVDisplayInformation.h"
48
#include "vtkPVGenericRenderWindowInteractor.h"
49
#include "vtkPVHardwareSelector.h"
50 51
#include "vtkPVInteractorStyle.h"
#include "vtkPVOptions.h"
52
#include "vtkPVSession.h"
53 54 55 56 57 58 59 60
#include "vtkPVSynchronizedRenderer.h"
#include "vtkPVSynchronizedRenderWindows.h"
#include "vtkPVTrackballRotate.h"
#include "vtkPVTrackballZoom.h"
#include "vtkRenderer.h"
#include "vtkRenderViewBase.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
61
#include "vtkPVDataDeliveryManager.h"
62 63 64
#include "vtkSelection.h"
#include "vtkSelectionNode.h"
#include "vtkSmartPointer.h"
65
#include "vtkStreamingDemandDrivenPipeline.h"
66
#include "vtkTimerLog.h"
67
#include "vtkTrackballPan.h"
68
#include "vtkTrivialProducer.h"
69 70 71
#include "vtkWeakPointer.h"

#include <assert.h>
72 73 74
#include <vector>
#include <set>
#include <map>
75 76 77 78

class vtkPVRenderView::vtkInternals
{
public:
79
  unsigned int UniqueId;
80
  vtkNew<vtkPVDataDeliveryManager> DeliveryManager;
81 82 83
  vtkInternals() : UniqueId(1)
  {
  }
84 85
};

86

Sebastien Jourdain's avatar
Sebastien Jourdain committed
87 88 89
//----------------------------------------------------------------------------
// Statics
//----------------------------------------------------------------------------
90
bool vtkPVRenderView::RemoteRenderingAllowed = true;
Sebastien Jourdain's avatar
Sebastien Jourdain committed
91
//----------------------------------------------------------------------------
92 93 94 95 96 97 98 99
vtkStandardNewMacro(vtkPVRenderView);
vtkInformationKeyMacro(vtkPVRenderView, USE_LOD, Integer);
vtkInformationKeyMacro(vtkPVRenderView, LOD_RESOLUTION, Double);
vtkInformationKeyMacro(vtkPVRenderView, NEED_ORDERED_COMPOSITING, Integer);
vtkCxxSetObjectMacro(vtkPVRenderView, LastSelection, vtkSelection);
//----------------------------------------------------------------------------
vtkPVRenderView::vtkPVRenderView()
{
100
  this->Internals = new vtkInternals();
101 102
  // non-reference counted, so no worries about reference loops.
  this->Internals->DeliveryManager->SetRenderView(this);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
103

104
  vtkPVOptions* options = vtkProcessModule::GetProcessModule()->GetOptions();
105

106
  this->RemoteRenderingAvailable = vtkPVRenderView::RemoteRenderingAllowed;
107

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
108 109
  this->StillRenderProcesses = vtkPVSession::NONE;
  this->InteractiveRenderProcesses = vtkPVSession::NONE;
110
  this->UsedLODForLastRender = false;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
111 112 113 114
  this->UseLODForInteractiveRender = false;
  this->UseOutlineForInteractiveRender = false;
  this->UseDistributedRenderingForStillRender = false;
  this->UseDistributedRenderingForInteractiveRender = false;
115
  this->MakingSelection = false;
116 117 118 119
  this->StillRenderImageReductionFactor = 1;
  this->InteractiveRenderImageReductionFactor = 2;
  this->RemoteRenderingThreshold = 0;
  this->LODRenderingThreshold = 0;
120
  this->ClientOutlineThreshold = 5;
121 122 123 124
  this->LODResolution = 0.5;
  this->UseLightKit = false;
  this->Interactor = 0;
  this->InteractorStyle = 0;
125 126
  this->TwoDInteractorStyle = 0;
  this->ThreeDInteractorStyle = 0;
127
  this->RubberBandStyle = 0;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
128
  this->RubberBandZoom = 0;
129 130 131 132 133 134 135 136 137 138
  this->CenterAxes = vtkPVCenterAxesActor::New();
  this->CenterAxes->SetComputeNormals(0);
  this->CenterAxes->SetPickable(0);
  this->CenterAxes->SetScale(0.25, 0.25, 0.25);
  this->OrientationWidget = vtkPVAxesWidget::New();
  this->InteractionMode = -1;
  this->LastSelection = NULL;
  this->UseOffscreenRenderingForScreenshots = false;
  this->UseInteractiveRenderingForSceenshots = false;
  this->UseOffscreenRendering = (options->GetUseOffscreenRendering() != 0);
139
  this->Selector = vtkPVHardwareSelector::New();
140
  this->SynchronizationCounter  = 0;
141
  this->PreviousParallelProjectionStatus = 0;
142
  this->NeedsOrderedCompositing = false;
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

  this->SynchronizedRenderers = vtkPVSynchronizedRenderer::New();

  if (this->SynchronizedWindows->GetLocalProcessIsDriver())
    {
    this->Interactor = vtkPVGenericRenderWindowInteractor::New();
    // essential to call Initialize() otherwise first time the render is called
    // on  the render window, it initializes the interactor which in turn
    // results in a call to Render() which can cause uncanny side effects.
    this->Interactor->Initialize();
    }

  vtkRenderWindow* window = this->SynchronizedWindows->NewRenderWindow();
  window->SetMultiSamples(0);
  window->SetOffScreenRendering(this->UseOffscreenRendering? 1 : 0);
  window->SetInteractor(this->Interactor);
  this->RenderView = vtkRenderViewBase::New();
  this->RenderView->SetRenderWindow(window);
  window->Delete();

  this->NonCompositedRenderer = vtkRenderer::New();
  this->NonCompositedRenderer->EraseOff();
  this->NonCompositedRenderer->InteractiveOff();
  this->NonCompositedRenderer->SetLayer(2);
  this->NonCompositedRenderer->SetActiveCamera(
    this->RenderView->GetRenderer()->GetActiveCamera());
  window->AddRenderer(this->NonCompositedRenderer);
  window->SetNumberOfLayers(3);
  this->RenderView->GetRenderer()->GetActiveCamera()->ParallelProjectionOff();

  vtkMemberFunctionCommand<vtkPVRenderView>* observer =
    vtkMemberFunctionCommand<vtkPVRenderView>::New();
  observer->SetCallback(*this, &vtkPVRenderView::ResetCameraClippingRange);
  this->GetRenderer()->AddObserver(vtkCommand::ResetCameraClippingRangeEvent,
    observer);
  observer->FastDelete();

  this->GetRenderer()->SetUseDepthPeeling(1);

  this->Light = vtkLight::New();
  this->Light->SetAmbientColor(1, 1, 1);
  this->Light->SetSpecularColor(1, 1, 1);
  this->Light->SetDiffuseColor(1, 1, 1);
  this->Light->SetIntensity(1.0);
  this->Light->SetLightType(2); // CameraLight
  this->LightKit = vtkLightKit::New();
  this->GetRenderer()->AddLight(this->Light);
  this->GetRenderer()->SetAutomaticLightCreation(0);

  if (this->Interactor)
    {
194 195 196 197
    this->InteractorStyle = // Default one will be the 3D
        this->ThreeDInteractorStyle = vtkPVInteractorStyle::New();
    this->TwoDInteractorStyle = vtkPVInteractorStyle::New();

198 199
    this->Interactor->SetRenderer(this->GetRenderer());
    this->Interactor->SetRenderWindow(this->GetRenderWindow());
200
    this->Interactor->SetInteractorStyle(this->ThreeDInteractorStyle);
201 202 203 204 205

    // Add some default manipulators. Applications can override them without
    // much ado.
    vtkPVTrackballRotate* manip = vtkPVTrackballRotate::New();
    manip->SetButton(1);
206
    this->ThreeDInteractorStyle->AddManipulator(manip);
207 208 209 210
    manip->Delete();

    vtkPVTrackballZoom* manip2 = vtkPVTrackballZoom::New();
    manip2->SetButton(3);
211
    this->ThreeDInteractorStyle->AddManipulator(manip2);
212 213
    manip2->Delete();

214 215
    vtkTrackballPan* manip3 = vtkTrackballPan::New();
    manip3->SetButton(2);
216
    this->ThreeDInteractorStyle->AddManipulator(manip3);
217 218
    manip3->Delete();

219 220
    this->RubberBandStyle = vtkInteractorStyleRubberBand3D::New();
    this->RubberBandStyle->RenderOnMouseMoveOff();
David E. DeMarle's avatar
David E. DeMarle committed
221
    vtkCommand* observer2 = vtkMakeMemberFunctionCommand(*this,
222 223
      &vtkPVRenderView::OnSelectionChangedEvent);
    this->RubberBandStyle->AddObserver(vtkCommand::SelectionChangedEvent,
David E. DeMarle's avatar
David E. DeMarle committed
224 225
      observer2);
    observer2->Delete();
226

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
227
    this->RubberBandZoom = vtkInteractorStyleRubberBandZoom::New();
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    }

  this->OrientationWidget->SetParentRenderer(this->GetRenderer());
  this->OrientationWidget->SetViewport(0, 0, 0.25, 0.25);
  this->OrientationWidget->SetInteractor(this->Interactor);

  this->GetRenderer()->AddActor(this->CenterAxes);

  this->SetInteractionMode(INTERACTION_MODE_3D);
}

//----------------------------------------------------------------------------
vtkPVRenderView::~vtkPVRenderView()
{
  // this ensure that the renderer releases graphics resources before the window
  // is destroyed.
244 245
  this->GetRenderWindow()->RemoveRenderer(this->NonCompositedRenderer);
  this->GetRenderWindow()->RemoveRenderer(this->GetRenderer());
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  this->GetNonCompositedRenderer()->SetRenderWindow(0);
  this->GetRenderer()->SetRenderWindow(0);

  this->SetLastSelection(NULL);
  this->Selector->Delete();
  this->SynchronizedRenderers->Delete();
  this->NonCompositedRenderer->Delete();
  this->RenderView->Delete();
  this->LightKit->Delete();
  this->Light->Delete();
  this->CenterAxes->Delete();
  this->OrientationWidget->Delete();

  if (this->Interactor)
    {
    this->Interactor->Delete();
    this->Interactor = 0;
    }
  if (this->InteractorStyle)
    {
266 267
    // Don't want to delete it as it is only pointing to either
    // [TwoDInteractorStyle, ThreeDInteractorStyle]
268 269
    this->InteractorStyle = 0;
    }
270 271 272 273 274 275 276 277 278 279
  if (this->TwoDInteractorStyle)
    {
    this->TwoDInteractorStyle->Delete();
    this->TwoDInteractorStyle = 0;
    }
  if (this->ThreeDInteractorStyle)
    {
    this->ThreeDInteractorStyle->Delete();
    this->ThreeDInteractorStyle = 0;
    }
280 281 282 283 284
  if (this->RubberBandStyle)
    {
    this->RubberBandStyle->Delete();
    this->RubberBandStyle = 0;
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
285 286 287 288 289
  if (this->RubberBandZoom)
    {
    this->RubberBandZoom->Delete();
    this->RubberBandZoom = 0;
    }
290

291 292
  delete this->Internals;
  this->Internals = NULL;
293 294
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
295
//----------------------------------------------------------------------------
296
vtkPVDataDeliveryManager* vtkPVRenderView::GetDeliveryManager()
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
297
{
298
  return this->Internals->DeliveryManager.GetPointer();
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
299 300
}

301 302 303 304 305 306 307 308
//----------------------------------------------------------------------------
void vtkPVRenderView::SetUseOffscreenRendering(bool use_offscreen)
{
  if (this->UseOffscreenRendering == use_offscreen)
    {
    return;
    }

309
  vtkPVOptions* options = vtkProcessModule::GetProcessModule()->GetOptions();
310 311 312 313 314 315 316 317 318
  bool process_use_offscreen = options->GetUseOffscreenRendering() != 0;

  this->UseOffscreenRendering = use_offscreen || process_use_offscreen;
  this->GetRenderWindow()->SetOffScreenRendering(this->UseOffscreenRendering);
}

//----------------------------------------------------------------------------
void vtkPVRenderView::Initialize(unsigned int id)
{
319 320 321 322 323
  if (this->Identifier == id)
    {
    // already initialized
    return;
    }
324 325 326
  this->SynchronizedWindows->AddRenderWindow(id, this->RenderView->GetRenderWindow());
  this->SynchronizedWindows->AddRenderer(id, this->RenderView->GetRenderer());
  this->SynchronizedWindows->AddRenderer(id, this->GetNonCompositedRenderer());
327

328 329
  this->SynchronizedRenderers->Initialize(
    this->SynchronizedWindows->GetSession(), id);
330 331 332 333
  this->SynchronizedRenderers->SetRenderer(this->RenderView->GetRenderer());

  this->Superclass::Initialize(id);
}
334

335 336 337
//----------------------------------------------------------------------------
void vtkPVRenderView::AddRepresentationInternal(vtkDataRepresentation* rep)
{
338 339
  vtkPVDataRepresentation* dataRep = vtkPVDataRepresentation::SafeDownCast(rep);
  if (dataRep != NULL)
340
    {
341 342 343
    // We only increase that counter when widget are not involved as in
    // collaboration mode only the master has the widget in its representation
    this->SynchronizationCounter++;
344
    unsigned int id = this->Internals->UniqueId++;
345
    this->Internals->DeliveryManager->RegisterRepresentation(id, dataRep);
346
    }
347

348 349 350 351 352 353
  this->Superclass::AddRepresentationInternal(rep);
}

//----------------------------------------------------------------------------
void vtkPVRenderView::RemoveRepresentationInternal(vtkDataRepresentation* rep)
{
354 355
  vtkPVDataRepresentation* dataRep = vtkPVDataRepresentation::SafeDownCast(rep);
  if (dataRep != NULL)
356
    {
357
    this->Internals->DeliveryManager->UnRegisterRepresentation(dataRep);
358

359 360 361
    // We only increase that counter when widget are not involved as in
    // collaboration mode only the master has the widget in its representation
    this->SynchronizationCounter++;
362 363 364
    }

  this->Superclass::RemoveRepresentationInternal(rep);
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
}

//----------------------------------------------------------------------------
vtkRenderer* vtkPVRenderView::GetRenderer()
{
  return this->RenderView->GetRenderer();
}

//----------------------------------------------------------------------------
void vtkPVRenderView::SetActiveCamera(vtkCamera* camera)
{
  this->GetRenderer()->SetActiveCamera(camera);
  this->GetNonCompositedRenderer()->SetActiveCamera(camera);
}

//----------------------------------------------------------------------------
vtkCamera* vtkPVRenderView::GetActiveCamera()
{
  return this->RenderView->GetRenderer()->GetActiveCamera();
}

//----------------------------------------------------------------------------
vtkRenderWindow* vtkPVRenderView::GetRenderWindow()
{
  return this->RenderView->GetRenderWindow();
}

//----------------------------------------------------------------------------
void vtkPVRenderView::SetInteractionMode(int mode)
{
  if (this->InteractionMode != mode)
    {
397 398 399 400 401
    if(this->InteractionMode == INTERACTION_MODE_3D)
      {
      this->PreviousParallelProjectionStatus = this->GetActiveCamera()->GetParallelProjection();
      }

402 403 404 405 406 407 408 409 410 411 412
    this->InteractionMode = mode;
    this->Modified();

    if (this->Interactor == NULL)
      {
      return;
      }

    switch (this->InteractionMode)
      {
    case INTERACTION_MODE_3D:
413 414
      this->Interactor->SetInteractorStyle(
            this->InteractorStyle = this->ThreeDInteractorStyle);
415
      // Get back to the previous state
416 417
      this->GetActiveCamera()->SetParallelProjection(this->PreviousParallelProjectionStatus);
      break;
418
    case INTERACTION_MODE_2D:
419 420 421
      this->Interactor->SetInteractorStyle(
            this->InteractorStyle = this->TwoDInteractorStyle);
      this->GetActiveCamera()->SetParallelProjection(1);
422 423 424 425 426 427
      break;

    case INTERACTION_MODE_SELECTION:
      this->Interactor->SetInteractorStyle(this->RubberBandStyle);
      break;

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
428 429
    case INTERACTION_MODE_ZOOM:
      this->Interactor->SetInteractorStyle(this->RubberBandZoom);
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
      break;
      }
    }
}

//----------------------------------------------------------------------------
void vtkPVRenderView::OnSelectionChangedEvent()
{
  int region[4];
  this->RubberBandStyle->GetStartPosition(&region[0]);
  this->RubberBandStyle->GetEndPosition(&region[2]);

  // NOTE: This gets called on the driver i.e. client or root-node in batch mode.
  // That's not necessarily the node on which the selection can be made, since
  // data may not be on this process.

  // selection is a data-selection (not geometry selection).
  int ordered_region[4];
  ordered_region[0] = region[0] < region[2]? region[0] : region[2];
  ordered_region[2] = region[0] > region[2]? region[0] : region[2];
  ordered_region[1] = region[1] < region[3]? region[1] : region[3];
  ordered_region[3] = region[1] > region[3]? region[1] : region[3];

  this->InvokeEvent(vtkCommand::SelectionChangedEvent, ordered_region);
}

//----------------------------------------------------------------------------
void vtkPVRenderView::SelectPoints(int region[4])
{
  this->Select(vtkDataObject::FIELD_ASSOCIATION_POINTS, region);
}

//----------------------------------------------------------------------------
void vtkPVRenderView::SelectCells(int region[4])
{
  this->Select(vtkDataObject::FIELD_ASSOCIATION_CELLS, region);
}

//----------------------------------------------------------------------------
void vtkPVRenderView::Select(int fieldAssociation, int region[4])
{
471 472
  // NOTE: selection is only supported in builtin or client-server mode. Not
  // supported in tile-display or batch modes.
473

474
  if (this->MakingSelection)
475
    {
476 477
    vtkErrorMacro("Select was called while making another selection.");
    return;
478
    }
479

480
  if (!this->GetRemoteRenderingAvailable())
481
    {
482 483
    vtkErrorMacro("Cannot make selections since remote rendering is not available.");
    return;
484
    }
485

486 487 488 489 490 491 492 493
  this->MakingSelection = true;

  // Make sure that the representations are up-to-date. This is required since
  // due to delayed-swicth-back-from-lod, the most recent render maybe a LOD
  // render (or a nonremote render) in which case we need to update the
  // representation pipelines correctly.
  this->Render(/*interactive*/false, /*skip-rendering*/false);

494 495 496 497 498 499 500 501 502
  this->SetLastSelection(NULL);

  this->Selector->SetRenderer(this->GetRenderer());
  this->Selector->SetFieldAssociation(fieldAssociation);
  // for now, we always do the process pass. In future, we can be smart about
  // disabling process pass when not needed.
  this->Selector->SetProcessID(
    vtkMultiProcessController::GetGlobalController()?
    vtkMultiProcessController::GetGlobalController()->GetLocalProcessId() : 0);
503

504
  vtkSelection* sel = this->Selector->Select(region);
505 506 507 508 509 510

  // look at ::Render(..,..). We need to disable these once we are done with
  // rendering.
  this->SynchronizedWindows->SetEnabled(false);
  this->SynchronizedRenderers->SetEnabled(false);

511 512
  if (sel)
    {
513
    // A valid sel is only generated on the "driver" node. The driver node may not have
514 515 516 517 518 519 520 521
    // the actual data (except in built-in mode). So representations on this
    // process may not be able to handle ConvertSelection() if call it right here.
    // Hence we broadcast the selection to all data-server nodes.
    this->FinishSelection(sel);
    sel->Delete();
    }
  else
    {
522
    vtkErrorMacro("Failed to capture selection.");
523 524
    }

525
  this->MakingSelection = false;
526 527 528 529 530
}

//----------------------------------------------------------------------------
void vtkPVRenderView::FinishSelection(vtkSelection* sel)
{
531
  assert(sel != NULL);
532 533
  this->SynchronizedWindows->BroadcastToDataServer(sel);

534
  // now, sel has PROP_ID() set and not PROP() pointers. We setup the PROP()
535 536 537 538 539 540 541 542
  // pointers, since representations have know knowledge for that the PROP_ID()s
  // are.
  for (unsigned int cc=0; cc < sel->GetNumberOfNodes(); cc++)
    {
    vtkSelectionNode* node = sel->GetNode(cc);
    if (node->GetProperties()->Has(vtkSelectionNode::PROP_ID()))
      {
      int propid = node->GetProperties()->Get(vtkSelectionNode::PROP_ID());
543
      vtkProp* prop = this->Selector->GetPropFromID(propid);
544
      node->GetProperties()->Set(vtkSelectionNode::PROP(), prop);
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
      }
    }

  // Now all processes have the full selection. We can tell the representations
  // to convert the selections.

  vtkSelection* converted = vtkSelection::New();

  // Now, vtkPVRenderView is in no position to tell how many representations got
  // selected, and what nodes in the vtkSelection correspond to which
  // representations. So it simply passes the full vtkSelection to all
  // representations and asks them to "convert" it. A representation will return
  // the original selection if it was not selected at all or returns the
  // converted selection for the part that it can handle, ignoring the rest.
  for (int i = 0; i < this->GetNumberOfRepresentations(); ++i)
    {
    vtkDataRepresentation* repr = this->GetRepresentation(i);
    vtkSelection* convertedSelection = repr->ConvertSelection(this, sel);
    if (convertedSelection == NULL|| convertedSelection == sel)
      {
      continue;
      }
    for (unsigned int cc=0; cc < convertedSelection->GetNumberOfNodes(); cc++)
      {
      vtkSelectionNode* node = convertedSelection->GetNode(cc);
      // update the SOURCE() for the node to be the selected representation.
      node->GetProperties()->Set(vtkSelectionNode::SOURCE_ID(), i);
      converted->AddNode(convertedSelection->GetNode(cc));
      }
    convertedSelection->Delete();
    }

  this->SetLastSelection(converted);
  converted->FastDelete();
579

580 581 582 583 584
}

//----------------------------------------------------------------------------
void vtkPVRenderView::ResetCameraClippingRange()
{
585 586 587 588 589 590 591
  if (this->GeometryBounds.IsValid())
    {
    double bounds[6];
    this->GeometryBounds.GetBounds(bounds);
    this->GetRenderer()->ResetCameraClippingRange(bounds);
    this->GetNonCompositedRenderer()->ResetCameraClippingRange(bounds);
    }
592 593 594
}

//----------------------------------------------------------------------------
595
void vtkPVRenderView::SynchronizeGeometryBounds()
596
{
597 598 599
  double bounds[6];
  vtkMath::UninitializeBounds(bounds);
  if (this->GeometryBounds.IsValid())
600
    {
601
    this->GeometryBounds.GetBounds(bounds);
602
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
603

604 605 606 607
  // sync up bounds across all processes when doing distributed rendering.
  this->SynchronizedWindows->SynchronizeBounds(bounds);

  if (!vtkMath::AreBoundsInitialized(bounds))
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
608
    {
609
    this->GeometryBounds.SetBounds(-1, 1, -1, 1, -1, 1);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
610
    }
611
  else
612
    {
613
    this->GeometryBounds.SetBounds(bounds);
614
    }
615

616
  this->UpdateCenterAxes();
617 618 619
  this->ResetCameraClippingRange();
}

620 621 622
//----------------------------------------------------------------------------
bool vtkPVRenderView::GetLocalProcessDoesRendering(bool using_distributed_rendering)
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
623
  switch (vtkProcessModule::GetProcessType())
624
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
625
  case vtkProcessModule::PROCESS_DATA_SERVER:
626 627
    return false;

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
628
  case vtkProcessModule::PROCESS_CLIENT:
629 630 631 632 633 634 635
    return true;

  default:
    return using_distributed_rendering;
    }
}

636 637 638 639
//----------------------------------------------------------------------------
// Note this is called on all processes.
void vtkPVRenderView::ResetCamera()
{
640 641 642 643
  // Since ResetCamera() is accessible via a property on the view proxy, this
  // method gets called directly (and on on the vtkSMRenderViewProxy). Hence
  // we need to ensure things are updated explicitly and cannot rely on the View
  // proxy to take care of updating the view.
644 645
  this->Update();

646 647
  // Remember, vtkRenderer::ResetCamera() calls
  // vtkRenderer::ResetCameraClippingPlanes() with the given bounds.
648 649 650
  double bounds[6];
  this->GeometryBounds.GetBounds(bounds);
  this->RenderView->GetRenderer()->ResetCamera(bounds);
651 652 653 654 655 656 657 658 659 660 661 662 663 664

  this->InvokeEvent(vtkCommand::ResetCameraEvent);
}

//----------------------------------------------------------------------------
// Note this is called on all processes.
void vtkPVRenderView::ResetCamera(double bounds[6])
{
  // Remember, vtkRenderer::ResetCamera() calls
  // vtkRenderer::ResetCameraClippingPlanes() with the given bounds.
  this->RenderView->GetRenderer()->ResetCamera(bounds);
  this->InvokeEvent(vtkCommand::ResetCameraEvent);
}

665
//----------------------------------------------------------------------------
666
bool vtkPVRenderView::TestCollaborationCounter()
667
{
668 669 670 671 672 673
  vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
  vtkPVSession* activeSession = vtkPVSession::SafeDownCast(pm->GetActiveSession());
  if (!activeSession || !activeSession->IsMultiClients())
    {
    return true;
    }
674

675 676 677 678 679 680
  vtkMultiProcessController* p_controller =
    this->SynchronizedWindows->GetParallelController();
  vtkMultiProcessController* d_controller = 
    this->SynchronizedWindows->GetClientDataServerController();
  vtkMultiProcessController* r_controller =
    this->SynchronizedWindows->GetClientServerController();
681 682 683
  if (d_controller != NULL)
    {
    vtkErrorMacro("RenderServer-DataServer configuration is not supported in "
684 685
      "multi-clients mode. Please restart ParaView in the right mode. "
      "Aborting since this could cause deadlocks and other issues.");
686 687
    abort();
    }
688 689 690

  if (this->SynchronizedWindows->GetMode() == vtkPVSynchronizedRenderWindows::CLIENT)
    {
691 692
    r_controller->Send(&this->SynchronizationCounter, 1, 1, 41000);
    unsigned int server_sync_counter;
693
    r_controller->Receive(&server_sync_counter, 1, 1, 41001);
694
    return (server_sync_counter == this->SynchronizationCounter);
695 696 697
    }
  else
    {
698
    bool counterSynchronizedSuccessfully = false;
699
    if (r_controller)
700
      {
701 702
      unsigned int client_sync_counter;
      r_controller->Receive(&client_sync_counter, 1, 1, 41000);
703
      r_controller->Send(&this->SynchronizationCounter, 1, 1, 41001 );
704
      counterSynchronizedSuccessfully =
705
        (client_sync_counter == this->SynchronizationCounter);
706
      }
707 708

    if (p_controller)
709
      {
710
      p_controller->Broadcast(&this->RemoteRenderingThreshold, 1, 0);
711
      int temp = counterSynchronizedSuccessfully? 1 : 0;
712
      p_controller->Broadcast(&temp, 1, 0);
713
      counterSynchronizedSuccessfully = (temp == 1);
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 745 746 747 748 749
    return counterSynchronizedSuccessfully;
    }
}

//----------------------------------------------------------------------------
void vtkPVRenderView::SynchronizeForCollaboration()
{
 vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
  vtkPVSession* activeSession = vtkPVSession::SafeDownCast(pm->GetActiveSession());
  if (!activeSession || !activeSession->IsMultiClients())
    {
    return;
    }

  // Update decisions about lod-rendering and remote-rendering.
  
  vtkMultiProcessController* p_controller =
    this->SynchronizedWindows->GetParallelController();
  vtkMultiProcessController* r_controller =
    this->SynchronizedWindows->GetClientServerController();

  if (this->SynchronizedWindows->GetMode() == vtkPVSynchronizedRenderWindows::CLIENT)
    {
    vtkMultiProcessStream stream;
    stream << (this->UseLODForInteractiveRender? 1 : 0)
           << (this->UseDistributedRenderingForStillRender? 1 : 0)
           << (this->UseDistributedRenderingForInteractiveRender? 1 :0)
           << (this->UseOutlineForInteractiveRender? 1 : 0)
           << this->StillRenderProcesses
           << this->InteractiveRenderProcesses;
    r_controller->Send(stream, 1, 42000);
    }
  else
    {
    vtkMultiProcessStream stream;
750 751 752 753 754
    if (r_controller)
      {
      r_controller->Receive(stream, 1, 42000);
      }
    if (p_controller)
755
      {
756
      p_controller->Broadcast(stream, 0);
757
      }
758 759 760 761 762 763 764 765 766 767 768
    int arg1, arg2, arg3, arg4;
    stream >> arg1
           >> arg2
           >> arg3
           >> arg4
           >> this->StillRenderProcesses
           >> this->InteractiveRenderProcesses;
    this->UseLODForInteractiveRender = (arg1 == 1);
    this->UseDistributedRenderingForStillRender = (arg2 == 1);
    this->UseDistributedRenderingForInteractiveRender = (arg3 == 1);
    this->UseOutlineForInteractiveRender = (arg4 == 1);
769 770 771
    }
}

772 773 774 775
//----------------------------------------------------------------------------
void vtkPVRenderView::Update()
{
  vtkTimerLog::MarkStartEvent("RenderView::Update");
776

777 778 779 780
  // reset the bounds, so that representations can provide us with bounds
  // information during update.
  this->GeometryBounds.Reset();

781 782
  this->Superclass::Update();

783 784 785 786 787 788
  // After every update we can expect the representation geometries to change.
  // Thus we need to determine whether we are doing to remote-rendering or not,
  // use-lod or not, etc. All these decisions are made right here to avoid
  // making them during each render-call.

  // Check if any representation told us that it needed ordered compositing.
789 790 791 792 793 794 795 796 797 798 799 800 801 802
  this->NeedsOrderedCompositing = false;
  int num_reprs = this->ReplyInformationVector->GetNumberOfInformationObjects();
  for (int cc=0; cc < num_reprs; cc++)
    {
    vtkInformation* info =
      this->ReplyInformationVector->GetInformationObject(cc);
    if (info->Has(NEED_ORDERED_COMPOSITING()) &&
      info->Get(NEED_ORDERED_COMPOSITING()) != 0)
      {
      this->NeedsOrderedCompositing= true;
      break;
      }
    }

803
  // Gather information about geometry sizes from all representations.
804
  double local_size = this->GetDeliveryManager()->GetVisibleDataSize(false) / 1024.0;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
805
  this->SynchronizedWindows->SynchronizeSize(local_size);
806
  // cout << "Full Geometry size: " << local_size << endl;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831

  // Update decisions about lod-rendering and remote-rendering.
  this->UseLODForInteractiveRender = this->ShouldUseLODRendering(local_size);
  this->UseDistributedRenderingForStillRender = this->ShouldUseDistributedRendering(local_size);
  if (!this->UseLODForInteractiveRender)
    {
    this->UseDistributedRenderingForInteractiveRender =
      this->UseDistributedRenderingForStillRender;
    this->UseOutlineForInteractiveRender = (this->ClientOutlineThreshold <= local_size);
    }

  this->StillRenderProcesses = this->InteractiveRenderProcesses =
    vtkPVSession::CLIENT;
  bool in_tile_display_mode = this->InTileDisplayMode();
  bool in_cave_mode = this->SynchronizedWindows->GetIsInCave();
  if (in_tile_display_mode || in_cave_mode ||
    this->UseDistributedRenderingForStillRender)
    {
    this->StillRenderProcesses = vtkPVSession::CLIENT_AND_SERVERS;
    }
  if (in_tile_display_mode || in_cave_mode ||
    this->UseDistributedRenderingForInteractiveRender)
    {
    this->InteractiveRenderProcesses = vtkPVSession::CLIENT_AND_SERVERS;
    }
832

833 834 835
  // Synchronize data bounds.
  this->SynchronizeGeometryBounds();

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
836
  vtkTimerLog::MarkEndEvent("RenderView::Update");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
837 838

  this->UpdateTimeStamp.Modified();
839 840
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
841 842 843 844 845 846 847 848 849 850
//----------------------------------------------------------------------------
void vtkPVRenderView::UpdateLOD()
{
  vtkTimerLog::MarkStartEvent("RenderView::UpdateLOD");

  // Update LOD geometry.
  this->CallProcessViewRequest(
    vtkPVView::REQUEST_UPDATE_LOD(),
    this->RequestInformation, this->ReplyInformationVector);

851
  double local_size = this->GetDeliveryManager()->GetVisibleDataSize(true) / 1024.0;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
852
  this->SynchronizedWindows->SynchronizeSize(local_size);
853
  // cout << "LOD Geometry size: " << local_size << endl;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870

  this->UseOutlineForInteractiveRender = (this->ClientOutlineThreshold <= local_size);
  this->UseDistributedRenderingForInteractiveRender =
    this->ShouldUseDistributedRendering(local_size);

  this->InteractiveRenderProcesses = vtkPVSession::CLIENT;
  bool in_tile_display_mode = this->InTileDisplayMode();
  bool in_cave_mode = this->SynchronizedWindows->GetIsInCave();
  if (in_tile_display_mode || in_cave_mode ||
    this->UseDistributedRenderingForInteractiveRender)
    {
    this->InteractiveRenderProcesses = vtkPVSession::CLIENT_AND_SERVERS;
    }

  vtkTimerLog::MarkEndEvent("RenderView::UpdateLOD");
}

871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
//----------------------------------------------------------------------------
void vtkPVRenderView::StillRender()
{
  vtkTimerLog::MarkStartEvent("Still Render");
  this->GetRenderWindow()->SetDesiredUpdateRate(0.002);
  this->Render(false, false);
  vtkTimerLog::MarkEndEvent("Still Render");
}

//----------------------------------------------------------------------------
void vtkPVRenderView::InteractiveRender()
{
  vtkTimerLog::MarkStartEvent("Interactive Render");
  this->GetRenderWindow()->SetDesiredUpdateRate(5.0);
  this->Render(true, false);
  vtkTimerLog::MarkEndEvent("Interactive Render");
}
888 889

//----------------------------------------------------------------------------
890
unsigned int vtkPVRenderView::GetNextPieceToDeliver(double planes[24])
891
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
892 893
  if (!vtkPVView::GetEnableStreaming())
    {
894
    return 0;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
895 896
    }

897 898 899 900 901 902 903 904 905
  bool force_modified = false;
  static double prev_planes[24];
  for (int cc=0; cc < 24 && !force_modified;cc++)
    {
    force_modified = prev_planes[cc] != planes[cc];
    }
  memcpy(prev_planes, planes, 24*sizeof(double));


Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
906
  if (this->UpdateTimeStamp > this->PriorityQueueBuildTimeStamp ||
907 908
    this->GetActiveCamera()->GetMTime() > this->PriorityQueueBuildTimeStamp ||
    force_modified)
909
    {
910 911 912 913
    // either the data or the camera has changed. Regenerate the priority queue.
    // Priority queue contains a list of (representation-id, block-id) tuples
    // indicating the blocks to request.
    vtkTimerLog::MarkStartEvent("Build View Priority Queue");
914
    this->GetDeliveryManager()->BuildPriorityQueue(planes);
915
    vtkTimerLog::MarkEndEvent("Build View Priority Queue");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
916
    this->PriorityQueueBuildTimeStamp.Modified();
917
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
918

919
  return this->GetDeliveryManager()->GetRepresentationIdFromQueue();
920 921 922 923 924
}
 
//----------------------------------------------------------------------------
void vtkPVRenderView::StreamingUpdate()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
925 926 927 928 929
  vtkTimerLog::MarkStartEvent("Streaming Update");
  // Update the representations.
  this->CallProcessViewRequest(vtkPVView::REQUEST_UPDATE(),
    this->RequestInformation, this->ReplyInformationVector);
  vtkTimerLog::MarkEndEvent("Streaming Update");
930
}
931

932 933 934
//----------------------------------------------------------------------------
void vtkPVRenderView::Render(bool interactive, bool skip_rendering)
{
935 936 937 938 939 940 941 942 943 944 945 946 947
  if (this->SynchronizedWindows->GetMode() !=
    vtkPVSynchronizedRenderWindows::CLIENT ||
    (!interactive && this->UseDistributedRenderingForStillRender) ||
    (interactive && this->UseDistributedRenderingForInteractiveRender))
    {
    // in multi-client modes, Render() will be called on client always. Now the
    // client need to coordinate with server only when we are remote rendering.
    // if Render() is called on server side, then we are indeed remote
    // rendering, irrespective of what the local flags tell us and we need to
    // coordinate with the client to update the local flags correctly.
    this->SynchronizeForCollaboration();
    }

948
  bool in_tile_display_mode = this->InTileDisplayMode();
949
  bool in_cave_mode = this->SynchronizedWindows->GetIsInCave();
950 951 952 953 954 955 956 957
  if (in_cave_mode && !this->RemoteRenderingAvailable)
    {
    static bool warned_once = false;
    if (!warned_once)
      {
      vtkErrorMacro(
        "In Cave mode and Display cannot be opened on server-side! "
        "Ensure the environment is set correctly in the pvx file.");
958
      in_cave_mode = false;
959 960
      }
    }
961

962 963
  // Use loss-less image compression for client-server for full-res renders.
  this->SynchronizedRenderers->SetLossLessCompression(!interactive);
964

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
965 966 967 968 969
  bool use_lod_rendering = interactive? this->GetUseLODForInteractiveRender() : false;
  if (use_lod_rendering)
    {
    this->RequestInformation->Set(USE_LOD(), 1);
    }
970

971
  // cout << "Using remote rendering: " << use_distributed_rendering << endl;
972

973
  // Decide if we are doing remote rendering or local rendering.
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
974 975 976
  bool use_distributed_rendering = interactive?
    this->GetUseDistributedRenderingForInteractiveRender():
    this->GetUseDistributedRenderingForStillRender();
977

978 979 980
  // Render each representation with available geometry.
  // This is the pass where representations get an opportunity to get the
  // currently "available" represented data and try to render it.
981
  this->CallProcessViewRequest(vtkPVView::REQUEST_RENDER(),
982 983 984 985 986 987 988 989
    this->RequestInformation, this->ReplyInformationVector);

  // set the image reduction factor.
  this->SynchronizedRenderers->SetImageReductionFactor(
    (interactive?
     this->InteractiveRenderImageReductionFactor :
     this->StillRenderImageReductionFactor));

990 991
  this->UsedLODForLastRender = use_lod_rendering;

992 993
  if (skip_rendering)
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
994
    // essential to restore state.
995 996 997
    return;
    }

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
  // When in tile-display mode, we are always doing shared rendering. However
  // when use_distributed_rendering we tell IceT that geometry is duplicated on
  // all processes.
  this->SynchronizedWindows->SetEnabled(
    use_distributed_rendering || in_tile_display_mode || in_cave_mode);
  this->SynchronizedRenderers->SetEnabled(
    use_distributed_rendering || in_tile_display_mode || in_cave_mode);
  this->SynchronizedRenderers->SetDataReplicatedOnAllProcesses(
    in_cave_mode ||
    (!use_distributed_rendering && in_tile_display_mode));

1009
  this->SynchronizedRenderers->SetKdTree(
1010
    this->Internals->DeliveryManager->GetKdTree());
1011

1012 1013 1014 1015 1016 1017 1018 1019 1020
  // When in batch mode, we are using the same render window for all views. That
  // makes it impossible for vtkPVSynchronizedRenderWindows to identify which
  // view is being rendered. We explicitly mark the view being rendered using
  // this HACK.
  this->SynchronizedWindows->BeginRender(this->GetIdentifier());

  // Call Render() on local render window only if
  // 1: Local process is the driver OR
  // 2: RenderEventPropagation is Off and we are doing distributed rendering.
1021
  // 3: In tile-display mode or cave-mode.
1022 1023
  // Note, ParaView no longer has RenderEventPropagation ON. It's set to off
  // always.
1024 1025 1026 1027 1028
  if (
    (this->SynchronizedWindows->GetLocalProcessIsDriver() ||
     (!this->SynchronizedWindows->GetRenderEventPropagation() && use_distributed_rendering) ||
     in_tile_display_mode || in_cave_mode) &&
    vtkProcessModule::GetProcessType() != vtkProcessModule::PROCESS_DATA_SERVER)
1029 1030 1031
    {
    this->GetRenderWindow()->Render();
    }
1032 1033 1034 1035 1036 1037 1038 1039 1040

  if (!this->MakingSelection)
    {
    // If we are making selection, then it's a multi-step render process and we
    // need to leave the SynchronizedWindows/SynchronizedRenderers enabled for
    // that entire process.
    this->SynchronizedWindows->SetEnabled(false);
    this->SynchronizedRenderers->SetEnabled(false);
    }
1041 1042
}

1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
//----------------------------------------------------------------------------
void vtkPVRenderView::Deliver(int use_lod,
    unsigned int size, unsigned int *representation_ids)
{
  // if in multi-clients mode, ensure that processes are in the same "state"
  // before doing the data delivery or we may end up with dead-locks due to
  // mismatched representations.
  if (!this->TestCollaborationCounter())
    {
    return;
    }

  // in multi-clients mode, for every Deliver() and Render() call, we obtain the
  // remote-rendering related ivars from the client.
  this->SynchronizeForCollaboration();

  this->GetDeliveryManager()->Deliver(use_lod, size, representation_ids);
}

1062
//----------------------------------------------------------------------------
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1063
int vtkPVRenderView::GetDataDistributionMode(bool use_remote_rendering)
1064 1065
{
  bool in_tile_display_mode = this->InTileDisplayMode();
1066 1067 1068
  bool in_cave_mode = this->SynchronizedWindows->GetIsInCave();
  if (in_cave_mode)
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1069
    return vtkMPIMoveData::CLONE;
1070
    }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1071 1072

  if (use_remote_rendering)
1073
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1074
    return in_tile_display_mode?
1075
      vtkMPIMoveData::COLLECT_AND_PASS_THROUGH:
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1076
      vtkMPIMoveData::PASS_THROUGH;
1077
    }
1078

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1079
  return in_tile_display_mode? vtkMPIMoveData::CLONE: vtkMPIMoveData::COLLECT;
1080 1081 1082
}

//----------------------------------------------------------------------------
1083 1084
void vtkPVRenderView::SetPiece(vtkInformation* info,
  vtkPVDataRepresentation* repr, vtkDataObject* data)
1085
{
1086 1087
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1088
    {
1089
    vtkGenericWarningMacro("Missing VIEW().");
1090 1091
    return;
    }
1092 1093

  view->GetDeliveryManager()->SetPiece(repr, data, false);
1094
}
1095

1096 1097 1098 1099
//----------------------------------------------------------------------------
vtkAlgorithmOutput* vtkPVRenderView::GetPieceProducer(vtkInformation* info,
    vtkPVDataRepresentation* repr)
{
1100 1101
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1102
    {
1103
    vtkGenericWarningMacro("Missing VIEW().");
1104 1105
    return NULL;
    }
1106 1107

  return view->GetDeliveryManager()->GetProducer(repr, false);
1108
}
1109

1110 1111 1112 1113
//----------------------------------------------------------------------------
void vtkPVRenderView::SetPieceLOD(vtkInformation* info,
  vtkPVDataRepresentation* repr, vtkDataObject* data)
{
1114 1115
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1116
    {
1117
    vtkGenericWarningMacro("Missing VIEW().");
1118
    return;
1119 1120 1121
    }

  view->GetDeliveryManager()->SetPiece(repr, data, true);
1122 1123 1124 1125 1126 1127
}

//----------------------------------------------------------------------------
vtkAlgorithmOutput* vtkPVRenderView::GetPieceProducerLOD(vtkInformation* info,
    vtkPVDataRepresentation* repr)
{
1128 1129
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1130
    {
1131
    vtkGenericWarningMacro("Missing VIEW().");
1132 1133 1134
    return NULL;
    }

1135
  return view->GetDeliveryManager()->GetProducer(repr, true);
1136 1137
}

1138 1139 1140 1141
//----------------------------------------------------------------------------
void vtkPVRenderView::MarkAsRedistributable(
  vtkInformation* info, vtkPVDataRepresentation* repr)
{
1142 1143
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1144
    {
1145
    vtkGenericWarningMacro("Missing VIEW().");
1146 1147
    return;
    }
1148 1149

  view->GetDeliveryManager()->MarkAsRedistributable(repr);
1150 1151
}

1152 1153 1154 1155
//----------------------------------------------------------------------------
void vtkPVRenderView::SetStreamable(
  vtkInformation* info, vtkPVDataRepresentation* repr, bool val)
{
1156 1157
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1158
    {
1159
    vtkGenericWarningMacro("Missing VIEW().");
1160 1161
    return;
    }
1162 1163

  view->GetDeliveryManager()->SetStreamable(repr, val);
1164 1165 1166
}


1167
//----------------------------------------------------------------------------
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1168 1169
void vtkPVRenderView::SetDeliverToAllProcesses(vtkInformation* info,
  vtkPVDataRepresentation* repr, bool clone)
1170
{
1171 1172
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
1173
    {
1174
    vtkGenericWarningMacro("Missing VIEW().");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1175
    return;
1176
    }
1177 1178

  view->GetDeliveryManager()->SetDeliverToAllProcesses(repr, clone, false);
1179 1180 1181
}

//----------------------------------------------------------------------------
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1182 1183
void vtkPVRenderView::SetDeliverLODToAllProcesses(vtkInformation* info,
  vtkPVDataRepresentation* repr, bool clone)
1184
{
1185 1186
  vtkPVRenderView* view = vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!view)
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1187
    {
1188
    vtkGenericWarningMacro("Missing VIEW().");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1189 1190
    return;
    }
1191 1192

  view->GetDeliveryManager()->SetDeliverToAllProcesses(repr, clone, true);
1193 1194
}

1195 1196 1197 1198
//----------------------------------------------------------------------------
void vtkPVRenderView::SetGeometryBounds(vtkInformation* info,
  double bounds[6], vtkMatrix4x4* matrix /*=NULL*/)
{
1199 1200
  vtkPVRenderView* self= vtkPVRenderView::SafeDownCast(info->Get(VIEW()));
  if (!self)
1201
    {
1202
    vtkGenericWarningMacro("Missing VIEW().");
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
    return;
    }

  if (self)
    {
    if (matrix && vtkMath::AreBoundsInitialized(bounds))
      {
      double min_point[4] = {bounds[0], bounds[2], bounds[4], 1};
      double max_point[4] = {bounds[1], bounds[3], bounds[5], 1};
      matrix->MultiplyPoint(min_point, min_point);
      matrix->MultiplyPoint(max_point, max_point);
      double transformed_bounds[6];
      transformed_bounds[0] = min_point[0] / min_point[3];
      transformed_bounds[2] = min_point[1] / min_point[3];
      transformed_bounds[4] = min_point[2] / min_point[3];
      transformed_bounds[1] = max_point[0] / max_point[3];
      transformed_bounds[3] = max_point[1] / max_point[3];
      transformed_bounds[5] = max_point[2] / max_point[3];
      self->GeometryBounds.AddBounds(transformed_bounds);
      }
    else
      {
      self->GeometryBounds.AddBounds(bounds);
      }
    }
}

1230
//----------------------------------------------------------------------------
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
1231
bool vtkPVRenderView::ShouldUseDistributedRendering(double geometry_size)
1232
{
1233 1234 1235 1236 1237
  if (this->GetRemoteRenderingAvailable() == false)
    {
    return false;
    }

1238
  if (this->MakingSelection)