[Paraview-developers] Announce: vtkPythonClassAlgorithm

Bob Pepin bobpepin at gmail.com
Mon Aug 7 14:02:45 EDT 2017


Hi Utkarsh,
thank you for sharing your code, I think the fact that you started work on
something similar shows that there is indeed a need for this kind of
feature. Would there be an interest in integrating this with ParaView once
it has reached a certain maturity?

Your approach seems to be complementary to what I have implemented, it
seems to me you could easily replace vtkPythonAlgo with vtkPythonClassAlgo.
I think that having a single string for module.class is indeed the better
solution, I went with separate parameters mostly because it was faster to
implement. In particular, Py_ImportModule("foo.bar.baz") returns the module
object for foo, and we will have to traverse to baz manually if we want to
create an instance from a class in baz.

I also think that a vanilla vtkPythonAlgorithm can not meet all the needs
of this feature. In my case I need for example to override processRequest
on the C++ level in order to reload the module on a new request (and
ideally only when the source code has changed, and only optionally).

The main issue going forward I can see right now involves passing
parameters to Python. Right now I have a C++ method SetStringProperty(name,
value) and use a <StringVectorProperty> with 2 elements. Now suppose I want
to have a FileName property so that SetStringProperty("filename", value) is
called when the FileName property is set to value. Do you know how to
achieve this with the existing mechanisms, for example is it possible to
have a StringVectorProperty with 2 elements where the first one is hidden
and set to a default value?
If not, do you think it would be possible to pass the value of a
StringVectorProperty through sprintf with a custom format string before
calling the command? For example, so that
<StringVectorProperty
  name="FileName"
  command="SetProperty"
  format="filename=%s" />
would result in the method call SetProperty("filename=foo.bar") when the
FileName property is set to "foo.bar".

Best,
Bob

On Mon, Aug 7, 2017 at 4:36 AM Utkarsh Ayachit <utkarsh.ayachit at kitware.com>
wrote:

> Bob,
>
> That's pretty cool! I'll take a closer look at it next week. This seems to
> be in similar vein to a WIP-branch I created a little while ago but never
> got around to finishing it. If you're interested, here's the commit:
>
>
> https://gitlab.kitware.com/utkarsh.ayachit/paraview/commit/bfea05b0d2114f51a581f63c368cdce603932619
>
> It relies on `vtkPythonAlgorithm` (
> https://blog.kitware.com/vtkpythonalgorithm-is-great/) to handle passing
> algorithm passes to a Python class.  The XML looks like
>
> <SourceProxy class="extras.Sphere"
>                  name="PythonAlgorithm"
>                  si_class="vtkSIPythonSourceProxy">
> </SourceProxy>
>
> Where the "class" is the Python class name indeed with extra being the
> module to import.
>
> Utkarsh
>
>
> On Sun, Aug 6, 2017 at 5:04 PM, Bob Pepin <bobpepin at gmail.com> wrote:
>
>> Hi,
>> I developed a ParaView plugin that is similar to Programmable
>> Filter/Source, except that the Python code is in a Python class in an
>> external file.
>>
>> The source code for a first (rough) version can be found on github at
>> https://github.com/bobpepin/vtkPythonClassAlgorithm
>>
>> I would be thankful for feedback or suggestions (as well as contributions
>> of course).
>>
>> Best,
>> Bob
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Search the list archives at:
>> http://markmail.org/search/?q=Paraview-developers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview-developers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview-developers/attachments/20170807/021fac1f/attachment.html>


More information about the Paraview-developers mailing list