Discussion:
[vtkusers] vtkParametricFunction sub-classes in Python
Jack Zentner
2016-08-29 14:03:07 UTC
Permalink
All,

I've been playing around with some parametric geometry in Python and I
wanted to use VTK to visualize the surfaces that I'm creating. It seems
that extending the vtkParametricFunction class and using it with the
vtkParametricFunctionSource should work great. However I can't seem to get
this to work from Python.

Per Andrew Maclean's instructions in the "Parametric Equations for Surfaces"
pdf, I've created my geometry class by inheriting from vtkParametricFunction
and implemented the Evaluate, EvaluateScalar and GetDimension methods. The
problem comes when I try to instantiate my new vtkParametricFunction object,
I get the following error:

TypeError: this is an abstract class and cannot be instantiated.

I though maybe it was because I had not explicitly implemented the other
virtual methods in the vtkParametricFunction interface. So I implemented all
of those as well and I still get the same error. Then I tried to inherit
from one of the C++ sub-classes of vtkParametricFunction and simply override
the Evaluate, EvaluateSCalar and GetDimension methods. This works from an
instantiation stand point but my overrides of Evaluate and the like are not
being recognized.

Am I missing something? Is it not possible to define vtkParametricFunction
sub-classes in Python for use with a vtkParametricFunctionSource object?

FYI, I'm using Python3.5 and the VTK 7.0 package from conda-forge.


Thank you in advance,

jack



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkParametricFunction-sub-classes-in-Python-tp5740029.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
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
David Gobbi
2016-08-29 14:31:00 UTC
Permalink
Hi Jack,

Virtual method hooks aren't implemented in the VTK python wrappers,
so a Python subclass of an abstract VTK class is still abstract. It's one
of the many improvements I'd add to the Python wrappers if I had the
time (my current wrapper improvement project is to update the VTK
wrapper hint system).

- David
Post by Jack Zentner
All,
I've been playing around with some parametric geometry in Python and I
wanted to use VTK to visualize the surfaces that I'm creating. It seems
that extending the vtkParametricFunction class and using it with the
vtkParametricFunctionSource should work great. However I can't seem to get
this to work from Python.
Per Andrew Maclean's instructions in the "Parametric Equations for Surfaces"
pdf, I've created my geometry class by inheriting from
vtkParametricFunction
and implemented the Evaluate, EvaluateScalar and GetDimension methods. The
problem comes when I try to instantiate my new vtkParametricFunction object,
TypeError: this is an abstract class and cannot be instantiated.
I though maybe it was because I had not explicitly implemented the other
virtual methods in the vtkParametricFunction interface. So I implemented all
of those as well and I still get the same error. Then I tried to inherit
from one of the C++ sub-classes of vtkParametricFunction and simply override
the Evaluate, EvaluateSCalar and GetDimension methods. This works from an
instantiation stand point but my overrides of Evaluate and the like are not
being recognized.
Am I missing something? Is it not possible to define vtkParametricFunction
sub-classes in Python for use with a vtkParametricFunctionSource object?
FYI, I'm using Python3.5 and the VTK 7.0 package from conda-forge.
Thank you in advance,
jack
Jack Zentner
2016-08-29 15:01:46 UTC
Permalink
David,

Thank you for getting back to me so quickly.

So I'm assuming that the lack of virtual method hooks in the wrappers is
also why I was not able to get my sub-classing hack of vtkParametricBour to
work. I was hoping that by reimplementing Evaluate, EvaluateScalar and
GetDimension on a Python-based sub-class of vtkParametricBour I could get
it all to work. Unfortunately it seems the vtkParametricBour.Evaluate() is
being used rather than my Python version. Is this your understanding as
well?

In the meantime, I guess I'll what I'll try to do is to make a Cython
interface to vtkParametricFunction and create a Cython-based sub-class to
consume my parametric surfaces. I'm pretty sure this will work although it
has been a little while since I used Cython for interfacing. If you or
anyone else has any better suggestions, please pass them along.

Thank you again,

jack

Loading...