[Paraview] ParaView numpy interface question
Cory Quammen
cory.quammen at kitware.com
Thu Apr 14 16:41:47 EDT 2016
Kevin,
You would probably be better off using a Programmable Filter to
perform this operation. It will take two inputs and produce one output
that you can render directly - no need to write and read and
intermediate file.
HTH,
Cory
On Mon, Apr 4, 2016 at 3:46 PM, Dean, Kevin
<kevin.dean at decisionsciencescorp.com> wrote:
> Hey all,
>
> I have a quick question about setting scalar values with the python macro
> inside paraview.
>
> So I have two images that I want to do scalar manipulation with.
>
> example code:
>
> from paraview import simple
>
> from vtk.util import numpy_support as npvtk
>
>
> import vtk.numpy_interface.dataset_adapter as dsa
> import pandas as pd
>
> import vtk
>
>
> scaling_vti = simple.XMLImageDataReader(FileName=[scaling_filename])
>
> scaling_rawData = simple.servermanager.Fetch(scaling_vti)
>
> scaling_data = dsa.WrapDataObject(scaling_rawData)
>
> scaling_array =
> pd.DataFrame(npvtk.vtk_to_numpy(data.GetPointData().GetScalars()), columns=
> ['scaling_error'])
>
> humans_vti = simple.FindSource(humans_filename)
>
> humans_vti.PointArrayStatus = ['Scattering Density']
> humans_rawData = simple.servermanager.Fetch(humans_vti)
> humans_data = dsa.WrapDataObject(humans_rawData)
> humans_array =
> pd.DataFrame(npvtk.vtk_to_numpy(humans_data.GetPointData().GetScalars()),
> columns=['scalar_intensity'])
>
> new_scalars = pd.DataFrame(humans_array.scalar_intensity *
> scaling_array.scaling_error)
>
> data.GetPointData().SetScalars(npvtk.numpy_to_vtk(new_scalars))
>
>
> After I do this, I can bypass the pipeline (because I haven't figure out how
> to use it yet) by
>
> writing this image to a new file then load it again to render it.
>
> Is there a way I can set the paraview image with the new scalar values and
> have it render without
> having to write it to a file first?
>
> Or, is there a way to convert the
> vtk.numpy_interface.dataset_adapter.DataSetAttributes type back
> to paraview.servermanager.FieldDataInformation?
>
> Thanks,
>
> Kevin E. Dean
>
>
> This email and its contents are confidential. If you are not the intended
> recipient, please do not disclose or use the information within this email
> or its attachments. If you have received this email in error, please report
> the error to the sender by return email and delete this communication from
> your records.
> _______________________________________________
> 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 ParaView Wiki at:
> http://paraview.org/Wiki/ParaView
>
> Search the list archives at: http://markmail.org/search/?q=ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/paraview
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
More information about the ParaView
mailing list