[Paraview] Python Programmable Filter

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Thu Nov 13 11:31:22 EST 2008


To print the class name for any vtkobject in python use:
   print obj.GetClassName()

Utkarsh

Jacques Papper wrote:
> Indeed the VTK online doxygen is very useful. Is there any way in python 
> of getting the name of the class of the object I'm dealing with ? That 
> way I can find the class documentation in the Doxygen ?
> Thanks again,
> Jacques
> 
> 2008/11/13 David E DeMarle <dave.demarle at kitware.com 
> <mailto:dave.demarle at kitware.com>>
> 
>     There is probably a python way to get help more easily, but one way to
>     figure it out is to look at the VTK doxygen documentation for
>     vtkDataObject and it's subclasses, and realize that all (or almost
>     all) of the public C++ methods are wrapped into python and therefore
>     available to use.
> 
>     cheers,
>     Dave
> 
>     On 11/13/08, Jacques Papper <jacques.papper at gmail.com
>     <mailto:jacques.papper at gmail.com>> wrote:
>      > Thanks a lot Utkarsh !
>      >
>      > It works. I was almost there, but I couldn't figure out a way to
>     expose the
>      > available interface for each object!
>      > Where am I supposed to look to figure out that CopyStructure(), and
>      > NewInstance(), SetBlock() etc ... are functions available ?
>      >
>      > Kind regards,
>      > Jacques Papper
>      >
>      >
>      > 2008/11/13 Utkarsh Ayachit <utkarsh.ayachit at kitware.com
>     <mailto:utkarsh.ayachit at kitware.com>>
>      >
>      > > Jacques,
>      > >
>      > > Couple of ways to solve your problem:
>      > >
>      > > * Solution One:
>      > > If you don't want to deal with the fact that your data is a
>      > vtkMultiblockDataSet, apply the "Merge Blocks" filter after each
>     of the
>      > "Extract Block" filters and then connect to the "Programmable
>     Filter" to to
>      > the output from the "Merge Blocks" and then your current script
>     should work
>      > just fine. The "Merge Blocks" will convert the
>     vtkMultiBlockDataSet to a
>      > vtkUnstructuredGrid on which your script is applicable.
>      > >
>      > > * Solution Two:
>      > >
>      > > input0 = self.GetInputDataObject(0,0)
>      > > input1 = self.GetInputDataObject(0,1)
>      > > output = self.GetOutputDataObject(0)
>      > >
>      > > input0Block0 = input0.GetBlock(0)
>      > > input1Block0 = input1.GetBlock(0)
>      > >
>      > > output.CopyStructure(input0)
>      > > outputBlock0 = input0Block0.NewInstance()
>      > > outputBlock0.CopyStructure(input0Block0)
>      > > output.SetBlock(0, outputBlock0)
>      > >
>      > >
>      >
>     outputBlock0.GetPointData().AddArray(input0Block0.GetPointData().GetArray("pressure1"))
>      > >
>      >
>     outputBlock0.GetPointData().AddArray(input1Block0.GetPointData().GetArray("pressure2"))
>      > >
>      > > The above script will work if you are extracting a single block
>     using the
>      > Extract Block filter. If you want to merge arrays for all the
>     blocks in the
>      > input you'll have to iterate over the datasets in the
>     vtkMultiblockDataset.
>      > Take a look at
>      > >
>      >
>     http://www.paraview.org/Wiki/Python_Programmable_Filter#Dealing_with_Composite_Datasets
>      > >
>      > > Utkarsh
>      > >
>      > >
>      > > Jacques Papper wrote:
>      > >
>      > > >
>      > > > Here is what I am doing at the moment.
>      > > > -Load geometry 1
>      > > > -Extract wing block
>      > > >
>      > > > -Load geometry 2
>      > > > -Extract wing block
>      > > >
>      > > > Then use the resample filter with wing1 as input and wing2 as
>     source
>      > > > (this works)
>      > > >
>      > > > The last bit is missing (that is merging the data from wing2
>     with the
>      > resampled data)
>      > > >
>      > > > Jacques
>      > > >
>      > > > 2008/11/13 Berk Geveci <berk.geveci at kitware.com
>     <mailto:berk.geveci at kitware.com>
>      > <mailto:berk.geveci at kitware.com <mailto:berk.geveci at kitware.com>>>
>      > > >
>      > > >
>      > > >    Programmable filter can still be made to work. Do the
>     datasets have
>      > > >    multiple parts? I am not sure how resampling would work
>     with multiple
>      > > >    parts. It is impossible to guess which parts map to which
>     parts...
>      > > >
>      > > >    -berk
>      > > >
>      > > >    On Thu, Nov 13, 2008 at 8:28 AM, Jacques Papper
>      > > >
>      > > >    <jacques.papper at gmail.com <mailto:jacques.papper at gmail.com>
>      > <mailto:jacques.papper at gmail.com
>     <mailto:jacques.papper at gmail.com>>> wrote:
>      > > >     > They are multi-block datasets from Ensight Reader.
>      > > >     > Is there another way of dealing with this then ?
>      > > >     > Jacques
>      > > >     >
>      > > >     > 2008/11/13 Berk Geveci <berk.geveci at kitware.com
>     <mailto:berk.geveci at kitware.com>
>      > > >    <mailto:berk.geveci at kitware.com
>     <mailto:berk.geveci at kitware.com>>>
>      > > >
>      > > >     >>
>      > > >     >> Are the inputs multi-block datasets by any chance?
>      > > >     >>
>      > > >     >>
>      > > >     >> -berk
>      > > >     >>
>      > > >     >> On Thu, Nov 13, 2008 at 6:03 AM, Jacques Papper
>      > > >
>      > > >     >> <jacques.papper at gmail.com
>     <mailto:jacques.papper at gmail.com>
>      > <mailto:jacques.papper at gmail.com
>     <mailto:jacques.papper at gmail.com>>> wrote:
>      > > >     >> > Hi Berk,
>      > > >     >> >
>      > > >     >> > I am trying out your suggestion of merging arrays :
>      > > >     >> >
>      > > >     >> > input0 = self.GetInputDataObject(0,0)
>      > > >     >> > input1 = self.GetInputDataObject(0,1)
>      > > >     >> > output = self.GetOutputDataObject(0)
>      > > >     >> >
>      > > >     >> >
>      > > >
>      >
>     output.GetPointData().AddArray(input0.GetPointData().GetArray("pressure1"))
>      > > >     >> >
>      > > >     >> >
>      > > >
>      >
>     output.GetPointData().AddArray(input1.GetPointData().GetArray("pressure2"))
>      > > >     >> >
>      > > >     >> > but I get the following error message :
>      > > >     >> >
>      > > >     >> >   File "<string>", line 2, in <module>
>      > > >     >> >   File "<string>", line 4, in RequestData
>      > > >     >> > AttributeError: GetPointData
>      > > >     >> >
>      > > >     >> > I also tried just using the programmable filter on
>     one source
>      > > >    and with
>      > > >     >> > the
>      > > >     >> > following code, and  I get the same error :
>      > > >     >> >
>      > > >     >> > input0=self.GetInputDataObject(0,0)
>      > > >     >> > input0.GetPointData()
>      > > >     >> >
>      > > >     >> > I am using version 3.4.0
>      > > >     >> >
>      > > >     >> >
>      > _______________________________________________
>      > > >     >> > ParaView mailing list
>      > > >     >> > ParaView at paraview.org <mailto:ParaView at paraview.org>
>     <mailto:ParaView at paraview.org <mailto:ParaView at paraview.org>>
>      > > >
>      > > >     >> >
>      > http://www.paraview.org/mailman/listinfo/paraview
>      > > >     >> >
>      > > >     >> >
>      > > >     >
>      > > >     >
>      > > >
>      > > >
>      > > >
>      > > >
>      >
>     ------------------------------------------------------------------------
>      > > >
>      > > >
>      > > > _______________________________________________
>      > > > ParaView mailing list
>      > > > ParaView at paraview.org <mailto:ParaView at paraview.org>
>      > > > http://www.paraview.org/mailman/listinfo/paraview
>      > > >
>      > >
>      >
>      >
>      > _______________________________________________
>      > ParaView mailing list
>      > ParaView at paraview.org <mailto:ParaView at paraview.org>
>      > http://www.paraview.org/mailman/listinfo/paraview
>      >
>      >
> 
> 
>     --
>     David E DeMarle
>     Kitware, Inc.
>     R&D Engineer
>     28 Corporate Drive
>     Clifton Park, NY 12065-8662
>     Phone: 518-371-3971 x109
> 
> 


More information about the ParaView mailing list