David,<div><br></div><div>Thanks for the clarification and the suggestion regarding vtkProgrammableSource. I'll look into that option.</div><div><br></div><div>-Ryan</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sun, Dec 9, 2012 at 1:25 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Ryan,<br>
<br>
This won't work, because your EvaluateFunction() and EvalutateGradient()<br>
methods will never get called. Overriding virtual methods through python<br>
doesn't work in the VTK wrappers. Maybe it will work at some point in<br>
the future.<br>
<br>
For sources and filters, people use vtkProgrammableSource and<br>
vtkProgrammableFilter to do what you are trying to do. You could use<br>
these as an example and write a vtkProgrammableImplicitFunction<br>
(in C++) that you could then use as a "hook" to write implicit functions<br>
in python.<br>
<span class="HOEnZb"><font color="#888888"><br>
- David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Sun, Dec 9, 2012 at 12:05 PM, Ryan Irvin <<a href="mailto:ryan.irvin@gmail.com">ryan.irvin@gmail.com</a>> wrote:<br>
> I'm trying to create a custom implicit surface function to represent a conic<br>
> asphere and my approach was to try and subclass vtkSphere. I had previously<br>
> tried to subclass vtkImplicitFunction without success and saw some posts<br>
> about not being able to subclass abstract classes in Python (I don't know if<br>
> this is still true).<br>
><br>
> The subclass I've put together is shown below, where the attribute surf_obj<br>
> is a python class representing the conic asphere and contains methods for<br>
> evaluating the surface function and gradient.<br>
><br>
> When I run my full script, the result is that the default vtkSphere is<br>
> always rendered. It's pretty apparent that I'm not understanding the proper<br>
> approach to this problem and/or am not properly subclassing vtkSphere.<br>
><br>
> I will be happy to provide the full *.py file which contains all of the code<br>
> but wasn't sure of the protocol and have not provided it with this post.<br>
><br>
> If anyone has any suggestions about the correct way to approach this problem<br>
> or can provide some advice for properly subclassing, I would very much<br>
> appreciate it.<br>
><br>
> -Ryan<br>
><br>
><br>
> class VtkImplicitConic( vtk.vtkSphere ):<br>
><br>
> def __init__( self, con_surf ):<br>
> self.surf_obj = con_surf<br>
> self.SetRadius( self.surf_obj.GetRadius() )<br>
><br>
><br>
> def EvaluateFunction( self, x, y, z ):<br>
> return self.surf_obj.EvaluateFunction( x, y, z )<br>
><br>
><br>
> def EvaluateGradient( self, x, n ):<br>
> n[0],n[1],n[2] = self.surf_obj.EvaluateGradient( x[0], x[1], x[2] )<br>
><br>
><br>
> def GetRadius( self ):<br>
> return self.surf_obj.GetRadius()<br>
><br>
><br>
> def SetRadius( self, radius ):<br>
> self.surf_obj.SetRadius( radius )<br>
</div></div></blockquote></div><br></div>