vtkInteractorEventRecorder can be used to record VTK events in a single file and replay it by pass these events to vtkRenderWindowInteractor.

Record

The following code shows how to use it to save all interactive information into a file.
We rotate the cone and switch its surface status between wireframe and flat plane by mouse and special keys.
The vtkInteractorEventRecorder object records these events into file /Users/weiyang/Desktop/record.txt

int main()
{
    vtkSmartPointer cone =
            vtkSmartPointer::New();
    cone->Update();

    vtkSmartPointer coneMapper =
            vtkSmartPointer::New();
    coneMapper->SetInputData( cone->GetOutput() );
    coneMapper->Update();

    vtkSmartPointer coneActor =
            vtkSmartPointer::New();
    coneActor->SetMapper( coneMapper );

    vtkSmartPointer renderer =
            vtkSmartPointer::New();
    renderer->AddActor( coneActor );
    renderer->SetBackground( 0, 0, 0 );

    vtkSmartPointer renderWindow =
            vtkSmartPointer::New();
    renderWindow->AddRenderer( renderer );

    vtkSmartPointer renderWindowInteractor =
            vtkSmartPointer::New();
    renderWindowInteractor->SetRenderWindow( renderWindow );

    vtkSmartPointer recorder =
            vtkSmartPointer::New();
    recorder->SetInteractor( renderWindowInteractor );
    recorder->SetFileName( "/Users/weiyang/Desktop/record.txt" );
    recorder->EnabledOn();
    recorder->Record();

    renderer->ResetCamera();
    renderWindow->Render();
    renderWindowInteractor->Start();
    return 0;
}

record.txt:


Replay

In the following example, I used renderWindowInteractor to diaplay window, so renderWindowInteractor->Start() is put before recorder->Play(). But there is UI event loop created by renderWindowInteractor->Start(), therefore user has to close the window in order to make replaying mechanism work.
main.cpp:

//...
    renderer->ResetCamera();
    renderWindow->Render();

    char *filePath = "/Users/weiyang/Desktop/record.txt";
    vtkSmartPointer recorder =
            vtkSmartPointer::New();
    recorder->SetInteractor( renderWindowInteractor );
    recorder->SetFileName( filePath );
    recorder->EnabledOn();
    recorder->DebugOn();

    std::ifstream inFile( filePath );
    int linesCount = std::count(std::istreambuf_iterator(inFile),
            std::istreambuf_iterator(), '\n');
    qDebug() << "There are " << linesCount << " lines.";

    renderWindowInteractor->Start();

    recorder->Play();
    return 0;



output:

There are 1145 lines.
Debug: In /Users/weiyang/Downloads/VTK-8.1.1/Rendering/Core/vtkInteractorEventRecorder.cxx, line 201
vtkInteractorEventRecorder (0x7f8f71560100): Playing

Debug: In /Users/weiyang/Downloads/VTK-8.1.1/Common/Core/vtkObject.cxx, line 886
vtkInteractorEventRecorder (0x7f8f71560100): UnRegistered by nullptr, ReferenceCount = 0

Debug: In /Users/weiyang/Downloads/VTK-8.1.1/Rendering/Core/vtkInteractorEventRecorder.cxx, line 114
vtkInteractorEventRecorder (0x7f8f71560100): Disabling widget

Debug: In /Users/weiyang/Downloads/VTK-8.1.1/Rendering/Core/vtkInteractorObserver.cxx, line 27
vtkInteractorObserver (0x7f8f71560100): vtkInteractorObserver (0x7f8f71560100): setting DefaultRenderer to 0x0

Debug: In /Users/weiyang/Downloads/VTK-8.1.1/Common/Core/vtkObject.cxx, line 150
vtkObject (0x7f8f71560100): Destructing!

 


0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x