ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkPVTrivialProducer.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: $RCSfile: vtkPVTrivialProducer.cxx,v $
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 #include "vtkPVTrivialProducer.h"
16 
17 #include "vtkDataObject.h"
18 #include "vtkInformation.h"
19 #include "vtkInformationVector.h"
20 #include "vtkObjectFactory.h"
21 #include "vtkStreamingDemandDrivenPipeline.h"
22 
23 #include <cmath>
24 #include <vector>
25 
26 struct vtkPVTrivialProducerInternal
27 {
28  std::vector<double> TimeSteps;
29  double FindNearestTime(double time) const
30  {
31  // we can't assume TimeSteps is sorted (see logic in SetOutput(.., time)),
32  // although in most cases it is.
33  double nearest_time = time;
34  double delta = VTK_DOUBLE_MAX;
35  for (const auto& t : this->TimeSteps)
36  {
37  const auto tdelta = std::abs(t - time);
38  if (tdelta < delta)
39  {
40  delta = tdelta;
41  nearest_time = t;
42  }
43  }
44  return nearest_time;
45  }
46 };
47 
49 //----------------------------------------------------------------------------
51 {
52  this->Internals = new vtkPVTrivialProducerInternal;
53 }
54 
55 //----------------------------------------------------------------------------
57 {
58  if (this->Internals)
59  {
60  delete this->Internals;
61  this->Internals = nullptr;
62  }
63 }
64 
65 //----------------------------------------------------------------------------
66 void vtkPVTrivialProducer::SetOutput(vtkDataObject* output)
67 {
68  this->Superclass::SetOutput(output);
69 }
70 
71 //----------------------------------------------------------------------------
72 void vtkPVTrivialProducer::SetOutput(vtkDataObject* output, double time)
73 {
74  if (this->Internals->TimeSteps.empty() == false && time <= this->Internals->TimeSteps.back())
75  {
76  vtkWarningMacro("New time step is not after last time step.");
77  }
78  this->Internals->TimeSteps.push_back(time);
79 
80  this->Modified();
81  this->SetOutput(output);
82 }
83 
84 //----------------------------------------------------------------------------
86  vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
87 {
88  if (!this->Superclass::ProcessRequest(request, inputVector, outputVector))
89  {
90  return 0;
91  }
92 
93  const auto& internals = (*this->Internals);
94 
95  vtkInformation* outputInfo = outputVector->GetInformationObject(0);
96  if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA()))
97  {
98  auto dobj = vtkDataObject::GetData(outputVector, 0);
99  if (!internals.TimeSteps.empty() && dobj != nullptr)
100  {
101  double uTime = outputInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
102  ? outputInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
103  : internals.TimeSteps.back();
104 
105  // we really don't produce any other timestep besides the last one. Let's
106  // check, however, if someone requested another timestep what we can
107  // satisfy. In that case, let's report a warning.
108  if (internals.FindNearestTime(uTime) != internals.TimeSteps.back())
109  {
110  //vtkWarningMacro("Cannot produce requested time '" << convert(uTime) << "', only '"
111  // << convert(internals.TimeSteps.back())
112  // << "' is available.");
113  }
114 
115  dobj->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), internals.TimeSteps.back());
116  }
117  }
118  else if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION()))
119  {
120  if (!internals.TimeSteps.empty())
121  {
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);
127  }
128  }
129  return 1;
130 }
131 
132 //----------------------------------------------------------------------------
133 void vtkPVTrivialProducer::PrintSelf(ostream& os, vtkIndent indent)
134 {
135  this->Superclass::PrintSelf(os, indent);
136 }
void PrintSelf(ostream &os, vtkIndent indent) override
int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void SetOutput(vtkDataObject *output) override
vtkStandardNewMacro(vtkPVTrivialProducer)