vtkPVDataDeliveryManager.cxx 22.1 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 "vtkDataObject.h"
19 20
#include "vtkExtentTranslator.h"
#include "vtkKdTreeManager.h"
21
#include "vtkMPIMoveData.h"
22 23 24 25 26
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOrderedCompositeDistributor.h"
#include "vtkPKdTree.h"
27
#include "vtkPVDataRepresentation.h"
28
#include "vtkPVRenderView.h"
29
#include "vtkPVStreamingMacros.h"
30 31
#include "vtkPVTrivialProducer.h"
#include "vtkSmartPointer.h"
32
#include "vtkStreamingDemandDrivenPipeline.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
33
#include "vtkTimerLog.h"
34
#include "vtkWeakPointer.h"
35 36

#include <assert.h>
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
#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;

70 71 72 73 74 75 76 77 78
  class vtkOrderedCompositingInfo
    {
  public:
    vtkSmartPointer<vtkExtentTranslator> Translator;
    double Origin[3];
    double Spacing[3];
    int WholeExtent[6];
    };

79 80 81
  class vtkItem
    {
    vtkSmartPointer<vtkPVTrivialProducer> Producer;
82 83

    // Data object produced by the representation.
84
    vtkWeakPointer<vtkDataObject> DataObject;
85 86 87 88 89 90 91 92

    // 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;

93 94 95
    // Data object for a streamed piece.
    vtkSmartPointer<vtkDataObject> StreamedPiece;

96 97 98
    unsigned long TimeStamp;
    unsigned long ActualMemorySize;
  public:
99
    vtkOrderedCompositingInfo OrderedCompositingInfo;
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    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)
116
      {
117 118
      this->DataObject = data;
      this->ActualMemorySize = data? data->GetActualMemorySize() : 0;
119 120 121

      vtkTimeStamp ts; ts.Modified();
      this->TimeStamp = ts;
122 123
      }

124 125
    void SetDeliveredDataObject(vtkDataObject* data)
      {
126 127 128 129 130 131
      this->DeliveredDataObject = data;
      }

    void SetRedistributedDataObject(vtkDataObject* data)
      {
      this->RedistributedDataObject = data;
132 133 134 135
      }

    vtkDataObject* GetDeliveredDataObject()
      {
136 137 138 139 140 141 142 143 144
      return this->DeliveredDataObject.GetPointer();
      }

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

    vtkPVTrivialProducer* GetProducer(bool use_redistributed_data)
145
      {
146 147 148 149 150 151 152 153 154
      if (use_redistributed_data && this->Redistributable)
        {
        this->Producer->SetOutput(this->RedistributedDataObject);
        }
      else
        {
        this->Producer->SetOutput(this->DeliveredDataObject);
        }
      return this->Producer.GetPointer();
155 156
      }

157 158 159 160
    vtkDataObject* GetDataObject() const
      { return this->DataObject.GetPointer(); }
    unsigned long GetTimeStamp() const
      { return this->TimeStamp; }
161

162 163 164 165 166 167 168 169
    unsigned long GetVisibleDataSize()
      {
      if (this->Representation && this->Representation->GetVisibility())
        {
        return this->ActualMemorySize;
        }
      return 0;
      }
170 171 172 173 174 175 176 177 178

    void SetNextStreamedPiece(vtkDataObject* data)
      {
      this->StreamedPiece = data;
      }
    vtkDataObject* GetStreamedPiece()
      {
      return this->StreamedPiece;
      }
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    };

  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)
    {
195
    return this->GetItem(repr->GetUniqueIdentifier(), use_second);
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    }

  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;
    }
215

216 217
  ItemsMapType ItemsMap;
};
218

219 220 221
//*****************************************************************************

vtkStandardNewMacro(vtkPVDataDeliveryManager);
222
//----------------------------------------------------------------------------
223
vtkPVDataDeliveryManager::vtkPVDataDeliveryManager()
224 225 226 227 228
  : Internals(new vtkInternals())
{
}

//----------------------------------------------------------------------------
229
vtkPVDataDeliveryManager::~vtkPVDataDeliveryManager()
230 231 232 233 234
{
  delete this->Internals;
  this->Internals = 0;
}

235
//----------------------------------------------------------------------------
236
void vtkPVDataDeliveryManager::SetRenderView(vtkPVRenderView* view)
237
{
238
  this->RenderView = view;
239 240
}

241
//----------------------------------------------------------------------------
242
vtkPVRenderView* vtkPVDataDeliveryManager::GetRenderView()
243
{
244
  return this->RenderView;
245 246
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
247
//----------------------------------------------------------------------------
248
unsigned long vtkPVDataDeliveryManager::GetVisibleDataSize(bool low_res)
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
249 250 251
{
  return this->Internals->GetVisibleDataSize(low_res);
}
252 253

//----------------------------------------------------------------------------
254
void vtkPVDataDeliveryManager::RegisterRepresentation(vtkPVDataRepresentation* repr)
255
{
256 257
  assert( "A representation must have a valid UniqueIdentifier"
          && repr->GetUniqueIdentifier());
258 259 260

  vtkInternals::vtkItem item;
  item.Representation = repr;
261
  this->Internals->ItemsMap[repr->GetUniqueIdentifier()].first = item;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
262 263 264

  vtkInternals::vtkItem item2;
  item2.Representation = repr;
265
  this->Internals->ItemsMap[repr->GetUniqueIdentifier()].second= item2;
266 267 268
}

//----------------------------------------------------------------------------
269
void vtkPVDataDeliveryManager::UnRegisterRepresentation(
270 271
  vtkPVDataRepresentation* repr)
{
272
  this->Internals->ItemsMap.erase(repr->GetUniqueIdentifier());
273 274 275 276 277 278 279 280 281 282
}

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

283
//----------------------------------------------------------------------------
284
void vtkPVDataDeliveryManager::SetDeliverToAllProcesses(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
285
  vtkPVDataRepresentation* repr, bool mode, bool low_res)
286
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
287
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
288 289
  if (item)
    {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
290
    item->AlwaysClone = mode;
291 292 293 294 295 296 297
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}

298
//----------------------------------------------------------------------------
299
void vtkPVDataDeliveryManager::MarkAsRedistributable(
300 301 302 303 304 305 306 307 308 309 310 311 312 313
  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
314

315
//----------------------------------------------------------------------------
316
void vtkPVDataDeliveryManager::SetStreamable(
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
  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.");
    }
}

332
//----------------------------------------------------------------------------
333
void vtkPVDataDeliveryManager::SetPiece(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
334
  vtkPVDataRepresentation* repr, vtkDataObject* data, bool low_res)
335
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
336
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
337 338
  if (item)
    {
339
    unsigned long data_time = 0;
340 341 342 343
    if (data && (data->GetMTime() > data_time))
      {
      data_time = data->GetMTime();
      }
344 345
    if (data_time > item->GetTimeStamp() ||
      item->GetDataObject() != data)
346 347 348
      {
      item->SetDataObject(data);
      }
349 350
    }
  else
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
351 352 353 354 355 356
    {
    vtkErrorMacro("Invalid argument.");
    }
}

//----------------------------------------------------------------------------
357
vtkAlgorithmOutput* vtkPVDataDeliveryManager::GetProducer(
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
358 359 360 361
  vtkPVDataRepresentation* repr, bool low_res)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, low_res);
  if (!item)
362 363
    {
    vtkErrorMacro("Invalid arguments.");
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
364 365 366
    return NULL;
    }

367 368
  return item->GetProducer(
    this->RenderView->GetUseOrderedCompositing())->GetOutputPort(0);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
369 370 371
}

//----------------------------------------------------------------------------
372
void vtkPVDataDeliveryManager::SetPiece(unsigned int id, vtkDataObject* data, bool
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
373 374 375 376 377 378 379 380 381 382
  low_res)
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(id, low_res);
  if (item)
    {
    item->SetDataObject(data);
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
383 384 385
    }
}

386
//----------------------------------------------------------------------------
387 388 389
void vtkPVDataDeliveryManager::SetOrderedCompositingInformation(
  vtkPVDataRepresentation* repr, vtkExtentTranslator* translator,
  const int whole_extents[6], const double origin[3], const double spacing[3])
390 391 392 393
{
  vtkInternals::vtkItem* item = this->Internals->GetItem(repr, false);
  if (item)
    {
394 395 396 397 398 399 400
    vtkInternals::vtkOrderedCompositingInfo info;
    info.Translator = translator;
    memcpy(info.WholeExtent, whole_extents, sizeof(int)*6);
    memcpy(info.Origin, origin, sizeof(double)*3);
    memcpy(info.Spacing, spacing, sizeof(double)*3);

    item->OrderedCompositingInfo = info;
401 402 403 404 405 406 407
    }
  else
    {
    vtkErrorMacro("Invalid argument.");
    }
}

408
//----------------------------------------------------------------------------
409
vtkAlgorithmOutput* vtkPVDataDeliveryManager::GetProducer(
410
  unsigned int id, bool low_res)
411
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
412
  vtkInternals::vtkItem* item = this->Internals->GetItem(id, low_res);
413 414 415 416 417 418
  if (!item)
    {
    vtkErrorMacro("Invalid arguments.");
    return NULL;
    }

419 420
  return item->GetProducer(
    this->RenderView->GetUseOrderedCompositing())->GetOutputPort(0);
421 422
}

423
//----------------------------------------------------------------------------
424
bool vtkPVDataDeliveryManager::NeedsDelivery(
425
  unsigned long timestamp,
426
  std::vector<unsigned int> &keys_to_deliver, bool use_low)
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
{
  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;
}

//----------------------------------------------------------------------------
444
void vtkPVDataDeliveryManager::Deliver(int use_lod, unsigned int size, unsigned int *values)
445 446

{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
  // 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 =
463 464 465
    use_lod? this->RenderView->GetUseDistributedRenderingForInteractiveRender() :
    this->RenderView->GetUseDistributedRenderingForStillRender();
  int mode = this->RenderView->GetDataDistributionMode(using_remote_rendering);
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
466

467 468 469 470 471 472
  for (unsigned int cc=0; cc < size; cc++)
    {
    vtkInternals::vtkItem* item = this->Internals->GetItem(values[cc], use_lod !=0);

    vtkDataObject* data = item->GetDataObject();

473 474 475 476 477 478
//    if (data != NULL && data->IsA("vtkUniformGridAMR"))
//      {
//      // we are dealing with AMR datasets.
//      // We assume for now we're not running in render-server mode. We can
//      // ensure that at some point in future.
//      // So we are either in pass-through or collect mode.
479

480 481
//      // FIXME: check that the mode flags are "suitable" for AMR.
//      }
482

483 484
    vtkNew<vtkMPIMoveData> dataMover;
    dataMover->InitializeForCommunicationForParaView();
485
    dataMover->SetOutputDataType(data ? data->GetDataObjectType() : VTK_POLY_DATA);
486 487
    dataMover->SetMoveMode(mode);
    if (item->AlwaysClone)
488
      {
489
      dataMover->SetMoveModeToClone();
490
      }
491 492
    dataMover->SetInputData(data);

493 494 495 496 497 498
    if (dataMover->GetOutputGeneratedOnProcess())
      {
      // release old memory (not necessarily, but try).
      item->SetDeliveredDataObject(NULL);
      }
    dataMover->Update();
499
    if (item->GetDeliveredDataObject() == NULL)
500 501 502
      {
      item->SetDeliveredDataObject(dataMover->GetOutputDataObject(0));
      }
503
    }
504

505 506 507
  vtkTimerLog::MarkEndEvent(use_lod?
    "LowRes Data Migration" : "FullRes Data Migration");
}
508

509 510 511 512 513
//----------------------------------------------------------------------------
void vtkPVDataDeliveryManager::RedistributeDataForOrderedCompositing(
  bool use_lod)
{
  if (this->RenderView->GetUpdateTimeStamp() > this->RedistributionTimeStamp)
514
    {
515 516 517 518
    vtkTimerLog::MarkStartEvent("Regenerate Kd-Tree");
    // need to re-generate the kd-tree.
    this->RedistributionTimeStamp.Modified();

519
    vtkNew<vtkKdTreeManager> cutsGenerator;
520 521 522 523 524 525
    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 &&
526
        item.Representation->GetVisibility())
527
        {
528
        if (item.OrderedCompositingInfo.Translator)
529
          {
530 531 532 533 534 535
          // implies that the representation is providing us with means to
          // override how the ordered compositing happens.
          const vtkInternals::vtkOrderedCompositingInfo &info =
            item.OrderedCompositingInfo;
          cutsGenerator->SetStructuredDataInformation(info.Translator,
            info.WholeExtent, info.Origin, info.Spacing);
536
          }
537
        else if (item.Redistributable)
538
          {
539
          cutsGenerator->AddDataObject(item.GetDeliveredDataObject());
540
          }
541 542
        }
      }
543 544
    cutsGenerator->GenerateKdTree();
    this->KdTree = cutsGenerator->GetKdTree();
545

546
    vtkTimerLog::MarkEndEvent("Regenerate Kd-Tree");
547
    }
548 549

  if (this->KdTree == NULL)
550
    {
551
    return;
552 553
    }

554 555 556 557
  vtkTimerLog::MarkStartEvent("Redistributing Data for Ordered Compositing");
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
558
    {
559 560 561 562 563 564 565 566
    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.
567
      item.GetDeliveredDataObject() == NULL)
568
      {
569 570
      continue;
      }
571

572 573 574 575 576 577 578 579 580 581 582 583
    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;
584 585
      }

586 587
    // release old memory (not necessarily, but try).
    item.SetRedistributedDataObject(NULL);
588

589 590 591 592 593 594 595 596 597
    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");
598 599
}

600
//----------------------------------------------------------------------------
601
vtkPKdTree* vtkPVDataDeliveryManager::GetKdTree()
602 603 604
{
  return this->KdTree;
}
605 606

//----------------------------------------------------------------------------
607 608
void vtkPVDataDeliveryManager::SetNextStreamedPiece(
  vtkPVDataRepresentation* repr, vtkDataObject* data)
609
{
610 611 612 613 614 615 616 617 618 619 620
  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);
}
621

622 623 624 625 626 627 628 629 630 631 632 633
//----------------------------------------------------------------------------
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();
}
634

635 636 637 638 639
//----------------------------------------------------------------------------
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.
640 641 642 643 644
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
    {
    vtkInternals::vtkItem& item = iter->second.first;
645
    item.SetNextStreamedPiece(NULL);
646 647 648 649
    }
}

//----------------------------------------------------------------------------
650 651
bool vtkPVDataDeliveryManager::GetRepresentationsReadyToStreamPieces(
  std::vector<unsigned int>& keys)
652
{
653 654
  // 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.
655 656 657
  vtkInternals::ItemsMapType::iterator iter;
  for (iter = this->Internals->ItemsMap.begin();
    iter != this->Internals->ItemsMap.end(); ++iter)
658
    {
659
    vtkInternals::vtkItem& item = iter->second.first;
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 691 692 693 694 695 696 697 698 699 700 701 702 703 704
    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())
705
      {
706
      item->SetNextStreamedPiece(dataMover->GetOutputDataObject(0));
707
      }
708 709 710
    }
}

711
//----------------------------------------------------------------------------
712
void vtkPVDataDeliveryManager::PrintSelf(ostream& os, vtkIndent indent)
713 714 715
{
  this->Superclass::PrintSelf(os, indent);
}
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730

//----------------------------------------------------------------------------
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;
}