forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkCompositeDataPipeline.cxx
1520 lines (1356 loc) · 51.4 KB
/
vtkCompositeDataPipeline.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
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
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
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
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCompositeDataPipeline.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.
=========================================================================*/
#include "vtkCompositeDataPipeline.h"
#include "vtkAlgorithm.h"
#include "vtkAlgorithmOutput.h"
#include "vtkCompositeDataIterator.h"
#include "vtkImageData.h"
#include "vtkInformationDoubleKey.h"
#include "vtkInformationExecutivePortKey.h"
#include "vtkInformationExecutivePortVectorKey.h"
#include "vtkInformation.h"
#include "vtkInformationIdTypeKey.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationIntegerVectorKey.h"
#include "vtkInformationKey.h"
#include "vtkInformationObjectBaseKey.h"
#include "vtkInformationStringKey.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkPolyData.h"
#include "vtkRectilinearGrid.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
#include "vtkTemporalDataSet.h"
#include "vtkUniformGrid.h"
//----------------------------------------------------------------------------
#if defined (JB_DEBUG1)
#ifndef WIN32
#else
#define OUTPUTTEXT(a) vtkOutputWindowDisplayText(a);
#endif
#undef vtkDebugMacro
#define vtkDebugMacro(a) \
{ \
vtkOStreamWrapper::EndlType endl; \
vtkOStreamWrapper::UseEndl(endl); \
vtkOStrStreamWrapper vtkmsg; \
const char *name = this->Algorithm->GetClassName(); \
if (!strcmp(name, "vtkTemporalDataSetCache") || \
!strcmp(name, "vtkContourFilter") || \
!strcmp(name, "vtkOpenDXStructuredGridReader") || \
!strcmp(name, "vtkPCellDataToPointData") || \
!strcmp(name, "vtkProcessIdScalars") || \
!strcmp(name, "vtkTemporalFractal") || \
!strcmp(name, "vtkTemporalSphereSource") || \
!strcmp(name, "vtkTemporalInterpolator") || \
!strcmp(name, "vtkTemporalStreamTracer")) \
{ \
vtkmsg << name << " : " a << endl; \
OUTPUTTEXT(vtkmsg.str()); \
vtkmsg.rdbuf()->freeze(0); \
} \
}
#endif
//----------------------------------------------------------------------------
/*
if (!strcmp(name, "vtkTemporalDataSetCache") || \
!strcmp(name, "vtkContourFilter")) \
!strcmp(name, "vtkOpenDXStructuredGridReader") || \
!strcmp(name, "vtkPCellDataToPointData") || \
!strcmp(name, "vtkProcessIdScalars") || \
!strcmp(name, "vtkTemporalFractal") || \
!strcmp(name, "vtkTemporalSphereSource") || \
!strcmp(name, "vtkTemporalInterpolator") || \
!strcmp(name, "vtkTemporalStreamTracer")) \
{ \
*/
vtkStandardNewMacro(vtkCompositeDataPipeline);
vtkInformationKeyMacro(vtkCompositeDataPipeline,REQUIRES_TIME_DOWNSTREAM, Integer);
vtkInformationKeyMacro(vtkCompositeDataPipeline, COMPOSITE_DATA_META_DATA, ObjectBase);
vtkInformationKeyMacro(vtkCompositeDataPipeline, UPDATE_COMPOSITE_INDICES, IntegerVector);
vtkInformationKeyMacro(vtkCompositeDataPipeline, COMPOSITE_INDICES, IntegerVector);
//----------------------------------------------------------------------------
vtkCompositeDataPipeline::vtkCompositeDataPipeline()
{
this->InLocalLoop = 0;
this->SuppressResetPipelineInformation = 0;
this->InformationCache = vtkInformation::New();
this->GenericRequest = vtkInformation::New();
this->DataObjectRequest = vtkInformation::New();
this->DataObjectRequest->Set(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT());
// The request is forwarded upstream through the pipeline.
this->DataObjectRequest->Set(
vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
// Algorithms process this request after it is forwarded.
this->DataObjectRequest->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);
this->InformationRequest = vtkInformation::New();
this->InformationRequest->Set(vtkDemandDrivenPipeline::REQUEST_INFORMATION());
// The request is forwarded upstream through the pipeline.
this->InformationRequest->Set(
vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
// Algorithms process this request after it is forwarded.
this->InformationRequest->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);
this->UpdateExtentRequest = vtkInformation::New();
this->UpdateExtentRequest->Set(
vtkStreamingDemandDrivenPipeline::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);
this->DataRequest = vtkInformation::New();
this->DataRequest->Set(REQUEST_DATA());
// The request is forwarded upstream through the pipeline.
this->DataRequest->Set(
vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
// Algorithms process this request after it is forwarded.
this->DataRequest->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);
}
//----------------------------------------------------------------------------
vtkCompositeDataPipeline::~vtkCompositeDataPipeline()
{
this->InformationCache->Delete();
this->GenericRequest->Delete();
this->DataObjectRequest->Delete();
this->InformationRequest->Delete();
this->UpdateExtentRequest->Delete();
this->DataRequest->Delete();
}
//----------------------------------------------------------------------------
int vtkCompositeDataPipeline::ForwardUpstream(vtkInformation* request)
{
vtkDebugMacro(<< "ForwardUpstream");
// Do not forward upstream if the input is shared with another
// executive.
if(this->SharedInputInformation)
{
return 1;
}
if (!this->Algorithm->ModifyRequest(request, BeforeForward))
{
return 0;
}
// Check if REQUIRES_TIME_DOWNSTREAM() key is in the output. If yes,
// pass it to inputs.
bool hasRTD = false;
int port = request->Get(FROM_OUTPUT_PORT());
if ( port < 0 )
{
for (int i=0; i<this->GetNumberOfOutputPorts(); i++)
{
if (this->GetOutputInformation(i) &&
this->GetOutputInformation(i)->Has(REQUIRES_TIME_DOWNSTREAM()))
{
hasRTD = true;
break;
}
}
}
else
{
if (this->GetOutputInformation(port) &&
this->GetOutputInformation(port)->Has(REQUIRES_TIME_DOWNSTREAM()))
{
hasRTD = true;
}
}
// Forward the request upstream through all input connections.
int result = 1;
for(int i=0; i < this->GetNumberOfInputPorts(); ++i)
{
int nic = this->Algorithm->GetNumberOfInputConnections(i);
vtkInformationVector* inVector = this->GetInputInformation()[i];
for(int j=0; j < nic; ++j)
{
vtkInformation* info = inVector->GetInformationObject(j);
// Get the executive producing this input. If there is none, then
// it is a NULL input.
vtkExecutive* e;
int producerPort;
vtkExecutive::PRODUCER()->Get(info, e, producerPort);
if(e)
{
request->Set(FROM_OUTPUT_PORT(), producerPort);
// if the input requires time them mark that
vtkInformation* ipi = this->Algorithm->GetInputPortInformation(i);
const char* rdt = ipi->Get(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
if ((rdt && !strcmp("vtkTemporalDataSet", rdt)) || hasRTD)
{
info->Set(REQUIRES_TIME_DOWNSTREAM(),1);
vtkDebugMacro(<< "Set REQUIRES_TIME_DOWNSTREAM");
}
if(!e->ProcessRequest(request,
e->GetInputInformation(),
e->GetOutputInformation()))
{
result = 0;
}
info->Remove(REQUIRES_TIME_DOWNSTREAM());
request->Set(FROM_OUTPUT_PORT(), port);
}
}
}
if (!this->Algorithm->ModifyRequest(request, AfterForward))
{
return 0;
}
return result;
}
//----------------------------------------------------------------------------
int vtkCompositeDataPipeline::ProcessRequest(vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
if(this->Algorithm && request->Has(REQUEST_DATA_OBJECT()))
{
vtkDebugMacro(<< "REQUEST_DATA_OBJECT()");
// if we are up to date then short circuit
if (this->PipelineMTime < this->DataObjectTime.GetMTime()
&& ! request->Has(REQUEST_REGENERATE_INFORMATION()))
{
return 1;
}
// request Update inputs first if they are out of date
if(!this->ForwardUpstream(request))
{
return 0;
}
// Make sure our output data type is up-to-date.
int result = 1;
if(this->PipelineMTime > this->DataObjectTime.GetMTime()
|| request->Has(REQUEST_REGENERATE_INFORMATION()))
{
// Request data type from the algorithm.
result = this->ExecuteDataObject(request,inInfoVec,outInfoVec);
// Make sure the data object exists for all output ports.
for(int i=0;
result && i < outInfoVec->GetNumberOfInformationObjects(); ++i)
{
vtkInformation* info = outInfoVec->GetInformationObject(i);
if(!info->Get(vtkDataObject::DATA_OBJECT()))
{
result = 0;
}
}
if(result)
{
// Data object is now up to date.
this->DataObjectTime.Modified();
}
}
return result;
}
if(this->Algorithm && request->Has(REQUEST_INFORMATION()))
{
vtkDebugMacro(<< "REQUEST_INFORMATION()");
return this->Superclass::ProcessRequest(request, inInfoVec,outInfoVec);
}
// Let the superclass handle other requests.
return this->Superclass::ProcessRequest(request, inInfoVec, outInfoVec);
}
//----------------------------------------------------------------------------
// Handle REQUEST_DATA_OBJECT
int vtkCompositeDataPipeline::ExecuteDataObject(
vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
vtkDebugMacro(<< "ExecuteDataObject");
int result=1;
// If the input is composite, allow algorithm to handle
// REQUEST_DATA_OBJECT only if it can handle composite
// datasets. Otherwise, the algorithm will get a chance to handle
// REQUEST_DATA_OBJECT when it is being iterated over.
int compositePort;
bool shouldIterate = this->ShouldIterateOverInput(compositePort) ||
this->ShouldIterateTemporalData(request, inInfoVec, outInfoVec);
if (!shouldIterate)
{
// Invoke the request on the algorithm.
result = this->CallAlgorithm(request, vtkExecutive::RequestDownstream,
inInfoVec, outInfoVec);
if (!result)
{
return result;
}
}
int i;
// Make sure a valid data object exists for all output ports.
for(i=0; result && i < this->Algorithm->GetNumberOfOutputPorts(); ++i)
{
vtkDebugMacro(<< "ExecuteDataObject calling CheckCompositeData");
result = this->CheckCompositeData(request, i, inInfoVec, outInfoVec);
}
return result;
}
//----------------------------------------------------------------------------
void vtkCompositeDataPipeline::ExecuteDataStart(
vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
// If the last iteration of ExecuteData had to iterate over time values, but
// the current does not, then we may need to replace the output.
bool hasIteratedTemporalData = false;
bool isIteratingTemporalData = false;
for (int i = 0; i < outInfoVec->GetNumberOfInformationObjects(); i++)
{
vtkInformation* info = outInfoVec->GetInformationObject(i);
if (info->Has(REQUIRES_TIME_DOWNSTREAM()))
{
isIteratingTemporalData = true;
}
vtkInformation* opi = this->Algorithm->GetOutputPortInformation(i);
const char* providedDataType = opi->Get(vtkDataObject::DATA_TYPE_NAME());
if (strcmp(providedDataType, "vtkTemporalDataSet") != 0 &&
info->Get(vtkDataObject::DATA_OBJECT())->IsA("vtkTemporalDataSet"))
{
hasIteratedTemporalData = true;
}
}
if (hasIteratedTemporalData && !isIteratingTemporalData)
{
this->SuppressResetPipelineInformation = 1;
this->ExecuteDataObject(this->DataObjectRequest, inInfoVec, outInfoVec);
this->SuppressResetPipelineInformation = 0;
}
this->Superclass::ExecuteDataStart(request, inInfoVec, outInfoVec);
}
//----------------------------------------------------------------------------
// Handle REQUEST_DATA
int vtkCompositeDataPipeline::ExecuteData(vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
vtkDebugMacro(<< "ExecuteData");
int result = 1;
int compositePort;
bool composite = this->ShouldIterateOverInput(compositePort);
bool temporal =
this->ShouldIterateTemporalData(request, inInfoVec, outInfoVec);
// This is stupid.
//compositePort = temporal ? -1 : compositePort;
if (temporal || composite)
{
this->ExecuteSimpleAlgorithm(request, inInfoVec, outInfoVec, compositePort);
}
else
{
vtkDebugMacro(<< " Superclass::ExecuteData");
result = this->Superclass::ExecuteData(request,inInfoVec,outInfoVec);
}
return result;
}
//----------------------------------------------------------------------------
int vtkCompositeDataPipeline::InputTypeIsValid(
int port, int index,vtkInformationVector **inInfoVec)
{
if (this->InLocalLoop)
{
return this->Superclass::InputTypeIsValid(port, index, inInfoVec);
}
if (!inInfoVec[port])
{
return 0;
}
// If we will be iterating over the input on this port, assume that we
// can handle any input type. The input type will be checked again during
// each step of the iteration.
int compositePort;
if (this->ShouldIterateOverInput(compositePort))
{
if (compositePort == port)
{
return 1;
}
}
// If the algorithm is requesting a vtkTemporalDataSet, then assume that the
// upstream pipeline will be run multiple times and a vtkTemporalDataSet will
// be created from the multiple results.
vtkInformation *info = this->Algorithm->GetInputPortInformation(port);
const char *requiredType
= info->Get(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
if (requiredType && (strcmp(requiredType, "vtkTemporalDataSet") == 0))
{
return 1;
}
// Otherwise, let superclass handle it.
return this->Superclass::InputTypeIsValid(port, index, inInfoVec);
}
//----------------------------------------------------------------------------
bool vtkCompositeDataPipeline::ShouldIterateOverInput(int& compositePort)
{
compositePort = -1;
// Find the first input that has a composite data that does not match
// the required input type. We assume that that port input has to
// be iterated over. We also require that this port has only one
// connection.
int numInputPorts = this->Algorithm->GetNumberOfInputPorts();
for(int i=0; i < numInputPorts; ++i)
{
int numInConnections = this->Algorithm->GetNumberOfInputConnections(i);
// If there is 1 connection
if (numInConnections == 1)
{
vtkInformation* inPortInfo =
this->Algorithm->GetInputPortInformation(i);
if (inPortInfo->Has(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE())
&& inPortInfo->Length(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE()) > 0)
{
const char* inputType = inPortInfo->Get(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), 0);
// the filter upstream will iterate
if (strcmp(inputType, "vtkTemporalDataSet") == 0)
{
vtkDebugMacro(<< "ShouldIterateOverInput returns 0 (Temporal)");
return false;
}
if (strcmp(inputType, "vtkCompositeDataSet") == 0 ||
strcmp(inputType, "vtkHierarchicalBoxDataSet") == 0 ||
strcmp(inputType, "vtkMultiBlockDataSet") == 0)
{
vtkDebugMacro(<< "ShouldIterateOverInput return 0 (Composite)");
return false;
}
vtkInformation* inInfo = this->GetInputInformation(i, 0);
vtkDataObject* input = inInfo->Get(vtkDataObject::DATA_OBJECT());
// If input does not match a required input type
bool foundMatch = false;
if(input)
{
int size = inPortInfo->Length(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
for(int j = 0; j < size; ++j)
{
if(input->IsA(inPortInfo->Get(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), j)))
{
foundMatch = true;
}
}
}
if (input && !foundMatch)
{
// If input is composite
if (vtkCompositeDataSet::SafeDownCast(input))
{
// Assume that we have to iterate over input
compositePort = i;
vtkDebugMacro(<< "ShouldIterateOverInput returns 1 (input composite)");
return true;
}
}
}
}
}
vtkDebugMacro(<< "ShouldIterateOverInput returns 0 (default)");
return false;
}
//----------------------------------------------------------------------------
bool vtkCompositeDataPipeline::ShouldIterateTemporalData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inInfoVec),
vtkInformationVector* outInfoVec)
{
// Exit fast if no outputs exist
if (!this->Algorithm->GetNumberOfOutputPorts())
{
vtkDebugMacro(<< "ShouldIterateTemporalData returns 0 (no outputs)");
return false;
}
// if the filter is a subclass of vtkTemporalDataSetAlgorithm
// we do not need to loop, because it will input and output temporal data
if (this->Algorithm->IsA("vtkTemporalDataSetAlgorithm"))
{
vtkDebugMacro(<< "ShouldIterateTemporalData returns 0 (vtkTemporalDataSetAlgorithm)");
return false;
}
// If the input to this is Temporal, the upstream will loop
// we do not have to.
int i, numInputPorts = this->Algorithm->GetNumberOfInputPorts();
for (i=0; i<numInputPorts; ++i)
{
vtkInformation* inPortInfo = this->Algorithm->GetInputPortInformation(i);
const char* inputType =
inPortInfo->Get(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
if (inputType && (strcmp(inputType, "vtkTemporalDataSet") == 0))
{
vtkDebugMacro(<< "ShouldIterateTemporalData returns 0 (vtkTemporalDataSet input)");
return false;
}
}
int numOut = outInfoVec->GetNumberOfInformationObjects();
for (int out = 0; out < numOut; out++)
{
if (outInfoVec->GetInformationObject(out)->Has(REQUIRES_TIME_DOWNSTREAM()))
{
// Time was requested so answer yes.
vtkDebugMacro(<< "ShouldIterateTemporalData returns 1 (REQUIRES_TIME_DOWNSTREAM)");
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
// Execute a simple (non-composite-aware) filter multiple times, once per
// block. Collect the result in a composite dataset that is of the same
// structure as the input.
void vtkCompositeDataPipeline::ExecuteSimpleAlgorithm(
vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec,
int compositePort)
{
vtkDebugMacro(<< "ExecuteSimpleAlgorithm");
this->ExecuteDataStart(request,inInfoVec,outInfoVec);
vtkInformation* outInfo = 0;
if (this->GetNumberOfOutputPorts() > 0)
{
outInfo = outInfoVec->GetInformationObject(0);
}
// Make sure a valid composite data object exists for all output ports.
for(int i=0; i < this->Algorithm->GetNumberOfOutputPorts(); ++i)
{
this->CheckCompositeData(request, i, inInfoVec, outInfoVec);
}
// if we have no composite inputs then we are looping over time on a source
if (compositePort==-1)
{
this->ExecuteSimpleAlgorithmTime(request, inInfoVec, outInfoVec);
return;
}
// Loop using the first input on the first port.
// This might not be valid for all cases but it is a decent
// assumption to start with.
// TODO: Loop over all inputs
vtkInformation* inInfo = 0;
inInfo = this->GetInputInformation(compositePort, 0);
vtkCompositeDataSet* input = vtkCompositeDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkSmartPointer<vtkCompositeDataSet> compositeOutput =
vtkCompositeDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// do we have a request for multiple time steps?
int numTimeSteps = 0;
double *times = 0;
numTimeSteps = outInfo->Length(UPDATE_TIME_STEPS());
if (numTimeSteps)
{
times = new double [numTimeSteps];
memcpy(times,outInfo->Get(UPDATE_TIME_STEPS()),
sizeof(double)*numTimeSteps);
}
if (input && compositeOutput)
{
compositeOutput->PrepareForNewData();
compositeOutput->CopyStructure(input);
vtkSmartPointer<vtkInformation> r =
vtkSmartPointer<vtkInformation>::New();
r->Set(FROM_OUTPUT_PORT(), PRODUCER()->GetPort(outInfo));
// The request is forwarded upstream through the pipeline.
r->Set(vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
// Algorithms process this request after it is forwarded.
r->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);
// Store the information (whole_extent and maximum_number_of_pieces)
// before looping. Otherwise, executeinformation will cause
// changes (because we pretend that the max. number of pieces is
// one to process the whole block)
this->PushInformation(inInfo);
vtkDebugMacro(<< "EXECUTING " << this->Algorithm->GetClassName());;
// True when the pipeline is iterating over the current (simple)
// filter to produce composite output. In this case,
// ExecuteDataStart() should NOT Initialize() the composite output.
this->InLocalLoop = 1;
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(input->NewIterator());
iter->VisitOnlyLeavesOn();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal();
iter->GoToNextItem())
{
// if it is a temporal input, set the time for each piece
if (times)
{
outInfo->Set(UPDATE_TIME_STEPS(), times, numTimeSteps);
}
vtkDataObject* dobj = iter->GetCurrentDataObject();
if (dobj)
{
// Note that since VisitOnlyLeaves is ON on the iterator,
// this method is called only for leaves, hence, we are assured that
// neither dobj nor outObj are vtkCompositeDataSet subclasses.
vtkDataObject* outObj =
this->ExecuteSimpleAlgorithmForBlock(inInfoVec,
outInfoVec,
inInfo,
outInfo,
r,
dobj);
if (outObj)
{
compositeOutput->SetDataSet(iter, outObj);
outObj->FastDelete();
}
}
}
// True when the pipeline is iterating over the current (simple)
// filter to produce composite output. In this case,
// ExecuteDataStart() should NOT Initialize() the composite output.
this->InLocalLoop = 0;
// Restore the extent information and force it to be
// copied to the output. Composite sources should set
// MAXIMUM_NUMBER_OF_PIECES to -1 anyway (and handle
// piece requests properly).
this->PopInformation(inInfo);
if (times)
{
outInfo->Set(UPDATE_TIME_STEPS(), times, numTimeSteps);
compositeOutput->GetInformation()->Set(
vtkDataObject::DATA_TIME_STEPS(), times, numTimeSteps);
delete [] times;
}
r->Set(REQUEST_INFORMATION());
this->CopyDefaultInformation(r, vtkExecutive::RequestDownstream,
this->GetInputInformation(),
this->GetOutputInformation());
vtkDataObject* curInput = inInfo->Get(vtkDataObject::DATA_OBJECT());
if (curInput != input)
{
inInfo->Remove(vtkDataObject::DATA_OBJECT());
inInfo->Set(vtkDataObject::DATA_OBJECT(), input);
}
vtkDataObject* curOutput = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (curOutput != compositeOutput.GetPointer())
{
compositeOutput->SetPipelineInformation(outInfo);
}
}
this->ExecuteDataEnd(request,inInfoVec,outInfoVec);
}
//----------------------------------------------------------------------------
vtkDataObject* vtkCompositeDataPipeline::ExecuteSimpleAlgorithmForBlock(
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec,
vtkInformation* inInfo,
vtkInformation* outInfo,
vtkInformation* request,
vtkDataObject* dobj)
{
vtkDebugMacro(<< "ExecuteSimpleAlgorithmForBlock");
if (dobj && dobj->IsA("vtkCompositeDataSet"))
{
vtkErrorMacro("ExecuteSimpleAlgorithmForBlock cannot be called "
"for a vtkCompositeDataSet");
return 0;
}
double time = 0;
int hasTime = outInfo->Length(UPDATE_TIME_STEPS());
if (hasTime)
{
time = outInfo->Get(UPDATE_TIME_STEPS())[0];
}
// There must be a bug somehwere. If this Remove()
// is not called, the following Set() has the effect
// of removing (!) the key.
if (inInfo)
{
inInfo->Remove(vtkDataObject::DATA_OBJECT());
inInfo->Set(vtkDataObject::DATA_OBJECT(), dobj);
// Process the whole dataset
this->CopyFromDataToInformation(dobj, inInfo);
}
request->Set(REQUEST_DATA_OBJECT());
this->SuppressResetPipelineInformation = 1;
this->Superclass::ExecuteDataObject(
request, this->GetInputInformation(),this->GetOutputInformation());
this->SuppressResetPipelineInformation = 0;
request->Remove(REQUEST_DATA_OBJECT());
request->Set(REQUEST_INFORMATION());
// Make sure that pipeline informations is in sync with the data
if (dobj)
{
dobj->CopyInformationToPipeline(request, 0, inInfo, 1);
// This should not be needed but since a lot of image filters do:
// img->GetScalarType(), it is necessary.
dobj->GetProducerPort(); // make sure there is pipeline info.
dobj->CopyInformationToPipeline
(request, 0, dobj->GetPipelineInformation(), 1);
}
this->Superclass::ExecuteInformation(request,inInfoVec,outInfoVec);
request->Remove(REQUEST_INFORMATION());
int storedPiece = -1;
int storedNumPieces = -1;
for(int m=0; m < this->Algorithm->GetNumberOfOutputPorts(); ++m)
{
vtkInformation* info = this->GetOutputInformation(m);
// Update the whole thing
if (info->Has(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()))
{
int extent[6] = {0,-1,0,-1,0,-1};
info->Get(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
extent);
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
extent,
6);
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT_INITIALIZED(),
1);
storedPiece =
info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
storedNumPieces=
info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
1);
vtkDebugMacro(<< "UPDATE_PIECE_NUMBER() 0" << " " << info);
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(), 0);
}
}
// if there was a time make sure that gets set in the RUE
if (hasTime)
{
outInfo->Set(UPDATE_TIME_STEPS(),&time,1);
}
request->Set(REQUEST_UPDATE_EXTENT());
this->CallAlgorithm(request, vtkExecutive::RequestUpstream,
inInfoVec, outInfoVec);
request->Remove(REQUEST_UPDATE_EXTENT());
request->Set(REQUEST_DATA());
this->Superclass::ExecuteData(request,inInfoVec,outInfoVec);
request->Remove(REQUEST_DATA());
for(int m=0; m < this->Algorithm->GetNumberOfOutputPorts(); ++m)
{
vtkInformation* info = this->GetOutputInformation(m);
if (storedPiece!=-1)
{
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
storedNumPieces);
vtkDebugMacro(<< "UPDATE_PIECE_NUMBER() 0" << " " << info);
info->Set(
vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
storedPiece);
}
}
vtkDataObject* output = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (!output)
{
return 0;
}
vtkDataObject* outputCopy = output->NewInstance();
outputCopy->ShallowCopy(output);
return outputCopy;
}
//----------------------------------------------------------------------------
// Execute a simple (non-composite-aware) filter multiple times, once per
// block. Collect the result in a composite dataset that is of the same
// structure as the input.
// Note that if this method is called we are assured that the input is not
// composite.
void vtkCompositeDataPipeline::ExecuteSimpleAlgorithmTime(
vtkInformation* request,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
vtkDebugMacro(<< "ExecuteSimpleAlgorithmTime");
vtkInformation* outInfo = 0;
vtkSmartPointer<vtkInformation> originalInformation =
vtkSmartPointer<vtkInformation>::New();
if (this->GetNumberOfOutputPorts() > 0)
{
outInfo = outInfoVec->GetInformationObject(0);
originalInformation->CopyEntry(outInfo,TIME_STEPS(), 0);
originalInformation->CopyEntry(outInfo,TIME_RANGE(), 0);
}
vtkSmartPointer<vtkTemporalDataSet> temporalOutput =
vtkTemporalDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// do we have a request for multiple time steps?
int numTimeSteps = 0;
double *times = 0;
numTimeSteps = outInfo->Length(UPDATE_TIME_STEPS());
times = new double [numTimeSteps];
memcpy(times,
outInfo->Get(UPDATE_TIME_STEPS()),
sizeof(double)*numTimeSteps);
int outputInitialized = 0;
vtkSmartPointer<vtkInformation> r =
vtkSmartPointer<vtkInformation>::New();
r->Set(FROM_OUTPUT_PORT(), request->Get(FROM_OUTPUT_PORT()));
// The request is forwarded upstream through the pipeline.
r->Set(vtkExecutive::FORWARD_DIRECTION(), vtkExecutive::RequestUpstream);
// Algorithms process this request after it is forwarded.
r->Set(vtkExecutive::ALGORITHM_AFTER_FORWARD(), 1);
vtkDebugMacro(<<"EXECUTING: " << this->Algorithm->GetClassName());
// Store the information (whole_extent and maximum_number_of_pieces)
// before looping. Otherwise, executeinformation will cause
// changes (because we pretend that the max. number of pieces is
// one to process the whole block)
// vtkInformation* inInfo = this->GetInputInformation(compositePort, 0);
// this->PushInformation(inInfo);
// True when the pipeline is iterating over the current (simple)
// filter to produce composite output. In this case,
// ExecuteDataStart() should NOT Initialize() the composite output.
this->InLocalLoop = 1;
for (unsigned int k=0; k< static_cast<unsigned int>(numTimeSteps); k++)
{
// if it is a temporal input, set the time for each piece
outInfo->Set(UPDATE_TIME_STEPS(), times+k, 1);
vtkDataObject* dobj = 0;
vtkDataObject* outCopy =
this->ExecuteSimpleAlgorithmForBlock(inInfoVec, outInfoVec,
0, outInfo,
r,
dobj);
if (outCopy)
{
vtkDebugMacro(<<"Got Data from Block");
if (!outputInitialized)
{
temporalOutput->PrepareForNewData();
outputInitialized = 1;
}
temporalOutput->SetTimeStep(k, outCopy);
outCopy->FastDelete();
}
}
// True when the pipeline is iterating over the current (simple)
// filter to produce composite output. In this case,
// ExecuteDataStart() should NOT Initialize() the composite output.
this->InLocalLoop = 0;
// Restore the extent information and force it to be
// copied to the output. Composite sources should set
// MAXIMUM_NUMBER_OF_PIECES to -1 anyway (and handle
// piece requests properly).
// this->PopInformation(inInfo);
outInfo->Set(UPDATE_TIME_STEPS(), times, numTimeSteps);
temporalOutput->GetInformation()->Set(
vtkDataObject::DATA_TIME_STEPS(), times, numTimeSteps);
delete [] times;
r->Set(REQUEST_INFORMATION());
this->CopyDefaultInformation(r,
vtkExecutive::RequestDownstream,
this->GetInputInformation(),
this->GetOutputInformation());
outInfo->CopyEntry(originalInformation, TIME_STEPS(), 0);
outInfo->CopyEntry(originalInformation, TIME_RANGE(), 0);
vtkDataObject* curOutput = outInfo->Get(vtkDataObject::DATA_OBJECT());
if (curOutput != temporalOutput.GetPointer())
{
temporalOutput->SetPipelineInformation(outInfo);
}
this->ExecuteDataEnd(request,inInfoVec,outInfoVec);
}
//----------------------------------------------------------------------------
int vtkCompositeDataPipeline::NeedToExecuteData(
int outputPort,
vtkInformationVector** inInfoVec,
vtkInformationVector* outInfoVec)
{
// Has the algorithm asked to be executed again?
if(this->ContinueExecuting)
{
return 1;
}
// If no port is specified, check all ports. This behavior is
// implemented by the superclass.
if(outputPort < 0)
{
return this->Superclass::NeedToExecuteData(outputPort,
inInfoVec,outInfoVec);
}
// Does the superclass want to execute?
if(this->vtkDemandDrivenPipeline::NeedToExecuteData(
outputPort,inInfoVec,outInfoVec))
{
return 1;
}
// We need to check the requested update extent. Get the output
// port information and data information. We do not need to check
// existence of values because it has already been verified by
// VerifyOutputInformation.
vtkInformation* outInfo = outInfoVec->GetInformationObject(outputPort);
vtkDataObject* dataObject = outInfo->Get(vtkDataObject::DATA_OBJECT());