vtkPVDataDeliveryManager.cxx 21.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   ParaView
  Module:    $RCSfile$

  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.

=========================================================================*/
15
#include "vtkPVDataDeliveryManager.h"
16 17

#include "vtkAlgorithmOutput.h"
18
#include "vtkBSPCutsGenerator.h"
19
#include "vtkDataObject.h"
20
#include "vtkMPIMoveData.h"
21 22 23 24 25
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOrderedCompositeDistributor.h"
#include "vtkPKdTree.h"
26
#include "vtkPVDataRepresentation.h"
27
#include "vtkPVRenderView.h"
28
#include "vtkPVStreamingMacros.h"
29 30
#include "vtkPVTrivialProducer.h"
#include "vtkSmartPointer.h"
31
#include "vtkStreamingDemandDrivenPipeline.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
32
#include "vtkTimerLog.h"
33
#include "vtkWeakPointer.h"
34 35

#include <assert.h>
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include <map>
#include <queue>
#include <utility>

//*****************************************************************************
class vtkPVDataDeliveryManager::vtkInternals
{
public:

  class vtkPriorityQueueItem
    {
  public:
    unsigned int RepresentationId;
    unsigned int BlockId;
    unsigned int Level;
    unsigned int Index;
    double Priority;

    vtkPriorityQueueItem() :
      RepresentationId(0), BlockId(0),
      Level(0), Index(0), Priority(0)
    {
    }

    bool operator < (const vtkPriorityQueueItem& other) const
      {
      return this->Priority < other.Priority;
      }
    };

  typedef std::priority_queue<vtkPriorityQueueItem> PriorityQueueType;
  PriorityQueueType PriorityQueue;

  class vtkItem
    {
    vtkSmartPointer<vtkPVTrivialProducer> Producer;
72 73

    // Data object produced by the representation.
74
    vtkWeakPointer<vtkDataObject> DataObject;
75 76 77 78 79 80 81 82

    // Data object available after delivery to the "rendering" node.
    vtkSmartPointer<vtkDataObject> DeliveredDataObject;

    // Data object after re-distributing when using ordered compositing, for
    // example.
    vtkSmartPointer<vtkDataObject> RedistributedDataObject;

83 84 85
    // Data object for a streamed piece.
    vtkSmartPointer<vtkDataObject> StreamedPiece;

86 87 88
    unsigned long TimeStamp;
    unsigned long ActualMemorySize;
  public:
89 90 91
    vtkWeakPointer<vtkAlgorithmOutput> ImageDataProducer;
      // <-- HACK for image data volume rendering.

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    vtkWeakPointer<vtkPVDataRepresentation> Representation;
    bool AlwaysClone;
    bool Redistributable;
    bool Streamable;

    vtkItem() :
      Producer(vtkSmartPointer<vtkPVTrivialProducer>::New()),
      TimeStamp(0),
      ActualMemorySize(0),
      AlwaysClone(false),
      Redistributable(false),
      Streamable(false)
    { }

    void SetDataObject(vtkDataObject* data)
107
      {
108 109
      this->DataObject = data;
      this->ActualMemorySize = data? data->GetActualMemorySize() : 0;
110 111 112

      vtkTimeStamp ts; ts.Modified();
      this->TimeStamp = ts;
113 114
      }

115 116
    void SetDeliveredDataObject(vtkDataObject* data)
      {
117 118 119 120 121 122
      this->DeliveredDataObject = data;
      }

    void SetRedistributedDataObject(vtkDataObject* data)
      {
      this->RedistributedDataObject = data;
123 124 125 126
      }

    vtkDataObject* GetDeliveredDataObject()
      {
127 128 129 130 131 132 133 134 135
      return this->DeliveredDataObject.GetPointer();
      }

    vtkDataObject* GetRedistributedDataObject()
      {
      return this->RedistributedDataObject.GetPointer();
      }

    vtkPVTrivialProducer* GetProducer(bool use_redistributed_data)
136
      {
137 138 139 140 141 142 143 144 145
      if (use_redistributed_data && this->Redistributable)
        {
        this->Producer->SetOutput(this->RedistributedDataObject);
        }
      else
        {
        this->Producer->SetOutput(this->DeliveredDataObject);
        }
      return this->Producer.GetPointer();
146 147
      }

148 149 150 151
    vtkDataObject* GetDataObject() const
      { return this->DataObject.GetPointer(); }
    unsigned long GetTimeStamp() const
      { return this->TimeStamp; }
152

153 154 155 156 157 158 159 160
    unsigned long GetVisibleDataSize()
      {
      if (this->Representation && this->Representation->GetVisibility())
        {
        return this->ActualMemorySize;
        }
      return 0;
      }
161 162 163 164 165 166 167 168 169

    void SetNextStreamedPiece(vtkDataObject* data)
      {
      this->StreamedPiece = data;
      }
    vtkDataObject* GetStreamedPiece()
      {
      return this->StreamedPiece;
      }
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    };

  typedef std::map<unsigned int, std::pair<vtkItem, vtkItem> > ItemsMapType;

  vtkItem* GetItem(unsigned int index, bool use_second)
    {
    if (this->ItemsMap.find(index) != this->ItemsMap.end())
      {
      return use_second? &(this->ItemsMap[index].second) :
        &(this->ItemsMap[index].first);
      }
    return NULL;
    }

  vtkItem* GetItem(vtkPVDataRepresentation* repr, bool use_second)
    {
186
    return this->GetItem(repr->GetUniqueIdentifier(), use_second);
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
    }

  unsigned long GetVisibleDataSize(bool use_second_if_available)
    {
    unsigned long size = 0;
    ItemsMapType::iterator iter;
    for (iter = this->ItemsMap.begin(); iter != this->ItemsMap.end(); ++iter)
      {
      if (use_second_if_available && iter->second.second.GetDataObject())
        {
        size += iter->second.second.GetVisibleDataSize();
        }
      else
        {
        size += iter->second.first.GetVisibleDataSize();
        }
      }
    return size;
    }
206

207 208
  ItemsMapType ItemsMap;
};
209

210 211 212
//*****************************************************************************

vtkStandardNewMacro(vtkPVDataDeliveryManager);
213
//----------------------------------------------------------------------------
214
vtkPVDataDeliveryManager::vtkPVDataDeliveryManager()
215 216 217 218 219
  : Internals(new vtkInternals())
{
}

//----------------------------------------------------------------------------
220
vtkPVDataDeliveryManager::~vtkPVDataDeliveryManager()
221 222 223 224 225
{
  delete this->Internals;
  this->Internals = 0;
}

226
//----------------------------------------------------------------------------
227
void vtkPVDataDeliveryManager::SetRenderView(vtkPVRenderView* view)
228
{
229
  this->RenderView = view;
230 231
}

232
//----------------------------------------------------------------------------
233
vtkPVRenderView* vtkPVDataDeliveryManager::GetRenderView()
234
{
235
  return this->RenderView;
236 237
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
238
//----------------------------------------------------------------------------
239
unsigned long vtkPVDataDeliveryManager::GetVisibleDataSize(bool low_res)
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
240 241 242
{
  return this->Internals->GetVisibleDataSize(low_res);
}
243 244

//----------------------------------------------------------------------------
245
void vtkPVDataDeliveryManager::RegisterRepresentation(vtkPVDataRepresentation* repr)
246
{
247 248
  assert( "A representation must have a valid UniqueIdentifier"
          && repr->GetUniqueIdentifier());
249 250 251

  vtkInternals::vtkItem item;
  item.Representation = repr;
252
  this->Internals->ItemsMap[repr->GetUniqueIdentifier()].first = item;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
253 254 255

  vtkInternals::vtkItem item2;
  item2.Representation = repr;
256
  this->Internals->ItemsMap[repr->GetUniqueIdentifier()].second= item2;
257 258 259
}

//----------------------------------------------------------------------------
260
void vtkPVDataDeliveryManager::UnRegisterRepresentation(
261 262
  vtkPVDataRepresentation* repr)
{
263
  this->Internals->ItemsMap.erase(repr->GetUniqueIdentifier());
264 265 266 267 268 269 270 271 272 273
}

//----------------------------------------------------------------------------
vtkPVDataRepresentation* vtkPVDataDeliveryManager::GetRepresentation(
  unsigned int index)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(index, false);
  return item? item->Representation : NULL;
}

274
//----------------------------------------------------------------------------
275
void vtkPVDataDeliveryManager::SetDeliverToAllProcesses(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
276
  vtkPVDataRepresentation* repr, bool mode, bool low_res)
277
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
278
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
279 280
  if (item)
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
281
    item->AlwaysClone = mode;
282 283 284 285 286 287 288
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}

289
//----------------------------------------------------------------------------
290
void vtkPVDataDeliveryManager::MarkAsRedistributable(
291 292 293 294 295 296 297 298 299 300 301 302 303 304
  vtkPVDataRepresentation* repr)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, false);
  vtkInternals::vtkItem* low_item = this->Internals->GetItem(repr, true);
  if (item)
    {
    item->Redistributable = true;
    low_item->Redistributable = true;
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
305

306
//----------------------------------------------------------------------------
307
void vtkPVDataDeliveryManager::SetStreamable(
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
  vtkPVDataRepresentation* repr, bool val)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, false);
  vtkInternals::vtkItem* low_item = this->Internals->GetItem(repr, true);
  if (item)
    {
    item->Streamable = val;
    low_item->Streamable = val;
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}

323
//----------------------------------------------------------------------------
324
void vtkPVDataDeliveryManager::SetPiece(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
325
  vtkPVDataRepresentation* repr, vtkDataObject* data, bool low_res)
326
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
327
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
328 329
  if (item)
    {
330
    unsigned long data_time = 0;
331 332 333 334
    if (data && (data->GetMTime() > data_time))
      {
      data_time = data->GetMTime();
      }
335 336
    if (data_time > item->GetTimeStamp() ||
      item->GetDataObject() != data)
337 338 339
      {
      item->SetDataObject(data);
      }
340 341
    }
  else
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
342 343 344 345 346 347
    {
    vtkErrorMacro("Invalid argument.");
    }
}

//----------------------------------------------------------------------------
348
vtkAlgorithmOutput* vtkPVDataDeliveryManager::GetProducer(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
349 350 351 352
  vtkPVDataRepresentation* repr, bool low_res)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
  if (!item)
353 354
    {
    vtkErrorMacro("Invalid arguments.");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
355 356 357
    return NULL;
    }

358 359
  return item->GetProducer(
    this->RenderView->GetUseOrderedCompositing())->GetOutputPort(0);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
360 361 362
}

//----------------------------------------------------------------------------
363
void vtkPVDataDeliveryManager::SetPiece(unsigned int id, vtkDataObject* data, bool
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
364 365 366 367 368 369 370 371 372 373
  low_res)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(id, low_res);
  if (item)
    {
    item->SetDataObject(data);
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
374 375 376
    }
}

377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::SetImageDataProducer(
  vtkPVDataRepresentation* repr, vtkAlgorithmOutput *producer)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, false);
  if (item)
    {
    item->ImageDataProducer = producer;
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}

392
//----------------------------------------------------------------------------
393
vtkAlgorithmOutput* vtkPVDataDeliveryManager::GetProducer(
394
  unsigned int id, bool low_res)
395
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
396
  vtkInternals::vtkItem* item = this->Internals->GetItem(id, low_res);
397 398 399 400 401 402
  if (!item)
    {
    vtkErrorMacro("Invalid arguments.");
    return NULL;
    }

403 404
  return item->GetProducer(
    this->RenderView->GetUseOrderedCompositing())->GetOutputPort(0);
405 406
}

407
//----------------------------------------------------------------------------
408
bool vtkPVDataDeliveryManager::NeedsDelivery(
409
  unsigned long timestamp,
410
  std::vector<unsigned int> &keys_to_deliver, bool use_low)
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
{
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
    {
    vtkInternals::vtkItem& item = use_low? iter->second.second : iter->second.first;
    if (item.Representation &&
      item.Representation->GetVisibility() &&
      item.GetTimeStamp() > timestamp)
      {
      keys_to_deliver.push_back(iter->first);
      }
    }
  return keys_to_deliver.size() > 0;
}

//----------------------------------------------------------------------------
428
void vtkPVDataDeliveryManager::Deliver(int use_lod, unsigned int size, unsigned int *values)
429 430

{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
  // This method gets called on all processes with the list of representations
  // to "deliver". We check with the view what mode we're operating in and
  // decide where the data needs to be delivered.
  //
  // Representations can provide overrides, e.g. though the view says data is
  // merely "pass-through", some representation says we need to clone the data
  // everywhere. That makes it critical that this method is called on all
  // processes at the same time to avoid deadlocks and other complications.
  //
  // This method will be implemented in "view-specific" subclasses since how the
  // data is delivered is very view specific.

  vtkTimerLog::MarkStartEvent(use_lod?
    "LowRes Data Migration" : "FullRes Data Migration");

  bool using_remote_rendering =
447 448 449
    use_lod? this->RenderView->GetUseDistributedRenderingForInteractiveRender() :
    this->RenderView->GetUseDistributedRenderingForStillRender();
  int mode = this->RenderView->GetDataDistributionMode(using_remote_rendering);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
450

451 452 453 454 455 456
  for (unsigned int cc=0; cc < size; cc++)
    {
    vtkInternals::vtkItem* item = this->Internals->GetItem(values[cc], use_lod !=0);

    vtkDataObject* data = item->GetDataObject();

457
    if (data->IsA("vtkUniformGridAMR"))
458
      {
459 460
      // we are dealing with AMR datasets.
      // We assume for now we're not running in render-server mode. We can
461
      // ensure that at some point in future.
462 463 464
      // So we are either in pass-through or collect mode.

      // FIXME: check that the mode flags are "suitable" for AMR.
465
      }
466

467 468 469 470 471
    vtkNew<vtkMPIMoveData> dataMover;
    dataMover->InitializeForCommunicationForParaView();
    dataMover->SetOutputDataType(data->GetDataObjectType());
    dataMover->SetMoveMode(mode);
    if (item->AlwaysClone)
472
      {
473
      dataMover->SetMoveModeToClone();
474
      }
475 476
    dataMover->SetInputData(data);

477 478 479 480 481 482
    if (dataMover->GetOutputGeneratedOnProcess())
      {
      // release old memory (not necessarily, but try).
      item->SetDeliveredDataObject(NULL);
      }
    dataMover->Update();
483
    if (item->GetDeliveredDataObject() == NULL)
484 485 486
      {
      item->SetDeliveredDataObject(dataMover->GetOutputDataObject(0));
      }
487
    }
488

489 490 491
  vtkTimerLog::MarkEndEvent(use_lod?
    "LowRes Data Migration" : "FullRes Data Migration");
}
492

493 494 495 496 497
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::RedistributeDataForOrderedCompositing(
  bool use_lod)
{
  if (this->RenderView->GetUpdateTimeStamp() > this->RedistributionTimeStamp)
498
    {
499 500 501 502
    vtkTimerLog::MarkStartEvent("Regenerate Kd-Tree");
    // need to re-generate the kd-tree.
    this->RedistributionTimeStamp.Modified();

503 504 505 506 507 508 509
    vtkNew<vtkBSPCutsGenerator> cutsGenerator;
    vtkInternals::ItemsMapType::iterator iter;
    for (iter = this->Internals->ItemsMap.begin();
      iter != this->Internals->ItemsMap.end(); ++iter)
      {
      vtkInternals::vtkItem& item =  iter->second.first;
      if (item.Representation &&
510
        item.Representation->GetVisibility())
511
        {
512 513 514 515 516 517 518 519
        if (item.Redistributable)
          {
          cutsGenerator->AddInputData(item.GetDeliveredDataObject());
          }
        else if (item.ImageDataProducer)
          {
          cutsGenerator->AddInputConnection(item.ImageDataProducer);
          }
520 521 522 523 524 525 526 527 528 529 530 531
        }
      }

    vtkMultiProcessController* controller =
      vtkMultiProcessController::GetGlobalController();
    vtkStreamingDemandDrivenPipeline *sddp = vtkStreamingDemandDrivenPipeline::
      SafeDownCast(cutsGenerator->GetExecutive());
    sddp->SetUpdateExtent
      (0,controller->GetLocalProcessId(),controller->GetNumberOfProcesses(),0);
    sddp->Update(0);

    this->KdTree = cutsGenerator->GetPKdTree();
532
    vtkTimerLog::MarkEndEvent("Regenerate Kd-Tree");
533
    }
534 535

  if (this->KdTree == NULL)
536
    {
537
    return;
538 539
    }

540 541 542 543
  vtkTimerLog::MarkStartEvent("Redistributing Data for Ordered Compositing");
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
544
    {
545 546 547 548 549 550 551 552
    vtkInternals::vtkItem& item = use_lod? iter->second.second : iter->second.first;

    if (!item.Redistributable ||
      item.Representation == NULL ||
      item.Representation->GetVisibility() == false ||

      // delivered object can be null in case we're updating lod and the
      // representation doeesn't have any LOD data.
553
      item.GetDeliveredDataObject() == NULL)
554
      {
555 556
      continue;
      }
557

558 559 560 561 562 563 564 565 566 567 568 569
    if (item.GetRedistributedDataObject() &&

      // input-data didn't change
      (item.GetDeliveredDataObject()->GetMTime() <
       item.GetRedistributedDataObject()->GetMTime()) &&

      // kd-tree didn't change
      (item.GetRedistributedDataObject()->GetMTime() >
       this->KdTree->GetMTime()))
      {
      // skip redistribution.
      continue;
570 571
      }

572 573
    // release old memory (not necessarily, but try).
    item.SetRedistributedDataObject(NULL);
574

575 576 577 578 579 580 581 582 583
    vtkNew<vtkOrderedCompositeDistributor> redistributor;
    redistributor->SetController(vtkMultiProcessController::GetGlobalController());
    redistributor->SetInputData(item.GetDeliveredDataObject());
    redistributor->SetPKdTree(this->KdTree);
    redistributor->SetPassThrough(0);
    redistributor->Update();
    item.SetRedistributedDataObject(redistributor->GetOutputDataObject(0));
    }
  vtkTimerLog::MarkEndEvent("Redistributing Data for Ordered Compositing");
584 585
}

586
//----------------------------------------------------------------------------
587
vtkPKdTree* vtkPVDataDeliveryManager::GetKdTree()
588 589 590
{
  return this->KdTree;
}
591 592

//----------------------------------------------------------------------------
593 594
void vtkPVDataDeliveryManager::SetNextStreamedPiece(
  vtkPVDataRepresentation* repr, vtkDataObject* data)
595
{
596 597 598 599 600 601 602 603 604 605 606
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, /*low_res=*/false);
  if (item == NULL)
    {
    vtkErrorMacro("Invalid argument.");
    return;
    }
  
  // For now, I am going to keep things simple. Piece is delivered to the
  // representation separately. That's it.
  item->SetNextStreamedPiece(data);
}
607

608 609 610 611 612 613 614 615 616 617 618 619
//----------------------------------------------------------------------------
vtkDataObject* vtkPVDataDeliveryManager::GetCurrentStreamedPiece(
  vtkPVDataRepresentation* repr)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, /*low_res=*/false);
  if (item == NULL)
    {
    vtkErrorMacro("Invalid argument.");
    return NULL;
    }
  return item->GetStreamedPiece();
}
620

621 622 623 624 625
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::ClearStreamedPieces()
{
  // I am not too sure if I want to do this. Right now I am thinking once a
  // piece is delivered, the delivery manager should no longer bother about it.
626 627 628 629 630
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
    {
    vtkInternals::vtkItem& item = iter->second.first;
631
    item.SetNextStreamedPiece(NULL);
632 633 634 635
    }
}

//----------------------------------------------------------------------------
636 637
bool vtkPVDataDeliveryManager::GetRepresentationsReadyToStreamPieces(
  std::vector<unsigned int>& keys)
638
{
639 640
  // I am not too sure if I want to do this. Right now I am thinking once a
  // piece is delivered, the delivery manager should no longer bother about it.
641 642 643
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
644
    {
645
    vtkInternals::vtkItem& item = iter->second.first;
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
    if (item.Representation &&
      item.Representation->GetVisibility() &&
      item.Streamable &&
      item.GetStreamedPiece())
      {
      keys.push_back(iter->first);
      }
    }
  return (keys.size() > 0);
}

//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::DeliverStreamedPieces(
  unsigned int size, unsigned int *values)
{
  // This method gets called on all processes to deliver any streamed pieces
  // currently available. This is similar to Deliver(...) except that this deals
  // with only delivering pieces for streaming. 

  bool using_remote_rendering =
    this->RenderView->GetUseDistributedRenderingForStillRender();
  int mode = this->RenderView->GetDataDistributionMode(using_remote_rendering);

  for (unsigned int cc=0; cc < size; cc++)
    {
    vtkInternals::vtkItem* item = this->Internals->GetItem(values[cc], false);

    // FIXME: we need information about the datatype on all processes. For now
    // we assume that the data type is same as the full-data (which is not
    // really necessary). We can API to allow representations to be able to
    // specify the data type.
    vtkDataObject* data = item->GetDataObject();
    vtkDataObject* piece = item->GetStreamedPiece();

    vtkNew<vtkMPIMoveData> dataMover;
    dataMover->InitializeForCommunicationForParaView();
    dataMover->SetOutputDataType(data->GetDataObjectType());
    dataMover->SetMoveMode(mode);
    if (item->AlwaysClone)
      {
      dataMover->SetMoveModeToClone();
      }
    dataMover->SetInputData(piece);
    dataMover->Update();
    if (dataMover->GetOutputGeneratedOnProcess())
691
      {
692
      item->SetNextStreamedPiece(dataMover->GetOutputDataObject(0));
693
      }
694 695 696
    }
}

697
//----------------------------------------------------------------------------
698
void vtkPVDataDeliveryManager::PrintSelf(ostream& os, vtkIndent indent)
699 700 701
{
  this->Superclass::PrintSelf(os, indent);
}
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716

//----------------------------------------------------------------------------
int vtkPVDataDeliveryManager::GetSynchronizationMagicNumber()
{
  const int prime = 31;
  int result = 1;
  result = prime * result + static_cast<int>(this->Internals->ItemsMap.size());
  vtkInternals::ItemsMapType::iterator iter = this->Internals->ItemsMap.begin();
  for(;iter != this->Internals->ItemsMap.end(); iter++)
    {
    result = prime * result + static_cast<int>(iter->first);
    }

  return result;
}