[vtkusers] Animation with VTU files.

kenichiro yoshimi rccm.kyoshimi at gmail.com
Sun Apr 8 00:56:28 EDT 2018


Hello Zoltan,

Probably it is possible to retrieve the vtkXMLUnstructuredGridReader
object from the object that sets the reader as input connection like
something below:

  sphereGlyph->SetSourceConnection(sphere->GetOutputPort());
  sphereGlyph->SetInputConnection(reader->GetOutputPort());

  // reversely access
  auto reader = vtkXMLUnstructuredGridReader::SafeDownCast(
    sphereGlyph->GetInputConnection(0, 0)->GetProducer());

Here is ReverseAccess example from VTK examples
https://lorensen.github.io/VTKExamples/site/Cxx/Visualization/ReverseAccess/

And I attach a simple code without programmable filter though I'm not
sure if this is a correct usage..

Thanks

2018-04-07 0:50 GMT+09:00 Zoltan Kovacs <Zoltan.Kovacs at esi-group.com>:
> 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
>
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DataAnimation.tar.gz
Type: application/x-gzip
Size: 3442 bytes
Desc: not available
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180408/04e96855/attachment.bin>


More information about the vtkusers mailing list