[vtkusers] Animation with VTU files.

Zoltan Kovacs Zoltan.Kovacs at esi-group.com
Fri Apr 6 11:50:18 EDT 2018


Dear VTK Users,

I have a question on animation with VTU file series. I wrote a code which displays particels modeled with sphere
glyphs, where the particle positions and radii are read from VTU files:

    VTK_CREATE(vtkXMLUnstructuredGridReader, particleReader);
    VTK_CREATE(vtkSphereSource, sphere);
    VTK_CREATE(vtkGlyph3D, sphereGlyph);
    VTK_CREATE(vtkVertexGlyphFilter, glyphFilter);
    VTK_CREATE(vtkPolyDataMapper, particleMapper);
    VTK_CREATE(vtkActor, particleActor);

    particleReader->SetFileName( particleName.c_str() );
    particleReader->Update();

    vtkUnstructuredGrid *grid           = particleReader->GetOutput();
    vtkPointData        *pointData      = grid->GetPointData();
    pointData->SetActiveScalars("Radii");

    glyphFilter->SetInputData(grid);
    glyphFilter->Update();

    sphere->SetRadius(1);
    sphereGlyph->SetSourceConnection(sphere->GetOutputPort());
    sphereGlyph->SetInputConnection(glyphFilter->GetOutputPort());

    particleMapper->SetInputConnection(sphereGlyph->GetOutputPort());
    particleMapper->SetScalarModeToUsePointFieldData();
    particleMapper->Update();
    particleActor->SetMapper(particleMapper);

    VTK_CREATE(vtkRenderer, renderer);
    VTK_CREATE(vtkRenderWindow, renderWindow);
    VTK_CREATE(vtkRenderWindowInteractor, renderWindowInteractor);

    renderWindow->AddRenderer(renderer);
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderer->AddActor(particleActor);
    renderer->SetBackground(.3, .6, .3);

    renderWindow->Render();
    renderWindowInteractor->Start();

I would like to make an animation where the particle postions are updated. Thus I would change the string particleName in the argument of the function particleReader->SetFileName() reading a new VTU file and update the whole procedure with the unstructured grid / 3D glyph / glyp filter obejcts. I try to use vktProgrammableFilter and vtkCallbackCommand to impelment the animation process as I found in the example
https://lorensen.github.io/VTKExamples/site/Cxx/Utilities/DataAnimation/

The example uses an vtkSphereSource as an input for the programmable filter, so the example has essentially the code

VTK_CREATE(vtkSphereSource, sphere);
VTK_CREATE(vtkProgrammableFilter, filter);
filter->SetInputConnection(sphere->GetOutputPort());
filter->SetExecuteMethod(AdjustPoints2, filter);
where the function "AdjustPoints2" updates some point position for the sphere source.

I try to figure out what kind of input can be given to the programmable filter in the case of the VTU files.
If would like to pass the reader itself to the programmable filer, so that it could be updated for each file
and I could make the proper update for the grid and the glyphs too. Then the updating function for the
programmable filter execution method looked like:

void Update(void *filterPointer)
{
    vtkSmartPointer<vtkProgrammableFilter> filter = static_cast<vtkProgrammableFilter*>(filterPointer);

    ...

    GetNewVTUFileName(particeName);
    particleReader->SetFileName( particleName.c_str() );
    particleReader->Update();

    vtkUnstructuredGrid *grid           = particleReader->GetOutput();
    vtkPointData        *pointData      = grid->GetPointData();
    pointData->SetActiveScalars("Radii");

    glyphFilter->SetInputData(grid);
    glyphFilter->Update();

    sphere->SetRadius(1);
    sphereGlyph->SetSourceConnection(sphere->GetOutputPort());
    sphereGlyph->SetInputConnection(glyphFilter->GetOutputPort());

    particleMapper->SetInputConnection(sphereGlyph->GetOutputPort());
    particleMapper->SetScalarModeToUsePointFieldData();
    particleMapper->Update();

}

I am not sure if this is feasible since I do not see how to pass the reader itself to the programmable filter.
Could anyone help me with this problem?

Thank you,
Zoltan


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180406/84cdf7b0/attachment.html>


More information about the vtkusers mailing list