forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTemporalSnapToTimeStep.cxx
191 lines (164 loc) · 6.34 KB
/
vtkTemporalSnapToTimeStep.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTemporalSnapToTimeStep.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 "vtkTemporalSnapToTimeStep.h"
#include "vtkDataObject.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include <cmath>
vtkStandardNewMacro(vtkTemporalSnapToTimeStep);
//------------------------------------------------------------------------------
vtkTemporalSnapToTimeStep::vtkTemporalSnapToTimeStep()
{
this->HasDiscrete = 0;
this->SnapMode = 0;
}
//------------------------------------------------------------------------------
vtkTemporalSnapToTimeStep::~vtkTemporalSnapToTimeStep() = default;
//------------------------------------------------------------------------------
vtkTypeBool vtkTemporalSnapToTimeStep::ProcessRequest(
vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
// modify the time in either of these passes
if (request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_TIME()) ||
request->Has(vtkStreamingDemandDrivenPipeline::REQUEST_UPDATE_EXTENT()))
{
return this->RequestUpdateExtent(request, inputVector, outputVector);
}
return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}
//------------------------------------------------------------------------------
// Change the information
int vtkTemporalSnapToTimeStep::RequestInformation(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
// get the info objects
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
this->HasDiscrete = 0;
// unset the time steps if they are set
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
{
outInfo->Remove(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
}
if (inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_STEPS()))
{
int numTimes = inInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
this->InputTimeValues.resize(numTimes);
inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &this->InputTimeValues[0]);
this->HasDiscrete = 1;
}
if (inInfo->Has(vtkStreamingDemandDrivenPipeline::TIME_RANGE()))
{
double* inRange = inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_RANGE());
double outRange[2];
outRange[0] = inRange[0];
outRange[1] = inRange[1];
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), outRange, 2);
}
return 1;
}
//------------------------------------------------------------------------------
// This method simply copies by reference the input data to the output.
int vtkTemporalSnapToTimeStep::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkDataObject* inData = inInfo->Get(vtkDataObject::DATA_OBJECT());
vtkDataObject* outData = outInfo->Get(vtkDataObject::DATA_OBJECT());
// shallow copy the data
if (inData && outData)
{
outData->ShallowCopy(inData);
// fill in the time steps
double inTime = inData->GetInformation()->Get(vtkDataObject::DATA_TIME_STEP());
if (inData->GetInformation()->Has(vtkDataObject::DATA_TIME_STEP()))
{
double outTime = inTime;
outData->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), outTime);
}
}
return 1;
}
//------------------------------------------------------------------------------
int vtkTemporalSnapToTimeStep::RequestUpdateExtent(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputVector, vtkInformationVector* outputVector)
{
// get the info objects
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
// find the nearest timestep in the input
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
double upTime = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
double* inTimes = new double[1];
if (!this->HasDiscrete || this->InputTimeValues.empty())
{
inTimes[0] = upTime;
}
else
{
double dist = VTK_DOUBLE_MAX;
int index = -1;
for (unsigned int t = 0; t < this->InputTimeValues.size(); t++)
{
double thisdist = fabs(upTime - this->InputTimeValues[t]);
if (this->SnapMode == VTK_SNAP_NEAREST && thisdist < dist)
{
index = t;
dist = thisdist;
}
else if (this->SnapMode == VTK_SNAP_NEXTBELOW_OR_EQUAL)
{
if (this->InputTimeValues[t] == upTime)
{
index = t;
break;
}
else if (this->InputTimeValues[t] < upTime)
{
index = t;
}
else if (this->InputTimeValues[t] > upTime)
{
break;
}
}
else if (this->SnapMode == VTK_SNAP_NEXTABOVE_OR_EQUAL)
{
if (this->InputTimeValues[t] == upTime)
{
index = t;
break;
}
else if (this->InputTimeValues[t] > upTime)
{
index = t;
break;
}
}
}
upTime = this->InputTimeValues[index == -1 ? 0 : index];
}
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP(), upTime);
delete[] inTimes;
}
return 1;
}
//------------------------------------------------------------------------------
void vtkTemporalSnapToTimeStep::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "SnapMode: " << this->SnapMode << endl;
}
//------------------------------------------------------------------------------