实现效果如图:
#include <vtkAutoInit.h>
//VTK_MODULE_INIT(vtkRenderingOpenGL2);
//VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
//VTK_MODULE_INIT(vtkRenderingFreeType);
#include <iostream>
#include <windows.h>
#include "vtkSmartPointer.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkTecplotReader.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkDataSetMapper.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCellDataToPointData.h"
#include "vtkAppendFilter.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkLookupTable.h"
#include "vtkScalarBarActor.h"
#include "vtkRenderWindowInteractor.h"
#include <string>
#include "vtkCellArray.h"
#include "vtkIdList.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkAnimationCue.h"
#include "vtkAnimationScene.h"
#include "vtkNew.h" class vtkCustomAnimationCue : public vtkAnimationCue
{
public:static vtkCustomAnimationCue* New();//vtkTypeRevisionMacro(vtkCustomAnimationCue,vtkAnimationCue);vtkRenderWindow * RenWin ;vtkSphereSource * Sphere ;protected:vtkCustomAnimationCue() {}virtual void TickInternal(double currenttime, double deltatime,double clocktime) {double new_st = currenttime * 180;this->Sphere->SetStartTheta(new_st);this->RenWin->Render();}private:};vtkStandardNewMacro(vtkCustomAnimationCue);void main() {/**/vtkNew<vtkRenderer> renderer ;vtkNew<vtkRenderWindow> renWin ;renWin->SetMultiSamples(0);//renWin->SetSize(2000,2000);renWin->AddRenderer(renderer);vtkNew<vtkSphereSource> sphere ;vtkNew<vtkPolyDataMapper> mapper ;mapper->SetInputConnection(sphere->GetOutputPort());vtkNew<vtkActor> actor ;actor->SetMapper(mapper);renderer->AddActor(actor);renWin->Render();/** /vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renWin);renderWindowInteractor->Start();**/vtkNew<vtkAnimationScene> scene ;//scene->SetModeToRealTime();scene->SetModeToSequence();scene->SetFrameRate(30);scene->SetStartTime(0);scene->SetEndTime(60);vtkNew<vtkCustomAnimationCue> cue;cue->Sphere = sphere;cue->RenWin = renWin;cue->SetTimeModeToNormalized();cue->SetStartTime(.0);cue->SetEndTime(1.0);scene->AddCue(cue);scene->Play();scene->Stop();}