# How to work with vtkParametricFunction in SlicerJupyter?

**URL:** <https://discourse.slicer.org/t/how-to-work-with-vtkparametricfunction-in-slicerjupyter/34833>\
**Category:** Support\
**Created:** [March 11, 2024, 6:17pm UTC](https://discourse.slicer.org/t/how-to-work-with-vtkparametricfunction-in-slicerjupyter/34833 "2024-03-11T18:17:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juergen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/juergen/32/66870_2.png) [@Juergen](https://discourse.slicer.org/u/Juergen)\
**Post date:** [March 11, 2024, 6:17pm UTC](https://discourse.slicer.org/t/how-to-work-with-vtkparametricfunction-in-slicerjupyter/34833/1 "2024-03-11T18:17:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 12, 2024, 3:57am UTC](https://discourse.slicer.org/t/how-to-work-with-vtkparametricfunction-in-slicerjupyter/34833/2 "2024-03-12T03:57:53Z")

</div>

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](https://discourse.vtk.org/t/python-custom-render-pass/5743) and [[vtkusers] vtkParametricFunction sub-classes in Python](https://vtkusers.public.kitware.narkive.com/CmEWpTLI/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.

---

<div class="post-metadata">

**Author:** ![Juergen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/juergen/32/66870_2.png) [@Juergen](https://discourse.slicer.org/u/Juergen)\
**Post date:** [March 13, 2024, 5:15pm UTC](https://discourse.slicer.org/t/how-to-work-with-vtkparametricfunction-in-slicerjupyter/34833/3 "2024-03-13T17:15:14Z")

</div>

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.
