1010#include < vtkStreamingDemandDrivenPipeline.h>
1111
1212#include < algorithm>
13- #include < cmath>
1413
1514vtkStandardNewMacro (vtkF3DMemoryMesh);
1615
@@ -41,40 +40,37 @@ vtkSmartPointer<vtkFloatArray> ConvertToFloatArray(const std::vector<float>& pos
4140// ------------------------------------------------------------------------------
4241vtkF3DMemoryMesh::vtkF3DMemoryMesh ()
4342{
44- Meshes = std::vector<vtkNew<vtkPolyData>>(1 );
4543 this ->SetNumberOfInputPorts (0 );
46- this ->timeRange = { 0.0 , 0.0 };
47- this ->timeStep = 1.0 ;
4844}
4945
5046// ------------------------------------------------------------------------------
5147vtkF3DMemoryMesh::~vtkF3DMemoryMesh () = default ;
5248
5349// ------------------------------------------------------------------------------
54- void vtkF3DMemoryMesh::SetPoints (const std::vector<float >& positions, size_t timeIdx )
50+ void vtkF3DMemoryMesh::SetPoints (const std::vector<float >& positions, const double timeStep )
5551{
5652 vtkNew<vtkPoints> points;
5753 points->SetDataTypeToFloat ();
5854 points->SetData (ConvertToFloatArray<3 >(positions));
5955
60- this ->Meshes [timeIdx ]->SetPoints (points);
56+ this ->Meshes [timeStep ]->SetPoints (points);
6157}
6258
6359// ------------------------------------------------------------------------------
64- void vtkF3DMemoryMesh::SetNormals (const std::vector<float >& normals, size_t timeIdx )
60+ void vtkF3DMemoryMesh::SetNormals (const std::vector<float >& normals, const double timeStamp )
6561{
66- this ->Meshes [timeIdx ]->GetPointData ()->SetNormals (ConvertToFloatArray<3 >(normals));
62+ this ->Meshes [timeStamp ]->GetPointData ()->SetNormals (ConvertToFloatArray<3 >(normals));
6763}
6864
6965// ------------------------------------------------------------------------------
70- void vtkF3DMemoryMesh::SetTCoords (const std::vector<float >& tcoords, size_t timeIdx )
66+ void vtkF3DMemoryMesh::SetTCoords (const std::vector<float >& tcoords, const double timeStamp )
7167{
72- this ->Meshes [timeIdx ]->GetPointData ()->SetTCoords (ConvertToFloatArray<2 >(tcoords));
68+ this ->Meshes [timeStamp ]->GetPointData ()->SetTCoords (ConvertToFloatArray<2 >(tcoords));
7369}
7470
7571// ------------------------------------------------------------------------------
7672void vtkF3DMemoryMesh::SetFaces (const std::vector<unsigned int >& faceSizes,
77- const std::vector<unsigned int >& faceIndices, size_t timeIdx )
73+ const std::vector<unsigned int >& faceIndices, const double timeStamp )
7874{
7975 vtkNew<vtkIdTypeArray> offsets;
8076 vtkNew<vtkIdTypeArray> connectivity;
@@ -102,44 +98,18 @@ void vtkF3DMemoryMesh::SetFaces(const std::vector<unsigned int>& faceSizes,
10298 vtkNew<vtkCellArray> polys;
10399 polys->SetData (offsets, connectivity);
104100
105- this ->Meshes [timeIdx]->SetPolys (polys);
106- }
107-
108- // ------------------------------------------------------------------------------
109- void vtkF3DMemoryMesh::SetTimeRange (std::pair<double , double > newTimeRange)
110- {
111- timeRange = newTimeRange;
112- }
113-
114- // ------------------------------------------------------------------------------
115- void vtkF3DMemoryMesh::SetTimeStep (double newTimeStep)
116- {
117- timeStep = newTimeStep;
118- }
119-
120- // ------------------------------------------------------------------------------
121- size_t vtkF3DMemoryMesh::GetTemporalStateCount ()
122- {
123- return Meshes.size ();
124- }
125-
126- // ------------------------------------------------------------------------------
127- void vtkF3DMemoryMesh::ReserveTemporalEntries (size_t newSize)
128- {
129- Meshes.resize (newSize);
101+ this ->Meshes [timeStamp]->SetPolys (polys);
130102}
131103
132104// ------------------------------------------------------------------------------
133105int vtkF3DMemoryMesh::RequestInformation (vtkInformation* vtkNotUsed (request),
134106 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
135107{
136- vtkInformation* outInfo = outputVector->GetInformationObject (0 );
108+ // timeRange = {map_min, map_max}, map_min always <= map_max
109+ auto timeRange = std::array<double , 2 >{ Meshes.begin ()->first , Meshes.rbegin ()->first };
137110
138- if (timeRange.first < timeRange.second )
139- {
140- std::array<double , 2 > arr = { timeRange.first , timeRange.second };
141- outInfo->Set (vtkStreamingDemandDrivenPipeline::TIME_RANGE (), arr.data (), 2 );
142- }
111+ vtkInformation* outInfo = outputVector->GetInformationObject (0 );
112+ outInfo->Set (vtkStreamingDemandDrivenPipeline::TIME_RANGE (), timeRange.data (), 2 );
143113
144114 return 1 ;
145115}
@@ -152,21 +122,21 @@ int vtkF3DMemoryMesh::RequestData(vtkInformation* vtkNotUsed(request),
152122 vtkPolyData* output = vtkPolyData::GetData (outInfo);
153123
154124 double requestedTimeValue = 0.0 ;
155- size_t timeIdx = 0 ;
156125
157- if (outInfo->Has (vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ()) && this ->timeStep > 0.0 &&
158- !this ->Meshes .empty ())
126+ if (outInfo->Has (vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ()) && !this ->Meshes .empty ())
159127 {
160128 requestedTimeValue = outInfo->Get (vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ());
161- const double clampedTime =
162- std::clamp (requestedTimeValue, this ->timeRange .first , this ->timeRange .second );
163- const double relative = (clampedTime - this ->timeRange .first ) / this ->timeStep ;
164- const double boundedRelative =
165- std::clamp (relative, 0.0 , static_cast <double >(std::max<size_t >(this ->Meshes .size (), 1 ) - 1 ));
166- timeIdx = static_cast <size_t >(std::llround (boundedRelative));
129+ auto iter = Meshes.upper_bound (requestedTimeValue);
130+ if (iter != Meshes.begin ())
131+ {
132+ iter = std::prev (iter);
133+ }
134+ output->ShallowCopy (iter->second );
135+ }
136+ else
137+ {
138+ output->ShallowCopy (this ->Meshes [0.0 ]);
167139 }
168-
169- output->ShallowCopy (this ->Meshes [timeIdx]);
170140
171141 return 1 ;
172142}
0 commit comments