|
1 | 1 | #include "vtkF3DMemoryMesh.h" |
2 | 2 |
|
3 | | -#include "vtkDataArrayRange.h" |
4 | 3 | #include "vtkFloatArray.h" |
5 | 4 | #include "vtkIdTypeArray.h" |
6 | 5 | #include "vtkInformationVector.h" |
7 | 6 | #include "vtkObjectFactory.h" |
8 | 7 | #include "vtkPointData.h" |
9 | 8 | #include "vtkSMPTools.h" |
10 | | - |
11 | | -#include <numeric> |
| 9 | +#include <vtkInformation.h> |
| 10 | +#include <vtkStreamingDemandDrivenPipeline.h> |
12 | 11 |
|
13 | 12 | vtkStandardNewMacro(vtkF3DMemoryMesh); |
14 | 13 |
|
@@ -46,30 +45,30 @@ vtkF3DMemoryMesh::vtkF3DMemoryMesh() |
46 | 45 | vtkF3DMemoryMesh::~vtkF3DMemoryMesh() = default; |
47 | 46 |
|
48 | 47 | //------------------------------------------------------------------------------ |
49 | | -void vtkF3DMemoryMesh::SetPoints(const std::vector<float>& positions) |
| 48 | +void vtkF3DMemoryMesh::SetPoints(const std::vector<float>& positions, const double timeStamp) |
50 | 49 | { |
51 | 50 | vtkNew<vtkPoints> points; |
52 | 51 | points->SetDataTypeToFloat(); |
53 | 52 | points->SetData(ConvertToFloatArray<3>(positions)); |
54 | 53 |
|
55 | | - this->Mesh->SetPoints(points); |
| 54 | + this->Meshes[timeStamp]->SetPoints(points); |
56 | 55 | } |
57 | 56 |
|
58 | 57 | //------------------------------------------------------------------------------ |
59 | | -void vtkF3DMemoryMesh::SetNormals(const std::vector<float>& normals) |
| 58 | +void vtkF3DMemoryMesh::SetNormals(const std::vector<float>& normals, const double timeStamp) |
60 | 59 | { |
61 | | - this->Mesh->GetPointData()->SetNormals(ConvertToFloatArray<3>(normals)); |
| 60 | + this->Meshes[timeStamp]->GetPointData()->SetNormals(ConvertToFloatArray<3>(normals)); |
62 | 61 | } |
63 | 62 |
|
64 | 63 | //------------------------------------------------------------------------------ |
65 | | -void vtkF3DMemoryMesh::SetTCoords(const std::vector<float>& tcoords) |
| 64 | +void vtkF3DMemoryMesh::SetTCoords(const std::vector<float>& tcoords, const double timeStamp) |
66 | 65 | { |
67 | | - this->Mesh->GetPointData()->SetTCoords(ConvertToFloatArray<2>(tcoords)); |
| 66 | + this->Meshes[timeStamp]->GetPointData()->SetTCoords(ConvertToFloatArray<2>(tcoords)); |
68 | 67 | } |
69 | 68 |
|
70 | 69 | //------------------------------------------------------------------------------ |
71 | | -void vtkF3DMemoryMesh::SetFaces( |
72 | | - const std::vector<unsigned int>& faceSizes, const std::vector<unsigned int>& faceIndices) |
| 70 | +void vtkF3DMemoryMesh::SetFaces(const std::vector<unsigned int>& faceSizes, |
| 71 | + const std::vector<unsigned int>& faceIndices, const double timeStamp) |
73 | 72 | { |
74 | 73 | vtkNew<vtkIdTypeArray> offsets; |
75 | 74 | vtkNew<vtkIdTypeArray> connectivity; |
@@ -97,16 +96,44 @@ void vtkF3DMemoryMesh::SetFaces( |
97 | 96 | vtkNew<vtkCellArray> polys; |
98 | 97 | polys->SetData(offsets, connectivity); |
99 | 98 |
|
100 | | - this->Mesh->SetPolys(polys); |
| 99 | + this->Meshes[timeStamp]->SetPolys(polys); |
| 100 | +} |
| 101 | + |
| 102 | +//------------------------------------------------------------------------------ |
| 103 | +int vtkF3DMemoryMesh::RequestInformation(vtkInformation* vtkNotUsed(request), |
| 104 | + vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector) |
| 105 | +{ |
| 106 | + // timeRange = {map_min, map_max}, map_min always <= map_max |
| 107 | + const auto timeRange = std::array<double, 2>{ Meshes.begin()->first, Meshes.rbegin()->first }; |
| 108 | + |
| 109 | + vtkInformation* outInfo = outputVector->GetInformationObject(0); |
| 110 | + outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange.data(), 2); |
| 111 | + |
| 112 | + return 1; |
101 | 113 | } |
102 | 114 |
|
103 | 115 | //------------------------------------------------------------------------------ |
104 | 116 | int vtkF3DMemoryMesh::RequestData(vtkInformation* vtkNotUsed(request), |
105 | 117 | vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector) |
106 | 118 | { |
107 | | - vtkPolyData* output = vtkPolyData::GetData(outputVector->GetInformationObject(0)); |
| 119 | + vtkInformation* outInfo = outputVector->GetInformationObject(0); |
| 120 | + vtkPolyData* output = vtkPolyData::GetData(outInfo); |
108 | 121 |
|
109 | | - output->ShallowCopy(this->Mesh); |
| 122 | + if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()) && !this->Meshes.empty()) |
| 123 | + { |
| 124 | + const double requestedTimeValue = |
| 125 | + outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()); |
| 126 | + auto iter = Meshes.upper_bound(requestedTimeValue); |
| 127 | + if (iter != Meshes.begin()) |
| 128 | + { |
| 129 | + iter = std::prev(iter); |
| 130 | + } |
| 131 | + output->ShallowCopy(iter->second); |
| 132 | + } |
| 133 | + else |
| 134 | + { |
| 135 | + output->ShallowCopy(this->Meshes[0.0]); |
| 136 | + } |
110 | 137 |
|
111 | 138 | return 1; |
112 | 139 | } |
0 commit comments