Quadric function to plot an ellipsoid

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Quadric function to plot an ellipsoid

Alberto Favaro
This post has NOT been accepted by the mailing list yet.
Dear Slicer community, i'm trying to plot on the 3D view an ellipsoid using the vtkquadric function as described in http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/DisplayQuadraticSurfaces.
My code is the following:

        quadric = vtk.vtkQuadric()
        quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
       
        # The sample function generates a distance function from the implicit
        # function. This is then contoured to get a polygonal surface.
        sample = vtk.vtkSampleFunction()
        sample.SetImplicitFunction(quadric)
        sample.SetModelBounds(-.5, .5, -.5, .5, -.5, .5)
        sample.SetSampleDimensions(1, 1, 1)
        sample.ComputeNormalsOff()
       
        # contour
        surface = vtk.vtkContourFilter()
        surface.SetInputConnection(sample.GetOutputPort())
        surface.SetValue(0, 0.0)

        apd = vtk.vtkAppendPolyData()
        apd.AddInputData(surface.GetOutput())
        apd.Update()

        scene = slicer.mrmlScene
        model = slicer.vtkMRMLModelNode()
        model.SetScene(scene)
        model.SetName(scene.GenerateUniqueName("Ellipsoid"))
        model.SetAndObservePolyData(sphere.GetOutput())
   
        modelDisplay = slicer.vtkMRMLModelDisplayNode()
        modelDisplay.SetColor(1,0,0) # yellow
        modelDisplay.SetBackfaceCulling(0)
        modelDisplay.SetScene(scene)
        scene.AddNode(modelDisplay)
        model.SetAndObserveDisplayNodeID(modelDisplay.GetID())
   
        scene.AddNode(model)

Unfortunately, nothing appears on the screen.
Can someone tell me where is the problem?
Many thanks

Alberto
Loading...