[vtkusers] HELP Wanted: Visualizing data from an OpenFOAM simulation

Bill Lorensen bill.lorensen at gmail.com
Tue Nov 8 14:54:18 EST 2016


Andre,

BTW: Thanks for providing a runnable script and data. Makes it easier to help.

Enjoy VTK,

Bill


On Tue, Nov 8, 2016 at 2:52 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> You need to set the active scalar for the point data and specify the
> range of the scalars for the mapper.
>
> See:
> #!
> import vtk
> file_name = "U_nearWalls.vtk"
>
> reader = vtk.vtkPolyDataReader()
> reader.SetFileName(file_name)
> reader.ReadAllScalarsOn()
> reader.ReadAllVectorsOn()
> reader.Update()
> reader.GetOutput().GetPointData().SetActiveScalars("U")
> mapper=vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(reader.GetOutputPort())
> mapper.SetScalarRange(reader.GetOutput().GetPointData().GetScalars().GetRange())
> actor=vtk.vtkActor()
> actor.SetMapper(mapper)
>
> renderer = vtk.vtkRenderer()
> renderer.AddActor(actor)
> renderer.SetBackground(0.1, 0.2, 0.4)
> render_window = vtk.vtkRenderWindow()
> render_window.AddRenderer(renderer)
> render_window.SetSize(300, 300)
> interactor = vtk.vtkRenderWindowInteractor()
> interactor.SetRenderWindow(render_window)
>
> interactor.Initialize()
> render_window.Render()
> interactor.Start()
>
> On Tue, Nov 8, 2016 at 1:08 PM, Andre Zimmer
> <andre.zimmer at rwth-aachen.de> wrote:
>> Hi,
>> by now I have spend days trying to visualize data from the OpenFOAM sample
>> function object.
>> Here is a small test case:
>> https://www.dropbox.com/s/5bhic1ms0anzrno/U_nearWalls.vtk?dl=0
>>
>> No matter what I do I always get a gray car. I have tried specifically
>> setting the scalar, vector, array, transforming and all kinds of stuff
>> without success.
>> In the simplest form I think the Python code should look like this:
>>
>> import vtk
>>  file_name = "U_nearWalls.vtk"
>>
>> reader = vtk.vtkPolyDataReader()
>> reader.SetFileName(file_name)
>> reader.ReadAllScalarsOn()
>> reader.ReadAllVectorsOn()
>> reader.Update()
>>
>> mapper=vtk.vtkPolyDataMapper()
>> mapper.SetInputConnection(reader.GetOutputPort())
>>
>> actor=vtk.vtkActor()
>> actor.SetMapper(mapper)
>>
>> renderer = vtk.vtkRenderer()
>> renderer.AddActor(actor)
>> renderer.SetBackground(0.1, 0.2, 0.4)
>>  render_window = vtk.vtkRenderWindow()
>> render_window.AddRenderer(renderer)
>> render_window.SetSize(300, 300)
>>  interactor = vtk.vtkRenderWindowInteractor()
>> interactor.SetRenderWindow(render_window)
>>
>> interactor.Initialize()
>> render_window.Render()
>> interactor.Start()
>>
>>
>> I am using Fedora 24, Python 2.7, VTK 6.3.
>> I assume it is only a small mistake I am making so hopefully someone can
>> help.
>>
>> Thank you in advance,
>> André
>> _______________________________________________
>> 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:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list