[vtkusers] Python vtkSphere Subclass

Ryan Irvin ryan.irvin at gmail.com
Sun Dec 9 14:05:20 EST 2012


I'm trying to create a custom implicit surface function to represent a
conic asphere and my approach was to try and subclass vtkSphere.  I had
previously tried to subclass vtkImplicitFunction without success and saw
some posts about not being able to subclass abstract classes in Python (I
don't know if this is still true).

The subclass I've put together is shown below, where the attribute surf_obj
is a python class representing the conic asphere and contains methods for
evaluating the surface function and gradient.

When I run my full script, the result is that the default vtkSphere is
always rendered.  It's pretty apparent that I'm not understanding the
proper approach to this problem and/or am not properly subclassing
vtkSphere.

I will be happy to provide the full *.py file which contains all of the
code but wasn't sure of the protocol and have not provided it with this
post.

If anyone has any suggestions about the correct way to approach this
problem or can provide some advice for properly subclassing, I would very
much appreciate it.

-Ryan


class VtkImplicitConic( vtk.vtkSphere ):

    def __init__( self, con_surf ):
        self.surf_obj = con_surf
        self.SetRadius( self.surf_obj.GetRadius() )


    def EvaluateFunction( self, x, y, z ):
        return self.surf_obj.EvaluateFunction( x, y, z )


    def EvaluateGradient( self, x, n ):
        n[0],n[1],n[2] = self.surf_obj.EvaluateGradient( x[0], x[1], x[2] )


    def GetRadius( self ):
        return self.surf_obj.GetRadius()


    def SetRadius( self, radius ):
        self.surf_obj.SetRadius( radius )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121209/4876d5b1/attachment.htm>


More information about the vtkusers mailing list