17 #include "vtkDataObject.h"
18 #include "vtkInformation.h"
19 #include "vtkInformationVector.h"
20 #include "vtkObjectFactory.h"
21 #include "vtkStreamingDemandDrivenPipeline.h"
26 struct vtkPVTrivialProducerInternal
28 std::vector<double> TimeSteps;
29 double FindNearestTime(
double time)
const
33 double nearest_time = time;
34 double delta = VTK_DOUBLE_MAX;
35 for (
const auto& t : this->TimeSteps)
37 const auto tdelta = std::abs(t - time);
52 this->Internals =
new vtkPVTrivialProducerInternal;
60 delete this->Internals;
61 this->Internals =
nullptr;
68 this->Superclass::SetOutput(output);
74 if (this->Internals->TimeSteps.empty() ==
false && time <= this->Internals->TimeSteps.back())
76 vtkWarningMacro(
"New time step is not after last time step.");
78 this->Internals->TimeSteps.push_back(time);
86 vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
88 if (!this->Superclass::ProcessRequest(request, inputVector, outputVector))
93 const auto& internals = (*this->Internals);
95 vtkInformation* outputInfo = outputVector->GetInformationObject(0);
96 if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
98 auto dobj = vtkDataObject::GetData(outputVector, 0);
99 if (!internals.TimeSteps.empty() && dobj !=
nullptr)
101 double uTime = outputInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
102 ? outputInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
103 : internals.TimeSteps.back();
108 if (internals.FindNearestTime(uTime) != internals.TimeSteps.back())
115 dobj->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), internals.TimeSteps.back());
118 else if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
120 if (!internals.TimeSteps.empty())
122 outputInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &internals.TimeSteps[0],
123 static_cast<int>(internals.TimeSteps.size()));
124 double timeRange[2] = { this->Internals->TimeSteps.front(),
125 this->Internals->TimeSteps.back() };
126 outputInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
135 this->Superclass::PrintSelf(os, indent);
void PrintSelf(ostream &os, vtkIndent indent) override
int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
~vtkPVTrivialProducer() override
void SetOutput(vtkDataObject *output) override
vtkStandardNewMacro(vtkPVTrivialProducer)