[vtkusers] Animation with VTU files.
Zoltan Kovacs
Zoltan.Kovacs at esi-group.com
Mon Apr 9 06:22:31 EDT 2018
Hi Kenichiro,
Thank you very much for your help! It seems to be what I need. Just one question: when I run your code I see the particles in the same position with increasing radii. Does it mean the radii are different in each VTU file whereas the particle positions are the same. Just to be sure that the particle coordinates were read in the file series correctly.
Thanks,
Zoltan
-----Original Message-----
From: kenichiro yoshimi <rccm.kyoshimi at gmail.com>
Sent: Sonntag, 8. April 2018 06:56
To: Zoltan Kovacs <Zoltan.Kovacs at esi-group.com>
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Animation with VTU files.
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
> particleReader->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/DataAnimatio
> n/
>
>
>
> 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
>
More information about the vtkusers
mailing list