11#include " vtkF3DMemoryMesh.h"
22
3+ #include " vtkCellArray.h"
34#include " vtkFloatArray.h"
45#include " vtkIdTypeArray.h"
6+ #include " vtkInformation.h"
57#include " vtkInformationVector.h"
68#include " vtkObjectFactory.h"
79#include " vtkPointData.h"
10+ #include " vtkPoints.h"
11+ #include " vtkPolyData.h"
812#include " vtkSMPTools.h"
9- #include < vtkInformation.h>
10- #include < vtkStreamingDemandDrivenPipeline.h>
13+ #include " vtkStreamingDemandDrivenPipeline.h"
1114
1215vtkStandardNewMacro (vtkF3DMemoryMesh);
1316
@@ -45,30 +48,38 @@ vtkF3DMemoryMesh::vtkF3DMemoryMesh()
4548vtkF3DMemoryMesh::~vtkF3DMemoryMesh () = default ;
4649
4750// ------------------------------------------------------------------------------
48- void vtkF3DMemoryMesh::SetPoints (const std::vector<float >& positions, const double timeStamp )
51+ void vtkF3DMemoryMesh::SetPoints (const std::vector<float >& positions)
4952{
5053 vtkNew<vtkPoints> points;
5154 points->SetDataTypeToFloat ();
5255 points->SetData (ConvertToFloatArray<3 >(positions));
53-
54- this ->Meshes [timeStamp]-> SetPoints (points );
56+ this -> StaticMesh -> SetPoints (points);
57+ this ->Modified ( );
5558}
5659
5760// ------------------------------------------------------------------------------
58- void vtkF3DMemoryMesh::SetNormals (const std::vector<float >& normals, const double timeStamp )
61+ void vtkF3DMemoryMesh::SetNormals (const std::vector<float >& normals)
5962{
60- this ->Meshes [timeStamp]->GetPointData ()->SetNormals (ConvertToFloatArray<3 >(normals));
63+ if (!normals.empty ())
64+ {
65+ this ->StaticMesh ->GetPointData ()->SetNormals (ConvertToFloatArray<3 >(normals));
66+ this ->Modified ();
67+ }
6168}
6269
6370// ------------------------------------------------------------------------------
64- void vtkF3DMemoryMesh::SetTCoords (const std::vector<float >& tcoords, const double timeStamp )
71+ void vtkF3DMemoryMesh::SetTCoords (const std::vector<float >& tcoords)
6572{
66- this ->Meshes [timeStamp]->GetPointData ()->SetTCoords (ConvertToFloatArray<2 >(tcoords));
73+ if (!tcoords.empty ())
74+ {
75+ this ->StaticMesh ->GetPointData ()->SetTCoords (ConvertToFloatArray<2 >(tcoords));
76+ this ->Modified ();
77+ }
6778}
6879
6980// ------------------------------------------------------------------------------
70- void vtkF3DMemoryMesh::SetFaces (const std::vector< unsigned int >& faceSizes,
71- const std::vector<unsigned int >& faceIndices , const double timeStamp )
81+ void vtkF3DMemoryMesh::SetFaces (
82+ const std::vector<unsigned int >& faceSizes , const std::vector< unsigned int >& faceIndices )
7283{
7384 vtkNew<vtkIdTypeArray> offsets;
7485 vtkNew<vtkIdTypeArray> connectivity;
@@ -95,19 +106,30 @@ void vtkF3DMemoryMesh::SetFaces(const std::vector<unsigned int>& faceSizes,
95106
96107 vtkNew<vtkCellArray> polys;
97108 polys->SetData (offsets, connectivity);
109+ this ->StaticMesh ->SetPolys (polys);
110+ this ->Modified ();
111+ }
98112
99- this ->Meshes [timeStamp]->SetPolys (polys);
113+ // ------------------------------------------------------------------------------
114+ void vtkF3DMemoryMesh::SetAnimatedMesh (double startTime, double endTime, MeshCallback callback)
115+ {
116+ this ->AnimatedCallback = std::move (callback);
117+ this ->TimeRange [0 ] = startTime;
118+ this ->TimeRange [1 ] = endTime;
119+ this ->IsAnimated = true ;
120+ this ->Modified ();
100121}
101122
102123// ------------------------------------------------------------------------------
103124int vtkF3DMemoryMesh::RequestInformation (vtkInformation* vtkNotUsed (request),
104125 vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
105126{
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-
109127 vtkInformation* outInfo = outputVector->GetInformationObject (0 );
110- outInfo->Set (vtkStreamingDemandDrivenPipeline::TIME_RANGE (), timeRange.data (), 2 );
128+
129+ if (this ->IsAnimated )
130+ {
131+ outInfo->Set (vtkStreamingDemandDrivenPipeline::TIME_RANGE (), this ->TimeRange , 2 );
132+ }
111133
112134 return 1 ;
113135}
@@ -119,21 +141,17 @@ int vtkF3DMemoryMesh::RequestData(vtkInformation* vtkNotUsed(request),
119141 vtkInformation* outInfo = outputVector->GetInformationObject (0 );
120142 vtkPolyData* output = vtkPolyData::GetData (outInfo);
121143
122- if (outInfo-> Has ( vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ()) && ! this ->Meshes . empty () )
144+ if (this -> IsAnimated && this ->AnimatedCallback )
123145 {
124- const double requestedTimeValue =
125- outInfo->Get (vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ());
126- auto iter = Meshes.upper_bound (requestedTimeValue);
127- if (iter != Meshes.begin ())
146+ double requestedTime = this ->TimeRange [0 ];
147+ if (outInfo->Has (vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP ()))
128148 {
129- iter = std::prev (iter );
149+ requestedTime = outInfo-> Get ( vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP () );
130150 }
131- output->ShallowCopy (iter->second );
132- }
133- else
134- {
135- output->ShallowCopy (this ->Meshes [0.0 ]);
151+ this ->AnimatedCallback (requestedTime, this );
136152 }
137153
154+ output->ShallowCopy (this ->StaticMesh );
155+
138156 return 1 ;
139157}
0 commit comments