How to work with vtkParametricFunction in SlicerJupyter?

Hello,
This is a question not directly related to Slicer, however I am using the SlicerJupyter kernel to interface with vtk.
I am trying to create my own parametric surface with the abstract class vtkParametricFunction but I don’t seem to define the necessary methods of my derived class to make it work. Has anybody worked with vtkParametricFunction in Python before and gotten it to work?
Thanks for any suggestions.

You can override methods of VTK classes in C++ but I don’t think you can override methods of a VTK object in Python. See python custom render pass - Support - VTK and [vtkusers] vtkParametricFunction sub-classes in Python. You can ask David Gobbi on the VTK forum to confirm that it is still the case.

However, even if you could override VTK methods in Python, you would probably not want do it for a parametric function because the function evaluation has to be extremely fast. If you implement the function in Python then an operation on the parametric function could take a minute, while if you used C++ it could take just a second.

Thanks, Andras.

It seems that it is still the case that it is not possible to subclass from an abstract base class that was implemented in C++ in the VTK code.

I thought that speed would not matter too much. Even if it was much slower than a C++ implementation, the surface would only need to be created once, no?

Right now I’m trying to create a surface that has cross-sections made of two half-ellipses, each with a different minor radius, but both with the same major radius. In the third dimension these cross-sections then linearly change in terms of their major and minor radius.

Initially I’ve used only two of these cross sections, at the beginning and at the end. Then I tried to use vtkRuledSurfaceFilter to connect them. Unless I used a really high number of points along the combined half-ellipses, something on the order of 2000, I would not get the right shape, especially around the areas of largest slopes/curvature: arc.SetResolution(2000, 40); arc.SetRuledModeToResample(). I also tried to experiment with arc.SetOrientLoops(True) but I’m not sure this did anything in my case. This seems to me not to be a very efficient way of doing things and I have to experiment with the resolution to create a kink-free shape. Now I created more cross-sectional contours between the end contours but that just adds complexity to this procedure.

Another things I was struggling with is that when I try to “combine” the two half-ellipses (created with vtkEllipseArcSource) via the vtkAppendPolyData tool, I always ended up with a contour with two cells in it. Then the RuledSurfaceFilter doesn’t work correctly because it combines lines (aka cells) i with i+1. I ended up writing boiler-plate code to manually merge the two half-ellipses so that they are one line (aka one cell).

Thanks for any suggestions you might have.