Announce: vtkPythonClassAlgorithm

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Announce: vtkPythonClassAlgorithm

Bob Pepin
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

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Announce: vtkPythonClassAlgorithm

Utkarsh Ayachit
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:


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 <[hidden email]> 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

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



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Announce: vtkPythonClassAlgorithm

Bob Pepin
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 <[hidden email]> 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:


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 <[hidden email]> 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

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



_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [EXTERNAL] Re: Announce: vtkPythonClassAlgorithm

Scott, W Alan
In reply to this post by Utkarsh Ayachit

Does this mean the Python could be developed in an IDE?

 

Alan

 

From: Paraview-developers [mailto:[hidden email]] On Behalf Of Utkarsh Ayachit
Sent: Sunday, August 6, 2017 8:37 PM
To: Bob Pepin <[hidden email]>
Cc: ParaView Developers <[hidden email]>
Subject: [EXTERNAL] Re: [Paraview-developers] Announce: vtkPythonClassAlgorithm

 

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:

 

 

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 <[hidden email]> 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

 

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

 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Announce: vtkPythonClassAlgorithm

Utkarsh Ayachit
In reply to this post by Bob Pepin
Bob,

> Would there be an interest in integrating this with ParaView once it has reached a certain maturity?

Surely. There's value to such a capability, no doubt.

> 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).

This is a use-case that I'm skeptical we can support robustly in
ParaView esp. in all modes it operates (client-server etc). I am not
convinced it's that useful besides debugging, however. We can sure add
a "reload" button to manually reimport the module, but that's not
exactly what you want. But I'll stay posted.

> 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?

Are you aware of this post:
https://blog.kitware.com/easy-customization-of-the-paraview-python-programmable-filter-property-panel/

Utkarsh
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [EXTERNAL] Re: Announce: vtkPythonClassAlgorithm

Utkarsh Ayachit
In reply to this post by Scott, W Alan
> Does this mean the Python could be developed in an IDE?

Sure, this will support that.
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [EXTERNAL] Re: Announce: vtkPythonClassAlgorithm

Bob Pepin
Hi Alan,
since this is a plugin, it means in fact that Python extensions can be developed in an IDE right now, even for older ParaView versions (assuming you have an environment in which to compile ParaView modules). If you want to give it a try, I would be very interested to hear if you got it to work on your platform or whether you had any trouble with the plugin or the documentation.

Best,
Bob

On Tue, Aug 15, 2017 at 4:43 AM Utkarsh Ayachit <[hidden email]> wrote:
> Does this mean the Python could be developed in an IDE?

Sure, this will support that.

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Announce: vtkPythonClassAlgorithm

Bob Pepin
In reply to this post by Utkarsh Ayachit
Hi,
 
> 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).

This is a use-case that I'm skeptical we can support robustly in
ParaView esp. in all modes it operates (client-server etc). I am not
convinced it's that useful besides debugging, however. We can sure add
a "reload" button to manually reimport the module, but that's not
exactly what you want. But I'll stay posted.


do you have a specific situation in mind regarding the reloading? Since the module uses Python's native functionality for reloading modules, I would assume that if we can load it, we can reload it. I agree however that checking whether the source has changed is a bit more delicate.

Besides, I think that a Reload button would be perfect, especially if it did an Apply at the same time. I was considering adding a checkbox that ends up calling Modified() on the vtk Algorithm object upon checking/unchecking, do you know of a better solution using only existing ParaView features?
 
> 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?

Are you aware of this post:
https://blog.kitware.com/easy-customization-of-the-paraview-python-programmable-filter-property-panel/

Thanks, This was exactly what I was looking for. Just out of curiosity, how does the "magic" work here? I.e. how does PV decide whether to call SetProperty(value) or SetProperty(name, value)? 

I also added a HDF5 Reader plugin to the github repository as an example.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [EXTERNAL] Re: Announce: vtkPythonClassAlgorithm

Scott, W Alan
In reply to this post by Scott, W Alan

Ping

 

From: Paraview-developers [mailto:[hidden email]] On Behalf Of Scott, W Alan
Sent: Monday, August 14, 2017 4:39 PM
To: Ayachit, Utkarsh (External Contacts) <[hidden email]>; Bob Pepin <[hidden email]>
Cc: ParaView Developers <[hidden email]>
Subject: Re: [Paraview-developers] [EXTERNAL] Re: Announce: vtkPythonClassAlgorithm

 

Does this mean the Python could be developed in an IDE?

 

Alan

 

From: Paraview-developers [[hidden email]] On Behalf Of Utkarsh Ayachit
Sent: Sunday, August 6, 2017 8:37 PM
To: Bob Pepin <[hidden email]>
Cc: ParaView Developers <[hidden email]>
Subject: [EXTERNAL] Re: [Paraview-developers] Announce: vtkPythonClassAlgorithm

 

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:

 

 

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 <[hidden email]> 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

 

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

 


_______________________________________________
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
Loading...