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

  Program:   Visualization Toolkit
  Module:    vtkStreamingDemandDrivenPipeline.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15
#include "vtkStreamingDemandDrivenPipeline.h"
16
17
18
19

#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkDataObject.h"
20
#include "vtkDataSet.h"
Berk Geveci's avatar
Berk Geveci committed
21
#include "vtkDataSetAttributes.h"
22
#include "vtkExtentTranslator.h"
23
#include "vtkInformation.h"
24
#include "vtkInformationDoubleKey.h"
25
#include "vtkInformationDoubleVectorKey.h"
26
#include "vtkInformationIdTypeKey.h"
27
#include "vtkInformationInformationVectorKey.h"
28
#include "vtkInformationIntegerKey.h"
29
#include "vtkInformationIntegerRequestKey.h"
30
#include "vtkInformationIntegerVectorKey.h"
31
#include "vtkInformationIterator.h"
32
#include "vtkInformationObjectBaseKey.h"
33
#include "vtkInformationRequestKey.h"
34
35
#include "vtkInformationStringKey.h"
#include "vtkInformationStringKey.h"
36
#include "vtkInformationUnsignedLongKey.h"
37
#include "vtkInformationVector.h"
38
#include "vtkObjectFactory.h"
39
#include "vtkSmartPointer.h"
40
#include "vtkNew.h"
41
42
43

vtkStandardNewMacro(vtkStreamingDemandDrivenPipeline);

44
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, CONTINUE_EXECUTING, Integer);
45
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, EXACT_EXTENT, Integer);
46
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, REQUEST_UPDATE_EXTENT, Request);
47
48
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, REQUEST_UPDATE_TIME, Request);
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, REQUEST_TIME_DEPENDENT_INFORMATION, Request);
49
50
51
52
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UPDATE_EXTENT_INITIALIZED, Integer);
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UPDATE_PIECE_NUMBER, Integer);
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UPDATE_NUMBER_OF_PIECES, Integer);
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UPDATE_NUMBER_OF_GHOST_LEVELS, Integer);
53
54
vtkInformationKeyRestrictedMacro(vtkStreamingDemandDrivenPipeline, WHOLE_EXTENT, IntegerVector, 6);
vtkInformationKeyRestrictedMacro(vtkStreamingDemandDrivenPipeline, UPDATE_EXTENT, IntegerVector, 6);
55
vtkInformationKeyRestrictedMacro(vtkStreamingDemandDrivenPipeline, COMBINED_UPDATE_EXTENT, IntegerVector, 6);
56
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UNRESTRICTED_UPDATE_EXTENT, Integer);
57
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, TIME_STEPS, DoubleVector);
58
59
60
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, UPDATE_TIME_STEP, Double);

vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, PREVIOUS_UPDATE_TIME_STEP, Double);
Ken Martin's avatar
Ken Martin committed
61
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, TIME_RANGE, DoubleVector);
62

63
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, BOUNDS, DoubleVector);
64
65
vtkInformationKeyMacro(vtkStreamingDemandDrivenPipeline, TIME_DEPENDENT_INFORMATION, Integer);

66
//----------------------------------------------------------------------------
67
class vtkStreamingDemandDrivenPipelineToDataObjectFriendship
68
69
{
public:
70
  static void Crop(vtkDataObject* obj, const int* extent)
71
    {
72
    obj->Crop(extent);
73
    }
74
75
};

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
namespace
{
void vtkSDDPSetUpdateExtentToWholeExtent(vtkInformation *info)
{
  typedef vtkStreamingDemandDrivenPipeline vtkSDDP;
  info->Set(vtkSDDP::UPDATE_PIECE_NUMBER(), 0);
  info->Set(vtkSDDP::UPDATE_NUMBER_OF_PIECES(), 1);
  info->Set(vtkSDDP::UPDATE_NUMBER_OF_GHOST_LEVELS(), 0);
  if(info->Has(vtkSDDP::WHOLE_EXTENT()))
    {
    int extent[6] = {0,-1,0,-1,0,-1};
    info->Get(vtkSDDP::WHOLE_EXTENT(), extent);
    info->Set(vtkSDDP::UPDATE_EXTENT(), extent, 6);
    }
}
}

93
94
95
//----------------------------------------------------------------------------
vtkStreamingDemandDrivenPipeline::vtkStreamingDemandDrivenPipeline()
{
96
  this->ContinueExecuting = 0;
97
98
  this->UpdateExtentRequest = 0;
  this->LastPropogateUpdateExtentShortCircuited = 0;
99
100
101
102
103
}

//----------------------------------------------------------------------------
vtkStreamingDemandDrivenPipeline::~vtkStreamingDemandDrivenPipeline()
{
104
105
106
107
  if (this->UpdateExtentRequest)
    {
    this->UpdateExtentRequest->Delete();
    }
108
109
110
111
112
113
114
115
}

//----------------------------------------------------------------------------
void vtkStreamingDemandDrivenPipeline::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

116
//----------------------------------------------------------------------------
117
118
119
120
int vtkStreamingDemandDrivenPipeline
::ProcessRequest(vtkInformation* request,
                 vtkInformationVector** inInfoVec,
                 vtkInformationVector* outInfoVec)
121
122
{
  // The algorithm should not invoke anything on the executive.
123
  if(!this->CheckAlgorithm("ProcessRequest", request))
124
125
126
127
128
    {
    return 0;
    }

  // Look for specially supported requests.
129
130
131
132
133
134
135
136
137
  if(request->Has(REQUEST_UPDATE_TIME()))
    {
    int result = 1;
    int outputPort = -1;
    if(request->Has(FROM_OUTPUT_PORT()))
      {
      outputPort = request->Get(FROM_OUTPUT_PORT());
      }

138
139
    int N2E =  this->Superclass::NeedToExecuteData(outputPort, inInfoVec,outInfoVec);
    if(!N2E && outputPort>=0)
140
141
142
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
      {
      vtkInformation* outInfo = outInfoVec->GetInformationObject(outputPort);
      vtkDataObject* dataObject = outInfo->Get(vtkDataObject::DATA_OBJECT());
      if (outInfo->Has(TIME_DEPENDENT_INFORMATION()))
        {
        N2E  = this->NeedToExecuteBasedOnTime(outInfo,dataObject);
        }
      else
        {
        N2E = 0;
        }
      }
    if(N2E)
      {
      result = this->CallAlgorithm(request, vtkExecutive::RequestUpstream,
                                   inInfoVec, outInfoVec);
      // Propagate the update extent to all inputs.
      if(result)
        {
        result = this->ForwardUpstream(request);
        }
      result = 1;
      }
    return result;
    }

 // Look for specially supported requests.
  if(request->Has(REQUEST_TIME_DEPENDENT_INFORMATION()))
    {
    int outputPort = -1;
    if(request->Has(FROM_OUTPUT_PORT()))
      {
      outputPort = request->Get(FROM_OUTPUT_PORT());
      }
    int N2E = 1;
    if(outputPort>=0)
      {
      vtkInformation* outInfo = outInfoVec->GetInformationObject(outputPort);
      if(!outInfo->Has(TIME_DEPENDENT_INFORMATION()))
        {
        N2E = 0;
        }
      }
    if(!N2E)
      {
      return 1;
      }
    }

189
190
191
  if(request->Has(REQUEST_UPDATE_EXTENT()))
    {
    // Get the output port from which the request was made.
192
    this->LastPropogateUpdateExtentShortCircuited = 1;
193
194
195
196
197
    int outputPort = -1;
    if(request->Has(FROM_OUTPUT_PORT()))
      {
      outputPort = request->Get(FROM_OUTPUT_PORT());
      }
198

199
    // Make sure the information on the output port is valid.
200
    if(!this->VerifyOutputInformation(outputPort,inInfoVec,outInfoVec))
201
202
203
204
      {
      return 0;
      }

205
206
207
208
209
210
211
212
213
214
215
216
    // Get the output info
    vtkInformation* outInfo = 0;
    if (outputPort > -1)
      {
      outInfo = outInfoVec->GetInformationObject(outputPort);
      }

    // Combine the requested extent into COMBINED_UPDATE_EXTENT,
    // but only do so if the UPDATE_EXTENT key exists and if the
    // UPDATE_EXTENT is not an empty extent
    int *updateExtent = 0;
    if (outInfo &&
217
        (updateExtent = outInfo->Get(UPDATE_EXTENT())) != 0)
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
      {
      // Downstream algorithms can set UPDATE_EXTENT_INITIALIZED to
      // REPLACE if they do not want to combine with previous extents
      if (outInfo->Get(UPDATE_EXTENT_INITIALIZED()) !=
          VTK_UPDATE_EXTENT_REPLACE)
        {
        int *combinedExtent = outInfo->Get(COMBINED_UPDATE_EXTENT());
        if (combinedExtent &&
            combinedExtent[0] <= combinedExtent[1] &&
            combinedExtent[2] <= combinedExtent[3] &&
            combinedExtent[4] <= combinedExtent[5])
          {
          if (updateExtent[0] <= updateExtent[1] &&
              updateExtent[2] <= updateExtent[3] &&
              updateExtent[4] <= updateExtent[5])
            {
            int newExtent[6];
            for (int ii = 0; ii < 6; ii += 2)
              {
              newExtent[ii] = combinedExtent[ii];
              if (updateExtent[ii] < newExtent[ii])
                {
                newExtent[ii] = updateExtent[ii];
                }
              newExtent[ii+1] = combinedExtent[ii+1];
              if (updateExtent[ii+1] > newExtent[ii+1])
                {
                newExtent[ii+1] = updateExtent[ii+1];
                }
              }
            outInfo->Set(COMBINED_UPDATE_EXTENT(), newExtent, 6);
            outInfo->Set(UPDATE_EXTENT(), newExtent, 6);
            }
          else
            {
            outInfo->Set(UPDATE_EXTENT(), combinedExtent, 6);
            }
          }
        else
          {
          outInfo->Set(COMBINED_UPDATE_EXTENT(), updateExtent, 6);
          }
        }
      }

263
264
    // If we need to execute, propagate the update extent.
    int result = 1;
265
    int N2E = this->NeedToExecuteData(outputPort,inInfoVec,outInfoVec);
266
    if (!N2E &&
267
        outInfo &&
268
269
        this->GetNumberOfInputPorts() &&
        inInfoVec[0]->GetNumberOfInformationObjects () > 0)
270
271
272
273
274
275
276
277
278
279
280
281
      {
      vtkInformation* inInfo = inInfoVec[0]->GetInformationObject(0);
      int outNumberOfPieces = outInfo->Get(UPDATE_NUMBER_OF_PIECES());
      int inNumberOfPieces = inInfo->Get(UPDATE_NUMBER_OF_PIECES());
      if(inNumberOfPieces != outNumberOfPieces)
        {
        N2E = 1;
        }
      else
        {
        if (outNumberOfPieces != 1)
          {
282
          int outPiece = outInfo->Get(UPDATE_PIECE_NUMBER());
283
284
285
286
287
288
          int inPiece = inInfo->Get(UPDATE_PIECE_NUMBER());
          if (inPiece != outPiece)
            {
            N2E = 1;
            }
          }
289
        }
290
291
      }
    if(N2E)
292
      {
293
      // Make sure input types are valid before algorithm does anything.
294
      if(!this->InputCountIsValid(inInfoVec) ||
295
         !this->InputTypeIsValid(inInfoVec))
296
        {
297
        result = 0;
298
        }
299
300
301
302
303
304
      else
        {
        // Invoke the request on the algorithm.
        this->LastPropogateUpdateExtentShortCircuited = 0;
        result = this->CallAlgorithm(request, vtkExecutive::RequestUpstream,
                                     inInfoVec, outInfoVec);
305

306
307
308
309
310
311
312
313
        // Propagate the update extent to all inputs.
        if(result)
          {
          result = this->ForwardUpstream(request);
          }
        result = 1;
        }
      }
314
    if (!N2E)
315
316
      {
      if(outInfo && outInfo->Has(COMBINED_UPDATE_EXTENT()))
317
        {
318
319
        static int emptyExt[6] = { 0, -1, 0, -1, 0, -1 };
        outInfo->Set(COMBINED_UPDATE_EXTENT(), emptyExt, 6);
320
321
322
323
324
325
326
327
        }
      }
    return result;
    }

  if(request->Has(REQUEST_DATA()))
    {
    // Let the superclass handle the request first.
328
    if(this->Superclass::ProcessRequest(request, inInfoVec, outInfoVec))
329
      {
330
      for(int i=0; i < outInfoVec->GetNumberOfInformationObjects(); ++i)
331
        {
332
        vtkInformation* info = outInfoVec->GetInformationObject(i);
333
        // Crop the output if the exact extent flag is set.
334
335
        if(info->Has(EXACT_EXTENT()) && info->Get(EXACT_EXTENT()))
          {
336
          vtkDataObject* data = info->Get(vtkDataObject::DATA_OBJECT());
337
338
          vtkStreamingDemandDrivenPipelineToDataObjectFriendship::Crop(
            data, info->Get(UPDATE_EXTENT()));
339
          }
340
341
342
343
344
345
        // Clear combined update extent, since the update cycle has completed
        if (info->Has(COMBINED_UPDATE_EXTENT()))
          {
          static int emptyExt[6] = { 0, -1, 0, -1, 0, -1 };
          info->Set(COMBINED_UPDATE_EXTENT(), emptyExt, 6);
          }
346
347
348
349
350
351
352
        }
      return 1;
      }
    return 0;
    }

  // Let the superclass handle other requests.
353
  return this->Superclass::ProcessRequest(request, inInfoVec, outInfoVec);
354
355
}

356
//----------------------------------------------------------------------------
357
int vtkStreamingDemandDrivenPipeline::Update()
358
{
359
  return this->Superclass::Update();
360
361
362
}

//----------------------------------------------------------------------------
363
int vtkStreamingDemandDrivenPipeline::Update(int port)
364
365
366
367
368
369
370
{
  return this->Update(port, 0);
}

//----------------------------------------------------------------------------
int vtkStreamingDemandDrivenPipeline::Update(int port,
                                             vtkInformationVector* requests)
371
372
{
  if(!this->UpdateInformation())
373
374
375
    {
    return 0;
    }
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  int numPorts = this->Algorithm->GetNumberOfOutputPorts();
  if (requests)
    {
    vtkInformationVector* outInfoVec = this->GetOutputInformation();
    for (int i=0; i<numPorts; i++)
      {
      vtkInformation* outInfo = outInfoVec->GetInformationObject(i);
      vtkInformation* req = requests->GetInformationObject(i);
      if (outInfo && req)
        {
        outInfo->Append(req);
        }
      }
    }

  if(port >= -1 && port < numPorts)
392
    {
Ken Martin's avatar
Ken Martin committed
393
394
395
    int retval = 1;
    // some streaming filters can request that the pipeline execute multiple
    // times for a single update
396
    do
Ken Martin's avatar
Ken Martin committed
397
      {
398
      this->PropagateTime(port);
399
      this->UpdateTimeDependentInformation(port);
400
401
402
403
404
      retval = retval && this->PropagateUpdateExtent(port);
      if (retval && !this->LastPropogateUpdateExtentShortCircuited)
        {
        retval = retval && this->UpdateData(port);
        }
Ken Martin's avatar
Ken Martin committed
405
      }
406
    while (this->ContinueExecuting);
Ken Martin's avatar
Ken Martin committed
407
    return retval;
408
409
410
411
412
413
    }
  else
    {
    return 1;
    }
}
414

415
//----------------------------------------------------------------------------
416
int vtkStreamingDemandDrivenPipeline::UpdateWholeExtent()
417
{
418
  this->UpdateInformation();
419
420
421
  // if we have an output then set the UE to WE for it
  if (this->Algorithm->GetNumberOfOutputPorts())
    {
422
    vtkSDDPSetUpdateExtentToWholeExtent
423
      (this->GetOutputInformation()->GetInformationObject(0));
424
425
426
427
428
429
430
431
432
433
434
435
436
    }
  // otherwise do it for the inputs
  else
    {
    // Loop over all input ports.
    for(int i=0; i < this->Algorithm->GetNumberOfInputPorts(); ++i)
      {
      // Loop over all connections on this input port.
      int numInConnections = this->Algorithm->GetNumberOfInputConnections(i);
      for (int j=0; j<numInConnections; j++)
        {
        // Get the pipeline information for this input connection.
        vtkInformation* inInfo = this->GetInputInformation(i, j);
437
        vtkSDDPSetUpdateExtentToWholeExtent(inInfo);
438
439
440
        }
      }
    }
441
  return this->Update();
442
443
}

444
//----------------------------------------------------------------------------
445
446
int
vtkStreamingDemandDrivenPipeline
447
448
449
::ExecuteInformation(vtkInformation* request,
                     vtkInformationVector** inInfoVec,
                     vtkInformationVector* outInfoVec)
450
{
451
  // Let the superclass make the request to the algorithm.
452
  if(this->Superclass::ExecuteInformation(request,inInfoVec,outInfoVec))
453
454
455
    {
    for(int i=0; i < this->Algorithm->GetNumberOfOutputPorts(); ++i)
      {
456
      vtkInformation* info = outInfoVec->GetInformationObject(i);
457
458
      vtkDataObject* data = info->Get(vtkDataObject::DATA_OBJECT());

459
460
461
462
      if (!data)
        {
        return 0;
        }
463
464

      if(data->GetExtentType() == VTK_3D_EXTENT)
465
466
467
468
469
470
471
472
473
        {
        if(!info->Has(WHOLE_EXTENT()))
          {
          int extent[6] = {0,-1,0,-1,0,-1};
          info->Set(WHOLE_EXTENT(), extent, 6);
          }
        }

      // Make sure an update request exists.
474
475
476
      // Request all data by default.
      vtkSDDPSetUpdateExtentToWholeExtent
        (outInfoVec->GetInformationObject(i));
477
478
479
480
481
482
483
      }
    return 1;
    }
  else
    {
    return 0;
    }
484
485
}

486
487
488
//----------------------------------------------------------------------------
void
vtkStreamingDemandDrivenPipeline
489
490
491
::CopyDefaultInformation(vtkInformation* request, int direction,
                         vtkInformationVector** inInfoVec,
                         vtkInformationVector* outInfoVec)
Ken Martin's avatar
Ken Martin committed
492
{
493
  // Let the superclass copy first.
494
495
  this->Superclass::CopyDefaultInformation(request, direction,
                                           inInfoVec, outInfoVec);
496

497
  if(request->Has(REQUEST_INFORMATION()))
498
    {
499
    if(this->GetNumberOfInputPorts() > 0)
500
      {
501
      if(vtkInformation* inInfo = inInfoVec[0]->GetInformationObject(0))
502
        {
Berk Geveci's avatar
Berk Geveci committed
503
504
505
506
507
        vtkInformation* scalarInfo =
          vtkDataObject::GetActiveFieldInformation(
            inInfo,
            vtkDataObject::FIELD_ASSOCIATION_POINTS,
            vtkDataSetAttributes::SCALARS);
508
        // Copy information from the first input to all outputs.
509
        for(int i=0; i < outInfoVec->GetNumberOfInformationObjects(); ++i)
510
          {
511
          vtkInformation* outInfo = outInfoVec->GetInformationObject(i);
512
          outInfo->CopyEntry(inInfo, WHOLE_EXTENT());
513
          outInfo->CopyEntry(inInfo, TIME_STEPS());
Ken Martin's avatar
Ken Martin committed
514
          outInfo->CopyEntry(inInfo, TIME_RANGE());
Berk Geveci's avatar
Berk Geveci committed
515
516
          outInfo->CopyEntry(inInfo, vtkDataObject::ORIGIN());
          outInfo->CopyEntry(inInfo, vtkDataObject::SPACING());
517
          outInfo->CopyEntry(inInfo, TIME_DEPENDENT_INFORMATION());
Berk Geveci's avatar
Berk Geveci committed
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
          if (scalarInfo)
            {
            int scalarType = VTK_DOUBLE;
            if (scalarInfo->Has(vtkDataObject::FIELD_ARRAY_TYPE()))
              {
              scalarType = scalarInfo->Get(vtkDataObject::FIELD_ARRAY_TYPE());
              }
            int numComp = 1;
            if (scalarInfo->Has(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS()))
              {
              numComp = scalarInfo->Get(vtkDataObject::FIELD_NUMBER_OF_COMPONENTS());
              }
            vtkDataObject::SetPointDataActiveScalarInfo(
              outInfo, scalarType, numComp);
            }
533
          }
534
        }
535
      }
536
    }
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

  if(request->Has(REQUEST_UPDATE_TIME()))
    {
    // Get the output port from which to copy the extent.
    int outputPort = -1;
    if(request->Has(FROM_OUTPUT_PORT()))
      {
      outputPort = request->Get(FROM_OUTPUT_PORT());
      }

    // Setup default information for the inputs.
    if(outInfoVec->GetNumberOfInformationObjects() > 0)
      {
      // Copy information from the output port that made the request.
      // Since VerifyOutputInformation has already been called we know
      // there is output information with a data object.
      vtkInformation* outInfo =
        outInfoVec->GetInformationObject((outputPort >= 0)? outputPort : 0);

      // Loop over all input ports.
      for(int i=0; i < this->Algorithm->GetNumberOfInputPorts(); ++i)
        {
        // Loop over all connections on this input port.
        int numInConnections = inInfoVec[i]->GetNumberOfInformationObjects();
        for (int j=0; j<numInConnections; j++)
          {
          // Get the pipeline information for this input connection.
          vtkInformation* inInfo = inInfoVec[i]->GetInformationObject(j);

          // Copy the time request
          if ( outInfo->Has(UPDATE_TIME_STEP()) )
            {
            inInfo->CopyEntry(outInfo, UPDATE_TIME_STEP());
            }
          }
        }
      }
    }
575
576
577
578
579
580
581
582
  if(request->Has(REQUEST_UPDATE_EXTENT()))
    {
    // Get the output port from which to copy the extent.
    int outputPort = -1;
    if(request->Has(FROM_OUTPUT_PORT()))
      {
      outputPort = request->Get(FROM_OUTPUT_PORT());
      }
Brad King's avatar
Brad King committed
583

584
585
586
587
588
589
590
591
592
593
594
    // Initialize input extent to whole extent if it is not
    // already initialized.
    // This may be overwritten by the default code below as
    // well as what that an algorith may do.
    for(int i=0; i < this->Algorithm->GetNumberOfInputPorts(); ++i)
      {
      // Loop over all connections on this input port.
      int numInConnections = inInfoVec[i]->GetNumberOfInformationObjects();
      for (int j=0; j<numInConnections; j++)
        {
        vtkInformation* inInfo = inInfoVec[i]->GetInformationObject(j);
595
        vtkSDDPSetUpdateExtentToWholeExtent(inInfo);
596
597
598
        }
      }

599
    // Setup default information for the inputs.
600
    if(outInfoVec->GetNumberOfInformationObjects() > 0)
601
602
603
604
605
      {
      // Copy information from the output port that made the request.
      // Since VerifyOutputInformation has already been called we know
      // there is output information with a data object.
      vtkInformation* outInfo =
606
        outInfoVec->GetInformationObject((outputPort >= 0)? outputPort : 0);
607
608
609
610
611

      // Loop over all input ports.
      for(int i=0; i < this->Algorithm->GetNumberOfInputPorts(); ++i)
        {
        // Loop over all connections on this input port.
612
        int numInConnections = inInfoVec[i]->GetNumberOfInformationObjects();
613
        for (int j=0; j<numInConnections; j++)
614
          {
615
          // Get the pipeline information for this input connection.
616
          vtkInformation* inInfo = inInfoVec[i]->GetInformationObject(j);
617

618
          // Copy the time request
619
          if ( outInfo->Has(UPDATE_TIME_STEP()) )
620
            {
621
            inInfo->CopyEntry(outInfo, UPDATE_TIME_STEP());
622
            }
623

624
625
626
627
628
          // If an algorithm wants an exact extent it must explicitly
          // add it to the request.  We do not want to get the setting
          // from another consumer of the same input.
          inInfo->Remove(EXACT_EXTENT());

629
630
631
632
          // Get the input data object for this connection.  It should
          // have already been created by the UpdateDataObject pass.
          vtkDataObject* inData = inInfo->Get(vtkDataObject::DATA_OBJECT());
          if(!inData)
Brad King's avatar
Brad King committed
633
            {
634
635
636
637
638
639
640
            vtkErrorMacro("Cannot copy default update request from output port "
                          << outputPort << " on algorithm "
                          << this->Algorithm->GetClassName()
                          << "(" << this->Algorithm << ") to input connection "
                          << j << " on input port " << i
                          << " because there is no data object.");
            continue;
Brad King's avatar
Brad King committed
641
            }
642

643
644

          if (outInfo->Has(UPDATE_EXTENT()))
Brad King's avatar
Brad King committed
645
            {
646
            inInfo->CopyEntry(outInfo, UPDATE_EXTENT());
Brad King's avatar
Brad King committed
647
            }
648

649
650
651
652
653
          inInfo->CopyEntry(outInfo, UPDATE_PIECE_NUMBER());
          inInfo->CopyEntry(outInfo, UPDATE_NUMBER_OF_PIECES());
          inInfo->CopyEntry(outInfo, UPDATE_NUMBER_OF_GHOST_LEVELS());

          inInfo->CopyEntry(outInfo, UPDATE_EXTENT_INITIALIZED());
654
655
656
657
658
659
          }
        }
      }
    }
}

660
661
662
663
664
665
666
//----------------------------------------------------------------------------
void
vtkStreamingDemandDrivenPipeline
::ResetPipelineInformation(int port, vtkInformation* info)
{
  this->Superclass::ResetPipelineInformation(port, info);
  info->Remove(WHOLE_EXTENT());
667
  info->Remove(EXACT_EXTENT());
668
669
670
671
672
  info->Remove(UPDATE_EXTENT_INITIALIZED());
  info->Remove(UPDATE_EXTENT());
  info->Remove(UPDATE_PIECE_NUMBER());
  info->Remove(UPDATE_NUMBER_OF_PIECES());
  info->Remove(UPDATE_NUMBER_OF_GHOST_LEVELS());
Ken Martin's avatar
Ken Martin committed
673
674
  info->Remove(TIME_STEPS());
  info->Remove(TIME_RANGE());
675
676
  info->Remove(UPDATE_TIME_STEP());
  info->Remove(PREVIOUS_UPDATE_TIME_STEP());
Berk Geveci's avatar
Berk Geveci committed
677
  info->Remove(vtkAlgorithm::CAN_HANDLE_PIECE_REQUEST());
678
  info->Remove(vtkAlgorithm::CAN_PRODUCE_SUB_EXTENT());
679
680
}

681
682
683
//----------------------------------------------------------------------------
int vtkStreamingDemandDrivenPipeline::PropagateUpdateExtent(int outputPort)
{
684
  // The algorithm should not invoke anything on the executive.
685
  if(!this->CheckAlgorithm("PropagateUpdateExtent", 0))
686
687
688
689
690
    {
    return 0;
    }

  // Range check.
691
  if(outputPort < -1 ||
692
693
694
695
696
697
698
699
700
     outputPort >= this->Algorithm->GetNumberOfOutputPorts())
    {
    vtkErrorMacro("PropagateUpdateExtent given output port index "
                  << outputPort << " on an algorithm with "
                  << this->Algorithm->GetNumberOfOutputPorts()
                  << " output ports.");
    return 0;
    }

701
  // Setup the request for update extent propagation.
702
703
704
705
706
707
708
709
710
  if (!this->UpdateExtentRequest)
    {
    this->UpdateExtentRequest = vtkInformation::New();
    this->UpdateExtentRequest->Set(REQUEST_UPDATE_EXTENT());
    // The request is forwarded upstream through the pipeline.
    this->UpdateExtentRequest->Set(vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
    // Algorithms process this request before it is forwarded.
    this->UpdateExtentRequest->Set(vtkExecutive::ALGORITHM_BEFORE_FORWARD(), 1);
    }
711

712
  this->UpdateExtentRequest->Set(FROM_OUTPUT_PORT(), outputPort);
Ken Martin's avatar
Ken Martin committed
713

714
  // Send the request.
715
716
  return this->ProcessRequest(this->UpdateExtentRequest,
                              this->GetInputInformation(),
717
                              this->GetOutputInformation());
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
750
751
752
753
754
755
756
757
758
759
760
int vtkStreamingDemandDrivenPipeline::PropagateTime(int outputPort)
{
  // The algorithm should not invoke anything on the executive.
  if(!this->CheckAlgorithm("PropagateTime", 0))
    {
    return 0;
    }

  // Range check.
  if(outputPort < -1 ||
     outputPort >= this->Algorithm->GetNumberOfOutputPorts())
    {
    vtkErrorMacro("PropagateUpdateTime given output port index "
                  << outputPort << " on an algorithm with "
                  << this->Algorithm->GetNumberOfOutputPorts()
                  << " output ports.");
    return 0;
    }

  // Setup the request for update extent propagation.
  vtkSmartPointer<vtkInformation> updateTimeRequest = vtkSmartPointer<vtkInformation>::New();

  //if (!this->UpdateExtentRequest)
    {
    updateTimeRequest->Set(REQUEST_UPDATE_TIME());
    // The request is forwarded upstream through the pipeline.
    updateTimeRequest->Set(vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
    // Algorithms process this request before it is forwarded.
    updateTimeRequest->Set(vtkExecutive::ALGORITHM_BEFORE_FORWARD(), 1);
    }

  updateTimeRequest->Set(FROM_OUTPUT_PORT(), outputPort);

  // Send the request.
  return this->ProcessRequest(updateTimeRequest,
                              this->GetInputInformation(),
                              this->GetOutputInformation());
}

//----------------------------------------------------------------------------
761
int vtkStreamingDemandDrivenPipeline::UpdateTimeDependentInformation(int port)
762
763
764
765
766
767
768
769
770
771
772
773
774
775
{
  // The algorithm should not invoke anything on the executive.
  if(!this->CheckAlgorithm("UpdateMetaInformation", 0))
    {
    return 0;
    }
  // Setup the request for information.
  vtkSmartPointer<vtkInformation> timeRequest = vtkSmartPointer<vtkInformation>::New();
  timeRequest->Set(REQUEST_TIME_DEPENDENT_INFORMATION());
  // The request is forwarded upstream through the pipeline.
  timeRequest->Set(vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
  // Algorithms process this request after it is forwarded.
  timeRequest->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);

776
777
  timeRequest->Set(FROM_OUTPUT_PORT(), port);

778
779
780
781
782
783
784
  // Send the request.
  return this->ProcessRequest(timeRequest,
                              this->GetInputInformation(),
                              this->GetOutputInformation());
}

//----------------------------------------------------------------------------
785
786
787
788
int vtkStreamingDemandDrivenPipeline
::VerifyOutputInformation(int outputPort,
                          vtkInformationVector** inInfoVec,
                          vtkInformationVector* outInfoVec)
789
{
790
  // If no port is specified, check all ports.
791
792
793
794
  if(outputPort < 0)
    {
    for(int i=0; i < this->Algorithm->GetNumberOfOutputPorts(); ++i)
      {
795
      if(!this->VerifyOutputInformation(i,inInfoVec,outInfoVec))
796
797
798
799
        {
        return 0;
        }
      }
800
    return 1;
801
802
    }

803
  // Get the information object to check.
804
  vtkInformation* outInfo = outInfoVec->GetInformationObject(outputPort);
805
806

  // Make sure there is a data object.  It is supposed to be created
Brad King's avatar
Brad King committed
807
  // by the UpdateDataObject step.
808
  vtkDataObject* dataObject = outInfo->Get(vtkDataObject::DATA_OBJECT());
809
810
811
812
813
814
815
816
  if(!dataObject)
    {
    vtkErrorMacro("No data object has been set in the information for "
                  "output port " << outputPort << ".");
    return 0;
    }

  // Check extents.
Ken Martin's avatar
Ken Martin committed
817
  vtkInformation* dataInfo = dataObject->GetInformation();
818
  if(dataInfo->Get(vtkDataObject::DATA_EXTENT_TYPE()) == VTK_PIECES_EXTENT)
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
    {
    // For an unstructured extent, make sure the update request
    // exists.  We do not need to check if it is valid because
    // out-of-range requests produce empty data.
    if(!outInfo->Has(UPDATE_PIECE_NUMBER()))
      {
      vtkErrorMacro("No update piece number has been set in the "
                    "information for output port " << outputPort
                    << " on algorithm " << this->Algorithm->GetClassName()
                    << "(" << this->Algorithm << ").");
      return 0;
      }
    if(!outInfo->Has(UPDATE_NUMBER_OF_PIECES()))
      {
      vtkErrorMacro("No update number of pieces has been set in the "
                    "information for output port " << outputPort
                    << " on algorithm " << this->Algorithm->GetClassName()
                    << "(" << this->Algorithm << ").");
      return 0;
      }
    if(!outInfo->Has(UPDATE_NUMBER_OF_GHOST_LEVELS()))
      {
841
842
      // Use zero ghost levels by default.
      outInfo->Set(UPDATE_NUMBER_OF_GHOST_LEVELS(), 0);
843
844
845
      }
    }
  else if(dataInfo->Get(vtkDataObject::DATA_EXTENT_TYPE()) == VTK_3D_EXTENT)
846
    {
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
    // For a structured extent, make sure the update request
    // exists.
    if(!outInfo->Has(WHOLE_EXTENT()))
      {
      vtkErrorMacro("No whole extent has been set in the "
                    "information for output port " << outputPort
                    << " on algorithm " << this->Algorithm->GetClassName()
                    << "(" << this->Algorithm << ").");
      return 0;
      }
    if(!outInfo->Has(UPDATE_EXTENT()))
      {
      vtkErrorMacro("No update extent has been set in the "
                    "information for output port " << outputPort
                    << " on algorithm " << this->Algorithm->GetClassName()
                    << "(" << this->Algorithm << ").");
      return 0;
      }
    // Make sure the update request is inside the whole extent.
    int wholeExtent[6];
    int updateExtent[6];
    outInfo->Get(WHOLE_EXTENT(), wholeExtent);
    outInfo->Get(UPDATE_EXTENT(), updateExtent);
    if((updateExtent[0] < wholeExtent[0] ||
        updateExtent[1] > wholeExtent[1] ||
        updateExtent[2] < wholeExtent[2] ||
        updateExtent[3] > wholeExtent[3] ||
        updateExtent[4] < wholeExtent[4] ||
        updateExtent[5] > wholeExtent[5]) &&
       (updateExtent[0] <= updateExtent[1] &&
        updateExtent[2] <= updateExtent[3] &&
        updateExtent[4] <= updateExtent[5]))
      {
880
      if (!outInfo->Has(UNRESTRICTED_UPDATE_EXTENT()))
881
        {
882
883
884
885
886
887
888
889
890
891
892
893
        // Update extent is outside the whole extent and is not empty.
        vtkErrorMacro("The update extent specified in the "
                      "information for output port " << outputPort
                      << " on algorithm " << this->Algorithm->GetClassName()
                      << "(" << this->Algorithm << ") is "
                      << updateExtent[0] << " " << updateExtent[1] << " "
                      << updateExtent[2] << " " << updateExtent[3] << " "
                      << updateExtent[4] << " " << updateExtent[5]
                      << ", which is outside the whole extent "
                      << wholeExtent[0] << " " << wholeExtent[1] << " "
                      << wholeExtent[2] << " " << wholeExtent[3] << " "
                      << wholeExtent[4] << " " << wholeExtent[5] << ".");
894
        return 0;
895
        }
896
      }
897
    }
898

899
900
  return 1;
}
901

902
//----------------------------------------------------------------------------
903
void
904
905
906
907
vtkStreamingDemandDrivenPipeline
::ExecuteDataStart(vtkInformation* request,
                   vtkInformationVector** inInfoVec,
                   vtkInformationVector* outInfoVec)
908
909
{
  // Preserve the execution continuation flag in the request across
910
911
  // iterations of the algorithm.  Perform start operations only if
  // not in an execute continuation.
912
913
914
915
916
917
918
  if(this->ContinueExecuting)
    {
    request->Set(CONTINUE_EXECUTING(), 1);
    }
  else
    {
    request->Remove(CONTINUE_EXECUTING());
919
    this->Superclass::ExecuteDataStart(request,inInfoVec,outInfoVec);
920
    }
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949

  int numInfo = outInfoVec->GetNumberOfInformationObjects();
  for(int i=0; i < numInfo ; ++i)
    {
    vtkInformation* outInfo = outInfoVec->GetInformationObject(i);
    int numPieces = outInfo->Get(UPDATE_NUMBER_OF_PIECES());
    if (numPieces > 1)
      {
      int* uExt = outInfo->Get(
        vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT());
      if (uExt)
        {
        // Store the total requested extent in ALL_PIECES_EXTENT.
        // This can be different than DATA_EXTENT if the algorithm
        // produces multiple pieces.
        // NOTE: we store this in outInfo because data info gets
        // wiped during execute. We move this to data info in
        // ExecuteDataEnd.
        outInfo->Set(vtkDataObject::ALL_PIECES_EXTENT(), uExt, 6);
        }

      // If the algorithm is capable of producing sub-extents, use
      // an extent translator to break update extent request into
      // pieces.
      if (outInfo->Has(vtkAlgorithm::CAN_PRODUCE_SUB_EXTENT()))
        {
        int piece = outInfo->Get(UPDATE_PIECE_NUMBER());
        int ghost = outInfo->Get(UPDATE_NUMBER_OF_GHOST_LEVELS());

950
951
952
953
954
955
        int splitMode = vtkExtentTranslator::BLOCK_MODE;
        if (outInfo->Has(vtkExtentTranslator::UPDATE_SPLIT_MODE()))
          {
          splitMode = outInfo->Get(vtkExtentTranslator::UPDATE_SPLIT_MODE());
          }

956
957
958
959
        vtkExtentTranslator* et = vtkExtentTranslator::New();
        int execExt[6];
        et->PieceToExtentThreadSafe(piece, numPieces, ghost,
                                    uExt, execExt,
960
                                    splitMode, 0);
961
962
963
964
965
966
        et->Delete();
        outInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
                     execExt, 6);
        }
      }
    }
967
}
968

969
970
//----------------------------------------------------------------------------
void
971
972
973
974
vtkStreamingDemandDrivenPipeline
::ExecuteDataEnd(vtkInformation* request,
                 vtkInformationVector** inInfoVec,
                 vtkInformationVector* outInfoVec)
975
{
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  int numInfo = outInfoVec->GetNumberOfInformationObjects();
  for(int i=0; i < numInfo ; ++i)
    {
    vtkInformation* outInfo = outInfoVec->GetInformationObject(i);
    int numPieces = outInfo->Get(UPDATE_NUMBER_OF_PIECES());
    if (numPieces > 1)
      {
      vtkDataObject* dobj = outInfo->Get(vtkDataObject::DATA_OBJECT());

      // See ExecuteDataStart for an explanation of this key and
      // why we move it from outInfo to data info.
      if (outInfo->Has(vtkDataObject::ALL_PIECES_EXTENT()))
        {
        dobj->GetInformation()->Set(vtkDataObject::ALL_PIECES_EXTENT(),
                                    outInfo->Get(vtkDataObject::ALL_PIECES_EXTENT()),
                                    6);
        }

      if (outInfo->Has(vtkAlgorithm::CAN_PRODUCE_SUB_EXTENT()))
        {
        int ghost = outInfo->Get(UPDATE_NUMBER_OF_GHOST_LEVELS());
        if (ghost > 0)
          {
          vtkDataSet* data = vtkDataSet::SafeDownCast(dobj);
          if (data)
For faster browsing, not all history is shown. View entire blame